Revision 83be7773ed3e2df8c2f8625d11ec35358586e48c authored by Anne van Kesteren on 13 March 2018, 17:31:34 UTC, committed by Anne van Kesteren on 13 March 2018, 17:31:34 UTC
See https://github.com/whatwg/html/pull/3562.
1 parent 970fca8
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>
![swh spinner](/static/img/swh-spinner.gif)
Computing file changes ...