Wed, 31 Dec 2014 06:09:35 +0100
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 | // This just verifies that FUEL integrates to the add-ons manager |
michael@0 | 7 | |
michael@0 | 8 | var testdata = { |
michael@0 | 9 | dummyid: "fuel-dummy-extension@mozilla.org", |
michael@0 | 10 | dummyname: "Dummy Extension", |
michael@0 | 11 | inspectorid: "addon1@tests.mozilla.org", |
michael@0 | 12 | inspectorname: "Test Addon", |
michael@0 | 13 | missing: "fuel.fuel-test-missing", |
michael@0 | 14 | dummy: "fuel.fuel-test" |
michael@0 | 15 | }; |
michael@0 | 16 | |
michael@0 | 17 | var Application = null |
michael@0 | 18 | |
michael@0 | 19 | function run_test() { |
michael@0 | 20 | var cm = AM_Cc["@mozilla.org/categorymanager;1"]. |
michael@0 | 21 | getService(AM_Ci.nsICategoryManager); |
michael@0 | 22 | |
michael@0 | 23 | try { |
michael@0 | 24 | var contract = cm.getCategoryEntry("JavaScript-global-privileged-property", |
michael@0 | 25 | "Application"); |
michael@0 | 26 | Application = AM_Cc[contract].getService(AM_Ci.extIApplication); |
michael@0 | 27 | } |
michael@0 | 28 | catch (e) { |
michael@0 | 29 | // This application does not include a FUEL variant. |
michael@0 | 30 | return; |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | do_test_pending(); |
michael@0 | 34 | createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); |
michael@0 | 35 | |
michael@0 | 36 | const profileDir = gProfD.clone(); |
michael@0 | 37 | profileDir.append("extensions"); |
michael@0 | 38 | |
michael@0 | 39 | writeInstallRDFForExtension({ |
michael@0 | 40 | id: "addon1@tests.mozilla.org", |
michael@0 | 41 | version: "1.0", |
michael@0 | 42 | name: "Test Addon", |
michael@0 | 43 | targetApplications: [{ |
michael@0 | 44 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 45 | minVersion: "1", |
michael@0 | 46 | maxVersion: "1" |
michael@0 | 47 | }], |
michael@0 | 48 | }, profileDir); |
michael@0 | 49 | |
michael@0 | 50 | startupManager(); |
michael@0 | 51 | |
michael@0 | 52 | Application.getExtensions(function(extensions) { |
michael@0 | 53 | // test to see if the extensions object is available |
michael@0 | 54 | do_check_neq(extensions, null); |
michael@0 | 55 | |
michael@0 | 56 | // test to see if a non-existant extension exists |
michael@0 | 57 | do_check_true(!extensions.has(testdata.dummyid)); |
michael@0 | 58 | |
michael@0 | 59 | // test to see if an extension exists |
michael@0 | 60 | do_check_true(extensions.has(testdata.inspectorid)); |
michael@0 | 61 | |
michael@0 | 62 | var inspector = extensions.get(testdata.inspectorid); |
michael@0 | 63 | do_check_eq(inspector.id, testdata.inspectorid); |
michael@0 | 64 | do_check_eq(inspector.name, testdata.inspectorname); |
michael@0 | 65 | do_check_eq(inspector.version, "1.0"); |
michael@0 | 66 | do_check_true(inspector.firstRun, true); |
michael@0 | 67 | do_check_true(inspector.enabled); |
michael@0 | 68 | |
michael@0 | 69 | // test to see if extension find works |
michael@0 | 70 | do_check_eq(extensions.all.length, 1); |
michael@0 | 71 | // STORAGE TESTING |
michael@0 | 72 | // Make sure the we are given the same extension (cached) so things like .storage work right |
michael@0 | 73 | inspector.storage.set("test", "simple check"); |
michael@0 | 74 | do_check_true(inspector.storage.has("test")); |
michael@0 | 75 | |
michael@0 | 76 | var inspector2 = extensions.get(testdata.inspectorid); |
michael@0 | 77 | do_check_eq(inspector2.id, testdata.inspectorid); |
michael@0 | 78 | do_check_true(inspector.storage.has("test")); |
michael@0 | 79 | do_check_eq(inspector2.storage.get("test", "cache"), inspector.storage.get("test", "original")); |
michael@0 | 80 | |
michael@0 | 81 | inspector.events.addListener("disable", onGenericEvent); |
michael@0 | 82 | inspector.events.addListener("enable", onGenericEvent); |
michael@0 | 83 | inspector.events.addListener("uninstall", onGenericEvent); |
michael@0 | 84 | inspector.events.addListener("cancel", onGenericEvent); |
michael@0 | 85 | |
michael@0 | 86 | AddonManager.getAddonByID(testdata.inspectorid, function(a) { |
michael@0 | 87 | a.userDisabled = true; |
michael@0 | 88 | |
michael@0 | 89 | do_check_eq(gLastEvent, "disable"); |
michael@0 | 90 | |
michael@0 | 91 | // enabling after a disable will only fire a 'cancel' event |
michael@0 | 92 | // see - http://mxr.mozilla.org/seamonkey/source/toolkit/mozapps/extensions/src/nsExtensionManager.js.in#5216 |
michael@0 | 93 | a.userDisabled = false; |
michael@0 | 94 | do_check_eq(gLastEvent, "cancel"); |
michael@0 | 95 | |
michael@0 | 96 | a.uninstall(); |
michael@0 | 97 | do_check_eq(gLastEvent, "uninstall"); |
michael@0 | 98 | |
michael@0 | 99 | a.cancelUninstall(); |
michael@0 | 100 | do_check_eq(gLastEvent, "cancel"); |
michael@0 | 101 | |
michael@0 | 102 | // PREF TESTING |
michael@0 | 103 | // Reset the install event preference, so that we can test it again later |
michael@0 | 104 | //inspector.prefs.get("install-event-fired").reset(); |
michael@0 | 105 | |
michael@0 | 106 | // test the value of the preference root |
michael@0 | 107 | do_check_eq(extensions.all[0].prefs.root, "extensions.addon1@tests.mozilla.org."); |
michael@0 | 108 | |
michael@0 | 109 | // test getting nonexistent values |
michael@0 | 110 | var itemValue = inspector.prefs.getValue(testdata.missing, "default"); |
michael@0 | 111 | do_check_eq(itemValue, "default"); |
michael@0 | 112 | |
michael@0 | 113 | do_check_eq(inspector.prefs.get(testdata.missing), null); |
michael@0 | 114 | |
michael@0 | 115 | // test setting and getting a value |
michael@0 | 116 | inspector.prefs.setValue(testdata.dummy, "dummy"); |
michael@0 | 117 | itemValue = inspector.prefs.getValue(testdata.dummy, "default"); |
michael@0 | 118 | do_check_eq(itemValue, "dummy"); |
michael@0 | 119 | |
michael@0 | 120 | // test for overwriting an existing value |
michael@0 | 121 | inspector.prefs.setValue(testdata.dummy, "smarty"); |
michael@0 | 122 | itemValue = inspector.prefs.getValue(testdata.dummy, "default"); |
michael@0 | 123 | do_check_eq(itemValue, "smarty"); |
michael@0 | 124 | |
michael@0 | 125 | // test setting and getting a value |
michael@0 | 126 | inspector.prefs.get(testdata.dummy).value = "dummy2"; |
michael@0 | 127 | itemValue = inspector.prefs.get(testdata.dummy).value; |
michael@0 | 128 | do_check_eq(itemValue, "dummy2"); |
michael@0 | 129 | |
michael@0 | 130 | // test resetting a pref [since there is no default value, the pref should disappear] |
michael@0 | 131 | inspector.prefs.get(testdata.dummy).reset(); |
michael@0 | 132 | var itemValue = inspector.prefs.getValue(testdata.dummy, "default"); |
michael@0 | 133 | do_check_eq(itemValue, "default"); |
michael@0 | 134 | |
michael@0 | 135 | // test to see if a non-existant property exists |
michael@0 | 136 | do_check_true(!inspector.prefs.has(testdata.dummy)); |
michael@0 | 137 | |
michael@0 | 138 | inspector.prefs.events.addListener("change", onPrefChange); |
michael@0 | 139 | inspector.prefs.setValue("fuel.fuel-test", "change event"); |
michael@0 | 140 | }); |
michael@0 | 141 | }); |
michael@0 | 142 | } |
michael@0 | 143 | |
michael@0 | 144 | function onGenericEvent(event) { |
michael@0 | 145 | gLastEvent = event.type; |
michael@0 | 146 | } |
michael@0 | 147 | |
michael@0 | 148 | function onPrefChange(evt) { |
michael@0 | 149 | Application.getExtensions(function(extensions) { |
michael@0 | 150 | var inspector3 = extensions.get(testdata.inspectorid); |
michael@0 | 151 | |
michael@0 | 152 | do_check_eq(evt.data, testdata.dummy); |
michael@0 | 153 | inspector3.prefs.events.removeListener("change", onPrefChange); |
michael@0 | 154 | |
michael@0 | 155 | inspector3.prefs.get("fuel.fuel-test").events.addListener("change", onPrefChange2); |
michael@0 | 156 | inspector3.prefs.setValue("fuel.fuel-test", "change event2"); |
michael@0 | 157 | }); |
michael@0 | 158 | } |
michael@0 | 159 | |
michael@0 | 160 | function onPrefChange2(evt) { |
michael@0 | 161 | do_check_eq(evt.data, testdata.dummy); |
michael@0 | 162 | |
michael@0 | 163 | do_execute_soon(do_test_finished); |
michael@0 | 164 | } |