blob: 6695d8f9c324b0c20f9b19c1f064a7349c770d5d [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;
Nicolás Peña Moreno66bb6b42019-05-01 17:40:5811 let img;
Nicolas Pena6e9d51e2019-01-30 15:25:0012 // Number of characters to be read on the initial read, before sleeping.
13 // Should be sufficient to do at least a first scan.
14 let numInitial = 75;
15 let sleep = 500;
16 async_test(function(t) {
Stephen McGruerdcfc14d2020-04-16 13:23:0317 assert_implements(window.PerformanceElementTiming, "PerformanceElementTiming is not implemented");
Nicolás Peña Moreno84bcab62019-03-06 17:00:4718 const img_src = 'resources/progressive-image.py?name=square20.jpg&numInitial='
19 + numInitial + '&sleep=' + sleep;
Nicolas Pena6e9d51e2019-01-30 15:25:0020 const observer = new PerformanceObserver(
21 t.step_func_done(function(entryList) {
22 assert_equals(entryList.getEntries().length, 1);
23 const entry = entryList.getEntries()[0];
Nicolás Peña Morenoe42570f2019-10-21 21:23:0924 const pathname = window.location.origin + '/element-timing/' + 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 Moreno66bb6b42019-05-01 17:40:5827 checkElement(entry, pathname, 'my_image', '', beforeRender + sleep, img);
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
Nicolás Peña Moreno66bb6b42019-05-01 17:40:5833 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>