blob: c0a7d4f1fb76ffdade7df5f2663f1e33de84e7f3 [file] [log] [blame]
Nicolas Pena6e9d51e2019-01-30 15:25:001<!DOCTYPE html>
2<html>
3<meta charset=utf-8 />
4<title>Element Timing: buffer elements before onload</title>
5<script src=/resources/testharness.js></script>
6<script src=/resources/testharnessreport.js></script>
7<script src="resources/element-timing-helpers.js"></script>
8<body>
9<script>
10 let beforeRender;
11 // Number of characters to be read on the initial read, before sleeping.
12 // Should be sufficient to do at least a first scan.
13 let numInitial = 75;
14 let sleep = 500;
15 async_test(function(t) {
Nicolás Peña Moreno84bcab62019-03-06 17:00:4716 const img_src = 'resources/progressive-image.py?name=square20.jpg&numInitial='
17 + numInitial + '&sleep=' + sleep;
Nicolas Pena6e9d51e2019-01-30 15:25:0018 const observer = new PerformanceObserver(
19 t.step_func_done(function(entryList) {
20 assert_equals(entryList.getEntries().length, 1);
21 const entry = entryList.getEntries()[0];
Nicolás Peña Moreno84bcab62019-03-06 17:00:4722 const index = window.location.href.lastIndexOf('/');
23 const pathname = window.location.href.substring(0, index) + '/' +
24 img_src;
Nicolas Pena6e9d51e2019-01-30 15:25:0025 // Since the image is only fully loaded after the sleep, the render timestamp
26 // must be greater than |beforeRender| + |sleep|.
Nicolás Peña Moreno15d28552019-04-01 19:03:0827 checkElement(entry, pathname, 'my_image', '', beforeRender + sleep);
Nicolás Peña Morenocf8e8812019-04-01 17:12:0228 checkNaturalSize(entry, 20, 20);
Nicolas Pena6e9d51e2019-01-30 15:25:0029 })
30 );
31 observer.observe({entryTypes: ['element']});
32
33 const img = document.createElement('img');
Nicolás Peña Moreno84bcab62019-03-06 17:00:4734 img.src = img_src;
Nicolas Pena6e9d51e2019-01-30 15:25:0035 img.setAttribute('elementtiming', 'my_image');
36 document.body.appendChild(img);
37 beforeRender = performance.now();
38 t.step_timeout(() => {assert_true(0);}, 2000);
39 }, "Element Timing: image render timestamp occurs after it is fully loaded.");
40</script>