tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

MarionetteReftestParent.sys.mjs (2992B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 /**
      6 * Parent JSWindowActor to handle navigation for reftests relying on marionette.
      7 */
      8 export class MarionetteReftestParent extends JSWindowActorParent {
      9  /**
     10   * Wait for the expected URL to be loaded.
     11   *
     12   * @param {string} url
     13   *        The expected url.
     14   * @param {boolean} useRemote
     15   *        True if tests are running with e10s.
     16   * @param {boolean} warnOnOverflow
     17   *        True if we should check the content fits in the viewport.
     18   *        This isn't necessary for print reftests where we will render the full
     19   *        size of the paginated content.
     20   * @returns {boolean} true if the page is fully loaded with the expected url,
     21   *         false otherwise.
     22   */
     23  async reftestWait(url, useRemote, warnOnOverflow) {
     24    try {
     25      const isCorrectUrl = await this.sendQuery(
     26        "MarionetteReftestParent:reftestWait",
     27        {
     28          url,
     29          useRemote,
     30          warnOnOverflow,
     31        }
     32      );
     33 
     34      if (isCorrectUrl) {
     35        // Trigger flush rendering for all remote frames.
     36        await this._flushRenderingInSubtree({
     37          ignoreThrottledAnimations: false,
     38        });
     39      }
     40 
     41      return isCorrectUrl;
     42    } catch (e) {
     43      if (e.name === "AbortError") {
     44        // If the query is aborted, the window global is being destroyed, most
     45        // likely because a navigation happened.
     46        return false;
     47      }
     48 
     49      // Other errors should not be swallowed.
     50      throw e;
     51    }
     52  }
     53 
     54  /**
     55   * Call flushRendering on all browsing contexts in the subtree.
     56   * Each actor will flush rendering in all the same process frames.
     57   */
     58  async _flushRenderingInSubtree({ ignoreThrottledAnimations }) {
     59    const browsingContext = this.manager.browsingContext;
     60    const contexts = browsingContext.getAllBrowsingContextsInSubtree();
     61 
     62    await Promise.all(
     63      contexts.map(async context => {
     64        if (context === browsingContext) {
     65          // Skip the top browsing context, for which flushRendering is
     66          // already performed via the initial reftestWait call.
     67          return;
     68        }
     69 
     70        const windowGlobal = context.currentWindowGlobal;
     71        if (!windowGlobal) {
     72          // Bail out if there is no window attached to the current context.
     73          return;
     74        }
     75 
     76        if (!windowGlobal.isProcessRoot) {
     77          // Bail out if this window global is not a process root.
     78          // MarionetteReftestChild::flushRendering will flush all same process
     79          // frames, so we only need to call flushRendering on process roots.
     80          return;
     81        }
     82 
     83        const reftestActor = windowGlobal.getActor("MarionetteReftest");
     84        await reftestActor.sendQuery("MarionetteReftestParent:flushRendering", {
     85          ignoreThrottledAnimations,
     86        });
     87      })
     88    );
     89  }
     90 }