tor-browser

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

browser_startup_flicker.js (3313B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /*
      7 * This test ensures that there is no unexpected flicker
      8 * on the first window opened during startup.
      9 */
     10 
     11 add_task(async function () {
     12  let startupRecorder =
     13    Cc["@mozilla.org/test/startuprecorder;1"].getService().wrappedJSObject;
     14  await startupRecorder.done;
     15 
     16  // Ensure all the frame data is in the test compartment to avoid traversing
     17  // a cross compartment wrapper for each pixel.
     18  let frames = Cu.cloneInto(startupRecorder.data.frames, {});
     19  ok(!!frames.length, "Should have captured some frames.");
     20 
     21  let unexpectedRects = 0;
     22  let alreadyFocused = false;
     23  let inRange = (val, min, max) => min <= val && val <= max;
     24  let tabBoundingRect = undefined;
     25  let urlbarBoundingRect = undefined;
     26  for (let i = 1; i < frames.length; ++i) {
     27    let frame = frames[i],
     28      previousFrame = frames[i - 1];
     29    let rects = compareFrames(frame, previousFrame);
     30    if (!alreadyFocused && isLikelyFocusChange(rects, frame)) {
     31      todo(
     32        false,
     33        "bug 1445161 - the window should be focused at first paint, " +
     34          rects.toSource()
     35      );
     36      continue;
     37    }
     38    alreadyFocused = true;
     39 
     40    rects = rects.filter(rect => {
     41      let width = frame.width;
     42 
     43      let exceptions = [
     44        /**
     45         * Please don't add anything new unless justified!
     46         */
     47        {
     48          name: "Shadow around active tab should not flicker on macOS (bug 1960967)",
     49          condition(r) {
     50            const tabRect = tabBoundingRect
     51              ? tabBoundingRect
     52              : (tabBoundingRect = gBrowser.tabContainer
     53                  .querySelector("tab[selected=true] .tab-background")
     54                  .getBoundingClientRect());
     55            return (
     56              inRange(r.x1, tabRect.x - 2, tabRect.x + 2) &&
     57              inRange(r.y1, tabRect.y - 2, tabRect.y + 2) &&
     58              inRange(r.w, tabRect.width - 4, tabRect.width + 4) &&
     59              inRange(r.h, tabRect.height - 4, tabRect.height + 4)
     60            );
     61          },
     62        },
     63        {
     64          name: "Pixel snapping on urlbar bottom border on MacOS & Windows",
     65          condition(r) {
     66            if (!urlbarBoundingRect) {
     67              urlbarBoundingRect = document
     68                .getElementById("urlbar")
     69                .getBoundingClientRect();
     70            }
     71            return rectMatchesBottomBorder(r, urlbarBoundingRect);
     72          },
     73        },
     74      ];
     75 
     76      let rectText = `${rect.toSource()}, window width: ${width}`;
     77      for (let e of exceptions) {
     78        if (e.condition(rect)) {
     79          todo(false, e.name + ", " + rectText);
     80          return false;
     81        }
     82      }
     83 
     84      ok(false, "unexpected changed rect: " + rectText);
     85      return true;
     86    });
     87    if (!rects.length) {
     88      info("ignoring identical frame");
     89      continue;
     90    }
     91 
     92    // Before dumping a frame with unexpected differences for the first time,
     93    // ensure at least one previous frame has been logged so that it's possible
     94    // to see the differences when examining the log.
     95    if (!unexpectedRects) {
     96      dumpFrame(previousFrame);
     97    }
     98    unexpectedRects += rects.length;
     99    dumpFrame(frame);
    100  }
    101  is(unexpectedRects, 0, "should have 0 unknown flickering areas");
    102 });