https://github.com/web-platform-tests/wpt
Revision 951ade940eacfdad4de7530058690a10637a277d authored by Geoffrey Sneddon on 09 April 2018, 11:49:58 UTC, committed by Geoffrey Sneddon on 09 April 2018, 11:49:58 UTC
1 parent 5d7a6b3
Raw File
Tip revision: 951ade940eacfdad4de7530058690a10637a277d authored by Geoffrey Sneddon on 09 April 2018, 11:49:58 UTC
fixup! Move the config into its own class
Tip revision: 951ade9
resource_memory_cached.sub.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Resource Timing memory cached resources</title>
<link rel="author" title="Google" href="http://www.google.com/" />
<link rel="help" href="http://www.w3.org/TR/resource-timing/#dom-performanceresourcetiming-initiatortype"/>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/webperftestharness.js"></script>
<script src="resources/webperftestharnessextension.js"></script>
<script>
setup({explicit_done: true});
let d;
let iframe;
let iframeBody;
let count = 0;
function onload_prep() {
    iframe = document.getElementById('frameContext');
    d = iframe.contentWindow.document;
    iframeBody = d.body;

    const image = d.createElement('img');
    image.addEventListener('load', function() {
        step_timeout(onload_test, 0); });
    image.src = 'blue.png?id=cached';
    iframeBody.appendChild(image);

    const image2 = d.createElement('img');
    image2.addEventListener('load', function() {
        step_timeout(onload_test, 0); });
    image2.src = 'blue.png?id=cached';
    iframeBody.appendChild(image2);
}

function onload_test() {
    ++count;
    if (count < 2)
        return;

    const context = new PerformanceContext(iframe.contentWindow.performance);
    const entries = context.getEntriesByType('resource');
    test_equals(entries.length, 1, "There should be only one entry");

    const index = window.location.pathname.lastIndexOf('/');
    const pathname = window.location.pathname.substring(0, index);
    let expected_entries = {};
    expected_entries[pathname + '/resources/blue.png?id=cached'] = 'img';
    test_resource_entries(entries, expected_entries);
    test_greater_than(entries[0].requestStart, 0, 'requestStart should be non-zero on the same-origin request');
    test_greater_or_equals(entries[0].responseEnd, entries[0].startTime, 'responseEnd should not be before startTime');
    test_greater_or_equals(entries[0].duration, 0, 'duration should not be negative');

    context.clearResourceTimings();
    start_crossorigin_test();
}
function start_crossorigin_test() {
    const image3 = d.createElement('img');
    image3.addEventListener("load", function() { step_timeout(finish_crossorigin_test, 0); });
    image3.src = 'http://{{domains[www1]}}:{{ports[http][1]}}{{location[path]}}/../resources/blue.png?id=cached';
    iframeBody.appendChild(image3);
}
function finish_crossorigin_test() {
    const context = new PerformanceContext(iframe.contentWindow.performance);
    const entries = context.getEntriesByType('resource');
    test_equals(entries.length, 1, 'There should be one entry in second test');
    test_true(entries[0].name.startsWith('http://{{domains[www1]}}:{{ports[http][1]}}'), 'Entry name should start with cross-origin domain');
    test_true(entries[0].name.endsWith('/resources/blue.png?id=cached'), 'Entry name should end with file name');
    test_equals(entries[0].requestStart, 0, 'requestStart should be 0 on the cross-origin request');
    done();
}
window.setup_iframe = () => {};
window.addEventListener('load', onload_prep);
</script>
</head>
<body>
<h1>Description</h1>
<p>This test validates that a memory cached resource appears in the buffer once.</p>
<div id="log"></div>
<iframe id="frameContext" src="resources/inject_resource_test.html"></iframe>
<img src="resources/blue.png?id=cached"></img>
<img src="http://{{domains[www1]}}:{{ports[http][1]}}{{location[path]}}/../resources/blue.png?id=cached"></img>
</body>
</html>
back to top