Skip to content

Commit

Permalink
[FS] Move and rename getOriginPrivateDirectory to StorageManager.
Browse files Browse the repository at this point in the history
Renames self.getOriginPrivateDirector() to
navigator.storage.getDirectory(), following the changes in
WICG/file-system-access#217.

Change-Id: Ie993c24b56ffdf369bb87ed03eb786f458e50ad5
  • Loading branch information
mkruisselbrink authored and chromium-wpt-export-bot committed Aug 18, 2020
1 parent 78c808d commit 7e017d5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
8 changes: 4 additions & 4 deletions native-file-system/opaque-origin.https.window.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async function verify_does_not_exist_in_data_uri_iframe(

// |kSandboxWindowUrl| sends two messages to this window. The first is the
// result of showDirectoryPicker(). The second is the result of
// getOriginPrivateDirectory(). For windows using sandbox='allow-scripts',
// navigator.storage.getDirectory(). For windows using sandbox='allow-scripts',
// both results must produce rejected promises.
async function verify_results_from_sandboxed_child_window(test) {
const event_watcher = new EventWatcher(test, self, 'message');
Expand All @@ -50,7 +50,7 @@ async function verify_results_from_sandboxed_child_window(test) {

const second_message_event = await event_watcher.wait_for('message');
assert_equals(second_message_event.data,
'getOriginPrivateDirectory(): REJECTED: SecurityError');
'navigator.storage.getDirectory(): REJECTED: SecurityError');
}

promise_test(async test => {
Expand All @@ -67,7 +67,7 @@ promise_test(
add_iframe(test, kSandboxWindowUrl, /*sandbox=*/ 'allow-scripts');
await verify_results_from_sandboxed_child_window(test);
},
'getOriginPrivateDirectory() and ' +
'navigator.storage.getDirectory() and ' +
'showDirectoryPicker() must reject in a sandboxed iframe.');

promise_test(
Expand All @@ -82,5 +82,5 @@ promise_test(

await verify_results_from_sandboxed_child_window(test);
},
'getOriginPrivateDirectory() and ' +
'navigator.storage.getDirectory() and ' +
'showDirectoryPicker() must reject in a sandboxed opened window.');
6 changes: 2 additions & 4 deletions native-file-system/resources/message-target.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ function add_message_event_handlers(receiver, target, target_origin) {

case 'create-file':
// Create a new file and then respond to the sender with it.
const directory =
await self.getOriginPrivateDirectory();
const directory = await navigator.storage.getDirectory();
const file_handle =
await directory.getFileHandle('temp-file', { create: true });
message_source.postMessage(
Expand All @@ -95,8 +94,7 @@ function add_message_event_handlers(receiver, target, target_origin) {

case 'create-directory':
// Create a new directory and then respond to the sender with it.
const parent_directory =
await self.getOriginPrivateDirectory();
const parent_directory = await navigator.storage.getDirectory();
const directory_handle =
await parent_directory.getDirectoryHandle('temp-directory',
{ create: true });
Expand Down
10 changes: 5 additions & 5 deletions native-file-system/resources/opaque-origin-sandbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// Sends two messages to its creator:
// (1) The result of showDirectoryPicker().
// (2) The result of getOriginPrivateDirectory().
// (2) The result of navigator.storage.getDirectory().

function post_message(data) {
if (window.parent !== null) {
Expand All @@ -27,13 +27,13 @@
}

try {
window.getOriginPrivateDirectory()
navigator.storage.getDirectory()
.then(() => {
post_message('getOriginPrivateDirectory(): FULFILLED');
post_message('navigator.storage.getDirectory(): FULFILLED');
}).catch(error => {
post_message(`getOriginPrivateDirectory(): REJECTED: ${error.name}`);
post_message(`navigator.storage.getDirectory(): REJECTED: ${error.name}`);
});
} catch (error) {
post_message(`getOriginPrivateDirectory(): EXCEPTION: ${error.name}`);
post_message(`navigator.storage.getDirectory(): EXCEPTION: ${error.name}`);
}
</script>
6 changes: 2 additions & 4 deletions native-file-system/resources/sandboxed-fs-test-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
// where that version uses the native file system instead.

async function cleanupSandboxedFileSystem() {
const dir =
await self.getOriginPrivateDirectory();
const dir = await navigator.storage.getDirectory();
for await (let entry of dir.values())
await dir.removeEntry(entry.name, {recursive: entry.kind === 'directory'});
}
Expand All @@ -18,8 +17,7 @@ function directory_test(func, description) {
// To be extra resilient against bad tests, cleanup before every test.
await cleanupSandboxedFileSystem();

const dir =
await self.getOriginPrivateDirectory();
const dir = await navigator.storage.getDirectory();
await func(t, dir);
}, description);
}

0 comments on commit 7e017d5

Please sign in to comment.