forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1758320 - Test file system access from multiple tabs. r=dom-stora…
…ge-reviewers,janv Differential Revision: https://phabricator.services.mozilla.com/D143740
- Loading branch information
1 parent
2d14bcc
commit e5c8aaa
Showing
6 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
leak-threshold: [default:51200] |
5 changes: 5 additions & 0 deletions
5
...ng/web-platform/mozilla/meta/dom/fs/fs-writable_unlocked_on_tab_close.https.window.js.ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[fs-writable_unlocked_on_tab_close.https.window.html] | ||
type: testharness | ||
prefs: | ||
[dom.storageManager.enabled:true, | ||
dom.fs.enabled:true] |
70 changes: 70 additions & 0 deletions
70
testing/web-platform/mozilla/tests/dom/fs/fs-writable_unlocked_on_tab_close.https.window.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// META: title=Origin private file system used from multiple tabs | ||
// META: script=support/testHelpers.js | ||
|
||
promise_test(async t => { | ||
const bc = new BroadcastChannel("Coordinate writables"); | ||
|
||
function firstReady(win) { | ||
return new Promise(resolve => { | ||
// Blur triggers after the unload event and after window.closed is set | ||
win.onblur = () => { | ||
// Closing the low-level file handle may get stuck, but the unlocking | ||
// request can only be sent to the parent after the handle is closed. | ||
// There is no guarantee when or if the closing will be complete. | ||
// | ||
// Therefore, the content process shutdown does not wait for the | ||
// completion but sets window.closed and calls the unload listeners | ||
// while actually still holding onto some resources. | ||
// | ||
// Since in this test we mainly want to ensure that a file | ||
// does not remain locked indefinitely, we wait for a reasonable amount | ||
// of time before creating a new writable, corresponding roughly to | ||
// a 500ms closing delay. | ||
const timeoutMs = 400; | ||
setTimeout(() => { | ||
resolve(win); | ||
}, timeoutMs); | ||
}; | ||
}); | ||
} | ||
|
||
const firstTabName = "support/fs-open_writable_then_close_tab.sub.html"; | ||
const firstTab = await firstReady(window.open(firstTabName)); | ||
assert_true(firstTab.closed, "Is the first tab already closed?"); | ||
|
||
function secondReady(win) { | ||
return new Promise(resolve => { | ||
bc.onmessage = e => { | ||
if (e.data === "Second window ready!") { | ||
resolve(win); | ||
} | ||
}; | ||
}); | ||
} | ||
|
||
const secondTabName = "support/fs-open_writable_after_trigger.sub.html"; | ||
const secondTab = await secondReady(window.open(secondTabName)); | ||
|
||
let isDone = false; | ||
let childStatus = "Success"; | ||
|
||
const secondSucceeded = new Promise(resolve => { | ||
bc.onmessage = e => { | ||
isDone = true; | ||
if (e.data !== "Success") { | ||
childStatus = e.data; | ||
} | ||
|
||
resolve(); | ||
}; | ||
}); | ||
|
||
bc.postMessage("Create writable in the second window"); | ||
|
||
await secondSucceeded; | ||
assert_true(isDone, "Did the second tab respond?"); | ||
|
||
await fetch_tests_from_window(secondTab); | ||
|
||
assert_equals(childStatus, "Success"); | ||
}, `writable available for other tabs after one tab is closed`); |
45 changes: 45 additions & 0 deletions
45
testing/web-platform/mozilla/tests/dom/fs/support/fs-open_writable_after_trigger.sub.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<title>Child context test(s)</title> | ||
<head> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="testHelpers.js"></script> | ||
</head> | ||
<body> | ||
<div id="log"></div> | ||
<script> | ||
const channel = new BroadcastChannel("Coordinate writables"); | ||
|
||
let triggered = false; | ||
|
||
channel.onmessage = e => { | ||
if ("Create writable in the second window" === e.data) { | ||
triggered = true; | ||
} | ||
}; | ||
|
||
channel.postMessage("Second window ready!"); | ||
|
||
promise_test(async t => { | ||
try { | ||
const maxWaitMs = 2000; | ||
await waitUntil(() => { return triggered; }, maxWaitMs); | ||
assert_true(triggered, "Did we receive a trigger?"); | ||
|
||
const dir = await navigator.storage.getDirectory(); | ||
const opts = { create: true }; | ||
const file = await dir.getFileHandle('funky-file-handle', opts); | ||
let writable = await file.createWritable({}); | ||
t.add_cleanup(async () => { await writable.close(); }); | ||
assert_true(!!writable, "Did we receive a writable?"); | ||
|
||
channel.postMessage("Success"); | ||
} catch(err) { | ||
channel.postMessage(err.message); | ||
|
||
throw err; | ||
} | ||
}); | ||
</script> | ||
</body> | ||
</html> |
20 changes: 20 additions & 0 deletions
20
testing/web-platform/mozilla/tests/dom/fs/support/fs-open_writable_then_close_tab.sub.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<title>Child context test(s)</title> | ||
<head> | ||
<script src="/resources/testharness.js"></script> | ||
</head> | ||
<body> | ||
<div id="log"></div> | ||
<script> | ||
window.addEventListener('load', async () => { | ||
const dir = await navigator.storage.getDirectory(); | ||
const opts = { create: true }; | ||
const file = await dir.getFileHandle('funky-file-handle', opts); | ||
const writable = await file.createWritable({}); | ||
|
||
window.close(); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
15 changes: 15 additions & 0 deletions
15
testing/web-platform/mozilla/tests/dom/fs/support/testHelpers.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
async function waitUntil(isWaitDone, untilMs, stepMs = 25) { | ||
const startMs = Date.now(); | ||
|
||
return new Promise((resolve, reject) => { | ||
const areWeDoneYet = setInterval(async function() { | ||
if (await isWaitDone()) { | ||
clearInterval(areWeDoneYet); | ||
resolve(); | ||
} else if (Date.now() > startMs + untilMs) { | ||
clearInterval(areWeDoneYet); | ||
reject(new Error("Timed out after " + untilMs + "ms")); | ||
} | ||
}, stepMs); | ||
}); | ||
} |