test_beacon.html (1445B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=936340 5 --> 6 <head> 7 <title>Test whether sendBeacon fails for non-HTTP URIs and syntactically incorrect calls</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 10 </head> 11 <body> 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=936340">Mozilla Bug 936340</a> 13 <p id="display"></p> 14 15 <div id="content"> 16 </div> 17 <pre id="test"> 18 <script class="testbody" type="text/javascript"> 19 20 SimpleTest.waitForExplicitFinish(); 21 SpecialPowers.pushPrefEnv({'set': [["beacon.enabled", true]]}, beginTest); 22 23 function beginTest() { 24 var threw; 25 for(let scheme of ["bad", "ftp", "data"]) { 26 try { 27 is(false, navigator.sendBeacon(`${scheme}://example.com`, "0")); 28 threw = false; 29 } catch (ex) { 30 threw = true; 31 } 32 ok(threw, `sendBeacon not supported for ${scheme} scheme.`); 33 } 34 35 for(let scheme of ["http", "https"]) { 36 try { 37 is(false, navigator.sendBeacon(`${scheme}://invalid:URL`, "0")); 38 threw = false; 39 } catch (ex) { 40 threw = true; 41 } 42 ok(threw, `sendBeacon not supported for invalid ${scheme} URLs.`); 43 } 44 45 try { 46 is(false, navigator.sendBeacon()); 47 threw = false; 48 } catch (e) { 49 threw = true; 50 } 51 ok(threw, "sendBeacon needs more parameters."); 52 53 SimpleTest.finish() 54 } 55 56 </script> 57 </pre> 58 </body> 59 </html>