OLD | NEW |
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/message_loop.h" | 5 #include "base/message_loop.h" |
6 #include "base/string16.h" | 6 #include "base/string16.h" |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/tabs/tab_strip_model.h" | 10 #include "chrome/browser/tabs/tab_strip_model.h" |
11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/browser_navigator.h" | 12 #include "chrome/browser/ui/browser_navigator.h" |
13 #include "chrome/browser/ui/browser_window.h" | 13 #include "chrome/browser/ui/browser_window.h" |
14 #include "chrome/browser/ui/find_bar/find_bar.h" | 14 #include "chrome/browser/ui/find_bar/find_bar.h" |
15 #include "chrome/browser/ui/find_bar/find_bar_controller.h" | 15 #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
16 #include "chrome/browser/ui/find_bar/find_notification_details.h" | 16 #include "chrome/browser/ui/find_bar/find_notification_details.h" |
17 #include "chrome/browser/ui/find_bar/find_tab_helper.h" | 17 #include "chrome/browser/ui/find_bar/find_tab_helper.h" |
18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
19 #include "chrome/common/url_constants.h" | 19 #include "chrome/common/url_constants.h" |
20 #include "chrome/test/base/in_process_browser_test.h" | 20 #include "chrome/test/base/in_process_browser_test.h" |
21 #include "chrome/test/base/ui_test_utils.h" | 21 #include "chrome/test/base/ui_test_utils.h" |
22 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
23 #include "content/public/browser/notification_types.h" | 23 #include "content/public/browser/notification_types.h" |
24 #include "content/public/browser/render_view_host.h" | 24 #include "content/public/browser/render_view_host.h" |
25 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
26 #include "content/public/browser/web_contents_view.h" | 26 #include "content/public/browser/web_contents_view.h" |
27 #include "net/test/test_server.h" | |
28 #include "ui/base/accelerators/accelerator.h" | 27 #include "ui/base/accelerators/accelerator.h" |
29 #include "ui/base/keycodes/keyboard_codes.h" | 28 #include "ui/base/keycodes/keyboard_codes.h" |
30 | 29 |
31 #if defined(TOOLKIT_VIEWS) | 30 #if defined(TOOLKIT_VIEWS) |
32 #include "chrome/browser/ui/views/find_bar_host.h" | 31 #include "chrome/browser/ui/views/find_bar_host.h" |
33 #include "ui/views/focus/focus_manager.h" | 32 #include "ui/views/focus/focus_manager.h" |
34 #include "ui/views/widget/widget.h" | 33 #include "ui/views/widget/widget.h" |
35 #elif defined(TOOLKIT_GTK) | 34 #elif defined(TOOLKIT_GTK) |
36 #include "chrome/browser/ui/gtk/slide_animator_gtk.h" | 35 #include "chrome/browser/ui/gtk/slide_animator_gtk.h" |
37 #elif defined(OS_MACOSX) | 36 #elif defined(OS_MACOSX) |
38 #include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" | 37 #include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" |
39 #endif | 38 #endif |
40 | 39 |
41 using content::NavigationController; | 40 using content::NavigationController; |
42 using content::WebContents; | 41 using content::WebContents; |
43 | 42 |
44 const std::string kSimplePage = "404_is_enough_for_us.html"; | 43 const std::string kFramePage = "frames.html"; |
45 const std::string kFramePage = "files/find_in_page/frames.html"; | 44 const std::string kFrameData = "framedata_general.html"; |
46 const std::string kFrameData = "files/find_in_page/framedata_general.html"; | 45 const std::string kUserSelectPage = "user-select.html"; |
47 const std::string kUserSelectPage = "files/find_in_page/user-select.html"; | 46 const std::string kCrashPage = "crash_1341577.html"; |
48 const std::string kCrashPage = "files/find_in_page/crash_1341577.html"; | 47 const std::string kTooFewMatchesPage = "bug_1155639.html"; |
49 const std::string kTooFewMatchesPage = "files/find_in_page/bug_1155639.html"; | 48 const std::string kLongTextareaPage = "large_textarea.html"; |
50 const std::string kLongTextareaPage = "files/find_in_page/large_textarea.html"; | 49 const std::string kEndState = "end_state.html"; |
51 const std::string kEndState = "files/find_in_page/end_state.html"; | 50 const std::string kPrematureEnd = "premature_end.html"; |
52 const std::string kPrematureEnd = "files/find_in_page/premature_end.html"; | 51 const std::string kMoveIfOver = "move_if_obscuring.html"; |
53 const std::string kMoveIfOver = "files/find_in_page/move_if_obscuring.html"; | 52 const std::string kBitstackCrash = "crash_14491.html"; |
54 const std::string kBitstackCrash = "files/find_in_page/crash_14491.html"; | 53 const std::string kSelectChangesOrdinal = "select_changes_ordinal.html"; |
55 const std::string kSelectChangesOrdinal = | 54 const std::string kSimple = "simple.html"; |
56 "files/find_in_page/select_changes_ordinal.html"; | 55 const std::string kLinkPage = "link.html"; |
57 const std::string kSimple = "files/find_in_page/simple.html"; | |
58 const std::string kLinkPage = "files/find_in_page/link.html"; | |
59 | 56 |
60 const bool kBack = false; | 57 const bool kBack = false; |
61 const bool kFwd = true; | 58 const bool kFwd = true; |
62 | 59 |
63 const bool kIgnoreCase = false; | 60 const bool kIgnoreCase = false; |
64 const bool kCaseSensitive = true; | 61 const bool kCaseSensitive = true; |
65 | 62 |
66 const int kMoveIterations = 30; | 63 const int kMoveIterations = 30; |
67 | 64 |
68 class FindInPageControllerTest : public InProcessBrowserTest { | 65 class FindInPageControllerTest : public InProcessBrowserTest { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 gfx::Point position; | 157 gfx::Point position; |
161 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); | 158 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); |
162 EXPECT_TRUE(fully_visible); | 159 EXPECT_TRUE(fully_visible); |
163 | 160 |
164 // If the Find box has moved then we are done. | 161 // If the Find box has moved then we are done. |
165 if (position.x() != start_x_position) | 162 if (position.x() != start_x_position) |
166 return position.x(); | 163 return position.x(); |
167 } | 164 } |
168 return start_x_position; | 165 return start_x_position; |
169 } | 166 } |
| 167 |
| 168 GURL GetURL(const std::string filename) { |
| 169 return ui_test_utils::GetTestUrl( |
| 170 FilePath().AppendASCII("find_in_page"), |
| 171 FilePath().AppendASCII(filename)); |
| 172 } |
170 }; | 173 }; |
171 | 174 |
172 // This test loads a page with frames and starts FindInPage requests. | 175 // This test loads a page with frames and starts FindInPage requests. |
173 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageFrames) { | 176 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageFrames) { |
174 ASSERT_TRUE(test_server()->Start()); | |
175 | |
176 // First we navigate to our frames page. | 177 // First we navigate to our frames page. |
177 GURL url = test_server()->GetURL(kFramePage); | 178 GURL url = GetURL(kFramePage); |
178 ui_test_utils::NavigateToURL(browser(), url); | 179 ui_test_utils::NavigateToURL(browser(), url); |
179 | 180 |
180 // Try incremental search (mimicking user typing in). | 181 // Try incremental search (mimicking user typing in). |
181 int ordinal = 0; | 182 int ordinal = 0; |
182 TabContentsWrapper* tab = browser()->GetSelectedTabContentsWrapper(); | 183 TabContentsWrapper* tab = browser()->GetSelectedTabContentsWrapper(); |
183 EXPECT_EQ(18, FindInPageWchar(tab, L"g", | 184 EXPECT_EQ(18, FindInPageWchar(tab, L"g", |
184 kFwd, kIgnoreCase, &ordinal)); | 185 kFwd, kIgnoreCase, &ordinal)); |
185 EXPECT_EQ(1, ordinal); | 186 EXPECT_EQ(1, ordinal); |
186 EXPECT_EQ(11, FindInPageWchar(tab, L"go", | 187 EXPECT_EQ(11, FindInPageWchar(tab, L"go", |
187 kFwd, kIgnoreCase, &ordinal)); | 188 kFwd, kIgnoreCase, &ordinal)); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 web_contents->GetRenderViewHost(), | 259 web_contents->GetRenderViewHost(), |
259 L"", | 260 L"", |
260 L"window.domAutomationController.send(getFocusedElement());", | 261 L"window.domAutomationController.send(getFocusedElement());", |
261 result); | 262 result); |
262 } | 263 } |
263 | 264 |
264 // This tests the FindInPage end-state, in other words: what is focused when you | 265 // This tests the FindInPage end-state, in other words: what is focused when you |
265 // close the Find box (ie. if you find within a link the link should be | 266 // close the Find box (ie. if you find within a link the link should be |
266 // focused). | 267 // focused). |
267 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageEndState) { | 268 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageEndState) { |
268 ASSERT_TRUE(test_server()->Start()); | |
269 | |
270 // First we navigate to our special focus tracking page. | 269 // First we navigate to our special focus tracking page. |
271 GURL url = test_server()->GetURL(kEndState); | 270 GURL url = GetURL(kEndState); |
272 ui_test_utils::NavigateToURL(browser(), url); | 271 ui_test_utils::NavigateToURL(browser(), url); |
273 | 272 |
274 TabContentsWrapper* tab_contents = browser()->GetSelectedTabContentsWrapper(); | 273 TabContentsWrapper* tab_contents = browser()->GetSelectedTabContentsWrapper(); |
275 ASSERT_TRUE(NULL != tab_contents); | 274 ASSERT_TRUE(NULL != tab_contents); |
276 | 275 |
277 // Verify that nothing has focus. | 276 // Verify that nothing has focus. |
278 std::string result; | 277 std::string result; |
279 ASSERT_TRUE(FocusedOnPage(tab_contents->web_contents(), &result)); | 278 ASSERT_TRUE(FocusedOnPage(tab_contents->web_contents(), &result)); |
280 ASSERT_STREQ("{nothing focused}", result.c_str()); | 279 ASSERT_STREQ("{nothing focused}", result.c_str()); |
281 | 280 |
(...skipping 28 matching lines...) Expand all Loading... |
310 find_tab_helper()->StopFinding(FindBarController::kKeepSelection); | 309 find_tab_helper()->StopFinding(FindBarController::kKeepSelection); |
311 | 310 |
312 // Verify that link2 is not focused. | 311 // Verify that link2 is not focused. |
313 ASSERT_TRUE(FocusedOnPage(tab_contents->web_contents(), &result)); | 312 ASSERT_TRUE(FocusedOnPage(tab_contents->web_contents(), &result)); |
314 EXPECT_STREQ("", result.c_str()); | 313 EXPECT_STREQ("", result.c_str()); |
315 } | 314 } |
316 | 315 |
317 // This test loads a single-frame page and makes sure the ordinal returned makes | 316 // This test loads a single-frame page and makes sure the ordinal returned makes |
318 // sense as we FindNext over all the items. | 317 // sense as we FindNext over all the items. |
319 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageOrdinal) { | 318 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageOrdinal) { |
320 ASSERT_TRUE(test_server()->Start()); | |
321 | |
322 // First we navigate to our page. | 319 // First we navigate to our page. |
323 GURL url = test_server()->GetURL(kFrameData); | 320 GURL url = GetURL(kFrameData); |
324 ui_test_utils::NavigateToURL(browser(), url); | 321 ui_test_utils::NavigateToURL(browser(), url); |
325 | 322 |
326 // Search for 'o', which should make the first item active and return | 323 // Search for 'o', which should make the first item active and return |
327 // '1 in 3' (1st ordinal of a total of 3 matches). | 324 // '1 in 3' (1st ordinal of a total of 3 matches). |
328 TabContentsWrapper* tab = browser()->GetSelectedTabContentsWrapper(); | 325 TabContentsWrapper* tab = browser()->GetSelectedTabContentsWrapper(); |
329 int ordinal = 0; | 326 int ordinal = 0; |
330 EXPECT_EQ(3, FindInPageWchar(tab, L"o", | 327 EXPECT_EQ(3, FindInPageWchar(tab, L"o", |
331 kFwd, kIgnoreCase, &ordinal)); | 328 kFwd, kIgnoreCase, &ordinal)); |
332 EXPECT_EQ(1, ordinal); | 329 EXPECT_EQ(1, ordinal); |
333 EXPECT_EQ(3, FindInPageWchar(tab, L"o", | 330 EXPECT_EQ(3, FindInPageWchar(tab, L"o", |
(...skipping 15 matching lines...) Expand all Loading... |
349 EXPECT_EQ(1, ordinal); | 346 EXPECT_EQ(1, ordinal); |
350 // This should go back to the end. | 347 // This should go back to the end. |
351 EXPECT_EQ(3, FindInPageWchar(tab, L"o", | 348 EXPECT_EQ(3, FindInPageWchar(tab, L"o", |
352 kBack, kIgnoreCase, &ordinal)); | 349 kBack, kIgnoreCase, &ordinal)); |
353 EXPECT_EQ(3, ordinal); | 350 EXPECT_EQ(3, ordinal); |
354 } | 351 } |
355 | 352 |
356 // This tests that the ordinal is correctly adjusted after a selection | 353 // This tests that the ordinal is correctly adjusted after a selection |
357 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, | 354 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, |
358 SelectChangesOrdinal_Issue20883) { | 355 SelectChangesOrdinal_Issue20883) { |
359 ASSERT_TRUE(test_server()->Start()); | |
360 | |
361 // First we navigate to our test content. | 356 // First we navigate to our test content. |
362 GURL url = test_server()->GetURL(kSelectChangesOrdinal); | 357 GURL url = GetURL(kSelectChangesOrdinal); |
363 ui_test_utils::NavigateToURL(browser(), url); | 358 ui_test_utils::NavigateToURL(browser(), url); |
364 | 359 |
365 // Search for a text that exists within a link on the page. | 360 // Search for a text that exists within a link on the page. |
366 TabContentsWrapper* tab = browser()->GetSelectedTabContentsWrapper(); | 361 TabContentsWrapper* tab = browser()->GetSelectedTabContentsWrapper(); |
367 ASSERT_TRUE(NULL != tab); | 362 ASSERT_TRUE(NULL != tab); |
368 int ordinal = 0; | 363 int ordinal = 0; |
369 EXPECT_EQ(4, FindInPageWchar(tab, | 364 EXPECT_EQ(4, FindInPageWchar(tab, |
370 L"google", | 365 L"google", |
371 kFwd, kIgnoreCase, &ordinal)); | 366 kFwd, kIgnoreCase, &ordinal)); |
372 EXPECT_EQ(1, ordinal); | 367 EXPECT_EQ(1, ordinal); |
(...skipping 13 matching lines...) Expand all Loading... |
386 kFwd, kIgnoreCase, &ordinal)); | 381 kFwd, kIgnoreCase, &ordinal)); |
387 EXPECT_EQ(3, ordinal); | 382 EXPECT_EQ(3, ordinal); |
388 | 383 |
389 // End the find session. | 384 // End the find session. |
390 tab->find_tab_helper()->StopFinding(FindBarController::kKeepSelection); | 385 tab->find_tab_helper()->StopFinding(FindBarController::kKeepSelection); |
391 } | 386 } |
392 | 387 |
393 // This test loads a page with frames and makes sure the ordinal returned makes | 388 // This test loads a page with frames and makes sure the ordinal returned makes |
394 // sense. | 389 // sense. |
395 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageMultiFramesOrdinal) { | 390 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageMultiFramesOrdinal) { |
396 ASSERT_TRUE(test_server()->Start()); | |
397 | |
398 // First we navigate to our page. | 391 // First we navigate to our page. |
399 GURL url = test_server()->GetURL(kFramePage); | 392 GURL url = GetURL(kFramePage); |
400 ui_test_utils::NavigateToURL(browser(), url); | 393 ui_test_utils::NavigateToURL(browser(), url); |
401 | 394 |
402 // Search for 'a', which should make the first item active and return | 395 // Search for 'a', which should make the first item active and return |
403 // '1 in 7' (1st ordinal of a total of 7 matches). | 396 // '1 in 7' (1st ordinal of a total of 7 matches). |
404 TabContentsWrapper* tab = browser()->GetSelectedTabContentsWrapper(); | 397 TabContentsWrapper* tab = browser()->GetSelectedTabContentsWrapper(); |
405 int ordinal = 0; | 398 int ordinal = 0; |
406 EXPECT_EQ(7, | 399 EXPECT_EQ(7, |
407 FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal)); | 400 FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal)); |
408 EXPECT_EQ(1, ordinal); | 401 EXPECT_EQ(1, ordinal); |
409 EXPECT_EQ(7, | 402 EXPECT_EQ(7, |
(...skipping 27 matching lines...) Expand all Loading... |
437 EXPECT_EQ(1, ordinal); | 430 EXPECT_EQ(1, ordinal); |
438 // Now we should wrap back to frame last frame. | 431 // Now we should wrap back to frame last frame. |
439 EXPECT_EQ(7, | 432 EXPECT_EQ(7, |
440 FindInPageWchar(tab, L"a", kBack, kIgnoreCase, &ordinal)); | 433 FindInPageWchar(tab, L"a", kBack, kIgnoreCase, &ordinal)); |
441 EXPECT_EQ(7, ordinal); | 434 EXPECT_EQ(7, ordinal); |
442 } | 435 } |
443 | 436 |
444 // We could get ordinals out of whack when restarting search in subframes. | 437 // We could get ordinals out of whack when restarting search in subframes. |
445 // See http://crbug.com/5132. | 438 // See http://crbug.com/5132. |
446 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPage_Issue5132) { | 439 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPage_Issue5132) { |
447 ASSERT_TRUE(test_server()->Start()); | |
448 | |
449 // First we navigate to our page. | 440 // First we navigate to our page. |
450 GURL url = test_server()->GetURL(kFramePage); | 441 GURL url = GetURL(kFramePage); |
451 ui_test_utils::NavigateToURL(browser(), url); | 442 ui_test_utils::NavigateToURL(browser(), url); |
452 | 443 |
453 // Search for 'goa' three times (6 matches on page). | 444 // Search for 'goa' three times (6 matches on page). |
454 int ordinal = 0; | 445 int ordinal = 0; |
455 TabContentsWrapper* tab = browser()->GetSelectedTabContentsWrapper(); | 446 TabContentsWrapper* tab = browser()->GetSelectedTabContentsWrapper(); |
456 EXPECT_EQ(6, FindInPageWchar(tab, L"goa", | 447 EXPECT_EQ(6, FindInPageWchar(tab, L"goa", |
457 kFwd, kIgnoreCase, &ordinal)); | 448 kFwd, kIgnoreCase, &ordinal)); |
458 EXPECT_EQ(1, ordinal); | 449 EXPECT_EQ(1, ordinal); |
459 EXPECT_EQ(6, FindInPageWchar(tab, L"goa", | 450 EXPECT_EQ(6, FindInPageWchar(tab, L"goa", |
460 kFwd, kIgnoreCase, &ordinal)); | 451 kFwd, kIgnoreCase, &ordinal)); |
461 EXPECT_EQ(2, ordinal); | 452 EXPECT_EQ(2, ordinal); |
462 EXPECT_EQ(6, FindInPageWchar(tab, L"goa", | 453 EXPECT_EQ(6, FindInPageWchar(tab, L"goa", |
463 kFwd, kIgnoreCase, &ordinal)); | 454 kFwd, kIgnoreCase, &ordinal)); |
464 EXPECT_EQ(3, ordinal); | 455 EXPECT_EQ(3, ordinal); |
465 // Add space to search (should result in no matches). | 456 // Add space to search (should result in no matches). |
466 EXPECT_EQ(0, FindInPageWchar(tab, L"goa ", | 457 EXPECT_EQ(0, FindInPageWchar(tab, L"goa ", |
467 kFwd, kIgnoreCase, &ordinal)); | 458 kFwd, kIgnoreCase, &ordinal)); |
468 EXPECT_EQ(0, ordinal); | 459 EXPECT_EQ(0, ordinal); |
469 // Remove the space, should be back to '3 out of 6') | 460 // Remove the space, should be back to '3 out of 6') |
470 EXPECT_EQ(6, FindInPageWchar(tab, L"goa", | 461 EXPECT_EQ(6, FindInPageWchar(tab, L"goa", |
471 kFwd, kIgnoreCase, &ordinal)); | 462 kFwd, kIgnoreCase, &ordinal)); |
472 EXPECT_EQ(3, ordinal); | 463 EXPECT_EQ(3, ordinal); |
473 } | 464 } |
474 | 465 |
475 // Load a page with no selectable text and make sure we don't crash. | 466 // Load a page with no selectable text and make sure we don't crash. |
476 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindUnselectableText) { | 467 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindUnselectableText) { |
477 ASSERT_TRUE(test_server()->Start()); | |
478 | |
479 // First we navigate to our page. | 468 // First we navigate to our page. |
480 GURL url = test_server()->GetURL(kUserSelectPage); | 469 GURL url = GetURL(kUserSelectPage); |
481 ui_test_utils::NavigateToURL(browser(), url); | 470 ui_test_utils::NavigateToURL(browser(), url); |
482 | 471 |
483 int ordinal = 0; | 472 int ordinal = 0; |
484 TabContentsWrapper* tab = browser()->GetSelectedTabContentsWrapper(); | 473 TabContentsWrapper* tab = browser()->GetSelectedTabContentsWrapper(); |
485 EXPECT_EQ(1, FindInPageWchar(tab, L"text", kFwd, kIgnoreCase, &ordinal)); | 474 EXPECT_EQ(1, FindInPageWchar(tab, L"text", kFwd, kIgnoreCase, &ordinal)); |
486 EXPECT_EQ(1, ordinal); | 475 EXPECT_EQ(1, ordinal); |
487 } | 476 } |
488 | 477 |
489 // Try to reproduce the crash seen in issue 1341577. | 478 // Try to reproduce the crash seen in issue 1341577. |
490 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindCrash_Issue1341577) { | 479 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindCrash_Issue1341577) { |
491 ASSERT_TRUE(test_server()->Start()); | |
492 | |
493 // First we navigate to our page. | 480 // First we navigate to our page. |
494 GURL url = test_server()->GetURL(kCrashPage); | 481 GURL url = GetURL(kCrashPage); |
495 ui_test_utils::NavigateToURL(browser(), url); | 482 ui_test_utils::NavigateToURL(browser(), url); |
496 | 483 |
497 // This would crash the tab. These must be the first two find requests issued | 484 // This would crash the tab. These must be the first two find requests issued |
498 // against the frame, otherwise an active frame pointer is set and it wont | 485 // against the frame, otherwise an active frame pointer is set and it wont |
499 // produce the crash. | 486 // produce the crash. |
500 // We used to check the return value and |ordinal|. With ICU 4.2, FiP does | 487 // We used to check the return value and |ordinal|. With ICU 4.2, FiP does |
501 // not find a stand-alone dependent vowel sign of Indic scripts. So, the | 488 // not find a stand-alone dependent vowel sign of Indic scripts. So, the |
502 // exptected values are all 0. To make this test pass regardless of | 489 // exptected values are all 0. To make this test pass regardless of |
503 // ICU version, we just call FiP and see if there's any crash. | 490 // ICU version, we just call FiP and see if there's any crash. |
504 // TODO(jungshik): According to a native Malayalam speaker, it's ok not | 491 // TODO(jungshik): According to a native Malayalam speaker, it's ok not |
505 // to find U+0D4C. Still need to investigate further this issue. | 492 // to find U+0D4C. Still need to investigate further this issue. |
506 int ordinal = 0; | 493 int ordinal = 0; |
507 TabContentsWrapper* tab = browser()->GetSelectedTabContentsWrapper(); | 494 TabContentsWrapper* tab = browser()->GetSelectedTabContentsWrapper(); |
508 FindInPageWchar(tab, L"\u0D4C", kFwd, kIgnoreCase, &ordinal); | 495 FindInPageWchar(tab, L"\u0D4C", kFwd, kIgnoreCase, &ordinal); |
509 FindInPageWchar(tab, L"\u0D4C", kFwd, kIgnoreCase, &ordinal); | 496 FindInPageWchar(tab, L"\u0D4C", kFwd, kIgnoreCase, &ordinal); |
510 | 497 |
511 // This should work fine. | 498 // This should work fine. |
512 EXPECT_EQ(1, FindInPageWchar(tab, L"\u0D24\u0D46", | 499 EXPECT_EQ(1, FindInPageWchar(tab, L"\u0D24\u0D46", |
513 kFwd, kIgnoreCase, &ordinal)); | 500 kFwd, kIgnoreCase, &ordinal)); |
514 EXPECT_EQ(1, ordinal); | 501 EXPECT_EQ(1, ordinal); |
515 EXPECT_EQ(0, FindInPageWchar(tab, L"nostring", | 502 EXPECT_EQ(0, FindInPageWchar(tab, L"nostring", |
516 kFwd, kIgnoreCase, &ordinal)); | 503 kFwd, kIgnoreCase, &ordinal)); |
517 EXPECT_EQ(0, ordinal); | 504 EXPECT_EQ(0, ordinal); |
518 } | 505 } |
519 | 506 |
520 // Try to reproduce the crash seen in http://crbug.com/14491, where an assert | 507 // Try to reproduce the crash seen in http://crbug.com/14491, where an assert |
521 // hits in the BitStack size comparison in WebKit. | 508 // hits in the BitStack size comparison in WebKit. |
522 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindCrash_Issue14491) { | 509 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindCrash_Issue14491) { |
523 ASSERT_TRUE(test_server()->Start()); | |
524 | |
525 // First we navigate to our page. | 510 // First we navigate to our page. |
526 GURL url = test_server()->GetURL(kBitstackCrash); | 511 GURL url = GetURL(kBitstackCrash); |
527 ui_test_utils::NavigateToURL(browser(), url); | 512 ui_test_utils::NavigateToURL(browser(), url); |
528 | 513 |
529 // This used to crash the tab. | 514 // This used to crash the tab. |
530 int ordinal = 0; | 515 int ordinal = 0; |
531 EXPECT_EQ(0, FindInPageWchar(browser()->GetSelectedTabContentsWrapper(), | 516 EXPECT_EQ(0, FindInPageWchar(browser()->GetSelectedTabContentsWrapper(), |
532 L"s", kFwd, kIgnoreCase, &ordinal)); | 517 L"s", kFwd, kIgnoreCase, &ordinal)); |
533 EXPECT_EQ(0, ordinal); | 518 EXPECT_EQ(0, ordinal); |
534 } | 519 } |
535 | 520 |
536 // Test to make sure Find does the right thing when restarting from a timeout. | 521 // Test to make sure Find does the right thing when restarting from a timeout. |
537 // We used to have a problem where we'd stop finding matches when all of the | 522 // We used to have a problem where we'd stop finding matches when all of the |
538 // following conditions were true: | 523 // following conditions were true: |
539 // 1) The page has a lot of text to search. | 524 // 1) The page has a lot of text to search. |
540 // 2) The page contains more than one match. | 525 // 2) The page contains more than one match. |
541 // 3) It takes longer than the time-slice given to each Find operation (100 | 526 // 3) It takes longer than the time-slice given to each Find operation (100 |
542 // ms) to find one or more of those matches (so Find times out and has to try | 527 // ms) to find one or more of those matches (so Find times out and has to try |
543 // again from where it left off). | 528 // again from where it left off). |
544 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindRestarts_Issue1155639) { | 529 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindRestarts_Issue1155639) { |
545 ASSERT_TRUE(test_server()->Start()); | |
546 | |
547 // First we navigate to our page. | 530 // First we navigate to our page. |
548 GURL url = test_server()->GetURL(kTooFewMatchesPage); | 531 GURL url = GetURL(kTooFewMatchesPage); |
549 ui_test_utils::NavigateToURL(browser(), url); | 532 ui_test_utils::NavigateToURL(browser(), url); |
550 | 533 |
551 // This string appears 5 times at the bottom of a long page. If Find restarts | 534 // This string appears 5 times at the bottom of a long page. If Find restarts |
552 // properly after a timeout, it will find 5 matches, not just 1. | 535 // properly after a timeout, it will find 5 matches, not just 1. |
553 int ordinal = 0; | 536 int ordinal = 0; |
554 EXPECT_EQ(5, FindInPageWchar(browser()->GetSelectedTabContentsWrapper(), | 537 EXPECT_EQ(5, FindInPageWchar(browser()->GetSelectedTabContentsWrapper(), |
555 L"008.xml", | 538 L"008.xml", |
556 kFwd, kIgnoreCase, &ordinal)); | 539 kFwd, kIgnoreCase, &ordinal)); |
557 EXPECT_EQ(1, ordinal); | 540 EXPECT_EQ(1, ordinal); |
558 } | 541 } |
559 | 542 |
560 // Make sure we don't get into an infinite loop when text box contains very | 543 // Make sure we don't get into an infinite loop when text box contains very |
561 // large amount of text. | 544 // large amount of text. |
562 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindRestarts_Issue70505) { | 545 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindRestarts_Issue70505) { |
563 ASSERT_TRUE(test_server()->Start()); | |
564 | |
565 // First we navigate to our page. | 546 // First we navigate to our page. |
566 GURL url = test_server()->GetURL(kLongTextareaPage); | 547 GURL url = GetURL(kLongTextareaPage); |
567 ui_test_utils::NavigateToURL(browser(), url); | 548 ui_test_utils::NavigateToURL(browser(), url); |
568 | 549 |
569 // If this test hangs on the FindInPage call, then it might be a regression | 550 // If this test hangs on the FindInPage call, then it might be a regression |
570 // such as the one found in issue http://crbug.com/70505. | 551 // such as the one found in issue http://crbug.com/70505. |
571 int ordinal = 0; | 552 int ordinal = 0; |
572 FindInPageWchar(browser()->GetSelectedTabContentsWrapper(), | 553 FindInPageWchar(browser()->GetSelectedTabContentsWrapper(), |
573 L"a", kFwd, kIgnoreCase, &ordinal); | 554 L"a", kFwd, kIgnoreCase, &ordinal); |
574 EXPECT_EQ(1, ordinal); | 555 EXPECT_EQ(1, ordinal); |
575 // TODO(finnur): We cannot reliably get the matchcount for this Find call | 556 // TODO(finnur): We cannot reliably get the matchcount for this Find call |
576 // until we fix issue http://crbug.com/71176. | 557 // until we fix issue http://crbug.com/71176. |
577 } | 558 } |
578 | 559 |
579 // This tests bug 11761: FindInPage terminates search prematurely. | 560 // This tests bug 11761: FindInPage terminates search prematurely. |
580 // This test is not expected to pass until bug 11761 is fixed. | 561 // This test is not expected to pass until bug 11761 is fixed. |
581 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, | 562 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, |
582 DISABLED_FindInPagePrematureEnd) { | 563 DISABLED_FindInPagePrematureEnd) { |
583 ASSERT_TRUE(test_server()->Start()); | |
584 | |
585 // First we navigate to our special focus tracking page. | 564 // First we navigate to our special focus tracking page. |
586 GURL url = test_server()->GetURL(kPrematureEnd); | 565 GURL url = GetURL(kPrematureEnd); |
587 ui_test_utils::NavigateToURL(browser(), url); | 566 ui_test_utils::NavigateToURL(browser(), url); |
588 | 567 |
589 TabContentsWrapper* tab_contents = browser()->GetSelectedTabContentsWrapper(); | 568 TabContentsWrapper* tab_contents = browser()->GetSelectedTabContentsWrapper(); |
590 ASSERT_TRUE(NULL != tab_contents); | 569 ASSERT_TRUE(NULL != tab_contents); |
591 | 570 |
592 // Search for a text that exists within a link on the page. | 571 // Search for a text that exists within a link on the page. |
593 int ordinal = 0; | 572 int ordinal = 0; |
594 EXPECT_EQ(2, FindInPageWchar(tab_contents, L"html ", | 573 EXPECT_EQ(2, FindInPageWchar(tab_contents, L"html ", |
595 kFwd, kIgnoreCase, &ordinal)); | 574 kFwd, kIgnoreCase, &ordinal)); |
596 EXPECT_EQ(1, ordinal); | 575 EXPECT_EQ(1, ordinal); |
597 } | 576 } |
598 | 577 |
599 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindDisappearOnNavigate) { | 578 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindDisappearOnNavigate) { |
600 ASSERT_TRUE(test_server()->Start()); | |
601 | |
602 // First we navigate to our special focus tracking page. | 579 // First we navigate to our special focus tracking page. |
603 GURL url = test_server()->GetURL(kSimplePage); | 580 GURL url = GetURL(kSimple); |
604 GURL url2 = test_server()->GetURL(kFramePage); | 581 GURL url2 = GetURL(kFramePage); |
605 ui_test_utils::NavigateToURL(browser(), url); | 582 ui_test_utils::NavigateToURL(browser(), url); |
606 | 583 |
607 browser()->ShowFindBar(); | 584 browser()->ShowFindBar(); |
608 | 585 |
609 gfx::Point position; | 586 gfx::Point position; |
610 bool fully_visible = false; | 587 bool fully_visible = false; |
611 | 588 |
612 // Make sure it is open. | 589 // Make sure it is open. |
613 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); | 590 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); |
614 EXPECT_TRUE(fully_visible); | 591 EXPECT_TRUE(fully_visible); |
(...skipping 20 matching lines...) Expand all Loading... |
635 #if defined(OS_MACOSX) | 612 #if defined(OS_MACOSX) |
636 // FindDisappearOnNewTabAndHistory is flaky, at least on Mac. | 613 // FindDisappearOnNewTabAndHistory is flaky, at least on Mac. |
637 // See http://crbug.com/43072 | 614 // See http://crbug.com/43072 |
638 #define FindDisappearOnNewTabAndHistory DISABLED_FindDisappearOnNewTabAndHistory | 615 #define FindDisappearOnNewTabAndHistory DISABLED_FindDisappearOnNewTabAndHistory |
639 #endif | 616 #endif |
640 | 617 |
641 // Make sure Find box disappears when History/Downloads page is opened, and | 618 // Make sure Find box disappears when History/Downloads page is opened, and |
642 // when a New Tab is opened. | 619 // when a New Tab is opened. |
643 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, | 620 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, |
644 FindDisappearOnNewTabAndHistory) { | 621 FindDisappearOnNewTabAndHistory) { |
645 ASSERT_TRUE(test_server()->Start()); | |
646 | |
647 // First we navigate to our special focus tracking page. | 622 // First we navigate to our special focus tracking page. |
648 GURL url = test_server()->GetURL(kSimplePage); | 623 GURL url = GetURL(kSimple); |
649 ui_test_utils::NavigateToURL(browser(), url); | 624 ui_test_utils::NavigateToURL(browser(), url); |
650 | 625 |
651 browser()->ShowFindBar(); | 626 browser()->ShowFindBar(); |
652 | 627 |
653 gfx::Point position; | 628 gfx::Point position; |
654 bool fully_visible = false; | 629 bool fully_visible = false; |
655 | 630 |
656 // Make sure it is open. | 631 // Make sure it is open. |
657 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); | 632 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); |
658 EXPECT_TRUE(fully_visible); | 633 EXPECT_TRUE(fully_visible); |
(...skipping 15 matching lines...) Expand all Loading... |
674 | 649 |
675 browser()->ShowHistoryTab(); | 650 browser()->ShowHistoryTab(); |
676 | 651 |
677 // Make sure Find box is closed. | 652 // Make sure Find box is closed. |
678 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); | 653 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); |
679 EXPECT_FALSE(fully_visible); | 654 EXPECT_FALSE(fully_visible); |
680 } | 655 } |
681 | 656 |
682 // Make sure Find box moves out of the way if it is obscuring the active match. | 657 // Make sure Find box moves out of the way if it is obscuring the active match. |
683 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindMovesWhenObscuring) { | 658 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindMovesWhenObscuring) { |
684 ASSERT_TRUE(test_server()->Start()); | 659 GURL url = GetURL(kMoveIfOver); |
685 | |
686 GURL url = test_server()->GetURL(kMoveIfOver); | |
687 ui_test_utils::NavigateToURL(browser(), url); | 660 ui_test_utils::NavigateToURL(browser(), url); |
688 | 661 |
689 browser()->ShowFindBar(); | 662 browser()->ShowFindBar(); |
690 | 663 |
691 // This is needed on GTK because the reposition operation is asynchronous. | 664 // This is needed on GTK because the reposition operation is asynchronous. |
692 MessageLoop::current()->RunAllPending(); | 665 MessageLoop::current()->RunAllPending(); |
693 | 666 |
694 gfx::Point start_position; | 667 gfx::Point start_position; |
695 gfx::Point position; | 668 gfx::Point position; |
696 bool fully_visible = false; | 669 bool fully_visible = false; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 // See http://crbug.com/43070 | 717 // See http://crbug.com/43070 |
745 #define MAYBE_FindNextInNewTabUsesPrepopulate \ | 718 #define MAYBE_FindNextInNewTabUsesPrepopulate \ |
746 DISABLED_FindNextInNewTabUsesPrepopulate | 719 DISABLED_FindNextInNewTabUsesPrepopulate |
747 #else | 720 #else |
748 #define MAYBE_FindNextInNewTabUsesPrepopulate FindNextInNewTabUsesPrepopulate | 721 #define MAYBE_FindNextInNewTabUsesPrepopulate FindNextInNewTabUsesPrepopulate |
749 #endif | 722 #endif |
750 | 723 |
751 // Make sure F3 in a new tab works if Find has previous string to search for. | 724 // Make sure F3 in a new tab works if Find has previous string to search for. |
752 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, | 725 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, |
753 MAYBE_FindNextInNewTabUsesPrepopulate) { | 726 MAYBE_FindNextInNewTabUsesPrepopulate) { |
754 ASSERT_TRUE(test_server()->Start()); | |
755 | |
756 // First we navigate to any page. | 727 // First we navigate to any page. |
757 GURL url = test_server()->GetURL(kSimplePage); | 728 GURL url = GetURL(kSimple); |
758 ui_test_utils::NavigateToURL(browser(), url); | 729 ui_test_utils::NavigateToURL(browser(), url); |
759 | 730 |
760 // Search for 'no_match'. No matches should be found. | 731 // Search for 'no_match'. No matches should be found. |
761 int ordinal = 0; | 732 int ordinal = 0; |
762 TabContentsWrapper* tab = browser()->GetSelectedTabContentsWrapper(); | 733 TabContentsWrapper* tab = browser()->GetSelectedTabContentsWrapper(); |
763 EXPECT_EQ(0, FindInPageWchar(tab, L"no_match", | 734 EXPECT_EQ(0, FindInPageWchar(tab, L"no_match", |
764 kFwd, kIgnoreCase, &ordinal)); | 735 kFwd, kIgnoreCase, &ordinal)); |
765 EXPECT_EQ(0, ordinal); | 736 EXPECT_EQ(0, ordinal); |
766 | 737 |
767 // Open another tab (tab B). | 738 // Open another tab (tab B). |
(...skipping 13 matching lines...) Expand all Loading... |
781 // Simulate what happens when you press F3 for FindNext. We should get a | 752 // Simulate what happens when you press F3 for FindNext. We should get a |
782 // response here (a hang means search was aborted). | 753 // response here (a hang means search was aborted). |
783 EXPECT_EQ(0, ui_test_utils::FindInPage(tab, string16(), | 754 EXPECT_EQ(0, ui_test_utils::FindInPage(tab, string16(), |
784 kFwd, kIgnoreCase, &ordinal)); | 755 kFwd, kIgnoreCase, &ordinal)); |
785 EXPECT_EQ(0, ordinal); | 756 EXPECT_EQ(0, ordinal); |
786 } | 757 } |
787 | 758 |
788 #if defined(TOOLKIT_VIEWS) | 759 #if defined(TOOLKIT_VIEWS) |
789 // Make sure Find box grabs the Esc accelerator and restores it again. | 760 // Make sure Find box grabs the Esc accelerator and restores it again. |
790 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, AcceleratorRestoring) { | 761 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, AcceleratorRestoring) { |
791 ASSERT_TRUE(test_server()->Start()); | |
792 | |
793 // First we navigate to any page. | 762 // First we navigate to any page. |
794 GURL url = test_server()->GetURL(kSimplePage); | 763 GURL url = GetURL(kSimple); |
795 ui_test_utils::NavigateToURL(browser(), url); | 764 ui_test_utils::NavigateToURL(browser(), url); |
796 | 765 |
797 gfx::NativeWindow window = browser()->window()->GetNativeHandle(); | 766 gfx::NativeWindow window = browser()->window()->GetNativeHandle(); |
798 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); | 767 views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); |
799 views::FocusManager* focus_manager = widget->GetFocusManager(); | 768 views::FocusManager* focus_manager = widget->GetFocusManager(); |
800 | 769 |
801 // See where Escape is registered. | 770 // See where Escape is registered. |
802 ui::Accelerator escape(ui::VKEY_ESCAPE, false, false, false); | 771 ui::Accelerator escape(ui::VKEY_ESCAPE, false, false, false); |
803 ui::AcceleratorTarget* old_target = | 772 ui::AcceleratorTarget* old_target = |
804 focus_manager->GetCurrentTargetForAccelerator(escape); | 773 focus_manager->GetCurrentTargetForAccelerator(escape); |
(...skipping 21 matching lines...) Expand all Loading... |
826 DropdownBarHost::disable_animations_during_testing_ = false; | 795 DropdownBarHost::disable_animations_during_testing_ = false; |
827 browser()->ShowFindBar(); | 796 browser()->ShowFindBar(); |
828 EXPECT_EQ(new_target, | 797 EXPECT_EQ(new_target, |
829 focus_manager->GetCurrentTargetForAccelerator(escape)); | 798 focus_manager->GetCurrentTargetForAccelerator(escape)); |
830 } | 799 } |
831 #endif // TOOLKIT_VIEWS | 800 #endif // TOOLKIT_VIEWS |
832 | 801 |
833 // Make sure Find box does not become UI-inactive when no text is in the box as | 802 // Make sure Find box does not become UI-inactive when no text is in the box as |
834 // we switch to a tab contents with an empty find string. See issue 13570. | 803 // we switch to a tab contents with an empty find string. See issue 13570. |
835 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, StayActive) { | 804 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, StayActive) { |
836 ASSERT_TRUE(test_server()->Start()); | |
837 | |
838 // First we navigate to any page. | 805 // First we navigate to any page. |
839 GURL url = test_server()->GetURL(kSimplePage); | 806 GURL url = GetURL(kSimple); |
840 ui_test_utils::NavigateToURL(browser(), url); | 807 ui_test_utils::NavigateToURL(browser(), url); |
841 | 808 |
842 browser()->ShowFindBar(); | 809 browser()->ShowFindBar(); |
843 | 810 |
844 // Simulate a user clearing the search string. Ideally, we should be | 811 // Simulate a user clearing the search string. Ideally, we should be |
845 // simulating keypresses here for searching for something and pressing | 812 // simulating keypresses here for searching for something and pressing |
846 // backspace, but that's been proven flaky in the past, so we go straight to | 813 // backspace, but that's been proven flaky in the past, so we go straight to |
847 // tab_contents. | 814 // tab_contents. |
848 FindTabHelper* find_tab_helper = | 815 FindTabHelper* find_tab_helper = |
849 browser()->GetSelectedTabContentsWrapper()->find_tab_helper(); | 816 browser()->GetSelectedTabContentsWrapper()->find_tab_helper(); |
850 // Stop the (non-existing) find operation, and clear the selection (which | 817 // Stop the (non-existing) find operation, and clear the selection (which |
851 // signals the UI is still active). | 818 // signals the UI is still active). |
852 find_tab_helper->StopFinding(FindBarController::kClearSelection); | 819 find_tab_helper->StopFinding(FindBarController::kClearSelection); |
853 // Make sure the Find UI flag hasn't been cleared, it must be so that the UI | 820 // Make sure the Find UI flag hasn't been cleared, it must be so that the UI |
854 // still responds to browser window resizing. | 821 // still responds to browser window resizing. |
855 ASSERT_TRUE(find_tab_helper->find_ui_active()); | 822 ASSERT_TRUE(find_tab_helper->find_ui_active()); |
856 } | 823 } |
857 | 824 |
858 // Make sure F3 works after you FindNext a couple of times and end the Find | 825 // Make sure F3 works after you FindNext a couple of times and end the Find |
859 // session. See issue http://crbug.com/28306. | 826 // session. See issue http://crbug.com/28306. |
860 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, RestartSearchFromF3) { | 827 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, RestartSearchFromF3) { |
861 ASSERT_TRUE(test_server()->Start()); | |
862 | |
863 // First we navigate to a simple page. | 828 // First we navigate to a simple page. |
864 GURL url = test_server()->GetURL(kSimple); | 829 GURL url = GetURL(kSimple); |
865 ui_test_utils::NavigateToURL(browser(), url); | 830 ui_test_utils::NavigateToURL(browser(), url); |
866 | 831 |
867 // Search for 'page'. Should have 1 match. | 832 // Search for 'page'. Should have 1 match. |
868 int ordinal = 0; | 833 int ordinal = 0; |
869 TabContentsWrapper* tab = browser()->GetSelectedTabContentsWrapper(); | 834 TabContentsWrapper* tab = browser()->GetSelectedTabContentsWrapper(); |
870 EXPECT_EQ(1, FindInPageWchar(tab, L"page", kFwd, kIgnoreCase, &ordinal)); | 835 EXPECT_EQ(1, FindInPageWchar(tab, L"page", kFwd, kIgnoreCase, &ordinal)); |
871 EXPECT_EQ(1, ordinal); | 836 EXPECT_EQ(1, ordinal); |
872 | 837 |
873 // Simulate what happens when you press F3 for FindNext. Still should show | 838 // Simulate what happens when you press F3 for FindNext. Still should show |
874 // one match. This cleared the pre-populate string at one point (see bug). | 839 // one match. This cleared the pre-populate string at one point (see bug). |
875 EXPECT_EQ(1, ui_test_utils::FindInPage(tab, string16(), | 840 EXPECT_EQ(1, ui_test_utils::FindInPage(tab, string16(), |
876 kFwd, kIgnoreCase, &ordinal)); | 841 kFwd, kIgnoreCase, &ordinal)); |
877 EXPECT_EQ(1, ordinal); | 842 EXPECT_EQ(1, ordinal); |
878 | 843 |
879 // End the Find session, thereby making the next F3 start afresh. | 844 // End the Find session, thereby making the next F3 start afresh. |
880 browser()->GetFindBarController()->EndFindSession( | 845 browser()->GetFindBarController()->EndFindSession( |
881 FindBarController::kKeepSelection); | 846 FindBarController::kKeepSelection); |
882 | 847 |
883 // Simulate F3 while Find box is closed. Should have 1 match. | 848 // Simulate F3 while Find box is closed. Should have 1 match. |
884 EXPECT_EQ(1, FindInPageWchar(tab, L"", kFwd, kIgnoreCase, &ordinal)); | 849 EXPECT_EQ(1, FindInPageWchar(tab, L"", kFwd, kIgnoreCase, &ordinal)); |
885 EXPECT_EQ(1, ordinal); | 850 EXPECT_EQ(1, ordinal); |
886 } | 851 } |
887 | 852 |
888 // When re-opening the find bar with F3, the find bar should be re-populated | 853 // When re-opening the find bar with F3, the find bar should be re-populated |
889 // with the last search from the same tab rather than the last overall search. | 854 // with the last search from the same tab rather than the last overall search. |
890 // http://crbug.com/30006 | 855 // http://crbug.com/30006 |
891 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PreferPreviousSearch) { | 856 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PreferPreviousSearch) { |
892 ASSERT_TRUE(test_server()->Start()); | |
893 | |
894 // First we navigate to any page. | 857 // First we navigate to any page. |
895 GURL url = test_server()->GetURL(kSimplePage); | 858 GURL url = GetURL(kSimple); |
896 ui_test_utils::NavigateToURL(browser(), url); | 859 ui_test_utils::NavigateToURL(browser(), url); |
897 | 860 |
898 // Find "Default". | 861 // Find "Default". |
899 int ordinal = 0; | 862 int ordinal = 0; |
900 TabContentsWrapper* tab1 = browser()->GetSelectedTabContentsWrapper(); | 863 TabContentsWrapper* tab1 = browser()->GetSelectedTabContentsWrapper(); |
901 EXPECT_EQ(1, FindInPageWchar(tab1, L"Default", kFwd, kIgnoreCase, &ordinal)); | 864 EXPECT_EQ(1, FindInPageWchar(tab1, L"text", kFwd, kIgnoreCase, &ordinal)); |
902 | 865 |
903 // Create a second tab. | 866 // Create a second tab. |
904 // For some reason we can't use AddSelectedTabWithURL here on ChromeOS. It | 867 // For some reason we can't use AddSelectedTabWithURL here on ChromeOS. It |
905 // could be some delicate assumption about the tab starting off unselected or | 868 // could be some delicate assumption about the tab starting off unselected or |
906 // something relating to user gesture. | 869 // something relating to user gesture. |
907 browser()->AddBlankTab(true); | 870 browser()->AddBlankTab(true); |
908 ui_test_utils::NavigateToURL(browser(), url); | 871 ui_test_utils::NavigateToURL(browser(), url); |
909 TabContentsWrapper* tab2 = browser()->GetSelectedTabContentsWrapper(); | 872 TabContentsWrapper* tab2 = browser()->GetSelectedTabContentsWrapper(); |
910 EXPECT_NE(tab1, tab2); | 873 EXPECT_NE(tab1, tab2); |
911 | 874 |
912 // Find "given". | 875 // Find "given". |
913 FindInPageWchar(tab2, L"given", kFwd, kIgnoreCase, &ordinal); | 876 FindInPageWchar(tab2, L"given", kFwd, kIgnoreCase, &ordinal); |
914 | 877 |
915 // Switch back to first tab. | 878 // Switch back to first tab. |
916 browser()->ActivateTabAt(0, false); | 879 browser()->ActivateTabAt(0, false); |
917 browser()->GetFindBarController()->EndFindSession( | 880 browser()->GetFindBarController()->EndFindSession( |
918 FindBarController::kKeepSelection); | 881 FindBarController::kKeepSelection); |
919 // Simulate F3. | 882 // Simulate F3. |
920 ui_test_utils::FindInPage(tab1, string16(), kFwd, kIgnoreCase, &ordinal); | 883 ui_test_utils::FindInPage(tab1, string16(), kFwd, kIgnoreCase, &ordinal); |
921 EXPECT_EQ(tab1->find_tab_helper()->find_text(), WideToUTF16(L"Default")); | 884 EXPECT_EQ(tab1->find_tab_helper()->find_text(), WideToUTF16(L"text")); |
922 } | 885 } |
923 | 886 |
924 // This tests that whenever you close and reopen the Find bar, it should show | 887 // This tests that whenever you close and reopen the Find bar, it should show |
925 // the last search entered in that tab. http://crbug.com/40121. | 888 // the last search entered in that tab. http://crbug.com/40121. |
926 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulateSameTab) { | 889 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulateSameTab) { |
927 #if defined(OS_MACOSX) | 890 #if defined(OS_MACOSX) |
928 // FindInPage on Mac doesn't use prepopulated values. Search there is global. | 891 // FindInPage on Mac doesn't use prepopulated values. Search there is global. |
929 return; | 892 return; |
930 #endif | 893 #endif |
931 | 894 |
932 ASSERT_TRUE(test_server()->Start()); | |
933 | |
934 // First we navigate to any page. | 895 // First we navigate to any page. |
935 GURL url = test_server()->GetURL(kSimple); | 896 GURL url = GetURL(kSimple); |
936 ui_test_utils::NavigateToURL(browser(), url); | 897 ui_test_utils::NavigateToURL(browser(), url); |
937 | 898 |
938 // Search for the word "page". | 899 // Search for the word "page". |
939 int ordinal = 0; | 900 int ordinal = 0; |
940 TabContentsWrapper* tab1 = browser()->GetSelectedTabContentsWrapper(); | 901 TabContentsWrapper* tab1 = browser()->GetSelectedTabContentsWrapper(); |
941 EXPECT_EQ(1, FindInPageWchar(tab1, L"page", kFwd, kIgnoreCase, &ordinal)); | 902 EXPECT_EQ(1, FindInPageWchar(tab1, L"page", kFwd, kIgnoreCase, &ordinal)); |
942 | 903 |
943 // Open the Find box. | 904 // Open the Find box. |
944 EnsureFindBoxOpen(); | 905 EnsureFindBoxOpen(); |
945 | 906 |
(...skipping 15 matching lines...) Expand all Loading... |
961 | 922 |
962 // This tests that whenever you open Find in a new tab it should prepopulate | 923 // This tests that whenever you open Find in a new tab it should prepopulate |
963 // with a previous search term (in any tab), if a search has not been issued in | 924 // with a previous search term (in any tab), if a search has not been issued in |
964 // this tab before. | 925 // this tab before. |
965 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulateInNewTab) { | 926 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulateInNewTab) { |
966 #if defined(OS_MACOSX) | 927 #if defined(OS_MACOSX) |
967 // FindInPage on Mac doesn't use prepopulated values. Search there is global. | 928 // FindInPage on Mac doesn't use prepopulated values. Search there is global. |
968 return; | 929 return; |
969 #endif | 930 #endif |
970 | 931 |
971 ASSERT_TRUE(test_server()->Start()); | |
972 | |
973 // First we navigate to any page. | 932 // First we navigate to any page. |
974 GURL url = test_server()->GetURL(kSimple); | 933 GURL url = GetURL(kSimple); |
975 ui_test_utils::NavigateToURL(browser(), url); | 934 ui_test_utils::NavigateToURL(browser(), url); |
976 | 935 |
977 // Search for the word "page". | 936 // Search for the word "page". |
978 int ordinal = 0; | 937 int ordinal = 0; |
979 TabContentsWrapper* tab1 = browser()->GetSelectedTabContentsWrapper(); | 938 TabContentsWrapper* tab1 = browser()->GetSelectedTabContentsWrapper(); |
980 EXPECT_EQ(1, FindInPageWchar(tab1, L"page", kFwd, kIgnoreCase, &ordinal)); | 939 EXPECT_EQ(1, FindInPageWchar(tab1, L"page", kFwd, kIgnoreCase, &ordinal)); |
981 EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText()); | 940 EXPECT_EQ(ASCIIToUTF16("1 of 1"), GetMatchCountText()); |
982 | 941 |
983 // Now create a second tab and load the same page. | 942 // Now create a second tab and load the same page. |
984 browser()->AddSelectedTabWithURL(url, content::PAGE_TRANSITION_TYPED); | 943 browser()->AddSelectedTabWithURL(url, content::PAGE_TRANSITION_TYPED); |
(...skipping 12 matching lines...) Expand all Loading... |
997 | 956 |
998 // This makes sure that we can search for A in tabA, then for B in tabB and | 957 // This makes sure that we can search for A in tabA, then for B in tabB and |
999 // when we come back to tabA we should still see A (because that was the last | 958 // when we come back to tabA we should still see A (because that was the last |
1000 // search in that tab). | 959 // search in that tab). |
1001 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulatePreserveLast) { | 960 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PrepopulatePreserveLast) { |
1002 #if defined(OS_MACOSX) | 961 #if defined(OS_MACOSX) |
1003 // FindInPage on Mac doesn't use prepopulated values. Search there is global. | 962 // FindInPage on Mac doesn't use prepopulated values. Search there is global. |
1004 return; | 963 return; |
1005 #endif | 964 #endif |
1006 | 965 |
1007 ASSERT_TRUE(test_server()->Start()); | |
1008 | |
1009 // First we navigate to any page. | 966 // First we navigate to any page. |
1010 GURL url = test_server()->GetURL(kSimple); | 967 GURL url = GetURL(kSimple); |
1011 ui_test_utils::NavigateToURL(browser(), url); | 968 ui_test_utils::NavigateToURL(browser(), url); |
1012 | 969 |
1013 // Search for the word "page". | 970 // Search for the word "page". |
1014 int ordinal = 0; | 971 int ordinal = 0; |
1015 TabContentsWrapper* tab1 = browser()->GetSelectedTabContentsWrapper(); | 972 TabContentsWrapper* tab1 = browser()->GetSelectedTabContentsWrapper(); |
1016 EXPECT_EQ(1, FindInPageWchar(tab1, L"page", kFwd, kIgnoreCase, &ordinal)); | 973 EXPECT_EQ(1, FindInPageWchar(tab1, L"page", kFwd, kIgnoreCase, &ordinal)); |
1017 | 974 |
1018 // Open the Find box. | 975 // Open the Find box. |
1019 EnsureFindBoxOpen(); | 976 EnsureFindBoxOpen(); |
1020 | 977 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1068 #endif | 1025 #endif |
1069 | 1026 |
1070 // This tests that search terms entered into an incognito find bar are not used | 1027 // This tests that search terms entered into an incognito find bar are not used |
1071 // as prepopulate terms for non-incognito windows. | 1028 // as prepopulate terms for non-incognito windows. |
1072 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, MAYBE_NoIncognitoPrepopulate) { | 1029 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, MAYBE_NoIncognitoPrepopulate) { |
1073 #if defined(OS_MACOSX) | 1030 #if defined(OS_MACOSX) |
1074 // FindInPage on Mac doesn't use prepopulated values. Search there is global. | 1031 // FindInPage on Mac doesn't use prepopulated values. Search there is global. |
1075 return; | 1032 return; |
1076 #endif | 1033 #endif |
1077 | 1034 |
1078 ASSERT_TRUE(test_server()->Start()); | |
1079 | |
1080 // First we navigate to the "simple" test page. | 1035 // First we navigate to the "simple" test page. |
1081 GURL url = test_server()->GetURL(kSimple); | 1036 GURL url = GetURL(kSimple); |
1082 ui_test_utils::NavigateToURL(browser(), url); | 1037 ui_test_utils::NavigateToURL(browser(), url); |
1083 | 1038 |
1084 // Search for the word "page" in the normal browser tab. | 1039 // Search for the word "page" in the normal browser tab. |
1085 int ordinal = 0; | 1040 int ordinal = 0; |
1086 TabContentsWrapper* tab1 = browser()->GetSelectedTabContentsWrapper(); | 1041 TabContentsWrapper* tab1 = browser()->GetSelectedTabContentsWrapper(); |
1087 EXPECT_EQ(1, FindInPageWchar(tab1, L"page", kFwd, kIgnoreCase, &ordinal)); | 1042 EXPECT_EQ(1, FindInPageWchar(tab1, L"page", kFwd, kIgnoreCase, &ordinal)); |
1088 | 1043 |
1089 // Open the Find box. | 1044 // Open the Find box. |
1090 EnsureFindBoxOpenForBrowser(browser()); | 1045 EnsureFindBoxOpenForBrowser(browser()); |
1091 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(browser())); | 1046 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(browser())); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1126 EXPECT_NE(tab1, tab2); | 1081 EXPECT_NE(tab1, tab2); |
1127 | 1082 |
1128 // Open the Find box and make sure it is prepopulated with the search term | 1083 // Open the Find box and make sure it is prepopulated with the search term |
1129 // from the original browser, not the search term from the incognito window. | 1084 // from the original browser, not the search term from the incognito window. |
1130 EnsureFindBoxOpenForBrowser(browser()); | 1085 EnsureFindBoxOpenForBrowser(browser()); |
1131 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(browser())); | 1086 EXPECT_EQ(ASCIIToUTF16("page"), GetFindBarTextForBrowser(browser())); |
1132 } | 1087 } |
1133 | 1088 |
1134 // This makes sure that dismissing the find bar with kActivateSelection works. | 1089 // This makes sure that dismissing the find bar with kActivateSelection works. |
1135 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, ActivateLinkNavigatesPage) { | 1090 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, ActivateLinkNavigatesPage) { |
1136 ASSERT_TRUE(test_server()->Start()); | |
1137 | |
1138 // First we navigate to our test content. | 1091 // First we navigate to our test content. |
1139 GURL url = test_server()->GetURL(kLinkPage); | 1092 GURL url = GetURL(kLinkPage); |
1140 ui_test_utils::NavigateToURL(browser(), url); | 1093 ui_test_utils::NavigateToURL(browser(), url); |
1141 | 1094 |
1142 TabContentsWrapper* tab = browser()->GetSelectedTabContentsWrapper(); | 1095 TabContentsWrapper* tab = browser()->GetSelectedTabContentsWrapper(); |
1143 int ordinal = 0; | 1096 int ordinal = 0; |
1144 FindInPageWchar(tab, L"link", kFwd, kIgnoreCase, &ordinal); | 1097 FindInPageWchar(tab, L"link", kFwd, kIgnoreCase, &ordinal); |
1145 EXPECT_EQ(ordinal, 1); | 1098 EXPECT_EQ(ordinal, 1); |
1146 | 1099 |
1147 // End the find session, click on the link. | 1100 // End the find session, click on the link. |
1148 ui_test_utils::WindowedNotificationObserver observer( | 1101 ui_test_utils::WindowedNotificationObserver observer( |
1149 content::NOTIFICATION_LOAD_STOP, | 1102 content::NOTIFICATION_LOAD_STOP, |
(...skipping 21 matching lines...) Expand all Loading... |
1171 MessageLoop::current()->RunAllPending(); | 1124 MessageLoop::current()->RunAllPending(); |
1172 | 1125 |
1173 EnsureFindBoxOpenForBrowser(popup); | 1126 EnsureFindBoxOpenForBrowser(popup); |
1174 | 1127 |
1175 // GTK adjusts FindBar size asynchronously. | 1128 // GTK adjusts FindBar size asynchronously. |
1176 MessageLoop::current()->RunAllPending(); | 1129 MessageLoop::current()->RunAllPending(); |
1177 | 1130 |
1178 ASSERT_LE(GetFindBarWidthForBrowser(popup), | 1131 ASSERT_LE(GetFindBarWidthForBrowser(popup), |
1179 popup->window()->GetBounds().width()); | 1132 popup->window()->GetBounds().width()); |
1180 } | 1133 } |
| 1134 |
| 1135 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, |
| 1136 FindMovesOnTabClose_Issue1343052) { |
| 1137 EnsureFindBoxOpen(); |
| 1138 ui_test_utils::RunAllPendingInMessageLoop(); // Needed on Linux. |
| 1139 |
| 1140 gfx::Point position; |
| 1141 EXPECT_TRUE(GetFindBarWindowInfo(&position, NULL)); |
| 1142 |
| 1143 // Open another tab. |
| 1144 GURL url = GetURL(kSimple); |
| 1145 ui_test_utils::NavigateToURLWithDisposition( |
| 1146 browser(), url, NEW_FOREGROUND_TAB, |
| 1147 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 1148 |
| 1149 // Close it. |
| 1150 browser()->CloseTab(); |
| 1151 |
| 1152 // See if the Find window has moved. |
| 1153 gfx::Point position2; |
| 1154 EXPECT_TRUE(GetFindBarWindowInfo(&position2, NULL)); |
| 1155 EXPECT_EQ(position, position2); |
| 1156 |
| 1157 // Toggle the bookmark bar state. Note that this starts an animation, and |
| 1158 // there isn't a good way other than looping and polling to see when it's |
| 1159 // done. So instead we change the state and open a new tab, since the new tab |
| 1160 // animation doesn't happen on tab change. |
| 1161 browser()->ToggleBookmarkBar(); |
| 1162 |
| 1163 ui_test_utils::NavigateToURLWithDisposition( |
| 1164 browser(), url, NEW_FOREGROUND_TAB, |
| 1165 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 1166 |
| 1167 EnsureFindBoxOpen(); |
| 1168 ui_test_utils::RunAllPendingInMessageLoop(); // Needed on Linux. |
| 1169 EXPECT_TRUE(GetFindBarWindowInfo(&position, NULL)); |
| 1170 |
| 1171 ui_test_utils::NavigateToURLWithDisposition( |
| 1172 browser(), url, NEW_FOREGROUND_TAB, |
| 1173 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 1174 browser()->CloseTab(); |
| 1175 EXPECT_TRUE(GetFindBarWindowInfo(&position2, NULL)); |
| 1176 EXPECT_EQ(position, position2); |
| 1177 } |
OLD | NEW |