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.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
michael@0 4 */
michael@0 5
michael@0 6 const UNPACKAGED_ADDON = do_get_file("data/test_bug564667");
michael@0 7 const PACKAGED_ADDON = do_get_file("data/test_bug564667.xpi");
michael@0 8
michael@0 9 var gIOS = Cc["@mozilla.org/network/io-service;1"].
michael@0 10 getService(Ci.nsIIOService);
michael@0 11
michael@0 12 var gCR = Cc["@mozilla.org/chrome/chrome-registry;1"].
michael@0 13 getService(Ci.nsIChromeRegistry).
michael@0 14 QueryInterface(Ci.nsIXULOverlayProvider);
michael@0 15
michael@0 16 /*
michael@0 17 * Checks that a mapping was added
michael@0 18 */
michael@0 19 function test_mapping(chromeURL, target) {
michael@0 20 var uri = gIOS.newURI(chromeURL, null, null);
michael@0 21
michael@0 22 try {
michael@0 23 var result = gCR.convertChromeURL(uri);
michael@0 24 do_check_eq(result.spec, target);
michael@0 25 }
michael@0 26 catch (ex) {
michael@0 27 do_throw(chromeURL + " not Registered");
michael@0 28 }
michael@0 29 }
michael@0 30
michael@0 31 /*
michael@0 32 * Checks that a mapping was removed
michael@0 33 */
michael@0 34 function test_removed_mapping(chromeURL, target) {
michael@0 35 var uri = gIOS.newURI(chromeURL, null, null);
michael@0 36 try {
michael@0 37 var result = gCR.convertChromeURL(uri);
michael@0 38 do_throw(chromeURL + " not removed");
michael@0 39 }
michael@0 40 catch (ex) {
michael@0 41 // This should throw
michael@0 42 }
michael@0 43 }
michael@0 44
michael@0 45 /*
michael@0 46 * Checks if any overlay was added after loading
michael@0 47 * the manifest files
michael@0 48 *
michael@0 49 * @param type The type of overlay: overlay|style
michael@0 50 */
michael@0 51 function test_no_overlays(chromeURL, target, type) {
michael@0 52 var type = type || "overlay";
michael@0 53 var uri = gIOS.newURI(chromeURL, null, null);
michael@0 54 var present = false, elem;
michael@0 55
michael@0 56 var overlays = (type == "overlay") ?
michael@0 57 gCR.getXULOverlays(uri) : gCR.getStyleOverlays(uri);
michael@0 58
michael@0 59 // We shouldn't be allowed to register overlays nor styles
michael@0 60 if (overlays.hasMoreElements()) {
michael@0 61 if (type == "styles")
michael@0 62 do_throw("Style Registered: " + chromeURL);
michael@0 63 else
michael@0 64 do_throw("Overlay Registered: " + chromeURL);
michael@0 65 }
michael@0 66 }
michael@0 67
michael@0 68 function testManifest(manifestPath, baseURI) {
michael@0 69
michael@0 70 // ------------------ Add manifest file ------------------------
michael@0 71 Components.manager.addBootstrappedManifestLocation(manifestPath);
michael@0 72
michael@0 73 // Test Adding Content URL
michael@0 74 test_mapping("chrome://test1/content", baseURI + "test/test1.xul");
michael@0 75
michael@0 76 // Test Adding Locale URL
michael@0 77 test_mapping("chrome://test1/locale", baseURI + "test/test1.dtd");
michael@0 78
michael@0 79 // Test Adding Skin URL
michael@0 80 test_mapping("chrome://test1/skin", baseURI + "test/test1.css");
michael@0 81
michael@0 82 // Test Adding Manifest URL
michael@0 83 test_mapping("chrome://test2/content", baseURI + "test/test2.xul");
michael@0 84 test_mapping("chrome://test2/locale", baseURI + "test/test2.dtd");
michael@0 85
michael@0 86 // Test Adding Override
michael@0 87 test_mapping("chrome://testOverride/content", 'file:///test1/override')
michael@0 88
michael@0 89 // Test Not-Adding Overlays
michael@0 90 test_no_overlays("chrome://test1/content/overlay.xul",
michael@0 91 "chrome://test1/content/test1.xul");
michael@0 92
michael@0 93 // Test Not-Adding Styles
michael@0 94 test_no_overlays("chrome://test1/content/style.xul",
michael@0 95 "chrome://test1/content/test1.css", "styles");
michael@0 96
michael@0 97
michael@0 98 // ------------------ Remove manifest file ------------------------
michael@0 99 Components.manager.removeBootstrappedManifestLocation(manifestPath);
michael@0 100
michael@0 101 // Test Removing Content URL
michael@0 102 test_removed_mapping("chrome://test1/content", baseURI + "test/test1.xul");
michael@0 103
michael@0 104 // Test Removing Content URL
michael@0 105 test_removed_mapping("chrome://test1/locale", baseURI + "test/test1.dtd");
michael@0 106
michael@0 107 // Test Removing Skin URL
michael@0 108 test_removed_mapping("chrome://test1/skin", baseURI + "test/test1.css");
michael@0 109
michael@0 110 // Test Removing Manifest URL
michael@0 111 test_removed_mapping("chrome://test2/content", baseURI + "test/test2.xul");
michael@0 112 test_removed_mapping("chrome://test2/locale", baseURI + "test/test2.dtd");
michael@0 113 }
michael@0 114
michael@0 115 function run_test() {
michael@0 116 // Test an unpackaged addon
michael@0 117 testManifest(UNPACKAGED_ADDON, gIOS.newFileURI(UNPACKAGED_ADDON).spec);
michael@0 118
michael@0 119 // Test a packaged addon
michael@0 120 testManifest(PACKAGED_ADDON, "jar:" + gIOS.newFileURI(PACKAGED_ADDON).spec + "!/");
michael@0 121 }

mercurial