Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: chrome/browser/ui/views/find_bar_host_interactive_uitest.cc

Issue 5463001: Figure out error in test PrepopulateRespectBlank.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/automation/ui_controls_win.cc ('k') | chrome/test/ui_test_utils.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
6 #include "base/string_util.h" 8 #include "base/string_util.h"
7 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/find_bar_controller.h" 10 #include "chrome/browser/find_bar_controller.h"
9 #include "chrome/browser/tab_contents/tab_contents.h" 11 #include "chrome/browser/tab_contents/tab_contents.h"
10 #include "chrome/browser/tabs/tab_strip_model.h" 12 #include "chrome/browser/tabs/tab_strip_model.h"
11 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/views/find_bar_host.h" 14 #include "chrome/browser/views/find_bar_host.h"
13 #include "chrome/browser/views/frame/browser_view.h" 15 #include "chrome/browser/views/frame/browser_view.h"
14 #include "chrome/browser/view_ids.h" 16 #include "chrome/browser/view_ids.h"
15 #include "chrome/test/in_process_browser_test.h" 17 #include "chrome/test/in_process_browser_test.h"
16 #include "chrome/test/ui_test_utils.h" 18 #include "chrome/test/ui_test_utils.h"
17 #include "net/test/test_server.h" 19 #include "net/test/test_server.h"
18 #include "views/focus/focus_manager.h" 20 #include "views/focus/focus_manager.h"
19 #include "views/view.h" 21 #include "views/view.h"
20 22
23 #if defined(OS_WIN)
24 #include <windows.h>
25 #include <Psapi.h>
26 #endif
27
21 namespace { 28 namespace {
22 29
23 // The delay waited after sending an OS simulated event. 30 // The delay waited after sending an OS simulated event.
24 static const int kActionDelayMs = 500; 31 static const int kActionDelayMs = 500;
25 static const char kSimplePage[] = "files/find_in_page/simple.html"; 32 static const char kSimplePage[] = "files/find_in_page/simple.html";
26 33
27 class FindInPageTest : public InProcessBrowserTest { 34 class FindInPageTest : public InProcessBrowserTest {
28 public: 35 public:
29 FindInPageTest() { 36 FindInPageTest() {
30 set_show_window(true); 37 set_show_window(true);
31 FindBarHost::disable_animations_during_testing_ = true; 38 FindBarHost::disable_animations_during_testing_ = true;
32 } 39 }
33 40
34 string16 GetFindBarText() { 41 string16 GetFindBarText() {
35 FindBarTesting* find_bar = 42 FindBarTesting* find_bar =
36 browser()->GetFindBarController()->find_bar()->GetFindBarTesting(); 43 browser()->GetFindBarController()->find_bar()->GetFindBarTesting();
37 return find_bar->GetFindText(); 44 return find_bar->GetFindText();
38 } 45 }
39 }; 46 };
40 47
41 void Checkpoint(const char* message, const base::TimeTicks& start_time) { 48 void Checkpoint(const char* message, const base::TimeTicks& start_time) {
42 LOG(INFO) << message << " : " 49 LOG(INFO) << message << " : "
43 << (base::TimeTicks::Now() - start_time).InMilliseconds() 50 << (base::TimeTicks::Now() - start_time).InMilliseconds()
44 << " ms" << std::flush; 51 << " ms" << std::flush;
45 } 52 }
46 53
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 = std::wstring(L"Unable to read filename (error ") +
M-A Ruel 2010/12/01 14:51:12 The 'std::wstring(' part is not strictly necessary
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
47 } // namespace 92 } // namespace
48 93
49 IN_PROC_BROWSER_TEST_F(FindInPageTest, CrashEscHandlers) { 94 IN_PROC_BROWSER_TEST_F(FindInPageTest, CrashEscHandlers) {
50 ASSERT_TRUE(test_server()->Start()); 95 ASSERT_TRUE(test_server()->Start());
51 96
52 // First we navigate to our test page (tab A). 97 // First we navigate to our test page (tab A).
53 GURL url = test_server()->GetURL(kSimplePage); 98 GURL url = test_server()->GetURL(kSimplePage);
54 ui_test_utils::NavigateToURL(browser(), url); 99 ui_test_utils::NavigateToURL(browser(), url);
55 100
56 browser()->Find(); 101 browser()->Find();
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 } 171 }
127 172
128 // This tests that whenever you clear values from the Find box and close it that 173 // 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: 174 // it respects that and doesn't show you the last search, as reported in bug:
130 // http://crbug.com/40121. 175 // http://crbug.com/40121.
131 IN_PROC_BROWSER_TEST_F(FindInPageTest, PrepopulateRespectBlank) { 176 IN_PROC_BROWSER_TEST_F(FindInPageTest, PrepopulateRespectBlank) {
132 #if defined(OS_MACOSX) 177 #if defined(OS_MACOSX)
133 // FindInPage on Mac doesn't use prepopulated values. Search there is global. 178 // FindInPage on Mac doesn't use prepopulated values. Search there is global.
134 return; 179 return;
135 #endif 180 #endif
136
137 base::TimeTicks start_time = base::TimeTicks::Now(); 181 base::TimeTicks start_time = base::TimeTicks::Now();
138 Checkpoint("Starting test server", start_time); 182 Checkpoint("Starting test server", start_time);
139 183
140 ASSERT_TRUE(test_server()->Start()); 184 ASSERT_TRUE(test_server()->Start());
141 185
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
142 // First we navigate to any page. 190 // First we navigate to any page.
143 Checkpoint("Navigating", start_time); 191 Checkpoint("Navigating", start_time);
144 GURL url = test_server()->GetURL(kSimplePage); 192 GURL url = test_server()->GetURL(kSimplePage);
145 ui_test_utils::NavigateToURL(browser(), url); 193 ui_test_utils::NavigateToURL(browser(), url);
146 194
147 // Show the Find bar. 195 // Show the Find bar.
148 Checkpoint("Showing Find window", start_time); 196 Checkpoint("Showing Find window", start_time);
149 browser()->GetFindBarController()->Show(); 197 browser()->GetFindBarController()->Show();
150 198
151 // Search for "a". 199 // Search for "a".
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 238 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
191 browser(), app::VKEY_F3, false, false, false, false)); 239 browser(), app::VKEY_F3, false, false, false, false));
192 240
193 // After the Find box has been reopened, it should still have no prepopulate 241 // After the Find box has been reopened, it should still have no prepopulate
194 // value. 242 // value.
195 Checkpoint("GetFindBarText", start_time); 243 Checkpoint("GetFindBarText", start_time);
196 EXPECT_EQ(string16(), GetFindBarText()); 244 EXPECT_EQ(string16(), GetFindBarText());
197 245
198 Checkpoint("Test completed", start_time); 246 Checkpoint("Test completed", start_time);
199 } 247 }
OLDNEW
« no previous file with comments | « chrome/browser/automation/ui_controls_win.cc ('k') | chrome/test/ui_test_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698