|
8 | 8 | <script src="/resources/testharness.js"></script>
|
9 | 9 | <script src="/resources/testharnessreport.js"></script>
|
10 | 10 | <script>
|
11 |
| - setup({ explicit_done: true }); |
12 |
| - |
13 | 11 | var t = async_test("Test that violation report event was fired");
|
14 | 12 | window.addEventListener("securitypolicyviolation", t.step_func_done(function(e) {
|
15 | 13 | assert_equals(e.violatedDirective, "style-src-attr");
|
16 | 14 | }));
|
17 | 15 | window.onload = function() {
|
18 |
| - try { |
19 |
| - runTests(); |
20 |
| - } finally { |
21 |
| - done(); |
22 |
| - } |
| 16 | + window.nodes = document.getElementById('nodes'); |
| 17 | + window.node1 = document.getElementById('node1'); |
| 18 | + window.node1.style.background = "yellow"; |
| 19 | + window.node1.style.color = "red"; |
| 20 | + window.node2 = document.getElementById('node1').cloneNode(true); |
| 21 | + window.node2.id = "node2"; |
| 22 | + window.node3 = document.getElementById('node3'); |
| 23 | + window.node3.style.background = "blue"; |
| 24 | + window.node3.style.color = "green"; |
| 25 | + window.node4 = document.getElementById('node3').cloneNode(false); |
| 26 | + window.node4.id = "node4"; |
| 27 | + window.node4.innerHTML = "Node #4"; |
| 28 | + nodes.appendChild(node1); |
| 29 | + nodes.appendChild(node2); |
| 30 | + nodes.appendChild(node3); |
| 31 | + nodes.appendChild(node4); |
| 32 | + test(function() { |
| 33 | + assert_equals(node1.style.background.match(/yellow/)[0], "yellow") |
| 34 | + }); |
| 35 | + test(function() { |
| 36 | + assert_equals(node2.style.background.match(/yellow/)[0], "yellow") |
| 37 | + }); |
| 38 | + test(function() { |
| 39 | + assert_equals(node3.style.background.match(/blue/)[0], "blue") |
| 40 | + }); |
| 41 | + test(function() { |
| 42 | + assert_equals(node4.style.background.match(/blue/)[0], "blue") |
| 43 | + }); |
| 44 | + test(function() { |
| 45 | + assert_equals(node1.style.color, "red") |
| 46 | + }); |
| 47 | + test(function() { |
| 48 | + assert_equals(node2.style.color, "red") |
| 49 | + }); |
| 50 | + test(function() { |
| 51 | + assert_equals(node3.style.color, "green") |
| 52 | + }); |
| 53 | + test(function() { |
| 54 | + assert_equals(node4.style.color, "green") |
| 55 | + }); |
| 56 | + test(function() { |
| 57 | + assert_equals(window.getComputedStyle(node1).background, window.getComputedStyle(node2).background) |
| 58 | + }); |
| 59 | + test(function() { |
| 60 | + assert_equals(window.getComputedStyle(node3).background, window.getComputedStyle(node4).background) |
| 61 | + }); |
| 62 | + test(function() { |
| 63 | + assert_equals(window.getComputedStyle(node1).color, window.getComputedStyle(node2).color) |
| 64 | + }); |
| 65 | + test(function() { |
| 66 | + assert_equals(window.getComputedStyle(node3).color, window.getComputedStyle(node4).color) |
| 67 | + }); |
| 68 | + window.ops = document.getElementById('ops'); |
| 69 | + ops.style.color = 'red'; |
| 70 | + window.clonedOps = ops.cloneNode(true); |
| 71 | + window.violetOps = document.getElementById('violetOps'); |
| 72 | + violetOps.style.background = 'rgb(238, 130, 238)'; |
| 73 | + document.getElementsByTagName('body')[0].appendChild(clonedOps); |
| 74 | + test(function() { |
| 75 | + assert_equals(ops.style.background, "") |
| 76 | + }); |
| 77 | + test(function() { |
| 78 | + assert_equals(ops.style.color, "red") |
| 79 | + }); |
| 80 | + test(function() { |
| 81 | + assert_equals(clonedOps.style.background, "") |
| 82 | + }); |
| 83 | + test(function() { |
| 84 | + assert_equals(violetOps.style.background.match(/rgb\(238, 130, 238\)/)[0], "rgb(238, 130, 238)") |
| 85 | + }); |
| 86 | + test(function() { |
| 87 | + assert_equals(window.getComputedStyle(clonedOps).background, window.getComputedStyle(ops).background) |
| 88 | + }); |
| 89 | + test(function() { |
| 90 | + assert_equals(window.getComputedStyle(clonedOps).color, window.getComputedStyle(ops).color) |
| 91 | + }); |
| 92 | + test(function() { |
| 93 | + assert_equals(window.getComputedStyle(ops).background, window.getComputedStyle(violetOps).background) |
| 94 | + }); |
| 95 | + test(function() { |
| 96 | + assert_equals(window.getComputedStyle(clonedOps).background, window.getComputedStyle(violetOps).background) |
| 97 | + }); |
| 98 | + test(function() { |
| 99 | + assert_equals(ops.id, "ops") |
| 100 | + }); |
| 101 | + test(function() { |
| 102 | + assert_equals(ops.id, clonedOps.id) |
| 103 | + }); |
| 104 | + test(function() { |
| 105 | + let el = document.getElementById("svg"); |
| 106 | + assert_equals(el.getAttribute("style"), ""); |
| 107 | + el.style.background = violetOps.style.background; |
| 108 | + assert_not_equals(el.style.background, ""); |
| 109 | + let clone = el.cloneNode(true); |
| 110 | + assert_equals(el.style.background, clone.style.background) |
| 111 | + }, "non-HTML namespace"); |
23 | 112 | };
|
24 |
| - |
25 |
| - function runTests() { |
26 |
| - window.nodes = document.getElementById('nodes'); |
27 |
| - window.node1 = document.getElementById('node1'); |
28 |
| - window.node1.style.background = "yellow"; |
29 |
| - window.node1.style.color = "red"; |
30 |
| - window.node2 = document.getElementById('node1').cloneNode(true); |
31 |
| - window.node2.id = "node2"; |
32 |
| - window.node3 = document.getElementById('node3'); |
33 |
| - window.node3.style.background = "blue"; |
34 |
| - window.node3.style.color = "green"; |
35 |
| - window.node4 = document.getElementById('node3').cloneNode(false); |
36 |
| - window.node4.id = "node4"; |
37 |
| - window.node4.innerHTML = "Node #4"; |
38 |
| - nodes.appendChild(node1); |
39 |
| - nodes.appendChild(node2); |
40 |
| - nodes.appendChild(node3); |
41 |
| - nodes.appendChild(node4); |
42 |
| - test(function() { |
43 |
| - assert_equals(node1.style.background.match(/yellow/)[0], "yellow") |
44 |
| - }); |
45 |
| - test(function() { |
46 |
| - assert_equals(node2.style.background.match(/yellow/)[0], "yellow") |
47 |
| - }); |
48 |
| - test(function() { |
49 |
| - assert_equals(node3.style.background.match(/blue/)[0], "blue") |
50 |
| - }); |
51 |
| - test(function() { |
52 |
| - assert_equals(node4.style.background.match(/blue/)[0], "blue") |
53 |
| - }); |
54 |
| - test(function() { |
55 |
| - assert_equals(node1.style.color, "red") |
56 |
| - }); |
57 |
| - test(function() { |
58 |
| - assert_equals(node2.style.color, "red") |
59 |
| - }); |
60 |
| - test(function() { |
61 |
| - assert_equals(node3.style.color, "green") |
62 |
| - }); |
63 |
| - test(function() { |
64 |
| - assert_equals(node4.style.color, "green") |
65 |
| - }); |
66 |
| - test(function() { |
67 |
| - assert_equals(window.getComputedStyle(node1).background, window.getComputedStyle(node2).background) |
68 |
| - }); |
69 |
| - test(function() { |
70 |
| - assert_equals(window.getComputedStyle(node3).background, window.getComputedStyle(node4).background) |
71 |
| - }); |
72 |
| - test(function() { |
73 |
| - assert_equals(window.getComputedStyle(node1).color, window.getComputedStyle(node2).color) |
74 |
| - }); |
75 |
| - test(function() { |
76 |
| - assert_equals(window.getComputedStyle(node3).color, window.getComputedStyle(node4).color) |
77 |
| - }); |
78 |
| - window.ops = document.getElementById('ops'); |
79 |
| - ops.style.color = 'red'; |
80 |
| - window.clonedOps = ops.cloneNode(true); |
81 |
| - window.violetOps = document.getElementById('violetOps'); |
82 |
| - violetOps.style.background = 'rgb(238, 130, 238)'; |
83 |
| - document.getElementsByTagName('body')[0].appendChild(clonedOps); |
84 |
| - test(function() { |
85 |
| - assert_equals(ops.style.background, "") |
86 |
| - }); |
87 |
| - test(function() { |
88 |
| - assert_equals(ops.style.color, "red") |
89 |
| - }); |
90 |
| - test(function() { |
91 |
| - assert_equals(clonedOps.style.background, "") |
92 |
| - }); |
93 |
| - test(function() { |
94 |
| - assert_equals(violetOps.style.background.match(/rgb\(238, 130, 238\)/)[0], "rgb(238, 130, 238)") |
95 |
| - }); |
96 |
| - test(function() { |
97 |
| - assert_equals(window.getComputedStyle(clonedOps).background, window.getComputedStyle(ops).background) |
98 |
| - }); |
99 |
| - test(function() { |
100 |
| - assert_equals(window.getComputedStyle(clonedOps).color, window.getComputedStyle(ops).color) |
101 |
| - }); |
102 |
| - test(function() { |
103 |
| - assert_equals(window.getComputedStyle(ops).background, window.getComputedStyle(violetOps).background) |
104 |
| - }); |
105 |
| - test(function() { |
106 |
| - assert_equals(window.getComputedStyle(clonedOps).background, window.getComputedStyle(violetOps).background) |
107 |
| - }); |
108 |
| - test(function() { |
109 |
| - assert_equals(ops.id, "ops") |
110 |
| - }); |
111 |
| - test(function() { |
112 |
| - assert_equals(ops.id, clonedOps.id) |
113 |
| - }); |
114 |
| - test(function() { |
115 |
| - let el = document.getElementById("svg"); |
116 |
| - assert_equals(el.getAttribute("style"), ""); |
117 |
| - el.style.background = violetOps.style.background; |
118 |
| - assert_not_equals(el.style.background, ""); |
119 |
| - let clone = el.cloneNode(true); |
120 |
| - assert_equals(el.style.background, clone.style.background) |
121 |
| - }, "non-HTML namespace"); |
122 |
| - } |
123 |
| - |
124 | 113 | </script>
|
125 | 114 | </head>
|
126 | 115 |
|
|
0 commit comments