Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/misc/resource-timing-sizes-redirect-img.html

Issue 2105713002: Render process changes for ResourceTiming sizes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@resource_timing_sizes_browser_process
Patch Set: Initialise encoded_body_length for sync XHR to data: URLs Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <script src="/resources/testharness.js"></script>
3 <script src="/resources/testharnessreport.js"></script>
4 <script src="/resources/get-host-info.js?pipe=sub"></script>
5 <script>
6 // Redirects for fetch() always apply CORS rules, whereas normal resources
7 // don't, so this test covers extra code paths beyond those covered by
8 // resource-timing-sizes-redirect.html.
9
10 const baseUrl = new URL('/resources/square20.png', location.href).href;
11
12 // Because apache decrements the Keep-Alive max value on each request, the
13 // transferSize will vary slightly between requests for the same resource.
14 const fuzzFactor = 3; // bytes
15
16 const minHeaderSize = 100;
17
18 const hostInfo = get_host_info();
19
20 var directUrl, sameOriginRedirect, crossOriginRedirect, mixedRedirect;
21 var complexRedirect;
22 var t = async_test('PerformanceResourceTiming sizes redirects img');
23
24 function checkResourceSizes() {
25 var entries = performance.getEntriesByType('resource');
26 var lowerBound, upperBound, withRedirectLowerBound;
27 var seenCount = 0;
28 for (var entry of entries) {
29 switch (entry.name) {
30 case directUrl:
31 assert_greater_than(entry.transferSize, minHeaderSize,
32 'direct transferSize');
33 lowerBound = entry.transferSize - fuzzFactor;
34 upperBound = entry.transferSize + fuzzFactor;
35 withRedirectLowerBound = entry.transferSize + minHeaderSize;
36 ++seenCount;
37 break;
38
39 case sameOriginRedirect:
40 assert_greater_than(entry.transferSize, withRedirectLowerBound,
41 'same origin transferSize');
42 ++seenCount;
43 break;
44
45 case crossOriginRedirect:
46 case mixedRedirect:
47 case complexRedirect:
48 assert_between_exclusive(entry.transferSize, lowerBound, upperBound,
49 'cross origin transferSize');
50 ++seenCount;
51 break;
52
53 default:
54 break;
55 }
56 }
57 assert_equals(seenCount, 5, 'seenCount');
58 t.done();
59 }
60
61 function redirectUrl(redirectSourceOrigin, targetUrl) {
62 return redirectSourceOrigin +
63 '/resources/redirect.php?url=' + encodeURIComponent(targetUrl);
64 }
65
66 // Loads the images in |urlArray| in sequence, finally calling |callback|.
67 // |callback| will be wrapped in t.step_func() when called.
68 function loadImages(urlArray, callback) {
69 var url = urlArray.shift();
70 var onload;
71 if (urlArray.length === 0) {
72 onload = t.step_func(callback);
73 } else {
74 onload = () => { loadImages(urlArray, callback); };
75 }
76 var img = document.createElement('img');
77 img.src = url;
78 img.onload = onload;
79 img.onerror = t.step_func(() => assert_unreached('Failed to load ' + url));
80 img.style = 'display: none;';
81 }
82
83 function cacheBustedUrl() {
84 return baseUrl + '?unique=' + Math.random().toString().substring(2);
85 }
86
87 function runTest() {
88 directUrl = cacheBustedUrl();
89 sameOriginRedirect = redirectUrl(hostInfo.HTTP_ORIGIN, cacheBustedUrl());
90 crossOriginRedirect = redirectUrl(hostInfo.HTTP_REMOTE_ORIGIN,
91 cacheBustedUrl());
92 mixedRedirect = redirectUrl(hostInfo.HTTP_REMOTE_ORIGIN,
93 redirectUrl(
94 hostInfo.HTTP_ORIGIN, cacheBustedUrl()));
95 complexRedirect = redirectUrl(hostInfo.HTTP_ORIGIN,
96 redirectUrl(hostInfo.HTTP_REMOTE_ORIGIN,
97 redirectUrl(hostInfo.HTTP_ORIGIN,
98 cacheBustedUrl())));
99 loadImages([directUrl, sameOriginRedirect, crossOriginRedirect,
100 mixedRedirect, complexRedirect], checkResourceSizes);
101 }
102
103 t.step(runTest);
104 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698