Index: chrome/browser/ui/touch/keyboard/keyboard_manager_browsertest.cc |
diff --git a/chrome/browser/ui/touch/keyboard/keyboard_manager_browsertest.cc b/chrome/browser/ui/touch/keyboard/keyboard_manager_browsertest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..67b00992ef8977f01d5fbb0d8cd31eba336bc541 |
--- /dev/null |
+++ b/chrome/browser/ui/touch/keyboard/keyboard_manager_browsertest.cc |
@@ -0,0 +1,92 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/ui/browser.h" |
+#include "chrome/browser/ui/touch/keyboard/keyboard_manager.h" |
+#include "chrome/common/chrome_notification_types.h" |
+#include "chrome/test/base/in_process_browser_test.h" |
+#include "chrome/test/base/ui_test_utils.h" |
+#include "content/common/content_notification_types.h" |
+#include "net/base/mock_host_resolver.h" |
+#include "views/widget/widget.h" |
+ |
+class KeyboardManagerTest : public InProcessBrowserTest, |
+ public NotificationObserver { |
+ public: |
+ KeyboardManagerTest() |
+ : InProcessBrowserTest(), |
+ keyboard_visible_(false) { |
+ } |
+ |
+ bool keyboard_visible() const { return keyboard_visible_; } |
+ |
+ void SetupNotificationListener() { |
+ registrar_.Add(this, |
+ chrome::NOTIFICATION_KEYBOARD_VISIBILITY_CHANGED, |
+ NotificationService::AllSources()); |
+ } |
+ |
+ private: |
+ virtual void TearDown() { |
+ registrar_.RemoveAll(); |
+ InProcessBrowserTest::TearDown(); |
+ } |
+ |
+ virtual void Observe(int type, |
+ const NotificationSource& source, |
+ const NotificationDetails& details) OVERRIDE { |
+ DCHECK_EQ(chrome::NOTIFICATION_KEYBOARD_VISIBILITY_CHANGED, type); |
+ keyboard_visible_ = *Details<bool>(details).ptr(); |
+ } |
+ |
+ bool keyboard_visible_; |
+ NotificationRegistrar registrar_; |
+}; |
+ |
+IN_PROC_BROWSER_TEST_F(KeyboardManagerTest, TestVisibility) { |
+ SetupNotificationListener(); |
+ |
+ // Move focus between the omnibox and the wrench menu a few times. Note that |
+ // it is necessary to RunAllPendingInMessageLoop each time after moving |
+ // focus between the omnibox and the wrench menu because of the task posted in |
+ // AccessiblePaneView::FocusWillChange |
+ |
+ browser()->FocusAppMenu(); |
+ EXPECT_FALSE(keyboard_visible()); |
+ ui_test_utils::RunAllPendingInMessageLoop(); |
+ |
+ browser()->FocusLocationBar(); |
+ EXPECT_TRUE(keyboard_visible()); |
+ ui_test_utils::RunAllPendingInMessageLoop(); |
+ |
+ browser()->FocusAppMenu(); |
+ EXPECT_FALSE(keyboard_visible()); |
+ ui_test_utils::RunAllPendingInMessageLoop(); |
+ |
+ browser()->FocusLocationBar(); |
+ EXPECT_TRUE(keyboard_visible()); |
+ ui_test_utils::RunAllPendingInMessageLoop(); |
+ |
+ // Test with some tabs now |
+ host_resolver()->AddRule("*", "127.0.0.1"); |
+ ASSERT_TRUE(test_server()->Start()); |
+ GURL base_url = test_server()->GetURL("files/keyboard/"); |
+ |
+ // Go to a page that gives focus to a textfield onload. |
+ ui_test_utils::NavigateToURL(browser(), base_url.Resolve("focus.html")); |
+ EXPECT_TRUE(keyboard_visible()); |
+ |
+ // Open a new tab that does not give focus to a textfield onload. |
+ browser()->AddSelectedTabWithURL(base_url.Resolve("blank.html"), |
+ PageTransition::LINK); |
+ ui_test_utils::WaitForNotification(content::NOTIFICATION_LOAD_STOP); |
+ |
+ // Focus the first tab where the textfield has the focus. |
+ browser()->SelectNextTab(); |
+ EXPECT_TRUE(keyboard_visible()); |
+ |
+ // Focus the next tab again. |
+ browser()->SelectNextTab(); |
+ EXPECT_FALSE(keyboard_visible()); |
+} |