summaryrefslogtreecommitdiffstats
path: root/dom/performance/tests/test_performance_paint_timing_helper.html
blob: c05b38cac043702be62917a4545b8153e0da5eb7 (plain)
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
<!--
  Any copyright is dedicated to the Public Domain.
  http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE HTML>
<html>
    <!--
      https://bugzilla.mozilla.org/show_bug.cgi?id=1518999
    -->
    <head>
        <title>Test for Bug 1518999</title>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    </head>
    <body>
        <div id="main"></div>
        <div id="image"></div>
        <div id="test">
            <script class="testbody" type="text/javascript">
             async function runTest() {
                const paintEntries = performance.getEntriesByType('paint');
                opener.is(paintEntries.length, 0, "No paint entries yet");

                const img = document.createElement("img");
                img.src = "http://example.org/tests/dom/performance/tests/logo.png";

                img.onload = function() {
                  function getAndTestEntries(runCount) {
                    function testEntries(entries) {
                      opener.is(entries.length, 1, "FCP Only returns");
                      opener.is(entries[0].entryType, "paint", "entryType is paint");
                      opener.is(entries[0].name, "first-contentful-paint",
                                "Returned entry should be first-contentful-paint" );
                      const fcpEntriesGotByName =
                          performance.getEntriesByName('first-contentful-paint');
                      opener.is(fcpEntriesGotByName.length, 1, "entries length should match");
                      opener.is(entries[0], fcpEntriesGotByName[0], "should be the same entry");
                      opener.done();
                    }
                    const entries = performance.getEntriesByType('paint');
                    if (entries.length < 1) {
                      if (runCount < 4) {
                        opener.SimpleTest.requestFlakyTimeout("FCP is being registered asynchronously, so wait a bit of time");
                        setTimeout(function() {
                          getAndTestEntries(runCount + 1);
                        }, 20);
                      } else {
                        opener.ok(false, "Unable to find paint entries within a reasonable amount of time");
                        opener.done();
                      }
                    } else {
                        testEntries(entries);
                    }
                  }
                  getAndTestEntries(1);
                }
                document.body.appendChild(img);
             }
             window.onload = function() {
                runTest();
             }
            </script>
        </div>
        </div>
    </body>
</html>