Bug 1458308 - Tests for migration and UI of app.update.auto pref r=rstrong
☠☠ backed out by f8c4d4c647ae ☠ ☠
authorKirk Steuber <ksteuber@mozilla.com>
Mon, 29 Oct 2018 21:36:04 +0000
changeset 499964 4bf34689d4b62ed8299e1239ec9c01a4a6833e38
parent 499963 51e675ce6c5626ee1feb5e125c7aa16867e5f213
child 499965 c975dd62f9d3a29afe36a1910f0f19a0cf8d1da2
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrstrong
bugs1458308
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1458308 - Tests for migration and UI of app.update.auto pref r=rstrong Depends on D4593 Differential Revision: https://phabricator.services.mozilla.com/D4594
toolkit/mozapps/update/tests/browser/browser.ini
toolkit/mozapps/update/tests/browser/browser_updateAutoPrefUI.js
toolkit/mozapps/update/tests/data/shared.js
toolkit/mozapps/update/tests/unit_aus_update/updateAutoPrefMigrate.js
toolkit/mozapps/update/tests/unit_aus_update/xpcshell.ini
--- a/toolkit/mozapps/update/tests/browser/browser.ini
+++ b/toolkit/mozapps/update/tests/browser/browser.ini
@@ -1,16 +1,19 @@
 [DEFAULT]
 tags = appupdate
 support-files =
   head.js
   downloadPage.html
   testConstants.js
 
 [browser_TelemetryUpdatePing.js]
+[browser_updateAutoPrefUI.js]
+skip-if = os != 'win'
+reason = Tests that update config is properly written to file, which is a Windows-only feature
 [browser_updatesBackgroundWindow.js]
 [browser_updatesBackgroundWindowFailures.js]
 skip-if = verify
 [browser_updatesBasicPrompt.js]
 skip-if = asan
 reason = Bug 1168003
 [browser_updatesBasicPromptNoStaging.js]
 [browser_updatesCantApply.js]
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/update/tests/browser/browser_updateAutoPrefUI.js
@@ -0,0 +1,55 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+ChromeUtils.import("resource://gre/modules/osfile.jsm", this);
+
+// Changes, then verifies the value of app.update.auto via the about:preferences
+// UI. Requires a tab with about:preferences open to be passed in.
+async function changeAndVerifyPref(tab, newConfigValue) {
+  await ContentTask.spawn(tab.linkedBrowser, {newConfigValue}, async function({newConfigValue}) {
+    let radioId = newConfigValue ? "autoDesktop" : "manualDesktop";
+    let radioElement = content.document.getElementById(radioId);
+    radioElement.click();
+  });
+
+  // At this point, we really need to wait for the change to finish being
+  // written to the disk before we go to verify anything. Unfortunately, it
+  // would be difficult to check for quick changes to the attributes of the
+  // about:preferences controls (to wait for the controls to be disabled and
+  // re-enabled). So instead, just start the verification by asking the
+  // Application Update Service for the value of app.update.auto. It already
+  // serializes reads and writes to the app update config file, so this will not
+  // resolve until the file write is complete.
+
+  let configValueRead = await gAUS.getAutoUpdateIsEnabled();
+  is(configValueRead, newConfigValue,
+     "Value returned should have matched the expected value");
+
+  let configFile = getUpdateConfigFile();
+  let decoder = new TextDecoder();
+  let fileContents = await OS.File.read(configFile.path);
+  let saveObject = JSON.parse(decoder.decode(fileContents));
+  is(saveObject["app.update.auto"], newConfigValue,
+     "Value in file should match expected");
+
+  await ContentTask.spawn(tab.linkedBrowser, {newConfigValue}, async function({newConfigValue}) {
+    let updateRadioGroup = content.document.getElementById("updateRadioGroup");
+    is(updateRadioGroup.value, `${newConfigValue}`,
+       "Update preference should match expected");
+  });
+}
+
+add_task(async function testUpdateAutoPrefUI() {
+  let originalPrefValue = await gAUS.getAutoUpdateIsEnabled();
+  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:preferences");
+
+  await changeAndVerifyPref(tab, true);
+  await changeAndVerifyPref(tab, false);
+  await changeAndVerifyPref(tab, false);
+  await changeAndVerifyPref(tab, true);
+
+  await BrowserTestUtils.removeTab(tab);
+  await gAUS.setAutoUpdateIsEnabled(originalPrefValue);
+});
--- a/toolkit/mozapps/update/tests/data/shared.js
+++ b/toolkit/mozapps/update/tests/data/shared.js
@@ -53,16 +53,17 @@ const DIR_UPDATED      = IS_MACOSX ? "Up
 const FILE_ACTIVE_UPDATE_XML         = "active-update.xml";
 const FILE_APPLICATION_INI           = "application.ini";
 const FILE_BACKUP_UPDATE_LOG         = "backup-update.log";
 const FILE_LAST_UPDATE_LOG           = "last-update.log";
 const FILE_UPDATE_SETTINGS_INI       = "update-settings.ini";
 const FILE_UPDATE_SETTINGS_INI_BAK   = "update-settings.ini.bak";
 const FILE_UPDATER_INI               = "updater.ini";
 const FILE_UPDATES_XML               = "updates.xml";
