Bug 1595135 - Make sure that we do thumbnail captures soon after requesting them in tests instead of waiting for an idle callback. r=Mardak
authorMike Conley <mconley@mozilla.com>
Mon, 18 Nov 2019 15:24:59 +0000
changeset 502419 4ddb439ba4c1f14314e3707830ee7f71a048b37b
parent 502418 63a9116eca768e552ff13fce5237fc6696dd7790
child 502420 a52581ac4a9dd02c9ae085f428db1e1579a60513
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 sure that we do thumbnail captures soon after requesting them in tests instead of waiting for an idle callback. r=Mardak This is so that we can ensure that the captures actually occur during the lifetime of the test. Differential Revision: https://phabricator.services.mozilla.com/D53224
toolkit/components/thumbnails/content/backgroundPageThumbsContent.js
--- a/toolkit/components/thumbnails/content/backgroundPageThumbsContent.js
+++ b/toolkit/components/thumbnails/content/backgroundPageThumbsContent.js
@@ -217,19 +217,30 @@ const backgroundPageThumbsContent = {
 
       finalCanvas.toBlob(blob => {
         capture.imageBlob = new Blob([blob]);
         // Load about:blank to finish the capture and wait for onStateChange.
         this._loadAboutBlank();
       });
     };
     let win = docShell.domWindow;
-    win.requestIdleCallback(() =>
-      doCapture().catch(ex => this._failCurrentCapture(ex.message))
-    );
+
+    let runCapture = () => {
+      doCapture().catch(ex => this._failCurrentCapture(ex.message));
+    };
+
+    // When testing, especially on debug builds, this idle callback might
+    // be called too late (or never called at all - see bug 1596781), and
+    // the test will time out. So if we're running in automation, we begin
+    // the capture on the next tick.
+    if (Cu.isInAutomation) {
+      Services.tm.dispatchToMainThread(runCapture);
+    } else {
+      win.requestIdleCallback(runCapture);
+    }
   },
 
   _finishCurrentCapture() {
     let capture = this._currentCapture;
     let fileReader = new FileReader();
     fileReader.onloadend = () => {
       sendAsyncMessage("BackgroundPageThumbs:didCapture", {
         id: capture.id,