DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (2aa33873a0c7)

VCS Links

Line Code
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Resource Timing: test behavior for reused 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 src="/common/get-host-info.sub.js"></script>
<script>
setup({explicit_done: true});
let d;
let iframe;
let iframeBody;
let count = 0;
const host = get_host_info();
const img_src = 'blue.png?id=cached';
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 = img_src;
    iframeBody.appendChild(image);

    const image2 = d.createElement('IMG');
    image2.addEventListener('load', function() {
        step_timeout(onload_test, 0); });
    image2.src = img_src;
    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/' + img_src] = '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://' + host.REMOTE_HOST + ':{{ports[http][1]}}{{location[path]}}/../resources/' + img_src;
    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://' + host.REMOTE_HOST + ':{{ports[http][1]}}'), 'Entry name should start with cross-origin domain');
    test_true(entries[0].name.endsWith('/resources/' + img_src), '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 reused 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>
<script>
    const img = document.createElement('IMG');
    img.src = "http://" + host.REMOTE_HOST + ":{{ports[http][1]}}{{location[path]}}/../resources/blue.png?id=cached";
    document.currentScript.parentNode.insertBefore(img, document.currentScript);
</script>
</body>
</html>