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: let {AddonTestUtils} = Components.utils.import("resource://testing-common/AddonManagerTesting.jsm", {}); michael@0: let {HttpServer} = Components.utils.import("resource://testing-common/httpd.js", {}); michael@0: michael@0: let gManagerWindow; michael@0: let gCategoryUtilities; michael@0: let gExperiments; michael@0: let gHttpServer; michael@0: michael@0: let gSavedManifestURI; michael@0: let gIsEnUsLocale; michael@0: michael@0: const SEC_IN_ONE_DAY = 24 * 60 * 60; michael@0: const MS_IN_ONE_DAY = SEC_IN_ONE_DAY * 1000; michael@0: michael@0: function getExperimentAddons() { michael@0: let deferred = Promise.defer(); michael@0: AddonManager.getAddonsByTypes(["experiment"], (addons) => { michael@0: deferred.resolve(addons); michael@0: }); michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function getInstallItem() { michael@0: let doc = gManagerWindow.document; michael@0: let view = doc.getElementById("view-port").selectedPanel; michael@0: let list = doc.getElementById("addon-list"); michael@0: michael@0: let node = list.firstChild; michael@0: while (node) { michael@0: if (node.getAttribute("status") == "installing") { michael@0: return node; michael@0: } michael@0: node = node.nextSibling; michael@0: } michael@0: michael@0: return null; michael@0: } michael@0: michael@0: function patchPolicy(policy, data) { michael@0: for (let key of Object.keys(data)) { michael@0: Object.defineProperty(policy, key, { michael@0: value: data[key], michael@0: writable: true, michael@0: }); michael@0: } michael@0: } michael@0: michael@0: function defineNow(policy, time) { michael@0: patchPolicy(policy, { now: () => new Date(time) }); michael@0: } michael@0: michael@0: function openDetailsView(aId) { michael@0: let item = get_addon_element(gManagerWindow, aId); michael@0: Assert.ok(item, "Should have got add-on element."); michael@0: is_element_visible(item, "Add-on element should be visible."); michael@0: michael@0: EventUtils.synthesizeMouseAtCenter(item, { clickCount: 1 }, gManagerWindow); michael@0: EventUtils.synthesizeMouseAtCenter(item, { clickCount: 2 }, gManagerWindow); michael@0: michael@0: let deferred = Promise.defer(); michael@0: wait_for_view_load(gManagerWindow, deferred.resolve); michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function clickRemoveButton(addonElement) { michael@0: let btn = gManagerWindow.document.getAnonymousElementByAttribute(addonElement, "anonid", "remove-btn"); michael@0: if (!btn) { michael@0: return Promise.reject(); michael@0: } michael@0: michael@0: EventUtils.synthesizeMouseAtCenter(btn, { clickCount: 1 }, gManagerWindow); michael@0: let deferred = Promise.defer(); michael@0: setTimeout(deferred.resolve, 0); michael@0: return deferred; michael@0: } michael@0: michael@0: function clickUndoButton(addonElement) { michael@0: let btn = gManagerWindow.document.getAnonymousElementByAttribute(addonElement, "anonid", "undo-btn"); michael@0: if (!btn) { michael@0: return Promise.reject(); michael@0: } michael@0: michael@0: EventUtils.synthesizeMouseAtCenter(btn, { clickCount: 1 }, gManagerWindow); michael@0: let deferred = Promise.defer(); michael@0: setTimeout(deferred.resolve, 0); michael@0: return deferred; michael@0: } michael@0: michael@0: add_task(function* initializeState() { michael@0: gManagerWindow = yield open_manager(); michael@0: gCategoryUtilities = new CategoryUtilities(gManagerWindow); michael@0: michael@0: registerCleanupFunction(() => { michael@0: Services.prefs.clearUserPref("experiments.enabled"); michael@0: if (gHttpServer) { michael@0: gHttpServer.stop(() => {}); michael@0: Services.prefs.clearUserPref("experiments.manifest.cert.checkAttributes"); michael@0: if (gSavedManifestURI !== undefined) { michael@0: Services.prefs.setCharPref("experments.manifest.uri", gSavedManifestURI); michael@0: } michael@0: } michael@0: if (gExperiments) { michael@0: let tmp = {}; michael@0: Cu.import("resource:///modules/experiments/Experiments.jsm", tmp); michael@0: gExperiments._policy = new tmp.Experiments.Policy(); michael@0: } michael@0: }); michael@0: michael@0: let chrome = Cc["@mozilla.org/chrome/chrome-registry;1"].getService(Ci.nsIXULChromeRegistry); michael@0: gIsEnUsLocale = chrome.getSelectedLocale("global") == "en-US"; michael@0: michael@0: // The Experiments Manager will interfere with us by preventing installs michael@0: // of experiments it doesn't know about. We remove it from the equation michael@0: // because here we are only concerned with core Addon Manager operation, michael@0: // not the superset Experiments Manager has imposed. michael@0: if ("@mozilla.org/browser/experiments-service;1" in Components.classes) { michael@0: let tmp = {}; michael@0: Cu.import("resource:///modules/experiments/Experiments.jsm", tmp); michael@0: // There is a race condition between XPCOM service initialization and michael@0: // this test running. We have to initialize the instance first, then michael@0: // uninitialize it to prevent this. michael@0: gExperiments = tmp.Experiments.instance(); michael@0: yield gExperiments._mainTask; michael@0: yield gExperiments.uninit(); michael@0: } michael@0: }); michael@0: michael@0: // On an empty profile with no experiments, the experiment category michael@0: // should be hidden. michael@0: add_task(function* testInitialState() { michael@0: Assert.ok(gCategoryUtilities.get("experiment", false), "Experiment tab is defined."); michael@0: Assert.ok(!gCategoryUtilities.isTypeVisible("experiment"), "Experiment tab hidden by default."); michael@0: }); michael@0: michael@0: add_task(function* testExperimentInfoNotVisible() { michael@0: yield gCategoryUtilities.openType("extension"); michael@0: let el = gManagerWindow.document.getElementsByClassName("experiment-info-container")[0]; michael@0: is_element_hidden(el, "Experiment info not visible on other types."); michael@0: }); michael@0: michael@0: // If we have an active experiment, we should see the experiments tab michael@0: // and that tab should have some messages. michael@0: add_task(function* testActiveExperiment() { michael@0: let addon = yield install_addon("addons/browser_experiment1.xpi"); michael@0: michael@0: Assert.ok(addon.userDisabled, "Add-on is disabled upon initial install."); michael@0: Assert.equal(addon.isActive, false, "Add-on is not active."); michael@0: michael@0: Assert.ok(gCategoryUtilities.isTypeVisible("experiment"), "Experiment tab visible."); michael@0: michael@0: yield gCategoryUtilities.openType("experiment"); michael@0: let el = gManagerWindow.document.getElementsByClassName("experiment-info-container")[0]; michael@0: is_element_visible(el, "Experiment info is visible on experiment tab."); michael@0: }); michael@0: michael@0: add_task(function* testExperimentLearnMore() { michael@0: // Actual URL is irrelevant. michael@0: Services.prefs.setCharPref("toolkit.telemetry.infoURL", michael@0: "http://mochi.test:8888/server.js"); michael@0: michael@0: yield gCategoryUtilities.openType("experiment"); michael@0: let btn = gManagerWindow.document.getElementById("experiments-learn-more"); michael@0: michael@0: if (!gUseInContentUI) { michael@0: is_element_hidden(btn, "Learn more button hidden if not using in-content UI."); michael@0: Services.prefs.clearUserPref("toolkit.telemetry.infoURL"); michael@0: michael@0: return; michael@0: } michael@0: michael@0: is_element_visible(btn, "Learn more button visible."); michael@0: michael@0: let deferred = Promise.defer(); michael@0: window.addEventListener("DOMContentLoaded", function onLoad(event) { michael@0: info("Telemetry privacy policy window opened."); michael@0: window.removeEventListener("DOMContentLoaded", onLoad, false); michael@0: michael@0: let browser = gBrowser.selectedTab.linkedBrowser; michael@0: let expected = Services.prefs.getCharPref("toolkit.telemetry.infoURL"); michael@0: Assert.equal(browser.currentURI.spec, expected, "New tab should have loaded privacy policy."); michael@0: browser.contentWindow.close(); michael@0: michael@0: Services.prefs.clearUserPref("toolkit.telemetry.infoURL"); michael@0: michael@0: deferred.resolve(); michael@0: }, false); michael@0: michael@0: info("Opening telemetry privacy policy."); michael@0: EventUtils.synthesizeMouseAtCenter(btn, {}, gManagerWindow); michael@0: michael@0: yield deferred.promise; michael@0: }); michael@0: michael@0: add_task(function* testOpenPreferences() { michael@0: yield gCategoryUtilities.openType("experiment"); michael@0: let btn = gManagerWindow.document.getElementById("experiments-change-telemetry"); michael@0: if (!gUseInContentUI) { michael@0: is_element_hidden(btn, "Change telemetry button not enabled in out of window UI."); michael@0: info("Skipping preferences open test because not using in-content UI."); michael@0: return; michael@0: } michael@0: michael@0: is_element_visible(btn, "Change telemetry button visible in in-content UI."); michael@0: michael@0: let deferred = Promise.defer(); michael@0: Services.obs.addObserver(function observer(prefWin, topic, data) { michael@0: Services.obs.removeObserver(observer, "advanced-pane-loaded"); michael@0: michael@0: info("Advanced preference pane opened."); michael@0: michael@0: // We want this test to fail if the preferences pane changes. michael@0: let el = prefWin.document.getElementById("dataChoicesPanel"); michael@0: is_element_visible(el); michael@0: michael@0: prefWin.close(); michael@0: info("Closed preferences pane."); michael@0: michael@0: deferred.resolve(); michael@0: }, "advanced-pane-loaded", false); michael@0: michael@0: info("Loading preferences pane."); michael@0: EventUtils.synthesizeMouseAtCenter(btn, {}, gManagerWindow); michael@0: michael@0: yield deferred.promise; michael@0: }); michael@0: michael@0: add_task(function* testButtonPresence() { michael@0: yield gCategoryUtilities.openType("experiment"); michael@0: let item = get_addon_element(gManagerWindow, "test-experiment1@experiments.mozilla.org"); michael@0: Assert.ok(item, "Got add-on element."); michael@0: item.parentNode.ensureElementIsVisible(item); michael@0: michael@0: let el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn"); michael@0: // Corresponds to the uninstall permission. michael@0: is_element_visible(el, "Remove button is visible."); michael@0: // Corresponds to lack of disable permission. michael@0: el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "disable-btn"); michael@0: is_element_hidden(el, "Disable button not visible."); michael@0: // Corresponds to lack of enable permission. michael@0: el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "enable-btn"); michael@0: is_element_hidden(el, "Enable button not visible."); michael@0: }); michael@0: michael@0: // Remove the add-on we've been testing with. michael@0: add_task(function* testCleanup() { michael@0: yield AddonTestUtils.uninstallAddonByID("test-experiment1@experiments.mozilla.org"); michael@0: // Verify some conditions, just in case. michael@0: let addons = yield getExperimentAddons(); michael@0: Assert.equal(addons.length, 0, "No experiment add-ons are installed."); michael@0: }); michael@0: michael@0: // The following tests should ideally live in browser/experiments/. However, michael@0: // they rely on some of the helper functions from head.js, which can't easily michael@0: // be consumed from other directories. So, they live here. michael@0: michael@0: add_task(function* testActivateExperiment() { michael@0: if (!gExperiments) { michael@0: info("Skipping experiments test because that feature isn't available."); michael@0: return; michael@0: } michael@0: michael@0: gHttpServer = new HttpServer(); michael@0: gHttpServer.start(-1); michael@0: let root = "http://localhost:" + gHttpServer.identity.primaryPort + "/"; michael@0: gHttpServer.registerPathHandler("/manifest", (request, response) => { michael@0: response.setStatusLine(null, 200, "OK"); michael@0: response.write(JSON.stringify({ michael@0: "version": 1, michael@0: "experiments": [ michael@0: { michael@0: id: "experiment-1", michael@0: xpiURL: TESTROOT + "addons/browser_experiment1.xpi", michael@0: xpiHash: "IRRELEVANT", michael@0: startTime: Date.now() / 1000 - 3600, michael@0: endTime: Date.now() / 1000 + 3600, michael@0: maxActiveSeconds: 600, michael@0: appName: [Services.appinfo.name], michael@0: channel: [gExperiments._policy.updatechannel()], michael@0: }, michael@0: ], michael@0: })); michael@0: response.processAsync(); michael@0: response.finish(); michael@0: }); michael@0: michael@0: Services.prefs.setBoolPref("experiments.manifest.cert.checkAttributes", false); michael@0: gSavedManifestURI = Services.prefs.getCharPref("experiments.manifest.uri"); michael@0: Services.prefs.setCharPref("experiments.manifest.uri", root + "manifest"); michael@0: michael@0: // We need to remove the cache file to help ensure consistent state. michael@0: yield OS.File.remove(gExperiments._cacheFilePath); michael@0: michael@0: Services.prefs.setBoolPref("experiments.enabled", true); michael@0: michael@0: info("Initializing experiments service."); michael@0: yield gExperiments.init(); michael@0: info("Experiments service finished first run."); michael@0: michael@0: // Check conditions, just to be sure. michael@0: let experiments = yield gExperiments.getExperiments(); michael@0: Assert.equal(experiments.length, 0, "No experiments known to the service."); michael@0: michael@0: // This makes testing easier. michael@0: gExperiments._policy.ignoreHashes = true; michael@0: michael@0: info("Manually updating experiments manifest."); michael@0: yield gExperiments.updateManifest(); michael@0: info("Experiments update complete."); michael@0: michael@0: let deferred = Promise.defer(); michael@0: gHttpServer.stop(() => { michael@0: gHttpServer = null; michael@0: michael@0: info("getting experiment by ID"); michael@0: AddonManager.getAddonByID("test-experiment1@experiments.mozilla.org", (addon) => { michael@0: Assert.ok(addon, "Add-on installed via Experiments manager."); michael@0: michael@0: deferred.resolve(); michael@0: }); michael@0: }); michael@0: michael@0: yield deferred.promise; michael@0: michael@0: Assert.ok(gCategoryUtilities.isTypeVisible, "experiment", "Experiment tab visible."); michael@0: yield gCategoryUtilities.openType("experiment"); michael@0: let el = gManagerWindow.document.getElementsByClassName("experiment-info-container")[0]; michael@0: is_element_visible(el, "Experiment info is visible on experiment tab."); michael@0: }); michael@0: michael@0: add_task(function testDeactivateExperiment() { michael@0: if (!gExperiments) { michael@0: return; michael@0: } michael@0: michael@0: // Fake an empty manifest to purge data from previous manifest. michael@0: yield gExperiments._updateExperiments({ michael@0: "version": 1, michael@0: "experiments": [], michael@0: }); michael@0: michael@0: yield gExperiments.disableExperiment("testing"); michael@0: michael@0: // We should have a record of the previously-active experiment. michael@0: let experiments = yield gExperiments.getExperiments(); michael@0: Assert.equal(experiments.length, 1, "1 experiment is known."); michael@0: Assert.equal(experiments[0].active, false, "Experiment is not active."); michael@0: michael@0: // We should have a previous experiment in the add-ons manager. michael@0: let deferred = Promise.defer(); michael@0: AddonManager.getAddonsByTypes(["experiment"], (addons) => { michael@0: deferred.resolve(addons); michael@0: }); michael@0: let addons = yield deferred.promise; michael@0: Assert.equal(addons.length, 1, "1 experiment add-on known."); michael@0: Assert.ok(addons[0].appDisabled, "It is a previous experiment."); michael@0: Assert.equal(addons[0].id, "experiment-1", "Add-on ID matches expected."); michael@0: michael@0: // Verify the UI looks sane. michael@0: michael@0: Assert.ok(gCategoryUtilities.isTypeVisible("experiment"), "Experiment tab visible."); michael@0: let item = get_addon_element(gManagerWindow, "experiment-1"); michael@0: Assert.ok(item, "Got add-on element."); michael@0: Assert.ok(!item.active, "Element should not be active."); michael@0: item.parentNode.ensureElementIsVisible(item); michael@0: michael@0: // User control buttons should not be present because previous experiments michael@0: // should have no permissions. michael@0: let el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn"); michael@0: is_element_hidden(el, "Remove button is not visible."); michael@0: el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "disable-btn"); michael@0: is_element_hidden(el, "Disable button is not visible."); michael@0: el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "enable-btn"); michael@0: is_element_hidden(el, "Enable button is not visible."); michael@0: el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "preferences-btn"); michael@0: is_element_hidden(el, "Preferences button is not visible."); michael@0: }); michael@0: michael@0: add_task(function testActivateRealExperiments() { michael@0: if (!gExperiments) { michael@0: info("Skipping experiments test because that feature isn't available."); michael@0: return; michael@0: } michael@0: michael@0: yield gExperiments._updateExperiments({ michael@0: "version": 1, michael@0: "experiments": [ michael@0: { michael@0: id: "experiment-2", michael@0: xpiURL: TESTROOT + "addons/browser_experiment1.xpi", michael@0: xpiHash: "IRRELEVANT", michael@0: startTime: Date.now() / 1000 - 3600, michael@0: endTime: Date.now() / 1000 + 3600, michael@0: maxActiveSeconds: 600, michael@0: appName: [Services.appinfo.name], michael@0: channel: [gExperiments._policy.updatechannel()], michael@0: }, michael@0: ], michael@0: }); michael@0: yield gExperiments._run(); michael@0: michael@0: // Check the active experiment. michael@0: michael@0: let item = get_addon_element(gManagerWindow, "test-experiment1@experiments.mozilla.org"); michael@0: Assert.ok(item, "Got add-on element."); michael@0: item.parentNode.ensureElementIsVisible(item); michael@0: michael@0: let el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "experiment-state"); michael@0: is_element_visible(el, "Experiment state label should be visible."); michael@0: if (gIsEnUsLocale) { michael@0: Assert.equal(el.value, "Active"); michael@0: } michael@0: michael@0: el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "experiment-time"); michael@0: is_element_visible(el, "Experiment time label should be visible."); michael@0: if (gIsEnUsLocale) { michael@0: Assert.equal(el.value, "Less than a day remaining"); michael@0: } michael@0: michael@0: el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "error-container"); michael@0: is_element_hidden(el, "error-container should be hidden."); michael@0: el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "warning-container"); michael@0: is_element_hidden(el, "warning-container should be hidden."); michael@0: el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "pending-container"); michael@0: is_element_hidden(el, "pending-container should be hidden."); michael@0: el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "version"); michael@0: is_element_hidden(el, "version should be hidden."); michael@0: el = item.ownerDocument.getAnonymousElementByAttribute(item, "class", "disabled-postfix"); michael@0: is_element_hidden(el, "disabled-postfix should be hidden."); michael@0: el = item.ownerDocument.getAnonymousElementByAttribute(item, "class", "update-postfix"); michael@0: is_element_hidden(el, "update-postfix should be hidden."); michael@0: el = item.ownerDocument.getAnonymousElementByAttribute(item, "class", "experiment-bullet"); michael@0: is_element_visible(el, "experiment-bullet should be visible."); michael@0: michael@0: // Check the previous experiment. michael@0: michael@0: item = get_addon_element(gManagerWindow, "experiment-1"); michael@0: Assert.ok(item, "Got add-on element."); michael@0: item.parentNode.ensureElementIsVisible(item); michael@0: michael@0: el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "experiment-state"); michael@0: is_element_visible(el, "Experiment state label should be visible."); michael@0: if (gIsEnUsLocale) { michael@0: Assert.equal(el.value, "Complete"); michael@0: } michael@0: michael@0: el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "experiment-time"); michael@0: is_element_visible(el, "Experiment time label should be visible."); michael@0: if (gIsEnUsLocale) { michael@0: Assert.equal(el.value, "Less than a day ago"); michael@0: } michael@0: michael@0: el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "error-container"); michael@0: is_element_hidden(el, "error-container should be hidden."); michael@0: el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "warning-container"); michael@0: is_element_hidden(el, "warning-container should be hidden."); michael@0: el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "pending-container"); michael@0: is_element_hidden(el, "pending-container should be hidden."); michael@0: el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "version"); michael@0: is_element_hidden(el, "version should be hidden."); michael@0: el = item.ownerDocument.getAnonymousElementByAttribute(item, "class", "disabled-postfix"); michael@0: is_element_hidden(el, "disabled-postfix should be hidden."); michael@0: el = item.ownerDocument.getAnonymousElementByAttribute(item, "class", "update-postfix"); michael@0: is_element_hidden(el, "update-postfix should be hidden."); michael@0: el = item.ownerDocument.getAnonymousElementByAttribute(item, "class", "experiment-bullet"); michael@0: is_element_visible(el, "experiment-bullet should be visible."); michael@0: michael@0: // Install an "older" experiment. michael@0: michael@0: yield gExperiments.disableExperiment("experiment-2"); michael@0: michael@0: let now = Date.now(); michael@0: let fakeNow = now - 5 * MS_IN_ONE_DAY; michael@0: defineNow(gExperiments._policy, fakeNow); michael@0: michael@0: yield gExperiments._updateExperiments({ michael@0: "version": 1, michael@0: "experiments": [ michael@0: { michael@0: id: "experiment-3", michael@0: xpiURL: TESTROOT + "addons/browser_experiment1.xpi", michael@0: xpiHash: "IRRELEVANT", michael@0: startTime: fakeNow / 1000 - SEC_IN_ONE_DAY, michael@0: endTime: now / 1000 + 10 * SEC_IN_ONE_DAY, michael@0: maxActiveSeconds: 100 * SEC_IN_ONE_DAY, michael@0: appName: [Services.appinfo.name], michael@0: channel: [gExperiments._policy.updatechannel()], michael@0: }, michael@0: ], michael@0: }); michael@0: yield gExperiments._run(); michael@0: michael@0: // Check the active experiment. michael@0: michael@0: item = get_addon_element(gManagerWindow, "test-experiment1@experiments.mozilla.org"); michael@0: Assert.ok(item, "Got add-on element."); michael@0: item.parentNode.ensureElementIsVisible(item); michael@0: michael@0: el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "experiment-state"); michael@0: is_element_visible(el, "Experiment state label should be visible."); michael@0: if (gIsEnUsLocale) { michael@0: Assert.equal(el.value, "Active"); michael@0: } michael@0: michael@0: el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "experiment-time"); michael@0: is_element_visible(el, "Experiment time label should be visible."); michael@0: if (gIsEnUsLocale) { michael@0: Assert.equal(el.value, "10 days remaining"); michael@0: } michael@0: michael@0: // Disable it and check it's previous experiment entry. michael@0: michael@0: yield gExperiments.disableExperiment("experiment-3"); michael@0: michael@0: item = get_addon_element(gManagerWindow, "experiment-3"); michael@0: Assert.ok(item, "Got add-on element."); michael@0: item.parentNode.ensureElementIsVisible(item); michael@0: michael@0: el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "experiment-state"); michael@0: is_element_visible(el, "Experiment state label should be visible."); michael@0: if (gIsEnUsLocale) { michael@0: Assert.equal(el.value, "Complete"); michael@0: } michael@0: michael@0: el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "experiment-time"); michael@0: is_element_visible(el, "Experiment time label should be visible."); michael@0: if (gIsEnUsLocale) { michael@0: Assert.equal(el.value, "5 days ago"); michael@0: } michael@0: }); michael@0: michael@0: add_task(function testDetailView() { michael@0: if (!gExperiments) { michael@0: info("Skipping experiments test because that feature isn't available."); michael@0: return; michael@0: } michael@0: michael@0: defineNow(gExperiments._policy, Date.now()); michael@0: yield gExperiments._updateExperiments({ michael@0: "version": 1, michael@0: "experiments": [ michael@0: { michael@0: id: "experiment-4", michael@0: xpiURL: TESTROOT + "addons/browser_experiment1.xpi", michael@0: xpiHash: "IRRELEVANT", michael@0: startTime: Date.now() / 1000 - 3600, michael@0: endTime: Date.now() / 1000 + 3600, michael@0: maxActiveSeconds: 600, michael@0: appName: [Services.appinfo.name], michael@0: channel: [gExperiments._policy.updatechannel()], michael@0: }, michael@0: ], michael@0: }); michael@0: yield gExperiments._run(); michael@0: michael@0: // Check active experiment. michael@0: michael@0: yield openDetailsView("test-experiment1@experiments.mozilla.org"); michael@0: michael@0: let el = gManagerWindow.document.getElementById("detail-experiment-state"); michael@0: is_element_visible(el, "Experiment state label should be visible."); michael@0: if (gIsEnUsLocale) { michael@0: Assert.equal(el.value, "Active"); michael@0: } michael@0: michael@0: el = gManagerWindow.document.getElementById("detail-experiment-time"); michael@0: is_element_visible(el, "Experiment time label should be visible."); michael@0: if (gIsEnUsLocale) { michael@0: Assert.equal(el.value, "Less than a day remaining"); michael@0: } michael@0: michael@0: el = gManagerWindow.document.getElementById("detail-version"); michael@0: is_element_hidden(el, "detail-version should be hidden."); michael@0: el = gManagerWindow.document.getElementById("detail-creator"); michael@0: is_element_hidden(el, "detail-creator should be hidden."); michael@0: el = gManagerWindow.document.getElementById("detail-experiment-bullet"); michael@0: is_element_visible(el, "experiment-bullet should be visible."); michael@0: michael@0: // Check previous experiment. michael@0: michael@0: yield gCategoryUtilities.openType("experiment"); michael@0: yield openDetailsView("experiment-3"); michael@0: michael@0: let el = gManagerWindow.document.getElementById("detail-experiment-state"); michael@0: is_element_visible(el, "Experiment state label should be visible."); michael@0: if (gIsEnUsLocale) { michael@0: Assert.equal(el.value, "Complete"); michael@0: } michael@0: michael@0: el = gManagerWindow.document.getElementById("detail-experiment-time"); michael@0: is_element_visible(el, "Experiment time label should be visible."); michael@0: if (gIsEnUsLocale) { michael@0: Assert.equal(el.value, "5 days ago"); michael@0: } michael@0: michael@0: el = gManagerWindow.document.getElementById("detail-version"); michael@0: is_element_hidden(el, "detail-version should be hidden."); michael@0: el = gManagerWindow.document.getElementById("detail-creator"); michael@0: is_element_hidden(el, "detail-creator should be hidden."); michael@0: el = gManagerWindow.document.getElementById("detail-experiment-bullet"); michael@0: is_element_visible(el, "experiment-bullet should be visible."); michael@0: }); michael@0: michael@0: add_task(function* testRemoveAndUndo() { michael@0: if (!gExperiments) { michael@0: info("Skipping experiments test because that feature isn't available."); michael@0: return; michael@0: } michael@0: michael@0: yield gCategoryUtilities.openType("experiment"); michael@0: michael@0: let addon = get_addon_element(gManagerWindow, "test-experiment1@experiments.mozilla.org"); michael@0: Assert.ok(addon, "Got add-on element."); michael@0: michael@0: yield clickRemoveButton(addon); michael@0: addon.parentNode.ensureElementIsVisible(addon); michael@0: michael@0: let el = gManagerWindow.document.getAnonymousElementByAttribute(addon, "class", "pending"); michael@0: is_element_visible(el, "Uninstall undo information should be visible."); michael@0: michael@0: yield clickUndoButton(addon); michael@0: addon = get_addon_element(gManagerWindow, "test-experiment1@experiments.mozilla.org"); michael@0: Assert.ok(addon, "Got add-on element."); michael@0: }); michael@0: michael@0: add_task(function* testCleanup() { michael@0: if (gExperiments) { michael@0: Services.prefs.clearUserPref("experiments.enabled"); michael@0: Services.prefs.clearUserPref("experiments.manifest.cert.checkAttributes"); michael@0: Services.prefs.setCharPref("experiments.manifest.uri", gSavedManifestURI); michael@0: michael@0: // We perform the uninit/init cycle to purge any leftover state. michael@0: yield OS.File.remove(gExperiments._cacheFilePath); michael@0: yield gExperiments.uninit(); michael@0: yield gExperiments.init(); michael@0: } michael@0: michael@0: // Check post-conditions. michael@0: let addons = yield getExperimentAddons(); michael@0: Assert.equal(addons.length, 0, "No experiment add-ons are installed."); michael@0: michael@0: yield close_manager(gManagerWindow); michael@0: });