Debian Codegraph @

testing/web-platform/mozilla/tests/dom/fs/fs-writable_unlocked_on_tab_close.https.window.js

raw
1 // META: title=Origin private file system used from multiple tabs
2 // META: script=support/testHelpers.js
3
4 promise_test(async t => {
5 const bc = new BroadcastChannel("Coordinate writables");
6
7 function firstReady(win) {
8 return new Promise(resolve => {
9 // Blur triggers after the unload event and after window.closed is set
10 win.onblur = () => {
11 // Closing the low-level file handle may get stuck, but the unlocking
12 // request can only be sent to the parent after the handle is closed.
13 // There is no guarantee when or if the closing will be complete.
14 //
15 // Therefore, the content process shutdown does not wait for the
16 // completion but sets window.closed and calls the unload listeners
17 // while actually still holding onto some resources.
18 //
19 // Since in this test we mainly want to ensure that a file
20 // does not remain locked indefinitely, we wait for a reasonable amount
21 // of time before creating a new writable, corresponding roughly to
22 // a 500ms closing delay.
23 const timeoutMs = 400;
24 setTimeout(() => {
25 resolve(win);
26 }, timeoutMs);
27 };
28 });
29 }
30
31 const firstTabName = "support/fs-open_writable_then_close_tab.sub.html";
32 const firstTab = await firstReady(window.open(firstTabName));
33 assert_true(firstTab.closed, "Is the first tab already closed?");
34
35 function secondReady(win) {
36 return new Promise(resolve => {
37 bc.onmessage = e => {
38 if (e.data === "Second window ready!") {
39 resolve(win);
40 }
41 };
42 });
43 }
44
45 const secondTabName = "support/fs-open_writable_after_trigger.sub.html";
46 const secondTab = await secondReady(window.open(secondTabName));
47
48 let isDone = false;
49 let childStatus = "Success";
50
51 const secondSucceeded = new Promise(resolve => {
52 bc.onmessage = e => {
53 isDone = true;
54 if (e.data !== "Success") {
55 childStatus = e.data;
56 }
57
58 resolve();
59 };
60 });
61
62 bc.postMessage("Create writable in the second window");
63
64 await secondSucceeded;
65 assert_true(isDone, "Did the second tab respond?");
66
67 await fetch_tests_from_window(secondTab);
68
69 assert_equals(childStatus, "Success");
70 }, `writable available for other tabs after one tab is closed`);