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

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

Issue 1409163006: Migrating tests to use EmbeddedTestServer (/chrome/browser misc) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix rebase bug. Created 5 years, 1 month 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/strings/string_util.h" 5 #include "base/strings/string_util.h"
6 #include "base/strings/utf_string_conversions.h" 6 #include "base/strings/utf_string_conversions.h"
7 #include "chrome/browser/chrome_notification_types.h" 7 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/ui/browser.h" 8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/browser_commands.h" 9 #include "chrome/browser/ui/browser_commands.h"
10 #include "chrome/browser/ui/browser_tabstrip.h" 10 #include "chrome/browser/ui/browser_tabstrip.h"
11 #include "chrome/browser/ui/find_bar/find_bar_controller.h" 11 #include "chrome/browser/ui/find_bar/find_bar_controller.h"
12 #include "chrome/browser/ui/find_bar/find_notification_details.h" 12 #include "chrome/browser/ui/find_bar/find_notification_details.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model.h" 13 #include "chrome/browser/ui/tabs/tab_strip_model.h"
14 #include "chrome/browser/ui/view_ids.h" 14 #include "chrome/browser/ui/view_ids.h"
15 #include "chrome/browser/ui/views/find_bar_host.h" 15 #include "chrome/browser/ui/views/find_bar_host.h"
16 #include "chrome/browser/ui/views/frame/browser_view.h" 16 #include "chrome/browser/ui/views/frame/browser_view.h"
17 #include "chrome/test/base/in_process_browser_test.h" 17 #include "chrome/test/base/in_process_browser_test.h"
18 #include "chrome/test/base/interactive_test_utils.h" 18 #include "chrome/test/base/interactive_test_utils.h"
19 #include "chrome/test/base/ui_test_utils.h" 19 #include "chrome/test/base/ui_test_utils.h"
20 #include "content/public/browser/notification_service.h" 20 #include "content/public/browser/notification_service.h"
21 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
22 #include "net/test/spawned_test_server/spawned_test_server.h" 22 #include "net/test/embedded_test_server/embedded_test_server.h"
23 #include "ui/base/clipboard/clipboard.h" 23 #include "ui/base/clipboard/clipboard.h"
24 #include "ui/events/keycodes/keyboard_codes.h" 24 #include "ui/events/keycodes/keyboard_codes.h"
25 #include "ui/views/focus/focus_manager.h" 25 #include "ui/views/focus/focus_manager.h"
26 #include "ui/views/view.h" 26 #include "ui/views/view.h"
27 27
28 using base::ASCIIToUTF16; 28 using base::ASCIIToUTF16;
29 using content::WebContents; 29 using content::WebContents;
30 30
31 namespace { 31 namespace {
32 32
33 static const char kSimplePage[] = "files/find_in_page/simple.html"; 33 static const char kSimplePage[] = "/find_in_page/simple.html";
34 34
35 class FindInPageTest : public InProcessBrowserTest { 35 class FindInPageTest : public InProcessBrowserTest {
36 public: 36 public:
37 FindInPageTest() { 37 FindInPageTest() {
38 FindBarHost::disable_animations_during_testing_ = true; 38 FindBarHost::disable_animations_during_testing_ = true;
39 } 39 }
40 40
41 base::string16 GetFindBarText() { 41 base::string16 GetFindBarText() {
42 FindBar* find_bar = browser()->GetFindBarController()->find_bar(); 42 FindBar* find_bar = browser()->GetFindBarController()->find_bar();
43 return find_bar->GetFindText(); 43 return find_bar->GetFindText();
44 } 44 }
45 45
46 base::string16 GetFindBarSelectedText() { 46 base::string16 GetFindBarSelectedText() {
47 FindBarTesting* find_bar = 47 FindBarTesting* find_bar =
48 browser()->GetFindBarController()->find_bar()->GetFindBarTesting(); 48 browser()->GetFindBarController()->find_bar()->GetFindBarTesting();
49 return find_bar->GetFindSelectedText(); 49 return find_bar->GetFindSelectedText();
50 } 50 }
51 51
52 private: 52 private:
53 DISALLOW_COPY_AND_ASSIGN(FindInPageTest); 53 DISALLOW_COPY_AND_ASSIGN(FindInPageTest);
54 }; 54 };
55 55
56 } // namespace 56 } // namespace
57 57
58 // Flaky because the test server fails to start? See: http://crbug.com/96594. 58 // Flaky because the test server fails to start? See: http://crbug.com/96594.
59 IN_PROC_BROWSER_TEST_F(FindInPageTest, CrashEscHandlers) { 59 IN_PROC_BROWSER_TEST_F(FindInPageTest, CrashEscHandlers) {
60 ASSERT_TRUE(test_server()->Start()); 60 ASSERT_TRUE(embedded_test_server()->Start());
61 61
62 // First we navigate to our test page (tab A). 62 // First we navigate to our test page (tab A).
63 GURL url = test_server()->GetURL(kSimplePage); 63 GURL url = embedded_test_server()->GetURL(kSimplePage);
64 ui_test_utils::NavigateToURL(browser(), url); 64 ui_test_utils::NavigateToURL(browser(), url);
65 65
66 chrome::Find(browser()); 66 chrome::Find(browser());
67 67
68 // Open another tab (tab B). 68 // Open another tab (tab B).
69 chrome::AddSelectedTabWithURL(browser(), url, ui::PAGE_TRANSITION_TYPED); 69 chrome::AddSelectedTabWithURL(browser(), url, ui::PAGE_TRANSITION_TYPED);
70 70
71 chrome::Find(browser()); 71 chrome::Find(browser());
72 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), 72 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(),
73 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); 73 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
(...skipping 10 matching lines...) Expand all
84 VIEW_ID_OMNIBOX)); 84 VIEW_ID_OMNIBOX));
85 // Check the location bar is focused. 85 // Check the location bar is focused.
86 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); 86 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
87 87
88 // This used to crash until bug 1303709 was fixed. 88 // This used to crash until bug 1303709 was fixed.
89 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 89 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
90 browser(), ui::VKEY_ESCAPE, false, false, false, false)); 90 browser(), ui::VKEY_ESCAPE, false, false, false, false));
91 } 91 }
92 92
93 IN_PROC_BROWSER_TEST_F(FindInPageTest, NavigationByKeyEvent) { 93 IN_PROC_BROWSER_TEST_F(FindInPageTest, NavigationByKeyEvent) {
94 ASSERT_TRUE(test_server()->Start()); 94 ASSERT_TRUE(embedded_test_server()->Start());
95 // Make sure Chrome is in the foreground, otherwise sending input 95 // Make sure Chrome is in the foreground, otherwise sending input
96 // won't do anything and the test will hang. 96 // won't do anything and the test will hang.
97 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 97 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
98 // First we navigate to any page. 98 // First we navigate to any page.
99 ui_test_utils::NavigateToURL(browser(), test_server()->GetURL(kSimplePage)); 99 ui_test_utils::NavigateToURL(browser(),
100 embedded_test_server()->GetURL(kSimplePage));
100 // Show the Find bar. 101 // Show the Find bar.
101 browser()->GetFindBarController()->Show(); 102 browser()->GetFindBarController()->Show();
102 EXPECT_TRUE( 103 EXPECT_TRUE(
103 ui_test_utils::IsViewFocused(browser(), VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); 104 ui_test_utils::IsViewFocused(browser(), VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
104 ui_test_utils::FindInPage( 105 ui_test_utils::FindInPage(
105 browser()->tab_strip_model()->GetActiveWebContents(), ASCIIToUTF16("a"), 106 browser()->tab_strip_model()->GetActiveWebContents(), ASCIIToUTF16("a"),
106 true, false, NULL, NULL); 107 true, false, NULL, NULL);
107 108
108 // The textfield should be focused after pressing [Enter] on the find button. 109 // The textfield should be focused after pressing [Enter] on the find button.
109 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_TAB, false, 110 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_TAB, false,
(...skipping 19 matching lines...) Expand all
129 130
130 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA) 131 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)
131 // TODO(erg): linux_aura bringup: http://crbug.com/163931 132 // TODO(erg): linux_aura bringup: http://crbug.com/163931
132 #define MAYBE_FocusRestore DISABLED_FocusRestore 133 #define MAYBE_FocusRestore DISABLED_FocusRestore
133 #else 134 #else
134 #define MAYBE_FocusRestore FocusRestore 135 #define MAYBE_FocusRestore FocusRestore
135 #endif 136 #endif
136 137
137 // Flaky because the test server fails to start? See: http://crbug.com/96594. 138 // Flaky because the test server fails to start? See: http://crbug.com/96594.
138 IN_PROC_BROWSER_TEST_F(FindInPageTest, MAYBE_FocusRestore) { 139 IN_PROC_BROWSER_TEST_F(FindInPageTest, MAYBE_FocusRestore) {
139 ASSERT_TRUE(test_server()->Start()); 140 ASSERT_TRUE(embedded_test_server()->Start());
140 141
141 GURL url = test_server()->GetURL("title1.html"); 142 GURL url = embedded_test_server()->GetURL("/title1.html");
142 ui_test_utils::NavigateToURL(browser(), url); 143 ui_test_utils::NavigateToURL(browser(), url);
143 144
144 // Focus the location bar, open and close the find-in-page, focus should 145 // Focus the location bar, open and close the find-in-page, focus should
145 // return to the location bar. 146 // return to the location bar.
146 chrome::FocusLocationBar(browser()); 147 chrome::FocusLocationBar(browser());
147 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); 148 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
148 // Ensure the creation of the find bar controller. 149 // Ensure the creation of the find bar controller.
149 browser()->GetFindBarController()->Show(); 150 browser()->GetFindBarController()->Show();
150 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), 151 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(),
151 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); 152 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
(...skipping 28 matching lines...) Expand all
180 FindBarController::kKeepSelectionOnPage, 181 FindBarController::kKeepSelectionOnPage,
181 FindBarController::kKeepResultsInFindBox); 182 FindBarController::kKeepResultsInFindBox);
182 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); 183 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
183 } 184 }
184 185
185 186
186 // TODO(phajdan.jr): Disabling due to possible timing issues on XP 187 // TODO(phajdan.jr): Disabling due to possible timing issues on XP
187 // interactive_ui_tests. 188 // interactive_ui_tests.
188 // http://crbug.com/311363 189 // http://crbug.com/311363
189 IN_PROC_BROWSER_TEST_F(FindInPageTest, DISABLED_SelectionRestoreOnTabSwitch) { 190 IN_PROC_BROWSER_TEST_F(FindInPageTest, DISABLED_SelectionRestoreOnTabSwitch) {
190 ASSERT_TRUE(test_server()->Start()); 191 ASSERT_TRUE(embedded_test_server()->Start());
191 192
192 // Make sure Chrome is in the foreground, otherwise sending input 193 // Make sure Chrome is in the foreground, otherwise sending input
193 // won't do anything and the test will hang. 194 // won't do anything and the test will hang.
194 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 195 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
195 196
196 // First we navigate to any page in the current tab (tab A). 197 // First we navigate to any page in the current tab (tab A).
197 GURL url = test_server()->GetURL(kSimplePage); 198 GURL url = embedded_test_server()->GetURL(kSimplePage);
198 ui_test_utils::NavigateToURL(browser(), url); 199 ui_test_utils::NavigateToURL(browser(), url);
199 200
200 // Show the Find bar. 201 // Show the Find bar.
201 browser()->GetFindBarController()->Show(); 202 browser()->GetFindBarController()->Show();
202 203
203 // Search for "abc". 204 // Search for "abc".
204 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 205 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
205 browser(), ui::VKEY_A, false, false, false, false)); 206 browser(), ui::VKEY_A, false, false, false, false));
206 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 207 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
207 browser(), ui::VKEY_B, false, false, false, false)); 208 browser(), ui::VKEY_B, false, false, false, false));
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 260
260 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA) 261 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)
261 // TODO(erg): linux_aura bringup: http://crbug.com/163931 262 // TODO(erg): linux_aura bringup: http://crbug.com/163931
262 #define MAYBE_FocusRestoreOnTabSwitch DISABLED_FocusRestoreOnTabSwitch 263 #define MAYBE_FocusRestoreOnTabSwitch DISABLED_FocusRestoreOnTabSwitch
263 #else 264 #else
264 #define MAYBE_FocusRestoreOnTabSwitch FocusRestoreOnTabSwitch 265 #define MAYBE_FocusRestoreOnTabSwitch FocusRestoreOnTabSwitch
265 #endif 266 #endif
266 267
267 // Flaky because the test server fails to start? See: http://crbug.com/96594. 268 // Flaky because the test server fails to start? See: http://crbug.com/96594.
268 IN_PROC_BROWSER_TEST_F(FindInPageTest, MAYBE_FocusRestoreOnTabSwitch) { 269 IN_PROC_BROWSER_TEST_F(FindInPageTest, MAYBE_FocusRestoreOnTabSwitch) {
269 ASSERT_TRUE(test_server()->Start()); 270 ASSERT_TRUE(embedded_test_server()->Start());
270 271
271 // First we navigate to our test page (tab A). 272 // First we navigate to our test page (tab A).
272 GURL url = test_server()->GetURL(kSimplePage); 273 GURL url = embedded_test_server()->GetURL(kSimplePage);
273 ui_test_utils::NavigateToURL(browser(), url); 274 ui_test_utils::NavigateToURL(browser(), url);
274 275
275 chrome::Find(browser()); 276 chrome::Find(browser());
276 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), 277 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(),
277 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); 278 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
278 279
279 // Search for 'a'. 280 // Search for 'a'.
280 ui_test_utils::FindInPage( 281 ui_test_utils::FindInPage(
281 browser()->tab_strip_model()->GetActiveWebContents(), 282 browser()->tab_strip_model()->GetActiveWebContents(),
282 ASCIIToUTF16("a"), true, false, NULL, NULL); 283 ASCIIToUTF16("a"), true, false, NULL, NULL);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); 316 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
316 } 317 }
317 318
318 // FindInPage on Mac doesn't use prepopulated values. Search there is global. 319 // FindInPage on Mac doesn't use prepopulated values. Search there is global.
319 #if !defined(OS_MACOSX) && !defined(USE_AURA) 320 #if !defined(OS_MACOSX) && !defined(USE_AURA)
320 // Flaky because the test server fails to start? See: http://crbug.com/96594. 321 // Flaky because the test server fails to start? See: http://crbug.com/96594.
321 // This tests that whenever you clear values from the Find box and close it that 322 // This tests that whenever you clear values from the Find box and close it that
322 // it respects that and doesn't show you the last search, as reported in bug: 323 // it respects that and doesn't show you the last search, as reported in bug:
323 // http://crbug.com/40121. For Aura see bug http://crbug.com/292299. 324 // http://crbug.com/40121. For Aura see bug http://crbug.com/292299.
324 IN_PROC_BROWSER_TEST_F(FindInPageTest, PrepopulateRespectBlank) { 325 IN_PROC_BROWSER_TEST_F(FindInPageTest, PrepopulateRespectBlank) {
325 ASSERT_TRUE(test_server()->Start()); 326 ASSERT_TRUE(embedded_test_server()->Start());
326 327
327 // Make sure Chrome is in the foreground, otherwise sending input 328 // Make sure Chrome is in the foreground, otherwise sending input
328 // won't do anything and the test will hang. 329 // won't do anything and the test will hang.
329 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 330 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
330 331
331 // First we navigate to any page. 332 // First we navigate to any page.
332 GURL url = test_server()->GetURL(kSimplePage); 333 GURL url = embedded_test_server()->GetURL(kSimplePage);
333 ui_test_utils::NavigateToURL(browser(), url); 334 ui_test_utils::NavigateToURL(browser(), url);
334 335
335 // Show the Find bar. 336 // Show the Find bar.
336 browser()->GetFindBarController()->Show(); 337 browser()->GetFindBarController()->Show();
337 338
338 // Search for "a". 339 // Search for "a".
339 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 340 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
340 browser(), ui::VKEY_A, false, false, false, false)); 341 browser(), ui::VKEY_A, false, false, false, false));
341 342
342 // We should find "a" here. 343 // We should find "a" here.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 // Flaky on Win. http://crbug.com/92467 378 // Flaky on Win. http://crbug.com/92467
378 // Flaky on ChromeOS. http://crbug.com/118216 379 // Flaky on ChromeOS. http://crbug.com/118216
379 // Flaky on linux aura. http://crbug.com/163931 380 // Flaky on linux aura. http://crbug.com/163931
380 #if defined(TOOLKIT_VIEWS) 381 #if defined(TOOLKIT_VIEWS)
381 #define MAYBE_PasteWithoutTextChange DISABLED_PasteWithoutTextChange 382 #define MAYBE_PasteWithoutTextChange DISABLED_PasteWithoutTextChange
382 #else 383 #else
383 #define MAYBE_PasteWithoutTextChange PasteWithoutTextChange 384 #define MAYBE_PasteWithoutTextChange PasteWithoutTextChange
384 #endif 385 #endif
385 386
386 IN_PROC_BROWSER_TEST_F(FindInPageTest, MAYBE_PasteWithoutTextChange) { 387 IN_PROC_BROWSER_TEST_F(FindInPageTest, MAYBE_PasteWithoutTextChange) {
387 ASSERT_TRUE(test_server()->Start()); 388 ASSERT_TRUE(embedded_test_server()->Start());
388 389
389 // Make sure Chrome is in the foreground, otherwise sending input 390 // Make sure Chrome is in the foreground, otherwise sending input
390 // won't do anything and the test will hang. 391 // won't do anything and the test will hang.
391 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 392 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
392 393
393 // First we navigate to any page. 394 // First we navigate to any page.
394 GURL url = test_server()->GetURL(kSimplePage); 395 GURL url = embedded_test_server()->GetURL(kSimplePage);
395 ui_test_utils::NavigateToURL(browser(), url); 396 ui_test_utils::NavigateToURL(browser(), url);
396 397
397 // Show the Find bar. 398 // Show the Find bar.
398 browser()->GetFindBarController()->Show(); 399 browser()->GetFindBarController()->Show();
399 400
400 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), 401 EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(),
401 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); 402 VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
402 403
403 // Search for "a". 404 // Search for "a".
404 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 405 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 ui_test_utils::UrlLoadObserver observer( 473 ui_test_utils::UrlLoadObserver observer(
473 GURL("about:blank"), content::NotificationService::AllSources()); 474 GURL("about:blank"), content::NotificationService::AllSources());
474 475
475 // Send Ctrl-Enter, should cause navigation to about:blank. 476 // Send Ctrl-Enter, should cause navigation to about:blank.
476 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 477 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
477 browser(), ui::VKEY_RETURN, true, false, false, false)); 478 browser(), ui::VKEY_RETURN, true, false, false, false));
478 479
479 observer.Wait(); 480 observer.Wait();
480 } 481 }
481 #endif 482 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698