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
|
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="timeout" content="long">
<title>Resource Timing: PerformanceResourceTiming interim resource times</title>
<link rel="author" title="Google" href="http://www.google.com/" />
<script src="/common/utils.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
const {REMOTE_ORIGIN} = get_host_info();
function interim_response_time_test({origin, with100, with103}) {
promise_test(async t => {
const delay = 500;
const url = new URL('/resource-timing/resources/header-delay.py',
origin == "same-origin" ? location.href : REMOTE_ORIGIN);
url.searchParams.set("delay", delay);
if (origin === "cross-origin-with-TAO")
url.searchParams.set("tao", "*");
if (with100)
url.searchParams.set("with100", "true");
if (with103)
url.searchParams.set("with103", "true");
const response = await fetch(url.toString(), {mode: "cors"});
assert_equals(response.status, 200)
await response.text();
const [entry] = performance.getEntriesByName(url.toString());
if (origin === "cross-origin") {
assert_equals(entry.firstInterimResponseStart, 0);
return;
}
let total_delay = entry.requestStart;
if (with100) {
total_delay += delay;
assert_greater_than(entry.firstInterimResponseStart,
total_delay,
"firstInterimResponseStart > 100 response");
}
if (with103) {
total_delay += delay;
if (with100) {
assert_less_than_equal(entry.firstInterimResponseStart,
total_delay, "firstInterimResponseStart > 100 response");
} else {
assert_greater_than(entry.firstInterimResponseStart,
delay, "firstInterimResponseStart > 100 response");
}
}
total_delay += delay;
if (!with100 && !with103)
assert_equals(entry.firstInterimResponseStart, 0);
assert_greater_than(entry.responseStart, total_delay,
"responseStart");
}, `Fetch from ${origin} ${with103 ? "with" : "without"} early hints, ${
with100 ? "with" : "without"} 100 response`);
}
for (const with103 of [true, false]) {
for (const with100 of [true, false]) {
for (origin of ['same-origin', 'cross-origin', 'cross-origin-with-TAO']) {
interim_response_time_test({with100, with103, origin});
}
}
}
</script>
</body>
</html>
|