tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_dynamic_import.html (1444B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Test import() should throw a TypeError for Worklets</title>
      5  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
      7  <script type="application/javascript" src="common.js"></script>
      8 </head>
      9 <body>
     10 
     11 <script type="application/javascript">
     12 const WORKLET_SCRIPT = "dynamic_import.js";
     13 
     14 function configureTest() {
     15  const ConsoleAPIStorage = SpecialPowers.Cc[
     16    "@mozilla.org/consoleAPI-storage;1"
     17  ].getService(SpecialPowers.Ci.nsIConsoleAPIStorage);
     18 
     19  // We use console API to check if a TypeError has been thrown, as worklets
     20  // have limitations to post the result back to the main document:
     21  // Worklets have a different global, and they don't have postMessage() APIs,
     22  // and static import SimpleTest.js in worklets also don't work.
     23  function observe(aSubject) {
     24    var obj = aSubject.wrappedJSObject;
     25    info("Got console message:" + obj.arguments[0]);
     26    is(TypeError.name + ": Success", obj.arguments[0], "import() should throw");
     27 
     28    ConsoleAPIStorage.removeLogEventListener(observe);
     29    SimpleTest.finish();
     30  }
     31 
     32  ConsoleAPIStorage.addLogEventListener(observe, SpecialPowers.wrap(document).nodePrincipal);
     33 }
     34 
     35 // This function is called into an iframe.
     36 function runTestInIframe() {
     37  var audioContext = new AudioContext();
     38  audioContext.audioWorklet.addModule(WORKLET_SCRIPT);
     39 }
     40 
     41 </script>
     42 </body>
     43 </html>