summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/mozilla/tests/dom/fs/support/fs-open_writable_after_trigger.sub.html
blob: b64d97083f59294ed5dfc04e562c111d2e92f945 (plain)
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
<!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>