Bug 1227461, don't iterate multiple times past the top-level document during tab navigation, prevents hang navigating in page info dialog, r=smaug
authorNeil Deakin <neil@mozilla.com>
Wed, 02 Dec 2015 09:34:42 -0500
changeset 309408 c6bacc29209b5a8afb28b296b1647ab461478ba6
parent 309407 633bfeaa021b75241fba50ab3544c46b9a84c00c
child 309409 cb6196bdba35102ff645918e1139199a4def84c2
push id5513
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 13:55:34 +0000
treeherdermozilla-beta@5ee97dd05b5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1227461
milestone45.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1227461, don't iterate multiple times past the top-level document during tab navigation, prevents hang navigating in page info dialog, r=smaug
dom/base/nsFocusManager.cpp
dom/tests/mochitest/chrome/window_focus_docnav.xul
--- a/dom/base/nsFocusManager.cpp
+++ b/dom/base/nsFocusManager.cpp
@@ -2822,16 +2822,21 @@ nsFocusManager::DetermineElementToMoveFo
         // appears in the tab order before all of the elements in the document.
         // Chrome documents however cannot be focused directly, so instead we
         // focus the first focusable element within the window.
         // For example, the urlbar.
         nsIContent* root = GetRootForFocus(piWindow, doc, true, true);
         return FocusFirst(root, aNextContent);
       }
 
+      // Once we have hit the top-level and have iterated to the end again, we
+      // just want to break out next time we hit this spot to prevent infinite
+      // iteration.
+      mayFocusRoot = true;
+
       // reset the tab index and start again from the beginning or end
       startContent = rootContent;
       tabIndex = forward ? 1 : 0;
     }
 
     // wrapped all the way around and didn't find anything to move the focus
     // to, so just break out
     if (startContent == originalStartContent)
--- a/dom/tests/mochitest/chrome/window_focus_docnav.xul
+++ b/dom/tests/mochitest/chrome/window_focus_docnav.xul
@@ -2,20 +2,21 @@
 <?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="textbox"/>
+<textbox id="textbox1"/>
+<textbox id="textbox2"/>
 
 <panel id="panel" onpopupshown="runTests(this, 1);"
-                  onpopuphidden="done()">
+                  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"/>
 
@@ -23,16 +24,37 @@
 <![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)
@@ -76,17 +98,17 @@ function runTests(panel, 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("textbox").inputField, "First back 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");
 }