1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/extensions/test/xpcshell/test_no_addons.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,98 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.6 + */ 1.7 + 1.8 +// Test startup and restart when no add-ons are installed 1.9 +// bug 944006 1.10 + 1.11 +Components.utils.import("resource://gre/modules/Promise.jsm"); 1.12 + 1.13 +// Load XPI Provider to get schema version ID 1.14 +let XPIScope = Components.utils.import("resource://gre/modules/addons/XPIProvider.jsm"); 1.15 +const DB_SCHEMA = XPIScope.DB_SCHEMA; 1.16 + 1.17 +createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); 1.18 + 1.19 +function run_test() { 1.20 + // Kick off the task-based tests... 1.21 + run_next_test(); 1.22 +} 1.23 + 1.24 +// Test for a preference to either exist with a specified value, or not exist at all 1.25 +function checkPending() { 1.26 + try { 1.27 + do_check_false(Services.prefs.getBoolPref("extensions.pendingOperations")); 1.28 + } 1.29 + catch (e) { 1.30 + // OK 1.31 + } 1.32 +} 1.33 + 1.34 +function checkString(aPref, aValue) { 1.35 + try { 1.36 + do_check_eq(Services.prefs.getCharPref(aPref), aValue) 1.37 + } 1.38 + catch (e) { 1.39 + //OK 1.40 + } 1.41 +} 1.42 + 1.43 +// Make sure all our extension state is empty/nonexistent 1.44 +function check_empty_state() { 1.45 + do_check_false(gExtensionsJSON.exists()); 1.46 + do_check_false(gExtensionsINI.exists()); 1.47 + 1.48 + do_check_eq(Services.prefs.getIntPref("extensions.databaseSchema"), DB_SCHEMA); 1.49 + 1.50 + checkString("extensions.bootstrappedAddons", "{}"); 1.51 + checkString("extensions.installCache", "[]"); 1.52 + checkPending(); 1.53 +} 1.54 + 1.55 +// After first run with no add-ons, we expect: 1.56 +// no extensions.json is created 1.57 +// no extensions.ini 1.58 +// database schema version preference is set 1.59 +// bootstrap add-ons preference is not found 1.60 +// add-on directory state preference is an empty array 1.61 +// no pending operations 1.62 +add_task(function first_run() { 1.63 + startupManager(); 1.64 + check_empty_state(); 1.65 + yield true; 1.66 +}); 1.67 + 1.68 +// Now do something that causes a DB load, and re-check 1.69 +function trigger_db_load() { 1.70 + let addonDefer = Promise.defer(); 1.71 + AddonManager.getAddonsByTypes(['extension'], addonDefer.resolve); 1.72 + let addonList = yield addonDefer.promise; 1.73 + 1.74 + do_check_eq(addonList.length, 0); 1.75 + check_empty_state(); 1.76 + 1.77 + yield true; 1.78 +}; 1.79 +add_task(trigger_db_load); 1.80 + 1.81 +// Now restart the manager and check again 1.82 +add_task(function restart_and_recheck() { 1.83 + restartManager(); 1.84 + check_empty_state(); 1.85 + yield true; 1.86 +}); 1.87 + 1.88 +// and reload the DB again 1.89 +add_task(trigger_db_load); 1.90 + 1.91 +// When we start up with no DB and an old database schema, we should update the 1.92 +// schema number but not create a database 1.93 +add_task(function upgrade_schema_version() { 1.94 + shutdownManager(); 1.95 + Services.prefs.setIntPref("extensions.databaseSchema", 1); 1.96 + 1.97 + startupManager(); 1.98 + do_check_eq(Services.prefs.getIntPref("extensions.databaseSchema"), DB_SCHEMA); 1.99 + check_empty_state(); 1.100 +}); 1.101 +