|
130 | 130 | } |
131 | 131 |
|
132 | 132 | function waitForResource(url) { |
133 | | - const name = new URL(url, location.href).href; |
| 133 | + const parsed = new URL(url, location.href); |
| 134 | + const name = parsed.href; |
| 135 | + // Implementations may cancel an in-flight script fetch on parser abort, in |
| 136 | + // which case no PerformanceResourceTiming entry is emitted. Race against a |
| 137 | + // slightly slower un-aborted control request so cancelled fetches settle |
| 138 | + // promptly without waiting for the 3s fallback timeout. |
| 139 | + const controlUrl = new URL(parsed); |
| 140 | + controlUrl.search = controlUrl.search.replace("trickle(d0.2)", "trickle(d0.3)"); |
| 141 | + controlUrl.searchParams.set("control_probe", Math.random()); |
| 142 | + const controlDone = fetch(controlUrl).then(r => r.text(), () => {}); |
134 | 143 | let observer; |
135 | | - return withTimeout(new Promise(resolve => { |
136 | | - observer = new PerformanceObserver(list => { |
137 | | - if (list.getEntries().some(e => e.name === name)) { |
138 | | - observer.disconnect(); |
139 | | - resolve(); |
140 | | - } |
141 | | - }); |
142 | | - observer.observe({ type: "resource", buffered: true }); |
143 | | - })).finally(() => observer?.disconnect()); |
| 144 | + return withTimeout(Promise.race([ |
| 145 | + controlDone, |
| 146 | + new Promise(resolve => { |
| 147 | + observer = new PerformanceObserver(list => { |
| 148 | + if (list.getEntries().some(e => e.name === name)) { |
| 149 | + observer.disconnect(); |
| 150 | + resolve(); |
| 151 | + } |
| 152 | + }); |
| 153 | + observer.observe({ type: "resource", buffered: true }); |
| 154 | + }), |
| 155 | + ])).finally(() => observer?.disconnect()); |
144 | 156 | } |
145 | 157 |
|
146 | 158 | promise_test(async (t) => { |
|
567 | 579 | t.add_cleanup(() => { delete window.iframe_blocked_ran; }); |
568 | 580 |
|
569 | 581 | const iframe = document.createElement("iframe"); |
| 582 | + t.add_cleanup(() => iframe.remove()); |
570 | 583 | iframe.srcdoc = "<!doctype html><body><div id='target'></div></body>"; |
571 | 584 | await new Promise(resolve => { |
572 | 585 | iframe.addEventListener("load", resolve, { once: true }); |
|
576 | 589 | iframe.contentWindow.notifyParent = () => { |
577 | 590 | window.iframe_blocked_ran = true; |
578 | 591 | }; |
| 592 | + const controlDone = fetch("resources/slow.js?pipe=trickle(d0.3)&f12_control=1") |
| 593 | + .then(r => r.text()) |
| 594 | + .then(() => new Promise(r => t.step_timeout(r, 0))); |
579 | 595 | const target = iframe.contentDocument.getElementById("target"); |
580 | 596 | const writer = target.streamHTMLUnsafe({ runScripts: true }).getWriter(); |
581 | 597 | await writer.write( |
|
584 | 600 | ); |
585 | 601 |
|
586 | 602 | iframe.remove(); |
587 | | - await new Promise(r => t.step_timeout(r, 350)); |
| 603 | + await controlDone; |
588 | 604 | assert_false(window.iframe_blocked_ran, "Scripts in removed iframe must not execute"); |
589 | 605 | }, "Removing iframe while stream is blocked on external script does not crash or execute scripts"); |
590 | 606 |
|
|
0 commit comments