Bug 1806808 [wpt PR 37624] - Revert "WPT: Allow `window.onload` to contain multiple...
[gecko.git] / testing / web-platform / tests / content-security-policy / style-src / inline-style-allowed-while-cloning-objects.sub.html
blobe99699410e00b5756a08dc7148e75388b40a3410
1 <!DOCTYPE html>
2 <html>
4 <head>
5 <!-- Programmatically converted from a WebKit Reftest, please forgive resulting idiosyncracies.-->
6 <meta http-equiv="Content-Security-Policy" content="style-src 'self'; script-src 'self' 'unsafe-inline'; connect-src 'self';">
7 <title>inline-style-allowed-while-cloning-objects</title>
8 <script src="/resources/testharness.js"></script>
9 <script src="/resources/testharnessreport.js"></script>
10 <script>
11 setup({ explicit_done: true });
13 var t = async_test("Test that violation report event was fired");
14 window.addEventListener("securitypolicyviolation", t.step_func_done(function(e) {
15 assert_equals(e.violatedDirective, "style-src-attr");
16 }));
17 window.onload = function() {
18 try {
19 runTests();
20 } finally {
21 done();
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)
102 test(function() {
103 assert_equals(window.getComputedStyle(ops).background, window.getComputedStyle(violetOps).background)
105 test(function() {
106 assert_equals(window.getComputedStyle(clonedOps).background, window.getComputedStyle(violetOps).background)
108 test(function() {
109 assert_equals(ops.id, "ops")
111 test(function() {
112 assert_equals(ops.id, clonedOps.id)
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");
124 </script>
125 </head>
127 <body>
129 This test ensures that styles can be set by object.cloneNode()
130 </p>
131 <div id="nodes">
132 This is a div (nodes)
133 <div id="node1"> This is a div. (node 1 or 2)</div>
134 <div id="node3"> This is a div. (node 3 or 4)</div>
135 </div>
136 <div id="ops" style="background: rgb(238, 130, 238)">
137 Yet another div.
138 </div>
139 <div id="violetOps">
140 Yet another div.
141 </div>
142 <svg id="svg" style="background: rgb(238, 130, 238)"></svg>
143 <div id="log"></div>
144 </body>
146 </html>