test_bug420499.xhtml (4704B)
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 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> 10 <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> 11 12 13 14 <menu id="menu" label="Menu"> 15 <menupopup id="file-popup"> 16 <!-- <input xmlns="http://www.w3.org/1999/xhtml" id="some-text" maxlength="10" value="some text"/> --> 17 <menu label="submenu"> 18 <menupopup id="file-popup-inner"> 19 20 <menuitem label="Item1"/> 21 <menuitem label="Item2"/> 22 <input xmlns="http://www.w3.org/1999/xhtml" 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> 29 30 <popupset> 31 <menupopup id="contextmenu"> 32 <menuitem label="Cut"/> 33 <menuitem label="Copy"/> 34 <menuitem label="Paste"/> 35 </menupopup> 36 <tooltip id="tooltip" orient="vertical"> 37 <description value="This is a tooltip"/> 38 </tooltip> 39 </popupset> 40 41 <!-- test results are displayed in the html:body --> 42 <body xmlns="http://www.w3.org/1999/xhtml" bgcolor="white"> 43 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> 49 50 <input type="text" id="text-input" maxlength="10" value="some more text"/> <br /> 51 52 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=420499" 53 target="_blank">Mozilla Bug 420499</a> 54 </body> 55 56 <!-- test code goes here --> 57 <script type="application/javascript"><![CDATA[ 58 59 /** Test for Bug 420499 */ 60 SimpleTest.waitForExplicitFinish(); 61 62 function getSelectionController() { 63 return window.docShell 64 .QueryInterface(Ci.nsIInterfaceRequestor) 65 .getInterface(Ci.nsISelectionDisplay) 66 .QueryInterface(Ci.nsISelectionController); 67 } 68 69 function isCaretVisible() { 70 var docShell = window.docShell; 71 var selCon = docShell.QueryInterface(Ci.nsIInterfaceRequestor) 72 .getInterface(Ci.nsISelectionDisplay) 73 .QueryInterface(Ci.nsISelectionController); 74 return selCon.caretVisible; 75 } 76 77 function focusInput() { 78 ok(!isCaretVisible(), "Caret shouldn't be visible"); 79 $("text-input").focus(); 80 ok(isCaretVisible(), "Caret should be visible when input focused"); 81 window.addEventListener("popupshown", popupMenuShownHandler); 82 $("menu").open = true; 83 } 84 85 function popupMenuShownHandler() { 86 window.removeEventListener("popupshown", popupMenuShownHandler); 87 ok(isCaretVisible(), "Caret shouldn't be visible when menu open"); 88 window.addEventListener("popuphidden", ensureParagraphFocused); 89 $("menu").open = false; 90 } 91 92 function ensureParagraphFocused() { 93 window.removeEventListener("popuphidden", ensureParagraphFocused); 94 ok(isCaretVisible(), "Caret should have returned to previous focus"); 95 window.addEventListener("popupshown", popupMenuShownHandler2); 96 $("contextmenu").openPopup($('text-input'), "topleft" , -1 , -1 , true, true); 97 } 98 99 function popupMenuShownHandler2() { 100 window.removeEventListener("popupshown", popupMenuShownHandler2); 101 ok(isCaretVisible(), "Caret should be visible when context menu open"); 102 window.addEventListener("popuphidden", ensureParagraphFocused2); 103 document.getElementById("contextmenu").hidePopup(); 104 } 105 106 function ensureParagraphFocused2() { 107 window.removeEventListener("popuphidden", ensureParagraphFocused2); 108 ok(isCaretVisible(), "Caret should still be visible"); 109 window.addEventListener("popupshown", tooltipShownHandler); 110 $("tooltip").openPopup($('text-input'), "topleft" , -1 , -1 , false, true); 111 } 112 113 function tooltipShownHandler() { 114 window.removeEventListener("popupshown", tooltipShownHandler); 115 ok(isCaretVisible(), "Caret should be visible when tooltip is visible"); 116 window.addEventListener("popuphidden", ensureParagraphFocused3); 117 document.getElementById("tooltip").hidePopup(); 118 } 119 120 function ensureParagraphFocused3() { 121 window.removeEventListener("popuphidden", ensureParagraphFocused2); 122 ok(isCaretVisible(), "Caret should still be visible"); 123 SimpleTest.finish(); 124 } 125 ]]></script> 126 </window>