Show More
@@ -1,94 +1,97 b'' | |||
|
1 | 1 | // |
|
2 | 2 | // Test display isolation |
|
3 | 3 | // An object whose metadata contains an "isolated" tag must be isolated |
|
4 | 4 | // from the rest of the document. In the case of inline SVGs, this means |
|
5 | 5 | // that multiple SVGs have different scopes. This test checks that there |
|
6 | 6 | // are no CSS leaks between two isolated SVGs. |
|
7 | 7 | // |
|
8 | 8 | |
|
9 | 9 | casper.notebook_test(function () { |
|
10 | 10 | this.evaluate(function () { |
|
11 | 11 | var cell = IPython.notebook.get_cell(0); |
|
12 | 12 | cell.set_text( "from IPython.core.display import SVG, display_svg\n" |
|
13 | 13 | + "s1 = '''<svg width='1cm' height='1cm' viewBox='0 0 1000 500'>" |
|
14 | 14 | + "<defs><style>rect {fill:red;}; </style></defs>" |
|
15 | 15 | + "<rect id='r1' x='200' y='100' width='600' height='300' /></svg>" |
|
16 | 16 | + "'''\n" |
|
17 | 17 | + "s2 = '''<svg width='1cm' height='1cm' viewBox='0 0 1000 500'>" |
|
18 | 18 | + "<rect id='r2' x='200' y='100' width='600' height='300' /></svg>" |
|
19 | 19 | + "'''\n" |
|
20 | 20 | + "display_svg(SVG(s1), metadata=dict(isolated=True))\n" |
|
21 | 21 | + "display_svg(SVG(s2), metadata=dict(isolated=True))\n" |
|
22 | 22 | ); |
|
23 | 23 | cell.execute(); |
|
24 | 24 | console.log("hello" ); |
|
25 | 25 | }); |
|
26 | 26 | |
|
27 | 27 | this.then(function() { |
|
28 | 28 | var fname=this.test.currentTestFile.split('/').pop().toLowerCase(); |
|
29 | 29 | this.echo(fname) |
|
30 | 30 | this.echo(this.currentUrl) |
|
31 | 31 | this.evaluate(function (n) { |
|
32 | 32 | IPython.notebook.rename(n); |
|
33 | 33 | console.write("hello" + n); |
|
34 | 34 | IPython.notebook.save_notebook(); |
|
35 | 35 | }, {n : fname}); |
|
36 | 36 | this.echo(this.currentUrl) |
|
37 | 37 | }); |
|
38 | 38 | |
|
39 | 39 | this.then(function() { |
|
40 | 40 | |
|
41 | 41 | url = this.evaluate(function() { |
|
42 | 42 | IPython.notebook.rename("foo"); |
|
43 | 43 | //$("span#notebook_name")[0].click(); |
|
44 | 44 | //$("input")[0].value = "please-work"; |
|
45 | 45 | //$(".btn-primary")[0].click(); |
|
46 | 46 | return document.location.href; |
|
47 | 47 | }) |
|
48 | 48 | this.echo("renamed" + url); |
|
49 | 49 | this.echo(this.currentUrl); |
|
50 | 50 | }); |
|
51 | 51 | |
|
52 | 52 | this.wait_for_output(0); |
|
53 | 53 | |
|
54 | 54 | this.then(function () { |
|
55 | 55 | var colors = this.evaluate(function () { |
|
56 | 56 | var colors = []; |
|
57 | 57 | var ifr = __utils__.findAll("iframe"); |
|
58 | 58 | var svg1 = ifr[0].contentWindow.document.getElementById('r1'); |
|
59 | 59 | colors[0] = window.getComputedStyle(svg1)["fill"]; |
|
60 | 60 | var svg2 = ifr[1].contentWindow.document.getElementById('r2'); |
|
61 | 61 | colors[1] = window.getComputedStyle(svg2)["fill"]; |
|
62 | 62 | return colors; |
|
63 | 63 | }); |
|
64 | 64 | |
|
65 | 65 | this.test.assertEquals(colors[0], '#ff0000', 'First svg should be red'); |
|
66 | 66 | this.test.assertEquals(colors[1], '#000000', 'Second svg should be black'); |
|
67 | 67 | }); |
|
68 | 68 | |
|
69 | 69 | // now ensure that we can pass the same metadata dict to plain old display() |
|
70 | 70 | this.thenEvaluate(function () { |
|
71 | 71 | var cell = IPython.notebook.get_cell(0); |
|
72 | cell.clear_output(); | |
|
72 | 73 | cell.set_text( "from IPython.display import display\n" |
|
73 | 74 | + "display(SVG(s1), metadata=dict(isolated=True))\n" |
|
74 | 75 | + "display(SVG(s2), metadata=dict(isolated=True))\n" |
|
75 | 76 | ); |
|
76 | 77 | cell.execute(); |
|
77 | 78 | }); |
|
78 | ||
|
79 | ||
|
80 | this.wait_for_output(0); | |
|
81 | ||
|
79 | 82 | // same test as original |
|
80 | 83 | this.then(function () { |
|
81 | 84 | var colors = this.evaluate(function () { |
|
82 | 85 | var colors = []; |
|
83 | 86 | var ifr = __utils__.findAll("iframe"); |
|
84 | 87 | var svg1 = ifr[0].contentWindow.document.getElementById('r1'); |
|
85 | 88 | colors[0] = window.getComputedStyle(svg1)["fill"]; |
|
86 | 89 | var svg2 = ifr[1].contentWindow.document.getElementById('r2'); |
|
87 | 90 | colors[1] = window.getComputedStyle(svg2)["fill"]; |
|
88 | 91 | return colors; |
|
89 | 92 | }); |
|
90 | 93 | |
|
91 | 94 | this.test.assertEquals(colors[0], '#ff0000', 'First svg should be red'); |
|
92 | 95 | this.test.assertEquals(colors[1], '#000000', 'Second svg should be black'); |
|
93 | 96 | }); |
|
94 | 97 | }); |
General Comments 0
You need to be logged in to leave comments.
Login now