Bug 1037166 - Convert the "Show Update History" dialog on advanced pane to be in-content.r=jaws
authorFischer.json <fischer.json@gmail.com>
Fri, 29 Jul 2016 17:03:05 +0800
changeset 309750 6d6f82046da48820aca4a866fa0184234783ed7d
parent 309749 184313cc7fd8286b543c168df1fc6eede4e50e83
child 309751 97650364974418715bae51a0d1d9281b40f0b592
push id31451
push userryanvm@gmail.com
push dateWed, 17 Aug 2016 19:49:29 +0000
treeherderautoland@6d6f82046da4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs1037166
milestone51.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 1037166 - Convert the "Show Update History" dialog on advanced pane to be in-content.r=jaws MozReview-Commit-ID: kmgB4Sv9KM
browser/components/preferences/in-content/advanced.js
browser/components/preferences/in-content/tests/browser_advanced_update.js
--- a/browser/components/preferences/in-content/advanced.js
+++ b/browser/components/preferences/in-content/advanced.js
@@ -742,21 +742,17 @@ var gAdvancedPane = {
     }
   },
 
   /**
    * Displays the history of installed updates.
    */
   showUpdates: function ()
   {
-    if (AppConstants.MOZ_UPDATER) {
-      var prompter = Components.classes["@mozilla.org/updates/update-prompt;1"]
-                               .createInstance(Components.interfaces.nsIUpdatePrompt);
-      prompter.showUpdateHistory(window);
-    }
+    gSubDialog.open("chrome://mozapps/content/update/history.xul");
   },
 
   // ENCRYPTION TAB
 
   /*
    * Preferences:
    *
    * security.default_personal_cert
--- a/browser/components/preferences/in-content/tests/browser_advanced_update.js
+++ b/browser/components/preferences/in-content/tests/browser_advanced_update.js
@@ -1,40 +1,163 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
-function test() {
-  waitForExplicitFinish();
-  resetPreferences();
+const { classes: Cc, interfaces: Ci, manager: Cm, utils: Cu, results: Cr } = Components;
+
+Cu.import('resource://gre/modules/XPCOMUtils.jsm');
+
+const uuidGenerator = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator);
+const dateFormat = Cc["@mozilla.org/intl/scriptabledateformat;1"]
+                      .getService(Components.interfaces.nsIScriptableDateFormat);
+
+const mockUpdateManager = {
+  contractId: "@mozilla.org/updates/update-manager;1",
+
+  _mockClassId: uuidGenerator.generateUUID(),
+
+  _originalClassId: "",
+
+  _originalFactory: null,
+
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsIUpdateManager]),
+
+  createInstance: function(outer, iiD) {
+    if (outer) {
+      throw Cr.NS_ERROR_NO_AGGREGATION;
+    }
+    return this.QueryInterface(iiD);
+  },
+
+  register: function () {
+    let registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
+    if (!registrar.isCIDRegistered(this._mockClassId)) {
+      this._originalClassId = registrar.contractIDToCID(this.contractId);
+      this._originalFactory = Cm.getClassObject(Cc[this.contractId], Ci.nsIFactory);
+      registrar.unregisterFactory(this._originalClassId, this._originalFactory);
+      registrar.registerFactory(this._mockClassId, "Unregister after testing", this.contractId, this);
+    }
+  },
 
-  registerCleanupFunction(resetPreferences);
-  Services.prefs.setBoolPref("browser.search.update", false);
+  unregister: function () {
+    let registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
+    registrar.unregisterFactory(this._mockClassId, this);
+    registrar.registerFactory(this._originalClassId, "", this.contractId, this._originalFactory);
+  },
+
+  get updateCount() {
+    return this._updates.length;
+  },
+
+  getUpdateAt: function (index) {
+    return this._updates[index];
+  },
 
-  open_preferences(runTest);
+  _updates: [
+    {
+      name: "Firefox Developer Edition 49.0a2",
+      statusText: "The Update was successfully installed",
+      buildID: "20160728004010",
+      type: "minor",
+      installDate: 1469763105156,
+      detailsURL: "https://www.mozilla.org/firefox/aurora/"
+    },
+    {
+      name: "Firefox Developer Edition 43.0a2",
+      statusText: "The Update was successfully installed",
+      buildID: "20150929004011",
+      type: "minor",
+      installDate: 1443585886224,
+      detailsURL: "https://www.mozilla.org/firefox/aurora/"
+    },
+    {
+      name: "Firefox Developer Edition 42.0a2",
+      statusText: "The Update was successfully installed",
+      buildID: "20150920004018",
+      type: "major",
+      installDate: 1442818147544,
+      detailsURL: "https://www.mozilla.org/firefox/aurora/"
+    }
+  ]
+};
+
+function resetPreferences() {
+  Services.prefs.clearUserPref("browser.search.update");
 }
 
-function runTest(win) {
-  let doc = win.document;
-  let enableSearchUpdate = doc.getElementById("enableSearchUpdate");
+function formatInstallDate(sec) {
+  var date = new Date(sec);
+  return dateFormat.FormatDateTime("",
+    dateFormat.dateFormatLong,
+    dateFormat.timeFormatSeconds,
+    date.getFullYear(),
+    date.getMonth() + 1,
+    date.getDate(),
+    date.getHours(),
+    date.getMinutes(),
+    date.getSeconds());
+}
 
-  win.gotoPref("paneAdvanced");
+registerCleanupFunction(resetPreferences);
 
-  let advancedPrefs = doc.getElementById("advancedPrefs");
-  let updateTab = doc.getElementById("updateTab");
-  advancedPrefs.selectedTab = updateTab;
+add_task(function*() {
+  yield openPreferencesViaOpenPreferencesAPI("advanced", "updateTab", { leaveOpen: true });
+  resetPreferences();
+  Services.prefs.setBoolPref("browser.search.update", false);
 
+  let doc = gBrowser.selectedBrowser.contentDocument;
+  let enableSearchUpdate = doc.getElementById("enableSearchUpdate");
   is_element_visible(enableSearchUpdate, "Check search update preference is visible");
 
   // Ensure that the update pref dialog reflects the actual pref value.
   ok(!enableSearchUpdate.checked, "Ensure search updates are disabled");
   Services.prefs.setBoolPref("browser.search.update", true);
   ok(enableSearchUpdate.checked, "Ensure search updates are enabled");
 
   gBrowser.removeCurrentTab();
-  win.close();
-  finish();
-}
+});
+
+add_task(function*() {
+  mockUpdateManager.register();
+
+  yield openPreferencesViaOpenPreferencesAPI("advanced", "updateTab", { leaveOpen: true });
+  let doc = gBrowser.selectedBrowser.contentDocument;
+
+  let showBtn = doc.getElementById("showUpdateHistory");
+  let dialogOverlay = doc.getElementById("dialogOverlay");
+
+  // Test the dialog window opens
+  is(dialogOverlay.style.visibility, "", "The dialog should be invisible");
+  showBtn.doCommand();
+  yield promiseLoadSubDialog("chrome://mozapps/content/update/history.xul");
+  is(dialogOverlay.style.visibility, "visible", "The dialog should be visible");
+
+  let dialogFrame = doc.getElementById("dialogFrame");
+  let frameDoc = dialogFrame.contentDocument;
+  let updates = frameDoc.querySelectorAll("update");
 
-function resetPreferences() {
-  Services.prefs.clearUserPref("browser.search.update");
-}
+  // Test the update history numbers are correct
+  is(updates.length, mockUpdateManager.updateCount, "The update count is incorrect.");
+
+  // Test the updates are displayed correctly
+  let update = null;
+  let updateData = null;
+  for (let i = 0; i < updates.length; ++i) {
+    update = updates[i];
+    updateData = mockUpdateManager.getUpdateAt(i);
+
+    is(update.name, updateData.name + " (" + updateData.buildID + ")", "Wrong update name");
+    is(update.type, updateData.type == "major" ? "New Version" : "Security Update", "Wrong update type");
+    is(update.installDate, formatInstallDate(updateData.installDate), "Wrong update installDate");
+    is(update.detailsURL, updateData.detailsURL, "Wrong update detailsURL");
+    is(update.status, updateData.statusText, "Wrong update status");
+  }
+
+  // Test the dialog window closes
+  let closeBtn = doc.getElementById("dialogClose");
+  closeBtn.doCommand();
+  is(dialogOverlay.style.visibility, "", "The dialog should be invisible");
+
+  mockUpdateManager.unregister();
+  gBrowser.removeCurrentTab();
+});