tor-browser

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

test_fileReaderSync_when_closing.html (1887B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <meta charset="utf-8">
      5  <title>Test for FileReaderSync when the worker is closing</title>
      6  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      7  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
      8 </head>
      9 <body>
     10  <script type="application/javascript">
     11 
     12 // In order to exercise FileReaderSync::SyncRead's syncLoop-using AsyncWait()
     13 // path, we need to provide a stream that will both 1) not have all the data
     14 // immediately available (eliminating memory-backed Blobs) and 2) return
     15 // NS_BASE_STREAM_WOULD_BLOCK.  Under e10s, any Blob/File sourced from the
     16 // parent process (as loadChromeScript performs) will be backed by an
     17 // RemoteLazyInputStream and will behave this way on first use (when it is in
     18 // the eInit state).  For ease of testing, we reuse script_createFile.js which
     19 // involves a file on disk, but a memory-backed Blob from the parent process
     20 // would be equally fine.  Under non-e10s, this File will not do the right
     21 // thing because a synchronous nsFileInputStream will be made directly
     22 // available and the AsyncWait path won't be taken, but the test will still
     23 // pass.
     24 
     25 var url = SimpleTest.getTestFileURL("script_createFile.js");
     26 var script = SpecialPowers.loadChromeScript(url);
     27 
     28 function onOpened(message) {
     29  function workerCode() {
     30    onmessage = function(e) {
     31      self.close();
     32      var fr = new FileReaderSync();
     33      self.postMessage(fr.readAsText(e.data));
     34    }
     35  }
     36 
     37  var b = new Blob([workerCode+'workerCode();']);
     38  var w = new Worker(URL.createObjectURL(b));
     39  w.onmessage = function(e) {
     40    is(e.data, "Hello world!", "The blob content is OK!");
     41    SimpleTest.finish();
     42  }
     43 
     44  w.postMessage(message.data);
     45 }
     46 
     47 script.addMessageListener("nonEmptyFile.opened", onOpened);
     48 script.sendAsyncMessage("nonEmptyFile.open");
     49 
     50 SimpleTest.waitForExplicitFinish();
     51 
     52  </script>
     53 </body>
     54 </html>