File: test_drawSnapshot_fixed.html

package info (click to toggle)
firefox 144.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,637,504 kB
  • sloc: cpp: 7,576,692; javascript: 6,430,831; ansic: 3,748,119; python: 1,398,978; xml: 628,810; asm: 438,679; java: 186,194; sh: 63,212; makefile: 19,159; objc: 13,086; perl: 12,986; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 53; csh: 10
file content (68 lines) | stat: -rw-r--r-- 1,980 bytes parent folder | download | duplicates (18)
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
<!DOCTYPE HTML>
<html>
<head>
  <meta charset="utf-8">
  <title>Test for drawSnapshot</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="/tests/SimpleTest/WindowSnapshot.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  <style>
    html {
      height: 2000px;
      overflow: hidden;
    }
    header {
      position: fixed;
      background: red;
      display: block;
      left: 0;
      right: 0;
      top: 0;
      height: 200px;
    }
  </style>
  <script type="application/javascript">
  function make_canvas() {
    var canvas = document.createElement("canvas");
    canvas.setAttribute("height", 2000);
    canvas.setAttribute("width", 500);
    return canvas;
  }

  SimpleTest.waitForExplicitFinish();
  window.addEventListener("load", runTests);
  
  window.scrollTo(0, 1000);

  async function runTests(event) {
    var testCanvas = make_canvas();
    var testCx = testCanvas.getContext("2d");
    var testWrapCx = SpecialPowers.wrap(testCx);

    // Take a snapshot of the page while scrolled down, so that the fixed header will
    // be visually in the middle of the root scroll frame, but should still be at the
    // top of the snapshot (since snapshots with a rect are taken relative to the document).
    var rect = new window.DOMRect(0, 0, 500, 2000);
    let image = await SpecialPowers.snapshotContext(window, rect, "rgb(255, 255, 255)", true);
    testWrapCx.drawImage(image, 0, 0);

    var refCanvas = make_canvas();
    var refCx = refCanvas.getContext("2d");

    // Construct a reference image with an equivalent red square at the top.
    refCx.fillStyle = "white";
    refCx.fillRect(0, 0, 500, 2000);
    refCx.fillStyle = "red";
    refCx.fillRect(0, 0, 500, 200);

    assertSnapshots(testCanvas, refCanvas, true, null, "position:fixed element with scrolling", "reference");

    SimpleTest.finish();
  }

  </script>
</head>
<body>
  <header></header>
</body>
</html>