summaryrefslogtreecommitdiffstats
path: root/layout/base/tests/file_zoom_restore_bfcache.html
blob: 77451f3ef6dbf9bb65058593ed44e7520a4584ea (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<!doctype html>
<script>
  var bcName = "zoomRestoreBfcache" + window.location.search;
  var bc = new BroadcastChannel(bcName);
  if (window.location.search == "?2") {
    bc.onmessage = (msgEvent) => {
      var msg = msgEvent.data;
      var command = msg.command;
      dump(`Subpage ?2 received command=${command}\n`);
      switch (command) {
        case "case2sendData": {
          bc.postMessage({command: "case2data", devicePixelRatio: window.devicePixelRatio,
            frameDevicePixelRatio: document.querySelector("iframe").contentWindow.devicePixelRatio});
          break;
        }
        case "case2action": {
          SpecialPowers.spawnChrome([], () => {
            const FullZoom = this.browsingContext.embedderElement.ownerGlobal.FullZoom;
            FullZoom.setZoom(2.0);
          });
          SpecialPowers.setFullZoom(window, 2);
          window.requestAnimationFrame(() => window.requestAnimationFrame(() => {
            bc.postMessage({command: "case2dataAnimationFrame", devicePixelRatio: window.devicePixelRatio,
            frameDevicePixelRatio: document.querySelector("iframe").contentWindow.devicePixelRatio });
          }));
          break;
        }
        case "case2back": {
          bc.close();
          window.history.back();
          break;
        }
      }
    }
  } else {
    bc.onmessage = (msgEvent) => {
      var msg = msgEvent.data;
      var command = msg.command;
      dump(`Subpage received command=${command}\n`);
      switch (command) {
        case "case1sendData": {
          bc.postMessage({command: "case1data", devicePixelRatio: window.devicePixelRatio});
          break;
        }
        case "case1click": {
          document.querySelector("a").click();
          // We are opening file_zoom_restore_bfcache.html?2, so the current
          // page is going into bfcache
          break;
        }
        case "case3sendData": {
          // We came back from bfcache
          SpecialPowers.spawnChrome([], () => {
            // We use FullZoom to set the zoom level in the parent, but if FullZoom is not
            // available then that will fail. So we don't wait here for the devicePixelRatio
            // to change if FullZoom is not available, and test_zoom_restore_bfcache.html
            // will mark this test as todo.
            return "FullZoom" in this.browsingContext.embedderElement.ownerGlobal;
          }).then((hasFullZoom) => {
            function waitUntilZoomLevelRestored() {
              // Zoom level is updated asynchronously when bfcache lives in the
              // parent process.
              if (!hasFullZoom || window.devicePixelRatio == 2) {
                bc.postMessage({command: "case3data", devicePixelRatio: window.devicePixelRatio,
                frameDevicePixelRatio: document.querySelector("iframe").contentWindow.devicePixelRatio});
                return;
              }
              window.requestAnimationFrame(waitUntilZoomLevelRestored);
            }
            window.requestAnimationFrame(waitUntilZoomLevelRestored);
          });
          break;
        }
        case "close": {
          SpecialPowers.spawnChrome([], () => {
            const FullZoom = this.browsingContext.embedderElement.ownerGlobal.FullZoom;
            FullZoom.setZoom(1.0);
          });
          bc.postMessage({command: "closed"});
          bc.close();
          window.close();
          break;
        }
      }
    }
  }
  window.addEventListener("pageshow", function(e) {
    bc.postMessage({command: "handlePageShow", eventPersisted: e.persisted});
  });
</script>
<a href="?2">This is a very interesting page</a>
<iframe srcdoc="And this is a nested frame"></iframe>