1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
'use strict';
// This script depends on the following scripts:
// /fs/resources/messaging-helpers.js
// /service-worker/resources/test-helpers.sub.js
promise_test(async t => {
function dummyCallback(records, observer) {};
let success = true;
try {
const observer = new FileSystemObserver(dummyCallback);
} catch (error) {
success = false;
}
assert_true(success);
}, 'Creating a FileSystemObserver from a window succeeds');
promise_test(async t => {
const dedicated_worker =
create_dedicated_worker(t, kDedicatedWorkerMessageTarget);
dedicated_worker.postMessage({type: 'create-file-system-observer'});
const event_watcher = new EventWatcher(t, dedicated_worker, 'message');
const message_event = await event_watcher.wait_for('message');
const response = message_event.data;
assert_true(response.createObserverSuccess);
}, 'Creating a FileSystemObserver from a dedicated worker succeeds');
if (self.SharedWorker !== undefined) {
promise_test(async t => {
const shared_worker = new SharedWorker(kSharedWorkerMessageTarget);
shared_worker.port.start();
shared_worker.port.postMessage({type: 'create-file-system-observer'});
const event_watcher = new EventWatcher(t, shared_worker.port, 'message');
const message_event = await event_watcher.wait_for('message');
const response = message_event.data;
assert_true(response.createObserverSuccess);
}, 'Creating a FileSystemObserver from a shared worker succeeds');
}
promise_test(async t => {
const scope = `${kServiceWorkerMessageTarget}?create-observer`;
const registration =
await create_service_worker(t, kServiceWorkerMessageTarget, scope);
await wait_for_state(t, registration.installing, 'activated');
registration.active.postMessage({type: 'create-file-system-observer'});
const event_watcher = new EventWatcher(t, navigator.serviceWorker, 'message');
const message_event = await event_watcher.wait_for('message');
const response = message_event.data;
assert_false(response.createObserverSuccess);
}, 'Creating a FileSystemObserver from a service worker fails');
|