1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/chrome/test/unit/test_bug564667.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,121 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.7 + */ 1.8 + 1.9 +const UNPACKAGED_ADDON = do_get_file("data/test_bug564667"); 1.10 +const PACKAGED_ADDON = do_get_file("data/test_bug564667.xpi"); 1.11 + 1.12 +var gIOS = Cc["@mozilla.org/network/io-service;1"]. 1.13 + getService(Ci.nsIIOService); 1.14 + 1.15 +var gCR = Cc["@mozilla.org/chrome/chrome-registry;1"]. 1.16 + getService(Ci.nsIChromeRegistry). 1.17 + QueryInterface(Ci.nsIXULOverlayProvider); 1.18 + 1.19 +/* 1.20 + * Checks that a mapping was added 1.21 + */ 1.22 +function test_mapping(chromeURL, target) { 1.23 + var uri = gIOS.newURI(chromeURL, null, null); 1.24 + 1.25 + try { 1.26 + var result = gCR.convertChromeURL(uri); 1.27 + do_check_eq(result.spec, target); 1.28 + } 1.29 + catch (ex) { 1.30 + do_throw(chromeURL + " not Registered"); 1.31 + } 1.32 +} 1.33 + 1.34 +/* 1.35 + * Checks that a mapping was removed 1.36 + */ 1.37 +function test_removed_mapping(chromeURL, target) { 1.38 + var uri = gIOS.newURI(chromeURL, null, null); 1.39 + try { 1.40 + var result = gCR.convertChromeURL(uri); 1.41 + do_throw(chromeURL + " not removed"); 1.42 + } 1.43 + catch (ex) { 1.44 + // This should throw 1.45 + } 1.46 +} 1.47 + 1.48 +/* 1.49 + * Checks if any overlay was added after loading 1.50 + * the manifest files 1.51 + * 1.52 + * @param type The type of overlay: overlay|style 1.53 + */ 1.54 +function test_no_overlays(chromeURL, target, type) { 1.55 + var type = type || "overlay"; 1.56 + var uri = gIOS.newURI(chromeURL, null, null); 1.57 + var present = false, elem; 1.58 + 1.59 + var overlays = (type == "overlay") ? 1.60 + gCR.getXULOverlays(uri) : gCR.getStyleOverlays(uri); 1.61 + 1.62 + // We shouldn't be allowed to register overlays nor styles 1.63 + if (overlays.hasMoreElements()) { 1.64 + if (type == "styles") 1.65 + do_throw("Style Registered: " + chromeURL); 1.66 + else 1.67 + do_throw("Overlay Registered: " + chromeURL); 1.68 + } 1.69 +} 1.70 + 1.71 +function testManifest(manifestPath, baseURI) { 1.72 + 1.73 + // ------------------ Add manifest file ------------------------ 1.74 + Components.manager.addBootstrappedManifestLocation(manifestPath); 1.75 + 1.76 + // Test Adding Content URL 1.77 + test_mapping("chrome://test1/content", baseURI + "test/test1.xul"); 1.78 + 1.79 + // Test Adding Locale URL 1.80 + test_mapping("chrome://test1/locale", baseURI + "test/test1.dtd"); 1.81 + 1.82 + // Test Adding Skin URL 1.83 + test_mapping("chrome://test1/skin", baseURI + "test/test1.css"); 1.84 + 1.85 + // Test Adding Manifest URL 1.86 + test_mapping("chrome://test2/content", baseURI + "test/test2.xul"); 1.87 + test_mapping("chrome://test2/locale", baseURI + "test/test2.dtd"); 1.88 + 1.89 + // Test Adding Override 1.90 + test_mapping("chrome://testOverride/content", 'file:///test1/override') 1.91 + 1.92 + // Test Not-Adding Overlays 1.93 + test_no_overlays("chrome://test1/content/overlay.xul", 1.94 + "chrome://test1/content/test1.xul"); 1.95 + 1.96 + // Test Not-Adding Styles 1.97 + test_no_overlays("chrome://test1/content/style.xul", 1.98 + "chrome://test1/content/test1.css", "styles"); 1.99 + 1.100 + 1.101 + // ------------------ Remove manifest file ------------------------ 1.102 + Components.manager.removeBootstrappedManifestLocation(manifestPath); 1.103 + 1.104 + // Test Removing Content URL 1.105 + test_removed_mapping("chrome://test1/content", baseURI + "test/test1.xul"); 1.106 + 1.107 + // Test Removing Content URL 1.108 + test_removed_mapping("chrome://test1/locale", baseURI + "test/test1.dtd"); 1.109 + 1.110 + // Test Removing Skin URL 1.111 + test_removed_mapping("chrome://test1/skin", baseURI + "test/test1.css"); 1.112 + 1.113 + // Test Removing Manifest URL 1.114 + test_removed_mapping("chrome://test2/content", baseURI + "test/test2.xul"); 1.115 + test_removed_mapping("chrome://test2/locale", baseURI + "test/test2.dtd"); 1.116 +} 1.117 + 1.118 +function run_test() { 1.119 + // Test an unpackaged addon 1.120 + testManifest(UNPACKAGED_ADDON, gIOS.newFileURI(UNPACKAGED_ADDON).spec); 1.121 + 1.122 + // Test a packaged addon 1.123 + testManifest(PACKAGED_ADDON, "jar:" + gIOS.newFileURI(PACKAGED_ADDON).spec + "!/"); 1.124 +}