|
| 1 | +const image_delay = 1000; |
| 2 | +const delay_pipe_value = image_delay / 1000; |
| 3 | + |
1 | 4 | // Receives an image LargestContentfulPaint |entry| and checks |entry|'s attribute values.
|
2 | 5 | // The |timeLowerBound| parameter is a lower bound on the loadTime value of the entry.
|
3 | 6 | // The |options| parameter may contain some string values specifying the following:
|
@@ -33,4 +36,33 @@ function checkImage(entry, expectedUrl, expectedID, expectedSize, timeLowerBound
|
33 | 36 | } else {
|
34 | 37 | assert_equals(entry.size, expectedSize);
|
35 | 38 | }
|
| 39 | + if (options.includes('animated')) { |
| 40 | + assert_greater_than(entry.loadTime, entry.firstAnimatedFrameTime, |
| 41 | + 'firstAnimatedFrameTime should be smaller than loadTime'); |
| 42 | + assert_greater_than(entry.renderTime, entry.firstAnimatedFrameTime, |
| 43 | + 'firstAnimatedFrameTime should be smaller than renderTime'); |
| 44 | + assert_less_than(entry.firstAnimatedFrameTime, image_delay, |
| 45 | + 'firstAnimatedFrameTime should be smaller than the delay applied to the second frame'); |
| 46 | + assert_greater_than(entry.firstAnimatedFrameTime, 0, |
| 47 | + 'firstAnimatedFrameTime should be larger than 0'); |
| 48 | + } |
| 49 | + if (options.includes('animated-zero')) { |
| 50 | + assert_equals(entry.firstAnimatedFrameTime, 0, 'firstAnimatedFrameTime should be 0'); |
| 51 | + } |
36 | 52 | }
|
| 53 | + |
| 54 | +const load_and_observe = url => { |
| 55 | + return new Promise(resolve => { |
| 56 | + (new PerformanceObserver(entryList => { |
| 57 | + for (let entry of entryList.getEntries()) { |
| 58 | + if (entry.url == url) { |
| 59 | + resolve(entryList.getEntries()[0]); |
| 60 | + } |
| 61 | + } |
| 62 | + })).observe({type: 'largest-contentful-paint', buffered: true}); |
| 63 | + const img = new Image(); |
| 64 | + img.id = 'image_id'; |
| 65 | + img.src = url; |
| 66 | + document.body.appendChild(img); |
| 67 | + }); |
| 68 | +}; |
0 commit comments