tor-browser

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

test_bug1277803.xhtml (2528B)


      1 <?xml version="1.0"?>
      2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
      3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
      4 
      5 <window title="Bug 1277803 test"
      6        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
      7        width="600"
      8        height="600"
      9        onload="runTest();">
     10 
     11  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
     12 
     13  <body xmlns="http://www.w3.org/1999/xhtml">
     14  </body>
     15 
     16  <script type="application/javascript"><![CDATA[
     17    SimpleTest.requestCompleteLog();
     18 
     19    const BASE_URI = "http://mochi.test:8888/chrome/dom/security/test/general/";
     20    const FAVICON_URI = BASE_URI + "favicon_bug1277803.ico";
     21    const LOADING_URI = BASE_URI + "bug1277803.html";
     22    let testWindow; //will be used to trigger favicon load
     23 
     24    let expectedPrincipal = Services.scriptSecurityManager
     25        .createContentPrincipal(Services.io.newURI(LOADING_URI), {});
     26    let systemPrincipal = Services.scriptSecurityManager.getSystemPrincipal();
     27 
     28    function runTest() {
     29      // Register our observer to intercept favicon requests.
     30      function observer(aSubject, aTopic) {
     31        // Make sure this is a favicon request.
     32        let httpChannel = aSubject.QueryInterface(Ci.nsIHttpChannel);
     33        if (FAVICON_URI != httpChannel.URI.spec) {
     34          return;
     35        }
     36 
     37        // Ensure the topic is the one we set an observer for.
     38        is(aTopic, "http-on-modify-request", "Expected observer topic");
     39 
     40        // Check for the correct loadingPrincipal, triggeringPrincipal.
     41        let triggeringPrincipal = httpChannel.loadInfo.triggeringPrincipal;
     42        let loadingPrincipal = httpChannel.loadInfo.loadingPrincipal;
     43 
     44        ok(loadingPrincipal.equals(expectedPrincipal), "Should be loading with the expected principal.");
     45        ok(triggeringPrincipal.equals(expectedPrincipal), "Should be triggered with the expected principal.");
     46 
     47        Services.obs.removeObserver(this, "http-on-modify-request");
     48        SimpleTest.finish();
     49      }
     50      Services.obs.addObserver(observer, "http-on-modify-request");
     51 
     52      // Now that the observer is set up, trigger a favicon load with navigation
     53      testWindow = window.open(LOADING_URI);
     54    }
     55 
     56    SimpleTest.waitForExplicitFinish();
     57    SimpleTest.registerCleanupFunction(function() {
     58      if (testWindow) {
     59        testWindow.close();
     60      }
     61    });
     62  ]]></script>
     63 
     64  <browser type="content" primary="true" flex="1" id="content" src="about:blank"/>
     65 </window>