summaryrefslogtreecommitdiffstats
path: root/dom/tests/mochitest/chrome/MozDomFullscreen_chrome.xul
blob: 7c36696b93fc83fbc0b10de1108b251342d359e1 (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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
<!--
  Test that "MozDOMFullscreen:*" events are dispatched to chrome on documents that use DOM fullscreen.

  Test Description:
  
  This chrome window has a browser. The browser's contentDocument (the "outer document")
  in turn has an iframe (the "inner document").
  
  We request fullscreen in the outer document, and check that MozDOMFullscreen:Entered and
  MozDOMFullscreen:NewOrigin are dispatched to chrome, targeted at the outer document.
  
  Then we request fullscreen in the inner document, and check that MozDOMFullscreen:NewOrigin
  is dispatched to chrome, targeted at the inner document.
  
  Then we cancel fullscreen in the inner document, and check that MozDOMFullscreen:NewOrigin is
  dispatched again to chrome, targeted at the outer document.
-->
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" onload="start();">

<script type="application/javascript" src="chrome://mochikit/content/chrome-harness.js"></script>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>      
<script type="application/javascript"><![CDATA[

function ok(condition, msg) {
  window.opener.wrappedJSObject.ok(condition, msg);
}

function is(a, b, msg) {
  window.opener.wrappedJSObject.is(a, b, msg);
}

var gBrowser = null;
var gOuterDoc = null;
var gInnerDoc = null;

var gReceivedFullscreenEnteredEvent = false;
var gReceivedNewOriginEvent = false;
function firstEntry(event) {
  if (event.type == "MozDOMFullscreen:Entered") {
    window.removeEventListener("MozDOMFullscreen:Entered", firstEntry, false);
    ok(!gReceivedFullscreenEnteredEvent, "MozDOMFullscreen:Entered shouldn't have been triggered twice");
    is(event.target, gOuterDoc.body, "First MozDOMFullscreen:Entered should be targeted at outer body");
    gReceivedFullscreenEnteredEvent = true;
  } else if (event.type == "MozDOMFullscreen:NewOrigin") {
    window.removeEventListener("MozDOMFullscreen:NewOrigin", firstEntry, false);
    ok(!gReceivedNewOriginEvent, "MozDOMFullscreen:NewOrigin shouldn't have been triggered twice");
    is(event.target, gOuterDoc, "First MozDOMFullscreen:NewOrigin should be targeted at outer doc");
    gReceivedNewOriginEvent = true;
  } else {
    ok(false, "Unknown event received");
  }
  if (!gReceivedFullscreenEnteredEvent || !gReceivedNewOriginEvent) {
    return;
  }

  ok(gOuterDoc.fullscreenElement != null, "Outer doc should be in fullscreen");
  gInnerDoc = gOuterDoc.getElementById("innerFrame").contentDocument;
  window.addEventListener("MozDOMFullscreen:NewOrigin", secondEntry, false);
  gInnerDoc.defaultView.focus();
  gInnerDoc.body.requestFullscreen();
}

function secondEntry(event) {
  is(event.target, gInnerDoc, "Second MozDOMFullscreen:NewOrigin should be targeted at inner doc");
  ok(gInnerDoc.fullscreenElement != null, "Inner doc should be in fullscreen");
  window.removeEventListener("MozDOMFullscreen:NewOrigin", secondEntry, false);
  window.addEventListener("MozDOMFullscreen:NewOrigin", thirdEntry, false);
  gInnerDoc.exitFullscreen();
}

function thirdEntry(event) {
  is(event.target, gOuterDoc, "Third MozDOMFullscreen:NewOrigin should be targeted at outer doc");
  ok(gOuterDoc.fullscreenElement != null, "Outer doc return to fullscreen after cancel fullscreen in inner doc");
  window.removeEventListener("MozDOMFullscreen:NewOrigin", thirdEntry, false);
  window.removeEventListener("MozDOMFullscreen:Exited", earlyExit, false);
  window.addEventListener("MozDOMFullscreen:Exited", lastExit, false);
  gOuterDoc.exitFullscreen();
}

function earlyExit(event) {
  ok(false, "MozDOMFullscreen:Exited should only be triggered after cancel all fullscreen");
}

function lastExit(event) {
  is(event.target, gOuterDoc, "MozDOMFullscreen:Exited should be targeted at the last exited doc");
  ok(gOuterDoc.fullscreenElement == null, "Fullscreen should have been fully exited");
  window.opener.wrappedJSObject.done();
}

function start() {
  SimpleTest.waitForFocus(
    function() {
      gBrowser = document.getElementById("browser");
      gOuterDoc = gBrowser.contentDocument;
      gBrowser.contentWindow.focus();
      window.addEventListener("MozDOMFullscreen:Entered", firstEntry, false);
      window.addEventListener("MozDOMFullscreen:NewOrigin", firstEntry, false);
      gOuterDoc.body.requestFullscreen();
    });
}

]]>
</script>
<browser type="content" id="browser" width="400" height="400" src="file_MozDomFullscreen.html"/>

</window>