Bug 1334496 - Part 2 - Test that content elements stay focused when showing a popup notification. r=Paolo draft
authorJohann Hofmann <jhofmann@mozilla.com>
Wed, 08 Mar 2017 11:57:07 +0100
changeset 556364 ccae9db2d090fd9ab967159bb5a136a9c54ad02b
parent 556363 75f395dcadd1134fe7ca6169533ffaa4c65a1485
child 622868 13eec71a22417bc4d4a9cb272e074ec9c39a970d
push id52525
push userbmo:jhofmann@mozilla.com
push dateWed, 05 Apr 2017 18:56:26 +0000
reviewersPaolo
bugs1334496
milestone55.0a1
Bug 1334496 - Part 2 - Test that content elements stay focused when showing a popup notification. r=Paolo MozReview-Commit-ID: 2CQ1NNauJ7f
browser/base/content/test/popupNotifications/browser_popupNotification_keyboard.js
--- a/browser/base/content/test/popupNotifications/browser_popupNotification_keyboard.js
+++ b/browser/base/content/test/popupNotifications/browser_popupNotification_keyboard.js
@@ -167,9 +167,42 @@ var tests = [
 
       // Check that the urlbar is still focused.
       is(Services.focus.focusedElement, gURLBar.inputField);
 
       this.notification.remove();
       notification.remove();
     }
   },
+  // Test that focus is not moved out of a content element if autofocus is not set.
+  { id: "Test#6",
+    *run() {
+      let id = this.id;
+      yield BrowserTestUtils.withNewTab("data:text/html,<input id='test-input'/>", function*(browser) {
+        let notifyObj = new BasicNotification(id);
+        yield ContentTask.spawn(browser, {}, function() {
+          content.document.getElementById("test-input").focus();
+        });
+
+        let opened = waitForNotificationPanel();
+        let notification = showNotification(notifyObj);
+        yield opened;
+
+        // Check that the focused element in the chrome window
+        // is either the browser in case we're running on e10s
+        // or the input field in case of non-e10s.
+        if (gMultiProcessBrowser) {
+          is(Services.focus.focusedElement, browser);
+        } else {
+          is(Services.focus.focusedElement, browser.contentDocument.getElementById("test-input"));
+        }
+
+        // Check that the input field is still focused inside the browser.
+        yield ContentTask.spawn(browser, {}, function() {
+          is(content.document.activeElement, content.document.getElementById("test-input"));
+        });
+
+        notification.remove();
+        goNext();
+      });
+    },
+  },
 ];