1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/base/tests/chrome/test_bug420499.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,129 @@ 1.4 +<?xml version="1.0"?> 1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?> 1.6 +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?> 1.7 +<!-- 1.8 +https://bugzilla.mozilla.org/show_bug.cgi?id=420499 1.9 +--> 1.10 +<window title="Mozilla Bug 420499" onload="setTimeout(focusInput, 500);" 1.11 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 1.12 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> 1.13 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> 1.14 + 1.15 + 1.16 + 1.17 + <menu id="menu" label="Menu"> 1.18 + <menupopup id="file-popup"> 1.19 + <!-- <textbox id="some-text" maxlength="10" value="some text"/> --> 1.20 + <menu label="submenu"> 1.21 + <menupopup id="file-popup-inner"> 1.22 + 1.23 + <menuitem label="Item1"/> 1.24 + <menuitem label="Item2"/> 1.25 + <textbox id="some-text" maxlength="10" value="some more text"/> 1.26 + </menupopup> 1.27 + </menu> 1.28 + <menuitem label="Item3"/> 1.29 + <menuitem label="Item4"/> 1.30 + </menupopup> 1.31 + </menu> 1.32 + 1.33 + <popupset> 1.34 + <popup id="contextmenu"> 1.35 + <menuitem label="Cut"/> 1.36 + <menuitem label="Copy"/> 1.37 + <menuitem label="Paste"/> 1.38 + </popup> 1.39 + <tooltip id="tooltip" orient="vertical"> 1.40 + <description value="This is a tooltip"/> 1.41 + </tooltip> 1.42 + </popupset> 1.43 + 1.44 + <!-- test results are displayed in the html:body --> 1.45 + <body xmlns="http://www.w3.org/1999/xhtml" bgcolor="white"> 1.46 + 1.47 + <p id="par1">Paragraph 1</p> 1.48 + <p id="par2">Paragraph 2</p> 1.49 + <p id="par3">Paragraph 3</p> 1.50 + <p id="par4">Paragraph 4</p> 1.51 + <p id="par5">Paragraph 5</p> 1.52 + 1.53 + <input type="text" id="text-input" maxlength="10" value="some more text"/> <br /> 1.54 + 1.55 + <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=420499" 1.56 + target="_blank">Mozilla Bug 420499</a> 1.57 + </body> 1.58 + 1.59 + <!-- test code goes here --> 1.60 + <script type="application/javascript"><![CDATA[ 1.61 + 1.62 + /** Test for Bug 420499 **/ 1.63 + SimpleTest.waitForExplicitFinish(); 1.64 + 1.65 + function getSelectionController() { 1.66 + return document.docShell 1.67 + .QueryInterface(Components.interfaces.nsIInterfaceRequestor) 1.68 + .getInterface(Components.interfaces.nsISelectionDisplay) 1.69 + .QueryInterface(Components.interfaces.nsISelectionController); 1.70 + } 1.71 + 1.72 + function isCaretVisible() { 1.73 + window.QueryInterface(Components.interfaces.nsIInterfaceRequestor); 1.74 + var docShell = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor) 1.75 + .getInterface(Components.interfaces.nsIWebNavigation) 1.76 + .QueryInterface(Components.interfaces.nsIDocShell); 1.77 + var selCon = docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor) 1.78 + .getInterface(Components.interfaces.nsISelectionDisplay) 1.79 + .QueryInterface(Components.interfaces.nsISelectionController); 1.80 + return selCon.caretVisible; 1.81 + } 1.82 + 1.83 + function focusInput() { 1.84 + ok(!isCaretVisible(), "Caret shouldn't be visible"); 1.85 + $("text-input").focus(); 1.86 + ok(isCaretVisible(), "Caret should be visible when input focused"); 1.87 + window.addEventListener("popupshown", popupMenuShownHandler, false); 1.88 + $("menu").open = true; 1.89 + } 1.90 + 1.91 + function popupMenuShownHandler() { 1.92 + window.removeEventListener("popupshown", popupMenuShownHandler, false); 1.93 + ok(!isCaretVisible(), "Caret shouldn't be visible when menu open"); 1.94 + window.addEventListener("popuphidden", ensureParagraphFocused, false); 1.95 + $("menu").open = false; 1.96 + } 1.97 + 1.98 + function ensureParagraphFocused() { 1.99 + window.removeEventListener("popuphidden", ensureParagraphFocused, false); 1.100 + ok(isCaretVisible(), "Caret should have returned to previous focus"); 1.101 + window.addEventListener("popupshown", popupMenuShownHandler2, false); 1.102 + $("contextmenu").openPopup($('text-input'), "topleft" , -1 , -1 , true, true); 1.103 + } 1.104 + 1.105 + function popupMenuShownHandler2() { 1.106 + window.removeEventListener("popupshown", popupMenuShownHandler2, false); 1.107 + ok(isCaretVisible(), "Caret should be visible when context menu open"); 1.108 + window.addEventListener("popuphidden", ensureParagraphFocused2, false); 1.109 + document.getElementById("contextmenu").hidePopup(); 1.110 + } 1.111 + 1.112 + function ensureParagraphFocused2() { 1.113 + window.removeEventListener("popuphidden", ensureParagraphFocused2, false); 1.114 + ok(isCaretVisible(), "Caret should still be visible"); 1.115 + window.addEventListener("popupshown", tooltipShownHandler, false); 1.116 + $("tooltip").openPopup($('text-input'), "topleft" , -1 , -1 , false, true); 1.117 + } 1.118 + 1.119 + function tooltipShownHandler() { 1.120 + window.removeEventListener("popupshown", tooltipShownHandler, false); 1.121 + ok(isCaretVisible(), "Caret should be visible when tooltip is visible"); 1.122 + window.addEventListener("popuphidden", ensureParagraphFocused3, false); 1.123 + document.getElementById("tooltip").hidePopup(); 1.124 + } 1.125 + 1.126 + function ensureParagraphFocused3() { 1.127 + window.removeEventListener("popuphidden", ensureParagraphFocused2, false); 1.128 + ok(isCaretVisible(), "Caret should still be visible"); 1.129 + SimpleTest.finish(); 1.130 + } 1.131 + ]]></script> 1.132 +</window>