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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
<!--
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]);
entries = window.performance.getEntriesByName("http://mochi.test:8888/tests/dom/tests/mochitest/general/resource_timing.js");
ok(!!entries[0], "same origin resource_timing.js is missing from entries");
checkSameOrigin(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 -->
<script type="text/javascript" src="http://mochi.test:8888/tests/dom/tests/mochitest/general/resource_timing.js"></script> <!-- same origin script -->
</div>
</body>
</html>
|