DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (b6d82b1a6b02)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
<!DOCTYPE html>
<meta charset="UTF-8">
<title>Test for scrollbar-*-color properties</title>
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/WindowSnapshot.js"></script>
<style>
  .outer {
    width: 100px;
    height: 100px;
    background: yellow;
    overflow: scroll;
  }
  .inner {
    width: 200px;
    height: 200px;
  }
</style>
<style id="style"></style>
<div class="outer">
  <div class="inner">
  </div>
</div>
<script>
function countPixels(canvas) {
  let result = new Map;
  let ctx = canvas.getContext("2d");
  let image = ctx.getImageData(0, 0, canvas.width, canvas.height);
  let data = image.data;
  let size = image.width * image.height;
  for (let i = 0; i < size; i++) {
    let key = data.subarray(i * 4, i * 4 + 3).toString();
    let value = result.get(key);
    value = value ? value : 0;
    result.set(key, value + 1);
  }
  return result;
}

const WIN_REFERENCES = [
  // Yellow background
  ["255,255,0", 6889],
  // Blue scrollbar face
  ["0,0,255", 540],
  // Cyan scrollbar track
  ["0,255,255", 2487],
];

const MAC_REFERENCES = [
  // Yellow background
  ["255,255,0", 7225],
  // Blue scrollbar face
  ["0,0,255", 416],
  // Cyan scrollbar track
  ["0,255,255", 1760],
];

const LINUX_REFERENCES = [
  // Yellow background
  ["255,255,0", 8100],
  // Blue scrollbar face
  ["0,0,255", 720],
  // Cyan scrollbar track
  ["0,255,255", 1180],
];

let outer = document.querySelector(".outer");
let outerRect = outer.getBoundingClientRect();
if (outerRect.width == outer.clientWidth &&
    outerRect.height == outer.clientHeight) {
  ok(true, "Using overlay scrollbar, skip this test");
} else {
  SimpleTest.waitForExplicitFinish();
  SpecialPowers.pushPrefEnv({
    "set": [["layout.css.scrollbar-color.enabled", true]],
  }, function() {
    document.querySelector("#style").textContent = `
      .outer { scrollbar-color: blue cyan; }
    `;

    let canvas = snapshotRect(window, outerRect);
    let stats = countPixels(canvas);
    let references;
    if (navigator.platform.startsWith("Win")) {
      references = WIN_REFERENCES;
    } else if (navigator.platform.startsWith("Mac")) {
      references = MAC_REFERENCES;
    } else if (navigator.platform.startsWith("Linux")) {
      references = LINUX_REFERENCES;
    } else {
      ok(false, "Unsupported platform");
    }
    for (let [color, count] of references) {
      let value = stats.get(color);
      is(value, count, `Pixel count of color ${color}`);
    }
    SimpleTest.finish();
  });
}
</script>