tor-browser

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

test_xslt.html (3195B)


      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 1182113 - Test service worker XSLT interception</title>
      9  <script src="/tests/SimpleTest/SimpleTest.js"></script>
     10  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     11 </head>
     12 <body>
     13 <p id="display"></p>
     14 <div id="content"></div>
     15 <pre id="test"></pre>
     16 <script src="utils.js"></script>
     17 <script class="testbody" type="text/javascript">
     18  var registration;
     19  var worker;
     20 
     21  function start() {
     22    return navigator.serviceWorker.register("xslt_worker.js",
     23                                            { scope: "./" })
     24      .then((swr) => {
     25        registration = swr;
     26 
     27        // Ensure the registration is active before continuing
     28        return waitForState(swr.installing, 'activated');
     29      });
     30  }
     31 
     32  function unregister() {
     33    return registration.unregister().then(function(result) {
     34      ok(result, "Unregister should return true.");
     35    }, function(e) {
     36      dump("Unregistering the SW failed with " + e + "\n");
     37    });
     38  }
     39 
     40  function getXmlString(xmlObject) {
     41    serializer = new XMLSerializer();
     42    return serializer.serializeToString(iframe.contentDocument);
     43  }
     44 
     45  function synthetic() {
     46    content = document.getElementById("content");
     47    ok(content, "parent exists.");
     48 
     49    iframe = document.createElement("iframe");
     50    content.appendChild(iframe);
     51 
     52    iframe.setAttribute('src', "xslt/test.xml");
     53 
     54    var p = new Promise(function(res, rej) {
     55      iframe.onload = function(e) {
     56        dump("Set request mode\n");
     57        registration.active.postMessage("synthetic");
     58        xmlString = getXmlString(iframe.contentDocument);
     59        ok(!xmlString.includes("Error"), "Load synthetic cross origin XSLT should be allowed");
     60        res();
     61      };
     62    });
     63 
     64    return p;
     65  }
     66 
     67  function cors() {
     68    var p = new Promise(function(res, rej) {
     69      iframe.onload = function(e) {
     70        xmlString = getXmlString(iframe.contentDocument);
     71        ok(!xmlString.includes("Error"), "Load CORS cross origin XSLT should be allowed");
     72        res();
     73      };
     74    });
     75 
     76    registration.active.postMessage("cors");
     77    iframe.setAttribute('src', "xslt/test.xml");
     78 
     79    return p;
     80  }
     81 
     82  function opaque() {
     83    var p = new Promise(function(res, rej) {
     84      iframe.onload = function(e) {
     85        xmlString = getXmlString(iframe.contentDocument);
     86        ok(xmlString.includes("Error"), "Load opaque cross origin XSLT should not be allowed");
     87        res();
     88      };
     89    });
     90 
     91    registration.active.postMessage("opaque");
     92    iframe.setAttribute('src', "xslt/test.xml");
     93 
     94    return p;
     95  }
     96 
     97  function runTest() {
     98     start()
     99      .then(synthetic)
    100      .then(opaque)
    101      .then(cors)
    102      .then(unregister)
    103      .catch(function(e) {
    104        ok(false, "Some test failed with error " + e);
    105      }).then(SimpleTest.finish);
    106  }
    107 
    108  SimpleTest.waitForExplicitFinish();
    109  SpecialPowers.pushPrefEnv({"set": [
    110    ["dom.serviceWorkers.exemptFromPerDomainMax", true],
    111    ["dom.serviceWorkers.enabled", true],
    112    ["dom.serviceWorkers.testing.enabled", true],
    113  ]}, runTest);
    114 </script>
    115 </pre>
    116 </body>
    117 </html>