1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/extensions/test/xpcshell/test_fuel.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,164 @@ 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 +// This just verifies that FUEL integrates to the add-ons manager 1.10 + 1.11 +var testdata = { 1.12 + dummyid: "fuel-dummy-extension@mozilla.org", 1.13 + dummyname: "Dummy Extension", 1.14 + inspectorid: "addon1@tests.mozilla.org", 1.15 + inspectorname: "Test Addon", 1.16 + missing: "fuel.fuel-test-missing", 1.17 + dummy: "fuel.fuel-test" 1.18 +}; 1.19 + 1.20 +var Application = null 1.21 + 1.22 +function run_test() { 1.23 + var cm = AM_Cc["@mozilla.org/categorymanager;1"]. 1.24 + getService(AM_Ci.nsICategoryManager); 1.25 + 1.26 + try { 1.27 + var contract = cm.getCategoryEntry("JavaScript-global-privileged-property", 1.28 + "Application"); 1.29 + Application = AM_Cc[contract].getService(AM_Ci.extIApplication); 1.30 + } 1.31 + catch (e) { 1.32 + // This application does not include a FUEL variant. 1.33 + return; 1.34 + } 1.35 + 1.36 + do_test_pending(); 1.37 + createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); 1.38 + 1.39 + const profileDir = gProfD.clone(); 1.40 + profileDir.append("extensions"); 1.41 + 1.42 + writeInstallRDFForExtension({ 1.43 + id: "addon1@tests.mozilla.org", 1.44 + version: "1.0", 1.45 + name: "Test Addon", 1.46 + targetApplications: [{ 1.47 + id: "xpcshell@tests.mozilla.org", 1.48 + minVersion: "1", 1.49 + maxVersion: "1" 1.50 + }], 1.51 + }, profileDir); 1.52 + 1.53 + startupManager(); 1.54 + 1.55 + Application.getExtensions(function(extensions) { 1.56 + // test to see if the extensions object is available 1.57 + do_check_neq(extensions, null); 1.58 + 1.59 + // test to see if a non-existant extension exists 1.60 + do_check_true(!extensions.has(testdata.dummyid)); 1.61 + 1.62 + // test to see if an extension exists 1.63 + do_check_true(extensions.has(testdata.inspectorid)); 1.64 + 1.65 + var inspector = extensions.get(testdata.inspectorid); 1.66 + do_check_eq(inspector.id, testdata.inspectorid); 1.67 + do_check_eq(inspector.name, testdata.inspectorname); 1.68 + do_check_eq(inspector.version, "1.0"); 1.69 + do_check_true(inspector.firstRun, true); 1.70 + do_check_true(inspector.enabled); 1.71 + 1.72 + // test to see if extension find works 1.73 + do_check_eq(extensions.all.length, 1); 1.74 + // STORAGE TESTING 1.75 + // Make sure the we are given the same extension (cached) so things like .storage work right 1.76 + inspector.storage.set("test", "simple check"); 1.77 + do_check_true(inspector.storage.has("test")); 1.78 + 1.79 + var inspector2 = extensions.get(testdata.inspectorid); 1.80 + do_check_eq(inspector2.id, testdata.inspectorid); 1.81 + do_check_true(inspector.storage.has("test")); 1.82 + do_check_eq(inspector2.storage.get("test", "cache"), inspector.storage.get("test", "original")); 1.83 + 1.84 + inspector.events.addListener("disable", onGenericEvent); 1.85 + inspector.events.addListener("enable", onGenericEvent); 1.86 + inspector.events.addListener("uninstall", onGenericEvent); 1.87 + inspector.events.addListener("cancel", onGenericEvent); 1.88 + 1.89 + AddonManager.getAddonByID(testdata.inspectorid, function(a) { 1.90 + a.userDisabled = true; 1.91 + 1.92 + do_check_eq(gLastEvent, "disable"); 1.93 + 1.94 + // enabling after a disable will only fire a 'cancel' event 1.95 + // see - http://mxr.mozilla.org/seamonkey/source/toolkit/mozapps/extensions/src/nsExtensionManager.js.in#5216 1.96 + a.userDisabled = false; 1.97 + do_check_eq(gLastEvent, "cancel"); 1.98 + 1.99 + a.uninstall(); 1.100 + do_check_eq(gLastEvent, "uninstall"); 1.101 + 1.102 + a.cancelUninstall(); 1.103 + do_check_eq(gLastEvent, "cancel"); 1.104 + 1.105 + // PREF TESTING 1.106 + // Reset the install event preference, so that we can test it again later 1.107 + //inspector.prefs.get("install-event-fired").reset(); 1.108 + 1.109 + // test the value of the preference root 1.110 + do_check_eq(extensions.all[0].prefs.root, "extensions.addon1@tests.mozilla.org."); 1.111 + 1.112 + // test getting nonexistent values 1.113 + var itemValue = inspector.prefs.getValue(testdata.missing, "default"); 1.114 + do_check_eq(itemValue, "default"); 1.115 + 1.116 + do_check_eq(inspector.prefs.get(testdata.missing), null); 1.117 + 1.118 + // test setting and getting a value 1.119 + inspector.prefs.setValue(testdata.dummy, "dummy"); 1.120 + itemValue = inspector.prefs.getValue(testdata.dummy, "default"); 1.121 + do_check_eq(itemValue, "dummy"); 1.122 + 1.123 + // test for overwriting an existing value 1.124 + inspector.prefs.setValue(testdata.dummy, "smarty"); 1.125 + itemValue = inspector.prefs.getValue(testdata.dummy, "default"); 1.126 + do_check_eq(itemValue, "smarty"); 1.127 + 1.128 + // test setting and getting a value 1.129 + inspector.prefs.get(testdata.dummy).value = "dummy2"; 1.130 + itemValue = inspector.prefs.get(testdata.dummy).value; 1.131 + do_check_eq(itemValue, "dummy2"); 1.132 + 1.133 + // test resetting a pref [since there is no default value, the pref should disappear] 1.134 + inspector.prefs.get(testdata.dummy).reset(); 1.135 + var itemValue = inspector.prefs.getValue(testdata.dummy, "default"); 1.136 + do_check_eq(itemValue, "default"); 1.137 + 1.138 + // test to see if a non-existant property exists 1.139 + do_check_true(!inspector.prefs.has(testdata.dummy)); 1.140 + 1.141 + inspector.prefs.events.addListener("change", onPrefChange); 1.142 + inspector.prefs.setValue("fuel.fuel-test", "change event"); 1.143 + }); 1.144 + }); 1.145 +} 1.146 + 1.147 +function onGenericEvent(event) { 1.148 + gLastEvent = event.type; 1.149 +} 1.150 + 1.151 +function onPrefChange(evt) { 1.152 + Application.getExtensions(function(extensions) { 1.153 + var inspector3 = extensions.get(testdata.inspectorid); 1.154 + 1.155 + do_check_eq(evt.data, testdata.dummy); 1.156 + inspector3.prefs.events.removeListener("change", onPrefChange); 1.157 + 1.158 + inspector3.prefs.get("fuel.fuel-test").events.addListener("change", onPrefChange2); 1.159 + inspector3.prefs.setValue("fuel.fuel-test", "change event2"); 1.160 + }); 1.161 +} 1.162 + 1.163 +function onPrefChange2(evt) { 1.164 + do_check_eq(evt.data, testdata.dummy); 1.165 + 1.166 + do_execute_soon(do_test_finished); 1.167 +}