Bug 1770047 [wpt PR 34117] - [Clipboard API] Clipboard Web Custom Formats implementat...
[gecko.git] / testing / web-platform / tests / web-share / test-fully-active.https.html
blob46991d3370f6f55b4ca59dc8cd3bd14bf628e9a2
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset="utf-8" />
5 <title>WebShare Test: consume user activation</title>
6 <link rel="help" href="https://github.com/w3c/web-share/pull/219" />
7 <script src="/resources/testharness.js"></script>
8 <script src="/resources/testharnessreport.js"></script>
9 <script src="/resources/testdriver.js"></script>
10 <script src="/resources/testdriver-vendor.js"></script>
11 </head>
12 <body>
13 <script>
14 async function loadIframe() {
15 const iframe = document.createElement("iframe");
16 iframe.src = "./resources/blank.html";
17 document.body.appendChild(iframe);
18 await new Promise((resolve) => {
19 iframe.addEventListener("load", resolve);
20 });
21 return iframe;
24 promise_test(async (t) => {
25 const iframe = await loadIframe();
26 const { contentWindow } = iframe;
27 const { navigator, DOMException } = contentWindow;
28 const data = { text: "text" };
29 iframe.remove();
30 await promise_rejects_dom(
32 "InvalidStateError",
33 DOMException,
34 navigator.share(data),
35 "Expected promise rejected with InvalidStateError from .share()"
37 }, "calling share() on non-fully active document returns a promise rejected with InvalidStateError");
39 promise_test(async (t) => {
40 const iframe = await loadIframe();
41 const { contentWindow } = iframe;
42 const { navigator, DOMException } = contentWindow;
43 const data = { text: "text" };
45 // Acquire transient activation, but make the iframe non-fully-active
46 await test_driver.bless(
47 "web share",
48 () => {
49 iframe.remove();
51 contentWindow
54 await promise_rejects_dom(
56 "InvalidStateError",
57 DOMException,
58 navigator.share(data),
59 "Expected promise rejected with InvalidStateError from .share()"
61 }, "calling share() with transient activation on non-fully active document returns a promise rejected with InvalidStateError");
63 promise_test(async (t) => {
64 const iframe = await loadIframe();
65 const { contentWindow } = iframe;
66 const { navigator } = contentWindow;
67 const data = { text: "text" };
69 assert_true(navigator.canShare(data), "doc is fully active, so true");
71 iframe.remove();
73 assert_false(navigator.canShare(data), "not fully active, so false");
74 }, "calling canShare() on a non-fully active document returns false");
75 </script>
76 </body>
77 </html>