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