Skip to content

Commit a015768

Browse files
Guohui Dengchromium-wpt-export-bot
authored andcommitted
[WPT] Fix a flaky test resource_dedicated_worker.html.
It's flakey because the number of resource timing entries depends on whether `favicon.ico` request is included or not. Reference: web-platform-tests/interop#1078 (comment) A more reliable way to verify the resources from workers don't appear in the main document, is to verify the resources from workers don't appear in the main document. . Bug: 454485904 Change-Id: I375fa1191ee3ae594cb5302679ccd5195b9baaa2 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7081867 Reviewed-by: Noam Rosenthal <[email protected]> Commit-Queue: Guohui Deng <[email protected]> Reviewed-by: Michal Mocny <[email protected]> Cr-Commit-Position: refs/heads/main@{#1541263}
1 parent aa81de6 commit a015768

File tree

1 file changed

+44
-6
lines changed

1 file changed

+44
-6
lines changed

resource-timing/resource_dedicated_worker.html

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,54 @@
99
<script src="/resources/testharnessreport.js"></script>
1010
<script src="resources/webperftestharness.js"></script>
1111
<script src="resources/webperftestharnessextension.js"></script>
12-
<link rel="stylesheet" href="resources/resource_timing_test0.css" />
12+
<script src="/common/get-host-info.sub.js"></script>
1313
<script>
14-
setup({explicit_done: true});
14+
15+
const mainDocResource = "/images/red.png?noCacheResourceDedicatedWorker";
16+
// Resources below are requested in the worker thread
17+
// "resources/worker_with_images.js".
18+
const workerResources = [
19+
"/resource-timing/resources/blue.png",
20+
"/resource-timing/resources/resource_timing_test0.png",
21+
];
22+
23+
const {promise: mainDocPromise, resolve: resolveMainDoc} = Promise.withResolvers();
24+
const {promise: workerPromise, resolve: resolveWorker} = Promise.withResolvers();
25+
26+
// Load main document resource
27+
var xhr = new XMLHttpRequest;
28+
xhr.open('get', mainDocResource, true);
29+
xhr.onload = function() {
30+
resolveMainDoc();
31+
}
32+
xhr.send();
33+
1534
const worker = new Worker("resources/worker_with_images.js");
1635
worker.onmessage = function(event) {
17-
const context = new PerformanceContext(window.performance);
18-
const entries = context.getEntriesByType('resource');
19-
test_equals(entries.length, 6, "There should be six entries: 4 scripts, 1 stylesheet, and the worker itself");
20-
done();
36+
resolveWorker();
2137
}
38+
39+
promise_test(async () => {
40+
await Promise.all([
41+
mainDocPromise,
42+
workerPromise,
43+
]);
44+
45+
const context = new PerformanceContext(window.performance);
46+
47+
// The main doc resource appears in the main document.
48+
const mainDocResourceUrl = new URL(mainDocResource, get_host_info().HTTP_ORIGIN).href;
49+
const mainDocEntries = context.getEntriesByName(mainDocResourceUrl);
50+
assert_greater_than(mainDocEntries.length, 0, "main doc resource appears");
51+
52+
// On the other hand, the worker resources don't.
53+
for(resource of workerResources) {
54+
let workerResourceUrl = new URL(resource, get_host_info().HTTP_ORIGIN).href;
55+
let workerEntries = context.getEntriesByName(workerResourceUrl);
56+
assert_equals(workerEntries.length, 0, "worker resources don't appear");
57+
}
58+
}, "Verify that resources requested by dedicated workers don't appear in the main document");
59+
2260
</script>
2361
</head>
2462
<body>

0 commit comments

Comments
 (0)