Bug 1000114 - Extend test coverage for experiments in addon manager UI. r=unfocused

This commit is contained in:
Georg Fritzsche 2014-05-09 14:03:10 +02:00
Родитель e55c45fbb7
Коммит 6eb0783437
1 изменённых файлов: 274 добавлений и 2 удалений

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

@ -11,6 +11,10 @@ let gExperiments;
let gHttpServer;
let gSavedManifestURI;
let gIsEnUsLocale;
const SEC_IN_ONE_DAY = 24 * 60 * 60;
const MS_IN_ONE_DAY = SEC_IN_ONE_DAY * 1000;
function getExperimentAddons() {
let deferred = Promise.defer();
@ -20,6 +24,48 @@ function getExperimentAddons() {
return deferred.promise;
}
function getInstallItem() {
let doc = gManagerWindow.document;
let view = doc.getElementById("view-port").selectedPanel;
let list = doc.getElementById("addon-list");
let node = list.firstChild;
while (node) {
if (node.getAttribute("status") == "installing") {
return node;
}
node = node.nextSibling;
}
return null;
}
function patchPolicy(policy, data) {
for (let key of Object.keys(data)) {
Object.defineProperty(policy, key, {
value: data[key],
writable: true,
});
}
}
function defineNow(policy, time) {
patchPolicy(policy, { now: () => new Date(time) });
}
function openDetailsView(aId) {
let item = get_addon_element(gManagerWindow, aId);
Assert.ok(item, "Should have got add-on element.");
is_element_visible(item, "Add-on element should be visible.");
EventUtils.synthesizeMouseAtCenter(item, { clickCount: 1 }, gManagerWindow);
EventUtils.synthesizeMouseAtCenter(item, { clickCount: 2 }, gManagerWindow);
let deferred = Promise.defer();
wait_for_view_load(gManagerWindow, deferred.resolve);
return deferred.promise;
}
add_task(function* initializeState() {
gManagerWindow = yield open_manager();
gCategoryUtilities = new CategoryUtilities(gManagerWindow);
@ -34,17 +80,22 @@ add_task(function* initializeState() {
}
}
if (gExperiments) {
gExperiments._policy.ignoreHashes = false;
let tmp = {};
Cu.import("resource:///modules/experiments/Experiments.jsm", tmp);
gExperiments._policy = new tmp.Experiments.Policy();
}
});
let chrome = Cc["@mozilla.org/chrome/chrome-registry;1"].getService(Ci.nsIXULChromeRegistry);
gIsEnUsLocale = chrome.getSelectedLocale("global") == "en-US";
// The Experiments Manager will interfere with us by preventing installs
// of experiments it doesn't know about. We remove it from the equation
// because here we are only concerned with core Addon Manager operation,
// not the superset Experiments Manager has imposed.
if ("@mozilla.org/browser/experiments-service;1" in Components.classes) {
let tmp = {};
Components.utils.import("resource:///modules/experiments/Experiments.jsm", tmp);
Cu.import("resource:///modules/experiments/Experiments.jsm", tmp);
// There is a race condition between XPCOM service initialization and
// this test running. We have to initialize the instance first, then
// uninitialize it to prevent this.
@ -302,6 +353,227 @@ add_task(function testDeactivateExperiment() {
is_element_hidden(el, "Preferences button is not visible.");
});
add_task(function testActivateRealExperiments() {
if (!gExperiments) {
info("Skipping experiments test because that feature isn't available.");
return;
}
yield gExperiments._updateExperiments({
"version": 1,
"experiments": [
{
id: "experiment-2",
xpiURL: TESTROOT + "addons/browser_experiment1.xpi",
xpiHash: "IRRELEVANT",
startTime: Date.now() / 1000 - 3600,
endTime: Date.now() / 1000 + 3600,
maxActiveSeconds: 600,
appName: [Services.appinfo.name],
channel: [gExperiments._policy.updatechannel()],
},
],
});
yield gExperiments._run();
// Check the active experiment.
let item = get_addon_element(gManagerWindow, "test-experiment1@experiments.mozilla.org");
Assert.ok(item, "Got add-on element.");
let el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "experiment-state");
is_element_visible(el, "Experiment state label should be visible.");
if (gIsEnUsLocale) {
Assert.equal(el.value, "Active");
}
el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "experiment-time");
is_element_visible(el, "Experiment time label should be visible.");
if (gIsEnUsLocale) {
Assert.equal(el.value, "Less than a day remaining");
}
el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "error-container");
is_element_hidden(el, "error-container should be hidden.");
el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "warning-container");
is_element_hidden(el, "warning-container should be hidden.");
el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "pending-container");
is_element_hidden(el, "pending-container should be hidden.");
el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "version");
is_element_hidden(el, "version should be hidden.");
el = item.ownerDocument.getAnonymousElementByAttribute(item, "class", "disabled-postfix");
is_element_hidden(el, "disabled-postfix should be hidden.");
el = item.ownerDocument.getAnonymousElementByAttribute(item, "class", "update-postfix");
is_element_hidden(el, "update-postfix should be hidden.");
el = item.ownerDocument.getAnonymousElementByAttribute(item, "class", "experiment-bullet");
is_element_visible(el, "experiment-bullet should be visible.");
// Check the previous experiment.
item = get_addon_element(gManagerWindow, "experiment-1");
Assert.ok(item, "Got add-on element.");
el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "experiment-state");
is_element_visible(el, "Experiment state label should be visible.");
if (gIsEnUsLocale) {
Assert.equal(el.value, "Complete");
}
el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "experiment-time");
is_element_visible(el, "Experiment time label should be visible.");
if (gIsEnUsLocale) {
Assert.equal(el.value, "Less than a day ago");
}
el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "error-container");
is_element_hidden(el, "error-container should be hidden.");
el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "warning-container");
is_element_hidden(el, "warning-container should be hidden.");
el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "pending-container");
is_element_hidden(el, "pending-container should be hidden.");
el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "version");
is_element_hidden(el, "version should be hidden.");
el = item.ownerDocument.getAnonymousElementByAttribute(item, "class", "disabled-postfix");
is_element_hidden(el, "disabled-postfix should be hidden.");
el = item.ownerDocument.getAnonymousElementByAttribute(item, "class", "update-postfix");
is_element_hidden(el, "update-postfix should be hidden.");
el = item.ownerDocument.getAnonymousElementByAttribute(item, "class", "experiment-bullet");
is_element_visible(el, "experiment-bullet should be visible.");
// Install an "older" experiment.
yield gExperiments.disableExperiment("experiment-2");
let now = Date.now();
let fakeNow = now - 5 * MS_IN_ONE_DAY;
defineNow(gExperiments._policy, fakeNow);
yield gExperiments._updateExperiments({
"version": 1,
"experiments": [
{
id: "experiment-3",
xpiURL: TESTROOT + "addons/browser_experiment1.xpi",
xpiHash: "IRRELEVANT",
startTime: fakeNow / 1000 - SEC_IN_ONE_DAY,
endTime: now / 1000 + 10 * SEC_IN_ONE_DAY,
maxActiveSeconds: 100 * SEC_IN_ONE_DAY,
appName: [Services.appinfo.name],
channel: [gExperiments._policy.updatechannel()],
},
],
});
yield gExperiments._run();
// Check the active experiment.
item = get_addon_element(gManagerWindow, "test-experiment1@experiments.mozilla.org");
Assert.ok(item, "Got add-on element.");
el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "experiment-state");
is_element_visible(el, "Experiment state label should be visible.");
if (gIsEnUsLocale) {
Assert.equal(el.value, "Active");
}
el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "experiment-time");
is_element_visible(el, "Experiment time label should be visible.");
if (gIsEnUsLocale) {
Assert.equal(el.value, "10 days remaining");
}
// Disable it and check it's previous experiment entry.
yield gExperiments.disableExperiment("experiment-3");
item = get_addon_element(gManagerWindow, "experiment-3");
Assert.ok(item, "Got add-on element.");
el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "experiment-state");
is_element_visible(el, "Experiment state label should be visible.");
if (gIsEnUsLocale) {
Assert.equal(el.value, "Complete");
}
el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "experiment-time");
is_element_visible(el, "Experiment time label should be visible.");
if (gIsEnUsLocale) {
Assert.equal(el.value, "5 days ago");
}
});
add_task(function testDetailView() {
if (!gExperiments) {
info("Skipping experiments test because that feature isn't available.");
return;
}
defineNow(gExperiments._policy, Date.now());
yield gExperiments._updateExperiments({
"version": 1,
"experiments": [
{
id: "experiment-4",
xpiURL: TESTROOT + "addons/browser_experiment1.xpi",
xpiHash: "IRRELEVANT",
startTime: Date.now() / 1000 - 3600,
endTime: Date.now() / 1000 + 3600,
maxActiveSeconds: 600,
appName: [Services.appinfo.name],
channel: [gExperiments._policy.updatechannel()],
},
],
});
yield gExperiments._run();
// Check active experiment.
yield openDetailsView("test-experiment1@experiments.mozilla.org");
let el = gManagerWindow.document.getElementById("detail-experiment-state");
is_element_visible(el, "Experiment state label should be visible.");
if (gIsEnUsLocale) {
Assert.equal(el.value, "Active");
}
el = gManagerWindow.document.getElementById("detail-experiment-time");
is_element_visible(el, "Experiment time label should be visible.");
if (gIsEnUsLocale) {
Assert.equal(el.value, "Less than a day remaining");
}
el = gManagerWindow.document.getElementById("detail-version");
is_element_hidden(el, "detail-version should be hidden.");
el = gManagerWindow.document.getElementById("detail-creator");
is_element_hidden(el, "detail-creator should be hidden.");
el = gManagerWindow.document.getElementById("detail-experiment-bullet");
is_element_visible(el, "experiment-bullet should be visible.");
// Check previous experiment.
yield gCategoryUtilities.openType("experiment");
yield openDetailsView("experiment-3");
let el = gManagerWindow.document.getElementById("detail-experiment-state");
is_element_visible(el, "Experiment state label should be visible.");
if (gIsEnUsLocale) {
Assert.equal(el.value, "Complete");
}
el = gManagerWindow.document.getElementById("detail-experiment-time");
is_element_visible(el, "Experiment time label should be visible.");
if (gIsEnUsLocale) {
Assert.equal(el.value, "5 days ago");
}
el = gManagerWindow.document.getElementById("detail-version");
is_element_hidden(el, "detail-version should be hidden.");
el = gManagerWindow.document.getElementById("detail-creator");
is_element_hidden(el, "detail-creator should be hidden.");
el = gManagerWindow.document.getElementById("detail-experiment-bullet");
is_element_visible(el, "experiment-bullet should be visible.");
});
add_task(function* testCleanup() {
if (gExperiments) {
Services.prefs.clearUserPref("experiments.enabled");