chrome/test/unit/test_bug564667.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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 const UNPACKAGED_ADDON = do_get_file("data/test_bug564667");
     7 const PACKAGED_ADDON = do_get_file("data/test_bug564667.xpi");
     9 var gIOS = Cc["@mozilla.org/network/io-service;1"].
    10            getService(Ci.nsIIOService);
    12 var gCR = Cc["@mozilla.org/chrome/chrome-registry;1"].
    13           getService(Ci.nsIChromeRegistry).
    14           QueryInterface(Ci.nsIXULOverlayProvider);
    16 /*
    17  * Checks that a mapping was added
    18  */
    19 function test_mapping(chromeURL, target) {
    20   var uri = gIOS.newURI(chromeURL, null, null);
    22   try {
    23     var result = gCR.convertChromeURL(uri);
    24     do_check_eq(result.spec, target);
    25   }
    26   catch (ex) {
    27     do_throw(chromeURL + " not Registered");
    28   }
    29 }
    31 /*
    32  * Checks that a mapping was removed
    33  */
    34 function test_removed_mapping(chromeURL, target) {
    35   var uri = gIOS.newURI(chromeURL, null, null);
    36   try {
    37     var result = gCR.convertChromeURL(uri);
    38     do_throw(chromeURL + " not removed");
    39   }
    40   catch (ex) {
    41     // This should throw
    42   }
    43 }
    45 /*
    46  * Checks if any overlay was added after loading
    47  * the manifest files
    48  *
    49  * @param type The type of overlay: overlay|style
    50  */
    51 function test_no_overlays(chromeURL, target, type) {
    52   var type = type || "overlay";
    53   var uri = gIOS.newURI(chromeURL, null, null);
    54   var present = false, elem;
    56   var overlays = (type == "overlay") ?
    57       gCR.getXULOverlays(uri) : gCR.getStyleOverlays(uri);
    59   // We shouldn't be allowed to register overlays nor styles
    60   if (overlays.hasMoreElements()) {
    61     if (type == "styles")
    62       do_throw("Style Registered: " + chromeURL);
    63     else
    64       do_throw("Overlay Registered: " + chromeURL);
    65   }
    66 }
    68 function testManifest(manifestPath, baseURI) {
    70   // ------------------  Add manifest file ------------------------
    71   Components.manager.addBootstrappedManifestLocation(manifestPath);
    73   // Test Adding Content URL
    74   test_mapping("chrome://test1/content", baseURI + "test/test1.xul");
    76   // Test Adding Locale URL
    77   test_mapping("chrome://test1/locale", baseURI + "test/test1.dtd");
    79   // Test Adding Skin URL
    80   test_mapping("chrome://test1/skin", baseURI + "test/test1.css");
    82   // Test Adding Manifest URL
    83   test_mapping("chrome://test2/content", baseURI + "test/test2.xul");
    84   test_mapping("chrome://test2/locale", baseURI + "test/test2.dtd");
    86   // Test Adding Override
    87   test_mapping("chrome://testOverride/content", 'file:///test1/override')
    89   // Test Not-Adding Overlays
    90   test_no_overlays("chrome://test1/content/overlay.xul",
    91                    "chrome://test1/content/test1.xul");
    93   // Test Not-Adding Styles
    94   test_no_overlays("chrome://test1/content/style.xul",
    95                    "chrome://test1/content/test1.css", "styles");
    98   // ------------------  Remove manifest file ------------------------
    99   Components.manager.removeBootstrappedManifestLocation(manifestPath);
   101   // Test Removing Content URL
   102   test_removed_mapping("chrome://test1/content", baseURI + "test/test1.xul");
   104   // Test Removing Content URL
   105   test_removed_mapping("chrome://test1/locale", baseURI + "test/test1.dtd");
   107   // Test Removing Skin URL
   108   test_removed_mapping("chrome://test1/skin", baseURI + "test/test1.css");
   110   // Test Removing Manifest URL
   111   test_removed_mapping("chrome://test2/content", baseURI + "test/test2.xul");
   112   test_removed_mapping("chrome://test2/locale", baseURI + "test/test2.dtd");
   113 }
   115 function run_test() {
   116   // Test an unpackaged addon
   117   testManifest(UNPACKAGED_ADDON, gIOS.newFileURI(UNPACKAGED_ADDON).spec);
   119   // Test a packaged addon
   120   testManifest(PACKAGED_ADDON, "jar:" + gIOS.newFileURI(PACKAGED_ADDON).spec + "!/");
   121 }

mercurial