match_all_controlled.html (2606B)
1 <!-- 2 Any copyright is dedicated to the Public Domain. 3 http://creativecommons.org/publicdomain/zero/1.0/ 4 --> 5 <!DOCTYPE HTML> 6 <html> 7 <head> 8 <title>Bug 1058311 - controlled page</title> 9 <script class="testbody" type="text/javascript"> 10 var re = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/; 11 var frameType = "none"; 12 var testWindow = parent; 13 14 if (parent != window) { 15 frameType = "nested"; 16 } else if (opener) { 17 frameType = "auxiliary"; 18 testWindow = opener; 19 } else if (parent == window) { 20 frameType = "top-level"; 21 } else { 22 postResult(false, "Unexpected frameType"); 23 } 24 25 window.onload = function() { 26 navigator.serviceWorker.ready.then(function(swr) { 27 // Send a message to our SW that will cause it to do clients.matchAll() 28 // and send a message *to each client about themselves* (rather than 29 // replying directly to us with all the clients it finds). 30 swr.active.postMessage("Start"); 31 }); 32 } 33 34 function postResult(result, msg) { 35 response = { 36 result, 37 message: msg 38 }; 39 40 testWindow.postMessage(response, "*"); 41 } 42 43 navigator.serviceWorker.onmessage = async function(msg) { 44 // ## Verify the contents of the SW's serialized rep of our client info. 45 // Clients are opaque identifiers at a spec level, but we want to verify 46 // that they are UUID's *without wrapping "{}" characters*. 47 result = re.test(msg.data.id); 48 postResult(result, "Client id test"); 49 50 result = msg.data.url == window.location; 51 postResult(result, "Client url test"); 52 53 result = msg.data.visibilityState === document.visibilityState; 54 postResult(result, "Client visibility test. expected=" +document.visibilityState); 55 56 result = msg.data.focused === document.hasFocus(); 57 postResult(result, "Client focus test. expected=" + document.hasFocus()); 58 59 result = msg.data.frameType === frameType; 60 postResult(result, "Client frameType test. expected=" + frameType); 61 62 result = msg.data.type === "window"; 63 postResult(result, "Client type test. expected=window"); 64 65 // ## Verify the FetchEvent.clientId 66 // In bug 1446225 it turned out we provided UUID's wrapped with {}'s. We 67 // now also get coverage by forcing our clients.get() to forbid UUIDs 68 // with that form. 69 70 const clientIdResp = await fetch('clientId'); 71 const fetchClientId = await clientIdResp.text(); 72 result = re.test(fetchClientId); 73 postResult(result, "Fetch clientId test"); 74 75 postResult(true, "DONE"); 76 window.close(); 77 }; 78 </script> 79 80 </head> 81 <body> 82 </body> 83 </html>