tor-browser

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

test_bug498897.html (2798B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=498897
      5 -->
      6 <head>
      7  <title>Test for Bug 498897</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=498897">Mozilla Bug 498897</a>
     13 <p id="display"><iframe id="testframe"></iframe></p>
     14 <div id="content" style="display: none">
     15  
     16 </div>
     17 <pre id="test">
     18 <script type="application/javascript">
     19 
     20 /** Test for Bug 498897 */
     21 
     22 var checkedLoad = false;
     23 
     24 const Cc = SpecialPowers.Cc;
     25 const Ci = SpecialPowers.Ci;
     26 
     27 // Content policy / factory implementation for the test
     28 var policyID = SpecialPowers.wrap(SpecialPowers.Components).ID("{65944d64-2390-422e-bea3-80d0af7f69ef}");
     29 var policyName = "@mozilla.org/498897_testpolicy;1";
     30 var policy = {
     31  // nsISupports implementation
     32  QueryInterface(iid) {
     33    if (iid.equals(Ci.nsISupports) ||
     34        iid.equals(Ci.nsIFactory) ||
     35        iid.equals(Ci.nsIContentPolicy))
     36      return this;
     37 
     38    throw SpecialPowers.Cr.NS_ERROR_NO_INTERFACE;
     39  },
     40 
     41  // nsIFactory implementation
     42  createInstance(iid) {
     43    return this.QueryInterface(iid);
     44  },
     45 
     46  // nsIContentPolicy implementation
     47  shouldLoad(contentLocation, loadInfo) {
     48    var url = window.location.href.substr(0, window.location.href.indexOf('test_bug498897'));
     49    let loadingPrincipal = loadInfo.loadingPrincipal;
     50    if (loadingPrincipal) {
     51      requestOrigin = loadingPrincipal.spec;
     52    }
     53    if (contentLocation.spec == url + "file_bug498897.css" &&
     54        requestOrigin == url + "file_bug498897.html") {
     55      checkedLoad = true;
     56    }
     57 
     58    return Ci.nsIContentPolicy.ACCEPT;
     59  },
     60 
     61  shouldProcess(contentLocation, loadInfo) {
     62    return Ci.nsIContentPolicy.ACCEPT;
     63  }
     64 }
     65 policy = SpecialPowers.wrapCallbackObject(policy);
     66 
     67 var componentManager = SpecialPowers.wrap(SpecialPowers.Components).manager
     68                                 .QueryInterface(Ci.nsIComponentRegistrar);
     69 componentManager.registerFactory(policyID, "Test content policy for bug 498897",
     70                                 policyName, policy);
     71 
     72 var categoryManager =
     73  Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
     74 categoryManager.addCategoryEntry("content-policy", policyName, policyName,
     75                                 false, true);
     76 
     77 function testFinished()
     78 {
     79  ok(checkedLoad, "Content policy didn't get called!");
     80 
     81  categoryManager.deleteCategoryEntry("content-policy", policyName, false);
     82 
     83  setTimeout(function() {
     84    componentManager.unregisterFactory(policyID, policy);
     85 
     86    SimpleTest.finish();
     87  }, 0);
     88 }
     89 
     90 SimpleTest.waitForExplicitFinish();
     91 
     92 document.getElementById("testframe").src = "file_bug498897.html";
     93 
     94 </script>
     95 </pre>
     96 </body>
     97 </html>