Chromium Code Reviews| 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..f3a025c498b82b576b7272f4a933d3669ad840d7 |
| --- /dev/null |
| +++ b/chrome/browser/ui/touch/keyboard/keyboard_manager_browsertest.cc |
| @@ -0,0 +1,93 @@ |
| +// 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/test/in_process_browser_test.h" |
| +#include "chrome/test/ui_test_utils.h" |
| +#include "net/base/mock_host_resolver.h" |
| +#include "views/widget/widget.h" |
| + |
| +class KeyboardManagerTest : public InProcessBrowserTest, |
| + public NotificationObserver { |
| + public: |
| + KeyboardManagerTest() : InProcessBrowserTest(), |
|
sky
2011/07/06 14:38:31
put the member initialize list on the next line an
sadrul
2011/07/06 16:18:19
Done.
|
| + keyboard_visible_(false) { |
| + } |
| + |
| + bool keyboard_visible() { return keyboard_visible_; } |
|
sky
2011/07/06 14:38:31
const
sadrul
2011/07/06 16:18:19
Done.
|
| + |
| + void SetupNotificationListener() { |
| + registrar_.Add(this, |
| + NotificationType::KEYBOARD_VISIBILITY_CHANGED, |
| + NotificationService::AllSources()); |
| + } |
| + |
| + private: |
| + virtual void TearDown() { |
| + registrar_.RemoveAll(); |
|
sky
2011/07/06 14:38:31
This will automatically happen in the destructor.
sadrul
2011/07/06 16:18:19
By the time this happens in the destructor, the No
|
| + InProcessBrowserTest::TearDown(); |
| + } |
| + |
| + virtual void Observe(NotificationType type, |
| + const NotificationSource& source, |
| + const NotificationDetails& details) OVERRIDE { |
| + DCHECK_EQ(NotificationType::KEYBOARD_VISIBILITY_CHANGED, type.value); |
| + 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 to RunAllPendingInMessageLoop each time after moving |
|
sky
2011/07/06 14:38:31
'to to' -> 'to'
sadrul
2011/07/06 16:18:19
Done.
|
| + // 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(); |
| + |
| + browser()->FocusNextPane(); |
| + EXPECT_FALSE(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(NotificationType::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()); |
| +} |