blob: f156e1a32c4863aecf770c6f18e7bb88e8b694ee [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) {
James Graham163424c2019-05-17 16:47:0317 if (!window.PerformanceElementTiming) {
18 assert_unreached("PerformanceElementTiming is not implemented");
19 }
Nicolás Peña Moreno84bcab62019-03-06 17:00:4720 const img_src = 'resources/progressive-image.py?name=square20.jpg&numInitial='
21 + numInitial + '&sleep=' + sleep;
Nicolas Pena6e9d51e2019-01-30 15:25:0022 const observer = new PerformanceObserver(
23 t.step_func_done(function(entryList) {
24 assert_equals(entryList.getEntries().length, 1);
25 const entry = entryList.getEntries()[0];
Nicolás Peña Morenoe42570f2019-10-21 21:23:0926 const pathname = window.location.origin + '/element-timing/' + img_src;
Nicolas Pena6e9d51e2019-01-30 15:25:0027 // Since the image is only fully loaded after the sleep, the render timestamp
28 // must be greater than |beforeRender| + |sleep|.
Nicolás Peña Moreno66bb6b42019-05-01 17:40:5829 checkElement(entry, pathname, 'my_image', '', beforeRender + sleep, img);
Nicolás Peña Morenocf8e8812019-04-01 17:12:0230 checkNaturalSize(entry, 20, 20);
Nicolas Pena6e9d51e2019-01-30 15:25:0031 })
32 );
33 observer.observe({entryTypes: ['element']});
34
Nicolás Peña Moreno66bb6b42019-05-01 17:40:5835 img = document.createElement('img');
Nicolás Peña Moreno84bcab62019-03-06 17:00:4736 img.src = img_src;
Nicolas Pena6e9d51e2019-01-30 15:25:0037 img.setAttribute('elementtiming', 'my_image');
38 document.body.appendChild(img);
39 beforeRender = performance.now();
40 t.step_timeout(() => {assert_true(0);}, 2000);
41 }, "Element Timing: image render timestamp occurs after it is fully loaded.");
42</script>