test_navigator_share_consume_user_activation.html (1494B)
1 <!DOCTYPE html> 2 <title>Web Share: consume transient activation</title> 3 <script src="/tests/SimpleTest/SimpleTest.js"></script> 4 <script src="/tests/SimpleTest/EventUtils.js"></script> 5 <link rel="stylesheet" href="/tests/SimpleTest/test.css" /> 6 <body> 7 <button id="share">Share</button> 8 </body> 9 <script> 10 // TODO: add a task that tests share() consume the transient user activation. 11 // Because OS-level prompt can't be cancelled, it's currently not possible to 12 // test this. We need to add a Web share Mocking service: 13 // https://bugzilla.mozilla.org/show_bug.cgi?id=1646229 14 15 // test that share() would be blocked with an already-consumed-activation. 16 add_task(async function blockedIfAlreadyConsumed() { 17 const wrappedDoc = SpecialPowers.wrap(document); 18 const button = document.getElementById("share"); 19 20 // Kick off transient activation 21 synthesizeMouseAtCenter(button, {}); 22 23 ok( 24 wrappedDoc.hasValidTransientUserGestureActivation, 25 "Activated by a gesture" 26 ); 27 28 wrappedDoc.consumeTransientUserGestureActivation(); 29 30 try { 31 const sharePromise = navigator.share({ title: "test" }); 32 await sharePromise; 33 ok(false, "must throw because activation was already consumed"); 34 } catch (err) { 35 is(err.name, "NotAllowedError", "Expected NotAllowedError DOMException"); 36 } finally { 37 ok( 38 !wrappedDoc.hasValidTransientUserGestureActivation, 39 "share() must consume the activation" 40 ); 41 } 42 }); 43 </script>