blob: 630fed78c964bd439ec3151fed7c5b88760fdfb5 [file] [log] [blame]
Noam Rosenthal5c835812022-01-24 15:20:471<!DOCTYPE html>
2<meta charset="utf-8">
3<title>Test the sequence of events when reporting image timing.</title>
4<script src="/resources/testharness.js"></script>
5<script src="/resources/testharnessreport.js"></script>
6<body>
7<script>
8 function test_image_sequence(src, event, t) {
9 const image = document.createElement('img');
10 const absoluteURL = new URL(src, location.href).toString();
11 document.body.appendChild(image);
12 t.add_cleanup(() => image.remove());
13 return new Promise(resolve => {
14 image.addEventListener(event, t.step_func(() => {
15 assert_equals(performance.getEntriesByName(absoluteURL).length, 1);
16 resolve();
17 }));
18 image.src = src;
19 });
20 }
21 promise_test(t => test_image_sequence('resources/blue.png', 'load', t),
22 "An image should receive its load event after the ResourceTiming entry is available");
23
24 promise_test(t => test_image_sequence('resources/nothing-at-all.png', 'error', t),
25 "A non-existent (404) image should receive its error event after the ResourceTiming entry is available");
26
27 promise_test(t => test_image_sequence('resources/invalid.png', 'error', t),
28 "An invalid image should receive its error event after the ResourceTiming entry is available");
29</script>