Skip to content

Commit

Permalink
Revert "Revert "WPT: Allow window.onload to contain multiple `test(…
Browse files Browse the repository at this point in the history
…)`s"" (#38806)

This reverts commit 5c571b8.

DO NOT MERGE: run `./wpt test-jobs --all` to see if it passes

Adjust test to test for two assertions

#38806 (comment)

Revert "DO NOT MERGE: run `./wpt test-jobs --all` to see if it passes"

This reverts commit 8891404.

Update comments

- Add @foolip's suggestion from #38806 (comment)
- Also, update comment at the top with better phrasing.

change referenced PR/CL
  • Loading branch information
jcscottiii committed Nov 29, 2023
1 parent 31655b3 commit 9f9188a
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,119 +8,108 @@
<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();
}
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");
};

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: 0 additions & 2 deletions css/cssom-view/negativeMargins.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
Hello
</div>
<script>
setup({explicit_done:true});
window.onload = function () {
var outer = document.getElementById('outer');
var inner = document.getElementById('inner');
Expand All @@ -26,7 +25,6 @@
[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,8 +12,6 @@

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

window.onload = () => {
const target = frames[0];
const origProto = Object.getPrototypeOf(target);
Expand All @@ -33,7 +31,5 @@
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: 28 additions & 0 deletions infrastructure/expected-fail/window-onload-test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<meta charset="utf-8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<script>
window.onload = () => {
test((t) => {
assert_true(true,'This should pass');
}, 'test 1');
test((t) => {
assert_true(false,'This should FAIL');
}, 'test 2');
test((t) => {
assert_true(false,'This should FAIL');
}, 'test 3');

promise_test(async t => {
assert_true(false,'This should FAIL');
},'promise 1');
promise_test(async t => {
assert_true(false,'This should FAIL');
},'promise 2');
promise_test(async t => {
assert_true(false,'This should FAIL');
},'promise 3');
};
</script>
14 changes: 8 additions & 6 deletions resources/test/tests/unit/late-test.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
<p>This test simulates an automated test running scenario, where the test
results emitted by testharness.js may be interpreted after some delay. It is
intended to demonstrate that in such cases, any additional tests which are
executed during that delay are <em>not</em> included in the dataset.</p>
executed during that delay are included in the dataset.</p>

<p>Although these "late" tests are likely an indication of a mistake in test
design, they cannot be detected deterministically, so in the interest of
stability, they should be silently tolerated.</p>
<p>Although these "late tests" are likely an indication of a mistake in test
design, they are also recorded. Previously, "late tests" were ignored.
This test changed to assert "late tests" were no longer ignored after
https://github.com/web-platform-tests/wpt/pull/38806 was introduced.</p>
<script>
async_test(function(t) {
var source = [
Expand All @@ -27,7 +28,7 @@
"test(function() {}, 'acceptable test');",
"onload = function() {",
" done();",
" test(function() {}, 'this test is late and should be ignored');",
" test(function() {}, 'test registered in onload handler');",
"};",
"</" + "script>"
].join("\n");
Expand All @@ -37,8 +38,9 @@
window.childReady = t.step_func(function(childWindow) {
childWindow.add_completion_callback(t.step_func(function(tests, status) {
t.step_timeout(t.step_func(function() {
assert_equals(tests.length, 1);
assert_equals(tests.length, 2);
assert_equals(tests[0].name, "acceptable test");
assert_equals(tests[1].name, "test registered in onload handler");
assert_equals(status.status, status.OK);
t.done();
}), 0);
Expand Down
5 changes: 5 additions & 0 deletions resources/testharness.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@
}

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 9f9188a

Please sign in to comment.