tor-browser

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

test_crash_with_content_policy.html (2264B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Crashtests for style system with content policy</title>
      5  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
      7 </head>
      8 <body>
      9 <iframe id="iframe"></iframe>
     10 <script>
     11 const TESTS = [
     12  "file_bug1381233.html",
     13 ];
     14 
     15 const Cc = SpecialPowers.Cc;
     16 const Ci = SpecialPowers.Ci;
     17 
     18 var policyID = SpecialPowers.wrap(SpecialPowers.Components).ID("{b80e19d0-878f-d41b-2654-194714a4115c}");
     19 var policyName = "@mozilla.org/testpolicy;1";
     20 var policy = {
     21  // nsISupports implementation
     22  QueryInterface: function(iid) {
     23 
     24    iid = SpecialPowers.wrap(iid);
     25    if (iid.equals(Ci.nsISupports) ||
     26        iid.equals(Ci.nsIFactory) ||
     27        iid.equals(Ci.nsIContentPolicy))
     28      return this;
     29 
     30    throw SpecialPowers.Cr.NS_ERROR_NO_INTERFACE;
     31  },
     32 
     33  // nsIFactory implementation
     34  createInstance: function(outer, iid) {
     35    return this.QueryInterface(iid);
     36  },
     37 
     38  // nsIContentPolicy implementation
     39  shouldLoad: function(contentLocation, loadInfo) {
     40    info(`shouldLoad is invoked for ${SpecialPowers.wrap(contentLocation).spec}`);
     41    return Ci.nsIContentPolicy.ACCEPT;
     42  },
     43  shouldProcess: function(contentLocation, loadInfo) {
     44    return Ci.nsIContentPolicy.ACCEPT;
     45  }
     46 }
     47 policy = SpecialPowers.wrapCallbackObject(policy);
     48 
     49 // Register content policy
     50 var componentManager = SpecialPowers.wrap(SpecialPowers.Components).manager
     51                                    .QueryInterface(Ci.nsIComponentRegistrar);
     52 componentManager.registerFactory(policyID, "Test content policy", policyName, policy);
     53 var categoryManager = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
     54 categoryManager.addCategoryEntry("content-policy", policyName, policyName, false, true);
     55 
     56 
     57 SimpleTest.waitForExplicitFinish();
     58 
     59 async function runTests() {
     60  let iframe = document.getElementById("iframe");
     61  for (let test of TESTS) {
     62    iframe.src = test;
     63    await new Promise(resolve => {
     64      iframe.onload = resolve;
     65    });
     66    ok(true, `${test} doesn't crash`);
     67  }
     68  categoryManager.deleteCategoryEntry("content-policy", policyName, false);
     69  componentManager.unregisterFactory(policyID, policy);
     70  SimpleTest.finish();
     71 }
     72 runTests();
     73 </script>
     74 </body>
     75 </html>