1 describe("plugins-legend", function() {
3 beforeEach(function() {
4 document
.body
.innerHTML
= "<div id='graph'></div><div id='label'></div>";
10 it('testLegendEscape', function() {
15 var data
= "X,<script>alert('XSS')</script>\n" +
22 var graph
= document
.getElementById("graph");
23 var g
= new Dygraph(graph
, data
, opts
);
25 var legendPlugin
= new Dygraph
.Plugins
.Legend();
26 legendPlugin
.activate(g
);
28 selectedX
: 'selectedX',
31 name
: "<script>alert('XSS')</script>",
36 legendPlugin
.select(e
);
38 var legendSpan
= legendPlugin
.legend_div_
.querySelector("span b span");
39 assert
.equal(legendSpan
.innerHTML
, "<script>alert('XSS')</script>");
43 it('should let labelsDiv be a string', function() {
44 var labelsDiv
= document
.getElementById('label');
45 var g
= new Dygraph('graph', 'X,Y\n1,2\n', {labelsDiv
: 'label'});
48 assert
.equal('1: Y: 2', Util
.nbspToSpace(labelsDiv
.textContent
));
51 it('should let labelsDiv be an Element', function() {
52 var labelsDiv
= document
.getElementById('label');
53 var g
= new Dygraph('graph', 'X,Y\n1,2\n', { labelsDiv
: labelsDiv
});
54 assert
.isNull(labelsDiv
.getAttribute('class')); // dygraph-legend not added.
56 assert
.equal('1: Y: 2', Util
.nbspToSpace(labelsDiv
.textContent
));
59 it('should render dashed patterns', function() {
60 var g
= new Dygraph('graph', 'X,Y\n1,2\n', {
61 strokePattern
: [5, 5],
66 // The legend has a dashed line and a label.
67 var legendEl
= document
.querySelector('.dygraph-legend > span');
68 assert
.equal(' Y', legendEl
.textContent
);
69 var dashEl
= document
.querySelector('.dygraph-legend > span > div');
70 assert
.equal(window
.getComputedStyle(dashEl
)['border-bottom-color'],