diff options
author | Matt A. Tobin <email@mattatobin.com> | 2018-02-10 02:51:36 -0500 |
---|---|---|
committer | Matt A. Tobin <email@mattatobin.com> | 2018-02-10 02:51:36 -0500 |
commit | 37d5300335d81cecbecc99812747a657588c63eb (patch) | |
tree | 765efa3b6a56bb715d9813a8697473e120436278 /toolkit/mozapps/webextensions/test/xpcshell/test_schema_change.js | |
parent | b2bdac20c02b12f2057b9ef70b0a946113a00e00 (diff) | |
parent | 4fb11cd5966461bccc3ed1599b808237be6b0de9 (diff) | |
download | UXP-37d5300335d81cecbecc99812747a657588c63eb.tar UXP-37d5300335d81cecbecc99812747a657588c63eb.tar.gz UXP-37d5300335d81cecbecc99812747a657588c63eb.tar.lz UXP-37d5300335d81cecbecc99812747a657588c63eb.tar.xz UXP-37d5300335d81cecbecc99812747a657588c63eb.zip |
Merge branch 'ext-work'
Diffstat (limited to 'toolkit/mozapps/webextensions/test/xpcshell/test_schema_change.js')
-rw-r--r-- | toolkit/mozapps/webextensions/test/xpcshell/test_schema_change.js | 317 |
1 files changed, 317 insertions, 0 deletions
diff --git a/toolkit/mozapps/webextensions/test/xpcshell/test_schema_change.js b/toolkit/mozapps/webextensions/test/xpcshell/test_schema_change.js new file mode 100644 index 000000000..3d386f663 --- /dev/null +++ b/toolkit/mozapps/webextensions/test/xpcshell/test_schema_change.js @@ -0,0 +1,317 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +BootstrapMonitor.init(); + +const PREF_DB_SCHEMA = "extensions.databaseSchema"; + +const profileDir = gProfD.clone(); +profileDir.append("extensions"); + +createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "49"); +startupManager(); + +/** + * Schema change with no application update reloads metadata. + */ +add_task(function* schema_change() { + const ID = "schema-change@tests.mozilla.org"; + + let xpiFile = createTempXPIFile({ + id: ID, + name: "Test Add-on", + version: "1.0", + bootstrap: true, + targetApplications: [{ + id: "xpcshell@tests.mozilla.org", + minVersion: "1", + maxVersion: "1.9.2" + }] + }); + + yield promiseInstallAllFiles([xpiFile]); + + let addon = yield promiseAddonByID(ID); + + notEqual(addon, null, "Got an addon object as expected"); + equal(addon.version, "1.0", "Got the expected version"); + + yield shutdownManager(); + + xpiFile = createTempXPIFile({ + id: ID, + name: "Test Add-on 2", + version: "2.0", + bootstrap: true, + targetApplications: [{ + id: "xpcshell@tests.mozilla.org", + minVersion: "1", + maxVersion: "1.9.2" + }] + }); + + Services.prefs.setIntPref(PREF_DB_SCHEMA, 0); + + let file = profileDir.clone(); + file.append(`${ID}.xpi`); + + // Make sure the timestamp is unchanged, so it is not re-scanned for that reason. + let timestamp = file.lastModifiedTime; + xpiFile.moveTo(profileDir, `${ID}.xpi`); + + file.lastModifiedTime = timestamp; + + yield startupManager(); + + addon = yield promiseAddonByID(ID); + notEqual(addon, null, "Got an addon object as expected"); + equal(addon.version, "2.0", "Got the expected version"); + + let waitUninstall = promiseAddonEvent("onUninstalled"); + addon.uninstall(); + yield waitUninstall; +}); + +/** + * Application update with no schema change does not reload metadata. + */ +add_task(function* schema_change() { + const ID = "schema-change@tests.mozilla.org"; + + let xpiFile = createTempXPIFile({ + id: ID, + name: "Test Add-on", + version: "1.0", + bootstrap: true, + targetApplications: [{ + id: "xpcshell@tests.mozilla.org", + minVersion: "1", + maxVersion: "2" + }] + }); + + yield promiseInstallAllFiles([xpiFile]); + + let addon = yield promiseAddonByID(ID); + + notEqual(addon, null, "Got an addon object as expected"); + equal(addon.version, "1.0", "Got the expected version"); + + yield shutdownManager(); + + xpiFile = createTempXPIFile({ + id: ID, + name: "Test Add-on 2", + version: "2.0", + bootstrap: true, + targetApplications: [{ + id: "xpcshell@tests.mozilla.org", + minVersion: "1", + maxVersion: "2" + }] + }); + + gAppInfo.version = "2"; + let file = profileDir.clone(); + file.append(`${ID}.xpi`); + + // Make sure the timestamp is unchanged, so it is not re-scanned for that reason. + let timestamp = file.lastModifiedTime; + xpiFile.moveTo(profileDir, `${ID}.xpi`); + + file.lastModifiedTime = timestamp; + + yield startupManager(); + + addon = yield promiseAddonByID(ID); + notEqual(addon, null, "Got an addon object as expected"); + equal(addon.version, "1.0", "Got the expected version"); + + let waitUninstall = promiseAddonEvent("onUninstalled"); + addon.uninstall(); + yield waitUninstall; +}); + +/** + * App update and a schema change causes a reload of the manifest. + */ +add_task(function* schema_change_app_update() { + const ID = "schema-change@tests.mozilla.org"; + + let xpiFile = createTempXPIFile({ + id: ID, + name: "Test Add-on", + version: "1.0", + bootstrap: true, + targetApplications: [{ + id: "xpcshell@tests.mozilla.org", + minVersion: "1", + maxVersion: "3" + }] + }); + + yield promiseInstallAllFiles([xpiFile]); + + let addon = yield promiseAddonByID(ID); + + notEqual(addon, null, "Got an addon object as expected"); + equal(addon.version, "1.0", "Got the expected version"); + + yield shutdownManager(); + + xpiFile = createTempXPIFile({ + id: ID, + name: "Test Add-on 2", + version: "2.0", + bootstrap: true, + targetApplications: [{ + id: "xpcshell@tests.mozilla.org", + minVersion: "1", + maxVersion: "3" + }] + }); + + gAppInfo.version = "3"; + Services.prefs.setIntPref(PREF_DB_SCHEMA, 0); + + let file = profileDir.clone(); + file.append(`${ID}.xpi`); + + // Make sure the timestamp is unchanged, so it is not re-scanned for that reason. + let timestamp = file.lastModifiedTime; + xpiFile.moveTo(profileDir, `${ID}.xpi`); + + file.lastModifiedTime = timestamp; + + yield startupManager(); + + addon = yield promiseAddonByID(ID); + notEqual(addon, null, "Got an addon object as expected"); + equal(addon.appDisabled, false); + equal(addon.version, "2.0", "Got the expected version"); + + let waitUninstall = promiseAddonEvent("onUninstalled"); + addon.uninstall(); + yield waitUninstall; +}); + +/** + * No schema change, no manifest reload. + */ +add_task(function* schema_change() { + const ID = "schema-change@tests.mozilla.org"; + + let xpiFile = createTempXPIFile({ + id: ID, + name: "Test Add-on", + version: "1.0", + bootstrap: true, + targetApplications: [{ + id: "xpcshell@tests.mozilla.org", + minVersion: "1", + maxVersion: "1.9.2" + }] + }); + + yield promiseInstallAllFiles([xpiFile]); + + let addon = yield promiseAddonByID(ID); + + notEqual(addon, null, "Got an addon object as expected"); + equal(addon.version, "1.0", "Got the expected version"); + + yield shutdownManager(); + + xpiFile = createTempXPIFile({ + id: ID, + name: "Test Add-on 2", + version: "2.0", + bootstrap: true, + targetApplications: [{ + id: "xpcshell@tests.mozilla.org", + minVersion: "1", + maxVersion: "1.9.2" + }] + }); + + let file = profileDir.clone(); + file.append(`${ID}.xpi`); + + // Make sure the timestamp is unchanged, so it is not re-scanned for that reason. + let timestamp = file.lastModifiedTime; + xpiFile.moveTo(profileDir, `${ID}.xpi`); + + file.lastModifiedTime = timestamp; + + yield startupManager(); + + addon = yield promiseAddonByID(ID); + notEqual(addon, null, "Got an addon object as expected"); + equal(addon.version, "1.0", "Got the expected version"); + + let waitUninstall = promiseAddonEvent("onUninstalled"); + addon.uninstall(); + yield waitUninstall; +}); + +/** + * Modified timestamp on the XPI causes a reload of the manifest. + */ +add_task(function* schema_change() { + const ID = "schema-change@tests.mozilla.org"; + + let xpiFile = createTempXPIFile({ + id: ID, + name: "Test Add-on", + version: "1.0", + bootstrap: true, + targetApplications: [{ + id: "xpcshell@tests.mozilla.org", + minVersion: "1", + maxVersion: "1.9.2" + }] + }); + + yield promiseInstallAllFiles([xpiFile]); + + let addon = yield promiseAddonByID(ID); + + notEqual(addon, null, "Got an addon object as expected"); + equal(addon.version, "1.0", "Got the expected version"); + + yield shutdownManager(); + + xpiFile = createTempXPIFile({ + id: ID, + name: "Test Add-on 2", + version: "2.0", + bootstrap: true, + targetApplications: [{ + id: "xpcshell@tests.mozilla.org", + minVersion: "1", + maxVersion: "1.9.2" + }] + }); + + xpiFile.moveTo(profileDir, `${ID}.xpi`); + + let file = profileDir.clone(); + file.append(`${ID}.xpi`); + + // Set timestamp in the future so manifest is re-scanned. + let timestamp = new Date(Date.now() + 60000); + xpiFile.moveTo(profileDir, `${ID}.xpi`); + + file.lastModifiedTime = timestamp; + + yield startupManager(); + + addon = yield promiseAddonByID(ID); + notEqual(addon, null, "Got an addon object as expected"); + equal(addon.version, "2.0", "Got the expected version"); + + let waitUninstall = promiseAddonEvent("onUninstalled"); + addon.uninstall(); + yield waitUninstall; +}); |