+const FILE_UPDATE_CONFIG             = "update-config.json";
 const FILE_UPDATE_LOG                = "update.log";
 const FILE_UPDATE_MAR                = "update.mar";
 const FILE_UPDATE_STATUS             = "update.status";
 const FILE_UPDATE_TEST               = "update.test";
 const FILE_UPDATE_VERSION            = "update.version";
 
 const UPDATE_SETTINGS_CONTENTS = "[Settings]\n" +
                                  "ACCEPTED_MAR_CHANNEL_IDS=xpcshell-test\n";
@@ -578,16 +579,25 @@ function getGREDir() {
  *
  * @return nsIFile for the Gecko Runtime Engine Binary directory.
  */
 function getGREBinDir() {
   return Services.dirsvc.get(NS_GRE_BIN_DIR, Ci.nsIFile);
 }
 
 /**
+ * Returns the file containing update configuration
+ */
+function getUpdateConfigFile() {
+  let configFile = getUpdatesRootDir();
+  configFile.append(FILE_UPDATE_CONFIG);
+  return configFile;
+}
+
+/**
  * Logs TEST-INFO messages.
  *
  * @param  aText
  *         The text to log.
  * @param  aCaller (optional)
  *         An optional Components.stack.caller. If not specified
  *         Components.stack.caller will be used.
  */
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/update/tests/unit_aus_update/updateAutoPrefMigrate.js
@@ -0,0 +1,83 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+ChromeUtils.import("resource://gre/modules/osfile.jsm", this);
+
+// Checks both the value returned by the update service and the one written to
+// the app update config file.
+async function verifyPref(configFile, expectedValue) {
+  let decoder = new TextDecoder();
+  let configValue = await gAUS.getAutoUpdateIsEnabled();
+  Assert.equal(configValue, expectedValue,
+               "Value returned should have matched the expected value");
+  let fileContents = await OS.File.read(configFile.path);
+  let saveObject = JSON.parse(decoder.decode(fileContents));
+  Assert.equal(saveObject["app.update.auto"], expectedValue,
+               "Value in file should match expected");
+}
+
+async function run_test() {
+  setupTestCommon();
+  standardInit();
+
+  let configFile = getUpdateConfigFile();
+
+  let originalFileValue = await gAUS.getAutoUpdateIsEnabled();
+  let originalConfigValue = Services.prefs.getBoolPref("app.update.auto", null);
+  let originalMigrationValue =
+    Services.prefs.getBoolPref("app.update.auto.migrated", null);
+
+  // Test migration of a |false| value
+  Services.prefs.setBoolPref("app.update.auto.migrated", false);
+  Services.prefs.setBoolPref("app.update.auto", false);
+  debugDump(`about to remove config file`);
+  configFile.remove(false);
+  Assert.ok(!configFile.exists(), "Pref file should have been removed");
+  await verifyPref(configFile, false);
+
+  // Test that migration doesn't happen twice
+  Services.prefs.setBoolPref("app.update.auto", true);
+  await verifyPref(configFile, false);
+
+  // If the file is deleted after migration, the default value should be
+  // returned, regardless of the pref value.
+  debugDump(`about to remove config file`);
+  configFile.remove(false);
+  Assert.ok(!configFile.exists(), "Pref file should have been removed");
+  let configValue = await gAUS.getAutoUpdateIsEnabled();
+  Assert.equal(configValue, true, "getAutoUpdateIsEnabled should have " +
+                                  "returned the default value (true)");
+
+  // Setting a new value should cause the value to get written out again
+  await gAUS.setAutoUpdateIsEnabled(false);
+  await verifyPref(configFile, false);
+
+  // Test migration of a |true| value
+  Services.prefs.setBoolPref("app.update.auto.migrated", false);
+  Services.prefs.setBoolPref("app.update.auto", true);
+  configFile.remove(false);
+  Assert.ok(!configFile.exists(), "App update config file should have been " +
+                                  "removed");
+  await verifyPref(configFile, true);
+
+  // Test that setting app.update.auto without migrating also works
+  await gAUS.setAutoUpdateIsEnabled(false);
+  await verifyPref(configFile, false);
+
+  // Restore original state
+  await gAUS.setAutoUpdateIsEnabled(originalFileValue);
+  if (originalConfigValue == null) {
+    Services.prefs.clearUserPref("app.update.auto");
+  } else {
+    Services.prefs.setBoolPref("app.update.auto", originalConfigValue);
+  }
+  if (originalMigrationValue == null) {
+    Services.prefs.clearUserPref("app.update.auto.migrated");
+  } else {
+    Services.prefs.setBoolPref("app.update.auto.migrated",
+                               originalMigrationValue);
+  }
+  doTestFinish();
+}
--- a/toolkit/mozapps/update/tests/unit_aus_update/xpcshell.ini
+++ b/toolkit/mozapps/update/tests/unit_aus_update/xpcshell.ini
@@ -23,11 +23,14 @@ head = head_update.js
 [downloadInterruptedOffline.js]
 [downloadInterruptedNoRecovery.js]
 [downloadInterruptedRecovery.js]
 [downloadResumeForSameAppVersion.js]
 [downloadCompleteAfterPartialFailure.js]
 [uiSilentPref.js]
 [uiUnsupportedAlreadyNotified.js]
 [uiAutoPref.js]
+[updateAutoPrefMigrate.js]
+skip-if = os != 'win'
+reason = Update pref migration is currently Windows only
 [updateDirectoryMigrate.js]
 skip-if = os != 'win'
 reason = Update directory migration is currently Windows only