OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "app/keyboard_codes.h" | 5 #include "app/keyboard_codes.h" |
6 #include "base/process_util.h" | |
7 #include "base/string_number_conversions.h" | |
8 #include "base/string_util.h" | 6 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/find_bar_controller.h" | 8 #include "chrome/browser/find_bar_controller.h" |
11 #include "chrome/browser/tab_contents/tab_contents.h" | 9 #include "chrome/browser/tab_contents/tab_contents.h" |
12 #include "chrome/browser/tabs/tab_strip_model.h" | 10 #include "chrome/browser/tabs/tab_strip_model.h" |
13 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/browser/views/find_bar_host.h" | 12 #include "chrome/browser/views/find_bar_host.h" |
15 #include "chrome/browser/views/frame/browser_view.h" | 13 #include "chrome/browser/views/frame/browser_view.h" |
16 #include "chrome/browser/view_ids.h" | 14 #include "chrome/browser/view_ids.h" |
17 #include "chrome/test/in_process_browser_test.h" | 15 #include "chrome/test/in_process_browser_test.h" |
18 #include "chrome/test/ui_test_utils.h" | 16 #include "chrome/test/ui_test_utils.h" |
19 #include "net/test/test_server.h" | 17 #include "net/test/test_server.h" |
20 #include "views/focus/focus_manager.h" | 18 #include "views/focus/focus_manager.h" |
21 #include "views/view.h" | 19 #include "views/view.h" |
22 | 20 |
23 #if defined(OS_WIN) | |
24 #include <windows.h> | |
25 #include <Psapi.h> | |
26 #endif | |
27 | |
28 namespace { | 21 namespace { |
29 | 22 |
30 // The delay waited after sending an OS simulated event. | 23 // The delay waited after sending an OS simulated event. |
31 static const int kActionDelayMs = 500; | 24 static const int kActionDelayMs = 500; |
32 static const char kSimplePage[] = "files/find_in_page/simple.html"; | 25 static const char kSimplePage[] = "files/find_in_page/simple.html"; |
33 | 26 |
34 class FindInPageTest : public InProcessBrowserTest { | 27 class FindInPageTest : public InProcessBrowserTest { |
35 public: | 28 public: |
36 FindInPageTest() { | 29 FindInPageTest() { |
37 set_show_window(true); | 30 set_show_window(true); |
38 FindBarHost::disable_animations_during_testing_ = true; | 31 FindBarHost::disable_animations_during_testing_ = true; |
39 } | 32 } |
40 | 33 |
41 string16 GetFindBarText() { | 34 string16 GetFindBarText() { |
42 FindBarTesting* find_bar = | 35 FindBarTesting* find_bar = |
43 browser()->GetFindBarController()->find_bar()->GetFindBarTesting(); | 36 browser()->GetFindBarController()->find_bar()->GetFindBarTesting(); |
44 return find_bar->GetFindText(); | 37 return find_bar->GetFindText(); |
45 } | 38 } |
46 }; | 39 }; |
47 | 40 |
48 void Checkpoint(const char* message, const base::TimeTicks& start_time) { | 41 void Checkpoint(const char* message, const base::TimeTicks& start_time) { |
49 LOG(INFO) << message << " : " | 42 LOG(INFO) << message << " : " |
50 << (base::TimeTicks::Now() - start_time).InMilliseconds() | 43 << (base::TimeTicks::Now() - start_time).InMilliseconds() |
51 << " ms" << std::flush; | 44 << " ms" << std::flush; |
52 } | 45 } |
53 | 46 |
54 // Test to make sure Chrome is in the foreground as we start testing. This is | |
55 // required for tests that synthesize input to the Chrome window. | |
56 bool ChromeInForeground() { | |
57 #if defined(OS_WIN) | |
58 HWND window = ::GetForegroundWindow(); | |
59 std::wstring caption; | |
60 std::wstring filename; | |
61 int len = ::GetWindowTextLength(window) + 1; | |
62 ::GetWindowText(window, WriteInto(&caption, len), len); | |
63 bool chrome_window_in_foreground = | |
64 (caption == L"about:blank - Google Chrome"); | |
65 if (!chrome_window_in_foreground) { | |
66 DWORD process_id; | |
67 int thread_id = ::GetWindowThreadProcessId(window, &process_id); | |
68 | |
69 base::ProcessHandle process; | |
70 if (base::OpenProcessHandleWithAccess(process_id, | |
71 PROCESS_QUERY_LIMITED_INFORMATION, | |
72 &process)) { | |
73 len = MAX_PATH; | |
74 if (!GetProcessImageFileName(process, WriteInto(&filename, len), len)) { | |
75 int error = GetLastError(); | |
76 filename = L"Unable to read filename (error " + | |
77 base::IntToString16(error) + L")"; | |
78 } | |
79 base::CloseProcessHandle(process); | |
80 } | |
81 } | |
82 EXPECT_TRUE(chrome_window_in_foreground) | |
83 << "Chrome must be in the foreground when running interactive tests\n" | |
84 << "Process in foreground: " << filename.c_str(); | |
85 return chrome_window_in_foreground; | |
86 #else | |
87 // Windows only at the moment. | |
88 return true; | |
89 #endif | |
90 } | |
91 | |
92 } // namespace | 47 } // namespace |
93 | 48 |
94 IN_PROC_BROWSER_TEST_F(FindInPageTest, CrashEscHandlers) { | 49 IN_PROC_BROWSER_TEST_F(FindInPageTest, CrashEscHandlers) { |
95 ASSERT_TRUE(test_server()->Start()); | 50 ASSERT_TRUE(test_server()->Start()); |
96 | 51 |
97 // First we navigate to our test page (tab A). | 52 // First we navigate to our test page (tab A). |
98 GURL url = test_server()->GetURL(kSimplePage); | 53 GURL url = test_server()->GetURL(kSimplePage); |
99 ui_test_utils::NavigateToURL(browser(), url); | 54 ui_test_utils::NavigateToURL(browser(), url); |
100 | 55 |
101 browser()->Find(); | 56 browser()->Find(); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 } | 126 } |
172 | 127 |
173 // This tests that whenever you clear values from the Find box and close it that | 128 // This tests that whenever you clear values from the Find box and close it that |
174 // it respects that and doesn't show you the last search, as reported in bug: | 129 // it respects that and doesn't show you the last search, as reported in bug: |
175 // http://crbug.com/40121. | 130 // http://crbug.com/40121. |
176 IN_PROC_BROWSER_TEST_F(FindInPageTest, PrepopulateRespectBlank) { | 131 IN_PROC_BROWSER_TEST_F(FindInPageTest, PrepopulateRespectBlank) { |
177 #if defined(OS_MACOSX) | 132 #if defined(OS_MACOSX) |
178 // FindInPage on Mac doesn't use prepopulated values. Search there is global. | 133 // FindInPage on Mac doesn't use prepopulated values. Search there is global. |
179 return; | 134 return; |
180 #endif | 135 #endif |
| 136 |
181 base::TimeTicks start_time = base::TimeTicks::Now(); | 137 base::TimeTicks start_time = base::TimeTicks::Now(); |
182 Checkpoint("Starting test server", start_time); | 138 Checkpoint("Starting test server", start_time); |
183 | 139 |
184 ASSERT_TRUE(test_server()->Start()); | 140 ASSERT_TRUE(test_server()->Start()); |
185 | 141 |
186 // Make sure Chrome is in the foreground, otherwise sending input | |
187 // won't do anything and the test will hang. | |
188 ASSERT_TRUE(ChromeInForeground()); | |
189 | |
190 // First we navigate to any page. | 142 // First we navigate to any page. |
191 Checkpoint("Navigating", start_time); | 143 Checkpoint("Navigating", start_time); |
192 GURL url = test_server()->GetURL(kSimplePage); | 144 GURL url = test_server()->GetURL(kSimplePage); |
193 ui_test_utils::NavigateToURL(browser(), url); | 145 ui_test_utils::NavigateToURL(browser(), url); |
194 | 146 |
195 // Show the Find bar. | 147 // Show the Find bar. |
196 Checkpoint("Showing Find window", start_time); | 148 Checkpoint("Showing Find window", start_time); |
197 browser()->GetFindBarController()->Show(); | 149 browser()->GetFindBarController()->Show(); |
198 | 150 |
199 // Search for "a". | 151 // Search for "a". |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( | 190 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
239 browser(), app::VKEY_F3, false, false, false, false)); | 191 browser(), app::VKEY_F3, false, false, false, false)); |
240 | 192 |
241 // After the Find box has been reopened, it should still have no prepopulate | 193 // After the Find box has been reopened, it should still have no prepopulate |
242 // value. | 194 // value. |
243 Checkpoint("GetFindBarText", start_time); | 195 Checkpoint("GetFindBarText", start_time); |
244 EXPECT_EQ(string16(), GetFindBarText()); | 196 EXPECT_EQ(string16(), GetFindBarText()); |
245 | 197 |
246 Checkpoint("Test completed", start_time); | 198 Checkpoint("Test completed", start_time); |
247 } | 199 } |
OLD | NEW |