Bug 1595135 - Make thumbnail tests run more quickly. r=Mardak
☠☠ backed out by f09b92421976 ☠ ☠
authorMike Conley <mconley@mozilla.com>
Wed, 13 Nov 2019 22:40:34 +0000
changeset 501939 5d7640ffbf2ad18d3bc99bac56b6500d80db987b
parent 501938 3af7f65785fe9e7ddd3d33afcede92f7ce21e111
child 501940 8b7a0fc358f3fc42fc639baff2aa43a60797be66
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMardak
bugs1595135
milestone72.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 1595135 - Make thumbnail tests run more quickly. r=Mardak Differential Revision: https://phabricator.services.mozilla.com/D52426
toolkit/components/thumbnails/BackgroundPageThumbs.jsm
toolkit/components/thumbnails/content/backgroundPageThumbsContent.js
--- a/toolkit/components/thumbnails/BackgroundPageThumbs.jsm
+++ b/toolkit/components/thumbnails/BackgroundPageThumbs.jsm
@@ -1,15 +1,18 @@
 /* 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/. */
 
 const EXPORTED_SYMBOLS = ["BackgroundPageThumbs"];
 
 const DEFAULT_CAPTURE_TIMEOUT = 30000; // ms
+// For testing, the above timeout is excessive, and makes our tests overlong.
+const TESTING_CAPTURE_TIMEOUT = 5000; // ms
+
 const DESTROY_BROWSER_TIMEOUT = 60000; // ms
 const FRAME_SCRIPT_URL =
   "chrome://global/content/backgroundPageThumbsContent.js";
 
 const TELEMETRY_HISTOGRAM_ID_PREFIX = "FX_THUMBNAILS_BG_";
 
 const ABOUT_NEWTAB_SEGREGATION_PREF =
   "privacy.usercontext.about_newtab_segregation.enabled";
@@ -468,21 +471,25 @@ Capture.prototype = {
    * Sends a message to the content script to start the capture.
    *
    * @param messageManager  The nsIMessageSender of the thumbnail browser.
    */
   start(messageManager) {
     this.startDate = new Date();
     tel("CAPTURE_QUEUE_TIME_MS", this.startDate - this.creationDate);
 
+    let fallbackTimeout = Cu.isInAutomation
+      ? TESTING_CAPTURE_TIMEOUT
+      : DEFAULT_CAPTURE_TIMEOUT;
+
     // timeout timer
     let timeout =
       typeof this.options.timeout == "number"
         ? this.options.timeout
-        : DEFAULT_CAPTURE_TIMEOUT;
+        : fallbackTimeout;
     this._timeoutTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
     this._timeoutTimer.initWithCallback(
       this,
       timeout,
       Ci.nsITimer.TYPE_ONE_SHOT
     );
 
     // didCapture registration
--- a/toolkit/components/thumbnails/content/backgroundPageThumbsContent.js
+++ b/toolkit/components/thumbnails/content/backgroundPageThumbsContent.js
@@ -12,16 +12,18 @@ const { XPCOMUtils } = ChromeUtils.impor
 );
 const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 XPCOMUtils.defineLazyGlobalGetters(this, ["Blob", "FileReader"]);
 
 // Let the page settle for this amount of milliseconds before capturing to allow
 // for any in-page changes or redirects.
 const SETTLE_WAIT_TIME = 2500;
+// For testing, the above timeout is excessive, and makes our tests overlong.
+const TESTING_SETTLE_WAIT_TIME = 0;
 
 const STATE_LOADING = 1;
 const STATE_CAPTURING = 2;
 const STATE_CANCELED = 3;
 
 // NOTE: Copied from nsSandboxFlags.h
 /**
  * This flag prevents content from creating new auxiliary browsing contexts,
@@ -135,33 +137,36 @@ const backgroundPageThumbsContent = {
         } else if (this._state == STATE_CANCELED) {
           delete this._currentCapture;
           this._startNextCapture();
         }
       } else if (
         this._state == STATE_LOADING &&
         (Components.isSuccessCode(status) || status === Cr.NS_BINDING_ABORTED)
       ) {
+        let waitTime = Cu.isInAutomation
+          ? TESTING_SETTLE_WAIT_TIME
+          : SETTLE_WAIT_TIME;
         // The requested page has loaded or stopped/aborted, so capture the page
         // soon but first let it settle in case of in-page redirects
         if (this._captureTimer) {
           // There was additional activity, so restart the wait timer
-          this._captureTimer.delay = SETTLE_WAIT_TIME;
+          this._captureTimer.delay = waitTime;
         } else {
           // Stay in LOADING until we're actually ready to be CAPTURING
           this._captureTimer = Cc["@mozilla.org/timer;1"].createInstance(
             Ci.nsITimer
           );
           this._captureTimer.init(
             () => {
               this._state = STATE_CAPTURING;
               this._captureCurrentPage();
               delete this._captureTimer;
             },
-            SETTLE_WAIT_TIME,
+            waitTime,
             Ci.nsITimer.TYPE_ONE_SHOT
           );
         }
       } else if (this._state != STATE_CANCELED) {
         // Something went wrong.  Cancel the capture.  Loading about:blank
         // while onStateChange is still on the stack does not actually stop
         // the request if it redirects, so do it asyncly.
         this._state = STATE_CANCELED;