Bug 907062, resolve the promise if the popup is already open so that the test doesn't occasionally fail, r=paolo
authorNeil Deakin <neil@mozilla.com>
Mon, 09 Sep 2013 20:13:58 -0400
changeset 159208 9f7c4970b7610607979c9081a8e07b5dcbed0662
parent 159207 5ec8ad37ff9637b9c20e8ef6dc6028004ed9e007
child 159209 1e15819af724ae710cfdfa9fa1ef408bcab4bfe6
push id2961
push userlsblakk@mozilla.com
push dateMon, 28 Oct 2013 21:59:28 +0000
treeherdermozilla-beta@73ef4f13486f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspaolo
bugs907062
milestone26.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 907062, resolve the promise if the popup is already open so that the test doesn't occasionally fail, r=paolo
browser/components/downloads/content/downloads.js
browser/components/downloads/test/browser/browser_basic_functionality.js
browser/components/downloads/test/browser/browser_first_download_panel.js
browser/components/downloads/test/browser/head.js
testing/profiles/prefs_general.js
--- a/browser/components/downloads/content/downloads.js
+++ b/browser/components/downloads/content/downloads.js
@@ -186,22 +186,29 @@ const DownloadsPanel = {
     DownloadsSummary.active = false;
     DownloadsCommon.log("DownloadsPanel terminated.");
   },
 
   //////////////////////////////////////////////////////////////////////////////
   //// Panel interface
 
   /**
-   * Main panel element in the browser window.
+   * Main panel element in the browser window, or null if the panel overlay
+   * hasn't been loaded yet.
    */
   get panel()
   {
+    // If the downloads panel overlay hasn't loaded yet, just return null
+    // without reseting this.panel.
+    let downloadsPanel = document.getElementById("downloadsPanel");
+    if (!downloadsPanel)
+      return null;
+
     delete this.panel;
-    return this.panel = document.getElementById("downloadsPanel");
+    return this.panel = downloadsPanel;
   },
 
   /**
    * Starts opening the downloads panel interface, anchored to the downloads
    * button of the browser window.  The list of downloads to display is
    * initialized the first time this method is called, and the panel is shown
    * only when data is ready.
    */
--- a/browser/components/downloads/test/browser/browser_basic_functionality.js
+++ b/browser/components/downloads/test/browser/browser_basic_functionality.js
@@ -14,16 +14,19 @@ function test_task()
     { state: nsIDM.DOWNLOAD_NOTSTARTED },
     { state: nsIDM.DOWNLOAD_PAUSED },
     { state: nsIDM.DOWNLOAD_FINISHED },
     { state: nsIDM.DOWNLOAD_FAILED },
     { state: nsIDM.DOWNLOAD_CANCELED },
   ];
 
   try {
+    // Wait for focus first
+    yield promiseFocus();
+
     // Ensure that state is reset in case previous tests didn't finish.
     yield task_resetState();
 
     // For testing purposes, show all the download items at once.
     var originalCountLimit = DownloadsView.kItemCountLimit;
     DownloadsView.kItemCountLimit = DownloadData.length;
     registerCleanupFunction(function () {
       DownloadsView.kItemCountLimit = originalCountLimit;
--- a/browser/components/downloads/test/browser/browser_first_download_panel.js
+++ b/browser/components/downloads/test/browser/browser_first_download_panel.js
@@ -5,16 +5,24 @@
 
 /**
  * Make sure the downloads panel only opens automatically on the first
  * download it notices. All subsequent downloads, even across sessions, should
  * not open the panel automatically.
  */
 function test_task()
 {
+  // Clear the download panel has shown preference first as this test is used to
+  // verify this preference's behaviour.
+  let oldPrefValue = true;
+  try {
+    oldPrefValue = Services.prefs.getBoolPref("browser.download.panel.shown");
+  } catch(ex) { }
+  Services.prefs.setBoolPref("browser.download.panel.shown", false);
+
   try {
     // Ensure that state is reset in case previous tests didn't finish.
     yield task_resetState();
 
     // With this set to false, we should automatically open the panel the first
     // time a download is started.
     DownloadsCommon.getData(window).panelHasShownBefore = false;
 
@@ -44,10 +52,14 @@ function test_task()
       setTimeout(deferTimeout.resolve, 2000);
       yield deferTimeout.promise;
     } finally {
       DownloadsPanel.onPopupShown = originalOnPopupShown;
     }
   } finally {
     // Clean up when the test finishes.
     yield task_resetState();
+    // Set the preference instead of clearing it afterwards to ensure the
+    // right value is used no matter what the default was. This ensures the
+    // panel doesn't appear and affect other tests.
+    Services.prefs.setBoolPref("browser.download.panel.shown", oldPrefValue);
   }
 }
--- a/browser/components/downloads/test/browser/head.js
+++ b/browser/components/downloads/test/browser/head.js
@@ -46,16 +46,20 @@ function promiseFocus()
   waitForFocus(deferred.resolve);
   return deferred.promise;
 }
 
 function promisePanelOpened()
 {
   let deferred = Promise.defer();
 
+  if (DownloadsPanel.panel && DownloadsPanel.panel.state == "open") {
+    return deferred.resolve();
+  }
+
   // Hook to wait until the panel is shown.
   let originalOnPopupShown = DownloadsPanel.onPopupShown;
   DownloadsPanel.onPopupShown = function () {
     DownloadsPanel.onPopupShown = originalOnPopupShown;
     originalOnPopupShown.apply(this, arguments);
 
     // Defer to the next tick of the event loop so that we don't continue
     // processing during the DOM event handler itself.
@@ -70,19 +74,16 @@ function task_resetState()
   // Remove all downloads.
   let publicList = yield Downloads.getPublicDownloadList();
   let downloads = yield publicList.getAll();
   for (let download of downloads) {
     publicList.remove(download);
     yield download.finalize(true);
   }
 
-  // Reset any prefs that might have been changed.
-  Services.prefs.clearUserPref("browser.download.panel.shown");
-
   DownloadsPanel.hidePanel();
 
   yield promiseFocus();
 }
 
 function task_addDownloads(aItems)
 {
   let startTimeMs = Date.now();
--- a/testing/profiles/prefs_general.js
+++ b/testing/profiles/prefs_general.js
@@ -143,8 +143,12 @@ user_pref("media.webaudio.legacy.Oscilla
 
 // Always use network provider for geolocation tests
 // so we bypass the OSX dialog raised by the corelocation provider
 user_pref("geo.provider.testing", true);
 
 // Background thumbnails in particular cause grief, and disabling thumbnails
 // in general can't hurt - we re-enable them when tests need them.
 user_pref("browser.pagethumbnails.capturing_disabled", true);
+
+// Indicate that the download panel has been shown once so that whichever
+// download test runs first doesn't show the popup inconsistently.
+user_pref("browser.download.panel.shown", true);