Bug 915962 - Part 3: Do not crash when pressing the space bar without having an element focused; r=roc
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 21 Apr 2015 14:06:54 -0400
changeset 259362 183d3acaef74aa353aed6cc2078627184a35a524
parent 259361 579ad8bc3ccfc1e49c74268692ad3d7af07fbf99
child 259363 23ed444769a8431ba08e07f271a3bf06044290c9
push id8007
push userraliiev@mozilla.com
push dateMon, 11 May 2015 19:23:16 +0000
treeherdermozilla-aurora@e2ce1aac996e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs915962
milestone40.0a1
Bug 915962 - Part 3: Do not crash when pressing the space bar without having an element focused; r=roc
dom/xbl/nsXBLPrototypeHandler.cpp
editor/libeditor/tests/test_bug915962.html
--- a/dom/xbl/nsXBLPrototypeHandler.cpp
+++ b/dom/xbl/nsXBLPrototypeHandler.cpp
@@ -473,17 +473,17 @@ nsXBLPrototypeHandler::DispatchXBLComman
     nsCOMPtr<nsIContent> focusedContent;
     if (windowToCheck) {
       nsCOMPtr<nsPIDOMWindow> focusedWindow;
       focusedContent =
         nsFocusManager::GetFocusedDescendant(windowToCheck, true, getter_AddRefs(focusedWindow));
     }
 
     // If the focus is in an editable region, don't scroll.
-    if (focusedContent->IsEditable()) {
+    if (focusedContent && focusedContent->IsEditable()) {
       return NS_OK;
     }
 
     // If the focus is in a form control, don't scroll.
     for (nsIContent* c = focusedContent; c; c = c->GetParent()) {
       nsCOMPtr<nsIFormControl> formControl = do_QueryInterface(c);
       if (formControl) {
         return NS_OK;
--- a/editor/libeditor/tests/test_bug915962.html
+++ b/editor/libeditor/tests/test_bug915962.html
@@ -62,14 +62,29 @@ function startTest() {
   step();
 
   ok(win.scrollY <= oldY, "Page is not scrolled down");
   ok(clicked, "The button should be clicked");
 
   win.close();
   cwu.restoreNormalRefresh();
 
-  SimpleTest.finish();
+  win = window.open("file_bug915962.html", "_blank",
+                    "width=600,height=600,scrollbars=yes");
+  cwu = SpecialPowers.getDOMWindowUtils(win);
+  SimpleTest.waitForFocus(function() {
+    is(win.scrollY, 0, "Sanity check");
+    synthesizeKey(" ", {}, win);
+
+    step();
+
+    isnot(win.scrollY, 0, "Page is scrolled down without crashing");
+
+    win.close();
+    cwu.restoreNormalRefresh();
+
+    SimpleTest.finish();
+  }, win);
 }
 </script>
 </pre>
 </body>
 </html>