window_focus_docnav.xhtml (4251B)
1 <?xml version="1.0"?> 2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?> 3 4 <window onload="start()" 5 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 6 7 <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/> 8 9 <input xmlns="http://www.w3.org/1999/xhtml" id="textbox1"/> 10 <input xmlns="http://www.w3.org/1999/xhtml" id="textbox2"/> 11 12 <panel id="panel" onpopupshown="runTests(this, 1);" 13 onpopuphidden="noChildrenTest()"> 14 <input xmlns="http://www.w3.org/1999/xhtml" id="p1textbox" value="Popup1"/> 15 </panel> 16 <panel id="panel2" onpopupshown="runTests(this, 2);" onpopuphidden="document.getElementById('panel').hidePopup()"> 17 <input xmlns="http://www.w3.org/1999/xhtml" id="p2textbox" value="Popup2"/> 18 </panel> 19 20 <browser id="browser" type="content" src="focus_frameset.html" style="width: 500px; height: 400px"/> 21 22 <script type="application/javascript"> 23 <![CDATA[ 24 25 var fm = Cc["@mozilla.org/focus-manager;1"]. 26 getService(Ci.nsIFocusManager); 27 28 function is(l, r, n) { window.arguments[0].SimpleTest.is(l,r,n); } 29 function ok(v, n) { window.arguments[0].SimpleTest.ok(v,n); } 30 31 function noChildrenTest() 32 { 33 // Remove the browser element and test navigation when there are no other documents. 34 // The focus should move or stay on the first focusable element. 35 let browser = document.getElementById("browser"); 36 browser.remove(); 37 38 let textbox1 = document.getElementById("textbox1"); 39 let textbox2 = document.getElementById("textbox2"); 40 41 textbox2.focus(); 42 next(window, textbox1, "Focus forward when no child documents"); 43 next(window, textbox1, "Focus forward again when no child documents"); 44 45 textbox2.focus(); 46 previous(window, textbox1, "Focus backward when no child documents"); 47 previous(window, textbox1, "Focus backward again when no child documents"); 48 49 done(); 50 } 51 52 function done() 53 { 54 window.close(); 55 window.arguments[0].SimpleTest.finish(); 56 } 57 58 function previous(expectedWindow, expectedElement, desc) 59 { 60 synthesizeKey("KEY_F6", {shiftKey: true}); 61 is(fm.focusedWindow, expectedWindow, desc); 62 is(fm.focusedElement, expectedElement, desc + " element"); 63 } 64 65 function next(expectedWindow, expectedElement, desc) 66 { 67 synthesizeKey("KEY_F6"); 68 is(fm.focusedWindow, expectedWindow, desc); 69 is(fm.focusedElement, expectedElement, desc + " element" + "::" + (fm.focusedElement ? fm.focusedElement.parentNode.id : "<none>")); 70 } 71 72 // This test runs through three cases. Document navigation forward and 73 // backward using the F6 key when no popups are open, with one popup open and 74 // with two popups open. 75 function runTests(panel, popupCount) 76 { 77 if (!popupCount || popupCount > 2) 78 popupCount = 0; 79 80 fm.clearFocus(window); 81 82 var childwin = document.getElementById("browser").contentWindow; 83 84 if (popupCount) { 85 next(window, document.getElementById("p1textbox"), "First into popup 1 with " + popupCount); 86 87 if (popupCount == 2) { 88 next(window, document.getElementById("p2textbox"), "First into popup 2 with " + popupCount); 89 } 90 } 91 92 next(childwin.frames[0], childwin.frames[0].document.documentElement, "First with " + popupCount); 93 next(childwin.frames[1], childwin.frames[1].document.documentElement, "Second with " + popupCount); 94 previous(childwin.frames[0], childwin.frames[0].document.documentElement, "Second back with " + popupCount); 95 96 if (popupCount) { 97 if (popupCount == 2) { 98 previous(window, document.getElementById("p2textbox"), "First back from popup 2 with " + popupCount); 99 } 100 101 previous(window, document.getElementById("p1textbox"), "First back from popup 1 with " + popupCount); 102 } 103 104 previous(window, document.getElementById("textbox1"), "First back with " + popupCount); 105 106 if (panel == document.getElementById("panel")) 107 document.getElementById("panel2").openPopup(null, "after_start", 100, 20); 108 else if (panel == document.getElementById("panel2")) 109 panel.hidePopup(); 110 else 111 document.getElementById("panel").openPopup(null, "after_start"); 112 } 113 114 function start() 115 { 116 window.arguments[0].SimpleTest.waitForExplicitFinish(); 117 window.arguments[0].SimpleTest.waitForFocus( 118 function() { runTests(null, 0); }, 119 document.getElementById("browser").contentWindow); 120 } 121 122 ]]></script> 123 124 </window>