Bug 1600783 - Test doh-rollout addon's local storage migration. r=mixedpuppy,maxxcrawford

Differential Revision: https://phabricator.services.mozilla.com/D55558

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Nihanth Subramanya 2019-12-03 23:45:14 +00:00
Родитель b52a7b4150
Коммит 874e5c0f9e
4 изменённых файлов: 136 добавлений и 1 удалений

Просмотреть файл

@ -386,7 +386,6 @@ const rollout = {
const legacyLocalStorageKeys = [
"doneFirstRun",
"skipHeuristicsCheck",
DOH_ENABLED_PREF,
DOH_PREVIOUS_TRR_MODE_PREF,
DOH_DOORHANGER_SHOWN_PREF,
DOH_DOORHANGER_USER_DECISION_PREF,

Просмотреть файл

@ -60,3 +60,5 @@ FINAL_TARGET_FILES.features['doh-rollout@mozilla.org']["_locales"]["ru"] += [
FINAL_TARGET_FILES.features['doh-rollout@mozilla.org']["_locales"]["zh_CN"] += [
'_locales/zh_CN/messages.json'
]
XPCSHELL_TESTS_MANIFESTS += ['test/unit/xpcshell.ini']

Просмотреть файл

@ -0,0 +1,130 @@
/**
* Older versions of the doh-rollout add-on used local storage for memory.
* The current version uses prefs, and migrates the old local storage values
* to prefs. This tests the migration code.
*/
"use strict";
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
// Does some useful imports that set up message managers.
ChromeUtils.import(
"resource://testing-common/ExtensionXPCShellUtils.jsm",
null
);
const { AddonTestUtils } = ChromeUtils.import(
"resource://testing-common/AddonTestUtils.jsm"
);
AddonTestUtils.init(this);
ChromeUtils.defineModuleGetter(
this,
"AddonManager",
"resource://gre/modules/AddonManager.jsm"
);
ChromeUtils.defineModuleGetter(
this,
"ExtensionParent",
"resource://gre/modules/ExtensionParent.jsm"
);
ChromeUtils.defineModuleGetter(
this,
"ExtensionStorageIDB",
"resource://gre/modules/ExtensionStorageIDB.jsm"
);
ChromeUtils.defineModuleGetter(
this,
"Preferences",
"resource://gre/modules/Preferences.jsm"
);
const MIGRATION_DONE_PREF = "doh-rollout.balrog-migration-done";
const ADDON_ID = "doh-rollout@mozilla.org";
add_task(async function setup() {
AddonTestUtils.createAppInfo(
"xpcshell@tests.mozilla.org",
"XPCShell",
"1",
"72"
);
await AddonTestUtils.promiseStartupManager();
let extensionPath = Services.dirsvc.get("GreD", Ci.nsIFile);
extensionPath.append("browser");
extensionPath.append("features");
extensionPath.append(ADDON_ID);
if (!extensionPath.exists()) {
extensionPath.leafName = `${ADDON_ID}.xpi`;
}
let startupPromise = new Promise(resolve => {
const { apiManager } = ExtensionParent;
function onReady(event, extension) {
if (extension.id == ADDON_ID) {
apiManager.off("ready", onReady);
resolve();
}
}
apiManager.on("ready", onReady);
});
await AddonManager.installTemporaryAddon(extensionPath);
await startupPromise;
});
add_task(async function testLocalStorageMigration() {
Preferences.reset(MIGRATION_DONE_PREF);
const legacyEntries = {
doneFirstRun: true,
skipHeuristicsCheck: true,
"doh-rollout.previous.trr.mode": 2,
"doh-rollout.doorhanger-shown": true,
"doh-rollout.doorhanger-decision": "UIOk",
"doh-rollout.disable-heuristics": true,
};
let policy = WebExtensionPolicy.getByID(ADDON_ID);
const storagePrincipal = ExtensionStorageIDB.getStoragePrincipal(
policy.extension
);
const idbConn = await ExtensionStorageIDB.open(storagePrincipal);
await idbConn.set(legacyEntries);
await idbConn.close();
let migrationDone = new Promise(resolve => {
Preferences.observe(MIGRATION_DONE_PREF, function obs() {
Preferences.ignore(MIGRATION_DONE_PREF, obs);
resolve();
});
});
let addon = await AddonManager.getAddonByID(ADDON_ID);
await addon.reload();
await migrationDone;
for (let [key, value] of Object.entries(legacyEntries)) {
if (!key.startsWith("doh-rollout")) {
key = "doh-rollout." + key;
}
Assert.equal(
Preferences.get(key),
value,
`${key} pref exists and has the right value ${value}`
);
Preferences.reset(key);
}
});

Просмотреть файл

@ -0,0 +1,4 @@
[DEFAULT]
firefox-appdir = browser
[test_localStorageMigration.js]