Skip to content

Commit

Permalink
Revert "WPT: Allow window.onload to contain multiple test()s"
Browse files Browse the repository at this point in the history
This reverts commit 4a03c6c459fdbf11976a424aa02a1d094484134c.

Reason for revert:

This has caused tests in upstream WPT to fail, blocking unrelated PRs. It was still possible to upstream this because those tests weren't triggered on the change due to a bug:
web-platform-tests#37623

There was an attempted fix for this:
web-platform-tests#37549

But, quoting jgraham from the WPT Matrix chat:

> the actual fix failed a test I wrote and now I need to spend some more time investigating

Original change's description:
> 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 <[email protected]>
> Auto-Submit: Mason Freed <[email protected]>
> Reviewed-by: Mason Freed <[email protected]>
> Commit-Queue: Mason Freed <[email protected]>
> Reviewed-by: Xianzhu Wang <[email protected]>
> Cr-Commit-Position: refs/heads/main@{#1081558}

Bug: 1395228,1395226,1307772
Change-Id: Icbddad3a8bb47473bcbc331f424661b9041addf2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4111318
Reviewed-by: David Baron <[email protected]>
Commit-Queue: Philip Jägenstedt <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1085925}
  • Loading branch information
foolip authored and chromium-wpt-export-bot committed Dec 21, 2022
1 parent 8073ec1 commit 5c571b8
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,108 +8,119 @@
<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() {
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");
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>

Expand Down
2 changes: 2 additions & 0 deletions css/cssom-view/negativeMargins.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Hello
</div>
<script>
setup({explicit_done:true});
window.onload = function () {
var outer = document.getElementById('outer');
var inner = document.getElementById('inner');
Expand All @@ -25,6 +26,7 @@
[inner, outer, document.body, document.querySelector('html')],
"elementsFromPoint should get sequence [inner, outer, body, html]");
});
done();
};
</script>
</body>
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

<script>
"use strict";
setup({ explicit_done: true });

window.onload = () => {
const target = frames[0];
const origProto = Object.getPrototypeOf(target);
Expand All @@ -31,5 +33,7 @@
testSettingImmutablePrototypeToNewValueOnly(
"Became cross-origin via document.domain", target, origProto,
"the original value from before going cross-origin", { isSameOriginDomain: false });

done();
};
</script>
2 changes: 1 addition & 1 deletion infrastructure/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ This directory contains a number of tests to ensure test running
infrastructure is operating correctly:

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

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

Expand Down
28 changes: 0 additions & 28 deletions infrastructure/expected-fail/window-onload-test.html

This file was deleted.

5 changes: 0 additions & 5 deletions resources/testharness.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,7 @@
}

on_event(window, 'load', function() {
setTimeout(() => {
this_obj.all_loaded = true;
if (tests.all_done()) {
tests.complete();
}
},0);
});

on_event(window, 'message', function(event) {
Expand Down

0 comments on commit 5c571b8

Please sign in to comment.