Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 <?xml version="1.0"?>
2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
4 <!--
5 https://bugzilla.mozilla.org/show_bug.cgi?id=420499
6 -->
7 <window title="Mozilla Bug 420499" onload="setTimeout(focusInput, 500);"
8 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
9 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
10 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
14 <menu id="menu" label="Menu">
15 <menupopup id="file-popup">
16 <!-- <textbox id="some-text" maxlength="10" value="some text"/> -->
17 <menu label="submenu">
18 <menupopup id="file-popup-inner">
20 <menuitem label="Item1"/>
21 <menuitem label="Item2"/>
22 <textbox id="some-text" maxlength="10" value="some more text"/>
23 </menupopup>
24 </menu>
25 <menuitem label="Item3"/>
26 <menuitem label="Item4"/>
27 </menupopup>
28 </menu>
30 <popupset>
31 <popup id="contextmenu">
32 <menuitem label="Cut"/>
33 <menuitem label="Copy"/>
34 <menuitem label="Paste"/>
35 </popup>
36 <tooltip id="tooltip" orient="vertical">
37 <description value="This is a tooltip"/>
38 </tooltip>
39 </popupset>
41 <!-- test results are displayed in the html:body -->
42 <body xmlns="http://www.w3.org/1999/xhtml" bgcolor="white">
44 <p id="par1">Paragraph 1</p>
45 <p id="par2">Paragraph 2</p>
46 <p id="par3">Paragraph 3</p>
47 <p id="par4">Paragraph 4</p>
48 <p id="par5">Paragraph 5</p>
50 <input type="text" id="text-input" maxlength="10" value="some more text"/> <br />
52 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=420499"
53 target="_blank">Mozilla Bug 420499</a>
54 </body>
56 <!-- test code goes here -->
57 <script type="application/javascript"><![CDATA[
59 /** Test for Bug 420499 **/
60 SimpleTest.waitForExplicitFinish();
62 function getSelectionController() {
63 return document.docShell
64 .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
65 .getInterface(Components.interfaces.nsISelectionDisplay)
66 .QueryInterface(Components.interfaces.nsISelectionController);
67 }
69 function isCaretVisible() {
70 window.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
71 var docShell = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
72 .getInterface(Components.interfaces.nsIWebNavigation)
73 .QueryInterface(Components.interfaces.nsIDocShell);
74 var selCon = docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
75 .getInterface(Components.interfaces.nsISelectionDisplay)
76 .QueryInterface(Components.interfaces.nsISelectionController);
77 return selCon.caretVisible;
78 }
80 function focusInput() {
81 ok(!isCaretVisible(), "Caret shouldn't be visible");
82 $("text-input").focus();
83 ok(isCaretVisible(), "Caret should be visible when input focused");
84 window.addEventListener("popupshown", popupMenuShownHandler, false);
85 $("menu").open = true;
86 }
88 function popupMenuShownHandler() {
89 window.removeEventListener("popupshown", popupMenuShownHandler, false);
90 ok(!isCaretVisible(), "Caret shouldn't be visible when menu open");
91 window.addEventListener("popuphidden", ensureParagraphFocused, false);
92 $("menu").open = false;
93 }
95 function ensureParagraphFocused() {
96 window.removeEventListener("popuphidden", ensureParagraphFocused, false);
97 ok(isCaretVisible(), "Caret should have returned to previous focus");
98 window.addEventListener("popupshown", popupMenuShownHandler2, false);
99 $("contextmenu").openPopup($('text-input'), "topleft" , -1 , -1 , true, true);
100 }
102 function popupMenuShownHandler2() {
103 window.removeEventListener("popupshown", popupMenuShownHandler2, false);
104 ok(isCaretVisible(), "Caret should be visible when context menu open");
105 window.addEventListener("popuphidden", ensureParagraphFocused2, false);
106 document.getElementById("contextmenu").hidePopup();
107 }
109 function ensureParagraphFocused2() {
110 window.removeEventListener("popuphidden", ensureParagraphFocused2, false);
111 ok(isCaretVisible(), "Caret should still be visible");
112 window.addEventListener("popupshown", tooltipShownHandler, false);
113 $("tooltip").openPopup($('text-input'), "topleft" , -1 , -1 , false, true);
114 }
116 function tooltipShownHandler() {
117 window.removeEventListener("popupshown", tooltipShownHandler, false);
118 ok(isCaretVisible(), "Caret should be visible when tooltip is visible");
119 window.addEventListener("popuphidden", ensureParagraphFocused3, false);
120 document.getElementById("tooltip").hidePopup();
121 }
123 function ensureParagraphFocused3() {
124 window.removeEventListener("popuphidden", ensureParagraphFocused2, false);
125 ok(isCaretVisible(), "Caret should still be visible");
126 SimpleTest.finish();
127 }
128 ]]></script>
129 </window>