|
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 */ |
|
5 |
|
6 const UNPACKAGED_ADDON = do_get_file("data/test_bug564667"); |
|
7 const PACKAGED_ADDON = do_get_file("data/test_bug564667.xpi"); |
|
8 |
|
9 var gIOS = Cc["@mozilla.org/network/io-service;1"]. |
|
10 getService(Ci.nsIIOService); |
|
11 |
|
12 var gCR = Cc["@mozilla.org/chrome/chrome-registry;1"]. |
|
13 getService(Ci.nsIChromeRegistry). |
|
14 QueryInterface(Ci.nsIXULOverlayProvider); |
|
15 |
|
16 /* |
|
17 * Checks that a mapping was added |
|
18 */ |
|
19 function test_mapping(chromeURL, target) { |
|
20 var uri = gIOS.newURI(chromeURL, null, null); |
|
21 |
|
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 } |
|
30 |
|
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 } |
|
44 |
|
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; |
|
55 |
|
56 var overlays = (type == "overlay") ? |
|
57 gCR.getXULOverlays(uri) : gCR.getStyleOverlays(uri); |
|
58 |
|
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 } |
|
67 |
|
68 function testManifest(manifestPath, baseURI) { |
|
69 |
|
70 // ------------------ Add manifest file ------------------------ |
|
71 Components.manager.addBootstrappedManifestLocation(manifestPath); |
|
72 |
|
73 // Test Adding Content URL |
|
74 test_mapping("chrome://test1/content", baseURI + "test/test1.xul"); |
|
75 |
|
76 // Test Adding Locale URL |
|
77 test_mapping("chrome://test1/locale", baseURI + "test/test1.dtd"); |
|
78 |
|
79 // Test Adding Skin URL |
|
80 test_mapping("chrome://test1/skin", baseURI + "test/test1.css"); |
|
81 |
|
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"); |
|
85 |
|
86 // Test Adding Override |
|
87 test_mapping("chrome://testOverride/content", 'file:///test1/override') |
|
88 |
|
89 // Test Not-Adding Overlays |
|
90 test_no_overlays("chrome://test1/content/overlay.xul", |
|
91 "chrome://test1/content/test1.xul"); |
|
92 |
|
93 // Test Not-Adding Styles |
|
94 test_no_overlays("chrome://test1/content/style.xul", |
|
95 "chrome://test1/content/test1.css", "styles"); |
|
96 |
|
97 |
|
98 // ------------------ Remove manifest file ------------------------ |
|
99 Components.manager.removeBootstrappedManifestLocation(manifestPath); |
|
100 |
|
101 // Test Removing Content URL |
|
102 test_removed_mapping("chrome://test1/content", baseURI + "test/test1.xul"); |
|
103 |
|
104 // Test Removing Content URL |
|
105 test_removed_mapping("chrome://test1/locale", baseURI + "test/test1.dtd"); |
|
106 |
|
107 // Test Removing Skin URL |
|
108 test_removed_mapping("chrome://test1/skin", baseURI + "test/test1.css"); |
|
109 |
|
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 } |
|
114 |
|
115 function run_test() { |
|
116 // Test an unpackaged addon |
|
117 testManifest(UNPACKAGED_ADDON, gIOS.newFileURI(UNPACKAGED_ADDON).spec); |
|
118 |
|
119 // Test a packaged addon |
|
120 testManifest(PACKAGED_ADDON, "jar:" + gIOS.newFileURI(PACKAGED_ADDON).spec + "!/"); |
|
121 } |