summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/network-error-logging/sends-report-on-cache-validation.https.html
blob: b87053cb7f7519c67f7592cabc68c8359201fb36 (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
<!DOCTYPE HTML>
<html>
<head>
  <title>
    Test that NEL reports are sent for cache validation requests
  </title>
  <script src='/resources/testharness.js'></script>
  <script src='/resources/testharnessreport.js'></script>
  <script src='./support/nel.sub.js'></script>
</head>
<body>
  <script>
    nel_test(async t => {
      // Fetch a resource that can be cached, but whose response requires
      // validation.  Do this *before* fetching the NEL policy for this origin,
      // to ensure that we don't generate any report about this request.
      await fetchValidatedCachedResource();
      // Fetch the NEL policy for this origin.
      await fetchResourceWithBasicPolicy();
      // Fetch the now-cached resource again.  Because the response requires
      // validation, this will result in a network request.
      await fetchValidatedCachedResource();
      // We should receive a report about the cache validation request.
      assert_true(await reportExists({
        url: getURLForValidatedCachedResource(),
        user_agent: navigator.userAgent,
        type: "network-error",
        body: {
          method: "GET",
          sampling_fraction: 1.0,
          status_code: 304,
          phase: "application",
          type: "ok",
        },
        metadata: {
          content_type: "application/reports+json",
        },
      }));
    });
  </script>
</body>
</html>