chrome/test/unit/test_bug397073.js

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
     4  */
     6 var MANIFESTS = [
     7   do_get_file("data/test_bug397073.manifest")
     8 ];
    11 registerManifests(MANIFESTS);
    13 var XULAppInfo = {
    14   vendor: "Mozilla",
    15   name: "XPCShell",
    16   ID: "{39885e5f-f6b4-4e2a-87e5-6259ecf79011}",
    17   version: "5",
    18   appBuildID: "2007010101",
    19   platformVersion: "1.9",
    20   platformBuildID: "2007010101",
    21   inSafeMode: false,
    22   logConsoleErrors: true,
    23   OS: "XPCShell",
    24   XPCOMABI: "noarch-spidermonkey",
    26   QueryInterface: function QueryInterface(iid) {
    27     if (iid.equals(Ci.nsIXULAppInfo)
    28      || iid.equals(Ci.nsIXULRuntime)
    29      || iid.equals(Ci.nsISupports))
    30       return this;
    32     throw Components.results.NS_ERROR_NO_INTERFACE;
    33   }
    34 };
    36 var XULAppInfoFactory = {
    37   createInstance: function (outer, iid) {
    38     if (outer != null)
    39       throw Components.results.NS_ERROR_NO_AGGREGATION;
    40     return XULAppInfo.QueryInterface(iid);
    41   }
    42 };
    43 var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
    44 registrar.registerFactory(XULAPPINFO_CID, "XULAppInfo",
    45                           XULAPPINFO_CONTRACTID, XULAppInfoFactory);
    47 var gIOS = Cc["@mozilla.org/network/io-service;1"]
    48             .getService(Ci.nsIIOService);
    49 var chromeReg = Cc["@mozilla.org/chrome/chrome-registry;1"]
    50                  .getService(Ci.nsIChromeRegistry);
    51 chromeReg.checkForNewChrome();
    53 var target = gIOS.newFileURI(do_get_file("data"));
    54 target = target.spec + "test/test.xul";
    56 function test_succeeded_mapping(namespace)
    57 {
    58   var uri = gIOS.newURI("chrome://" + namespace + "/content/test.xul",
    59                         null, null);
    60   try {
    61     var result = chromeReg.convertChromeURL(uri);
    62     do_check_eq(result.spec, target);
    63   }
    64   catch (ex) {
    65     do_throw(namespace);
    66   }
    67 }
    69 function test_failed_mapping(namespace)
    70 {
    71   var uri = gIOS.newURI("chrome://" + namespace + "/content/test.xul",
    72                         null, null);
    73   try {
    74     var result = chromeReg.convertChromeURL(uri);
    75     do_throw(namespace);
    76   }
    77   catch (ex) {
    78   }
    79 }
    81 function run_test()
    82 {
    83   test_succeeded_mapping("test1");
    84   test_succeeded_mapping("test2");
    86   test_failed_mapping("test3");
    87 }

mercurial