summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/resource-timing/workerStart-tao-protected.https.html
blob: f54c0f2756eac3edc09602c113e7fdd55223a886 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Resource Timing - Check that workerStart is TAO protected</title>
<link rel="author" title="Google" href="http://www.google.com/" />
<link rel="help"
  href="https://www.w3.org/TR/resource-timing-2/#sec-performanceresourcetiming">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="resources/entry-invariants.js"></script>
<script src="resources/resource-loaders.js"></script>
</head>
<body>
<script>

const {HTTPS_REMOTE_ORIGIN} = get_host_info();

const worker_has_unregistered = new Promise(resolve => {
  addEventListener("message", e => {
    if (e.data === "unregistered") {
      resolve();
    }
  });
});

// Open window to remote origin with a SW install.
let openee;
const service_worker_has_installed = new Promise(resolve => {
  addEventListener("message", e => {
    if (e.data === 'installed') {
      resolve();
    }
  });
  openee = window.open(HTTPS_REMOTE_ORIGIN +
    "/resource-timing/resources/sw-install.html");
});

const load_after_sw_install = async path => {
  await service_worker_has_installed;
  return load.iframe(path);
}

attribute_test(load_after_sw_install,
  `${HTTPS_REMOTE_ORIGIN}/resource-timing/resources/green.html`,
  entry => {
    assert_equals(entry.workerStart, 0, "workerStart must be zero");
    invariants.assert_tao_failure_resource(entry);
  },
  "A resource from a cross-origin service worker must not expose workerStart " +
  "when there is a TAO failure");

attribute_test(load_after_sw_install,
  `${HTTPS_REMOTE_ORIGIN}/resource-timing/resources/blank-with-tao.html`,
  entry => {
    assert_greater_than(entry.workerStart, 0,
      "workerStart must be greater than zero");
    // TODO(crbug.com/925239): need to add coverage for transferSize,
    // encoded/decodedBodySize but that's broken right now.
    // TODO(crbug.com/1171767): need to add coverage for SW-handled resources
    // that redirect. Should workerStart be non-zero if any piece of the
    // redirect chain is handled by a SW?
  },
  "A resource from a cross-origin service worker must expose workerStart " +
  "when there is a TAO match");

promise_test(async () => {
  openee.postMessage("unregister", "*");
  await worker_has_unregistered;
  openee.close();
}, "Not a test - needed to unregister the SW and close its embedder");

</script>
</body>
</html>