1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
<!DOCTYPE html>
<html>
<head>
<!-- Programmatically converted from a WebKit Reftest, please forgive resulting idiosyncracies.-->
<meta http-equiv="Content-Security-Policy" content="style-src 'self'; script-src 'self' 'unsafe-inline'; connect-src 'self';">
<title>inline-style-allowed-while-cloning-objects</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
setup({ explicit_done: true });
var t = async_test("Test that violation report event was fired");
window.addEventListener("securitypolicyviolation", t.step_func_done(function(e) {
assert_equals(e.violatedDirective, "style-src-attr");
}));
window.onload = function() {
try {
runTests();
} finally {
done();
}
};
function runTests() {
window.nodes = document.getElementById('nodes');
window.node1 = document.getElementById('node1');
window.node1.style.background = "yellow";
window.node1.style.color = "red";
window.node2 = document.getElementById('node1').cloneNode(true);
window.node2.id = "node2";
window.node3 = document.getElementById('node3');
window.node3.style.background = "blue";
window.node3.style.color = "green";
window.node4 = document.getElementById('node3').cloneNode(false);
window.node4.id = "node4";
window.node4.innerHTML = "Node #4";
nodes.appendChild(node1);
nodes.appendChild(node2);
nodes.appendChild(node3);
nodes.appendChild(node4);
test(function() {
assert_equals(node1.style.background.match(/yellow/)[0], "yellow")
});
test(function() {
assert_equals(node2.style.background.match(/yellow/)[0], "yellow")
});
test(function() {
assert_equals(node3.style.background.match(/blue/)[0], "blue")
});
test(function() {
assert_equals(node4.style.background.match(/blue/)[0], "blue")
});
test(function() {
assert_equals(node1.style.color, "red")
});
test(function() {
assert_equals(node2.style.color, "red")
});
test(function() {
assert_equals(node3.style.color, "green")
});
test(function() {
assert_equals(node4.style.color, "green")
});
test(function() {
assert_equals(window.getComputedStyle(node1).background, window.getComputedStyle(node2).background)
});
test(function() {
assert_equals(window.getComputedStyle(node3).background, window.getComputedStyle(node4).background)
});
test(function() {
assert_equals(window.getComputedStyle(node1).color, window.getComputedStyle(node2).color)
});
test(function() {
assert_equals(window.getComputedStyle(node3).color, window.getComputedStyle(node4).color)
});
window.ops = document.getElementById('ops');
ops.style.color = 'red';
window.clonedOps = ops.cloneNode(true);
window.violetOps = document.getElementById('violetOps');
violetOps.style.background = 'rgb(238, 130, 238)';
document.getElementsByTagName('body')[0].appendChild(clonedOps);
test(function() {
assert_equals(ops.style.background, "")
});
test(function() {
assert_equals(ops.style.color, "red")
});
test(function() {
assert_equals(clonedOps.style.background, "")
});
test(function() {
assert_equals(violetOps.style.background.match(/rgb\(238, 130, 238\)/)[0], "rgb(238, 130, 238)")
});
test(function() {
assert_equals(window.getComputedStyle(clonedOps).background, window.getComputedStyle(ops).background)
});
test(function() {
assert_equals(window.getComputedStyle(clonedOps).color, window.getComputedStyle(ops).color)
});
test(function() {
assert_equals(window.getComputedStyle(ops).background, window.getComputedStyle(violetOps).background)
});
test(function() {
assert_equals(window.getComputedStyle(clonedOps).background, window.getComputedStyle(violetOps).background)
});
test(function() {
assert_equals(ops.id, "ops")
});
test(function() {
assert_equals(ops.id, clonedOps.id)
});
test(function() {
let el = document.getElementById("svg");
assert_equals(el.getAttribute("style"), "");
el.style.background = violetOps.style.background;
assert_not_equals(el.style.background, "");
let clone = el.cloneNode(true);
assert_equals(el.style.background, clone.style.background)
}, "non-HTML namespace");
}
</script>
</head>
<body>
<p>
This test ensures that styles can be set by object.cloneNode()
</p>
<div id="nodes">
This is a div (nodes)
<div id="node1"> This is a div. (node 1 or 2)</div>
<div id="node3"> This is a div. (node 3 or 4)</div>
</div>
<div id="ops" style="background: rgb(238, 130, 238)">
Yet another div.
</div>
<div id="violetOps">
Yet another div.
</div>
<svg id="svg" style="background: rgb(238, 130, 238)"></svg>
<div id="log"></div>
</body>
</html>
|