Skip to content

Commit e085ff1

Browse files
mfreed7chromium-wpt-export-bot
authored andcommitted
WPT: Allow window.onload to contain multiple test()s
****************************************************************** *** SHERIFFS: please don't revert this CL if it causes web_tests to flake/fail. If that happens, the cause is a bad test. Please mark that test as flaky/fail in TestExpectations, with a new crbug. Please block the new bug against crbug.com/1395228. Thanks! ****************************************************************** Prior to this CL, a test like this: ``` <script> window.onload = () => { test((t) => { ... }, 'test 1'); test((t) => { ... }, 'test 2'); test((t) => { ... }, 'test 3'); }; </script> ``` would not run anything after test #1. The issue is that the testharness immediately adds a window load handler that marks `all_loaded = true`, and that ends the tests as soon as the first result from the first test is processed. (The test runner waits for the first test because `Tests.prototype.all_done()` also waits until `this.tests.length > 0`.) There were various mitigating corner cases, such as if you started the list of tests with a promise_test(), that would increment a counter that kept the rest of the tests alive. Etc. With this CL, the testharness-added window.onload handler runs a setTimeout(0), so that `all_loaded` is only set to true after all of the tests are loaded by any window.onload handler. This exposed a few tests that should have been failing but were masked by the lack of test coverage - bugs have been filed for those. Also, several tests that were working around this via various means are also cleaned up in this CL. I'm sure there are more of those. Bug: 1395228,1395226,1307772 Change-Id: I6f12b5922186af4e1e06808ad23b47ceac68559c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4074305 Reviewed-by: Weizhong Xia <weizhong@google.com> Auto-Submit: Mason Freed <masonf@chromium.org> Reviewed-by: Mason Freed <masonf@chromium.org> Commit-Queue: Mason Freed <masonf@chromium.org> Reviewed-by: Xianzhu Wang <wangxianzhu@chromium.org> Cr-Commit-Position: refs/heads/main@{#1081558}
1 parent 7d8e7db commit e085ff1

File tree

6 files changed

+130
-114
lines changed

6 files changed

+130
-114
lines changed

content-security-policy/style-src/inline-style-allowed-while-cloning-objects.sub.html

+96-107
Original file line numberDiff line numberDiff line change
@@ -8,119 +8,108 @@
88
<script src="/resources/testharness.js"></script>
99
<script src="/resources/testharnessreport.js"></script>
1010
<script>
11-
setup({ explicit_done: true });
12-
1311
var t = async_test("Test that violation report event was fired");
1412
window.addEventListener("securitypolicyviolation", t.step_func_done(function(e) {
1513
assert_equals(e.violatedDirective, "style-src-attr");
1614
}));
1715
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");
23112
};
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-
124113
</script>
125114
</head>
126115

css/cssom-view/negativeMargins.html

-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
Hello
1010
</div>
1111
<script>
12-
setup({explicit_done:true});
1312
window.onload = function () {
1413
var outer = document.getElementById('outer');
1514
var inner = document.getElementById('inner');
@@ -26,7 +25,6 @@
2625
[inner, outer, document.body, document.querySelector('html')],
2726
"elementsFromPoint should get sequence [inner, outer, body, html]");
2827
});
29-
done();
3028
};
3129
</script>
3230
</body>

html/browsers/the-windowproxy-exotic-object/windowproxy-prototype-setting-goes-cross-origin-domain.sub.html

-4
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
<script>
1414
"use strict";
15-
setup({ explicit_done: true });
16-
1715
window.onload = () => {
1816
const target = frames[0];
1917
const origProto = Object.getPrototypeOf(target);
@@ -33,7 +31,5 @@
3331
testSettingImmutablePrototypeToNewValueOnly(
3432
"Became cross-origin via document.domain", target, origProto,
3533
"the original value from before going cross-origin", { isSameOriginDomain: false });
36-
37-
done();
3834
};
3935
</script>

infrastructure/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ This directory contains a number of tests to ensure test running
22
infrastructure is operating correctly:
33

44
* The tests in assumptions/ are designed to test UA assumptions
5-
documented in [assumptions.md](/docs/_writing-tests/assumptions.md).
5+
documented in [assumptions.md](/docs/writing-tests/assumptions.md).
66

77
* The tests in server/ are designed to test the WPT server configuration
88

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf-8">
3+
<script src="/resources/testharness.js"></script>
4+
<script src="/resources/testharnessreport.js"></script>
5+
6+
<script>
7+
window.onload = () => {
8+
test((t) => {
9+
assert_true(true,'This should pass');
10+
}, 'test 1');
11+
test((t) => {
12+
assert_true(false,'This should FAIL');
13+
}, 'test 2');
14+
test((t) => {
15+
assert_true(false,'This should FAIL');
16+
}, 'test 3');
17+
18+
promise_test(async t => {
19+
assert_true(false,'This should FAIL');
20+
},'promise 1');
21+
promise_test(async t => {
22+
assert_true(false,'This should FAIL');
23+
},'promise 2');
24+
promise_test(async t => {
25+
assert_true(false,'This should FAIL');
26+
},'promise 3');
27+
};
28+
</script>

resources/testharness.js

+5
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,12 @@
9191
}
9292

9393
on_event(window, 'load', function() {
94+
setTimeout(() => {
9495
this_obj.all_loaded = true;
96+
if (tests.all_done()) {
97+
tests.complete();
98+
}
99+
},0);
95100
});
96101

97102
on_event(window, 'message', function(event) {

0 commit comments

Comments
 (0)