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>
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");
17 window
.onload = function() {
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
);
43 assert_equals(node1
.style
.background
.match(/yellow/)[0], "yellow")
46 assert_equals(node2
.style
.background
.match(/yellow/)[0], "yellow")
49 assert_equals(node3
.style
.background
.match(/blue/)[0], "blue")
52 assert_equals(node4
.style
.background
.match(/blue/)[0], "blue")
55 assert_equals(node1
.style
.color
, "red")
58 assert_equals(node2
.style
.color
, "red")
61 assert_equals(node3
.style
.color
, "green")
64 assert_equals(node4
.style
.color
, "green")
67 assert_equals(window
.getComputedStyle(node1
).background
, window
.getComputedStyle(node2
).background
)
70 assert_equals(window
.getComputedStyle(node3
).background
, window
.getComputedStyle(node4
).background
)
73 assert_equals(window
.getComputedStyle(node1
).color
, window
.getComputedStyle(node2
).color
)
76 assert_equals(window
.getComputedStyle(node3
).color
, window
.getComputedStyle(node4
).color
)
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
);
85 assert_equals(ops
.style
.background
, "")
88 assert_equals(ops
.style
.color
, "red")
91 assert_equals(clonedOps
.style
.background
, "")
94 assert_equals(violetOps
.style
.background
.match(/rgb\(238, 130, 238\)/)[0], "rgb(238, 130, 238)")
97 assert_equals(window
.getComputedStyle(clonedOps
).background
, window
.getComputedStyle(ops
).background
)
100 assert_equals(window
.getComputedStyle(clonedOps
).color
, window
.getComputedStyle(ops
).color
)
103 assert_equals(window
.getComputedStyle(ops
).background
, window
.getComputedStyle(violetOps
).background
)
106 assert_equals(window
.getComputedStyle(clonedOps
).background
, window
.getComputedStyle(violetOps
).background
)
109 assert_equals(ops
.id
, "ops")
112 assert_equals(ops
.id
, clonedOps
.id
)
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");
129 This test ensures that styles can be set by object.cloneNode()
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>
136 <div id=
"ops" style=
"background: rgb(238, 130, 238)">
142 <svg id=
"svg" style=
"background: rgb(238, 130, 238)"></svg>