Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

<meta charset=utf-8>
<title>Largest Contentful Paint: observe cross origin images with various Timing-Allow-Origin headers</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/largest-contentful-paint-helpers.js"></script>
<div id='my_div'></div>
setup({"hide_test_state": true});
async_test(t => {
assert_implements(window.LargestContentfulPaint, "LargestContentfulPaint is not implemented");
+ 'origin=' + window.location.origin +'&tao=';
const valid_tao = ['wildcard', 'origin', 'multi', 'multi_wildcard', 'match_origin', 'match_wildcard'];
const invalid_tao = ['null', 'space', 'uppercase'];
const div = document.getElementById('my_div');
let img_length = 20;
function addImage(tao) {
const img = document.createElement('img');
img.src = remote_img + tao; = tao;
// Set increasing size so that largest-contentful-paint captures all of them.
img.height = img_length;
img.width = img_length;
let img_count = 0;
const total_images = valid_tao.length + invalid_tao.length;
let beforeLoad;
new PerformanceObserver(
t.step_func(entryList => {
assert_equals(entryList.getEntries().length, 1);
const entry = entryList.getEntries()[0];
const tao =;
const url = remote_img + tao;
const size = img_length * img_length;
let options = valid_tao.includes(tao) ? [] : ['renderTimeIs0'];
checkImage(entry, url, tao, size, beforeLoad, options);
beforeLoad =;
// Process valid TAO images first.
if (img_count < valid_tao.length)
// Then add invalid TAO images.
else if (img_count < total_images)
addImage(invalid_tao[img_count - valid_tao.length]);
// Once we've seen all the images, end the test.
).observe({type: 'largest-contentful-paint'});
// Add first image, the rest will be added on each observer callback.
beforeLoad =;
}, 'Cross-origin elements with valid TAO have correct renderTime, with invalid TAO have renderTime set to 0.');