OLD | NEW |
---|---|
(Empty) | |
1 <!DOCTYPE html> | |
2 <script src="/resources/testharness.js"></script> | |
3 <script src="/resources/testharnessreport.js"></script> | |
4 <script src="/misc/resources/run-async-tasks-promise.js"></script> | |
5 <script> | |
6 // The header bytes are expected to be > |minHeaderSize| and | |
7 // < |maxHeaderSize|. If they are outside this range the test will fail. | |
8 const minHeaderSize = 100; | |
9 const maxHeaderSize = 1024; | |
10 | |
11 // The size of this resource must be > maxHeaderSize for the test to be | |
12 // reliable. | |
13 var url = new URL('/resources/square.png', location.href).href; | |
14 const expectedSize = 18299; | |
15 | |
16 function checkBodySizeFields(entry, expectedSize) { | |
17 assert_equals(entry.decodedBodySize, expectedSize, 'decodedBodySize'); | |
18 assert_equals(entry.encodedBodySize, expectedSize, 'encodedBodySize'); | |
19 } | |
20 | |
21 function checkResourceSizes() { | |
22 var entries = performance.getEntriesByType('resource'); | |
23 var seenCount = 0; | |
24 for (var entry of entries) { | |
25 if (entry.name === url) { | |
26 checkBodySizeFields(entry, expectedSize); | |
27 if (seenCount === 0) { | |
28 // 200 response | |
29 assert_between_exclusive(entry.transferSize, | |
30 expectedSize + minHeaderSize, | |
31 expectedSize + maxHeaderSize, | |
32 '200 transferSize'); | |
33 } else if (seenCount === 1) { | |
34 // from cache | |
35 assert_equals(entry.transferSize, 0, 'cached transferSize'); | |
36 } else if (seenCount === 2) { | |
37 // 304 response | |
38 assert_between_exclusive(entry.transferSize, minHeaderSize, | |
39 maxHeaderSize, '304 transferSize'); | |
40 } else { | |
41 assert_unreached('Too many matching fetches.'); | |
42 } | |
43 ++seenCount; | |
44 } | |
45 } | |
Kunihiko Sakamoto
2016/07/07 09:56:50
Add assertion for seenCount value?
Adam Rice
2016/07/07 11:21:12
I switched to using getEntriesByName(url) and adde
| |
46 } | |
47 | |
48 promise_test(() => { | |
49 // Use a different URL every time so that the cache behaviour does not | |
50 // depend on execution order. | |
51 url = url + '?unique=' + Math.random().toString().substring(2); | |
52 var eatBody = response => response.arrayBuffer(); | |
53 var mustRevalidate = {headers: {'Cache-Control': 'max-age=0'}}; | |
54 return fetch(url) | |
55 .then(eatBody) | |
56 .then(() => fetch(url)) | |
57 .then(eatBody) | |
58 .then(() => fetch(url, mustRevalidate)) | |
59 .then(eatBody) | |
60 .then(runAsyncTasks) | |
61 .then(checkResourceSizes); | |
62 }, 'PerformanceResourceTiming sizes caching test'); | |
63 | |
64 </script> | |
OLD | NEW |