Bug 1595135 - Make thumbnail tests run more quickly. r=Mardak
authorMike Conley <mconley@mozilla.com>
Mon, 18 Nov 2019 15:24:29 +0000
changeset 502418 63a9116eca768e552ff13fce5237fc6696dd7790
parent 502417 fcb6a78740f837e54e53ca967009b0690a1ad5e7
child 502419 4ddb439ba4c1f14314e3707830ee7f71a048b37b
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;