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>
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
);
24 promise_test(async (t
) => {
25 const iframe
= await
loadIframe();
26 const { contentWindow
} = iframe
;
27 const { navigator
, DOMException
} = contentWindow
;
28 const data
= { text
: "text" };
30 await
promise_rejects_dom(
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(
54 await
promise_rejects_dom(
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");
73 assert_false(navigator
.canShare(data
), "not fully active, so false");
74 }, "calling canShare() on a non-fully active document returns false");