summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/element-timing/redirects-tao-star.html
blob: e5067d3d6bd7915522bfb670fad0919f0e4101fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8" />
<title>This test validates element timing information for cross-origin redirect chain images.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/element-timing-helpers.js"></script>
<script src=/common/get-host-info.sub.js></script>
</head>
<body>
<script>
async_test(t => {
    assert_implements(window.PerformanceElementTiming, "PerformanceElementTiming is not implemented");
    let destUrl = get_host_info().HTTP_REMOTE_ORIGIN
            + '/resource-timing/resources/multi_redirect.py?';
    destUrl += 'page_origin=' +  get_host_info().HTTP_ORIGIN;
    destUrl += '&cross_origin=' + get_host_info().HTTP_REMOTE_ORIGIN;
    destUrl += '&final_resource=' + '/element-timing/resources/circle-tao.svg';
    destUrl += '&timing_allow=1';
    destUrl += '&tao_steps=';
    for (let taoSteps=0; taoSteps < 4; taoSteps++) {
        const image = document.createElement('img');
        image.src = destUrl + taoSteps;
        image.setAttribute('elementtiming', taoSteps);
        image.setAttribute('id', 'id' + taoSteps)
        document.body.appendChild(image);
    }
    let numObserved = 0;
    let observedMap = [false, false, false, false];
    const beforeRender = performance.now();
    new PerformanceObserver(t.step_func(entries => {
        entries.getEntries().forEach(entry => {
            const taoSteps = entry.identifier;
            assert_false(observedMap[taoSteps], 'Should observe each image once');
            observedMap[taoSteps] = true;
            if (taoSteps !== '3') {
                assert_equals(entry.renderTime, 0,
                    'renderTime should be 0 when there is ' + taoSteps + ' tao steps');
            }
            const bound = taoSteps === '3' ? beforeRender : 0;
            checkElement(entry, destUrl + taoSteps, taoSteps, 'id' + taoSteps, bound,
                    document.getElementById(taoSteps));
        });
        numObserved += entries.getEntries().length;
        if (numObserved === 4)
            t.done();
    })).observe({type: 'element', buffered: true});
}, 'Cross-origin image without TAO should not have its renderTime set, with full TAO it should.');
</script>
</body>
</html>