summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/resource-timing/sizes-redirect-img.html
blob: e440029782b5d5e7637dfa30683d6f77a72d61b1 (plain)
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
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="resources/sizes-helper.js"></script>
<script src="resources/resource-loaders.js"></script>
<script src="resources/entry-invariants.js"></script>
<script>
// Redirects for fetch() always apply CORS rules, whereas normal resources
// don't, so this test covers extra code paths beyond those covered by
// resource-timing-sizes-redirect.html.

const baseUrl = new URL('/resource-timing/resources/TAOResponse.py?tao=wildcard&img=true', location.href).href;

const expectedSize = 1010;

const hostInfo = get_host_info();

const redirectUrl = (redirectSourceOrigin, targetUrl) => {
  return redirectSourceOrigin +
    '/resource-timing/resources/redirect-cors.py?allow_origin=*&timing_allow_origin=*' +
    '&location=' + encodeURIComponent(targetUrl);
};

const verify_entry = entry => {
  checkSizeFields(entry, expectedSize, expectedSize + headerSize);
};

attribute_test(load.image, baseUrl,
  verify_entry,
  "PerformanceResourceTiming sizes redirect image - direct URL");

attribute_test(load.image,
  redirectUrl(hostInfo.HTTP_ORIGIN, baseUrl),
  verify_entry,
  "PerformanceResourceTiming sizes redirect image - same origin redirect");

attribute_test(load.image_cors,
  redirectUrl(hostInfo.HTTP_REMOTE_ORIGIN, baseUrl),
  verify_entry,
  "PerformanceResourceTiming sizes redirect image - cross origin redirect");

attribute_test(load.image_cors,
  redirectUrl(hostInfo.HTTP_REMOTE_ORIGIN,
    redirectUrl(hostInfo.HTTP_ORIGIN, baseUrl)),
  verify_entry,
  "PerformanceResourceTiming sizes redirect image - cross origin to same origin redirect");

attribute_test(load.image_cors,
  redirectUrl(hostInfo.HTTP_ORIGIN,
    redirectUrl(hostInfo.HTTP_REMOTE_ORIGIN,
      redirectUrl(hostInfo.HTTP_ORIGIN,
        baseUrl))),
  verify_entry,
  "PerformanceResourceTiming sizes redirect image - same origin to remote " +
  "origin to same origin redirect");
</script>