michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: */ michael@0: michael@0: const UNPACKAGED_ADDON = do_get_file("data/test_bug564667"); michael@0: const PACKAGED_ADDON = do_get_file("data/test_bug564667.xpi"); michael@0: michael@0: var gIOS = Cc["@mozilla.org/network/io-service;1"]. michael@0: getService(Ci.nsIIOService); michael@0: michael@0: var gCR = Cc["@mozilla.org/chrome/chrome-registry;1"]. michael@0: getService(Ci.nsIChromeRegistry). michael@0: QueryInterface(Ci.nsIXULOverlayProvider); michael@0: michael@0: /* michael@0: * Checks that a mapping was added michael@0: */ michael@0: function test_mapping(chromeURL, target) { michael@0: var uri = gIOS.newURI(chromeURL, null, null); michael@0: michael@0: try { michael@0: var result = gCR.convertChromeURL(uri); michael@0: do_check_eq(result.spec, target); michael@0: } michael@0: catch (ex) { michael@0: do_throw(chromeURL + " not Registered"); michael@0: } michael@0: } michael@0: michael@0: /* michael@0: * Checks that a mapping was removed michael@0: */ michael@0: function test_removed_mapping(chromeURL, target) { michael@0: var uri = gIOS.newURI(chromeURL, null, null); michael@0: try { michael@0: var result = gCR.convertChromeURL(uri); michael@0: do_throw(chromeURL + " not removed"); michael@0: } michael@0: catch (ex) { michael@0: // This should throw michael@0: } michael@0: } michael@0: michael@0: /* michael@0: * Checks if any overlay was added after loading michael@0: * the manifest files michael@0: * michael@0: * @param type The type of overlay: overlay|style michael@0: */ michael@0: function test_no_overlays(chromeURL, target, type) { michael@0: var type = type || "overlay"; michael@0: var uri = gIOS.newURI(chromeURL, null, null); michael@0: var present = false, elem; michael@0: michael@0: var overlays = (type == "overlay") ? michael@0: gCR.getXULOverlays(uri) : gCR.getStyleOverlays(uri); michael@0: michael@0: // We shouldn't be allowed to register overlays nor styles michael@0: if (overlays.hasMoreElements()) { michael@0: if (type == "styles") michael@0: do_throw("Style Registered: " + chromeURL); michael@0: else michael@0: do_throw("Overlay Registered: " + chromeURL); michael@0: } michael@0: } michael@0: michael@0: function testManifest(manifestPath, baseURI) { michael@0: michael@0: // ------------------ Add manifest file ------------------------ michael@0: Components.manager.addBootstrappedManifestLocation(manifestPath); michael@0: michael@0: // Test Adding Content URL michael@0: test_mapping("chrome://test1/content", baseURI + "test/test1.xul"); michael@0: michael@0: // Test Adding Locale URL michael@0: test_mapping("chrome://test1/locale", baseURI + "test/test1.dtd"); michael@0: michael@0: // Test Adding Skin URL michael@0: test_mapping("chrome://test1/skin", baseURI + "test/test1.css"); michael@0: michael@0: // Test Adding Manifest URL michael@0: test_mapping("chrome://test2/content", baseURI + "test/test2.xul"); michael@0: test_mapping("chrome://test2/locale", baseURI + "test/test2.dtd"); michael@0: michael@0: // Test Adding Override michael@0: test_mapping("chrome://testOverride/content", 'file:///test1/override') michael@0: michael@0: // Test Not-Adding Overlays michael@0: test_no_overlays("chrome://test1/content/overlay.xul", michael@0: "chrome://test1/content/test1.xul"); michael@0: michael@0: // Test Not-Adding Styles michael@0: test_no_overlays("chrome://test1/content/style.xul", michael@0: "chrome://test1/content/test1.css", "styles"); michael@0: michael@0: michael@0: // ------------------ Remove manifest file ------------------------ michael@0: Components.manager.removeBootstrappedManifestLocation(manifestPath); michael@0: michael@0: // Test Removing Content URL michael@0: test_removed_mapping("chrome://test1/content", baseURI + "test/test1.xul"); michael@0: michael@0: // Test Removing Content URL michael@0: test_removed_mapping("chrome://test1/locale", baseURI + "test/test1.dtd"); michael@0: michael@0: // Test Removing Skin URL michael@0: test_removed_mapping("chrome://test1/skin", baseURI + "test/test1.css"); michael@0: michael@0: // Test Removing Manifest URL michael@0: test_removed_mapping("chrome://test2/content", baseURI + "test/test2.xul"); michael@0: test_removed_mapping("chrome://test2/locale", baseURI + "test/test2.dtd"); michael@0: } michael@0: michael@0: function run_test() { michael@0: // Test an unpackaged addon michael@0: testManifest(UNPACKAGED_ADDON, gIOS.newFileURI(UNPACKAGED_ADDON).spec); michael@0: michael@0: // Test a packaged addon michael@0: testManifest(PACKAGED_ADDON, "jar:" + gIOS.newFileURI(PACKAGED_ADDON).spec + "!/"); michael@0: }