testing/web-platform/tests/fetch/stale-while-revalidate/stale-css.tentative.html
author Philip Jägenstedt <philip@foolip.org>
Tue, 05 Mar 2019 11:09:13 +0000
changeset 464498 83d693e14a497587112f99198db036e97a97031e
parent 464361 66b1aba3fb4372ec47986e728b1da9b32dd3d368
child 464559 1774d9a9e839869b7995207f543bb5f6a6fe8a1b
permissions -rw-r--r--
Bug 1527478 [wpt PR 15350] - Fetch: use `t.step_timeout()` instead of bare `step_timeout()`, a=testonly Automatic update from web-platform-tests Fetch: use `t.step_timeout()` instead of bare `step_timeout()` (#15350) This avoid a harness error in the case of failure: https://wpt.fyi/results/fetch/stale-while-revalidate?run_id=6045131320852480&run_id=4797529354928128&run_id=6524192509919232&run_id=6492651545165824 -- wpt-commits: 8686e3e2268c7746bdfe88e892cb986b0ba7b779 wpt-pr: 15350

<!DOCTYPE html>
<!---
Tentative test against:
https://github.com/whatwg/fetch/pull/853
-->
<meta charset="utf-8">
<title>Tests Stale While Revalidate works for css</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script>

async_test(t => {
  window.onload = t.step_func(() => {
    t.step_timeout(() => {
      assert_equals(window.getComputedStyle(document.body).getPropertyValue('background-color'), "rgb(0, 128, 0)");
      var link2 = document.createElement("link");
      link2.onload = t.step_func(() => {
        assert_equals(window.getComputedStyle(document.body).getPropertyValue('background-color'), "rgb(0, 128, 0)");
        var checkResult = () => {
          // We poll because we don't know when the revalidation will occur.
          fetch("stale-css.py?query").then(t.step_func((response) => {
            var count = response.headers.get("Count");
            if (count == '2') {
                t.done();
            } else {
              t.step_timeout(checkResult, 25);
            }
          }));
        };
        t.step_timeout(checkResult, 25);
      });
      link2.rel = "stylesheet";
      link2.type = "text/css";
      link2.href = "stale-css.py";
      document.body.appendChild(link2);
    }, 0);
  });
}, 'Cache returns stale resource');

var link = document.createElement("link");
link.rel = "stylesheet";
link.type = "text/css";
link.href = "stale-css.py";
document.body.appendChild(link);
</script>
</body>