diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /dom/tests/mochitest/chrome | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/tests/mochitest/chrome')
65 files changed, 5846 insertions, 0 deletions
diff --git a/dom/tests/mochitest/chrome/489127.html b/dom/tests/mochitest/chrome/489127.html new file mode 100644 index 000000000..5e20345cf --- /dev/null +++ b/dom/tests/mochitest/chrome/489127.html @@ -0,0 +1,200 @@ +<!DOCTYPE HTML>
+<html>
+<head>
+ <title>nsIDOMWindowUtils::nodesFromRect test - bug 489127</title>
+ <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
+<script type="application/javascript;version=1.8">
+
+ var SimpleTest = window.opener.SimpleTest;
+ function ok() { window.opener.ok.apply(window.opener, arguments); }
+ function done() { window.opener.done.apply(window.opener, arguments); }
+ let e = {};
+
+ let dwu = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
+ .getInterface(Components.interfaces.nsIDOMWindowUtils);
+
+ /*
+ nsIDOMNodeList nodesFromRect(in float aX,
+ in float aY,
+ in float aTopSize,
+ in float aRightSize,
+ in float aBottomSize,
+ in float aLeftSize,
+ in boolean aIgnoreRootScrollFrame,
+ in boolean aFlushLayout);
+
+ */
+
+ function check(x, y, top, right, bottom, left, list) {
+ let nodes = dwu.nodesFromRect(x, y, top, right, bottom, left, true, false);
+
+ list.push(e.body);
+ list.push(e.html);
+
+ if (nodes.length != list.length) {
+ ok(false, "Different number of nodes for rect" +
+ "[" + x + "," + y + "], " +
+ "[" + top + "," + right + "," + bottom + "," + left + "]");
+ return;
+ }
+
+ for (var i = 0; i < nodes.length; i++) {
+ if (nodes[i] != list[i]) {
+ ok(false, "Unexpected node #" + i + " for rect " +
+ "[" + x + "," + y + "], " +
+ "[" + top + "," + right + "," + bottom + "," + left + "]");
+ return;
+ }
+ }
+ ok(true, "All correct nodes found for rect " +
+ "[" + x + "," + y + "], " +
+ "[" + top + "," + right + "," + bottom + "," + left + "]");
+ }
+
+ function doTest() {
+
+ // Set up shortcut access to elements
+ e['html'] = document.getElementsByTagName("html")[0];
+ ['h1', 'd1', 'd2', 'p1', 'p2', 'p3', 'p4', 'p5', 'p6', 'span',
+ 'a1', 'a2', 'a3', 'transf', 'iframe1', 'body'].forEach(function(a) {
+ e[a] = document.getElementById(a);
+ });
+
+ window.scrollTo(0, 0);
+
+ // Top, Right, Bottom, Left directions:
+ check(53, 71, 0, 0, 0, 0, []);
+ check(53, 71, 10, 0, 0, 0, [e.h1]);
+ check(53, 71, 0, 10, 0, 0, [e.p3]);
+ check(53, 71, 0, 0, 10, 0, [e.d1]);
+ check(152, 105, 0, 0, 0, 10, [e.d1]);
+ check(152, 105, 10, 10, 10, 10, [e.p4, e.p3, e.d1]);
+
+ // e.p1 is invisible and shouldn't appear:
+ check(153,193,0,0,0,0,[e.p5]);
+ check(153,193,0,20,0,20, [e.p5, e.d2]);
+
+ // Precise pixel checks:
+ check(144, 183, 0, 0, 0, 0, []);
+ check(144, 183, 0, 0, 1, 0, [e.p5]);
+ check(144, 183, 0, 0, 0, 1, [e.d2]);
+ check(144, 183, 0, 0, 1, 1, [e.p5, e.d2]);
+ check(77, 240, 0, 0, 0, 0, [e.p2]);
+ check(77, 240, 1, 0, 0, 0, [e.p5, e.p2]);
+ check(77, 240, 0, 0, 1, 0, [e.span, e.p2]);
+ check(77, 240, 1, 0, 1, 0, [e.p5, e.span, e.p2]);
+
+ // Expanding area checks:
+ check(39, 212, 0, 0, 0, 0, []);
+ check(39, 212, 10, 0, 0, 0, [e.d2]);
+ check(39, 212, 0, 0, 10, 0, [e.p2]);
+ check(39, 212, 10, 1, 30, 0, [e.d2, e.p2]);
+ check(39, 212, 10, 5, 30, 0, [e.span, e.d2, e.p2]);
+ check(39, 212, 10, 15, 30, 0, [e.p5, e.span, e.d2, e.p2]);
+
+ // Elements inside iframe shouldn't be returned:
+ check(15, 410, 0, 30, 50, 0, [e.iframe1]);
+
+ // Area with links and text nodes:
+ let [x1, y1] = getCenterFor(e.a1);
+ let [x2, y2] = getCenterFor(e.a2);
+ let [x3, y3] = getCenterFor(e.a3);
+ let [xt, yt] = [(x2 + x1) / 2, y1]; //text node between a1 and a2
+
+ check(x1, y1, 0, 0, 0, 0, [e.a1.firstChild, e.a1, e.p6]);
+ check(x1, y1, 0, 0, y3 - y1, 0, [e.a3.firstChild, e.a3, e.a1.firstChild, e.a1, e.p6]);
+ check(x1, y1, 0, xt - x1, 0, 0, [e.p6.childNodes[1], e.a1.firstChild, e.a1, e.p6]);
+ check(x1, y1, 0, x2 - x1, 0, 0, [e.a2.firstChild, e.a2, e.p6.childNodes[1], e.a1.firstChild, e.a1, e.p6]);
+ check(x1, y1, 0, x2 - x1, y3 - y1, 0, [e.a3.firstChild, e.a3, e.a2.firstChild, e.a2, e.p6.childNodes[1], e.a1.firstChild, e.a1, e.p6]);
+
+ // 2d transform:
+ check(61, 671, 0, 0, 0, 0, []);
+ check(61, 671, 0, 30, 0, 10, [e.transf]);
+ check(61, 671, 0, 30, 90, 10, [e.transf.firstChild, e.transf]);
+
+ done();
+
+ }
+
+ function getCenterFor(element) {
+ let rect = element.getBoundingClientRect();
+ return [(rect.left + rect.right) / 2, (rect.top + rect.bottom) / 2];
+ }
+
+ addLoadEvent(doTest);
+</script>
+<style type="text/css">
+
+body {
+ margin: 8px;
+ padding: 0;
+}
+
+h1, div, p, span, iframe {
+ display: block;
+ width: 100px;
+ height: 30px;
+ border: 3px solid black;
+ padding: 10px;
+ margin: 10px;
+}
+
+
+span {
+ display: inline-block;
+}
+
+#iframe1 {
+ height: 100px;
+ margin-top: 60px;
+}
+
+#p6 {
+ height: 50px;
+ margin-top: 30px;
+}
+
+#transf {
+ margin-top: 60px;
+ -moz-transform: rotate(-45deg);
+}
+
+#decimal {
+ position: relative;
+ left: 0.5px;
+ top: 50.5px;
+}
+</style>
+</head>
+<body id="body">
+ <h1 id="h1"></h1>
+ <div id="d1"></div>
+
+ <!-- floated element -->
+ <div id="d2" style="float: left"></div>
+
+ <!-- hidden element -->
+ <p id="p1" style="float: left; visibility: hidden"></p>
+
+ <p id="p2" style="clear: left"><span id="span"></span></p>
+
+ <!-- absolute position -->
+ <p id="p3" style="position:absolute; top: 10px; left:50px; height:50px;"></p>
+
+ <!-- fixed position -->
+ <p id="p4" style="position: fixed; top: 30px; left: 150px; height: 50px; background-color: blue;"></p>
+
+ <!-- relative position -->
+ <p id="p5" style="position:relative; top: -100px; left: 30px; margin-bottom: -70px; background-color: green"></p>
+
+ <!-- decimal CSS pixels -->
+ <div id="decimal"></div>
+
+ <iframe id="iframe1" src="data:text/html,<div>div</div><p>p</p>"></iframe>
+
+ <p id="p6"><a href="#" id="a1">A</a> / <a href="#" id="a2">A</a><br/><a href="#" id="a3">A</a></p>
+
+ <div id="transf">text</div>
+</body>
+</html>
diff --git a/dom/tests/mochitest/chrome/DOMWindowCreated_chrome.xul b/dom/tests/mochitest/chrome/DOMWindowCreated_chrome.xul new file mode 100644 index 000000000..3faaf8fd5 --- /dev/null +++ b/dom/tests/mochitest/chrome/DOMWindowCreated_chrome.xul @@ -0,0 +1,33 @@ +<?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 for Persistent Storage in chrome
+ -->
+<window id="sample-window" width="400" height="400"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+ <script type="application/javascript"
+ src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="application/javascript"
+ src="chrome://mochikit/content/chrome-harness.js"></script>
+
+<script type="application/javascript">
+var SimpleTest = window.opener.wrappedJSObject.SimpleTest;
+
+document.addEventListener("DOMWindowCreated", function(e) {
+ var otherWindow = e.target.defaultView.wrappedJSObject;
+ SimpleTest.is(e.type, "DOMWindowCreated", "DOMWindowCreated: " + otherWindow);
+ otherWindow.doneFunction = function() {
+ SimpleTest.ok(true, "doneFunction was called");
+ SimpleTest.finish();
+ window.close();
+ };
+}, false);
+
+var root = getRootDirectory(window.location.href);
+var el = document.createElement("iframe");
+el.setAttribute('type', 'content');
+el.setAttribute('src', root + 'DOMWindowCreated_content.html');
+document.documentElement.appendChild(el);
+</script>
+</window>
diff --git a/dom/tests/mochitest/chrome/DOMWindowCreated_content.html b/dom/tests/mochitest/chrome/DOMWindowCreated_content.html new file mode 100644 index 000000000..acb6b0582 --- /dev/null +++ b/dom/tests/mochitest/chrome/DOMWindowCreated_content.html @@ -0,0 +1,9 @@ +<!DOCTYPE html>
+<head>
+ <title>DOMWindowCreated helper</title>
+
+ <script type="application/javascript">
+ window.doneFunction();
+ </script>
+<body>
+ <h1>DOMWindowCreated Helper</h1>
diff --git a/dom/tests/mochitest/chrome/MozDomFullscreen_chrome.xul b/dom/tests/mochitest/chrome/MozDomFullscreen_chrome.xul new file mode 100644 index 000000000..7c36696b9 --- /dev/null +++ b/dom/tests/mochitest/chrome/MozDomFullscreen_chrome.xul @@ -0,0 +1,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> diff --git a/dom/tests/mochitest/chrome/child_focus_frame.html b/dom/tests/mochitest/chrome/child_focus_frame.html new file mode 100644 index 000000000..d7f0ff63c --- /dev/null +++ b/dom/tests/mochitest/chrome/child_focus_frame.html @@ -0,0 +1,57 @@ +<html id="t13"> +<body id="inner-document"> + +<input id="t19" value="Input" accesskey="b"> +<input id="t14" tabindex="2" type="password" value="test"> +<button id="t20">Button</button> +<div style="float: left; margin-top: 30px;"> + <button id="t21">Button 2</button> +</div> +<div id="abs" style="position: absolute; top: 40px; left: 250px;"> + <button id="t22" accesskey="c">Button 3</button> + <p><span> + <select id="t15" tabindex="2" accesskey="e"> + <option>One + </select> + </span></p> +</div> +<div id="t16" tabindex="2" style="overflow: scroll; max-height: 20px;"> + This is a scrollable area with some sufficiently long text contained within it. +</div> +<img id="n5" src="happy.png"/> +<img id="t23" tabindex="0" src="happy.png"/> +<a id="t17" tabindex="2" accesskey="f">1</a> +<a id="t24" tabindex="0" href="#">2</a> +<a id="t25" href="#">Link 3</a> +<br> +<span id="hiddenspan" style="display: none;"></span> +<input id="t26" tabindex="0" type="checkbox" accesskey="a"> +<input id="o11" tabindex="-1" type="checkbox"> +<div style="display: none;"><input/></div> +<div id="t27" style="overflow: scroll; max-height: 20px;"> + This is a scrollable area with some sufficiently long text contained within it. + This is a scrollable area with some sufficiently long text contained within it. + <button id="inscroll" tabindex="-1">Button 4</button> +</div> +<map name="map1"> + <area id="t31" href="#" shape="rect" coords="0,0,5,5"> + <area id="t32" href="#" shape="rect" coords="10,10,15,15"> + <area id="t18" href="#" shape="circle" coords="0,8,4" tabindex="2">Button 5</area> + <area id="t33" href="#" shape="poly" coords="10,1,16,3,14,10,7,10,10,1"> +</map> +<input type="hidden"/> +<fieldset style="float: right;"> +<legend id="legend">Options</legend> + <input id="t28" type="radio" name="options" value="optionone">One + <label id="ad" accesskey="d">Label:<input id="t29" type="radio" name="options" value="optiontwo">Two</label> +</fieldset> +<div id="t30" tabindex="0">abc</div> +<input id="o18" accesskey="u" disabled size="3"/> +<label id="ag" accesskey="g" for="n6">L</label> +<input id="n6" tabindex="-1" type="button"/> +<span id="n7" accesskey="t">s</span> +<img id="image" src="data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%18%00%00%00%18%02%03%00%00%00%9D%19%D5k%00%00%00%04gAMA%00%00%B1%8F%0B%FCa%05%00%00%00%0CPLTE%FF%FF%FF%FF%FF%FF%F7%DC%13%00%00%00%03%80%01X%00%00%00%01tRNS%08N%3DPT%00%00%00%01bKGD%00%88%05%1DH%00%00%00%09pHYs%00%00%0B%11%00%00%0B%11%01%7Fd_%91%00%00%00%07tIME%07%D2%05%0C%14%0C%0D%D8%3F%1FQ%00%00%00%5CIDATx%9C%7D%8E%CB%09%C0%20%10D%07r%B7%20%2F%E9wV0%15h%EA%D9%12D4%BB%C1x%CC%5C%1E%0C%CC%07%C0%9C0%9Dd7()%C0A%D3%8D%E0%B8%10%1DiCHM%D0%AC%D2d%C3M%F1%B4%E7%FF%10%0BY%AC%25%93%CD%CBF%B5%B2%C0%3Alh%CD%AE%13%DF%A5%F7%E0%03byW%09A%B4%F3%E2%00%00%00%00IEND%AEB%60%82" + usemap="#map1" ismap> + +</body> +</html> diff --git a/dom/tests/mochitest/chrome/chrome.ini b/dom/tests/mochitest/chrome/chrome.ini new file mode 100644 index 000000000..3060bc01e --- /dev/null +++ b/dom/tests/mochitest/chrome/chrome.ini @@ -0,0 +1,90 @@ +[DEFAULT] +skip-if = os == 'android' +support-files = + 489127.html + DOMWindowCreated_chrome.xul + DOMWindowCreated_content.html + MozDomFullscreen_chrome.xul + child_focus_frame.html + file_DOM_element_instanceof.xul + file_MozDomFullscreen.html + file_bug799299.xul + file_bug800817.xul + file_bug830858.xul + file_bug1224790-1_modal.xul + file_bug1224790-1_nonmodal.xul + file_bug1224790-2_modal.xul + file_bug1224790-2_nonmodal.xul + file_subscript_bindings.js + focus_frameset.html + focus_window2.xul + fullscreen.xul + queryCaretRectUnix.html + queryCaretRectWin.html + selectAtPoint.html + sizemode_attribute.xul + window_activation.xul + window_callback_wrapping.xul + window_docshell_swap.xul + window_focus.xul + window_focus_docnav.xul + !/dom/tests/mochitest/general/file_clonewrapper.html + !/dom/tests/mochitest/general/file_moving_nodeList.html + !/dom/tests/mochitest/general/file_moving_xhr.html + !/dom/tests/mochitest/geolocation/network_geolocation.sjs + +[test_DOMWindowCreated.xul] +[test_DOM_element_instanceof.xul] +[test_activation.xul] +tags = fullscreen +[test_bug799299.xul] +[test_bug800817.xul] +[test_bug830396.xul] +[test_bug830858.xul] +[test_bug1224790-1.xul] +tags = openwindow +# synthesizeNativeOSXClick does not work on 10.6 +skip-if = os != 'mac' || os_version == '10.6' +[test_bug1224790-2.xul] +tags = openwindow +# synthesizeNativeOSXClick does not work on 10.6 +skip-if = os != 'mac' || os_version == '10.6' +[test_callback_wrapping.xul] +[test_clonewrapper.xul] +[test_cyclecollector.xul] +[test_docshell_swap.xul] +[test_focus.xul] +skip-if = os == 'linux' && !debug # bug 1296622 +[test_focus_docnav.xul] +[test_focus_switchbinding.xul] +[test_focused_link_scroll.xul] +[test_fullscreen.xul] +tags = fullscreen +# disabled on linux for timeouts--bug-867745 +skip-if = os == 'linux' +[test_geolocation.xul] +[test_indexedSetter.html] +[test_moving_nodeList.xul] +[test_moving_xhr.xul] +[test_MozDomFullscreen_event.xul] +tags = fullscreen +# disabled on OS X for intermittent failures--bug-798848 +skip-if = toolkit == 'cocoa' +[test_nodesFromRect.html] +[test_parsingMode.html] +[test_popup_blocker_chrome.xul] +[test_queryCaretRect.html] +[test_resize_move_windows.xul] +# disabled on linux for timeouts--bug-834716 +skip-if = os == 'linux' +[test_sandbox_bindings.xul] +[test_sandbox_eventhandler.xul] +[test_sandbox_image.xul] +[test_sandbox_postMessage.html] +[test_selectAtPoint.html] +[test_sizemode_attribute.xul] +tags = fullscreen +skip-if = os != 'win' +[test_subscript_bindings.xul] +[test_xray_event_constructor.xul] +[test_clipboard_events_chrome.html] diff --git a/dom/tests/mochitest/chrome/file_DOM_element_instanceof.xul b/dom/tests/mochitest/chrome/file_DOM_element_instanceof.xul new file mode 100644 index 000000000..e4cfd8d30 --- /dev/null +++ b/dom/tests/mochitest/chrome/file_DOM_element_instanceof.xul @@ -0,0 +1,30 @@ +<?xml version="1.0"?> +<?xml-stylesheet type="text/css" href="chrome://global/skin"?> +<window title="Mozilla Bug 824917" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + + <iframe type="content"></iframe> + + <script type="application/javascript"> + <![CDATA[ + /** Test for Bug 799299 **/ + var SimpleTest = opener.wrappedJSObject.SimpleTest; + var ok = opener.wrappedJSObject.ok; + + var doc = frames[0].document; + ok(doc.createElement("body") instanceof HTMLBodyElement, + "Should be instance of HTMLBodyElement"); + ok(doc.createElement("div") instanceof HTMLDivElement, + "Should be instance of HTMLDivElement"); + ok(doc.createElement("frameset") instanceof HTMLFrameSetElement, + "Should be instance of HTMLFrameSetElement"); + ok(doc.createElement("h1") instanceof HTMLHeadingElement, + "Should be instance of HTMLHeadingElement"); + ok(doc.createElement("label") instanceof HTMLLabelElement, + "Should be instance of HTMLLabelElement"); + + window.close(); + opener.wrappedJSObject.SimpleTest.finish(); + ]]> + </script> +</window> diff --git a/dom/tests/mochitest/chrome/file_MozDomFullscreen.html b/dom/tests/mochitest/chrome/file_MozDomFullscreen.html new file mode 100644 index 000000000..f95489270 --- /dev/null +++ b/dom/tests/mochitest/chrome/file_MozDomFullscreen.html @@ -0,0 +1,8 @@ +<html> +<head> +</head> +<body style="background-color: blue;"> +<p>Outer doc</p> +<iframe id="innerFrame" src="http://mochi.test:8888/"></iframe> +</body> +</html> diff --git a/dom/tests/mochitest/chrome/file_bug1224790-1_modal.xul b/dom/tests/mochitest/chrome/file_bug1224790-1_modal.xul new file mode 100644 index 000000000..7a2ad495f --- /dev/null +++ b/dom/tests/mochitest/chrome/file_bug1224790-1_modal.xul @@ -0,0 +1,33 @@ +<?xml version="1.0"?> +<?xml-stylesheet type="text/css" href="chrome://global/skin"?> +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=1224790 +--> +<dialog title="Mozilla Bug 1224790" + buttons="accept" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> + + <!-- test results are displayed in the html:body --> + <body xmlns="http://www.w3.org/1999/xhtml"> + </body> + + <!-- test code goes here --> + <script type="application/javascript"> + <![CDATA[ + /** Test for Bug 1224790 **/ + + function runTests() { + window.openDialog('file_bug1224790-1_nonmodal.xul', '', 'dialog=no'); + } + + function nonModalClosed() { + window.close(); + opener.wrappedJSObject.modalClosed(); + } + + SimpleTest.waitForFocus(runTests); + ]]> + </script> +</dialog> diff --git a/dom/tests/mochitest/chrome/file_bug1224790-1_nonmodal.xul b/dom/tests/mochitest/chrome/file_bug1224790-1_nonmodal.xul new file mode 100644 index 000000000..e09efc9c0 --- /dev/null +++ b/dom/tests/mochitest/chrome/file_bug1224790-1_nonmodal.xul @@ -0,0 +1,28 @@ +<?xml version="1.0"?> +<?xml-stylesheet type="text/css" href="chrome://global/skin"?> +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=1224790 +--> +<window title="Mozilla Bug 1224790" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> + + <!-- test results are displayed in the html:body --> + <body xmlns="http://www.w3.org/1999/xhtml"> + </body> + + <!-- test code goes here --> + <script type="application/javascript"> + <![CDATA[ + /** Test for Bug 1224790 **/ + + function runTests() { + window.close(); + opener.wrappedJSObject.nonModalClosed(); + } + + SimpleTest.waitForFocus(runTests); + ]]> + </script> +</window> diff --git a/dom/tests/mochitest/chrome/file_bug1224790-2_modal.xul b/dom/tests/mochitest/chrome/file_bug1224790-2_modal.xul new file mode 100644 index 000000000..34f49e3c4 --- /dev/null +++ b/dom/tests/mochitest/chrome/file_bug1224790-2_modal.xul @@ -0,0 +1,35 @@ +<?xml version="1.0"?> +<?xml-stylesheet type="text/css" href="chrome://global/skin"?> +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=1224790 +--> +<dialog title="Mozilla Bug 1224790" + buttons="accept" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> + + <!-- test results are displayed in the html:body --> + <body xmlns="http://www.w3.org/1999/xhtml"> + </body> + + <!-- test code goes here --> + <script type="application/javascript"> + <![CDATA[ + /** Test for Bug 1224790 **/ + + var nonModal = null; + + function runTests() { + nonModal = window.openDialog('file_bug1224790-2_nonmodal.xul', '', 'dialog=no'); + } + + function nonModalOpened() { + window.close(); + nonModal.wrappedJSObject.modalClosed(opener); + } + + SimpleTest.waitForFocus(runTests); + ]]> + </script> +</dialog> diff --git a/dom/tests/mochitest/chrome/file_bug1224790-2_nonmodal.xul b/dom/tests/mochitest/chrome/file_bug1224790-2_nonmodal.xul new file mode 100644 index 000000000..0116dfeb2 --- /dev/null +++ b/dom/tests/mochitest/chrome/file_bug1224790-2_nonmodal.xul @@ -0,0 +1,46 @@ +<?xml version="1.0"?> +<?xml-stylesheet type="text/css" href="chrome://global/skin"?> +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=1224790 +--> +<window title="Mozilla Bug 1224790" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> + + <!-- test results are displayed in the html:body --> + <body xmlns="http://www.w3.org/1999/xhtml"> + </body> + + <!-- test code goes here --> + <script type="application/javascript"> + <![CDATA[ + /** Test for Bug 1224790 **/ + + function runTests() { + opener.wrappedJSObject.nonModalOpened() + } + + function modalClosed(grandparent) { + // Request cycle collection to trigger destructor for parent modal window, + // that mutates mAncestorLink of this window. + const Ci = Components.interfaces; + const Cu = Components.utils; + var { Services } = Cu.import("resource://gre/modules/Services.jsm", {}); + var windowUtils = window.QueryInterface(Ci.nsIInterfaceRequestor). + getInterface(Ci.nsIDOMWindowUtils); + + Services.obs.notifyObservers(null, "child-cc-request", null); + windowUtils.cycleCollect(); + + // Wait for a while. + setTimeout(function() { + window.close(); + grandparent.wrappedJSObject.nonModalClosed(); + }, 3000); + } + + SimpleTest.waitForFocus(runTests); + ]]> + </script> +</window> diff --git a/dom/tests/mochitest/chrome/file_bug799299.xul b/dom/tests/mochitest/chrome/file_bug799299.xul new file mode 100644 index 000000000..2bbb0a23a --- /dev/null +++ b/dom/tests/mochitest/chrome/file_bug799299.xul @@ -0,0 +1,66 @@ +<?xml version="1.0"?> +<?xml-stylesheet type="text/css" href="chrome://global/skin"?> +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=799299 +--> +<window title="Mozilla Bug 799299" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/> + + <!-- test results are displayed in the html:body --> + <body xmlns="http://www.w3.org/1999/xhtml"> + <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=799299" + target="_blank">Mozilla Bug 799299</a> + </body> + + <!-- test code goes here --> + <script type="application/javascript"> + <![CDATA[ + /** Test for Bug 799299 **/ + + function sendClick(win) { + var wu = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor) + .getInterface(Components.interfaces.nsIDOMWindowUtils); + wu.sendMouseEventToWindow("mousedown", 10, 10, 0, 0, 0); + wu.sendMouseEventToWindow("mouseup", 10, 10, 0, 0, 0); + } + + function runTests() { + var b1 = document.getElementById("b1"); + var b2 = document.getElementById("b2"); + b1.contentWindow.focus(); + opener.wrappedJSObject.is(document.activeElement, b1, + "Focused first iframe"); + + var didCallDummy = false; + b2.contentWindow.addEventListener("mousedown", function(e) { didCallDummy = true; }); + sendClick(b2.contentWindow); + opener.wrappedJSObject.ok(didCallDummy, "dummy mousedown handler should fire"); + opener.wrappedJSObject.is(document.activeElement, b2, + "Focus shifted to second iframe"); + + b1.contentWindow.focus(); + opener.wrappedJSObject.is(document.activeElement, b1, + "Re-focused first iframe for the first time"); + + var didCallListener = false; + b2.contentWindow.addEventListener("mousedown", function(e) { didCallListener = true; e.preventDefault(); }); + sendClick(b2.contentWindow); + opener.wrappedJSObject.ok(didCallListener, "mousedown handler should fire"); + opener.wrappedJSObject.is(document.activeElement, b2, + "focus should move to the second iframe"); + + window.close(); + opener.wrappedJSObject.SimpleTest.finish(); + } + + SimpleTest.waitForFocus(runTests); + ]]> + </script> + <hbox flex="1"> + <browser id="b1" type="content" src="about:blank" flex="1" style="border: 1px solid black;"/> + <browser id="b2" type="content" src="about:blank" flex="1" style="border: 1px solid black;"/> + </hbox> +</window> diff --git a/dom/tests/mochitest/chrome/file_bug800817.xul b/dom/tests/mochitest/chrome/file_bug800817.xul new file mode 100644 index 000000000..87f900074 --- /dev/null +++ b/dom/tests/mochitest/chrome/file_bug800817.xul @@ -0,0 +1,80 @@ +<?xml version="1.0"?> +<?xml-stylesheet type="text/css" href="chrome://global/skin"?> +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=800817 +--> +<window title="Mozilla Bug 800817" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/> + + <!-- test results are displayed in the html:body --> + <body xmlns="http://www.w3.org/1999/xhtml"> + <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=800817" + target="_blank">Mozilla Bug 800817</a> + </body> + + <!-- test code goes here --> + <script type="application/javascript"> + <![CDATA[ + /** Test for Bug 800817 **/ + + function sendClick(win) { + var wu = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor) + .getInterface(Components.interfaces.nsIDOMWindowUtils); + wu.sendMouseEventToWindow("mousedown", 10, 10, 0, 0, 0); + wu.sendMouseEventToWindow("mouseup", 10, 10, 0, 0, 0); + } + + function runTests() { + var b1 = document.getElementById("b1"); + var b2 = document.getElementById("b2"); + + var testMozBrowser = opener.wrappedJSObject.testMozBrowser; + if (testMozBrowser) { + b1.setAttribute("mozbrowser", "true"); + b2.setAttribute("mozbrowser", "true"); + } + + if (testMozBrowser) + opener.wrappedJSObject.info("Testing with mozbrowser=true"); + else + opener.wrappedJSObject.info("Testing without mozbrowser"); + + b1.contentWindow.focus(); + opener.wrappedJSObject.is(document.activeElement, b1, + "Focused first iframe"); + + var didCallDummy = false; + b2.contentWindow.addEventListener("mousedown", function(e) { didCallDummy = true; }); + sendClick(b2.contentWindow); + opener.wrappedJSObject.ok(didCallDummy, "dummy mousedown handler should fire"); + opener.wrappedJSObject.is(document.activeElement, b2, + "Focus shifted to second iframe"); + + b1.contentWindow.focus(); + opener.wrappedJSObject.is(document.activeElement, b1, + "Re-focused first iframe for the first time"); + + var didCallListener = false; + b2.contentWindow.addEventListener("mousedown", function(e) { didCallListener = true; e.preventDefault(); }); + sendClick(b2.contentWindow); + opener.wrappedJSObject.ok(didCallListener, "mousedown handler should fire"); + opener.wrappedJSObject.is(document.activeElement, b1, + "Did not move focus to the second iframe"); + + window.close(); + opener.wrappedJSObject.finishedTests(); + } + + SimpleTest.waitForFocus(runTests); + ]]> + </script> + <iframe xmlns="http://www.w3.org/1999/xhtml" + id="b1" type="content" src="about:blank" + style="width: 300px; height: 550px; border: 1px solid black;"/> + <iframe xmlns="http://www.w3.org/1999/xhtml" + id="b2" type="content" src="about:blank" + style="width: 300px; height: 550px; border: 1px solid black;"/> +</window> diff --git a/dom/tests/mochitest/chrome/file_bug830858.xul b/dom/tests/mochitest/chrome/file_bug830858.xul new file mode 100644 index 000000000..ba2a7c1b8 --- /dev/null +++ b/dom/tests/mochitest/chrome/file_bug830858.xul @@ -0,0 +1,67 @@ +<?xml version="1.0"?> +<?xml-stylesheet type="text/css" href="chrome://global/skin"?> +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=830858 +--> +<window title="Mozilla Bug 830858" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/> + + <!-- test results are displayed in the html:body --> + <body xmlns="http://www.w3.org/1999/xhtml"> + <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=830858" + target="_blank">Mozilla Bug 830858</a> + </body> + + <!-- test code goes here --> + <script type="application/javascript"> + <![CDATA[ + /** Test for Bug 830858 **/ + + function runTests() { + var b = document.getElementById("b"); + var win = b.contentWindow; + var doc = win.document; + var wu = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor) + .getInterface(Components.interfaces.nsIDOMWindowUtils); + + var docListenerCalled = 0; + doc.addEventListener("foo", function() { ++docListenerCalled; }, true); + var winListenerCalled = 0; + win.addEventListener("foo", function() { ++winListenerCalled; }, true); + var iframeListenerCalled = 0; + b.addEventListener("foo", function() { ++iframeListenerCalled; }, true); + + doc.dispatchEvent(new Event("foo")); + opener.wrappedJSObject.is(docListenerCalled, 1, "Normal dispatch to Document"); + opener.wrappedJSObject.is(winListenerCalled, 1, "Normal dispatch to Document"); + opener.wrappedJSObject.is(iframeListenerCalled, 1, "Normal dispatch to Document"); + + win.dispatchEvent(new Event("foo")); + opener.wrappedJSObject.is(docListenerCalled, 1, "Normal dispatch to Window"); + opener.wrappedJSObject.is(winListenerCalled, 2, "Normal dispatch to Window"); + opener.wrappedJSObject.is(iframeListenerCalled, 2, "Normal dispatch to Window"); + + wu.dispatchEventToChromeOnly(doc, new Event("foo")); + opener.wrappedJSObject.is(docListenerCalled, 1, "Chrome-only dispatch to Document"); + opener.wrappedJSObject.is(winListenerCalled, 2, "Chrome-only dispatch to Document"); + opener.wrappedJSObject.is(iframeListenerCalled, 3, "Chrome-only dispatch to Document"); + + wu.dispatchEventToChromeOnly(win, new Event("foo")); + opener.wrappedJSObject.is(docListenerCalled, 1, "Chrome-only dispatch to Window"); + opener.wrappedJSObject.is(winListenerCalled, 2, "Chrome-only dispatch to Window"); + opener.wrappedJSObject.is(iframeListenerCalled, 4, "Chrome-only dispatch to Window"); + + window.close(); + opener.wrappedJSObject.finishedTests(); + } + + SimpleTest.waitForFocus(runTests); + ]]> + </script> + <iframe xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" + id="b" type="content" src="about:blank" + style="width: 300px; height: 550px; border: 1px solid black;"/> +</window> diff --git a/dom/tests/mochitest/chrome/file_subscript_bindings.js b/dom/tests/mochitest/chrome/file_subscript_bindings.js new file mode 100644 index 000000000..cfc9128d3 --- /dev/null +++ b/dom/tests/mochitest/chrome/file_subscript_bindings.js @@ -0,0 +1 @@ +new window.XMLHttpRequest(); diff --git a/dom/tests/mochitest/chrome/focus_frameset.html b/dom/tests/mochitest/chrome/focus_frameset.html new file mode 100644 index 000000000..32cfa5cdb --- /dev/null +++ b/dom/tests/mochitest/chrome/focus_frameset.html @@ -0,0 +1,26 @@ +<html id="outer"> + +<script type="application/javascript" + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> +<script> +if (opener) + SimpleTest.waitForFocus(() => opener.framesetWindowLoaded(window)); +// Don't try to call finish() in this frame, since it will get upset that we +// ran no tests. +SimpleTest.waitForExplicitFinish(); +</script> + +<frameset rows="30%, 70%"> + <frame src="data:text/html,<html id='f1' ><body id='framebody1'><input id='f2'><body></html>"> + <frameset cols="30%, 33%, 34%"> + <frame src="data:text/html,<html id='f3'><body id='framebody2'><input id='f4'><body></html>"> + <frame src="data:text/html,<html id='f5'><body id='framebody3'><input id='f6' tabindex='2'><body></html>"> + <frame src="data:text/html,<html id='f7'><body id='framebody4'><input id='f8'><body></html>"> + </frameset> + <noframes> + <input id="unused1"/> + <input id="unused2" tabindex="1"/> + </noframes> +</frameset> + +</html> diff --git a/dom/tests/mochitest/chrome/focus_window2.xul b/dom/tests/mochitest/chrome/focus_window2.xul new file mode 100644 index 000000000..1e67343d9 --- /dev/null +++ b/dom/tests/mochitest/chrome/focus_window2.xul @@ -0,0 +1,27 @@ +<?xml version="1.0"?> +<?xml-stylesheet href="chrome://global/skin" type="text/css"?> + +<window id="other-document" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + +<script type="application/javascript" + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + +<script> +<![CDATA[ + +function focused() +{ + if (window.arguments) + setTimeout(() => window.arguments[0](window, window.arguments[1]), 0); +} + +SimpleTest.waitForFocus(focused); + +]]> +</script> + +<button id="other" label="OK"/> +<textbox id="other-textbox" value="test"/> + +</window> diff --git a/dom/tests/mochitest/chrome/fullscreen.xul b/dom/tests/mochitest/chrome/fullscreen.xul new file mode 100644 index 000000000..faaafec94 --- /dev/null +++ b/dom/tests/mochitest/chrome/fullscreen.xul @@ -0,0 +1,27 @@ +<?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 for fullscreen sizemode in chrome + --> +<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" + sizemode="fullscreen"> + +<script> + +window.addEventListener("fullscreen", onFullScreen, true); + +function onFullScreen(event) +{ + window.opener.wrappedJSObject.done(window.fullScreen); +} + +</script> + +<body xmlns="http://www.w3.org/1999/xhtml"> + +<button id="find-button" label="Find"/> +<button id="cancel-button" label="Cancel"/> + +</body> +</window> diff --git a/dom/tests/mochitest/chrome/queryCaretRectUnix.html b/dom/tests/mochitest/chrome/queryCaretRectUnix.html new file mode 100644 index 000000000..fae5bb7ec --- /dev/null +++ b/dom/tests/mochitest/chrome/queryCaretRectUnix.html @@ -0,0 +1,214 @@ +<!DOCTYPE HTML> +<html> +<head> +<title>nsIDOMWindowUtils::sendQueryContentEvent w/QUERY_CARET_RECT test</title> +<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> +<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> + +<style> + #text { + position: absolute; + left: 0em; + top: 0em; + font-size: 10pt; + font-family: monospace; + line-height: 20px; + letter-spacing: 0px; + margin-top:-1px; /* nix the text area border */ + overflow: hidden; + width:800px; + height:400px; + } + #div-hor { + position: absolute; + left: 0em; + border-top:1px solid lightgray; + width: 1000px; + pointer-events:none; + } + #div-ver { + position: absolute; + top: 0em; + border-left:1px solid lightgray; + height: 500px; + pointer-events:none; + } +</style> + +<script type="application/javascript;version=1.8"> + var SimpleTest = window.opener.SimpleTest; + var Ci = Components.interfaces; + + function ok() { window.opener.ok.apply(window.opener, arguments); } + function done() { window.opener.done.apply(window.opener, arguments); } + + function dumpLn() { + for (let idx = 0; idx < arguments.length; idx++) + dump(arguments[idx] + " "); + dump("\n"); + } + + // drawn grid is 20x20 + function drawGrid() { + for (var idx = 0; idx < 20; idx++) { + var e = document.createElement("div"); + e.setAttribute("id", "div-hor"); + e.style.top = (idx*20) + "px"; + document.getElementById("container").appendChild(e); + } + for (var idx = 0; idx < 40; idx++) { + var e = document.createElement("div"); + e.setAttribute("id", "div-ver"); + e.style.left = (idx*20) + "px"; + document.getElementById("container").appendChild(e); + } + } + + function getSelection(aElement) { + if (aElement instanceof Ci.nsIDOMNSEditableElement) { + return aElement.QueryInterface(Ci.nsIDOMNSEditableElement) + .editor.selection; + } + return null; + } + + function testCaretPosition(aDomWinUtils, aOffset, aRectDims) { + let rect = aDomWinUtils.sendQueryContentEvent( + aDomWinUtils.QUERY_CARET_RECT, + aOffset, 0, 0, 0, + aDomWinUtils.QUERY_CONTENT_FLAG_USE_XP_LINE_BREAK); + ok(rect, "rect returned"); + ok(rect.succeeded, "call succeeded"); + + info("left:" + rect.left + " top:" + rect.top); + + ok(rect.left > aRectDims.min.left, "rect.left > " + aRectDims.min.left); + ok(rect.left < aRectDims.max.left, "rect.left < " + aRectDims.max.left); + ok(rect.top > aRectDims.min.top, "rect.top > " + aRectDims.min.top); + ok(rect.top < aRectDims.max.top, "rect.top < " + aRectDims.max.top); + } + + function doTest() { + let domWinUtils = window.QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIDOMWindowUtils); + + let text = document.getElementById("text"); + + text.focus(); + + let textrect = text.getBoundingClientRect(); + + let cp = document.caretPositionFromPoint(10, 395); + let input = cp.offsetNode; + let offset = cp.offset; + input.selectionStart = input.selectionEnd = offset; + + let selection = getSelection(text); + + testCaretPosition(domWinUtils, input.selectionStart, { + min: { left: 5, top: 380 }, + max: { left: 25, top: 390 }, + }); + + testCaretPosition(domWinUtils, input.selectionEnd, { + min: { left: 5, top: 380 }, + max: { left: 25, top: 390 }, + }); + + testCaretPosition(domWinUtils, text.selectionStart, { + min: { left: 5, top: 380 }, + max: { left: 25, top: 390 }, + }); + + testCaretPosition(domWinUtils, text.selectionEnd, { + min: { left: 5, top: 380 }, + max: { left: 25, top: 390 }, + }); + + testCaretPosition(domWinUtils, selection.anchorOffset, { + min: { left: 5, top: 380 }, + max: { left: 25, top: 390 }, + }); + + testCaretPosition(domWinUtils, selection.focusOffset, { + min: { left: 5, top: 380 }, + max: { left: 25, top: 390 }, + }); + + cp = document.caretPositionFromPoint(395, 395); + input = cp.offsetNode; + offset = cp.offset; + input.selectionStart = input.selectionEnd = offset; + + selection = getSelection(text); + + testCaretPosition(domWinUtils, input.selectionStart, { + min: { left: 390, top: 380 }, + max: { left: 400, top: 390 }, + }); + + testCaretPosition(domWinUtils, input.selectionEnd, { + min: { left: 390, top: 380 }, + max: { left: 400, top: 390 }, + }); + + testCaretPosition(domWinUtils, text.selectionStart, { + min: { left: 390, top: 380 }, + max: { left: 400, top: 390 }, + }); + + testCaretPosition(domWinUtils, text.selectionEnd, { + min: { left: 390, top: 380 }, + max: { left: 400, top: 390 }, + }); + + testCaretPosition(domWinUtils, selection.anchorOffset, { + min: { left: 390, top: 380 }, + max: { left: 400, top: 390 }, + }); + + testCaretPosition(domWinUtils, selection.focusOffset, { + min: { left: 390, top: 380 }, + max: { left: 400, top: 390 }, + }); + + done(); + } + +</script> + +<body onload="doTest()"> +<textarea id="text" wrap="on"> +Alice was beginning to get very tired of sitting by her sister on the bank, +and of having nothing to do: once or twice she had peeped into the book +her sister was reading, but it had no pictures or conversations in it, +`and what is the use of a book,' thought Alice `without pictures or +conversation?' + +So she was considering in her own mind (as well as she could, for the +hot day made her feel very sleepy and stupid), whether the pleasure of +making a daisy-chain would be worth the trouble of getting up and +picking the daisies, when suddenly a White Rabbit with pink In another +moment down went Alice after it, never once considering how in the world +she was to get out again. + +The rabbit-hole went straight on like a tunnel for some way, and then +dipped suddenly down, so suddenly that Alice had not a moment to think +about stopping herself before she found herself falling down a very deep +well. + +Either the well was very deep, or she fell very slowly, for she had +plenty of time as she went down to look about her and to wonder what was + going to happen next. First, she tried to look down and make out what +she was coming to, but it was too dark to see anything; then she looked +at the sides of the well, and noticed that they were filled with +cupboards and book-shelves; here and there she saw maps and pictures +hung upon pegs. She took down a jar from one of the shelves as she +passed; it was labelled `ORANGE MARMALADE', but to her great +disappointment it was empty: she did not like to drop the jar for fear +of killing somebody, so managed to put it into one of the cupboards as +she fell past it. +</textarea> +<div id="container"></div> +</body> +</html> diff --git a/dom/tests/mochitest/chrome/queryCaretRectWin.html b/dom/tests/mochitest/chrome/queryCaretRectWin.html new file mode 100644 index 000000000..cd5a8ec64 --- /dev/null +++ b/dom/tests/mochitest/chrome/queryCaretRectWin.html @@ -0,0 +1,223 @@ +<!DOCTYPE HTML>
+<html>
+<head>
+<title>nsIDOMWindowUtils::sendQueryContentEvent w/QUERY_CARET_RECT test</title>
+<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
+
+<!--
+ #########################################################
+ # WARNING: this file has Windows line endings. If you
+ # update this file please maintain them. Line endings are
+ # taken into account when calculating query caret rect
+ # values.
+ #########################################################
+-->
+
+<style>
+ #text {
+ position: absolute;
+ left: 0em;
+ top: 0em;
+ font-size: 10pt;
+ font-family: monospace;
+ line-height: 20px;
+ letter-spacing: 0px;
+ margin-top:-1px; /* nix the text area border */
+ overflow: hidden;
+ width:800px;
+ height:400px;
+ }
+ #div-hor {
+ position: absolute;
+ left: 0em;
+ border-top:1px solid lightgray;
+ width: 1000px;
+ pointer-events:none;
+ }
+ #div-ver {
+ position: absolute;
+ top: 0em;
+ border-left:1px solid lightgray;
+ height: 500px;
+ pointer-events:none;
+ }
+</style>
+
+<script type="application/javascript;version=1.8">
+ var SimpleTest = window.opener.SimpleTest;
+ var Ci = Components.interfaces;
+
+ function ok() { window.opener.ok.apply(window.opener, arguments); }
+ function done() { window.opener.done.apply(window.opener, arguments); }
+
+ function dumpLn() {
+ for (let idx = 0; idx < arguments.length; idx++)
+ dump(arguments[idx] + " ");
+ dump("\n");
+ }
+
+ // drawn grid is 20x20
+ function drawGrid() {
+ for (var idx = 0; idx < 20; idx++) {
+ var e = document.createElement("div");
+ e.setAttribute("id", "div-hor");
+ e.style.top = (idx*20) + "px";
+ document.getElementById("container").appendChild(e);
+ }
+ for (var idx = 0; idx < 40; idx++) {
+ var e = document.createElement("div");
+ e.setAttribute("id", "div-ver");
+ e.style.left = (idx*20) + "px";
+ document.getElementById("container").appendChild(e);
+ }
+ }
+
+ function getSelection(aElement) {
+ if (aElement instanceof Ci.nsIDOMNSEditableElement) {
+ return aElement.QueryInterface(Ci.nsIDOMNSEditableElement)
+ .editor.selection;
+ }
+ return null;
+ }
+
+ function testCaretPosition(aDomWinUtils, aOffset, aRectDims) {
+ let rect = aDomWinUtils.sendQueryContentEvent(
+ aDomWinUtils.QUERY_CARET_RECT,
+ aOffset, 0, 0, 0,
+ aDomWinUtils.QUERY_CONTENT_FLAG_USE_XP_LINE_BREAK);
+ ok(rect, "rect returned");
+ ok(rect.succeeded, "call succeeded");
+
+ info("left:" + rect.left + " top:" + rect.top);
+
+ ok(rect.left > aRectDims.min.left, "rect.left > " + aRectDims.min.left);
+ ok(rect.left < aRectDims.max.left, "rect.left < " + aRectDims.max.left);
+ ok(rect.top > aRectDims.min.top, "rect.top > " + aRectDims.min.top);
+ ok(rect.top < aRectDims.max.top, "rect.top < " + aRectDims.max.top);
+ }
+
+ function doTest() {
+ let domWinUtils = window.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIDOMWindowUtils);
+
+ let text = document.getElementById("text");
+
+ text.focus();
+
+ let textrect = text.getBoundingClientRect();
+
+ let cp = document.caretPositionFromPoint(10, 395);
+ let input = cp.offsetNode;
+ let offset = cp.offset;
+ input.selectionStart = input.selectionEnd = offset;
+
+ let selection = getSelection(text);
+
+ testCaretPosition(domWinUtils, input.selectionStart, {
+ min: { left: 10, top: 380 },
+ max: { left: 25, top: 390 },
+ });
+
+ testCaretPosition(domWinUtils, input.selectionEnd, {
+ min: { left: 10, top: 380 },
+ max: { left: 25, top: 390 },
+ });
+
+ testCaretPosition(domWinUtils, text.selectionStart, {
+ min: { left: 10, top: 380 },
+ max: { left: 25, top: 390 },
+ });
+
+ testCaretPosition(domWinUtils, text.selectionEnd, {
+ min: { left: 10, top: 380 },
+ max: { left: 25, top: 390 },
+ });
+
+ testCaretPosition(domWinUtils, selection.anchorOffset, {
+ min: { left: 10, top: 380 },
+ max: { left: 25, top: 390 },
+ });
+
+ testCaretPosition(domWinUtils, selection.focusOffset, {
+ min: { left: 10, top: 380 },
+ max: { left: 25, top: 390 },
+ });
+
+ cp = document.caretPositionFromPoint(395, 395);
+ input = cp.offsetNode;
+ offset = cp.offset;
+ input.selectionStart = input.selectionEnd = offset;
+
+ selection = getSelection(text);
+
+ testCaretPosition(domWinUtils, input.selectionStart, {
+ min: { left: 390, top: 380 },
+ max: { left: 400, top: 390 },
+ });
+
+ testCaretPosition(domWinUtils, input.selectionEnd, {
+ min: { left: 390, top: 380 },
+ max: { left: 400, top: 390 },
+ });
+
+ testCaretPosition(domWinUtils, text.selectionStart, {
+ min: { left: 390, top: 380 },
+ max: { left: 400, top: 390 },
+ });
+
+ testCaretPosition(domWinUtils, text.selectionEnd, {
+ min: { left: 390, top: 380 },
+ max: { left: 400, top: 390 },
+ });
+
+ testCaretPosition(domWinUtils, selection.anchorOffset, {
+ min: { left: 390, top: 380 },
+ max: { left: 400, top: 390 },
+ });
+
+ testCaretPosition(domWinUtils, selection.focusOffset, {
+ min: { left: 390, top: 380 },
+ max: { left: 400, top: 390 },
+ });
+
+ done();
+ }
+
+</script>
+
+<body onload="doTest()">
+<textarea id="text" wrap="on">
+Alice was beginning to get very tired of sitting by her sister on the bank,
+and of having nothing to do: once or twice she had peeped into the book
+her sister was reading, but it had no pictures or conversations in it,
+`and what is the use of a book,' thought Alice `without pictures or
+conversation?'
+
+So she was considering in her own mind (as well as she could, for the
+hot day made her feel very sleepy and stupid), whether the pleasure of
+making a daisy-chain would be worth the trouble of getting up and
+picking the daisies, when suddenly a White Rabbit with pink In another
+moment down went Alice after it, never once considering how in the world
+she was to get out again.
+
+The rabbit-hole went straight on like a tunnel for some way, and then
+dipped suddenly down, so suddenly that Alice had not a moment to think
+about stopping herself before she found herself falling down a very deep
+well.
+
+Either the well was very deep, or she fell very slowly, for she had
+plenty of time as she went down to look about her and to wonder what was
+ going to happen next. First, she tried to look down and make out what
+she was coming to, but it was too dark to see anything; then she looked
+at the sides of the well, and noticed that they were filled with
+cupboards and book-shelves; here and there she saw maps and pictures
+hung upon pegs. She took down a jar from one of the shelves as she
+passed; it was labelled `ORANGE MARMALADE', but to her great
+disappointment it was empty: she did not like to drop the jar for fear
+of killing somebody, so managed to put it into one of the cupboards as
+she fell past it.
+</textarea>
+<div id="container"></div>
+</body>
+</html>
diff --git a/dom/tests/mochitest/chrome/selectAtPoint.html b/dom/tests/mochitest/chrome/selectAtPoint.html new file mode 100644 index 000000000..8c625e6f7 --- /dev/null +++ b/dom/tests/mochitest/chrome/selectAtPoint.html @@ -0,0 +1,281 @@ +<!DOCTYPE HTML> +<html> +<head> +<title>nsIDOMWindowUtils::selectAtPoint test</title> +<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> +<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> + +<script type="application/javascript;version=1.8"> + var SimpleTest = window.opener.SimpleTest; + var Ci = Components.interfaces; + + function ok() { window.opener.ok.apply(window.opener, arguments); } + function done() { window.opener.done.apply(window.opener, arguments); } + + function dumpLn() { + for (let idx = 0; idx < arguments.length; idx++) + dump(arguments[idx] + " "); + dump("\n"); + } + + function getCharacterDims() { + let span = document.getElementById("measure"); + let rect = span.getBoundingClientRect(); + return { width: rect.right - rect.left, + height: rect.bottom - rect.top }; + } + + function setStart(aDWU, aX, aY, aSelectType) + { + // Clear any existing selection + let selection = document.getSelection(); + selection.removeAllRanges(); + + // Select text + let result = aDWU.selectAtPoint(aX, aY, aSelectType); + ok(result == true, "selectAtPoint secceeded?"); + } + + function setEnd(aDWU, aX, aY, aSelectType) + { + // Select text + let result = aDWU.selectAtPoint(aX, aY, aSelectType); + ok(result == true, "selectAtPoint secceeded?"); + } + + function setSingle(aDWU, aX, aY, aSelectType, aSelectTypeStr, aExpectedSelectionText) { + // Clear any existing selection + let selection = document.getSelection(); + selection.removeAllRanges(); + + // Select text + let result = aDWU.selectAtPoint(aX, aY, aSelectType); + ok(result == true, "selectAtPoint secceeded?"); + } + + function checkSelection(aDoc, aSelectTypeStr, aExpectedSelectionText) { + // Retrieve text selected + let selection = aDoc.getSelection(); + let text = selection.toString(); + + // Test + let result = (text == aExpectedSelectionText); + ok(result, aSelectTypeStr + " selection text matches?"); + if (!result) { + dumpLn(aSelectTypeStr + " selection text:", "[" + text + "] expected:[" + aExpectedSelectionText + "]" ); + } + } + + function doTest() { + let dwu = window.QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIDOMWindowUtils); + + let os = Components.classes["@mozilla.org/xre/app-info;1"] + .getService(Ci.nsIXULRuntime).OS; + let isLinux = (os == "Linux"); + let isMac = (os == "Darwin"); + let isWindows = (os == "WINNT"); + + if (!isLinux && !isMac && !isWindows) { + done(); + return; + } + + window.scrollTo(0, 0); + + // Trick to get character spacing - get the bounds around a + // single character trapped in a div. + let charDims = getCharacterDims(); + // dumpLn("character dims:", charDims.width, charDims.height); + + // + // Root frame selection + // + + // First div in the main page + + let div = document.getElementById("div1"); + let rect = div.getBoundingClientRect(); + + // Centered on the first character in the sentence div + let targetPoint = { xPos: rect.left + (charDims.width / 2), + yPos: rect.top + (charDims.height / 2) }; + + setSingle(dwu, targetPoint.xPos, targetPoint.yPos, Ci.nsIDOMWindowUtils.SELECT_WORDNOSPACE); + checkSelection(document, "SELECT_WORDNOSPACE", "ttestselection1"); + setSingle(dwu, targetPoint.xPos, targetPoint.yPos, Ci.nsIDOMWindowUtils.SELECT_WORD); + if (isLinux || isMac) { + checkSelection(document, "SELECT_WORD", "ttestselection1"); + } else if (isWindows) { + checkSelection(document, "SELECT_WORD", "ttestselection1 "); + } + setSingle(dwu, targetPoint.xPos, targetPoint.yPos, Ci.nsIDOMWindowUtils.SELECT_PARAGRAPH); + checkSelection(document, "SELECT_PARAGRAPH", "ttestselection1 Lorem ipsum dolor sit amet, at duo debet graeci, vivendum vulputate per ut. Ne labore incorrupte vix. Cu copiosae postulant tincidunt ius, in illud appetere contentiones eos. Ei munere officiis assentior pro, nibh decore ius at."); + + // Centered on the second character in the sentence div + targetPoint = { xPos: rect.left + (charDims.width + (charDims.width / 2)), + yPos: rect.top + (charDims.height / 2) }; + setSingle(dwu, targetPoint.xPos, targetPoint.yPos, Ci.nsIDOMWindowUtils.SELECT_CHARACTER); + checkSelection(document, "SELECT_CHARACTER", "te"); + setSingle(dwu, targetPoint.xPos, targetPoint.yPos, Ci.nsIDOMWindowUtils.SELECT_CLUSTER); + checkSelection(document, "SELECT_CLUSTER", "te"); + + // Separate character blocks in a word 't(te)s(ts)election1' + targetPoint = { xPos: rect.left + (charDims.width + (charDims.width / 2)), + yPos: rect.top + (charDims.height / 2) }; + setStart(dwu, targetPoint.xPos, targetPoint.yPos, Ci.nsIDOMWindowUtils.SELECT_CHARACTER); + targetPoint = { xPos: rect.left + ((charDims.width * 4) + (charDims.width / 2)), + yPos: rect.top + (charDims.height / 2) }; + setEnd(dwu, targetPoint.xPos, targetPoint.yPos, Ci.nsIDOMWindowUtils.SELECT_CHARACTER); + if (isLinux || isMac) { + // XXX I think this is a bug, the right hand selection is 4.5 characters over with a + // monspaced font. what we want: t(te)s(ts)election1 what we get: t(te)st(se)lection1 + checkSelection(document, "split selection", "tese"); + } else if (isWindows) { + checkSelection(document, "split selection", "tets"); + } + + // Trying to select where there's no text, should fail but not throw + let result = dwu.selectAtPoint(rect.left - 20, rect.top - 20, Ci.nsIDOMWindowUtils.SELECT_CHARACTER, false); + ok(result == false, "couldn't select?"); + + // Second div in the main page + + div = document.getElementById("div2"); + rect = div.getBoundingClientRect(); + + // Centered on the first line, first character in the paragraph div + targetPoint = { xPos: rect.left + (charDims.width / 2), + yPos: rect.top + (charDims.height / 2) }; + setSingle(dwu, targetPoint.xPos + 50, targetPoint.yPos, Ci.nsIDOMWindowUtils.SELECT_PARAGRAPH); + checkSelection(document, "SELECT_PARAGRAPH", "Lorem ipsum dolor sit amet, at duo debet graeci, vivendum vulputate per ut. Ne labore incorrupte vix. Cu copiosae postulant tincidunt ius, in illud appetere contentiones eos."); + + // + // Inner IFRAME selection tests + // + + let frame = document.getElementById("frame1"); + let dwuFrame = frame.contentDocument + .defaultView + .QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIDOMWindowUtils); + + frame.contentWindow.scrollTo(0, 0); + + rect = frame.getBoundingClientRect(); + + targetPoint = { xPos: charDims.width / 2, + yPos: charDims.height / 2 }; + setSingle(dwuFrame, targetPoint.xPos, targetPoint.yPos, Ci.nsIDOMWindowUtils.SELECT_WORDNOSPACE); + checkSelection(frame.contentWindow.document, "SELECT_WORDNOSPACE", "ttestselection2"); + setSingle(dwuFrame, targetPoint.xPos, targetPoint.yPos, Ci.nsIDOMWindowUtils.SELECT_WORD); + if (isLinux || isMac) { + checkSelection(frame.contentWindow.document, "SELECT_WORD", "ttestselection2"); + } else if (isWindows) { + checkSelection(frame.contentWindow.document, "SELECT_WORD", "ttestselection2 "); + } + setSingle(dwuFrame, targetPoint.xPos, targetPoint.yPos, Ci.nsIDOMWindowUtils.SELECT_PARAGRAPH); + checkSelection(frame.contentWindow.document, "SELECT_PARAGRAPH", "ttestselection2 Lorem ipsum dolor sit amet, at duo debet graeci, vivendum vulputate per ut."); + + // Outside the frame should throw. This is a failure in coordinate setup of + // nsDOMWindowUtils::SelectAtPoint. + let thr = false; + try { + dwuFrame.selectAtPoint(rect.right + 50, rect.top, Ci.nsIDOMWindowUtils.SELECT_WORD, false); + } catch (ex) { thr = true; } + ok(thr == true, "selectAtPoint expected throw?"); + + done(); + } + + let frameLoad = false; + let pageLoad = false; + let painted = false; + function testReady() { + if (frameLoad && pageLoad && painted) + doTest(); + } + + function onFrameLoad() { + // Exit the onload handler before trying the test, because we need + // to ensure that paint unsupression has happened. + setTimeout(function() { + frameLoad = true; + testReady(); + }, 0); + } + + function onPageLoad() { + // Exit the onload handler before trying the test, because we need + // to ensure that paint unsupression has happened + // XXXroc why do we need to separately test for the loading of the frame + // and a paint? That should not be necessary for this test. + setTimeout(function() { + pageLoad = true; + testReady(); + }, 0); + } + + function onPaint() { + window.removeEventListener("MozAfterPaint", onPaint, false); + painted = true; + testReady(); + } + + window.addEventListener("MozAfterPaint", onPaint, false); +</script> + +<style type="text/css"> + +body { + font-family: monospace; + margin-left: 40px; + margin-top: 40px; + padding: 0; +} + +#div1 { + border: 1px solid red; + width: 400px; + height: 100px; +} + +#frame1 { + display: block; + height: 100px; + width: 300px; + border: 1px solid blue; + padding: 0; + margin: 0; +} + +#div2 { + border: 1px solid green; +} + +#measure { + padding: 0px; + margin: 0px; + border: 1px solid red; +} + +</style> +</head> +<body id="body" onload="onPageLoad();"> + +<div id="div1">ttestselection1 Lorem ipsum dolor sit amet, at duo debet graeci, vivendum vulputate per ut. Ne labore incorrupte vix. Cu copiosae postulant tincidunt ius, in illud appetere contentiones eos. Ei munere officiis assentior pro, nibh decore ius at.</div> + +<br /> + +<iframe id="frame1" src="data:text/html,<html><body style='margin: 0; padding: 0; font-family: monospace;' onload='window.parent.onFrameLoad();'><div id='sel2'>ttestselection2 Lorem ipsum dolor sit amet, at duo debet graeci, vivendum vulputate per ut.</div><br/><br/></body></html>"></iframe> + +<br/> + +<div id="div2">Lorem ipsum dolor sit amet, at duo debet graeci, vivendum vulputate per ut. Ne labore incorrupte vix. Cu copiosae postulant tincidunt ius, in illud appetere contentiones eos.</div> + +<br /> + +<span id="measure">t</span> + +</body> +</html> diff --git a/dom/tests/mochitest/chrome/sizemode_attribute.xul b/dom/tests/mochitest/chrome/sizemode_attribute.xul new file mode 100644 index 000000000..bb65c04bb --- /dev/null +++ b/dom/tests/mochitest/chrome/sizemode_attribute.xul @@ -0,0 +1,87 @@ +<?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 for fullscreen sizemode in chrome + --> +<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" + persist="sizemode" + sizemode="normal" + onload="nextStep()"> + +<script type="text/javascript;version=1.8"> +let tests = [ + function test1() { + checkAndContinue("normal"); + }, + + function test2() { + listen("fullscreen", () => checkAndContinue("fullscreen")); + window.fullScreen = true; + }, + + function test3() { + listen("fullscreen", () => checkAndContinue("normal")); + window.fullScreen = false; + }, + + function test4() { + listen("resize", () => checkAndContinue("maximized")); + window.maximize(); + }, + + function test5() { + listen("fullscreen", () => checkAndContinue("fullscreen")); + window.fullScreen = true; + }, + + function test6() { + listen("fullscreen", () => checkAndContinue("maximized")); + window.fullScreen = false; + }, + + function test7() { + listen("resize", () => checkAndContinue("normal")); + window.restore(); + }, + + function test8() { + window.opener.wrappedJSObject.done(); + } +]; + +function nextStep() { + tests.shift()(); +} + +function listen(event, fn) { + window.addEventListener(event, function listener() { + window.removeEventListener(event, listener, false); + fn(); + }, false); +} + +function checkAndContinue(sizemode) { + + let windowStates = { + "fullscreen": window.STATE_FULLSCREEN, + "normal": window.STATE_NORMAL, + "maximized": window.STATE_MAXIMIZED + }; + + setTimeout(function() { + is(window.document.documentElement.getAttribute("sizemode"), sizemode, "sizemode attribute should match actual window state"); + is(window.fullScreen, sizemode == "fullscreen", "window.fullScreen should match actual window state"); + is(window.windowState, windowStates[sizemode], "window.sizeMode should match actual window state"); + nextStep(); + }, 0); +} + +let is = window.opener.wrappedJSObject.is; + +</script> + +<body xmlns="http://www.w3.org/1999/xhtml"> + +</body> +</window> diff --git a/dom/tests/mochitest/chrome/test_DOMWindowCreated.xul b/dom/tests/mochitest/chrome/test_DOMWindowCreated.xul new file mode 100644 index 000000000..2b74cde11 --- /dev/null +++ b/dom/tests/mochitest/chrome/test_DOMWindowCreated.xul @@ -0,0 +1,29 @@ +<?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 for Persistent Storage in chrome
+ -->
+<window id="sample-window" width="400" height="400"
+ xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+ <script type="application/javascript"
+ src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="application/javascript"
+ src="chrome://mochikit/content/chrome-harness.js"></script>
+
+<body xmlns="http://www.w3.org/1999/xhtml">
+<p id="display">
+</p>
+<div id="content" style="display: none">
+</div>
+<pre id="test">
+</pre>
+</body>
+
+<script>
+SimpleTest.waitForExplicitFinish();
+var root = getRootDirectory(window.location.href);
+window.open(root + "DOMWindowCreated_chrome.xul", "_blank", "chrome,width=600,height=550");
+</script>
+
+</window>
diff --git a/dom/tests/mochitest/chrome/test_DOM_element_instanceof.xul b/dom/tests/mochitest/chrome/test_DOM_element_instanceof.xul new file mode 100644 index 000000000..220220420 --- /dev/null +++ b/dom/tests/mochitest/chrome/test_DOM_element_instanceof.xul @@ -0,0 +1,34 @@ +<?xml version="1.0"?> +<?xml-stylesheet type="text/css" href="chrome://global/skin"?> +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=824917 +--> +<window title="Mozilla Bug 824917" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> + + <!-- test results are displayed in the html:body --> + <body xmlns="http://www.w3.org/1999/xhtml"> + <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=824917" + target="_blank">Mozilla Bug 824917</a> + </body> + + <iframe type="content"></iframe> + + <!-- test code goes here --> + <script type="application/javascript"> + <![CDATA[ + /** Test for Bug 824917 **/ + + function runTests() { + window.open("file_DOM_element_instanceof.xul", "_blank", "chrome,width=600,height=550"); + } + + addLoadEvent(runTests); + + SimpleTest.waitForExplicitFinish(); + + ]]> + </script> +</window> diff --git a/dom/tests/mochitest/chrome/test_MozDomFullscreen_event.xul b/dom/tests/mochitest/chrome/test_MozDomFullscreen_event.xul new file mode 100644 index 000000000..3ece38553 --- /dev/null +++ b/dom/tests/mochitest/chrome/test_MozDomFullscreen_event.xul @@ -0,0 +1,56 @@ +<?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 "MozShowFullScreenWarning" is dispatched to chrome on restricted keypress. + --> +<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" width="400" height="400"> + + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + +<script> +SimpleTest.waitForExplicitFinish(); + +// Ensure the full-screen api is enabled, and will be disabled on test exit. +var gPrevEnabled = SpecialPowers.getBoolPref("full-screen-api.enabled"); +var gPrevTrusted = SpecialPowers.getBoolPref("full-screen-api.allow-trusted-requests-only"); +var newwindow; +var Cc = Components.classes; +var Ci = Components.interfaces; + +function make_uri(url) { + var ios = Cc["@mozilla.org/network/io-service;1"]. + getService(Ci.nsIIOService); + return ios.newURI(url, null, null); +} + +// Ensure "fullscreen" permissions are not present on the test URI. +var pm = Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager); +var uri = make_uri("http://mochi.test:8888"); +var ssm = Components.classes["@mozilla.org/scriptsecuritymanager;1"] + .getService(Ci.nsIScriptSecurityManager); +var principal = ssm.createCodebasePrincipal(uri, {}); +pm.removeFromPrincipal(principal, "fullscreen"); + +SpecialPowers.pushPrefEnv({"set": [ + ['full-screen-api.enabled', true], + ['full-screen-api.allow-trusted-requests-only', false], + ['full-screen-api.transition-duration.enter', '0 0'], + ['full-screen-api.transition-duration.leave', '0 0'] +]}, setup); + +function setup() { + newwindow = window.open("MozDomFullscreen_chrome.xul", "_blank","chrome,resizable=yes,width=400,height=400"); +} + +function done() +{ + newwindow.close(); + SimpleTest.finish(); +} + +</script> + +<body xmlns="http://www.w3.org/1999/xhtml" style="height: 300px; overflow: auto;"/> + +</window> diff --git a/dom/tests/mochitest/chrome/test_activation.xul b/dom/tests/mochitest/chrome/test_activation.xul new file mode 100644 index 000000000..ff1809036 --- /dev/null +++ b/dom/tests/mochitest/chrome/test_activation.xul @@ -0,0 +1,42 @@ +<?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"?> +<?xml-stylesheet href="data:text/css, + +%23box { + background: blue; +} + +%23box:-moz-window-inactive { + background: cyan; +} + +" type="text/css"?> +<!-- + Test for the :-moz-window-inactive pseudoclass + --> +<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" + sizemode="fullscreen"> + + <script type="application/javascript" + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + +<box id="box" height="100"/> + +<script> +SimpleTest.waitForExplicitFinish(); + +newwindow = window.open("window_activation.xul", "_blank","chrome,width=300,height=200"); + +function complete() +{ + newwindow.close(); + SimpleTest.finish(); +} + +</script> + + +<body xmlns="http://www.w3.org/1999/xhtml" style="height: 300px; overflow: auto;"/> + +</window> diff --git a/dom/tests/mochitest/chrome/test_bug1224790-1.xul b/dom/tests/mochitest/chrome/test_bug1224790-1.xul new file mode 100644 index 000000000..6c14d7c08 --- /dev/null +++ b/dom/tests/mochitest/chrome/test_bug1224790-1.xul @@ -0,0 +1,71 @@ +<?xml version="1.0"?> +<?xml-stylesheet type="text/css" href="chrome://global/skin"?> +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=1224790 +--> +<window title="Mozilla Bug 1224790" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/> + + <!-- test code goes here --> + <script type="application/javascript"> + <![CDATA[ + + /** Test for Bug 1224790 **/ + /* + * 1. Opens modal dialog + * 2. Open non-modal window from modal dialog + * 3. Close non-modal window + * 4. Close modal dialog + * 5. Click button to ensure mouse event is working + */ + + function startTest() { + window.openDialog('file_bug1224790-1_modal.xul', '', 'modal'); + } + + function modalClosed() { + SimpleTest.waitForFocus(gotFocus); + } + + var timer = null; + function gotFocus() { + var button = document.getElementById('button'); + synthesizeMouseAtCenter(button, { type: 'mousemove' }, window); + function click() { + // The bug is not reproducible with synthesizeMouseAtCenter. + // Need to emulate native mouse event. + synthesizeNativeOSXClick(button.boxObject.screenX + button.boxObject.width / 2, + button.boxObject.screenY + button.boxObject.height / 2); + } + click(); + // On debug build, it's possible that the click event handler is not + // triggered by the first click in case the click is dispatched too early + // before Firefox gets ready for input. + // Click the button again after 1 sec when we don't get click event. + timer = setTimeout(click, 1000); + } + + function onClick() { + if (timer) { + // Avoid clicking unrelated thing. + clearTimeout(timer); + } + ok(true, "Click event should be fired"); + SimpleTest.finish(); + } + + SimpleTest.waitForExplicitFinish(); + SimpleTest.waitForFocus(startTest); + ]]> + </script> + + <!-- test results are displayed in the html:body --> + <body xmlns="http://www.w3.org/1999/xhtml"> + <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1224790" + target="_blank">Mozilla Bug 1224790</a> + </body> + <button id="button" label="button" oncommand="onClick()" /> +</window> diff --git a/dom/tests/mochitest/chrome/test_bug1224790-2.xul b/dom/tests/mochitest/chrome/test_bug1224790-2.xul new file mode 100644 index 000000000..5ce7f1054 --- /dev/null +++ b/dom/tests/mochitest/chrome/test_bug1224790-2.xul @@ -0,0 +1,72 @@ +<?xml version="1.0"?> +<?xml-stylesheet type="text/css" href="chrome://global/skin"?> +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=1224790 +--> +<window title="Mozilla Bug 1224790" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/> + + <!-- test code goes here --> + <script type="application/javascript"> + <![CDATA[ + + /** Test for Bug 1224790 **/ + /* + * 1. Opens modal dialog + * 2. Open non-modal window from modal dialog + * 3. Close modal dialog + * 4. Wait for a while for destructor for modal dialog + * 5. Close non-modal window + * 6. Click button to ensure mouse event is working + */ + + function startTest() { + window.openDialog('file_bug1224790-2_modal.xul', '', 'modal'); + } + + function nonModalClosed() { + SimpleTest.waitForFocus(gotFocus); + } + + var timer = null; + function gotFocus() { + var button = document.getElementById('button'); + synthesizeMouseAtCenter(button, { type: 'mousemove' }, window); + function click() { + // The bug is not reproducible with synthesizeMouseAtCenter. + // Need to emulate native mouse event. + synthesizeNativeOSXClick(button.boxObject.screenX + button.boxObject.width / 2, + button.boxObject.screenY + button.boxObject.height / 2); + } + click(); + // On debug build, it's possible that the click event handler is not + // triggered by the first click in case the click is dispatched too early + // before Firefox gets ready for input. + // Click the button again after 1 sec when we don't get click event. + timer = setTimeout(click, 1000); + } + + function onClick() { + if (timer) { + // Avoid clicking unrelated thing. + clearTimeout(timer); + } + ok(true, "Click event should be fired"); + SimpleTest.finish(); + } + + SimpleTest.waitForExplicitFinish(); + SimpleTest.waitForFocus(startTest); + ]]> + </script> + + <!-- test results are displayed in the html:body --> + <body xmlns="http://www.w3.org/1999/xhtml"> + <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1224790" + target="_blank">Mozilla Bug 1224790</a> + </body> + <button id="button" label="button" oncommand="onClick()" /> +</window> diff --git a/dom/tests/mochitest/chrome/test_bug799299.xul b/dom/tests/mochitest/chrome/test_bug799299.xul new file mode 100644 index 000000000..9819f95a1 --- /dev/null +++ b/dom/tests/mochitest/chrome/test_bug799299.xul @@ -0,0 +1,31 @@ +<?xml version="1.0"?> +<?xml-stylesheet type="text/css" href="chrome://global/skin"?> +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=799299 +--> +<window title="Mozilla Bug 799299" onload="runTests()" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/> + + <!-- test results are displayed in the html:body --> + <body xmlns="http://www.w3.org/1999/xhtml"> + <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=799299" + target="_blank">Mozilla Bug 799299</a> + </body> + + <!-- test code goes here --> + <script type="application/javascript"> + <![CDATA[ + /** Test for Bug 799299 **/ + + function runTests() { + window.open("file_bug799299.xul", "_blank", "chrome,width=600,height=550"); + } + + SimpleTest.waitForExplicitFinish(); + + ]]> + </script> +</window> diff --git a/dom/tests/mochitest/chrome/test_bug800817.xul b/dom/tests/mochitest/chrome/test_bug800817.xul new file mode 100644 index 000000000..7a0aaeb6f --- /dev/null +++ b/dom/tests/mochitest/chrome/test_bug800817.xul @@ -0,0 +1,43 @@ +<?xml version="1.0"?> +<?xml-stylesheet type="text/css" href="chrome://global/skin"?> +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=800817 +--> +<window title="Mozilla Bug 800817" onload="runTests()" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/> + + <!-- test results are displayed in the html:body --> + <body xmlns="http://www.w3.org/1999/xhtml"> + <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=800817" + target="_blank">Mozilla Bug 800817</a> + </body> + + <!-- test code goes here --> + <script type="application/javascript"> + <![CDATA[ + /** Test for Bug 800817 **/ + + var testMozBrowser = false; + function runTests() { + // Run a first round of tests for non-mozbrowser iframes. + window.open("file_bug800817.xul", "_blank", "chrome,width=600,height=550"); + } + + function finishedTests() { + if (!testMozBrowser) { + testMozBrowser = true; + // Run a second round of tests for mozbrowser iframes. + window.open("file_bug800817.xul", "_blank", "chrome,width=600,height=550"); + } else { + SimpleTest.finish(); + } + } + + SimpleTest.waitForExplicitFinish(); + + ]]> + </script> +</window> diff --git a/dom/tests/mochitest/chrome/test_bug830396.xul b/dom/tests/mochitest/chrome/test_bug830396.xul new file mode 100644 index 000000000..e5f32930f --- /dev/null +++ b/dom/tests/mochitest/chrome/test_bug830396.xul @@ -0,0 +1,39 @@ +<?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"?> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=830396 +--> +<window title="Mozilla Bug 830396" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + + <script type="application/javascript" + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" /> +<script class="testbody" type="application/javascript"> +<![CDATA[ + +function runTests() +{ + var doc = frames[0].document; + var cs = doc.defaultView.getComputedStyle(doc.body); + var nsIDOMCSSValueList = Components.interfaces.nsIDOMCSSValueList; + ok(cs.getPropertyCSSValue("cursor") instanceof nsIDOMCSSValueList, + "CSSValueList should be a nsIDOMCSSValueList"); + SimpleTest.finish(); +} +]]> +</script> +<body onload="runTests();" xmlns="http://www.w3.org/1999/xhtml"> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=830396">Mozilla Bug 830396</a> +<p id="display"></p> +<div id="content" style="display: none"> + +</div> +<pre id="test"> +</pre> +<iframe type="content"></iframe> +</body> + + +</window> diff --git a/dom/tests/mochitest/chrome/test_bug830858.xul b/dom/tests/mochitest/chrome/test_bug830858.xul new file mode 100644 index 000000000..61ab13fd0 --- /dev/null +++ b/dom/tests/mochitest/chrome/test_bug830858.xul @@ -0,0 +1,36 @@ +<?xml version="1.0"?> +<?xml-stylesheet type="text/css" href="chrome://global/skin"?> +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=830858 +--> +<window title="Mozilla Bug 830858" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" + onload="runTests()"> + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> + + <!-- test code goes here --> + <script type="application/javascript"> + <![CDATA[ + + /** Test for Bug 830858 **/ + + function runTests() { + window.open("file_bug830858.xul", "_blank", "chrome,width=600,height=550"); + } + + function finishedTests() { + SimpleTest.finish(); + } + + SimpleTest.waitForExplicitFinish(); + + ]]> + </script> + + <!-- test results are displayed in the html:body --> + <body xmlns="http://www.w3.org/1999/xhtml"> + <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=830858" + target="_blank">Mozilla Bug 830858</a> + </body> +</window> diff --git a/dom/tests/mochitest/chrome/test_callback_wrapping.xul b/dom/tests/mochitest/chrome/test_callback_wrapping.xul new file mode 100644 index 000000000..4546c65d5 --- /dev/null +++ b/dom/tests/mochitest/chrome/test_callback_wrapping.xul @@ -0,0 +1,22 @@ +<?xml version="1.0"?> +<?xml-stylesheet type="text/css" href="chrome://global/skin"?> +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=742222 +--> +<window title="Mozilla Bug 742222" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> + + <!-- test results are displayed in the html:body --> + <body xmlns="http://www.w3.org/1999/xhtml"> + <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=742222" + target="_blank">Mozilla Bug 742222</a> + </body> + + <!-- test code goes here --> + <script type="application/javascript"> + SimpleTest.waitForExplicitFinish(); + window.open("window_callback_wrapping.xul"); + </script> +</window> diff --git a/dom/tests/mochitest/chrome/test_clipboard_events_chrome.html b/dom/tests/mochitest/chrome/test_clipboard_events_chrome.html new file mode 100644 index 000000000..509cd3d5d --- /dev/null +++ b/dom/tests/mochitest/chrome/test_clipboard_events_chrome.html @@ -0,0 +1,63 @@ +<html> +<body onload="runTest()"> + +<script type="application/javascript" + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> +<script type="application/javascript" + src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> + +<script> +// This test checks that the dom.event.clipboardevents.enabled does not apply to chrome shells. + +SimpleTest.waitForExplicitFinish(); +function runTest() +{ + SpecialPowers.pushPrefEnv({"set": [['dom.event.clipboardevents.enabled', false]]}, function() { + window.open("data:text/html,<body onload='window.opener.doChecks(this)'><input id='i' value='Sample Text'></body>", + "_blank", "chrome,width=200,height=200"); + }); +} + +var event_fired = false; + +function doChecks(win) +{ + var windowFocused = function() { + var textbox = win.document.getElementById("i"); + textbox.value = "Sample Text"; + + textbox.oncut = function() { event_fired = true; }; + textbox.oncopy = function() { event_fired = true; }; + textbox.onpaste = function() { event_fired = true; }; + + textbox.select(); + textbox.focus(); + + textbox.setSelectionRange(1, 4); + synthesizeKey("x", {accelKey: 1}, win); + is(textbox.value, "Sle Text", "cut changed text when preference is disabled"); + ok(event_fired, "cut event fired when preference is disabled") + + event_fired = false; + textbox.setSelectionRange(4, 6); + synthesizeKey("c", {accelKey: 1}, win); + is(textbox.value, "Sle Text", "cut changed text when preference is disabled"); + ok(event_fired, "copy event fired when preference is disabled") + + event_fired = false; + textbox.setSelectionRange(1, 4); + synthesizeKey("v", {accelKey: 1}, win); + is(textbox.value, "STeText", "paste changed text when preference is disabled"); + ok(event_fired, "paste event fired when preference is disabled") + + win.close(); + SimpleTest.finish(); + } + + SimpleTest.waitForFocus(windowFocused, win); +} + +</script> + +<p id="display"></p> +</body></html> diff --git a/dom/tests/mochitest/chrome/test_clonewrapper.xul b/dom/tests/mochitest/chrome/test_clonewrapper.xul new file mode 100644 index 000000000..ceef40fdc --- /dev/null +++ b/dom/tests/mochitest/chrome/test_clonewrapper.xul @@ -0,0 +1,117 @@ +<?xml version="1.0"?> +<?xml-stylesheet type="text/css" href="chrome://global/skin"?> +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=667388 +--> +<window title="Mozilla Bug 667388" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> + + <!-- test code goes here --> + <script type="application/javascript"> + <![CDATA[ + + // Setup. + const Cu = Components.utils; + SimpleTest.waitForExplicitFinish(); + window.testObject = { myNumber: 42, + myDomain: window.location.domain }; + + + // Wait for both frames to load before proceeding. + var framesLoaded = [null, false, false, false]; + function onFrameLoaded(id) { + + // Mark this frame as loaded. + framesLoaded[id] = true; + + // Allow it to call various helpers. + window.frames[id].wrappedJSObject.is = is; + window.frames[id].wrappedJSObject.ok = ok; + window.frames[id].wrappedJSObject.info = info; + + // If all the frames are loaded, start the test. + if (framesLoaded[1] && framesLoaded[2] && framesLoaded[3]) + startTest(); + } + + function reject(e) { + ok(false, "Rejected Promise: " + e); + SimpleTest.finish(); + } + + function startTest() { + + runChromeContentTest(window.frames[1]).then( + runContentContentTest.bind(null, window.frames[1], window.frames[2], + true, "Should be able to clone same-origin"), reject).then( + runContentContentTest.bind(null, window.frames[2], window.frames[3], + false, "Should not be able to clone cross-origin"), reject).then(function() { + // Colaborate with document.domain, then try again. + frames[2].document.domain = 'example.org'; + frames[3].document.domain = 'example.org'; + return runContentContentTest(window.frames[2], window.frames[3], + true, "Should be able to clone cross-origin with document.domain") + }, reject).then(SimpleTest.finish.bind(SimpleTest), reject); + } + + // Tests cloning between chrome and content. + function runChromeContentTest(contentWin) { + + // We should be able to clone a content object. + tryToClone(contentWin.wrappedJSObject.testObject, + true, + "Chrome should be able to clone content object"); + + return Promise.resolve(); + } + + // Test cloning between content and content. + // + // Note - the way we do this is kind of sketchy. Because we're grabbing the + // test object from win1 by waiving Xray (via .wrappedJSObject), the object + // we're passing from win1 to win2 is actually the waived object (which has + // a distinct identity in the compartment of win2). So this means that we're + // actually giving win2 Xray waivers to win1! This doesn't affect things as + // long as the security wrappers check documentDomainMakesSameOrigin directly + // for the puncture case rather than checking IsTransparent(), but it still + // gives rise to a situation that wouldn't really happen in practice. + function runContentContentTest(win1, win2, shouldSucceed, msg) { + + var p = win1.wrappedJSObject.tryToClone(win2.wrappedJSObject.testObject, + shouldSucceed, msg); + if (!shouldSucceed) + return; + return new Promise(function(resolve) { + p.then(function(cloneResult) { + is(Cu.waiveXrays(cloneResult).toSource(), win2.wrappedJSObject.testObject.toSource(), + "Clone should create an identical object"); + resolve(); + }); + }); + } + + function tryToClone(obj, shouldSucceed, message) { + var success = false; + var sink = window.frames[0]; + try { sink.postMessage(obj, '*'); success = true; } + catch (e) { message = message + ' (threw: ' + e.message + ')'; } + is(success, shouldSucceed, message); + } + + ]]> + </script> + + <!-- test results are displayed in the html:body --> + <body xmlns="http://www.w3.org/1999/xhtml"> + <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=667388" + target="_blank">Mozilla Bug 667388</a> + <iframe id="sink" /> + <!-- The first two are same-origin, the third is not. --> + <iframe id="frame1" onload="onFrameLoaded(1);" src="http://test1.example.org/tests/dom/tests/mochitest/general/file_clonewrapper.html" /> + <iframe id="frame2" onload="onFrameLoaded(2);" src="http://test1.example.org/tests/dom/tests/mochitest/general/file_clonewrapper.html" /> + <iframe id="frame3" onload="onFrameLoaded(3);" src="http://test2.example.org/tests/dom/tests/mochitest/general/file_clonewrapper.html" /> + </body> + +</window> diff --git a/dom/tests/mochitest/chrome/test_cyclecollector.xul b/dom/tests/mochitest/chrome/test_cyclecollector.xul new file mode 100644 index 000000000..28bb5e7a9 --- /dev/null +++ b/dom/tests/mochitest/chrome/test_cyclecollector.xul @@ -0,0 +1,55 @@ +<?xml version="1.0"?> +<?xml-stylesheet type="text/css" href="chrome://global/skin"?> +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id= +--> +<window title="Mozilla Bug " + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> + + <!-- test results are displayed in the html:body --> + <body xmlns="http://www.w3.org/1999/xhtml"> + <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=" + target="_blank">Mozilla Bug </a> + </body> + + <!-- test code goes here --> + <script type="application/javascript"> + <![CDATA[ + /** Test for Bug **/ + let Ci = Components.interfaces; + var obs = Components.classes["@mozilla.org/observer-service;1"] + .getService(Ci.nsIObserverService); + var didCall = false; + var observer = { + QueryInterface: function QueryInterface(aIID) { + if (aIID.equals(Ci.nsIObserver) || + aIID.equals(Ci.nsISupports)) + return this; + throw Components.results.NS_NOINTERFACE; + }, + observe: function(subject, topic, data) { + obs.removeObserver(observer, "cycle-collector-begin"); + observer = null; + didCall = true; + } + }; + + // Start an incremental GC, to make sure that calling ccSlice + // when an IGC is running finishes the GC. + SpecialPowers.Cu.getJSTestingFunctions().gcslice(1); + + // Make sure that we call the observer even if we're in the middle + // of an ICC when we add the observer. See bug 981033. + SpecialPowers.finishCC(); + SpecialPowers.ccSlice(1); + + obs.addObserver(observer, "cycle-collector-begin", false); + + SpecialPowers.DOMWindowUtils.cycleCollect(); + + ok(didCall, "Observer should have been called!"); + ]]> + </script> +</window> diff --git a/dom/tests/mochitest/chrome/test_docshell_swap.xul b/dom/tests/mochitest/chrome/test_docshell_swap.xul new file mode 100644 index 000000000..b80e402cd --- /dev/null +++ b/dom/tests/mochitest/chrome/test_docshell_swap.xul @@ -0,0 +1,74 @@ +<?xml version="1.0"?> +<?xml-stylesheet type="text/css" href="chrome://global/skin"?> +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> +<window title="Docshell swap test" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> + + <!-- test results are displayed in the html:body --> + <body xmlns="http://www.w3.org/1999/xhtml"> + + </body> + + <!-- test code goes here --> + <script type="application/javascript"> + <![CDATA[ + + SimpleTest.waitForExplicitFinish(); + + // Create two identical windows, each with a <browser> element. + let win1 = window.openDialog("window_docshell_swap.xul", "_blank","chrome,width=300,height=200"); + let win2 = window.openDialog("window_docshell_swap.xul", "_blank","chrome,width=300,height=200"); + + let loadCount = 0; + function loadHandler() { + loadCount++; + if (loadCount < 2) + return; + + let browser1 = win1.document.getElementById("browser"); + let browser2 = win2.document.getElementById("browser"); + + let flo1 = browser1.QueryInterface(Components.interfaces.nsIFrameLoaderOwner); + let flo2 = browser2.QueryInterface(Components.interfaces.nsIFrameLoaderOwner); + + let pongCount = 0; + + function gotPong(target_ok) { + pongCount++; + ok(target_ok, "message went to correct target"); + if (pongCount == 1) { + win1.close(); + win2.close(); + SimpleTest.finish(); + } + } + + let mm1 = flo1.frameLoader.messageManager; + let mm2 = flo2.frameLoader.messageManager; + + // Swap docshells. Everything should be identical to before, since there was nothing to + // distinguish these docshells. + flo1.swapFrameLoaders(flo2); + + // mm1 shouldn't change here, but we update it in case it does due to a bug. + mm1 = flo1.frameLoader.messageManager; + + // Load ping-pong code into first window. + mm1.loadFrameScript("data:,addMessageListener('ping', () => sendAsyncMessage('pong'));", false); + + // A pong message received in win1 means success. + win1.messageManager.addMessageListener("pong", () => { gotPong(true); }); + + // A pong message received in win2 means failure! + win2.messageManager.addMessageListener("pong", () => { gotPong(false); }); + + // Send the ping to win1. + mm1.sendAsyncMessage("ping"); + } + + win1.addEventListener("load", loadHandler, false); + win2.addEventListener("load", loadHandler, false); + ]]> + </script> +</window> diff --git a/dom/tests/mochitest/chrome/test_focus.xul b/dom/tests/mochitest/chrome/test_focus.xul new file mode 100644 index 000000000..14fecb9c4 --- /dev/null +++ b/dom/tests/mochitest/chrome/test_focus.xul @@ -0,0 +1,33 @@ +<?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"?> + +<window title="Focus Tests" + onload="setTimeout(runTest, 0);" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + + <script type="application/javascript" + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> + +<script> +if (navigator.platform.startsWith("Win")) { + SimpleTest.expectAssertions(0, 1); +} + +SimpleTest.waitForExplicitFinish(); +function runTest() +{ + window.open("window_focus.xul", "_blank", "chrome,width=600,height=550"); +} +</script> + +<body xmlns="http://www.w3.org/1999/xhtml"> +<p id="display"> +</p> +<div id="content" style="display: none"> +</div> +<pre id="test"> +</pre> +</body> + +</window> diff --git a/dom/tests/mochitest/chrome/test_focus_docnav.xul b/dom/tests/mochitest/chrome/test_focus_docnav.xul new file mode 100644 index 000000000..48ce66fac --- /dev/null +++ b/dom/tests/mochitest/chrome/test_focus_docnav.xul @@ -0,0 +1,28 @@ +<?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"?> + +<window onload="runTest();" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + + <script type="application/javascript" + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> + +<script> +SimpleTest.waitForExplicitFinish(); +function runTest() +{ + window.open("window_focus_docnav.xul", "_blank", "chrome,width=600,height=550"); +} +</script> + +<body xmlns="http://www.w3.org/1999/xhtml"> +<p id="display"> +</p> +<div id="content" style="display: none"> +</div> +<pre id="test"> +</pre> +</body> + +</window> diff --git a/dom/tests/mochitest/chrome/test_focus_switchbinding.xul b/dom/tests/mochitest/chrome/test_focus_switchbinding.xul new file mode 100644 index 000000000..2f3e0c944 --- /dev/null +++ b/dom/tests/mochitest/chrome/test_focus_switchbinding.xul @@ -0,0 +1,57 @@ +<?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"?> + +<window title="Focus Switch Binding Test" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + + <script type="application/javascript" + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> + +<script> +SimpleTest.waitForExplicitFinish(); + +function switchBinding() +{ + $("box").style.MozBinding = "url(#second)"; +} +</script> + +<xbl:bindings xmlns:xbl="http://www.mozilla.org/xbl" + xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + <xbl:binding id="first"> + <xbl:content> + <xul:button label="First"/> + </xbl:content> + <xbl:implementation> + <xbl:constructor> + document.getAnonymousNodes(this)[0].focus(); + setTimeout(switchBinding, 0); + </xbl:constructor> + </xbl:implementation> + </xbl:binding> + <xbl:binding id="second"> + <xbl:content> + <xul:button label="Second"/> + </xbl:content> + <xbl:implementation> + <xbl:constructor> + $("after").focus(); + </xbl:constructor> + </xbl:implementation> + </xbl:binding> +</xbl:bindings> + +<box id="box" style="-moz-binding: url(#first)"/> +<button id="after" label="After" onfocus="is(document.activeElement, $('after'), 'focus set'); SimpleTest.finish()"/> + +<body xmlns="http://www.w3.org/1999/xhtml"> +<p id="display"> +</p> +<div id="content" style="display: none"> +</div> +<pre id="test"> +</pre> +</body> + +</window> diff --git a/dom/tests/mochitest/chrome/test_focused_link_scroll.xul b/dom/tests/mochitest/chrome/test_focused_link_scroll.xul new file mode 100644 index 000000000..1621eef83 --- /dev/null +++ b/dom/tests/mochitest/chrome/test_focused_link_scroll.xul @@ -0,0 +1,48 @@ +<?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"?> + +<window title="Focus Scroll Tests" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + + <script type="application/javascript" + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> + <script type="application/javascript" + src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/> + +<body xmlns="http://www.w3.org/1999/xhtml"> +<div id="div" style="width:500px;height:48px;overflow:auto;font-size:16px;line-height:16px;"> +aaaaaaaaa<br/>bbbbbbbb<br/> +<a href="about:blank;" id="a">ccccccccc<br/>ddddddddd</a> +</div> +<p id="display"> +</p> +<div id="content" style="display: none"> +</div> +<pre id="test"> +</pre> +</body> + +<script> + +SimpleTest.waitForExplicitFinish(); + +function runTest() +{ + var fm = Components.classes["@mozilla.org/focus-manager;1"]. + getService(Components.interfaces.nsIFocusManager); + var div = document.getElementById('div'); + var a = document.getElementById('a'); + synthesizeMouse(a, 4, 4, { type: "mousedown" }, window); + is(fm.focusedElement, a, + "The anchor element isn't set focus by the mouse down event"); + is(div.scrollTop, 0, + "The div element was scrolled by the mouse down event"); + SimpleTest.finish(); +} + +SimpleTest.waitForFocus(runTest); + +</script> + +</window> diff --git a/dom/tests/mochitest/chrome/test_fullscreen.xul b/dom/tests/mochitest/chrome/test_fullscreen.xul new file mode 100644 index 000000000..fcc577f6d --- /dev/null +++ b/dom/tests/mochitest/chrome/test_fullscreen.xul @@ -0,0 +1,37 @@ +<?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 for fullscreen sizemode in chrome + --> +<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" + sizemode="fullscreen"> + + <script type="application/javascript" + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + +<script> +SimpleTest.waitForExplicitFinish(); + +newwindow = window.open("fullscreen.xul", "_blank","chrome,resizable=yes"); + +function done() +{ + // because we are cancelling the fullscreen event, it + // takes a bit for the fullScreen property to be set + setTimeout("complete()", 0); +} + +function complete() +{ + ok(newwindow.fullScreen, "window.fullScreen is true."); + newwindow.close(); + SimpleTest.finish(); +} + +</script> + + +<body xmlns="http://www.w3.org/1999/xhtml" style="height: 300px; overflow: auto;"/> + +</window> diff --git a/dom/tests/mochitest/chrome/test_geolocation.xul b/dom/tests/mochitest/chrome/test_geolocation.xul new file mode 100644 index 000000000..ba01149e5 --- /dev/null +++ b/dom/tests/mochitest/chrome/test_geolocation.xul @@ -0,0 +1,35 @@ +<?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 for Geolocation in chrome + --> +<window id="sample-window" width="400" height="400" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + <script type="application/javascript" + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + +<script> +SimpleTest.waitForExplicitFinish(); + +var Ci = Components.interfaces; +var Cc = Components.classes; + +var geolocation = Cc["@mozilla.org/geolocation;1"].getService(Ci.nsISupports); +geolocation.getCurrentPosition(done, error); + +function error(error) +{ + ok(0, "error occured trying to get geolocation from chrome"); + SimpleTest.finish(); +} +function done(position) +{ + ok(position, "geolocation was found from chrome"); + SimpleTest.finish(); +} +</script> + +<body xmlns="http://www.w3.org/1999/xhtml" style="height: 300px; overflow: auto;"/> + +</window> diff --git a/dom/tests/mochitest/chrome/test_indexedSetter.html b/dom/tests/mochitest/chrome/test_indexedSetter.html new file mode 100644 index 000000000..2a90f4548 --- /dev/null +++ b/dom/tests/mochitest/chrome/test_indexedSetter.html @@ -0,0 +1,38 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=715156 +--> +<head> + <meta charset="utf-8"> + <title>Test for Bug 715156</title> + <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> + <script type="application/javascript"> + + /** Test for Bug 715156 **/ + + function runTests() { + var doc = document.getElementById("testFrame").contentDocument; + var options = doc.createElement("select").options; + ok(Components.utils.isXrayWrapper(options), "should be an Xray wrapper"); + var option = doc.createElement("option"); + options[4] = option; + is(options.length, 5, "setting an indexed property through an Xray wrapper should work") + is(options[4], option, "setting an indexed property through an Xray wrapper should work") + SimpleTest.finish(); + } + + SimpleTest.waitForExplicitFinish(); + addLoadEvent(runTests); + + </script> +</head> +<body> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=715156">Mozilla Bug 715156</a> +<p id="display"></p> +<iframe id="testFrame"></iframe> +<pre id="test"> +</pre> +</body> +</html> diff --git a/dom/tests/mochitest/chrome/test_moving_nodeList.xul b/dom/tests/mochitest/chrome/test_moving_nodeList.xul new file mode 100644 index 000000000..9762cedda --- /dev/null +++ b/dom/tests/mochitest/chrome/test_moving_nodeList.xul @@ -0,0 +1,45 @@ +<?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"?> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=684115 +--> +<window title="Mozilla Bug 684115" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + <script type="application/javascript" + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + + <!-- test results are displayed in the html:body --> + <body xmlns="http://www.w3.org/1999/xhtml"> + <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=654370" + target="_blank">Mozilla Bug 684115</a> + </body> + + <!-- test code goes here --> + <script type="application/javascript"><![CDATA[ + SimpleTest.waitForExplicitFinish(); + + var firstWindow, secondWindow; + function iframe_loaded() { + if (!firstWindow || !secondWindow) + return; + var nodeList = firstWindow.document.childNodes; + ok(!("expando" in nodeList), "shouldn't be able to see expandos on the NodeList"); + nodeList = firstWindow.wrappedJSObject.getNodeList(); + ok(("expando" in nodeList), "should be able to see expandos on the NodeList"); + options = firstWindow.wrappedJSObject.getOptions(); + is(options.selectedIndex, -1, "can access selectedIndex in chrome"); + secondWindow.wrappedJSObject.tryToUseNodeList(nodeList, ok); + nodeList = document.childNodes; + secondWindow.wrappedJSObject.tryToUseNodeList(nodeList, ok); + SimpleTest.finish(); + } + + ]]></script> + + <iframe id="one" src="http://mochi.test:8888/tests/dom/tests/mochitest/general/file_moving_nodeList.html" + onload="firstWindow = this.contentWindow; iframe_loaded()" /> + <iframe id="two" src="http://example.org/tests/dom/tests/mochitest/general/file_moving_nodeList.html" + onload="secondWindow = this.contentWindow; iframe_loaded()" /> +</window> diff --git a/dom/tests/mochitest/chrome/test_moving_xhr.xul b/dom/tests/mochitest/chrome/test_moving_xhr.xul new file mode 100644 index 000000000..63946342b --- /dev/null +++ b/dom/tests/mochitest/chrome/test_moving_xhr.xul @@ -0,0 +1,41 @@ +<?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"?> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=684115 +--> +<window title="Mozilla Bug 684115" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + <script type="application/javascript" + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + + <!-- test results are displayed in the html:body --> + <body xmlns="http://www.w3.org/1999/xhtml"> + <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=654370" + target="_blank">Mozilla Bug 684115</a> + </body> + + <!-- test code goes here --> + <script type="application/javascript"><![CDATA[ + SimpleTest.waitForExplicitFinish(); + + var firstWindow, secondWindow; + function iframe_loaded() { + if (!firstWindow || !secondWindow) + return; + var xhr = firstWindow.wrappedJSObject.createXHR(); + ok(("expando" in xhr), "should be able to see expandos on the XHR"); + is(xhr.readyState, XMLHttpRequest.UNSENT, "can access readyState in chrome"); + secondWindow.wrappedJSObject.tryToUseXHR(xhr, ok); + secondWindow.wrappedJSObject.tryToUseXHR(new XMLHttpRequest(), ok); + SimpleTest.finish(); + } + + ]]></script> + + <iframe id="one" src="http://mochi.test:8888/tests/dom/tests/mochitest/general/file_moving_xhr.html" + onload="firstWindow = this.contentWindow; iframe_loaded()" /> + <iframe id="two" src="http://example.org/tests/dom/tests/mochitest/general/file_moving_xhr.html" + onload="secondWindow = this.contentWindow; iframe_loaded()" /> +</window> diff --git a/dom/tests/mochitest/chrome/test_nodesFromRect.html b/dom/tests/mochitest/chrome/test_nodesFromRect.html new file mode 100644 index 000000000..50910d64a --- /dev/null +++ b/dom/tests/mochitest/chrome/test_nodesFromRect.html @@ -0,0 +1,21 @@ +<!DOCTYPE HTML>
+<html>
+<head>
+ <title>nsIDOMWindowUtils::nodesFromRect test - bug 489127</title>
+ <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
+<script type="application/javascript">
+ SimpleTest.waitForExplicitFinish();
+ function done() {
+ testwindow.close();
+ SimpleTest.finish();
+ }
+ var testwindow = window.open("489127.html", '_new', 'width=600,height=400');
+</script>
+</head>
+<body>
+<p id="display"></p>
+<div id="content" style="display: none">
+</body>
+</html>
+
diff --git a/dom/tests/mochitest/chrome/test_parsingMode.html b/dom/tests/mochitest/chrome/test_parsingMode.html new file mode 100644 index 000000000..011bded1d --- /dev/null +++ b/dom/tests/mochitest/chrome/test_parsingMode.html @@ -0,0 +1,67 @@ +<!DOCTYPE HTML> +<html> +<head> + <title>CSSStyleSheet parsingMode test - bug 1230491</title> + <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> +<script type="application/javascript"> + SimpleTest.waitForExplicitFinish(); + function run() { + const Cc = Components.classes; + const Ci = Components.interfaces; + + const sss = Cc["@mozilla.org/content/style-sheet-service;1"] + .getService(Ci.nsIStyleSheetService); + const domutils = Cc["@mozilla.org/inspector/dom-utils;1"] + .getService(Ci.inIDOMUtils); + const utils = window.QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIDOMWindowUtils); + + const userUrl = encodeURI("data:text/css,body { color: seagreen; }"); + utils.loadSheetUsingURIString(userUrl, sss.USER_SHEET); + + const agentUrl = encodeURI("data:text/css,body { color: tomato; }"); + utils.loadSheetUsingURIString(agentUrl, sss.AGENT_SHEET); + + const authorUrl = "chrome://mochikit/content/tests/SimpleTest/test.css"; + + let results = []; + for (let sheet of domutils.getAllStyleSheets(document)) { + if (sheet.href === agentUrl) { + is(sheet.parsingMode, "agent", "agent sheet has expected mode"); + results[sss.AGENT_SHEET] = 1; + } else if (sheet.href === userUrl) { + is(sheet.parsingMode, "user", "user sheet has expected mode"); + results[sss.USER_SHEET] = 1; + } else if (sheet.href === authorUrl) { + is(sheet.parsingMode, "author", + "author sheet has expected mode"); + results[sss.AUTHOR_SHEET] = 1; + } else if (sheet.href === "about:PreferenceStyleSheet") { + is(sheet.parsingMode, "agent", + "about:PreferenceStyleSheet has agent mode"); + continue; + } else { + // Ignore sheets we don't care about. + continue; + } + + // Check that re-parsing preserves the mode. + let mode = sheet.parsingMode; + domutils.parseStyleSheet(sheet, "body { color: chartreuse; }"); + is(sheet.parsingMode, mode, + "check that re-parsing preserved mode " + mode); + } + + ok(results[sss.AGENT_SHEET] && results[sss.USER_SHEET] && + results[sss.AUTHOR_SHEET], + "all sheets seen"); + + SimpleTest.finish(); + } +</script> +</head> +<body onload="run()"> + <div> What? </div> +</body> +</html> diff --git a/dom/tests/mochitest/chrome/test_popup_blocker_chrome.xul b/dom/tests/mochitest/chrome/test_popup_blocker_chrome.xul new file mode 100644 index 000000000..d2e421651 --- /dev/null +++ b/dom/tests/mochitest/chrome/test_popup_blocker_chrome.xul @@ -0,0 +1,54 @@ +<?xml version="1.0"?> +<?xml-stylesheet type="text/css" href="chrome://global/skin"?> +<?xml-stylesheet type="text/css" href="/tests/SimpleTest/test.css"?> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=662519 +--> +<window title="Mozilla Bug 662519" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + + <!-- test results are displayed in the html:body --> + <body xmlns="http://www.w3.org/1999/xhtml"> + <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=662519" + target="_blank">Mozilla Bug 662519</a> + </body> + + <!-- test code goes here --> + <script type="application/javascript"> + <![CDATA[ + + /** Test for Bug 662519 **/ + + SimpleTest.waitForExplicitFinish(); + + // We have to enable dom.disable_open_during_load which is disabled + // by the test harness. + let prefs = Components.classes["@mozilla.org/preferences-service;1"] + .getService(Components.interfaces.nsIPrefBranch); + var gLastDomLoadValue = prefs.getBoolPref("dom.disable_open_during_load"); + prefs.setBoolPref("dom.disable_open_during_load", true); + + let w = window.open("data:text/html,foobar", "", "width=200,height=200"); + ok(w, "The window object shouldn't be null"); + + SimpleTest.waitForFocus(function() { + w.close(); + ok(true, "The popup appeared"); + + SimpleTest.waitForFocus(function() { + let w = window.open("data:text/html,foobar", "", "width=200,height=200"); + ok(w, "The window object shouldn't be null"); + + SimpleTest.waitForFocus(function() { + w.close(); + + ok(true, "The popup appeared"); + prefs.setBoolPref("dom.disable_open_during_load", gLastDomLoadValue); + SimpleTest.finish(); + }, w, false); + }); + }, w, false); + ]]> + </script> +</window> diff --git a/dom/tests/mochitest/chrome/test_queryCaretRect.html b/dom/tests/mochitest/chrome/test_queryCaretRect.html new file mode 100644 index 000000000..ef7165077 --- /dev/null +++ b/dom/tests/mochitest/chrome/test_queryCaretRect.html @@ -0,0 +1,22 @@ +<!DOCTYPE HTML> +<html> +<head> + <title>nsIDOMWindowUtils::sendQueryContentEvent w/QUERY_CARET_RECT test</title> + <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> +<script type="application/javascript"> + SimpleTest.waitForExplicitFinish(); + function done() { + testwindow.close(); + SimpleTest.finish(); + } + var isWindows = ("@mozilla.org/windows-registry-key;1" in Components.classes); + var testwindow = window.open("queryCaretRect" + (isWindows ? "Win" : "Unix") + ".html", + "_new", "width=800,height=800"); +</script> +</head> +<body> +<p id="display"></p> +<div id="content" style="display: none"> +</body> +</html> diff --git a/dom/tests/mochitest/chrome/test_resize_move_windows.xul b/dom/tests/mochitest/chrome/test_resize_move_windows.xul new file mode 100644 index 000000000..b5102a79a --- /dev/null +++ b/dom/tests/mochitest/chrome/test_resize_move_windows.xul @@ -0,0 +1,282 @@ +<?xml version="1.0"?> +<?xml-stylesheet type="text/css" href="chrome://global/skin"?> +<?xml-stylesheet type="text/css" href="/tests/SimpleTest/test.css"?> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=565541 +--> +<window title="Mozilla Bug 565541" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + + <!-- test results are displayed in the html:body --> + <body xmlns="http://www.w3.org/1999/xhtml"> + <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=565541" + target="_blank">Mozilla Bug 565541</a> + </body> + + <!-- test code goes here --> + <script type="application/javascript"> + <![CDATA[ + + /** Test for Bug 565541 **/ + var previousX, previousY, previousWidth, previousHeight; + + function backValues() + { + previousX = window.top.screenX; + previousY = window.top.screenY; + previousWidth = window.top.innerWidth; + previousHeight = window.top.innerHeight; + } + + function restoreValues() + { + window.top.screenX = previousX; + window.top.screenY = previousY; + window.top.innerWidth = previousWidth; + window.top.innerHeight = previousHeight; + } + + function getNewWidth(aWindow) + { + return (aWindow.innerWidth > (screen.width / 2)) ? 100 : screen.width; + } + + function getNewHeight(aWindow) + { + return (aWindow.innerHeight > (screen.height / 2)) ? 100 : screen.height; + } + + function getNewX(aWindow) + { + return (aWindow.screenX > ((screen.width - aWindow.outerWidth) / 2)) + ? 0 : screen.width - aWindow.outerWidth; + } + + function getNewY(aWindow) + { + return (aWindow.screenY > ((screen.height - aWindow.outerHeight) / 2)) + ? 0 : screen.height - aWindow.outerHeight; + } + + /** + * hitEventLoop is called when we want to check something but we can't rely on + * an event or a specific number of event loop hiting. + * This method can be called by specifying a condition, a test (using SimpleTest + * API), how many times the event loop has to be hitten and what to call next. + * If times < 0, the event loop will be hitten as long as the condition isn't + * true or the test doesn't time out. + */ + function hitEventLoop(condition, test, times, next) { + if (condition() || times == 0) { + test(); + next(); + return; + } + + setTimeout(hitEventLoop, 0, condition, test, times - 1, next); + } + + function checkChangeIsEnabled(aWindow, aNext) + { + // Something should happen. We are not going to go to the next test until + // it does. + var hits = -1; + + var prevWidth; + var prevHeight; + + var prevX; + var prevY; + + var oWidth; + var oHeight; + + function sizeChangeCondition() { + return aWindow.innerWidth != prevWidth && aWindow.innerHeight != prevHeight; + } + + function sizeChangeTest() { + isnot(aWindow.innerWidth, prevWidth, "Window width should have changed"); + isnot(aWindow.innerHeight, prevHeight, "Window height should have changed"); + + prevWidth = aWindow.innerWidth; + prevHeight = aWindow.innerHeight; + } + + function posChangeCondition() { + // With GTK, sometimes, only one dimension changes. + if (navigator.platform.indexOf('Linux') != -1) { + return aWindow.screenX != prevX || aWindow.screenY != prevY; + } + return aWindow.screenX != prevX && aWindow.screenY != prevY; + } + + function posChangeConditionIgnoreLinux() { + if (posChangeCondition()) { + return true; + } + + if (navigator.platform.indexOf('Linux') != -1) { + return true; + } + } + + function posChangeTest() { + // With GTK, sometimes, only one dimension changes. + if (navigator.platform.indexOf('Linux') != -1) { + // With GTK, sometimes, aWindow.screenX changes during two calls. + // So we call it once and save the returned value. + var x = aWindow.screenX; + var y = aWindow.screenY; + if (x != prevX) { + isnot(x, prevX, "Window x position should have changed"); + } + if (y != prevY) { + isnot(y, prevY, "Window y position should have changed"); + } + } else { + isnot(aWindow.screenX, prevX, "Window x position should have changed"); + isnot(aWindow.screenY, prevY, "Window y position should have changed"); + } + + prevX = aWindow.screenX; + prevY = aWindow.screenY; + } + + function outerChangeCondition() { + return aWindow.outerWidth != oWidth && aWindow.outerHeight != oHeight; + } + + function outerChangeTest() { + isnot(aWindow.outerWidth, oWidth, "Window outerWidth should have changed"); + isnot(aWindow.outerHeight, oHeight, "Window outerHeight should have changed"); + + aWindow.outerWidth = oWidth; + aWindow.outerHeight = oHeight; + } + + /** + * Size checks. + */ + prevWidth = aWindow.innerWidth; + prevHeight = aWindow.innerHeight; + + aWindow.innerWidth = getNewWidth(aWindow); + aWindow.innerHeight = getNewHeight(aWindow); + + hitEventLoop(sizeChangeCondition, sizeChangeTest, hits, function () { + aWindow.resizeTo(getNewWidth(aWindow), getNewHeight(aWindow)); + + hitEventLoop(sizeChangeCondition, sizeChangeTest, hits, function () { + aWindow.resizeBy(getNewWidth(aWindow) - aWindow.innerWidth, + getNewHeight(aWindow) - aWindow.innerHeight); + + hitEventLoop(sizeChangeCondition, sizeChangeTest, hits, function () { + prevWidth = aWindow.innerWidth = getNewWidth(aWindow); + prevHeight = aWindow.innerHeight = getNewHeight(aWindow); + aWindow.sizeToContent(); + + hitEventLoop(sizeChangeCondition, sizeChangeTest, hits, function () { + /** + * Position checks. + */ + prevX = aWindow.screenX; + prevY = aWindow.screenY; + + aWindow.screenX = getNewX(aWindow); + aWindow.screenY = getNewY(aWindow); + + hitEventLoop(posChangeCondition, posChangeTest, hits, function () { + aWindow.moveTo(getNewX(aWindow), getNewY(aWindow)); + + hitEventLoop(posChangeCondition, posChangeTest, hits, function () { + aWindow.moveBy(getNewX(aWindow) - aWindow.screenX, + getNewY(aWindow) - aWindow.screenY); + + hitEventLoop(posChangeConditionIgnoreLinux, posChangeTest, hits, function () { + /** + * Outer width/height checks. + */ + oWidth = aWindow.outerWidth; + oHeight = aWindow.outerHeight; + + aWindow.outerWidth = oWidth * 2; + aWindow.outerHeight = oHeight * 2; + + hitEventLoop(outerChangeCondition, outerChangeTest, hits, aNext); + }); + }); + }); + }); + }); + }); + }); + } + + SimpleTest.waitForExplicitFinish(); + SimpleTest.waitForFocus(function() { + if (screen.width <= 200 || screen.height <= 200) { + todo(false, "The screen is too small to run this test."); + SimpleTest.finish(); + } + + backValues(); + + // We are in a chrome context, we can change the size and position. + checkChangeIsEnabled(window.top, function() { + // We create a window and check that the size and position can be set with + // window.open parameters and can be changed by the created window. + var w = window.open("data:text/html,<script>" + + "function check(next) {" + + " var is_range = function(aTest, aValue, aRange, aMsg) {" + + " ok(aTest < aValue + aRange && aTest > aValue - aRange, aMsg);" + + " };" + + " is_range(window.innerWidth, 170, 5, 'parameter width should be taken into account');" + + " is_range(window.innerHeight, 170, 5, 'parameter height should be taken into account');" + + " is_range(window.screenX, 25, 5, 'parameter screenX should be taken into account');" + + " is_range(window.screenY, 25, 5, 'parameter screenY should be taken into account');" + + " checkChangeIsEnabled(window, next);" + + "} <\/script>", '', + 'width=170,height=170,screenX=25,screenY=25'); + + SimpleTest.waitForFocus(function() { + // This test relies on passing cross-origin windows to a chrome function, + // which is generally forbidden if we don't twiddle the knob below. + Components.utils.forcePermissiveCOWs(); + w.wrappedJSObject.ok = SimpleTest.ok; + w.wrappedJSObject.checkChangeIsEnabled = window.checkChangeIsEnabled; + w.wrappedJSObject.check(function() { + // The current window can change the size and position of the created one. + checkChangeIsEnabled(w, function() { + w.close(); + + // If we call window.open with an empty string as a third parameter, + // by default, it will create a new tab instead of a new window. + // In a chrome context, the size and position can change. + w = window.open("data:text/html,<script>" + + "function check(next) {" + + " checkChangeIsEnabled(window, next);" + + "} <\/script>", '', ''); + + SimpleTest.waitForFocus(function() { + w.wrappedJSObject.checkChangeIsEnabled = window.checkChangeIsEnabled; + w.wrappedJSObject.check(function() { + // The current window can change the size and position of the new tab. + // Because we are in a chrome context. + checkChangeIsEnabled(w, function() { + w.close(); + + restoreValues(); + SimpleTest.finish(); + }); + }); + }, w, false); + }); + }); + }, w, false); + }); + }); + ]]> + </script> +</window> diff --git a/dom/tests/mochitest/chrome/test_sandbox_bindings.xul b/dom/tests/mochitest/chrome/test_sandbox_bindings.xul new file mode 100644 index 000000000..eaf940010 --- /dev/null +++ b/dom/tests/mochitest/chrome/test_sandbox_bindings.xul @@ -0,0 +1,318 @@ +<?xml version="1.0"?> +<?xml-stylesheet type="text/css" href="chrome://global/skin"?> +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=741267 +--> +<window title="Mozilla Bug 741267" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> + <script type="application/javascript"> + + +</script> + <iframe id="t"></iframe> + + <!-- test results are displayed in the html:body --> + <body xmlns="http://www.w3.org/1999/xhtml"> + <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=741267" + target="_blank">Mozilla Bug 741267</a> + </body> + + <!-- test code goes here --> + <script type="application/javascript"> + <![CDATA[ + + /** Test for Bug 741267 **/ + const Cu = Components.utils; + function isXrayWrapper(x) { + return Components.utils.isXrayWrapper(x); + } + + function doTest() { + var win = $("t").contentWindow; + ok(isXrayWrapper(win), + "We want to be testing things with an Xray as sandboxPrototype here"); + + var sandbox = Components.utils.Sandbox(win, { sandboxPrototype: win }); + + is(sandbox._content, undefined, "_content does nothing over Xray"); + + try { + var css = Components.utils.evalInSandbox("CSSStyleDeclaration", sandbox); + is(String(css.prototype), "[object CSSStyleDeclarationPrototype]", + "'CSSStyleDeclaration.prototype' in a sandbox should return the CSSStyleDeclaration interface prototype object"); + } catch (e) { + ok(false, "'CSSStyleDeclaration' shouldn't throw in a sandbox"); + } + try { + var et = Components.utils.evalInSandbox("EventTarget", sandbox); + ok(et, "'EventTarget' in a sandbox should return the EventTarget interface object"); + ok(isXrayWrapper(et), "Getting an interface object on an Xray wrapper should return an Xray wrapper"); + } catch (e) { + ok(false, "'EventTarget' shouldn't throw in a sandbox"); + } + try { + var xhr = Components.utils.evalInSandbox("XMLHttpRequest.prototype", sandbox); + ok(xhr, "'XMLHttpRequest.prototype' in a sandbox should return the XMLHttpRequest interface prototype object"); + ok(isXrayWrapper(xhr), "Getting an interface prototype object on an Xray wrapper should return an Xray wrapper"); + ok(isXrayWrapper(xhr.constructor), "Getting the constructor property on an Xray wrapper of an interface prototype object should return an Xray wrapper"); + isnot(Object.getOwnPropertyDescriptor(xhr, "send"), undefined, + "We should claim to have a send() method"); + isnot(Object.keys(xhr).indexOf("responseType"), -1, + "We should claim to have a responseType property"); + isnot(Object.getOwnPropertyNames(xhr).indexOf("open"), -1, + "We should claim to have an open() method"); + isnot(Object.getOwnPropertyDescriptor(xhr, "constructor"), undefined, + "We should claim to have a 'constructor' property"); + } catch (e) { + ok(false, "'XMLHttpRequest.prototype' shouldn't throw in a sandbox"); + } + try { + var img = Components.utils.evalInSandbox("Image.prototype", sandbox); + ok(img, "'Image.prototype' in a sandbox should return the interface prototype object"); + ok(isXrayWrapper(img), "Getting an interface prototype object on an Xray wrapper should return an Xray wrapper"); + } catch (e) { + ok(false, "'Image.prototype' shouldn't throw in a sandbox"); + } + try { + var xhr = Components.utils.evalInSandbox("XMLHttpRequest", sandbox); + xhr.prototype = "notok"; + } finally { + isnot(xhr.prototype, "notok", "'XMLHttpRequest.prototype' should be readonly"); + } + var constructorWritable = false; + try { + var xhr = Components.utils.evalInSandbox("XMLHttpRequest.prototype", sandbox); + xhr.constructor = "ok"; + is(xhr.constructor, "ok", "'XMLHttpRequest.prototype.constructor' should be writeable"); + } catch (e) { + ok(false, "'XMLHttpRequest.prototype.constructor' should be writeable"); + } + try { + var xhr = Components.utils.evalInSandbox("XMLHttpRequest", sandbox); + is(String(xhr), String(XMLHttpRequest), "'XMLHttpRequest' in a sandbox should return the XMLHttpRequest interface object"); + ok(isXrayWrapper(xhr.prototype), "Getting the prototype property on an Xray wrapper of an interface object should return an Xray wrapper"); + isnot(Object.getOwnPropertyDescriptor(xhr, "UNSENT"), undefined, + "We should claim to have an UNSENT constant"); + isnot(Object.keys(xhr).indexOf("OPENED"), -1, + "We should claim to have an OPENED constant"); + isnot(Object.getOwnPropertyNames(xhr).indexOf("DONE"), -1, + "We should claim to have a DONE constant"); + isnot(Object.getOwnPropertyDescriptor(xhr, "prototype"), undefined, + "We should claim to have 'prototype' property"); + } catch (e) { + ok(false, "'XMLHttpRequest' shouldn't throw in a sandbox"); + } + try { + var xhr = Components.utils.evalInSandbox("new XMLHttpRequest()", sandbox); + is("" + xhr, new XMLHttpRequest() + "", "'new XMLHttpRequest()' in a sandbox should create an XMLHttpRequest object"); + } catch (e) { + ok(false, "'new XMLHttpRequest()' shouldn't throw in a sandbox (1)"); + } + try { + var xhr = Components.utils.evalInSandbox("XMLHttpRequest.toString = function () { return 'Failed'; }; XMLHttpRequest;", sandbox); + is(xhr.toString(), XMLHttpRequest + "", "XMLHttpRequest.toString in the sandbox should not override the native toString behaviour"); + } catch (e) { + ok(false, "'XMLHttpRequest' shouldn't throw in a sandbox"); + } + try { + var xhr = Components.utils.evalInSandbox("XMLHttpRequest.prototype.toString = function () { return 'Failed'; }; new XMLHttpRequest();", sandbox); + is(xhr.toString(), new XMLHttpRequest() + "", "XMLHttpRequest.prototype.toString in the sandbox should not override the native toString behaviour"); + } catch (e) { + ok(false, "'new XMLHttpRequest()' shouldn't throw in a sandbox (2)"); + } + + try { + // have to run this test before document.defaultView.XMLHttpRequest + // gets munged in the sandbox. + var proto = Components.utils.evalInSandbox("XMLHttpRequest.prototype", sandbox); + props = []; + for (var i in proto) { + props.push(i); + } + isnot(props.indexOf("dispatchEvent"), -1, + "'dispatchEvent' property should be enumerable on XMLHttpRequest.prototype"); + props = Object.getOwnPropertyNames(proto); + is(props.indexOf("dispatchEvent"), -1, + "'dispatchEvent' is not an own property on XMLHttpRequest.prototype; it's on EventTarget.prototype") + } catch (e) { + ok(false, "XMLHttpRequest.prototype manipulation via an Xray shouldn't throw" + e); + } + try { + Components.utils.evalInSandbox("XMLHttpRequest.prototype.a = 'expando a'", sandbox); + Components.utils.evalInSandbox("XMLHttpRequest.prototype.b = 'expando b'", sandbox); + Components.utils.evalInSandbox("XMLHttpRequest.prototype", sandbox).b = 'xrayexpando'; + var xhr = Components.utils.evalInSandbox("new XMLHttpRequest()", sandbox); + is(xhr.a, undefined, "'XMLHttpRequest()' in a sandbox should not have expandos from inside the sandbox"); + is(xhr.b, "xrayexpando", "'new XMLHttpRequest()' in a sandbox should have Xray expandos"); + } catch (e) { + ok(false, "'new XMLHttpRequest()' shouldn't throw in a sandbox"); + } + try { + Components.utils.evalInSandbox("document.defaultView.XMLHttpRequest = function() {};", sandbox); + var win = Components.utils.evalInSandbox("document.defaultView", sandbox); + var xhr = new win.XMLHttpRequest(); + is("" + xhr, new XMLHttpRequest() + "", "'new XMLHttpRequest()' in a sandbox should create an XMLHttpRequest object"); + } catch (e) { + ok(false, "'new XMLHttpRequest()' shouldn't throw in a sandbox"); + } + try { + var canvas = Components.utils.evalInSandbox("document.createElement('canvas').getContext('2d')", sandbox); + is(canvas.DRAWWINDOW_DRAW_CARET, CanvasRenderingContext2D.DRAWWINDOW_DRAW_CARET, "Constants should be defined on DOM objects in a sandbox"); + } catch (e) { + ok(false, "'document.createElement('canvas').getContext('2D')' shouldn't throw in a sandbox"); + } + try { + var classList = Components.utils.evalInSandbox("document.body.className = 'a b'; document.body.classList", sandbox); + is(classList.toString(), "a b", "Stringifier should be called"); + } catch (e) { + ok(false, "Stringifying shouldn't throw in a sandbox"); + } + try { + var ctx = Components.utils.evalInSandbox("var ctx = document.createElement('canvas').getContext('2d'); ctx.foopy = 5; ctx", sandbox); + ok(!("foopy" in ctx), "We should have an Xray here"); + var data = ctx.createImageData(1, 1); + for (var i = 0; i < data.data.length; ++i) { + // Watch out for premultiplied bits... just set all the alphas to 255 + if (i % 4 == 3) { + // Note - We need to waive Xrays here because indexed access on Typed + // Arrays is forbidden over Xrays for performance reasons. + Cu.waiveXrays(data.data)[i] = 255; + } else { + Cu.waiveXrays(data.data)[i] = i; + } + } + ctx.putImageData(data, 0, 0); + var data2 = ctx.getImageData(0, 0, 1, 1); + is(data2.data.length, data.data.length, "Lengths must match"); + for (i = 0; i < data.data.length; ++i) + is(Cu.waiveXrays(data.data)[i], Cu.waiveXrays(data2.data)[i], "Data at " + i + " should match"); + } catch (e) { + ok(false, "Imagedata manipulation via an Xray shouldn't throw " + e); + } + + try { + var list = Components.utils.evalInSandbox("document.getElementsByTagName('*')", sandbox); + props = []; + for (var i in list) { + props.push(i); + } + is(props.indexOf("constructor"), -1, + "'constructor' property should not be enumerable on list object"); + props = Object.getOwnPropertyNames(list); + is(props.indexOf("constructor"), -1, + "'constructor' property should not be an own property name on list object"); + } catch (e) { + ok(false, "NodeList.prototype manipulation via an Xray shouldn't throw" + e); + } + + try { + var proto = Components.utils.evalInSandbox("NodeList.prototype", sandbox); + props = []; + for (var i in proto) { + props.push(i); + } + is(props.indexOf("constructor"), -1, + "'constructor' property should not be enumerable on proto directly"); + props = Object.getOwnPropertyNames(proto); + isnot(props.indexOf("constructor"), -1, + "'constructor' property should be an own property name on proto"); + } catch (e) { + ok(false, "NodeList.prototype manipulation via an Xray shouldn't throw" + e); + } + + try { + var url = Components.utils.evalInSandbox("URL", sandbox); + for (var i in url) { + url[i]; + } + isnot(url.createObjectURL, undefined, "Should have a createObjectURL"); + ok(true, "We didn't crash!"); + } catch (e) { + ok(false, "URL interface object manipulation via an Xray shouldn't throw" + e); + } + + try { + url.revokeObjectURL(""); + } catch (e) { + // Just testing whether revokeObjectURL crashes us + } + ok(true, "We didn't crash!"); + + // And now tests that don't use a window-associated sandbox + sandbox = Components.utils.Sandbox(win.document.nodePrincipal, + { sandboxPrototype: win }); + try { + var ws = Components.utils.evalInSandbox('var ws = new WebSocket("ws://example.org"); ws', sandbox); + // Test that we actually got a WebSocket object, probably + ok("bufferedAmount" in ws, "What is this object?"); + } catch (e) { + ok(false, "Should be able to create a WebSocket in a sandbox " + e); + } + try { + var es = Components.utils.evalInSandbox('var es = new EventSource("about:blank"); es', sandbox); + // Test that we actually got a EventSource object, probably + is(es.url, "about:blank", "What is this object?"); + } catch (e) { + ok(false, "Should be able to create an EventSource in a sandbox " + e); + } + + try { + var nodeFilterIface = Components.utils.evalInSandbox( + 'NodeFilter.myExpando = "FAIL"; NodeFilter', sandbox); + is(nodeFilterIface.myExpando, undefined, + "Should have Xrays for callback interface objects"); + } catch (e) { + ok(false, "Should be able to return NodeFilter from a sandbox " + e); + } + + try { + var eventCtor = Components.utils.evalInSandbox("Event", sandbox); + var e = new eventCtor("test", { bubbles: true }); + is(e.bubbles, true, "Dictionary argument should work"); + } catch (e) { + ok(false, "Should be able to construct my event " + e); + } + + try { + var elem = Components.utils.evalInSandbox('document.createElement("p")', sandbox); + elem.expando = 5; + elem.expando = 7; + is(elem.expando, 7, "Should be able to set expandos on Xrays for DOM bindings"); + var doc = Components.utils.evalInSandbox('document', sandbox); + doc.expando = 5; + doc.expando = 7; + is(doc.expando, 7, "Should be able to set expandos on Xrays for DOM bindings with named properties"); + } catch (e) { + ok(false, "Setting expandos on Xrays shouldn't throw " + e); + } + + // Test that binding a bareword window method produces something + // which has a .call + try { + var binary = Components.utils.evalInSandbox( + 'btoa.bind(window).call(null, "foo")', sandbox); + is(binary, "Zm9v", "Should get the right result from .call on bound btoa"); + } catch (e) { + ok(false, ".call on bound btoa shouldn't throw " + e); + } + + // Test that binding a bareword window method produces something + // which has a .apply + try { + var binary = Components.utils.evalInSandbox( + 'btoa.bind(window).apply(null, ["foo"])', sandbox); + is(binary, "Zm9v", "Should get the right result from .apply on bound btoa"); + } catch (e) { + ok(false, ".apply on bound btoa shouldn't throw " + e); + } + + SimpleTest.finish(); + } + + SimpleTest.waitForExplicitFinish(); + addLoadEvent(doTest); + ]]> + </script> +</window> diff --git a/dom/tests/mochitest/chrome/test_sandbox_eventhandler.xul b/dom/tests/mochitest/chrome/test_sandbox_eventhandler.xul new file mode 100644 index 000000000..536a94517 --- /dev/null +++ b/dom/tests/mochitest/chrome/test_sandbox_eventhandler.xul @@ -0,0 +1,38 @@ +<?xml version="1.0"?> +<?xml-stylesheet type="text/css" href="chrome://global/skin"?> +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=817284 +--> +<window title="Mozilla Bug 817284" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> + + <!-- test results are displayed in the html:body --> + <body xmlns="http://www.w3.org/1999/xhtml"> + <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=817284" + target="_blank">Mozilla Bug 817284</a> + </body> + + <!-- test code goes here --> + <script type="application/javascript"> + <![CDATA[ + + /** Test for Bug 817284 **/ + var cu = Components.utils; + var sb = cu.Sandbox("http://example.com", { wantGlobalProperties: ["XMLHttpRequest"] }); + + // Test event handler calls + var xhr = cu.evalInSandbox( + 'var xhr = new XMLHttpRequest();\ + var called = false;\ + xhr.onload = function() { called = true; };\ + xhr', sb); + + var e = document.createEvent("Events"); + e.initEvent("load", false, false); + xhr.dispatchEvent(e); + is(cu.evalInSandbox('called', sb), true, "Event handler should have been called"); + ]]> + </script> +</window> diff --git a/dom/tests/mochitest/chrome/test_sandbox_image.xul b/dom/tests/mochitest/chrome/test_sandbox_image.xul new file mode 100644 index 000000000..15818b903 --- /dev/null +++ b/dom/tests/mochitest/chrome/test_sandbox_image.xul @@ -0,0 +1,37 @@ +<?xml version="1.0"?> +<?xml-stylesheet type="text/css" href="chrome://global/skin"?> +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=616397 +--> +<window title="Mozilla Bug 616397" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> + + <iframe id="t"></iframe> + + <!-- test results are displayed in the html:body --> + <body xmlns="http://www.w3.org/1999/xhtml"> + <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=616397" + target="_blank">Mozilla Bug 616397</a> + </body> + + + <!-- test code goes here --> + <script type="application/javascript"> + <![CDATA[ + /** Test for Bug 616397 **/ + function doTest() { + var win = $("t").contentWindow; + var sandbox = Components.utils.Sandbox(win, { sandboxPrototype: win }); + var result = Components.utils.evalInSandbox("new Image()", sandbox); + isnot(result, null, "Should have an image"); + is(result.tagName, "IMG", "Should have the right tag name"); + SimpleTest.finish(); + } + + SimpleTest.waitForExplicitFinish(); + addLoadEvent(doTest); + ]]> + </script> +</window> diff --git a/dom/tests/mochitest/chrome/test_sandbox_postMessage.html b/dom/tests/mochitest/chrome/test_sandbox_postMessage.html new file mode 100644 index 000000000..46164a181 --- /dev/null +++ b/dom/tests/mochitest/chrome/test_sandbox_postMessage.html @@ -0,0 +1,36 @@ +<!DOCTYPE HTML> +<html> +<head> + <title>Testing postMessage from sandbox</title> + <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> +<script type="application/javascript"> + SimpleTest.waitForExplicitFinish(); + function doTest() { + var sandbox = Components.utils.Sandbox("http://mochi.test:8888/", { wantXrays: true }); + var win = window.frames["sameDomain"]; + sandbox.win = win; + sandbox.is = is; + sandbox.done = SimpleTest.finish; + + result = Components.utils.evalInSandbox('var data = {some:"data"};' + +'win.addEventListener("message", receiveMessage, false);' + +'function receiveMessage(event)' + +'{' + +' is(JSON.stringify(event.data), JSON.stringify(data), "Received the expected message data");' + +' done();' + +'}' + +'win.postMessage(data, "*")' + , sandbox); + } + + addLoadEvent(doTest); +</script> +</head> +<body> +<iframe src="http://mochi.test:8888/" + id="sameDomain" name="sameDomain"> +</iframe> +</body> +</html> + diff --git a/dom/tests/mochitest/chrome/test_selectAtPoint.html b/dom/tests/mochitest/chrome/test_selectAtPoint.html new file mode 100644 index 000000000..c96c6607b --- /dev/null +++ b/dom/tests/mochitest/chrome/test_selectAtPoint.html @@ -0,0 +1,21 @@ +<!DOCTYPE HTML> +<html> +<head> + <title>nsIDOMWindowUtils::selectAtPoint test</title> + <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> +<script type="application/javascript"> + SimpleTest.waitForExplicitFinish(); + function done() { + testwindow.close(); + SimpleTest.finish(); + } + var testwindow = window.open("selectAtPoint.html", '_new', 'width=800,height=800'); +</script> +</head> +<body> +<p id="display"></p> +<div id="content" style="display: none"> +</body> +</html> + diff --git a/dom/tests/mochitest/chrome/test_sizemode_attribute.xul b/dom/tests/mochitest/chrome/test_sizemode_attribute.xul new file mode 100644 index 000000000..d0066ea1c --- /dev/null +++ b/dom/tests/mochitest/chrome/test_sizemode_attribute.xul @@ -0,0 +1,26 @@ +<?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 for the sizemode attribute + --> +<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" + sizemode="fullscreen"> + + <script type="application/javascript" + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + +<script> +SimpleTest.waitForExplicitFinish(); + +newwindow = window.open("sizemode_attribute.xul", "_blank","chrome,resizable=yes"); + +function done() { + newwindow.close(); + SimpleTest.finish(); +} + +</script> +<body xmlns="http://www.w3.org/1999/xhtml" style="height: 300px;"/> + +</window> diff --git a/dom/tests/mochitest/chrome/test_subscript_bindings.xul b/dom/tests/mochitest/chrome/test_subscript_bindings.xul new file mode 100644 index 000000000..132d3b4d6 --- /dev/null +++ b/dom/tests/mochitest/chrome/test_subscript_bindings.xul @@ -0,0 +1,44 @@ +<?xml version="1.0"?> +<?xml-stylesheet type="text/css" href="chrome://global/skin"?> +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=741267 +--> +<window title="Mozilla Bug 741267" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> + + <iframe id="t"></iframe> + + <!-- test results are displayed in the html:body --> + <body xmlns="http://www.w3.org/1999/xhtml"> + <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=741267" + target="_blank">Mozilla Bug 741267</a> + </body> + + <!-- test code goes here --> + <script type="application/javascript"> + <![CDATA[ + + /** Test for Bug 741267 **/ + function doTest() { + // Resolve XMLHttpRequest on the chrome global + new XMLHttpRequest(); + + var loader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"].getService(Components.interfaces.mozIJSSubScriptLoader); + var context = { window: $("t").contentWindow }; + var thrown = false; + try { + loader.loadSubScript(/.*\//.exec(window.location.href)[0] + "file_subscript_bindings.js", context); + } catch (e) { + thrown = true; + } + ok(!thrown, "'new window.XMLHttpRequest()' in a subscript shouldn't throw"); + SimpleTest.finish(); + } + + SimpleTest.waitForExplicitFinish(); + addLoadEvent(doTest); + ]]> + </script> +</window> diff --git a/dom/tests/mochitest/chrome/test_xray_event_constructor.xul b/dom/tests/mochitest/chrome/test_xray_event_constructor.xul new file mode 100644 index 000000000..9e18374ee --- /dev/null +++ b/dom/tests/mochitest/chrome/test_xray_event_constructor.xul @@ -0,0 +1,35 @@ +<?xml version="1.0"?> +<?xml-stylesheet type="text/css" href="chrome://global/skin"?> +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=861493 +--> +<window title="Mozilla Bug 861493" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> + + <iframe id="t" type="content"></iframe> + + <!-- test results are displayed in the html:body --> + <body xmlns="http://www.w3.org/1999/xhtml"> + <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=861493" + target="_blank">Mozilla Bug 861493</a> + </body> + + <!-- test code goes here --> + <script type="application/javascript"> + <![CDATA[ + /** Test for Bug 861493 **/ + SimpleTest.waitForExplicitFinish(); + + addLoadEvent(function() { + ok(Components.utils.isXrayWrapper($("t").contentWindow), + "Should have xray"); + var e = new ($("t").contentWindow).Event("test", { bubbles: true }); + is(e.bubbles, true, "Dictionary should have worked"); + SimpleTest.finish(); + }) + + ]]> + </script> +</window> diff --git a/dom/tests/mochitest/chrome/window_activation.xul b/dom/tests/mochitest/chrome/window_activation.xul new file mode 100644 index 000000000..eb2d44ed4 --- /dev/null +++ b/dom/tests/mochitest/chrome/window_activation.xul @@ -0,0 +1,37 @@ +<?xml version="1.0"?> +<?xml-stylesheet href="chrome://global/skin" type="text/css"?> +<?xml-stylesheet href="data:text/css, + +%23box { + background: blue; +} + +%23box:-moz-window-inactive { + background: cyan; +} + +" type="text/css"?> + +<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + +<box id="box" height="100"/> + +<script type="application/javascript"><![CDATA[ + +var ok = window.opener.wrappedJSObject.ok; +var complete = window.opener.wrappedJSObject.complete; +var openerDoc = window.opener.wrappedJSObject.document; +var SimpleTest = window.opener.wrappedJSObject.SimpleTest; + +SimpleTest.waitForFocus(function () { + ok(getComputedStyle(document.getElementById("box"), "").backgroundColor, "rgb(0, 0, 255)"); + ok(getComputedStyle(openerDoc.getElementById("box"), "").backgroundColor, "rgb(0, 255, 255)"); + window.opener.focus(); + ok(getComputedStyle(document.getElementById("box"), "").backgroundColor, "rgb(0, 255, 255)"); + ok(getComputedStyle(openerDoc.getElementById("box"), "").backgroundColor, "rgb(0, 0, 255)"); + complete(); +}, window); + +]]></script> + +</window> diff --git a/dom/tests/mochitest/chrome/window_callback_wrapping.xul b/dom/tests/mochitest/chrome/window_callback_wrapping.xul new file mode 100644 index 000000000..6bb817657 --- /dev/null +++ b/dom/tests/mochitest/chrome/window_callback_wrapping.xul @@ -0,0 +1,21 @@ +<?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"?> +<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + + <browser type="content" + src="data:text/html,<script>var x = new XMLHttpRequest(); x.onreadystatechange = function() {}</script>"/> + + <script type="application/javascript"><![CDATA[ + window.onload = function() { + var z = new XPCNativeWrapper(window.frames[0].wrappedJSObject.x).onreadystatechange; + var t = window.opener.SimpleTest; + t.ok(true, "Hey, we didn't crash"); + window.close(); + t.finish(); + } + ]]> +</script> + +</window> diff --git a/dom/tests/mochitest/chrome/window_docshell_swap.xul b/dom/tests/mochitest/chrome/window_docshell_swap.xul new file mode 100644 index 000000000..3b849b64c --- /dev/null +++ b/dom/tests/mochitest/chrome/window_docshell_swap.xul @@ -0,0 +1,8 @@ +<?xml version="1.0"?> +<?xml-stylesheet href="chrome://global/skin" type="text/css"?> + +<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + +<browser type="content" src="about:blank" id="browser"/> + +</window> diff --git a/dom/tests/mochitest/chrome/window_focus.xul b/dom/tests/mochitest/chrome/window_focus.xul new file mode 100644 index 000000000..4bf210311 --- /dev/null +++ b/dom/tests/mochitest/chrome/window_focus.xul @@ -0,0 +1,1729 @@ +<?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"?> +<!-- + This test checks focus in various ways +--> +<window id="outer-document" title="Focus Test" width="600" height="550" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + <script type="application/javascript" + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + <script type="application/javascript" + src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> + +<body xmlns="http://www.w3.org/1999/xhtml"/> + + <script type="application/javascript"><![CDATA[ + +var fm = Components.classes["@mozilla.org/focus-manager;1"]. + getService(Components.interfaces.nsIFocusManager); + +const kChildDocumentRootIndex = 13; +const kBeforeTabboxIndex = 34; +const kTabbableSteps = 38; +const kFocusSteps = 26; +const kNoFocusSteps = 7; +const kOverflowElementIndex = 27; + +var gTestStarted = false; +var gPartialTabbing = false; +var gMoveToFocusFrame = false; +var gLastFocus = null; +var gLastFocusWindow = window; +var gLastFocusMethod = -1; +var gEvents = ""; +var gExpectedEvents = ""; +var gEventMatched = true; +var gShowOutput = false; +var gChildWindow = null; + +var gOldExpectedWindow = null; +var gNewExpectedWindow = null; + +function is(l, r, n) { window.opener.wrappedJSObject.SimpleTest.is(l,r,n); } +function ok(v, n) { window.opener.wrappedJSObject.SimpleTest.ok(v,n); } + +function initEvents(target) +{ + target.addEventListener("focus", eventOccured, true); + target.addEventListener("blur", eventOccured, true); + getTopWindow(target).addEventListener("activate", eventOccured, true); + getTopWindow(target).addEventListener("deactivate", eventOccured, true); +} + +function eventOccured(event) +{ + // iframes should never receive focus or blur events directly + if (event.target instanceof Element && event.target.localName == "iframe") + ok(false, "iframe " + event.type + "occured"); + + var id; + if (gOldExpectedWindow && event.type == "blur") { + if (event.target instanceof Window) + id = "frame-" + gOldExpectedWindow.document.documentElement.id + "-window"; + else if (event.target instanceof Document) + id = "frame-" + gOldExpectedWindow.document.documentElement.id + "-document"; + else + id = event.originalTarget.id; + } + else if (gNewExpectedWindow && event.type == "focus") { + if (event.target instanceof Window) + id = "frame-" + gNewExpectedWindow.document.documentElement.id + "-window"; + else if (event.target instanceof Document) + id = "frame-" + gNewExpectedWindow.document.documentElement.id + "-document"; + else + id = event.originalTarget.id; + } + else if (event.type == "activate" || event.type == "deactivate") + id = event.target.document.documentElement.id + "-window"; + else if (event.target instanceof Window) + id = (event.target == window) ? "outer-window" : "child-window"; + else if (event.target instanceof Document) + id = (event.target == document) ? "outer-document" : "child-document"; + else + id = event.originalTarget.id; + + if (gEvents) + gEvents += " "; + gEvents += event.type + ": " + id; +} + +function expectFocusShift(callback, expectedWindow, expectedElement, focusChanged, testid) +{ + if (expectedWindow == null) + expectedWindow = expectedElement ? + expectedElement.ownerDocument.defaultView : + gLastFocusWindow; + + var expectedEvents = ""; + if (focusChanged) { + var id; + if (getTopWindow(gLastFocusWindow) != getTopWindow(expectedWindow)) { + id = getTopWindow(gLastFocusWindow).document.documentElement.id; + expectedEvents += "deactivate: " + id + "-window"; + } + + if (gLastFocus && gLastFocus.id != "t" + kChildDocumentRootIndex && + (!gOldExpectedWindow || gOldExpectedWindow.document.documentElement != gLastFocus)) { + if (expectedEvents) + expectedEvents += " "; + if (!gOldExpectedWindow) + expectedEvents += "commandupdate: cu "; + expectedEvents += "blur: " + gLastFocus.id; + } + + if (gLastFocusWindow && gLastFocusWindow != expectedWindow) { + if (!gMoveToFocusFrame) { + if (gOldExpectedWindow) + id = "frame-" + gOldExpectedWindow.document.documentElement.id; + else + id = (gLastFocusWindow == window) ? "outer" : "child"; + if (expectedEvents) + expectedEvents += " "; + expectedEvents += "blur: " + id + "-document " + + "blur: " + id + "-window"; + } + } + + if (getTopWindow(gLastFocusWindow) != getTopWindow(expectedWindow)) { + id = getTopWindow(expectedWindow).document.documentElement.id; + if (expectedEvents) + expectedEvents += " "; + expectedEvents += "activate: " + id + "-window"; + } + + if (expectedWindow && gLastFocusWindow != expectedWindow) { + if (gNewExpectedWindow) + id = "frame-" + gNewExpectedWindow.document.documentElement.id; + else + id = (expectedWindow == window) ? "outer" : "child"; + if (expectedEvents) + expectedEvents += " "; + expectedEvents += "focus: " + id + "-document " + + "focus: " + id + "-window"; + } + + // for this test which fires a mouse event on a label, the document will + // be focused first and then the label code will focus the related + // control. This doesn't result in different focus events, but a command + // update will occur for the document and then a second command update will + // occur when the control is focused. However, this will only happen on + // platforms or controls where mouse clicks cause trigger focus. + if (testid == "mouse on html label with content inside" && + mouseWillTriggerFocus(expectedElement)) { + expectedEvents += " commandupdate: cu"; + } + + if (expectedElement && + (!gNewExpectedWindow || gNewExpectedWindow.document.documentElement != expectedElement)) { + if (!gNewExpectedWindow) { + if (expectedEvents) + expectedEvents += " "; + expectedEvents += "commandupdate: cu"; + } + if (expectedElement.id != "t" + kChildDocumentRootIndex) { + if (expectedEvents) + expectedEvents += " "; + expectedEvents += "focus: " + expectedElement.id; + } + } + else if (expectedWindow && gLastFocusWindow != expectedWindow && + !expectedElement) { + if (expectedEvents) + expectedEvents += " "; + expectedEvents += "commandupdate: cu"; + } + } + + gLastFocus = expectedElement; + gLastFocusWindow = expectedWindow; + + callback(); + + compareEvents(expectedEvents, expectedWindow, expectedElement, testid); +} + +function compareEvents(expectedEvents, expectedWindow, expectedElement, testid) +{ + if (!gShowOutput) { + gEvents = ""; + return; + } + + is(gEvents, expectedEvents, testid + " events"); + gEvents = ""; + + var doc; + if (expectedWindow == window) + doc = "outer-document"; + else if (expectedWindow == gChildWindow) + doc = "inner-document"; + else if (gNewExpectedWindow) + doc = gNewExpectedWindow.document.body ? gNewExpectedWindow.document.body.id : + gNewExpectedWindow.document.documentElement.id; + else + doc = "other-document"; + + var focusedElement = fm.focusedElement; + is(focusedElement ? focusedElement.id : "none", + expectedElement ? expectedElement.id : "none", testid + " focusedElement"); + is(fm.focusedWindow, expectedWindow, testid + " focusedWindow"); + var focusedWindow = {}; + is(fm.getFocusedElementForWindow(expectedWindow, false, focusedWindow), + expectedElement, testid + " getFocusedElementForWindow"); + is(focusedWindow.value, expectedWindow, testid + " getFocusedElementForWindow frame"); + is(expectedWindow.document.hasFocus(), true, testid + " hasFocus"); + is(expectedWindow.document.activeElement ? expectedWindow.document.activeElement.id : "none", + expectedElement ? expectedElement.id : doc, testid + " activeElement"); + var cdwindow = getTopWindow(expectedWindow); + if (cdwindow.document.commandDispatcher) { + is(cdwindow.document.commandDispatcher.focusedWindow, expectedWindow, testid + " commandDispatcher focusedWindow"); + is(cdwindow.document.commandDispatcher.focusedElement, focusedElement, testid + " commandDispatcher focusedElement"); + } + + if (gLastFocusMethod != -1) { + is(fm.getLastFocusMethod(null), gLastFocusMethod, testid + " lastFocusMethod null"); + is(fm.getLastFocusMethod(expectedWindow), gLastFocusMethod, testid + " lastFocusMethod window"); + } + + // the parent should have the iframe focused + if (doc == "inner-document") { + is(document.hasFocus(), true, testid + " hasFocus"); + is(fm.getFocusedElementForWindow(window, false, focusedWindow), + $("childframe"), testid + " getFocusedElementForWindow for parent"); + is(focusedWindow.value, window, testid + " getFocusedElementForWindow for parent frame"); + is(fm.getFocusedElementForWindow(window, true, focusedWindow), + expectedElement, testid + " getFocusedElementForWindow deep for parent"); + is(focusedWindow.value, gChildWindow, testid + " getFocusedElementForWindow deep for parent frame"); + is(document.activeElement.id, "childframe", testid + " activeElement for parent"); + } + + // compare the selection for the child window. Skip mouse tests as the caret + // is adjusted by the selection code for mouse clicks, and not the focus code. + if (expectedWindow == window) { + var selection = window.getSelection(); + ok(selection.focusNode == null && selection.focusOffset == 0 && + selection.anchorNode == null && selection.anchorOffset == 0, testid + " selection"); + } + else if ((expectedWindow == gChildWindow) && !testid.indexOf("mouse") == -1) { + checkSelection(expectedElement, testid); + } +} + +function checkSelection(node, testid) +{ + var selection = gChildWindow.getSelection(); + + var range = gChildWindow.document.createRange(); + range.selectNodeContents(node); + if (!node.firstChild || node.localName == "input" || + node.localName == "select" || node.localName == "button") { + range.setStartBefore(node); + range.setEndBefore(node); + } + + if (node.firstChild) + range.setEnd(range.startContainer, range.startOffset); + + is(selection.focusNode, range.startContainer, testid + " selection focusNode"); + is(selection.focusOffset, range.startOffset, testid + " selection focusOffset"); + is(selection.anchorNode, range.endContainer, testid + " selection anchorNode"); + is(selection.anchorOffset, range.endOffset, testid + " selection anchorOffset"); +} + +function getTopWindow(win) +{ + return win.QueryInterface(Components.interfaces.nsIInterfaceRequestor). + getInterface(Components.interfaces.nsIWebNavigation). + QueryInterface(Components.interfaces.nsIDocShellTreeItem).rootTreeItem. + QueryInterface(Components.interfaces.nsIInterfaceRequestor). + getInterface(Components.interfaces.nsIDOMWindow); +} + +function mouseWillTriggerFocus(element) +{ + if (!element) { + return false; + } + + if (navigator.platform.indexOf("Mac") != 0) { + return true; + } + + if (element.namespaceURI == "http://www.w3.org/1999/xhtml") { + // links are special. They can be focused but show no focus ring + if (element.localName == "a" || element.localName == "div" || + element.localName == "select" || + element.localName == "input" && (element.type == "text" || + element.type == "password")) { + return true; + } + } else if (element.localName == "listbox") { + return true; + } + + return false; +} + +function mouseOnElement(element, expectedElement, focusChanged, testid) +{ + var expectedWindow = (element.ownerDocument.defaultView == gChildWindow) ? gChildWindow : window; + // on Mac, form elements are not focused when clicking, except for lists and textboxes. + var noFocusOnMouse = !mouseWillTriggerFocus(element) + + if (noFocusOnMouse) { + // no focus so the last focus method will be 0 + gLastFocusMethod = 0; + expectFocusShift(() => synthesizeMouse(element, 4, 4, { }, element.ownerDocument.defaultView), + expectedWindow, null, true, testid); + gLastFocusMethod = fm.FLAG_BYMOUSE; + } + else { + expectFocusShift(() => synthesizeMouse(element, 4, 4, { }, element.ownerDocument.defaultView), + element.ownerDocument.defaultView, + expectedElement, focusChanged, testid); + } +} + +function done() +{ + var opener = window.opener; + window.close(); + opener.wrappedJSObject.SimpleTest.finish(); +} + +var pressTab = () => synthesizeKey("VK_TAB", { }); + +function setFocusTo(id, fwindow) +{ + gLastFocus = getById(id); + gLastFocusWindow = fwindow; + if (gLastFocus) + gLastFocus.focus(); + else + fm.clearFocus(fwindow); + gEvents = ""; +} + +function getById(id) +{ + if (gNewExpectedWindow) + return gNewExpectedWindow.document.getElementById(id); + var element = $(id); + if (!element) + element = $("childframe").contentDocument.getElementById(id); + return element; +} + +function startTest() +{ + if (gTestStarted) + return; + gTestStarted = true; + + gChildWindow = $("childframe").contentWindow; + gShowOutput = true; + + // synthesize a mousemove over the image to ensure that the imagemap data is + // created. Otherwise, the special imagemap frames might not exist, and + // won't be focusable. + synthesizeMouse(getById("image"), 4, 4, { type: "mousemove" }, gChildWindow); + + initEvents(window); + + is(fm.activeWindow, window, "activeWindow"); + is(gChildWindow.document.hasFocus(), false, " child document hasFocus"); + + // test to see if the Mac Full Keyboard Access setting is set. If t3 is + // focused after tab is pressed, then it is set to textboxes and lists only. + // Otherwise, all elements are in the tab order. + pressTab(); + + if (fm.focusedElement.id == "t3") + gPartialTabbing = true; + else + is(fm.focusedElement.id, "t1", "initial tab key"); + + is(fm.getLastFocusMethod(null), fm.FLAG_BYKEY, "last focus method null start"); + is(fm.getLastFocusMethod(window), fm.FLAG_BYKEY, "last focus method window start"); + + fm.clearFocus(window); + gEvents = ""; + + gLastFocusMethod = fm.FLAG_BYKEY; + if (gPartialTabbing) { + var partialTabList = ["t3", "t5", "t9", "t10", "t11", "t12", "t13", "t14", "t15", + "t16", "t19", "t20", "t21", "t22", "t26", "t27", "t28", "t29", "t30"]; + for (var idx = 0; idx < partialTabList.length; idx++) { + expectFocusShift(pressTab, null, getById(partialTabList[idx]), true, "partial tab key " + partialTabList[idx]); + } + setFocusTo("last", window); + expectFocusShift(pressTab, null, getById(partialTabList[0]), true, "partial tab key wrap to start"); + expectFocusShift(() => synthesizeKey("VK_TAB", { shiftKey: true }), + null, getById("last"), true, "partial shift tab key wrap to end"); + for (var idx = partialTabList.length - 1; idx >= 0; idx--) { + expectFocusShift(() => synthesizeKey("VK_TAB", { shiftKey: true }), + null, getById(partialTabList[idx]), true, "partial tab key " + partialTabList[idx]); + } + } + else { + // TAB key + for (var idx = 1; idx <= kTabbableSteps; idx++) { + expectFocusShift(pressTab, null, getById("t" + idx), true, "tab key t" + idx); + } + + // wrapping around at end with TAB key + setFocusTo("last", window); + expectFocusShift(pressTab, null, getById("t1"), true, "tab key wrap to start"); + expectFocusShift(() => synthesizeKey("VK_TAB", { shiftKey: true }), + null, getById("last"), true, "shift tab key wrap to end"); + + // Shift+TAB key + setFocusTo("o5", window); + for (idx = kTabbableSteps; idx > 0; idx--) { + expectFocusShift(() => synthesizeKey("VK_TAB", { shiftKey: true }), + null, getById("t" + idx), true, "shift tab key t" + idx); + } + } + + var t19 = getById("t19"); + is(t19.selectionStart, 0, "input focused from tab key selectionStart"); + is(t19.selectionEnd, 5, "input focused from tab key selectionEnd"); + t19.setSelectionRange(0, 0); + + gLastFocusMethod = 0; + var selectFired = false; + function selectListener() { selectFired = true; } + t19.addEventListener("select", selectListener, false); + expectFocusShift(() => t19.select(), + null, getById("t" + 19), true, "input.select()"); + t19.removeEventListener("select", selectListener, false); + ok(selectFired, "select event fires for input"); + + // mouse clicking + gLastFocusMethod = fm.FLAG_BYMOUSE; + for (idx = kTabbableSteps; idx >= 1; idx--) { + // skip the document root and the overflow element + if (idx == kChildDocumentRootIndex || idx == kOverflowElementIndex) + continue; + if ((navigator.platform.indexOf("Mac") == 0) && (idx == kBeforeTabboxIndex + 1)) + continue; + + var element = getById("t" + idx); + // skip area elements, as getBoundingClientRect doesn't return their actual coordinates + if (element.localName == "area") + continue; + + mouseOnElement(element, getById("t" + idx), true, "mouse on element t" + idx); + var expectedWindow = (element.ownerDocument.defaultView == gChildWindow) ? gChildWindow : window; + if (element.localName == "listbox" && expectedWindow == window && + navigator.platform.indexOf("Mac") == 0) { + // after focusing a listbox on Mac, clear the focus before continuing. + setFocusTo(null, window); + } + } + + ok(t19.selectionStart == t19.selectionEnd, "input focused from mouse selection"); + + // mouse clicking on elements that are not tabbable + for (idx = 1; idx <= kFocusSteps; idx++) { + var element = getById("o" + (idx % 2 ? idx : idx - 1)); + + mouseOnElement(element, element, idx % 2, + "mouse on non-tabbable element o" + idx); + } + + // mouse clicking on elements that are not tabbable and have user-focus: none + // or are not focusable for other reasons (for instance, being disabled) + // These elements will clear the focus when clicked. + for (idx = 1; idx <= kNoFocusSteps; idx++) { + var element = getById("n" + idx); + gLastFocusMethod = idx % 2 ? 0 : fm.FLAG_BYMOUSE; + + mouseOnElement(element, idx % 2 ? null: element, true, "mouse on unfocusable element n" + idx); + } + + if (idx == kOverflowElementIndex) { + gLastFocusMethod = fm.FLAG_BYMOUSE; + var element = getById("t" + idx); + expectFocusShift(() => synthesizeMouse(element, 4, 4, { }, element.ownerDocument.defaultView), + window, null, true, "mouse on scrollable element"); + } + + // focus() method + gLastFocusMethod = 0; + for (idx = kTabbableSteps; idx >= 1; idx--) { + if ((navigator.platform.indexOf("Mac") == 0) && (idx == kBeforeTabboxIndex + 1)) + continue; + expectFocusShift(() => getById("t" + idx).focus(), + null, getById("t" + idx), true, "focus method on element t" + idx); + } + + $("t1").focus(); + ok(gEvents === "", "focusing element that is already focused"); + + $("t2").blur(); + $("t7").blur(); + ok(gEvents === "", "blurring element that is not focused"); + is(document.activeElement, $("t1"), "old element still focused after blur() on another element"); + + // focus() method on elements that are not tabbable + for (idx = 1; idx <= kFocusSteps; idx++) { + var expected = getById("o" + (idx % 2 ? idx : idx - 1)); + expectFocusShift(() => getById("o" + idx).focus(), + expected.ownerDocument.defaultView, + expected, idx % 2, "focus method on non-tabbable element o" + idx); + } + + // focus() method on elements that are not tabbable and have user-focus: none + // or are not focusable for other reasons (for instance, being disabled) + for (idx = 1; idx <= kNoFocusSteps; idx++) { + var expected = getById("o" + (idx % 2 ? idx : idx - 1)); + expectFocusShift(() => getById("o" + idx).focus(), + expected.ownerDocument.defaultView, + expected, idx % 2, "focus method on unfocusable element n" + idx); + } + + // the focus() method on the legend element should focus the legend if it is + // focusable, or the first element after the legend if it is not focusable. + if (!gPartialTabbing) { + gLastFocusMethod = fm.FLAG_BYMOVEFOCUS; + var legend = getById("legend"); + expectFocusShift(() => legend.focus(), + null, getById("t28"), true, "focus method on unfocusable legend"); + gLastFocusMethod = 0; + legend.tabIndex = "0"; + expectFocusShift(() => legend.focus(), + null, getById("legend"), true, "focus method on focusable legend"); + legend.tabIndex = "-1"; + } + + var accessKeyDetails = (navigator.platform.indexOf("Mac") >= 0) ? + { ctrlKey : true } : { altKey : true }; + + // test accesskeys + var keys = ["t26", "t19", "t22", "t29", "t15", "t17", "n6", + "t4", "o1", "o9", "n4"]; + for (var k = 0; k < keys.length; k++) { + var key = String.fromCharCode(65 + k); + + // accesskeys D and G are for labels so get redirected + gLastFocusMethod = (key == "D" || key == "G") ? fm.FLAG_BYMOVEFOCUS : fm.FLAG_BYKEY; + + // on Windows and Linux, the shift key must be pressed for content area access keys + // and on Mac, the alt key must be pressed for content area access keys + var isContent = (getById(keys[k]).ownerDocument.defaultView == gChildWindow); + if (navigator.platform.indexOf("Mac") == -1) { + accessKeyDetails.shiftKey = isContent; + } else { + accessKeyDetails.altKey = isContent; + } + + expectFocusShift(() => synthesizeKey(key, accessKeyDetails), + null, getById(keys[k]), true, "accesskey " + key); + } + + // clicking on the labels + gLastFocusMethod = fm.FLAG_BYMOVEFOCUS | fm.FLAG_BYMOUSE; + mouseOnElement(getById("ad"), getById("t29"), true, "mouse on html label with content inside"); + mouseOnElement(getById("ag"), getById("n6"), true, "mouse on html label with for attribute"); + gLastFocusMethod = 0; + expectFocusShift(() => synthesizeMouse(getById("aj"), 2, 2, { }), + null, getById("o9"), true, "mouse on xul label with content inside"); + expectFocusShift(() => synthesizeMouse(getById("ak"), 2, 2, { }), + null, getById("n4"), true, "mouse on xul label with control attribute"); + + // test accesskeys that shouldn't work + k = "o".charCodeAt(0); + while (k++ < "v".charCodeAt(0)) { + var key = String.fromCharCode(k); + expectFocusShift(() => synthesizeKey(key, accessKeyDetails), + window, getById("n4"), false, "non accesskey " + key); + } + gLastFocusMethod = -1; + + // should focus the for element when using the focus method on a label as well + expectFocusShift(() => getById("ad").focus(), + null, getById("t29"), true, "mouse on html label using focus method"); + + // make sure that the text is selected when clicking a label associated with an input + getById("ag").htmlFor = "t19"; + expectFocusShift(() => synthesizeMouse(getById("ag"), 2, 2, { }, gChildWindow), + null, getById("t19"), true, "mouse on html label with for attribute changed"); + is(t19.selectionStart, 0, "input focused from label, selectionStart"); + is(t19.selectionEnd, 5, "input focused from label, selectionEnd"); + + // switch to another panel in a tabbox and ensure that tabbing moves between + // elements on the new panel. + $("tabbox").selectedIndex = 1; + expectFocusShift(() => getById("t" + kBeforeTabboxIndex).focus(), + null, getById("t" + kBeforeTabboxIndex), true, "focus method on element before tabbox"); + + if (!gPartialTabbing) { + expectFocusShift(pressTab, null, getById("tab2"), true, "focus method on tab"); + expectFocusShift(pressTab, null, getById("htab1"), true, "tab key switch tabpanel 1"); + expectFocusShift(pressTab, null, getById("htab2"), true, "tab key switch tabpanel 2"); + expectFocusShift(pressTab, null, getById("t" + (kBeforeTabboxIndex + 4)), true, "tab key switch tabpanel 3"); + } + $("tabbox").selectedIndex = 0; + + // ---- the following checks when the focus changes during a blur or focus event ---- + + var o5 = $("o5"); + var o9 = $("o9"); + var t3 = $("t3"); + var t17 = getById("t17"); + var t19 = getById("t19"); + var shiftFocusParentDocument = () => o9.focus(); + var shiftFocusChildDocument = () => t17.focus(); + + var trapBlur = function (element, eventListener, blurFunction) + { + element.focus(); + gEvents = ""; + element.addEventListener("blur", eventListener, false); + blurFunction(); + element.removeEventListener("blur", eventListener, false); + } + + var functions = [ + element => element.focus(), + element => synthesizeMouse(element, 4, 4, { }, element.ownerDocument.defaultView) + ]; + + // first, check cases where the focus is adjusted during the blur event. Iterate twice, + // once with the focus method and then focusing by mouse clicking + for (var l = 0; l < 2; l++) { + var adjustFocus = functions[l]; + var mod = (l == 1) ? " with mouse" : ""; + + // an attempt is made to switch the focus from one element (o5) to another + // element (t3) within the same document, yet the focus is shifted to a + // third element (o9) in the same document during the blur event for the + // first element. + trapBlur(o5, shiftFocusParentDocument, () => adjustFocus(t3)); + compareEvents("commandupdate: cu blur: o5 commandupdate: cu focus: o9", + window, o9, "change focus to sibling during element blur, attempted sibling" + mod); + + // similar, but the third element (t17) is in a child document + trapBlur(o9, shiftFocusChildDocument, () => adjustFocus(t3)); + compareEvents("commandupdate: cu blur: o9 blur: outer-document blur: outer-window " + + "focus: child-document focus: child-window commandupdate: cu focus: t17", + gChildWindow, t17, "change focus to child document during element blur, attempted sibling" + mod); + + // similar, but an attempt to switch focus within the same document, but the + // third element (t17) is in a parent document + trapBlur(t17, shiftFocusParentDocument, () => adjustFocus(t19)); + compareEvents("commandupdate: cu blur: t17 blur: child-document blur: child-window " + + "focus: outer-document focus: outer-window commandupdate: cu focus: o9", + window, o9, "change focus to parent document during element blur, attempted sibling" + mod); + + // similar, but blur is called instead of switching focus + trapBlur(t3, shiftFocusParentDocument, () => t3.blur()); + compareEvents("commandupdate: cu blur: t3 commandupdate: cu focus: o9", + window, o9, "change focus to same document during clear focus" + mod); + + // check when an element in the same document is focused during the + // element's blur event, but an attempt was made to focus an element in the + // child document. In this case, the focus in the parent document should be + // what was set during the blur event, but the actual focus should still + // move to the child document. + trapBlur(t3, shiftFocusParentDocument, () => adjustFocus(t17)); + compareEvents("commandupdate: cu blur: t3 commandupdate: cu focus: o9 " + + "blur: outer-document blur: outer-window " + + "focus: child-document focus: child-window commandupdate: cu focus: t17", + gChildWindow, t17, "change focus to sibling during element blur, attempted child" + mod); + is(fm.getFocusedElementForWindow(window, false, {}), $("childframe"), + "change focus to sibling during element blur, attempted child, focused in parent" + mod); + + // similar, but with a parent + trapBlur(t19, shiftFocusChildDocument, () => adjustFocus(t3)); + compareEvents("commandupdate: cu blur: t19 commandupdate: cu focus: t17 " + + "blur: child-document blur: child-window " + + "focus: outer-document focus: outer-window commandupdate: cu focus: t3", + window, t3, "change focus to sibling during element blur, attempted parent" + mod); + is(fm.getFocusedElementForWindow(gChildWindow, false, {}), t17, + "change focus to sibling during element blur, attempted child, focused in child" + mod); + + // similar, with a child, but the blur event focuses a child element also + trapBlur(t3, shiftFocusChildDocument, () => adjustFocus(t19)); + compareEvents("commandupdate: cu blur: t3 blur: outer-document blur: outer-window " + + "focus: child-document focus: child-window commandupdate: cu focus: t17", + gChildWindow, t17, "change focus to child during element blur, attempted child" + mod); + + // similar, with a parent, where the blur event focuses a parent element also + trapBlur(t17, shiftFocusParentDocument, () => adjustFocus(t3)); + compareEvents("commandupdate: cu blur: t17 blur: child-document blur: child-window " + + "focus: outer-document focus: outer-window commandupdate: cu focus: o9", + window, o9, "change focus to parent during element blur, attempted parent" + mod); + } + + var trapFocus = function (element, eventListener) + { + element.addEventListener("focus", eventListener, false); + element.focus(); + element.removeEventListener("focus", eventListener, false); + } + + fm.clearFocus(window); + gEvents = ""; + + // next, check cases where the focus is adjusted during the focus event + + // switch focus to an element in the same document + trapFocus(o5, shiftFocusParentDocument); + compareEvents("commandupdate: cu focus: o5 commandupdate: cu blur: o5 commandupdate: cu focus: o9", + window, o9, "change focus to sibling during element focus"); + + // similar, but the new element (t17) is in a child document + trapFocus(o5, shiftFocusChildDocument); + compareEvents("commandupdate: cu blur: o9 " + + "commandupdate: cu focus: o5 commandupdate: cu blur: o5 " + + "blur: outer-document blur: outer-window " + + "focus: child-document focus: child-window commandupdate: cu focus: t17", + gChildWindow, t17, "change focus to child document during element focus"); + + // similar, but the new element (o9) is in a parent document. + trapFocus(t19, shiftFocusParentDocument); + compareEvents("commandupdate: cu blur: t17 " + + "commandupdate: cu focus: t19 commandupdate: cu blur: t19 " + + "blur: child-document blur: child-window " + + "focus: outer-document focus: outer-window commandupdate: cu focus: o9", + window, o9, "change focus to parent document during element focus"); + + // clear the focus during the focus event + trapFocus(t3, () => fm.clearFocus(window)); + compareEvents("commandupdate: cu blur: o9 commandupdate: cu focus: t3 commandupdate: cu blur: t3", + window, null, "clear focus during focus event"); + + if (!gPartialTabbing) + doCommandDispatcherTests(); + + testMoveFocus(); + + doRemoveTests(); + + // tests various focus manager apis for null checks + var exh = false; + try { + fm.clearFocus(null); + } + catch (ex) { exh = true; } + is(exh, true, "clearFocus with null window causes exception"); + + var exh = false; + try { + fm.getFocusedElementForWindow(null, false, focusedWindow); + } + catch (ex) { exh = true; } + is(exh, true, "getFocusedElementForWindow with null window causes exception"); + + // just make sure that this doesn't crash + fm.moveCaretToFocus(null); + + // ---- tests for the FLAG_NOSWITCHFRAME flag + getById("o5").focus(); + gLastFocusMethod = 0; + gEvents = ""; + // focus is being shifted in a child, so the focus should not change + expectFocusShift(() => fm.setFocus(getById("t20"), fm.FLAG_NOSWITCHFRAME), + window, getById("o5"), false, "no switch frame focus to child"); + setFocusTo("t20", gChildWindow); + + // here, however, focus is being shifted in a parent, which will have to blur + // the child, so the focus will always change + expectFocusShift(() => fm.setFocus(getById("o5"), fm.FLAG_NOSWITCHFRAME), + window, getById("o5"), true, "no switch frame focus to parent"); + + expectFocusShift(() => fm.setFocus(getById("t1"), fm.FLAG_NOSWITCHFRAME), + window, getById("t1"), true, "no switch frame focus to same window"); + + // ---- tests for focus and scrolling into view ---- + var inscroll = getById("inscroll"); + inscroll.tabIndex = 0; + is(inscroll.parentNode.scrollTop, 0, "scroll position before focus"); + inscroll.focus(); + ok(inscroll.parentNode.scrollTop > 5, "scroll position after focus"); + inscroll.parentNode.scrollTop = 0; + fm.setFocus(inscroll, fm.FLAG_NOSCROLL); + is(inscroll.parentNode.scrollTop, 0, "scroll position after noscroll focus"); + + getById("t9").focus(); + getById("inpopup1").focus(); + is(fm.focusedElement, getById("t9"), "focus in closed popup"); + + // ---- tests to check if tabbing out of a textbox works + + setFocusTo("t1", window); + + var textbox1 = document.createElement("textbox"); + $("innerbox").appendChild(textbox1); + + var textbox2 = document.createElement("textbox"); + $("innerbox").appendChild(textbox2); + + gLastFocusMethod = 0; + expectFocusShift(() => textbox2.focus(), + null, textbox2.inputField, true, "focus on textbox"); + gLastFocusMethod = fm.FLAG_BYKEY; + expectFocusShift(() => synthesizeKey("VK_TAB", { shiftKey: true }), + null, textbox1.inputField, true, "shift+tab on textbox"); + + textbox1.tabIndex = 2; + textbox2.tabIndex = 2; + gLastFocusMethod = 0; + expectFocusShift(() => textbox2.focus(), + null, textbox2.inputField, true, "focus on textbox with tabindex set"); + gLastFocusMethod = fm.FLAG_BYKEY; + expectFocusShift(() => synthesizeKey("VK_TAB", { shiftKey: true }), + null, textbox1.inputField, true, "shift+tab on textbox with tabindex set"); + + // ---- test for bug 618907 which ensures that canceling the mousedown event still focuses the + // right frame + + var childContentFrame = document.getElementById("ifa") + childContentFrame.style.MozUserFocus = ""; + + var frab = childContentFrame.contentDocument.getElementById("fra-b"); + var mouseDownListener = event => event.preventDefault(); + frab.addEventListener("mousedown", mouseDownListener, false); + + var childElementToFocus = childContentFrame.contentDocument.getElementById("fra"); + gLastFocus = childElementToFocus; + gLastFocusWindow = childContentFrame.contentWindow; + gLastFocus.focus(); + gEvents = ""; + + setFocusTo("t1", window); + + gLastFocusMethod = -1; + expectFocusShift(() => synthesizeMouse(frab, 5, 5, { }, childContentFrame.contentWindow), + null, childElementToFocus, true, + "mousedown event canceled - chrome to content"); + + frab.removeEventListener("mousedown", mouseDownListener, false); + + var t5 = getById("t5"); + t5.addEventListener("mousedown", mouseDownListener, false); + synthesizeMouse(t5, 10, 10, { }) + t5.removeEventListener("mousedown", mouseDownListener, false); + is(fm.focusedElement, childElementToFocus, + "mousedown event cancelled - content to chrome - element"); + is(fm.focusedWindow, childContentFrame.contentWindow, "mousedown event cancelled - content to chrome - window"); + + // ---- test to check that refocusing an element during a blur event doesn't succeed + + var t1 = getById("t1"); + t1.addEventListener("blur", () => t1.focus(), true); + t1.focus(); + var t3 = getById("t3"); + synthesizeMouse(t3, 2, 2, { }); + is(fm.focusedElement, t3, "focus during blur"); + + setFocusTo("t9", window); + gLastFocusMethod = -1; + window.openDialog("focus_window2.xul", "_blank", "chrome", otherWindowFocused); +} + +function doCommandDispatcherTests() +{ + var t19 = getById("t19"); + t19.focus(); + gLastFocusWindow = gChildWindow; + gLastFocus = t19; + gEvents = ""; + + expectFocusShift(() => document.commandDispatcher.focusedElement = getById("o9"), + null, getById("o9"), true, "command dispatcher set focusedElement"); + expectFocusShift(() => document.commandDispatcher.advanceFocus(), + null, getById("o13"), true, "command dispatcher advanceFocus"); + expectFocusShift(() => document.commandDispatcher.rewindFocus(), + null, getById("o9"), true, "command dispatcher rewindFocus"); + expectFocusShift(() => document.commandDispatcher.focusedElement = null, + null, null, true, "command dispatcher set focusedElement to null"); + expectFocusShift(() => document.commandDispatcher.focusedWindow = gChildWindow, + null, getById("t19"), true, "command dispatcher set focusedElement to null"); + expectFocusShift(() => document.commandDispatcher.focusedElement = null, + gChildWindow, null, true, "command dispatcher set focusedElement to null in child"); + expectFocusShift(() => document.commandDispatcher.advanceFocusIntoSubtree(getById("t19")), + null, getById("t20"), true, "command dispatcher advanceFocusIntoSubtree child"); + expectFocusShift(() => document.commandDispatcher.advanceFocusIntoSubtree(null), + null, getById("t21"), true, "command dispatcher advanceFocusIntoSubtree null child"); + expectFocusShift(() => document.commandDispatcher.advanceFocusIntoSubtree(getById("o9").parentNode), + null, getById("o9"), true, "command dispatcher advanceFocusIntoSubtree parent"); +} + +function doRemoveTests() +{ + // next, some tests which remove elements + var t19 = getById("t19"); + t19.focus(); + t19.parentNode.removeChild(t19); + + is(fm.focusedElement, null, "removed element focusedElement"); + is(fm.focusedWindow, gChildWindow, "removed element focusedWindow"); + is(gChildWindow.document.hasFocus(), true, "removed element hasFocus"); + is(gChildWindow.document.activeElement, getById("inner-document"), "removed element activeElement"); + + getById("t15").focus(); + var abs = getById("abs"); + abs.parentNode.removeChild(abs); + + is(fm.focusedElement, null, "removed ancestor focusedElement"); + is(fm.focusedWindow, gChildWindow, "removed ancestor focusedWindow"); + is(gChildWindow.document.hasFocus(), true, "removed ancestor hasFocus"); + is(gChildWindow.document.activeElement, getById("inner-document"), "removed ancestor activeElement"); +} + +// tests for the FocusManager moveFocus method +function testMoveFocus() +{ + setFocusTo("t6", window); + + // moving focus while an element is already focused + var newFocus; + gLastFocusMethod = fm.FLAG_BYMOVEFOCUS; + var expectedFirst = getById(gPartialTabbing ? "t3" : "t1"); + expectFocusShift(() => newFocus = fm.moveFocus(null, null, fm.MOVEFOCUS_FIRST, 0), + window, expectedFirst, true, "moveFocus to first null window null content"); + is(newFocus, fm.focusedElement, "moveFocus to first null window null content return value"); + + expectFocusShift(() => newFocus = fm.moveFocus(null, null, fm.MOVEFOCUS_LAST, 0), + window, getById("last"), true, "moveFocus to last null window null content"); + is(newFocus, fm.focusedElement, "moveFocus to last null window null content return value"); + + gLastFocusMethod = 0; + newFocus = fm.moveFocus(null, null, fm.MOVEFOCUS_ROOT, 0); + is(newFocus, null, "moveFocus to root null window null content return value"); + is(fm.focusedWindow, window, "moveFocus to root null window null content focusedWindow"); + is(fm.focusedElement, null, "moveFocus to root null window null content focusedElement"); + + // moving focus while no element is focused + fm.clearFocus(window); + gEvents = ""; + gLastFocus = null; + gLastFocusMethod = fm.FLAG_BYMOVEFOCUS; + expectFocusShift(() => newFocus = fm.moveFocus(null, null, fm.MOVEFOCUS_FIRST, 0), + window, expectedFirst, true, "moveFocus to first null window null content no focus"); + is(newFocus, fm.focusedElement, "moveFocus to first null window null content no focus return value"); + fm.clearFocus(window); + gEvents = ""; + gLastFocus = null; + expectFocusShift(() => newFocus = fm.moveFocus(null, null, fm.MOVEFOCUS_LAST, 0), + window, getById("last"), true, "moveFocus to last null window null content no focus"); + is(newFocus, fm.focusedElement, "moveFocus to last null window null content no focus return value"); + fm.clearFocus(window); + gEvents = ""; + gLastFocusMethod = 0; + newFocus = fm.moveFocus(null, null, fm.MOVEFOCUS_ROOT, 0); + is(newFocus, null, "moveFocus to root null window null content no focus return value"); + is(fm.focusedWindow, window, "moveFocus to root null window null content no focus focusedWindow"); + is(fm.focusedElement, null, "moveFocus to root null window null content no focus focusedElement"); + + // moving focus from a specified element + setFocusTo("t6", window); + gLastFocusMethod = fm.FLAG_BYMOVEFOCUS; + expectFocusShift(() => newFocus = fm.moveFocus(null, getById("specialroot"), fm.MOVEFOCUS_FIRST, 0), + window, getById("t3"), true, "moveFocus to first null window with content"); +// XXXndeakin P3 this doesn't work +// expectFocusShift(() => newFocus = fm.moveFocus(null, getById("specialroot"), fm.MOVEFOCUS_LAST, 0), +// window, getById("o3"), true, "moveFocus to last null window with content"); + + // move focus to first in child window + expectFocusShift(() => newFocus = fm.moveFocus(gChildWindow, null, fm.MOVEFOCUS_FIRST, 0), + gChildWindow, getById("t" + (kChildDocumentRootIndex + 1)), true, + "moveFocus to first child window null content"); + is(newFocus, getById("t" + (kChildDocumentRootIndex + 1)), + "moveFocus to first child window null content return value"); + + // move focus to last in child window + setFocusTo("t6", window); + var expectedLast = getById(gPartialTabbing ? "t30" : "t" + (kBeforeTabboxIndex - 1)); + expectFocusShift(() => newFocus = fm.moveFocus(gChildWindow, null, fm.MOVEFOCUS_LAST, 0), + gChildWindow, expectedLast, true, + "moveFocus to last child window null content"); + is(newFocus, getById(expectedLast), + "moveFocus to last child window null content return value"); + + // move focus to root in child window + setFocusTo("t6", window); + var childroot = getById("t" + kChildDocumentRootIndex); + gLastFocusMethod = 0; + newFocus = fm.moveFocus(gChildWindow, null, fm.MOVEFOCUS_ROOT, 0), + is(newFocus, childroot, "moveFocus to root child window null content return value"); + is(fm.focusedWindow, gChildWindow, "moveFocus to root child window null content focusedWindow"); + is(fm.focusedElement, childroot, "moveFocus to root child window null content focusedElement"); + + // MOVEFOCUS_CARET tests + getById("t20").focus(); + gEvents = ""; + + var selection = gChildWindow.getSelection(); + selection.removeAllRanges(); + + newFocus = fm.moveFocus(gChildWindow, null, fm.MOVEFOCUS_CARET, 0); + is(newFocus, null, "move caret when at document root"); + is(fm.focusedElement, null, "move caret when at document root"); + + var node = getById("t16").firstChild; + var range = gChildWindow.document.createRange(); + range.setStart(node, 3); + range.setEnd(node, 3); + selection.addRange(range); + + newFocus = fm.moveFocus(gChildWindow, null, fm.MOVEFOCUS_CARET, 0); + is(newFocus, null, "move caret to non-link return value"); + is(fm.focusedElement, null, "move caret to non-link"); + + var t25 = getById("t25"); + var node = t25.firstChild; + range.setStart(node, 1); + range.setEnd(node, 1); + newFocus = fm.moveFocus(gChildWindow, null, fm.MOVEFOCUS_CARET, 0); + + is(newFocus, t25, "move caret to link return value"); + is(fm.focusedElement, t25, "move caret to link focusedElement"); + + // enable caret browsing temporarily to test caret movement + var prefs = Components.classes["@mozilla.org/preferences-service;1"]. + getService(Components.interfaces.nsIPrefBranch); + prefs.setBoolPref("accessibility.browsewithcaret", true); + + synthesizeKey("VK_LEFT", { }, gChildWindow); + synthesizeKey("VK_LEFT", { }, gChildWindow); + is(fm.focusedElement, null, "move caret away from link"); + + synthesizeKey("VK_LEFT", { }, gChildWindow); + is(fm.focusedElement, getById("t24"), "move caret away onto link"); + + prefs.setBoolPref("accessibility.browsewithcaret", false); + + // cases where focus in on a content node with no frame + + if (!gPartialTabbing) { + getById("t24").blur(); + gEvents = ""; + gLastFocus = null; + gLastFocusWindow = gChildWindow; + gLastFocusMethod = fm.FLAG_BYKEY; + + selection.selectAllChildren(getById("hiddenspan")); + expectFocusShift(() => synthesizeKey("VK_TAB", { }), + gChildWindow, getById("t26"), true, "tab with selection on hidden content"); + + setFocusTo($("o15"), window); + $("o15").hidden = true; + document.documentElement.getBoundingClientRect(); // flush after hiding + expectFocusShift(() => synthesizeKey("VK_TAB", { }), + window, $("o17"), true, "tab with focus on hidden content"); + + $("o17").hidden = true; + document.documentElement.getBoundingClientRect(); + expectFocusShift(() => synthesizeKey("VK_TAB", { shiftKey: true }), + window, $("o13"), true, "shift+tab with focus on hidden content"); + } + + // cases with selection in an <input> + + var t19 = getById("t19"); + t19.setSelectionRange(0, 0); + setFocusTo("t18", gChildWindow); + + gLastFocusMethod = fm.FLAG_BYMOVEFOCUS; + expectFocusShift(() => newFocus = fm.moveFocus(null, null, fm.MOVEFOCUS_FORWARD, 0), + gChildWindow, t19, true, "moveFocus to next textbox"); + is(t19.selectionStart, 0, "input focused after moveFocus selectionStart"); + is(t19.selectionEnd, 5, "input focused after moveFocus selectionEnd"); + + t19.setSelectionRange(0, 0); + setFocusTo("t18", gChildWindow); + gLastFocusMethod = fm.FLAG_BYKEY; + expectFocusShift(() => newFocus = fm.moveFocus(null, null, fm.MOVEFOCUS_FORWARD, fm.FLAG_BYKEY), + gChildWindow, t19, true, "moveFocus to next textbox by key"); + is(t19.selectionStart, 0, "input focused after moveFocus by key selectionStart"); + is(t19.selectionEnd, 5, "input focused after moveFocus by key selectionEnd"); +} + +function otherWindowFocused(otherWindow) +{ + var expectedElement = getById("t9"); + + is(fm.activeWindow, otherWindow, "other activeWindow"); + is(fm.focusedWindow, otherWindow, "other focusedWindow"); + is(window.document.hasFocus(), false, "when lowered document hasFocus"); + var focusedWindow = {}; + is(fm.getFocusedElementForWindow(window, false, focusedWindow), + expectedElement, "when lowered getFocusedElementForWindow"); + is(focusedWindow.value, window, "when lowered getFocusedElementForWindow frame"); + is(document.activeElement.id, expectedElement.id, "when lowered activeElement"); + is(window.document.commandDispatcher.focusedWindow, window, " commandDispatcher in other window focusedWindow"); + is(window.document.commandDispatcher.focusedElement, expectedElement, " commandDispatcher in other window focusedElement"); + + compareEvents("deactivate: outer-document-window blur: t9 blur: outer-document blur: outer-window", + otherWindow, null, "other window opened"); + + otherWindow.document.getElementById("other").focus(); + + for (var idx = kTabbableSteps; idx >= 1; idx--) { + expectedElement = getById("t" + idx); + if (!expectedElement) // skip elements that were removed in doRemoveTests() + continue; + if ((navigator.platform.indexOf("Mac") == 0) && (idx == kBeforeTabboxIndex + 1)) + continue; + + expectedElement.focus(); + + is(fm.focusedElement.id, "other", "when lowered focusedElement t" + idx); + is(fm.focusedWindow, otherWindow, "when lowered focusedWindow t" + idx); + + var checkWindow = expectedElement.ownerDocument.defaultView; + is(fm.getFocusedElementForWindow(checkWindow, false, {}).id, expectedElement.id, + "when lowered getFocusedElementForWindow t" + idx); + is(checkWindow.document.activeElement.id, expectedElement.id, "when lowered activeElement t" + idx); + if (checkWindow != window) { + is(fm.getFocusedElementForWindow(window, false, {}), $("childframe"), + "when lowered parent getFocusedElementForWindow t" + idx); + is(document.activeElement.id, "childframe", + "when lowered parent activeElement t" + idx); + } + } + + gEvents = gEvents.replace(/commandupdate: cu\s?/g, ""); + is(gEvents, "", "when lowered no events fired"); + + var other = otherWindow.document.getElementById("other"); + other.focus(); + is(fm.focusedElement, other, "focus method in second window"); + + otherWindow.close(); + + getById("n2").focus(); + + // next, check modal dialogs + // XXXndeakin Bug 621399 - the modal dialog test as well as later tests sometime fail + // on Windows 8 so just end the test here. + if (navigator.userAgent.indexOf("Windows NT 6.2") >= 0) { + done(); + } + else { + window.openDialog("focus_window2.xul", "_blank", "chrome,modal", modalWindowOpened); + } +} + +function modalWindowOpened(modalWindow) +{ + var elem = modalWindow.document.getElementById("other"); + if (gPartialTabbing) + elem.focus(); + else + synthesizeKey("VK_TAB", { }, modalWindow); + is(fm.activeWindow, modalWindow, "modal activeWindow"); + is(fm.focusedElement, elem, "modal focusedElement"); + + modalWindow.close(); + SimpleTest.waitForFocus(modalWindowClosed); +} + +function modalWindowClosed() +{ + is(fm.activeWindow, window, "modal window closed activeWindow"); + is(fm.focusedElement, getById("n2"), "modal window closed focusedElement"); + + window.open("focus_frameset.html", "_blank", "width=400,height=400,toolbar=no"); +} + +function framesetWindowLoaded(framesetWindow) +{ + gLastFocus = null; + gLastFocusWindow = framesetWindow; + gEvents = ""; + + is(fm.activeWindow, getTopWindow(framesetWindow), "frameset window active"); + gOldExpectedWindow = getTopWindow(framesetWindow); + + gMoveToFocusFrame = true; + for (var idx = 1; idx <= 8; idx++) { + gNewExpectedWindow = framesetWindow.frames[(idx - 1) >> 1]; + if (idx % 2) + initEvents(gNewExpectedWindow); + expectFocusShift(() => synthesizeKey("VK_TAB", { }, framesetWindow), + gNewExpectedWindow, getById("f" + idx), true, "frameset tab key f" + idx); + gMoveToFocusFrame = false; + gOldExpectedWindow = gNewExpectedWindow; + } + + gNewExpectedWindow = framesetWindow.frames[0]; + expectFocusShift(() => synthesizeKey("VK_TAB", { }, framesetWindow), + gNewExpectedWindow, getById("f1"), true, "frameset tab key wrap to start"); + gOldExpectedWindow = gNewExpectedWindow; + gNewExpectedWindow = framesetWindow.frames[3]; + expectFocusShift(() => synthesizeKey("VK_TAB", { shiftKey: true }, framesetWindow), + gNewExpectedWindow, getById("f8"), true, "frameset shift tab key wrap to end"); + + for (idx = 7; idx >= 1; idx--) { + gOldExpectedWindow = gNewExpectedWindow; + gNewExpectedWindow = framesetWindow.frames[(idx - 1) >> 1]; + expectFocusShift(() => synthesizeKey("VK_TAB", { shiftKey: true }, framesetWindow), + gNewExpectedWindow, getById("f" + idx), true, "frameset shift tab key f" + idx); + } + + // document shifting + // XXXndeakin P3 ctrl+tab doesn't seem to be testable currently for some reason + gNewExpectedWindow = framesetWindow.frames[1]; + expectFocusShift(() => synthesizeKey("VK_F6", { ctrlKey: true }, framesetWindow), + gNewExpectedWindow, getById("f3"), true, "switch document forward with f6"); + gOldExpectedWindow = gNewExpectedWindow; + gNewExpectedWindow = framesetWindow.frames[2]; + expectFocusShift(() => synthesizeKey("VK_F6", { }, framesetWindow), + gNewExpectedWindow, getById("f5"), true, "switch document forward with ctrl+tab"); + gOldExpectedWindow = gNewExpectedWindow; + gNewExpectedWindow = framesetWindow.frames[3]; + expectFocusShift(() => synthesizeKey("VK_F6", { ctrlKey: true }, framesetWindow), + gNewExpectedWindow, getById("f7"), true, "switch document forward with ctrl+f6"); + gOldExpectedWindow = gNewExpectedWindow; + gNewExpectedWindow = framesetWindow.frames[0]; + expectFocusShift(() => synthesizeKey("VK_F6", { ctrlKey: true }, framesetWindow), + gNewExpectedWindow, getById("f1"), true, "switch document forward and wrap"); + +// going backwards by document and wrapping doesn't currently work, but didn't work +// before the focus reworking either + +/* + gOldExpectedWindow = gNewExpectedWindow; + gNewExpectedWindow = framesetWindow.frames[3]; + expectFocusShift(() => synthesizeKey("VK_F6", { ctrlKey: true, shiftKey: true }, framesetWindow), + gNewExpectedWindow, getById("f7"), true, "switch document backward and wrap"); + */ + + fm.moveFocus(framesetWindow.frames[3], null, fm.MOVEFOCUS_ROOT, 0); + gEvents = ""; + + gOldExpectedWindow = gNewExpectedWindow; + gNewExpectedWindow = framesetWindow.frames[2]; + expectFocusShift(() => synthesizeKey("VK_F6", { ctrlKey: true, shiftKey: true }, framesetWindow), + gNewExpectedWindow, getById("f5"), true, "switch document backward with f6"); + gOldExpectedWindow = gNewExpectedWindow; + gNewExpectedWindow = framesetWindow.frames[1]; + expectFocusShift(() => synthesizeKey("VK_F6", { ctrlKey: true, shiftKey: true }, framesetWindow), + gNewExpectedWindow, getById("f3"), true, "switch document backward with ctrl+tab"); + gOldExpectedWindow = gNewExpectedWindow; + gNewExpectedWindow = framesetWindow.frames[0]; + expectFocusShift(() => synthesizeKey("VK_F6", { ctrlKey: true, shiftKey: true }, framesetWindow), + gNewExpectedWindow, getById("f1"), true, "switch document backward with ctrl+f6"); + + // skip the window switching tests for now on Linux, as raising and lowering + // a window is asynchronous there + if (navigator.platform.indexOf("Linux") == -1) { + window.openDialog("focus_window2.xul", "_blank", "chrome", switchWindowTest, framesetWindow); + } + else { + gOldExpectedWindow = null; + gNewExpectedWindow = null; + framesetWindow.close(); + SimpleTest.waitForFocus(doWindowNoRootTest); + } +} + +// test switching between two windows +function switchWindowTest(otherWindow, framesetWindow) +{ + initEvents(otherWindow); + var otherElement = otherWindow.document.getElementById("other"); + otherElement.focus(); + + framesetWindow.frames[1].document.getElementById("f4").focus(); + + is(fm.focusedElement, otherElement, "focus after inactive window focus"); + + gLastFocus = otherElement; + gLastFocusWindow = otherWindow; + gEvents = ""; + gOldExpectedWindow = otherWindow; + gNewExpectedWindow = framesetWindow.frames[1]; + + expectFocusShift(() => gNewExpectedWindow.focus(), + gNewExpectedWindow, getById("f4"), true, "switch to frame in another window"); + is(fm.getFocusedElementForWindow(otherWindow, false, {}).id, "other", "inactive window has focused element"); + + gOldExpectedWindow = framesetWindow.frames[1]; + gNewExpectedWindow = otherWindow; + expectFocusShift(() => otherWindow.focus(), + gNewExpectedWindow, getById("other"), true, "switch to another window"); + + var exh = false; + try { + fm.activeWindow = framesetWindow.frames[0]; + } + catch (ex) { exh = true; } + is(exh, true, "activeWindow set to non top-level window"); + + exh = false; + try { + fm.activeWindow = null; + } + catch (ex) { exh = true; } + is(exh, true, "activeWindow set to null"); + is(fm.activeWindow, otherWindow, "window not changed when activeWindow set to null"); + + var topWindow = getTopWindow(framesetWindow); + + ok(topWindow.document.commandDispatcher.getControllerForCommand("cmd_copy"), + "getControllerForCommand for focused window set"); + ok(otherWindow.document.commandDispatcher.getControllerForCommand("cmd_copy"), + "getControllerForCommand for non-focused window set"); + ok(topWindow.document.commandDispatcher.getControllerForCommand("cmd_copy") != + otherWindow.document.commandDispatcher.getControllerForCommand("cmd_copy"), + "getControllerForCommand for two windows different"); + ok(topWindow.document.commandDispatcher.getControllers() != + otherWindow.document.commandDispatcher.getControllers(), + "getControllers for two windows different"); + + gOldExpectedWindow = otherWindow; + gNewExpectedWindow = framesetWindow.frames[1]; + expectFocusShift(() => fm.activeWindow = topWindow, + gNewExpectedWindow, getById("f4"), true, "switch to frame activeWindow"); + + fm.clearFocus(otherWindow); + gOldExpectedWindow = gNewExpectedWindow; + gNewExpectedWindow = otherWindow; + expectFocusShift(() => fm.setFocus(otherElement, fm.FLAG_RAISE), + gNewExpectedWindow, getById("other"), true, "switch to window with raise"); + + getTopWindow(framesetWindow).document.commandDispatcher.focusedWindow = gOldExpectedWindow; + is(fm.activeWindow, gNewExpectedWindow, "setting commandDispatcher focusedWindow doesn't raise window"); + + fm.moveFocus(otherWindow, null, fm.MOVEFOCUS_FORWARD, 0); + var otherTextbox = otherWindow.document.getElementById("other-textbox"); + otherTextbox.setSelectionRange(2, 3); + fm.activeWindow = topWindow; + fm.activeWindow = otherWindow; + is(otherTextbox.selectionStart, 2, "selectionStart after textbox focus and window raise"); + is(otherTextbox.selectionEnd, 3, "selectionEnd after textbox focus and window raise"); + is(fm.getLastFocusMethod(null), fm.FLAG_BYMOVEFOCUS, "last focus method after textbox focus and window raise"); + + fm.clearFocus(otherWindow); + + // test to ensure that a synthetic event works + var synevent = document.createEvent("Event"); + synevent.initEvent("focus", false, false); + otherTextbox.inputField.dispatchEvent(synevent); + is(synevent.type, "focus", "event.type after synthetic focus event"); + is(synevent.target, otherTextbox, "event.target after synthetic focus event"); + is(fm.focusedElement, null, "focusedElement after synthetic focus event"); + is(otherWindow.document.activeElement, otherWindow.document.documentElement, + "document.activeElement after synthetic focus event"); + + // check accessing a focus event after the event has finishing firing + function continueTest(event) { + is(event.type, "focus", "event.type after accessing focus event in timeout"); + is(event.target, otherTextbox, "event.target after accessing focus event in timeout"); + + gOldExpectedWindow = null; + gNewExpectedWindow = null; + otherWindow.close(); + framesetWindow.close(); + + SimpleTest.waitForFocus(doWindowNoRootTest); + } + + function textboxFocused(event) { + otherTextbox.removeEventListener("focus", textboxFocused, true); + setTimeout(continueTest, 0, event); + } + + otherTextbox.addEventListener("focus", textboxFocused, true); + otherTextbox.focus(); +} + +// open a window with no root element +var noRootWindow = null; +function doWindowNoRootTest() +{ + var data = "data:application/vnd.mozilla.xul+xml," + unescape( + "<window onfocus='dostuff()' xmlns='http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul'" + + " style='-moz-user-focus: normal;'>" + + "<script>function dostuff() { setTimeout(function() { " + + "document.documentElement.focus(); document.removeChild(document.documentElement);" + + "window.opener.focus(); }, 100); }</script></window>"); + + addEventListener("focus", doFrameSwitchingTests, true); + noRootWindow = window.open(data, "_blank", "chrome,width=100,height=100"); +} + +// these tests check when focus is moved between a tree of frames to ensure +// that the focus is in the right place at each event step. +function doFrameSwitchingTests() +{ + removeEventListener("focus", doFrameSwitchingTests, true); + noRootWindow.close(); + + var framea = document.getElementById("ifa"); + var frameb = document.getElementById("ifb"); + framea.style.MozUserFocus = ""; + frameb.style.MozUserFocus = ""; + + window.removeEventListener("focus", eventOccured, true); + window.removeEventListener("blur", eventOccured, true); + + var inputa = framea.contentDocument.body.firstChild; + inputa.focus(); + + addFrameSwitchingListeners(framea); + addFrameSwitchingListeners(frameb); + var framec = framea.contentDocument.body.lastChild; + addFrameSwitchingListeners(framec); + + var framed = framec.contentDocument.body.lastChild; + addFrameSwitchingListeners(framed); + + var inputc = framec.contentDocument.body.firstChild; + + var expectedMainWindowFocus = framea; + + // An element in the immediate parent frame is focused. Focus an element in + // the child. The child should be focused and the parent's current focus should + // be the child iframe. + gEventMatched = true; + is(fm.getFocusedElementForWindow(window, false, {}), expectedMainWindowFocus, + "parent of framea has iframe focused"); + gExpectedEvents = [[inputa, "blur", null, framea.contentWindow, window, framea], + [framea.contentDocument, "blur", null, null, window, framea], + [framea.contentWindow, "blur", null, null, window, framea], + [framec.contentDocument, "focus", null, framec.contentWindow, window, framea], + [framec.contentWindow, "focus", null, framec.contentWindow, window, framea], + [inputc, "focus", inputc, framec.contentWindow, window, framea]]; + inputc.focus(); + ok(gEventMatched && gExpectedEvents.length == 0, "frame switch from parent input to child input" + gExpectedEvents); + + // An element in a child is focused. Focus an element in the immediate + // parent. + gEventMatched = true; + gExpectedEvents = [[inputc, "blur", null, framec.contentWindow, window, framea], + [framec.contentDocument, "blur", null, null, window, framea], + [framec.contentWindow, "blur", null, null, window, framea], + [framea.contentDocument, "focus", null, framea.contentWindow, window, framea], + [framea.contentWindow, "focus", null, framea.contentWindow, window, framea], + [inputa, "focus", inputa, framea.contentWindow, window, framea]]; + inputa.focus(); + ok(gEventMatched && gExpectedEvents.length == 0, "frame switch from child input to parent input"); + + // An element in a frame is focused. Focus an element in a sibling frame. + // The common ancestor of the two frames should have its focused node + // cleared after the element is blurred. + var inputb = frameb.contentDocument.body.firstChild; + + gEventMatched = true; + gExpectedEvents = [[inputa, "blur", null, framea.contentWindow, window, framea], + [framea.contentDocument, "blur", null, null, window, null], + [framea.contentWindow, "blur", null, null, window, null], + [frameb.contentDocument, "focus", null, frameb.contentWindow, window, frameb], + [frameb.contentWindow, "focus", null, frameb.contentWindow, window, frameb], + [inputb, "focus", inputb, frameb.contentWindow, window, frameb]]; + inputb.focus(); + ok(gEventMatched && gExpectedEvents.length == 0, "frame switch from input to sibling frame"); + is(fm.getFocusedElementForWindow(framea.contentWindow, false, {}), inputa, + "blurred frame still has input as focus"); + + // focus a descendant in a sibling + var inputd = framed.contentDocument.body.firstChild; + gEventMatched = true; + gExpectedEvents = [[inputb, "blur", null, frameb.contentWindow, window, frameb], + [frameb.contentDocument, "blur", null, null, window, null], + [frameb.contentWindow, "blur", null, null, window, null], + [framed.contentDocument, "focus", null, framed.contentWindow, window, framea], + [framed.contentWindow, "focus", null, framed.contentWindow, window, framea], + [inputd, "focus", inputd, framed.contentWindow, window, framea]]; + inputd.focus(); + ok(gEventMatched && gExpectedEvents.length == 0, "frame switch from input to sibling descendant"); + is(fm.getFocusedElementForWindow(framea.contentWindow, false, {}), framec, + "sibling parent focus has shifted to frame"); + + // focus an ancestor + gEventMatched = true; + gExpectedEvents = [[inputd, "blur", null, framed.contentWindow, window, framea], + [framed.contentDocument, "blur", null, null, window, framea], + [framed.contentWindow, "blur", null, null, window, framea], + [framea.contentDocument, "focus", null, framea.contentWindow, window, framea], + [framea.contentWindow, "focus", null, framea.contentWindow, window, framea], + [inputa, "focus", inputa, framea.contentWindow, window, framea]]; + inputa.focus(); + ok(gEventMatched && gExpectedEvents.length == 0, "frame switch from child input to ancestor"); + + // focus a descendant + gEventMatched = true; + gExpectedEvents = [[inputa, "blur", null, framea.contentWindow, window, framea], + [framea.contentDocument, "blur", null, null, window, framea], + [framea.contentWindow, "blur", null, null, window, framea], + [framed.contentDocument, "focus", null, framed.contentWindow, window, framea], + [framed.contentWindow, "focus", null, framed.contentWindow, window, framea], + [inputd, "focus", inputd, framed.contentWindow, window, framea]]; + inputd.focus(); + ok(gEventMatched && gExpectedEvents.length == 0, "frame switch from child input to ancestor"); + is(fm.getFocusedElementForWindow(framea.contentWindow, false, {}), framec, + "parent focus has shifted to frame"); + + // focus a sibling frame by setting focusedWindow + gEventMatched = true; + gExpectedEvents = [[inputd, "blur", null, framed.contentWindow, window, framea], + [framed.contentDocument, "blur", null, null, window, null], + [framed.contentWindow, "blur", null, null, window, null], + [frameb.contentDocument, "focus", null, frameb.contentWindow, window, frameb], + [frameb.contentWindow, "focus", null, frameb.contentWindow, window, frameb], + [inputb, "focus", inputb, frameb.contentWindow, window, frameb]]; + fm.focusedWindow = frameb.contentWindow; + ok(gEventMatched && gExpectedEvents.length == 0, "frame switch using focusedWindow"); + + // clear the focus in an unfocused frame + gEventMatched = true; + gExpectedEvents = []; + fm.clearFocus(framec.contentWindow); + ok(gEventMatched && gExpectedEvents.length == 0, "clearFocus in unfocused frame"); + + // focus a sibling frame by setting focusedWindow when no element is focused in that frame + gEventMatched = true; + gExpectedEvents = [[inputb, "blur", null, frameb.contentWindow, window, frameb], + [frameb.contentDocument, "blur", null, null, window, null], + [frameb.contentWindow, "blur", null, null, window, null], + [framec.contentDocument, "focus", null, framec.contentWindow, window, framea], + [framec.contentWindow, "focus", null, framec.contentWindow, window, framea]]; + fm.focusedWindow = framec.contentWindow; + ok(gEventMatched && gExpectedEvents.length == 0, "frame switch using focusedWindow with no element focused"); + is(fm.getFocusedElementForWindow(framea.contentWindow, false, {}), framec, + "parent focus has shifted to frame using focusedWindow"); + + // focus the parent frame by setting focusedWindow. This should have no effect. + gEventMatched = true; + gExpectedEvents = []; + fm.focusedWindow = framea.contentWindow; + ok(gEventMatched && gExpectedEvents.length == 0, "frame switch to parent using focusedWindow"); + + // clear the focus in the parent frame + gEventMatched = true; + gExpectedEvents = [[framec.contentDocument, "blur", null, null, window, framea], + [framec.contentWindow, "blur", null, null, window, framea], + [framea.contentDocument, "focus", null, framea.contentWindow, window, framea], + [framea.contentWindow, "focus", null, framea.contentWindow, window, framea]]; + fm.clearFocus(framea.contentWindow); + ok(gEventMatched && gExpectedEvents.length == 0, "clearFocus in parent frame"); + + // clear the focus in an unfocused child frame + gEventMatched = true; + gExpectedEvents = []; + fm.clearFocus(framed.contentWindow); + ok(gEventMatched && gExpectedEvents.length == 0, "clearFocus in unfocused child frame"); + + var exh = false; + try { + fm.focusedWindow = null; + } + catch (ex) { exh = true; } + is(exh, true, "focusedWindow set to null"); + is(fm.focusedWindow, framea.contentWindow, "window not changed when focusedWindow set to null"); + + doFrameHistoryTests() +} + +function doFrameHistoryTests() +{ + var t20 = getById("t20"); + t20.focus(); + + gChildWindow.addEventListener("focus", + function(event) { + if (event.target == t20) { + is(fm.focusedElement, t20, "focus restored after history back"); done(); + } + }, true); + + // make sure that loading a new page and then going back maintains the focus + gChildWindow.location = "data:text/html,<script>window.onload=function() {setTimeout(function () {SpecialPowers.wrap(window).back();}, 0);}</script>"; +} + +function addFrameSwitchingListeners(frame) +{ + frame.contentWindow.addEventListener("focus", frameSwitchingEventOccured, false); + frame.contentWindow.addEventListener("blur", frameSwitchingEventOccured, false); + frame.contentDocument.addEventListener("focus", frameSwitchingEventOccured, false); + frame.contentDocument.addEventListener("blur", frameSwitchingEventOccured, false); + + var node = frame.contentDocument.body.firstChild; + node.addEventListener("focus", frameSwitchingEventOccured, false); + node.addEventListener("blur", frameSwitchingEventOccured, false); +} + +function frameSwitchingEventOccured(event) +{ + if (!gExpectedEvents.length) { + gEventMatched = false; + return; + } + + try { + var events = gExpectedEvents.shift(); + is(event.target, events[0], "event target"); + is(event.type, events[1], "event type"); + is(fm.focusedElement, events[2], "focused element"); + is(fm.focusedWindow, events[3], "focused frame"); + if (events[4]) + is(fm.getFocusedElementForWindow(events[4], false, {}), events[5], "focused element in frame"); + + if (gEventMatched && event.target == events[0] && event.type == events[1] && + fm.focusedElement == events[2] && fm.focusedWindow == events[3]) { + if (!events[4] || fm.getFocusedElementForWindow(events[4], false, {}) == events[5]) + return; + } + } catch (ex) { ok(ex, "exception"); } + + gEventMatched = false; +} + +SimpleTest.waitForExplicitFinish(); +SimpleTest.waitForFocus(startTest); + +]]> +</script> + +<commandset id="cu" + commandupdater="true" + events="focus" + oncommandupdate="eventOccured(event)"/> + +<!-- + The elements with ids starting with t are focusable and in the taborder. + The elements with ids starting with o are: + odd numbered ids - focusable but not part of the tab order + even numbered ids - not focusable with -moz-user-focus: ignore or disabled + The elements with ids starting with n are: + odd numbered ids - not focusable with -moz-user-focus: none + even numbered ids - focusable but not part of the tab order + --> +<vbox id="buttonbox"> +<hbox id="innerbox"> + <button id="t4" accesskey="h" label="no tabindex"/> + <button id="o1" accesskey="i" label="tabindex = -1" tabindex="-1"/> + <listbox id="t5" label="tabindex = 0" tabindex="0" rows="1"> + <listitem/> + </listbox> + <button id="t1" label="tabindex = 2" tabindex="2"/> +</hbox> +<hbox> + <button id="o2" accesskey="o" style="-moz-user-focus: ignore;" label="no tabindex"/> + <button id="o4" style="-moz-user-focus: ignore;" label="tabindex = -1" tabindex="-1"/> + <button id="t6" style="-moz-user-focus: ignore;" label="tabindex = 0" tabindex="0"/> + <button id="t2" style="-moz-user-focus: ignore;" label="tabindex = 2" tabindex="2"/> +</hbox> +<hbox id="specialroot"> + <button id="t7" style="-moz-user-focus: normal;" label="no tabindex"/> + <button id="o3" style="-moz-user-focus: normal;" label="tabindex = -1" tabindex="-1"/> + <button id="t8" style="-moz-user-focus: normal;" label="tabindex = 0" tabindex="0"/> + <listbox id="t3" style="-moz-user-focus: normal;" label="tabindex = 2" tabindex="2" rows="1"> + <listitem/> + </listbox> +</hbox> +<hbox> + <button accesskey="p" style="display: none;"/> <button accesskey="q" style="visibility: collapse;"/> + <button style="display: none;" tabindex="2"/> <button style="visibility: collapse;" tabindex="2"/> +</hbox> +<hbox> + <button id="o20" accesskey="s" label="no tabindex" disabled="true"/> + <button id="o22" label="tabindex = -1" tabindex="-1" disabled="true"/> + <button id="o24" label="tabindex = 0" tabindex="0" disabled="true"/> + <button id="o26" label="tabindex = 2" tabindex="2" disabled="true"/> +</hbox> +</vbox> +<vbox> +<hbox> + <dropmarker id="o6" value="no tabindex"/> + <dropmarker id="o8" value="tabindex = -1" tabindex="-1"/> + <dropmarker id="o10" value="tabindex = 0" tabindex="0"/> + <dropmarker id="o12" value="tabindex = 2" tabindex="2"/> + <dropmarker id="t9" accesskey="r" style="-moz-user-focus: normal;" value="no tabindex" /> + <dropmarker id="t10" style="-moz-user-focus: normal;" value="tabindex = -1" tabindex="-1" /> + <dropmarker id="t11" style="-moz-user-focus: normal;" value="tabindex = 0" tabindex="0" /> + <dropmarker id="t12" style="-moz-user-focus: normal;" value="tabindex = 2" tabindex="2" /> + <dropmarker id="o14" style="-moz-user-focus: ignore;" value="no tabindex"/> + <dropmarker id="o16" style="-moz-user-focus: ignore;" value="tabindex = -1" tabindex="-1"/> + <dropmarker id="n1" style="-moz-user-focus: none;" value="tabindex = 0" tabindex="0"/> + <dropmarker id="n3" style="-moz-user-focus: none;" value="tabindex = 2" tabindex="2"/> +</hbox> +</vbox> +<browser id="childframe" type="content" src="child_focus_frame.html" width="300" height="195"/> +<button id="t34"/> +<tabbox id="tabbox"> + <tabs><tab id="t35" label="One"/><tab id="tab2" label="Two"/></tabs> + <tabpanels> + <tabpanel> + <checkbox id="t36"/> + <button id="t37"/> + </tabpanel> + <tabpanel> + <checkbox id="htab1"/> + <button id="nohtab2" tabindex="7"/> + <checkbox id="htab2" tabindex="0"/> + </tabpanel> + </tabpanels> +</tabbox> +<hbox> +<panel> + <button id="inpopup1" label="One"/> + <textbox label="Two"/> +</panel> +<description label="o" accesskey="v"/> +<button id="t38"/> +<!-- The 't' element tests end here so it doesn't matter that these elements are tabbable --> +<label id="aj" value="j" accesskey="j" control="o9"/> +<label id="ak" accesskey="k" control="n4">k</label> +<checkbox id="o5"/><checkbox id="o7"/><hbox><checkbox id="o9"/></hbox> +<checkbox id="o13"/><checkbox id="o15"/><checkbox id="o17"/><checkbox id="o19"/><checkbox id="o21"/><checkbox id="o23"/><checkbox id="o25"/> +<checkbox id="n2"/><checkbox id="n4"/> +<listbox id="last" width="20" rows="1"/> + +<iframe id="ifa" width="40" height="60" style="-moz-user-focus: ignore;" type="content" + src="data:text/html,<input id=fra size='2'><input id='fra-b' size='2'> + <iframe src='data:text/html,<input id=frc><iframe src="data:text/html,<input id=frd>"></iframe>'></iframe>"/> +<iframe id="ifb" width="20" height="20" style="-moz-user-focus: ignore;" + src="data:text/html,<input id=frd></iframe>"/> + +</hbox> +</window> diff --git a/dom/tests/mochitest/chrome/window_focus_docnav.xul b/dom/tests/mochitest/chrome/window_focus_docnav.xul new file mode 100644 index 000000000..a4e0a5691 --- /dev/null +++ b/dom/tests/mochitest/chrome/window_focus_docnav.xul @@ -0,0 +1,126 @@ +<?xml version="1.0"?> +<?xml-stylesheet href="chrome://global/skin" type="text/css"?> + +<window onload="start()" + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> + +<script type="application/javascript" + src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/> + +<textbox id="textbox1"/> +<textbox id="textbox2"/> + +<panel id="panel" onpopupshown="runTests(this, 1);" + onpopuphidden="noChildrenTest()"> + <textbox id="p1textbox" value="Popup1"/> +</panel> +<panel id="panel2" onpopupshown="runTests(this, 2);" onpopuphidden="document.getElementById('panel').hidePopup()"> + <textbox id="p2textbox" value="Popup2"/> +</panel> + +<browser id="browser" type="content" src="focus_frameset.html" width="500" height="400"/> + +<script type="application/javascript"> +<![CDATA[ + +var fm = Components.classes["@mozilla.org/focus-manager;1"]. + getService(Components.interfaces.nsIFocusManager); + +function is(l, r, n) { window.opener.wrappedJSObject.SimpleTest.is(l,r,n); } +function ok(v, n) { window.opener.wrappedJSObject.SimpleTest.ok(v,n); } + +function noChildrenTest() +{ + // Remove the browser element and test navigation when there are no other documents. + // The focus should move or stay on the first focusable element. + let browser = document.getElementById("browser"); + browser.parentNode.removeChild(browser); + + let textbox1 = document.getElementById("textbox1"); + let textbox2 = document.getElementById("textbox2"); + + textbox2.focus(); + next(window, textbox1.inputField, "Focus forward when no child documents"); + next(window, textbox1.inputField, "Focus forward again when no child documents"); + + textbox2.focus(); + previous(window, textbox1.inputField, "Focus backward when no child documents"); + previous(window, textbox1.inputField, "Focus backward again when no child documents"); + + done(); +} + +function done() +{ + var opener = window.opener; + window.close(); + opener.wrappedJSObject.SimpleTest.finish(); +} + +function previous(expectedWindow, expectedElement, desc) +{ + synthesizeKey("VK_F6", { shiftKey: true }); + is(fm.focusedWindow, expectedWindow, desc); + is(fm.focusedElement, expectedElement, desc + " element"); +} + +function next(expectedWindow, expectedElement, desc) +{ + synthesizeKey("VK_F6", { }); + is(fm.focusedWindow, expectedWindow, desc); + is(fm.focusedElement, expectedElement, desc + " element" + "::" + (fm.focusedElement ? fm.focusedElement.parentNode.id : "<none>")); +} + +// This test runs through three cases. Document navigation forward and +// backward using the F6 key when no popups are open, with one popup open and +// with two popups open. +function runTests(panel, popupCount) +{ + if (!popupCount || popupCount > 2) + popupCount = 0; + + fm.clearFocus(window); + + var childwin = document.getElementById("browser").contentWindow; + + if (popupCount) { + next(window, document.getElementById("p1textbox").inputField, "First into popup 1 with " + popupCount); + + if (popupCount == 2) { + next(window, document.getElementById("p2textbox").inputField, "First into popup 2 with " + popupCount); + } + } + + next(childwin.frames[0], childwin.frames[0].document.documentElement, "First with " + popupCount); + next(childwin.frames[1], childwin.frames[1].document.documentElement, "Second with " + popupCount); + previous(childwin.frames[0], childwin.frames[0].document.documentElement, "Second back with " + popupCount); + + if (popupCount) { + if (popupCount == 2) { + previous(window, document.getElementById("p2textbox").inputField, "First back from popup 2 with " + popupCount); + } + + previous(window, document.getElementById("p1textbox").inputField, "First back from popup 1 with " + popupCount); + } + + previous(window, document.getElementById("textbox1").inputField, "First back with " + popupCount); + + if (panel == document.getElementById("panel")) + document.getElementById("panel2").openPopup(null, "after_start", 100, 20); + else if (panel == document.getElementById("panel2")) + panel.hidePopup(); + else + document.getElementById("panel").openPopup(null, "after_start"); +} + +function start() +{ + window.opener.wrappedJSObject.SimpleTest.waitForExplicitFinish(); + window.opener.wrappedJSObject.SimpleTest.waitForFocus( + function() { runTests(null, 0); }, + document.getElementById("browser").contentWindow); +} + +]]></script> + +</window> |