summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-backgrounds/background-image-shared-stylesheet.html
blob: c0c0661291b8a4ae1c4b33a7d231f9511d878b9f (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
<!doctype html>
<html class="reftest-wait">
<meta charset="utf-8">
<title>CSS Test: Canceled load in another page doesn't affect new stylesheet</title>
<link rel="author" title="Emilio Cobos Álvarez" href="mailto:emilio@crisal.io">
<link rel="author" title="Mozilla" href="https://mozilla.org">
<link rel="help" href="https://drafts.csswg.org/css-backgrounds/#background-image">
<link rel="help" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1800979">
<link rel="match" href="background-image-shared-stylesheet-ref.html">
<iframe></iframe>
<script>
const IMAGE_URI = new URL("/images/green.png", location.href).href + "?pipe=trickle(d2)&" + Math.random();
const SHEET_URI = "data:text/css," + encodeURI(`:root{background-image: url('${IMAGE_URI}');}`);
const iframe = document.querySelector("iframe");

function willNavigate() {
  // The child page has already loaded the stylesheet (guaranteed by the <script> rules)
  // and is about to navigate away. Trigger our stylesheet load and thus image
  // load when it does. The background-image should still apply to us.
  iframe.addEventListener("load", function() {
    let link = document.createElement("link");
    link.rel = "stylesheet";
    link.href = SHEET_URI;
    link.onload = function() {
      iframe.remove();
      // We need to also make sure that the image has actually finished to load,
      // so that the reftest screenshot can be taken.
      const image = new Image();
      image.onload = function() {
        document.documentElement.className = "";
      };
      image.src = IMAGE_URI;
    };
    document.head.appendChild(link);
  }, { once: true });
}

onload = function() {
  document.querySelector("iframe").srcdoc = `
    <!doctype html>
    <link rel="stylesheet" href="${SHEET_URI}">
    <script>
      document.documentElement.getBoundingClientRect(); // Should trigger the image load.
      parent.willNavigate();
      window.location = "/css/reference/blank.html";
    </` + `script>
  `;
};
</script>