test_wakelock_on_initial_about_blank.html (1727B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>Test requesting lock on the initial about:blank</title> 6 <link rel="help" href="https://bugzilla.mozilla.org/1882344"/> 7 <script src="/tests/SimpleTest/SimpleTest.js"></script> 8 <link rel="stylesheet" href="/tests/SimpleTest/test.css"/> 9 <script> 10 11 add_task(async function test() { 12 const iframe = document.createElement('iframe'); 13 iframe.src = "file_empty.html"; 14 document.documentElement.appendChild(iframe); 15 16 // https://html.spec.whatwg.org/multipage/nav-history-apis.html#the-window-object:initialise-the-document-object 17 is(iframe.contentWindow.location.href, "about:blank", "Initial about:blank is loaded"); 18 19 let lock; 20 try { 21 // request lock on initial about:blank 22 lock = await iframe.contentWindow.navigator.wakeLock.request(); 23 } catch (err) { 24 // This could happen if the initial about:blank document is inactive 25 // once the async code in .request runs. 26 ok(true, "request was rejected"); 27 return; 28 } 29 30 if (iframe.contentWindow.location.href == "about:blank") { 31 await new Promise((res, _rej) => { iframe.onload = res; }); 32 } 33 isnot(iframe.contentWindow.location.href, "about:blank", "Target document is loaded"); 34 35 is(lock.released, true, "lock was released by load of target doc"); 36 37 // window and wakeLock object stayed the same, but document changed 38 await iframe.contentWindow.navigator.wakeLock.request(); 39 ok(true, "Was able to request lock on target document"); 40 }); 41 42 </script> 43 </head> 44 <body> 45 <p id="display"></p> 46 <div id="content" style="display: none"></div> 47 <pre id="test"></pre> 48 </body> 49 </html>