Bug 936814 - Part 3: Add tests for cross origin resource timing check r=bz

This commit is contained in:
Valentin Gosu 2014-09-10 10:00:59 +03:00
Родитель 37ba14d4ad
Коммит c69a596dda
20 изменённых файлов: 264 добавлений и 0 удалений

Просмотреть файл

@ -14,6 +14,24 @@ support-files =
historyframes.html
resource_timing_iframe.html
resource_timing_main_test.html
resource_timing_cross_origin.html
res0.resource
res1.resource
res1.resource^headers^
res2.resource
res2.resource^headers^
res3.resource
res3.resource^headers^
res4.resource
res4.resource^headers^
res5.resource
res5.resource^headers^
res6.resource
res6.resource^headers^
res7.resource
res7.resource^headers^
res8.resource
res8.resource^headers^
[test_497898.html]
skip-if = (buildapp == 'b2g' && toolkit != 'gonk') || toolkit == 'android' #Bug 931116, b2g desktop specific, initial triage
@ -57,6 +75,8 @@ skip-if = buildapp == 'mulet'
[test_picture_pref.html]
[test_resource_timing.html]
skip-if = buildapp == 'b2g' || buildapp == 'mulet' # b2g(No clipboard) b2g-debug(No clipboard) b2g-desktop(No clipboard)
[test_resource_timing_cross_origin.html]
skip-if = buildapp == 'b2g' || buildapp == 'mulet'
[test_performance_now.html]
[test_srcset_pref.html]
[test_showModalDialog.html]

Просмотреть файл

Просмотреть файл

Просмотреть файл

@ -0,0 +1,2 @@
HTTP 200
Timing-Allow-Origin: *

Просмотреть файл

Просмотреть файл

@ -0,0 +1,2 @@
HTTP 302 Moved
Location: http://test2.example.com/tests/image/test/mochitest/red.png

Просмотреть файл

Просмотреть файл

@ -0,0 +1,2 @@
HTTP 200
Timing-Allow-Origin: http://mochi.test:8888

Просмотреть файл

Просмотреть файл

@ -0,0 +1,3 @@
HTTP 302 Moved
Timing-Allow-Origin: *
Location: http://mochi.test:8888/tests/dom/tests/mochitest/general/res1.resource

Просмотреть файл

Просмотреть файл

@ -0,0 +1,2 @@
HTTP 200
Timing-Allow-Origin: http://mochi.test:8889

Просмотреть файл

Просмотреть файл

@ -0,0 +1,2 @@
HTTP 200
Timing-Allow-Origin:

Просмотреть файл

Просмотреть файл

@ -0,0 +1,2 @@
HTTP 200
Timing-Allow-Origin: http://mochi.test:8888 http://test1.com

Просмотреть файл

Просмотреть файл

@ -0,0 +1,2 @@
HTTP 302 Moved
Location: http://test1.example.com/tests/dom/tests/mochitest/general/res4.resource

Просмотреть файл

