toolkit/mozapps/extensions/test/browser/browser_experiments.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 * http://creativecommons.org/publicdomain/zero/1.0/
michael@0 3 */
michael@0 4
michael@0 5 let {AddonTestUtils} = Components.utils.import("resource://testing-common/AddonManagerTesting.jsm", {});
michael@0 6 let {HttpServer} = Components.utils.import("resource://testing-common/httpd.js", {});
michael@0 7
michael@0 8 let gManagerWindow;
michael@0 9 let gCategoryUtilities;
michael@0 10 let gExperiments;
michael@0 11 let gHttpServer;
michael@0 12
michael@0 13 let gSavedManifestURI;
michael@0 14 let gIsEnUsLocale;
michael@0 15
michael@0 16 const SEC_IN_ONE_DAY = 24 * 60 * 60;
michael@0 17 const MS_IN_ONE_DAY = SEC_IN_ONE_DAY * 1000;
michael@0 18
michael@0 19 function getExperimentAddons() {
michael@0 20 let deferred = Promise.defer();
michael@0 21 AddonManager.getAddonsByTypes(["experiment"], (addons) => {
michael@0 22 deferred.resolve(addons);
michael@0 23 });
michael@0 24 return deferred.promise;
michael@0 25 }
michael@0 26
michael@0 27 function getInstallItem() {
michael@0 28 let doc = gManagerWindow.document;
michael@0 29 let view = doc.getElementById("view-port").selectedPanel;
michael@0 30 let list = doc.getElementById("addon-list");
michael@0 31
michael@0 32 let node = list.firstChild;
michael@0 33 while (node) {
michael@0 34 if (node.getAttribute("status") == "installing") {
michael@0 35 return node;
michael@0 36 }
michael@0 37 node = node.nextSibling;
michael@0 38 }
michael@0 39
michael@0 40 return null;
michael@0 41 }
michael@0 42
michael@0 43 function patchPolicy(policy, data) {
michael@0 44 for (let key of Object.keys(data)) {
michael@0 45 Object.defineProperty(policy, key, {
michael@0 46 value: data[key],
michael@0 47 writable: true,
michael@0 48 });
michael@0 49 }
michael@0 50 }
michael@0 51
michael@0 52 function defineNow(policy, time) {
michael@0 53 patchPolicy(policy, { now: () => new Date(time) });
michael@0 54 }
michael@0 55
michael@0 56 function openDetailsView(aId) {
michael@0 57 let item = get_addon_element(gManagerWindow, aId);
michael@0 58 Assert.ok(item, "Should have got add-on element.");
michael@0 59 is_element_visible(item, "Add-on element should be visible.");
michael@0 60
michael@0 61 EventUtils.synthesizeMouseAtCenter(item, { clickCount: 1 }, gManagerWindow);
michael@0 62 EventUtils.synthesizeMouseAtCenter(item, { clickCount: 2 }, gManagerWindow);
michael@0 63
michael@0 64 let deferred = Promise.defer();
michael@0 65 wait_for_view_load(gManagerWindow, deferred.resolve);
michael@0 66 return deferred.promise;
michael@0 67 }
michael@0 68
michael@0 69 function clickRemoveButton(addonElement) {
michael@0 70 let btn = gManagerWindow.document.getAnonymousElementByAttribute(addonElement, "anonid", "remove-btn");
michael@0 71 if (!btn) {
michael@0 72 return Promise.reject();
michael@0 73 }
michael@0 74
michael@0 75 EventUtils.synthesizeMouseAtCenter(btn, { clickCount: 1 }, gManagerWindow);
michael@0 76 let deferred = Promise.defer();
michael@0 77 setTimeout(deferred.resolve, 0);
michael@0 78 return deferred;
michael@0 79 }
michael@0 80
michael@0 81 function clickUndoButton(addonElement) {
michael@0 82 let btn = gManagerWindow.document.getAnonymousElementByAttribute(addonElement, "anonid", "undo-btn");
michael@0 83 if (!btn) {
michael@0 84 return Promise.reject();
michael@0 85 }
michael@0 86
michael@0 87 EventUtils.synthesizeMouseAtCenter(btn, { clickCount: 1 }, gManagerWindow);
michael@0 88 let deferred = Promise.defer();
michael@0 89 setTimeout(deferred.resolve, 0);
michael@0 90 return deferred;
michael@0 91 }
michael@0 92
michael@0 93 add_task(function* initializeState() {
michael@0 94 gManagerWindow = yield open_manager();
michael@0 95 gCategoryUtilities = new CategoryUtilities(gManagerWindow);
michael@0 96
michael@0 97 registerCleanupFunction(() => {
michael@0 98 Services.prefs.clearUserPref("experiments.enabled");
michael@0 99 if (gHttpServer) {
michael@0 100 gHttpServer.stop(() => {});
michael@0 101 Services.prefs.clearUserPref("experiments.manifest.cert.checkAttributes");
michael@0 102 if (gSavedManifestURI !== undefined) {
michael@0 103 Services.prefs.setCharPref("experments.manifest.uri", gSavedManifestURI);
michael@0 104 }
michael@0 105 }
michael@0 106 if (gExperiments) {
michael@0 107 let tmp = {};
michael@0 108 Cu.import("resource:///modules/experiments/Experiments.jsm", tmp);
michael@0 109 gExperiments._policy = new tmp.Experiments.Policy();
michael@0 110 }
michael@0 111 });
michael@0 112
michael@0 113 let chrome = Cc["@mozilla.org/chrome/chrome-registry;1"].getService(Ci.nsIXULChromeRegistry);
michael@0 114 gIsEnUsLocale = chrome.getSelectedLocale("global") == "en-US";
michael@0 115
michael@0 116 // The Experiments Manager will interfere with us by preventing installs
michael@0 117 // of experiments it doesn't know about. We remove it from the equation
michael@0 118 // because here we are only concerned with core Addon Manager operation,
michael@0 119 // not the superset Experiments Manager has imposed.
michael@0 120 if ("@mozilla.org/browser/experiments-service;1" in Components.classes) {
michael@0 121 let tmp = {};
michael@0 122 Cu.import("resource:///modules/experiments/Experiments.jsm", tmp);
michael@0 123 // There is a race condition between XPCOM service initialization and
michael@0 124 // this test running. We have to initialize the instance first, then
michael@0 125 // uninitialize it to prevent this.
michael@0 126 gExperiments = tmp.Experiments.instance();
michael@0 127 yield gExperiments._mainTask;
michael@0 128 yield gExperiments.uninit();
michael@0 129 }
michael@0 130 });
michael@0 131
michael@0 132 // On an empty profile with no experiments, the experiment category
michael@0 133 // should be hidden.
michael@0 134 add_task(function* testInitialState() {
michael@0 135 Assert.ok(gCategoryUtilities.get("experiment", false), "Experiment tab is defined.");
michael@0 136 Assert.ok(!gCategoryUtilities.isTypeVisible("experiment"), "Experiment tab hidden by default.");
michael@0 137 });
michael@0 138
michael@0 139 add_task(function* testExperimentInfoNotVisible() {
michael@0 140 yield gCategoryUtilities.openType("extension");
michael@0 141 let el = gManagerWindow.document.getElementsByClassName("experiment-info-container")[0];
michael@0 142 is_element_hidden(el, "Experiment info not visible on other types.");
michael@0 143 });
michael@0 144
michael@0 145 // If we have an active experiment, we should see the experiments tab
michael@0 146 // and that tab should have some messages.
michael@0 147 add_task(function* testActiveExperiment() {
michael@0 148 let addon = yield install_addon("addons/browser_experiment1.xpi");
michael@0 149
michael@0 150 Assert.ok(addon.userDisabled, "Add-on is disabled upon initial install.");
michael@0 151 Assert.equal(addon.isActive, false, "Add-on is not active.");
michael@0 152
michael@0 153 Assert.ok(gCategoryUtilities.isTypeVisible("experiment"), "Experiment tab visible.");
michael@0 154
michael@0 155 yield gCategoryUtilities.openType("experiment");
michael@0 156 let el = gManagerWindow.document.getElementsByClassName("experiment-info-container")[0];
michael@0 157 is_element_visible(el, "Experiment info is visible on experiment tab.");
michael@0 158 });
michael@0 159
michael@0 160 add_task(function* testExperimentLearnMore() {
michael@0 161 // Actual URL is irrelevant.
michael@0 162 Services.prefs.setCharPref("toolkit.telemetry.infoURL",
michael@0 163 "http://mochi.test:8888/server.js");
michael@0 164
michael@0 165 yield gCategoryUtilities.openType("experiment");
michael@0 166 let btn = gManagerWindow.document.getElementById("experiments-learn-more");
michael@0 167
michael@0 168 if (!gUseInContentUI) {
michael@0 169 is_element_hidden(btn, "Learn more button hidden if not using in-content UI.");
michael@0 170 Services.prefs.clearUserPref("toolkit.telemetry.infoURL");
michael@0 171
michael@0 172 return;
michael@0 173 }
michael@0 174
michael@0 175 is_element_visible(btn, "Learn more button visible.");
michael@0 176
michael@0 177 let deferred = Promise.defer();
michael@0 178 window.addEventListener("DOMContentLoaded", function onLoad(event) {
michael@0 179 info("Telemetry privacy policy window opened.");
michael@0 180 window.removeEventListener("DOMContentLoaded", onLoad, false);
michael@0 181
michael@0 182 let browser = gBrowser.selectedTab.linkedBrowser;
michael@0 183 let expected = Services.prefs.getCharPref("toolkit.telemetry.infoURL");
michael@0 184 Assert.equal(browser.currentURI.spec, expected, "New tab should have loaded privacy policy.");
michael@0 185 browser.contentWindow.close();
michael@0 186
michael@0 187 Services.prefs.clearUserPref("toolkit.telemetry.infoURL");
michael@0 188
michael@0 189 deferred.resolve();
michael@0 190 }, false);
michael@0 191
michael@0 192 info("Opening telemetry privacy policy.");
michael@0 193 EventUtils.synthesizeMouseAtCenter(btn, {}, gManagerWindow);
michael@0 194
michael@0 195 yield deferred.promise;
michael@0 196 });
michael@0 197
michael@0 198 add_task(function* testOpenPreferences() {
michael@0 199 yield gCategoryUtilities.openType("experiment");
michael@0 200 let btn = gManagerWindow.document.getElementById("experiments-change-telemetry");
michael@0 201 if (!gUseInContentUI) {
michael@0 202 is_element_hidden(btn, "Change telemetry button not enabled in out of window UI.");
michael@0 203 info("Skipping preferences open test because not using in-content UI.");
michael@0 204 return;
michael@0 205 }
michael@0 206
michael@0 207 is_element_visible(btn, "Change telemetry button visible in in-content UI.");
michael@0 208
michael@0 209 let deferred = Promise.defer();
michael@0 210 Services.obs.addObserver(function observer(prefWin, topic, data) {
michael@0 211 Services.obs.removeObserver(observer, "advanced-pane-loaded");
michael@0 212
michael@0 213 info("Advanced preference pane opened.");
michael@0 214
michael@0 215 // We want this test to fail if the preferences pane changes.
michael@0 216 let el = prefWin.document.getElementById("dataChoicesPanel");
michael@0 217 is_element_visible(el);
michael@0 218
michael@0 219 prefWin.close();
michael@0 220 info("Closed preferences pane.");
michael@0 221
michael@0 222 deferred.resolve();
michael@0 223 }, "advanced-pane-loaded", false);
michael@0 224
michael@0 225 info("Loading preferences pane.");
michael@0 226 EventUtils.synthesizeMouseAtCenter(btn, {}, gManagerWindow);
michael@0 227
michael@0 228 yield deferred.promise;
michael@0 229 });
michael@0 230
michael@0 231 add_task(function* testButtonPresence() {
michael@0 232 yield gCategoryUtilities.openType("experiment");
michael@0 233 let item = get_addon_element(gManagerWindow, "test-experiment1@experiments.mozilla.org");
michael@0 234 Assert.ok(item, "Got add-on element.");
michael@0 235 item.parentNode.ensureElementIsVisible(item);
michael@0 236
michael@0 237 let el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
michael@0 238 // Corresponds to the uninstall permission.
michael@0 239 is_element_visible(el, "Remove button is visible.");
michael@0 240 // Corresponds to lack of disable permission.
michael@0 241 el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "disable-btn");
michael@0 242 is_element_hidden(el, "Disable button not visible.");
michael@0 243 // Corresponds to lack of enable permission.
michael@0 244 el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "enable-btn");
michael@0 245 is_element_hidden(el, "Enable button not visible.");
michael@0 246 });
michael@0 247
michael@0 248 // Remove the add-on we've been testing with.
michael@0 249 add_task(function* testCleanup() {
michael@0 250 yield AddonTestUtils.uninstallAddonByID("test-experiment1@experiments.mozilla.org");
michael@0 251 // Verify some conditions, just in case.
michael@0 252 let addons = yield getExperimentAddons();
michael@0 253 Assert.equal(addons.length, 0, "No experiment add-ons are installed.");
michael@0 254 });
michael@0 255
michael@0 256 // The following tests should ideally live in browser/experiments/. However,
michael@0 257 // they rely on some of the helper functions from head.js, which can't easily
michael@0 258 // be consumed from other directories. So, they live here.
michael@0 259
michael@0 260 add_task(function* testActivateExperiment() {
michael@0 261 if (!gExperiments) {
michael@0 262 info("Skipping experiments test because that feature isn't available.");
michael@0 263 return;
michael@0 264 }
michael@0 265
michael@0 266 gHttpServer = new HttpServer();
michael@0 267 gHttpServer.start(-1);
michael@0 268 let root = "http://localhost:" + gHttpServer.identity.primaryPort + "/";
michael@0 269 gHttpServer.registerPathHandler("/manifest", (request, response) => {
michael@0 270 response.setStatusLine(null, 200, "OK");
michael@0 271 response.write(JSON.stringify({
michael@0 272 "version": 1,
michael@0 273 "experiments": [
michael@0 274 {
michael@0 275 id: "experiment-1",
michael@0 276 xpiURL: TESTROOT + "addons/browser_experiment1.xpi",
michael@0 277 xpiHash: "IRRELEVANT",
michael@0 278 startTime: Date.now() / 1000 - 3600,
michael@0 279 endTime: Date.now() / 1000 + 3600,
michael@0 280 maxActiveSeconds: 600,
michael@0 281 appName: [Services.appinfo.name],
michael@0 282 channel: [gExperiments._policy.updatechannel()],
michael@0 283 },
michael@0 284 ],
michael@0 285 }));
michael@0 286 response.processAsync();
michael@0 287 response.finish();
michael@0 288 });
michael@0 289
michael@0 290 Services.prefs.setBoolPref("experiments.manifest.cert.checkAttributes", false);
michael@0 291 gSavedManifestURI = Services.prefs.getCharPref("experiments.manifest.uri");
michael@0 292 Services.prefs.setCharPref("experiments.manifest.uri", root + "manifest");
michael@0 293
michael@0 294 // We need to remove the cache file to help ensure consistent state.
michael@0 295 yield OS.File.remove(gExperiments._cacheFilePath);
michael@0 296
michael@0 297 Services.prefs.setBoolPref("experiments.enabled", true);
michael@0 298
michael@0 299 info("Initializing experiments service.");
michael@0 300 yield gExperiments.init();
michael@0 301 info("Experiments service finished first run.");
michael@0 302
michael@0 303 // Check conditions, just to be sure.
michael@0 304 let experiments = yield gExperiments.getExperiments();
michael@0 305 Assert.equal(experiments.length, 0, "No experiments known to the service.");
michael@0 306
michael@0 307 // This makes testing easier.
michael@0 308 gExperiments._policy.ignoreHashes = true;
michael@0 309
michael@0 310 info("Manually updating experiments manifest.");
michael@0 311 yield gExperiments.updateManifest();
michael@0 312 info("Experiments update complete.");
michael@0 313
michael@0 314 let deferred = Promise.defer();
michael@0 315 gHttpServer.stop(() => {
michael@0 316 gHttpServer = null;
michael@0 317
michael@0 318 info("getting experiment by ID");
michael@0 319 AddonManager.getAddonByID("test-experiment1@experiments.mozilla.org", (addon) => {
michael@0 320 Assert.ok(addon, "Add-on installed via Experiments manager.");
michael@0 321
michael@0 322 deferred.resolve();
michael@0 323 });
michael@0 324 });
michael@0 325
michael@0 326 yield deferred.promise;
michael@0 327
michael@0 328 Assert.ok(gCategoryUtilities.isTypeVisible, "experiment", "Experiment tab visible.");
michael@0 329 yield gCategoryUtilities.openType("experiment");
michael@0 330 let el = gManagerWindow.document.getElementsByClassName("experiment-info-container")[0];
michael@0 331 is_element_visible(el, "Experiment info is visible on experiment tab.");
michael@0 332 });
michael@0 333
michael@0 334 add_task(function testDeactivateExperiment() {
michael@0 335 if (!gExperiments) {
michael@0 336 return;
michael@0 337 }
michael@0 338
michael@0 339 // Fake an empty manifest to purge data from previous manifest.
michael@0 340 yield gExperiments._updateExperiments({
michael@0 341 "version": 1,
michael@0 342 "experiments": [],
michael@0 343 });
michael@0 344
michael@0 345 yield gExperiments.disableExperiment("testing");
michael@0 346
michael@0 347 // We should have a record of the previously-active experiment.
michael@0 348 let experiments = yield gExperiments.getExperiments();
michael@0 349 Assert.equal(experiments.length, 1, "1 experiment is known.");
michael@0 350 Assert.equal(experiments[0].active, false, "Experiment is not active.");
michael@0 351
michael@0 352 // We should have a previous experiment in the add-ons manager.
michael@0 353 let deferred = Promise.defer();
michael@0 354 AddonManager.getAddonsByTypes(["experiment"], (addons) => {
michael@0 355 deferred.resolve(addons);
michael@0 356 });
michael@0 357 let addons = yield deferred.promise;
michael@0 358 Assert.equal(addons.length, 1, "1 experiment add-on known.");
michael@0 359 Assert.ok(addons[0].appDisabled, "It is a previous experiment.");
michael@0 360 Assert.equal(addons[0].id, "experiment-1", "Add-on ID matches expected.");
michael@0 361
michael@0 362 // Verify the UI looks sane.
michael@0 363
michael@0 364 Assert.ok(gCategoryUtilities.isTypeVisible("experiment"), "Experiment tab visible.");
michael@0 365 let item = get_addon_element(gManagerWindow, "experiment-1");
michael@0 366 Assert.ok(item, "Got add-on element.");
michael@0 367 Assert.ok(!item.active, "Element should not be active.");
michael@0 368 item.parentNode.ensureElementIsVisible(item);
michael@0 369
michael@0 370 // User control buttons should not be present because previous experiments
michael@0 371 // should have no permissions.
michael@0 372 let el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "remove-btn");
michael@0 373 is_element_hidden(el, "Remove button is not visible.");
michael@0 374 el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "disable-btn");
michael@0 375 is_element_hidden(el, "Disable button is not visible.");
michael@0 376 el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "enable-btn");
michael@0 377 is_element_hidden(el, "Enable button is not visible.");
michael@0 378 el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "preferences-btn");
michael@0 379 is_element_hidden(el, "Preferences button is not visible.");
michael@0 380 });
michael@0 381
michael@0 382 add_task(function testActivateRealExperiments() {
michael@0 383 if (!gExperiments) {
michael@0 384 info("Skipping experiments test because that feature isn't available.");
michael@0 385 return;
michael@0 386 }
michael@0 387
michael@0 388 yield gExperiments._updateExperiments({
michael@0 389 "version": 1,
michael@0 390 "experiments": [
michael@0 391 {
michael@0 392 id: "experiment-2",
michael@0 393 xpiURL: TESTROOT + "addons/browser_experiment1.xpi",
michael@0 394 xpiHash: "IRRELEVANT",
michael@0 395 startTime: Date.now() / 1000 - 3600,
michael@0 396 endTime: Date.now() / 1000 + 3600,
michael@0 397 maxActiveSeconds: 600,
michael@0 398 appName: [Services.appinfo.name],
michael@0 399 channel: [gExperiments._policy.updatechannel()],
michael@0 400 },
michael@0 401 ],
michael@0 402 });
michael@0 403 yield gExperiments._run();
michael@0 404
michael@0 405 // Check the active experiment.
michael@0 406
michael@0 407 let item = get_addon_element(gManagerWindow, "test-experiment1@experiments.mozilla.org");
michael@0 408 Assert.ok(item, "Got add-on element.");
michael@0 409 item.parentNode.ensureElementIsVisible(item);
michael@0 410
michael@0 411 let el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "experiment-state");
michael@0 412 is_element_visible(el, "Experiment state label should be visible.");
michael@0 413 if (gIsEnUsLocale) {
michael@0 414 Assert.equal(el.value, "Active");
michael@0 415 }
michael@0 416
michael@0 417 el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "experiment-time");
michael@0 418 is_element_visible(el, "Experiment time label should be visible.");
michael@0 419 if (gIsEnUsLocale) {
michael@0 420 Assert.equal(el.value, "Less than a day remaining");
michael@0 421 }
michael@0 422
michael@0 423 el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "error-container");
michael@0 424 is_element_hidden(el, "error-container should be hidden.");
michael@0 425 el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "warning-container");
michael@0 426 is_element_hidden(el, "warning-container should be hidden.");
michael@0 427 el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "pending-container");
michael@0 428 is_element_hidden(el, "pending-container should be hidden.");
michael@0 429 el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "version");
michael@0 430 is_element_hidden(el, "version should be hidden.");
michael@0 431 el = item.ownerDocument.getAnonymousElementByAttribute(item, "class", "disabled-postfix");
michael@0 432 is_element_hidden(el, "disabled-postfix should be hidden.");
michael@0 433 el = item.ownerDocument.getAnonymousElementByAttribute(item, "class", "update-postfix");
michael@0 434 is_element_hidden(el, "update-postfix should be hidden.");
michael@0 435 el = item.ownerDocument.getAnonymousElementByAttribute(item, "class", "experiment-bullet");
michael@0 436 is_element_visible(el, "experiment-bullet should be visible.");
michael@0 437
michael@0 438 // Check the previous experiment.
michael@0 439
michael@0 440 item = get_addon_element(gManagerWindow, "experiment-1");
michael@0 441 Assert.ok(item, "Got add-on element.");
michael@0 442 item.parentNode.ensureElementIsVisible(item);
michael@0 443
michael@0 444 el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "experiment-state");
michael@0 445 is_element_visible(el, "Experiment state label should be visible.");
michael@0 446 if (gIsEnUsLocale) {
michael@0 447 Assert.equal(el.value, "Complete");
michael@0 448 }
michael@0 449
michael@0 450 el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "experiment-time");
michael@0 451 is_element_visible(el, "Experiment time label should be visible.");
michael@0 452 if (gIsEnUsLocale) {
michael@0 453 Assert.equal(el.value, "Less than a day ago");
michael@0 454 }
michael@0 455
michael@0 456 el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "error-container");
michael@0 457 is_element_hidden(el, "error-container should be hidden.");
michael@0 458 el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "warning-container");
michael@0 459 is_element_hidden(el, "warning-container should be hidden.");
michael@0 460 el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "pending-container");
michael@0 461 is_element_hidden(el, "pending-container should be hidden.");
michael@0 462 el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "version");
michael@0 463 is_element_hidden(el, "version should be hidden.");
michael@0 464 el = item.ownerDocument.getAnonymousElementByAttribute(item, "class", "disabled-postfix");
michael@0 465 is_element_hidden(el, "disabled-postfix should be hidden.");
michael@0 466 el = item.ownerDocument.getAnonymousElementByAttribute(item, "class", "update-postfix");
michael@0 467 is_element_hidden(el, "update-postfix should be hidden.");
michael@0 468 el = item.ownerDocument.getAnonymousElementByAttribute(item, "class", "experiment-bullet");
michael@0 469 is_element_visible(el, "experiment-bullet should be visible.");
michael@0 470
michael@0 471 // Install an "older" experiment.
michael@0 472
michael@0 473 yield gExperiments.disableExperiment("experiment-2");
michael@0 474
michael@0 475 let now = Date.now();
michael@0 476 let fakeNow = now - 5 * MS_IN_ONE_DAY;
michael@0 477 defineNow(gExperiments._policy, fakeNow);
michael@0 478
michael@0 479 yield gExperiments._updateExperiments({
michael@0 480 "version": 1,
michael@0 481 "experiments": [
michael@0 482 {
michael@0 483 id: "experiment-3",
michael@0 484 xpiURL: TESTROOT + "addons/browser_experiment1.xpi",
michael@0 485 xpiHash: "IRRELEVANT",
michael@0 486 startTime: fakeNow / 1000 - SEC_IN_ONE_DAY,
michael@0 487 endTime: now / 1000 + 10 * SEC_IN_ONE_DAY,
michael@0 488 maxActiveSeconds: 100 * SEC_IN_ONE_DAY,
michael@0 489 appName: [Services.appinfo.name],
michael@0 490 channel: [gExperiments._policy.updatechannel()],
michael@0 491 },
michael@0 492 ],
michael@0 493 });
michael@0 494 yield gExperiments._run();
michael@0 495
michael@0 496 // Check the active experiment.
michael@0 497
michael@0 498 item = get_addon_element(gManagerWindow, "test-experiment1@experiments.mozilla.org");
michael@0 499 Assert.ok(item, "Got add-on element.");
michael@0 500 item.parentNode.ensureElementIsVisible(item);
michael@0 501
michael@0 502 el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "experiment-state");
michael@0 503 is_element_visible(el, "Experiment state label should be visible.");
michael@0 504 if (gIsEnUsLocale) {
michael@0 505 Assert.equal(el.value, "Active");
michael@0 506 }
michael@0 507
michael@0 508 el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "experiment-time");
michael@0 509 is_element_visible(el, "Experiment time label should be visible.");
michael@0 510 if (gIsEnUsLocale) {
michael@0 511 Assert.equal(el.value, "10 days remaining");
michael@0 512 }
michael@0 513
michael@0 514 // Disable it and check it's previous experiment entry.
michael@0 515
michael@0 516 yield gExperiments.disableExperiment("experiment-3");
michael@0 517
michael@0 518 item = get_addon_element(gManagerWindow, "experiment-3");
michael@0 519 Assert.ok(item, "Got add-on element.");
michael@0 520 item.parentNode.ensureElementIsVisible(item);
michael@0 521
michael@0 522 el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "experiment-state");
michael@0 523 is_element_visible(el, "Experiment state label should be visible.");
michael@0 524 if (gIsEnUsLocale) {
michael@0 525 Assert.equal(el.value, "Complete");
michael@0 526 }
michael@0 527
michael@0 528 el = item.ownerDocument.getAnonymousElementByAttribute(item, "anonid", "experiment-time");
michael@0 529 is_element_visible(el, "Experiment time label should be visible.");
michael@0 530 if (gIsEnUsLocale) {
michael@0 531 Assert.equal(el.value, "5 days ago");
michael@0 532 }
michael@0 533 });
michael@0 534
michael@0 535 add_task(function testDetailView() {
michael@0 536 if (!gExperiments) {
michael@0 537 info("Skipping experiments test because that feature isn't available.");
michael@0 538 return;
michael@0 539 }
michael@0 540
michael@0 541 defineNow(gExperiments._policy, Date.now());
michael@0 542 yield gExperiments._updateExperiments({
michael@0 543 "version": 1,
michael@0 544 "experiments": [
michael@0 545 {
michael@0 546 id: "experiment-4",
michael@0 547 xpiURL: TESTROOT + "addons/browser_experiment1.xpi",
michael@0 548 xpiHash: "IRRELEVANT",
michael@0 549 startTime: Date.now() / 1000 - 3600,
michael@0 550 endTime: Date.now() / 1000 + 3600,
michael@0 551 maxActiveSeconds: 600,
michael@0 552 appName: [Services.appinfo.name],
michael@0 553 channel: [gExperiments._policy.updatechannel()],
michael@0 554 },
michael@0 555 ],
michael@0 556 });
michael@0 557 yield gExperiments._run();
michael@0 558
michael@0 559 // Check active experiment.
michael@0 560
michael@0 561 yield openDetailsView("test-experiment1@experiments.mozilla.org");
michael@0 562
michael@0 563 let el = gManagerWindow.document.getElementById("detail-experiment-state");
michael@0 564 is_element_visible(el, "Experiment state label should be visible.");
michael@0 565 if (gIsEnUsLocale) {
michael@0 566 Assert.equal(el.value, "Active");
michael@0 567 }
michael@0 568
michael@0 569 el = gManagerWindow.document.getElementById("detail-experiment-time");
michael@0 570 is_element_visible(el, "Experiment time label should be visible.");
michael@0 571 if (gIsEnUsLocale) {
michael@0 572 Assert.equal(el.value, "Less than a day remaining");
michael@0 573 }
michael@0 574
michael@0 575 el = gManagerWindow.document.getElementById("detail-version");
michael@0 576 is_element_hidden(el, "detail-version should be hidden.");
michael@0 577 el = gManagerWindow.document.getElementById("detail-creator");
michael@0 578 is_element_hidden(el, "detail-creator should be hidden.");
michael@0 579 el = gManagerWindow.document.getElementById("detail-experiment-bullet");
michael@0 580 is_element_visible(el, "experiment-bullet should be visible.");
michael@0 581
michael@0 582 // Check previous experiment.
michael@0 583
michael@0 584 yield gCategoryUtilities.openType("experiment");
michael@0 585 yield openDetailsView("experiment-3");
michael@0 586
michael@0 587 let el = gManagerWindow.document.getElementById("detail-experiment-state");
michael@0 588 is_element_visible(el, "Experiment state label should be visible.");
michael@0 589 if (gIsEnUsLocale) {
michael@0 590 Assert.equal(el.value, "Complete");
michael@0 591 }
michael@0 592
michael@0 593 el = gManagerWindow.document.getElementById("detail-experiment-time");
michael@0 594 is_element_visible(el, "Experiment time label should be visible.");
michael@0 595 if (gIsEnUsLocale) {
michael@0 596 Assert.equal(el.value, "5 days ago");
michael@0 597 }
michael@0 598
michael@0 599 el = gManagerWindow.document.getElementById("detail-version");
michael@0 600 is_element_hidden(el, "detail-version should be hidden.");
michael@0 601 el = gManagerWindow.document.getElementById("detail-creator");
michael@0 602 is_element_hidden(el, "detail-creator should be hidden.");
michael@0 603 el = gManagerWindow.document.getElementById("detail-experiment-bullet");
michael@0 604 is_element_visible(el, "experiment-bullet should be visible.");
michael@0 605 });
michael@0 606
michael@0 607 add_task(function* testRemoveAndUndo() {
michael@0 608 if (!gExperiments) {
michael@0 609 info("Skipping experiments test because that feature isn't available.");
michael@0 610 return;
michael@0 611 }
michael@0 612
michael@0 613 yield gCategoryUtilities.openType("experiment");
michael@0 614
michael@0 615 let addon = get_addon_element(gManagerWindow, "test-experiment1@experiments.mozilla.org");
michael@0 616 Assert.ok(addon, "Got add-on element.");
michael@0 617
michael@0 618 yield clickRemoveButton(addon);
michael@0 619 addon.parentNode.ensureElementIsVisible(addon);
michael@0 620
michael@0 621 let el = gManagerWindow.document.getAnonymousElementByAttribute(addon, "class", "pending");
michael@0 622 is_element_visible(el, "Uninstall undo information should be visible.");
michael@0 623
michael@0 624 yield clickUndoButton(addon);
michael@0 625 addon = get_addon_element(gManagerWindow, "test-experiment1@experiments.mozilla.org");
michael@0 626 Assert.ok(addon, "Got add-on element.");
michael@0 627 });
michael@0 628
michael@0 629 add_task(function* testCleanup() {
michael@0 630 if (gExperiments) {
michael@0 631 Services.prefs.clearUserPref("experiments.enabled");
michael@0 632 Services.prefs.clearUserPref("experiments.manifest.cert.checkAttributes");
michael@0 633 Services.prefs.setCharPref("experiments.manifest.uri", gSavedManifestURI);
michael@0 634
michael@0 635 // We perform the uninit/init cycle to purge any leftover state.
michael@0 636 yield OS.File.remove(gExperiments._cacheFilePath);
michael@0 637 yield gExperiments.uninit();
michael@0 638 yield gExperiments.init();
michael@0 639 }
michael@0 640
michael@0 641 // Check post-conditions.
michael@0 642 let addons = yield getExperimentAddons();
michael@0 643 Assert.equal(addons.length, 0, "No experiment add-ons are installed.");
michael@0 644
michael@0 645 yield close_manager(gManagerWindow);
michael@0 646 });

mercurial