OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/keyboard_codes.h" | 5 #include "base/keyboard_codes.h" |
6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
7 #include "chrome/browser/browser.h" | 7 #include "chrome/browser/browser.h" |
8 #include "chrome/browser/browser_window.h" | 8 #include "chrome/browser/browser_window.h" |
9 #include "chrome/browser/find_bar_controller.h" | 9 #include "chrome/browser/find_bar_controller.h" |
10 #include "chrome/browser/find_notification_details.h" | 10 #include "chrome/browser/find_notification_details.h" |
11 #include "chrome/browser/renderer_host/render_view_host.h" | 11 #include "chrome/browser/renderer_host/render_view_host.h" |
12 #include "chrome/browser/tab_contents/tab_contents.h" | 12 #include "chrome/browser/tab_contents/tab_contents.h" |
13 #include "chrome/browser/tab_contents/tab_contents_view.h" | 13 #include "chrome/browser/tab_contents/tab_contents_view.h" |
14 #include "chrome/browser/views/find_bar_host.h" | 14 #include "chrome/browser/views/find_bar_host.h" |
15 #include "chrome/common/notification_service.h" | 15 #include "chrome/common/notification_service.h" |
16 #include "chrome/test/in_process_browser_test.h" | 16 #include "chrome/test/in_process_browser_test.h" |
17 #include "chrome/test/ui_test_utils.h" | 17 #include "chrome/test/ui_test_utils.h" |
18 #include "views/focus/focus_manager.h" | 18 #include "views/focus/focus_manager.h" |
19 | 19 |
20 const std::wstring kSimplePage = L"404_is_enough_for_us.html"; | 20 const std::wstring kSimplePage = L"404_is_enough_for_us.html"; |
21 const std::wstring kFramePage = L"files/find_in_page/frames.html"; | 21 const std::wstring kFramePage = L"files/find_in_page/frames.html"; |
22 const std::wstring kFrameData = L"files/find_in_page/framedata_general.html"; | 22 const std::wstring kFrameData = L"files/find_in_page/framedata_general.html"; |
23 const std::wstring kUserSelectPage = L"files/find_in_page/user-select.html"; | 23 const std::wstring kUserSelectPage = L"files/find_in_page/user-select.html"; |
24 const std::wstring kCrashPage = L"files/find_in_page/crash_1341577.html"; | 24 const std::wstring kCrashPage = L"files/find_in_page/crash_1341577.html"; |
25 const std::wstring kTooFewMatchesPage = L"files/find_in_page/bug_1155639.html"; | 25 const std::wstring kTooFewMatchesPage = L"files/find_in_page/bug_1155639.html"; |
26 const std::wstring kEndState = L"files/find_in_page/end_state.html"; | 26 const std::wstring kEndState = L"files/find_in_page/end_state.html"; |
27 const std::wstring kPrematureEnd = L"files/find_in_page/premature_end.html"; | 27 const std::wstring kPrematureEnd = L"files/find_in_page/premature_end.html"; |
28 const std::wstring kMoveIfOver = L"files/find_in_page/move_if_obscuring.html"; | 28 const std::wstring kMoveIfOver = L"files/find_in_page/move_if_obscuring.html"; |
29 const std::wstring kBitstackCrash = L"files/find_in_page/crash_14491.html"; | 29 const std::wstring kBitstackCrash = L"files/find_in_page/crash_14491.html"; |
| 30 const std::wstring kSelectChangesOrdinal = |
| 31 L"files/find_in_page/select_changes_ordinal.html"; |
30 | 32 |
31 const bool kBack = false; | 33 const bool kBack = false; |
32 const bool kFwd = true; | 34 const bool kFwd = true; |
33 | 35 |
34 const bool kIgnoreCase = false; | 36 const bool kIgnoreCase = false; |
35 const bool kCaseSensitive = true; | 37 const bool kCaseSensitive = true; |
36 | 38 |
37 class FindInPageControllerTest : public InProcessBrowserTest { | 39 class FindInPageControllerTest : public InProcessBrowserTest { |
38 public: | 40 public: |
39 FindInPageControllerTest() { | 41 FindInPageControllerTest() { |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 // This should wrap to the top. | 220 // This should wrap to the top. |
219 EXPECT_EQ(3, ui_test_utils::FindInPage(tab, L"o", | 221 EXPECT_EQ(3, ui_test_utils::FindInPage(tab, L"o", |
220 kFwd, kIgnoreCase, &ordinal)); | 222 kFwd, kIgnoreCase, &ordinal)); |
221 EXPECT_EQ(1, ordinal); | 223 EXPECT_EQ(1, ordinal); |
222 // This should go back to the end. | 224 // This should go back to the end. |
223 EXPECT_EQ(3, ui_test_utils::FindInPage(tab, L"o", | 225 EXPECT_EQ(3, ui_test_utils::FindInPage(tab, L"o", |
224 kBack, kIgnoreCase, &ordinal)); | 226 kBack, kIgnoreCase, &ordinal)); |
225 EXPECT_EQ(3, ordinal); | 227 EXPECT_EQ(3, ordinal); |
226 } | 228 } |
227 | 229 |
| 230 // This tests that the ordinal is correctly adjusted after a selection |
| 231 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, |
| 232 SelectChangesOrdinal_Issue20883) { |
| 233 HTTPTestServer* server = StartHTTPServer(); |
| 234 |
| 235 // First we navigate to our test content. |
| 236 GURL url = server->TestServerPageW(kSelectChangesOrdinal); |
| 237 ui_test_utils::NavigateToURL(browser(), url); |
| 238 |
| 239 TabContents* tab_contents = browser()->GetSelectedTabContents(); |
| 240 ASSERT_TRUE(NULL != tab_contents); |
| 241 |
| 242 // Search for a text that exists within a link on the page. |
| 243 TabContents* tab = browser()->GetSelectedTabContents(); |
| 244 int ordinal = 0; |
| 245 EXPECT_EQ(4, ui_test_utils::FindInPage(tab_contents, L"google", |
| 246 kFwd, kIgnoreCase, &ordinal)); |
| 247 EXPECT_EQ(1, ordinal); |
| 248 |
| 249 // Move the selection to link 1, after searching. |
| 250 std::string result; |
| 251 ui_test_utils::ExecuteJavaScriptAndExtractString( |
| 252 tab_contents->render_view_host(), |
| 253 L"", |
| 254 L"window.domAutomationController.send(selectLink1());", |
| 255 &result); |
| 256 |
| 257 // Do a find-next after the selection. This should move forward |
| 258 // from there to the 3rd instance of 'google'. |
| 259 EXPECT_EQ(4, ui_test_utils::FindInPage(tab, L"google", |
| 260 kFwd, kIgnoreCase, &ordinal)); |
| 261 EXPECT_EQ(3, ordinal); |
| 262 |
| 263 // End the find session. |
| 264 tab_contents->StopFinding(false); |
| 265 } |
| 266 |
228 // This test loads a page with frames and makes sure the ordinal returned makes | 267 // This test loads a page with frames and makes sure the ordinal returned makes |
229 // sense. | 268 // sense. |
230 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageMultiFramesOrdinal) { | 269 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageMultiFramesOrdinal) { |
231 HTTPTestServer* server = StartHTTPServer(); | 270 HTTPTestServer* server = StartHTTPServer(); |
232 | 271 |
233 // First we navigate to our page. | 272 // First we navigate to our page. |
234 GURL url = server->TestServerPageW(kFramePage); | 273 GURL url = server->TestServerPageW(kFramePage); |
235 ui_test_utils::NavigateToURL(browser(), url); | 274 ui_test_utils::NavigateToURL(browser(), url); |
236 | 275 |
237 // Search for 'a', which should make the first item active and return | 276 // Search for 'a', which should make the first item active and return |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 // backspace, but that's been proven flaky in the past, so we go straight to | 668 // backspace, but that's been proven flaky in the past, so we go straight to |
630 // tab_contents. | 669 // tab_contents. |
631 TabContents* tab_contents = browser()->GetSelectedTabContents(); | 670 TabContents* tab_contents = browser()->GetSelectedTabContents(); |
632 // Stop the (non-existing) find operation, and clear the selection (which | 671 // Stop the (non-existing) find operation, and clear the selection (which |
633 // signals the UI is still active). | 672 // signals the UI is still active). |
634 tab_contents->StopFinding(true); | 673 tab_contents->StopFinding(true); |
635 // Make sure the Find UI flag hasn't been cleared, it must be so that the UI | 674 // Make sure the Find UI flag hasn't been cleared, it must be so that the UI |
636 // still responds to browser window resizing. | 675 // still responds to browser window resizing. |
637 ASSERT_TRUE(tab_contents->find_ui_active()); | 676 ASSERT_TRUE(tab_contents->find_ui_active()); |
638 } | 677 } |
OLD | NEW |