@ -0,0 +1,182 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE HTML>
<html>
<head>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="application/javascript">
function ok(cond, message) {
window.opener.ok(cond, message)
}
function is(received, expected, message) {
window.opener.is(received, expected, message);
}
function isnot(received, notExpected, message) {
window.opener.isnot(received, notExpected, message);
}
var bufferFullCounter = 0;
const expectedBufferFullEvents = 0;
const properties = ["startTime", "redirectStart", "redirectEnd", "fetchStart",
"domainLookupStart", "domainLookupEnd", "connectStart",
"connectEnd", "requestStart", "responseStart", "responseEnd"];
window.onload = function() {
ok(!!window.performance, "Performance object should exist");
ok(!!window.performance.getEntries, "Performance.getEntries() should exist");
ok(!!window.performance.getEntriesByName, "Performance.getEntriesByName() should exist");
ok(!!window.performance.getEntriesByType, "Performance.getEntriesByType() should exist");
window.performance.onresourcetimingbufferfull = function() {
bufferFullCounter += 1;
}
makeXhr("http://mochi.test:8888/tests/dom/tests/mochitest/general/test-data.json", firstCheck);
};
function firstCheck() {
var entries = window.performance.getEntriesByName("http://mochi.test:8888/tests/dom/tests/mochitest/general/test-data.json");
ok(!!entries[0], "same origin test-data.json is missing from entries");
checkSameOrigin(entries[0]);
var entries = window.performance.getEntriesByName("http://mochi.test:8888/tests/dom/tests/mochitest/general/res0.resource");
ok(!!entries[0], "same origin res0.resource is missing from entries");
checkSameOrigin(entries[0]);
entries = window.performance.getEntriesByName("http://test1.example.com/tests/dom/tests/mochitest/general/res0.resource");
ok(!!entries[0], "cross origin res0.resource is missing from entries");
checkCrossOrigin(entries[0]);
entries = window.performance.getEntriesByName("http://test1.example.com/tests/dom/tests/mochitest/general/res1.resource");
ok(!!entries[0], "res1.resource is missing from entries");
checkSameOrigin(entries[0]);
entries = window.performance.getEntriesByName("http://test1.example.com/tests/dom/tests/mochitest/general/res2.resource");
ok(!!entries[0], "redirected res2.resource is missing from entries");
checkRedirectedCrossOrigin(entries[0]);
entries = window.performance.getEntriesByName("http://test1.example.com/tests/dom/tests/mochitest/general/res3.resource");
ok(!!entries[0], "cross origin res3.resource is missing from entries");
checkSameOrigin(entries[0]);
entries = window.performance.getEntriesByName("http://test1.example.com/tests/dom/tests/mochitest/general/res4.resource");
ok(!!entries[0], "redirected res4.resource is missing from entries");
checkRedirectedSameOrigin(entries[0]);
entries = window.performance.getEntriesByName("http://test1.example.com/tests/dom/tests/mochitest/general/res5.resource");
ok(!!entries[0], "cross origin res5.resource is missing from entries");
checkCrossOrigin(entries[0]);
entries = window.performance.getEntriesByName("http://test1.example.com/tests/dom/tests/mochitest/general/res6.resource");
ok(!!entries[0], "cross origin res6.resource is missing from entries");
checkCrossOrigin(entries[0]);
entries = window.performance.getEntriesByName("http://test1.example.com/tests/dom/tests/mochitest/general/res7.resource");
ok(!!entries[0], "cross origin res7.resource is missing from entries");
checkCrossOrigin(entries[0]);
entries = window.performance.getEntriesByName("http://test1.example.com/tests/dom/tests/mochitest/general/res8.resource");
ok(!!entries[0], "redirected res8.resource is missing from entries");
checkRedirectCrossOriginResourceSameOrigin(entries[0]);
is(bufferFullCounter, expectedBufferFullEvents, "Buffer full was called");
finishTests();
}
function checkEntry(entry, checks) {
// If the entry is undefined, we return early so we don't get a JS error
if (entry == undefined)
return;
for (var j = 1; j < properties.length; ++j) {
var prop = properties[j];
if (checks[prop] != undefined) {
is(entry[prop], checks[prop], "Wrong value for prop " + prop + " for resource " + entry.name);
} else {
isnot(entry[prop], 0, "Wrong value for prop " + prop + " for resource " + entry.name);
}
}
}
// No redirects have occured so RedirectStart/End are 0
function checkSameOrigin(entry) {
const checks = { "redirectStart": 0, "redirectEnd": 0 };
checkEntry(entry, checks);
}
// This is a cross-origin resource that doesn't pass the check
// All of these attributes are 0. No redirects
function checkCrossOrigin(entry) {
const checks = { "redirectStart": 0, "redirectEnd": 0,
"domainLookupStart": 0, "domainLookupEnd": 0,
"connectStart": 0, "connectEnd": 0,
"requestStart": 0, "responseStart": 0 };
checkEntry(entry, checks);
}
// A cross-origin redirect has occured. RedirectStart/End and the rest of the
// attributes are 0.
function checkRedirectedCrossOrigin(entry) {
const checks = { "redirectStart": 0, "redirectEnd": 0,
"domainLookupStart": 0, "domainLookupEnd": 0,
"connectStart": 0, "connectEnd": 0,
"requestStart": 0, "responseStart": 0 };
checkEntry(entry, checks);
}
// The redirect is to the same origin as the initial document,
// so no entries are 0.
function checkRedirectedSameOrigin(entry) {
const checks = { };
checkEntry(entry, checks);
}
// The final entry passes the timing-allow-check,
// but one of the redirects does not. redirectStart/End are 0.
function checkRedirectCrossOriginResourceSameOrigin(entry) {
const checks = { "redirectStart": 0, "redirectEnd": 0 };
checkEntry(entry, checks);
}
function makeXhr(aUrl, aCallback) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onload = aCallback;
xmlhttp.open("get", aUrl, true);
xmlhttp.send();
}
function finishTests() {
window.opener.finishTests();
}
</script>
<body>
<a target="_blank"
href="https://bugzilla.mozilla.org/show_bug.cgi?id=822480"
title="Add resource timing API.">
Bug #822480 - Add in the Resource Timing API
</a>
<p id="display"></p>
<div id="content">
<object data="http://mochi.test:8888/tests/dom/tests/mochitest/general/res0.resource"> <!-- same origin, no header -->
<object data="http://test1.example.com/tests/dom/tests/mochitest/general/res0.resource"> <!-- cross origin, no header -->
<object data="http://test1.example.com/tests/dom/tests/mochitest/general/res1.resource"> <!-- cross origin, Timing-Allow-Origin: * header -->
<object data="http://test1.example.com/tests/dom/tests/mochitest/general/res2.resource"> <!-- cross origin redirect to test2.example.com, no header -->
<object data="http://test1.example.com/tests/dom/tests/mochitest/general/res3.resource"> <!-- cross origin, Timing-Allow-Origin: http://mochi.test:8888 header -->
<object data="http://test1.example.com/tests/dom/tests/mochitest/general/res4.resource"> <!-- cross origin redirect to mochi.test:8888/.../res1.resource, Timing-Allow-Origin: * -->
<object data="http://test1.example.com/tests/dom/tests/mochitest/general/res5.resource"> <!-- cross origin, Timing-Allow-Origin: http://mochi.test:8889 -->
<object data="http://test1.example.com/tests/dom/tests/mochitest/general/res6.resource"> <!-- cross origin, Timing-Allow-Origin: "" (empty string) -->
<object data="http://test1.example.com/tests/dom/tests/mochitest/general/res7.resource"> <!-- cross origin, Timing-Allow-Origin: http://mochi.test:8888 http://test1.com header -->
<object data="http://test1.example.com/tests/dom/tests/mochitest/general/res8.resource"> <!-- double cross origin redirect -->
</div>
</body>
</html>

Просмотреть файл

@ -0,0 +1,45 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=822480
-->
<head>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<pre id="test">
<script type="application/javascript">
SimpleTest.waitForExplicitFinish();
// Resource timing is prefed off by default, so we had to use this workaround
var subwindow = null;
SpecialPowers.pushPrefEnv({"set": [["dom.enable_resource_timing", true]]}, start);
function start() {
subwindow = window.open("resource_timing_cross_origin.html");
}
function finishTests() {
subwindow.close();
SpecialPowers.pushPrefEnv({"clear":[["dom.enable_resource_timing"]]}, SimpleTest.finish);
}
</script>
</pre>
<a target="_blank"
href="https://bugzilla.mozilla.org/show_bug.cgi?id=936814"
title="Cross origin resource timing">
Bug #936814 - Implement the "timing allow check algorithm" for cross-origin Resource Timing
</a>
</body>
</html>