michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: // Checks that we migrate data from the old extensions.rdf database. This michael@0: // matches test_migrate1.js however it runs with a lightweight theme selected michael@0: // so the themes should appear disabled. michael@0: michael@0: Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm"); michael@0: michael@0: var addon1 = { michael@0: id: "addon1@tests.mozilla.org", michael@0: version: "1.0", michael@0: name: "Test 1", michael@0: targetApplications: [{ michael@0: id: "xpcshell@tests.mozilla.org", michael@0: minVersion: "1", michael@0: maxVersion: "1" michael@0: }] michael@0: }; michael@0: michael@0: var addon2 = { michael@0: id: "addon2@tests.mozilla.org", michael@0: version: "2.0", michael@0: name: "Test 2", michael@0: targetApplications: [{ michael@0: id: "toolkit@mozilla.org", michael@0: minVersion: "1", michael@0: maxVersion: "1" michael@0: }] michael@0: }; michael@0: michael@0: var addon3 = { michael@0: id: "addon3@tests.mozilla.org", michael@0: version: "2.0", michael@0: name: "Test 3", michael@0: targetApplications: [{ michael@0: id: "xpcshell@tests.mozilla.org", michael@0: minVersion: "1", michael@0: maxVersion: "1" michael@0: }] michael@0: }; michael@0: michael@0: var addon4 = { michael@0: id: "addon4@tests.mozilla.org", michael@0: version: "2.0", michael@0: name: "Test 4", michael@0: targetApplications: [{ michael@0: id: "toolkit@mozilla.org", michael@0: minVersion: "1", michael@0: maxVersion: "1" michael@0: }] michael@0: }; michael@0: michael@0: var addon5 = { michael@0: id: "addon5@tests.mozilla.org", michael@0: version: "2.0", michael@0: name: "Test 5", michael@0: targetApplications: [{ michael@0: id: "toolkit@mozilla.org", michael@0: minVersion: "1", michael@0: maxVersion: "1" michael@0: }] michael@0: }; michael@0: michael@0: var theme1 = { michael@0: id: "theme1@tests.mozilla.org", michael@0: version: "1.0", michael@0: name: "Theme 1", michael@0: type: 4, michael@0: internalName: "theme1/1.0", michael@0: targetApplications: [{ michael@0: id: "xpcshell@tests.mozilla.org", michael@0: minVersion: "1", michael@0: maxVersion: "2" michael@0: }] michael@0: }; michael@0: michael@0: var theme2 = { michael@0: id: "theme2@tests.mozilla.org", michael@0: version: "1.0", michael@0: name: "Theme 2", michael@0: type: 4, michael@0: internalName: "theme2/1.0", michael@0: targetApplications: [{ michael@0: id: "xpcshell@tests.mozilla.org", michael@0: minVersion: "1", michael@0: maxVersion: "2" michael@0: }] michael@0: }; michael@0: michael@0: const profileDir = gProfD.clone(); michael@0: profileDir.append("extensions"); michael@0: michael@0: function run_test() { michael@0: do_test_pending(); michael@0: createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "2", "2"); michael@0: michael@0: writeInstallRDFForExtension(addon1, profileDir); michael@0: writeInstallRDFForExtension(addon2, profileDir); michael@0: writeInstallRDFForExtension(addon3, profileDir); michael@0: writeInstallRDFForExtension(addon4, profileDir); michael@0: writeInstallRDFForExtension(addon5, profileDir); michael@0: writeInstallRDFForExtension(theme1, profileDir); michael@0: writeInstallRDFForExtension(theme2, profileDir); michael@0: michael@0: // Cannot use the LightweightThemeManager before AddonManager has been started michael@0: // so inject the correct prefs michael@0: Services.prefs.setCharPref("lightweightThemes.usedThemes", JSON.stringify([{ michael@0: id: "1", michael@0: version: "1", michael@0: name: "Test LW Theme", michael@0: description: "A test theme", michael@0: author: "Mozilla", michael@0: homepageURL: "http://localhost/data/index.html", michael@0: headerURL: "http://localhost/data/header.png", michael@0: footerURL: "http://localhost/data/footer.png", michael@0: previewURL: "http://localhost/data/preview.png", michael@0: iconURL: "http://localhost/data/icon.png" michael@0: }])); michael@0: Services.prefs.setBoolPref("lightweightThemes.isThemeSelected", true); michael@0: michael@0: let stagedXPIs = profileDir.clone(); michael@0: stagedXPIs.append("staged-xpis"); michael@0: stagedXPIs.append("addon6@tests.mozilla.org"); michael@0: stagedXPIs.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0755); michael@0: michael@0: let addon6 = do_get_addon("test_migrate6"); michael@0: addon6.copyTo(stagedXPIs, "tmp.xpi"); michael@0: stagedXPIs = stagedXPIs.parent; michael@0: michael@0: stagedXPIs.append("addon7@tests.mozilla.org"); michael@0: stagedXPIs.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0755); michael@0: michael@0: let addon7 = do_get_addon("test_migrate7"); michael@0: addon7.copyTo(stagedXPIs, "tmp.xpi"); michael@0: stagedXPIs = stagedXPIs.parent; michael@0: michael@0: let old = do_get_file("data/test_migrate.rdf"); michael@0: old.copyTo(gProfD, "extensions.rdf"); michael@0: michael@0: // Theme state is determined by the selected theme pref michael@0: Services.prefs.setCharPref("general.skins.selectedSkin", "theme1/1.0"); michael@0: michael@0: startupManager(); michael@0: check_startup_changes("installed", []); michael@0: check_startup_changes("updated", []); michael@0: check_startup_changes("uninstalled", []); michael@0: check_startup_changes("disabled", []); michael@0: check_startup_changes("enabled", []); michael@0: michael@0: AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", michael@0: "addon2@tests.mozilla.org", michael@0: "addon3@tests.mozilla.org", michael@0: "addon4@tests.mozilla.org", michael@0: "addon5@tests.mozilla.org", michael@0: "addon6@tests.mozilla.org", michael@0: "addon7@tests.mozilla.org", michael@0: "theme1@tests.mozilla.org", michael@0: "theme2@tests.mozilla.org"], function([a1, a2, a3, michael@0: a4, a5, a6, michael@0: a7, t1, t2]) { michael@0: // addon1 was user and app enabled in the old extensions.rdf michael@0: do_check_neq(a1, null); michael@0: do_check_false(a1.userDisabled); michael@0: do_check_false(a1.appDisabled); michael@0: do_check_true(a1.isActive); michael@0: do_check_true(isExtensionInAddonsList(profileDir, a1.id)); michael@0: michael@0: // addon2 was user disabled and app enabled in the old extensions.rdf michael@0: do_check_neq(a2, null); michael@0: do_check_true(a2.userDisabled); michael@0: do_check_false(a2.appDisabled); michael@0: do_check_false(a2.isActive); michael@0: do_check_false(isExtensionInAddonsList(profileDir, a2.id)); michael@0: michael@0: // addon3 was pending user disable and app disabled in the old extensions.rdf michael@0: do_check_neq(a3, null); michael@0: do_check_true(a3.userDisabled); michael@0: do_check_true(a3.appDisabled); michael@0: do_check_false(a3.isActive); michael@0: do_check_false(isExtensionInAddonsList(profileDir, a3.id)); michael@0: michael@0: // addon4 was pending user enable and app disabled in the old extensions.rdf michael@0: do_check_neq(a4, null); michael@0: do_check_false(a4.userDisabled); michael@0: do_check_true(a4.appDisabled); michael@0: do_check_false(a4.isActive); michael@0: do_check_false(isExtensionInAddonsList(profileDir, a4.id)); michael@0: michael@0: // addon5 was disabled and compatible but a new version has been installed michael@0: // since, it should still be disabled but should be incompatible michael@0: do_check_neq(a5, null); michael@0: do_check_true(a5.userDisabled); michael@0: do_check_true(a5.appDisabled); michael@0: do_check_false(a5.isActive); michael@0: do_check_false(isExtensionInAddonsList(profileDir, a5.id)); michael@0: michael@0: // addon6 should be installed and compatible and packed unless unpacking is michael@0: // forced michael@0: do_check_neq(a6, null); michael@0: do_check_false(a6.userDisabled); michael@0: do_check_false(a6.appDisabled); michael@0: do_check_true(a6.isActive); michael@0: do_check_true(isExtensionInAddonsList(profileDir, a6.id)); michael@0: if (Services.prefs.getBoolPref("extensions.alwaysUnpack")) michael@0: do_check_eq(a6.getResourceURI("install.rdf").scheme, "file"); michael@0: else michael@0: do_check_eq(a6.getResourceURI("install.rdf").scheme, "jar"); michael@0: michael@0: // addon7 should be installed and compatible and unpacked michael@0: do_check_neq(a7, null); michael@0: do_check_false(a7.userDisabled); michael@0: do_check_false(a7.appDisabled); michael@0: do_check_true(a7.isActive); michael@0: do_check_true(isExtensionInAddonsList(profileDir, a7.id)); michael@0: do_check_eq(a7.getResourceURI("install.rdf").scheme, "file"); michael@0: michael@0: // Theme 1 was previously disabled michael@0: do_check_neq(t1, null); michael@0: do_check_true(t1.userDisabled); michael@0: do_check_false(t1.appDisabled); michael@0: do_check_false(t1.isActive); michael@0: do_check_true(isThemeInAddonsList(profileDir, t1.id)); michael@0: do_check_true(hasFlag(t1.permissions, AddonManager.PERM_CAN_ENABLE)); michael@0: michael@0: // Theme 2 was previously disabled michael@0: do_check_neq(t1, null); michael@0: do_check_true(t2.userDisabled); michael@0: do_check_false(t2.appDisabled); michael@0: do_check_false(t2.isActive); michael@0: do_check_false(isThemeInAddonsList(profileDir, t2.id)); michael@0: do_check_true(hasFlag(t2.permissions, AddonManager.PERM_CAN_ENABLE)); michael@0: michael@0: do_check_false(stagedXPIs.exists()); michael@0: michael@0: do_execute_soon(do_test_finished); michael@0: }); michael@0: }