Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/browser.h" | |
| 6 #include "chrome/browser/ui/touch/keyboard/keyboard_manager.h" | |
| 7 #include "chrome/test/in_process_browser_test.h" | |
| 8 #include "chrome/test/ui_test_utils.h" | |
| 9 #include "net/base/mock_host_resolver.h" | |
| 10 #include "views/widget/widget.h" | |
| 11 | |
| 12 class KeyboardManagerTest : public InProcessBrowserTest, | |
| 13 public NotificationObserver { | |
| 14 public: | |
| 15 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.
| |
| 16 keyboard_visible_(false) { | |
| 17 } | |
| 18 | |
| 19 bool keyboard_visible() { return keyboard_visible_; } | |
|
sky
2011/07/06 14:38:31
const
sadrul
2011/07/06 16:18:19
Done.
| |
| 20 | |
| 21 void SetupNotificationListener() { | |
| 22 registrar_.Add(this, | |
| 23 NotificationType::KEYBOARD_VISIBILITY_CHANGED, | |
| 24 NotificationService::AllSources()); | |
| 25 } | |
| 26 | |
| 27 private: | |
| 28 virtual void TearDown() { | |
| 29 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
| |
| 30 InProcessBrowserTest::TearDown(); | |
| 31 } | |
| 32 | |
| 33 virtual void Observe(NotificationType type, | |
| 34 const NotificationSource& source, | |
| 35 const NotificationDetails& details) OVERRIDE { | |
| 36 DCHECK_EQ(NotificationType::KEYBOARD_VISIBILITY_CHANGED, type.value); | |
| 37 keyboard_visible_ = *Details<bool>(details).ptr(); | |
| 38 } | |
| 39 | |
| 40 bool keyboard_visible_; | |
| 41 NotificationRegistrar registrar_; | |
| 42 }; | |
| 43 | |
| 44 IN_PROC_BROWSER_TEST_F(KeyboardManagerTest, TestVisibility) { | |
| 45 SetupNotificationListener(); | |
| 46 | |
| 47 // Move focus between the omnibox and the wrench menu a few times. Note that | |
| 48 // 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.
| |
| 49 // focus between the omnibox and the wrench menu because of the task posted in | |
| 50 // AccessiblePaneView::FocusWillChange | |
| 51 | |
| 52 browser()->FocusAppMenu(); | |
| 53 EXPECT_FALSE(keyboard_visible()); | |
| 54 ui_test_utils::RunAllPendingInMessageLoop(); | |
| 55 | |
| 56 browser()->FocusLocationBar(); | |
| 57 EXPECT_TRUE(keyboard_visible()); | |
| 58 ui_test_utils::RunAllPendingInMessageLoop(); | |
| 59 | |
| 60 browser()->FocusAppMenu(); | |
| 61 EXPECT_FALSE(keyboard_visible()); | |
| 62 ui_test_utils::RunAllPendingInMessageLoop(); | |
| 63 | |
| 64 browser()->FocusLocationBar(); | |
| 65 EXPECT_TRUE(keyboard_visible()); | |
| 66 ui_test_utils::RunAllPendingInMessageLoop(); | |
| 67 | |
| 68 browser()->FocusNextPane(); | |
| 69 EXPECT_FALSE(keyboard_visible()); | |
| 70 ui_test_utils::RunAllPendingInMessageLoop(); | |
| 71 | |
| 72 // Test with some tabs now | |
| 73 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 74 ASSERT_TRUE(test_server()->Start()); | |
| 75 GURL base_url = test_server()->GetURL("files/keyboard/"); | |
| 76 | |
| 77 // Go to a page that gives focus to a textfield onload. | |
| 78 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("focus.html")); | |
| 79 EXPECT_TRUE(keyboard_visible()); | |
| 80 | |
| 81 // Open a new tab that does not give focus to a textfield onload. | |
| 82 browser()->AddSelectedTabWithURL(base_url.Resolve("blank.html"), | |
| 83 PageTransition::LINK); | |
| 84 ui_test_utils::WaitForNotification(NotificationType::LOAD_STOP); | |
| 85 | |
| 86 // Focus the first tab where the textfield has the focus. | |
| 87 browser()->SelectNextTab(); | |
| 88 EXPECT_TRUE(keyboard_visible()); | |
| 89 | |
| 90 // Focus the next tab again. | |
| 91 browser()->SelectNextTab(); | |
| 92 EXPECT_FALSE(keyboard_visible()); | |
| 93 } | |
| OLD | NEW |