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/browser_window.h" | |
7 #include "chrome/browser/ui/virtual_keyboard/virtual_keyboard_manager.h" | |
8 #include "chrome/common/chrome_notification_types.h" | |
9 #include "chrome/test/base/in_process_browser_test.h" | |
10 #include "chrome/test/base/ui_test_utils.h" | |
11 #include "content/public/browser/notification_service.h" | |
12 #include "content/public/browser/notification_types.h" | |
13 #include "net/base/mock_host_resolver.h" | |
14 #include "ui/views/widget/widget.h" | |
15 | |
16 class VirtualKeyboardManagerTest : public InProcessBrowserTest, | |
17 public content::NotificationObserver { | |
18 public: | |
19 VirtualKeyboardManagerTest() | |
20 : InProcessBrowserTest(), | |
21 keyboard_visible_(false) { | |
22 } | |
23 | |
24 bool keyboard_visible() const { return keyboard_visible_; } | |
25 | |
26 void SetupNotificationListener() { | |
27 registrar_.Add(this, | |
28 chrome::NOTIFICATION_KEYBOARD_VISIBILITY_CHANGED, | |
29 content::NotificationService::AllSources()); | |
30 } | |
31 | |
32 private: | |
33 virtual void TearDown() { | |
34 registrar_.RemoveAll(); | |
35 InProcessBrowserTest::TearDown(); | |
36 } | |
37 | |
38 virtual void Observe(int type, | |
39 const content::NotificationSource& source, | |
40 const content::NotificationDetails& details) OVERRIDE { | |
41 DCHECK_EQ(chrome::NOTIFICATION_KEYBOARD_VISIBILITY_CHANGED, type); | |
42 keyboard_visible_ = *content::Details<bool>(details).ptr(); | |
43 } | |
44 | |
45 bool keyboard_visible_; | |
46 content::NotificationRegistrar registrar_; | |
47 }; | |
48 | |
49 IN_PROC_BROWSER_TEST_F(VirtualKeyboardManagerTest, TestVisibility) { | |
50 SetupNotificationListener(); | |
51 browser()->window()->Show(); | |
52 | |
53 // Move focus between the omnibox and the wrench menu a few times. Note that | |
54 // it is necessary to RunAllPendingInMessageLoop each time after moving | |
55 // focus between the omnibox and the wrench menu because of the task posted in | |
56 // AccessiblePaneView::FocusWillChange | |
57 | |
58 browser()->FocusAppMenu(); | |
59 EXPECT_FALSE(keyboard_visible()); | |
60 ui_test_utils::RunAllPendingInMessageLoop(); | |
61 | |
62 browser()->FocusLocationBar(); | |
63 EXPECT_TRUE(keyboard_visible()); | |
64 ui_test_utils::RunAllPendingInMessageLoop(); | |
65 | |
66 browser()->FocusAppMenu(); | |
67 EXPECT_FALSE(keyboard_visible()); | |
68 ui_test_utils::RunAllPendingInMessageLoop(); | |
69 | |
70 browser()->FocusLocationBar(); | |
71 EXPECT_TRUE(keyboard_visible()); | |
72 ui_test_utils::RunAllPendingInMessageLoop(); | |
73 | |
74 // Test with some tabs now | |
75 host_resolver()->AddRule("*", "127.0.0.1"); | |
76 ASSERT_TRUE(test_server()->Start()); | |
77 GURL base_url = test_server()->GetURL("files/keyboard/"); | |
78 | |
79 // Go to a page that gives focus to a textfield onload. | |
80 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("focus.html")); | |
81 EXPECT_TRUE(keyboard_visible()); | |
82 | |
83 // Open a new tab that does not give focus to a textfield onload. | |
84 ui_test_utils::WindowedNotificationObserver load_stop_observer( | |
85 content::NOTIFICATION_LOAD_STOP, | |
86 content::NotificationService::AllSources()); | |
87 browser()->AddSelectedTabWithURL(base_url.Resolve("blank.html"), | |
88 content::PAGE_TRANSITION_LINK); | |
89 load_stop_observer.Wait(); | |
90 | |
91 // Focus the first tab where the textfield has the focus. | |
92 browser()->SelectNextTab(); | |
93 EXPECT_TRUE(keyboard_visible()); | |
94 | |
95 // Focus the next tab again. | |
96 browser()->SelectNextTab(); | |
97 EXPECT_FALSE(keyboard_visible()); | |
98 } | |
OLD | NEW |