toolkit/mozapps/extensions/test/xpcshell/test_fuel.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial