| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/browser/browser.h" | 6 #include "chrome/browser/browser.h" |
| 7 #include "chrome/browser/find_notification_details.h" | 7 #include "chrome/browser/find_notification_details.h" |
| 8 #include "chrome/browser/renderer_host/render_view_host.h" | 8 #include "chrome/browser/renderer_host/render_view_host.h" |
| 9 #include "chrome/browser/tab_contents/tab_contents.h" | 9 #include "chrome/browser/tab_contents/tab_contents.h" |
| 10 #include "chrome/browser/tab_contents/web_contents.h" | 10 #include "chrome/browser/tab_contents/web_contents.h" |
| 11 #include "chrome/browser/tab_contents/web_contents_view.h" | 11 #include "chrome/browser/tab_contents/web_contents_view.h" |
| 12 #include "chrome/browser/views/find_bar_win.h" | 12 #include "chrome/browser/views/find_bar_win.h" |
| 13 #include "chrome/common/notification_service.h" | 13 #include "chrome/common/notification_service.h" |
| 14 #include "chrome/test/in_process_browser_test.h" | 14 #include "chrome/test/in_process_browser_test.h" |
| 15 #include "chrome/test/ui_test_utils.h" | 15 #include "chrome/test/ui_test_utils.h" |
| 16 #include "net/base/host_resolver_unittest.h" |
| 16 | 17 |
| 17 const std::wstring kFramePage = L"files/find_in_page/frames.html"; | 18 const std::wstring kFramePage = L"files/find_in_page/frames.html"; |
| 18 const std::wstring kFrameData = L"files/find_in_page/framedata_general.html"; | 19 const std::wstring kFrameData = L"files/find_in_page/framedata_general.html"; |
| 19 const std::wstring kUserSelectPage = L"files/find_in_page/user-select.html"; | 20 const std::wstring kUserSelectPage = L"files/find_in_page/user-select.html"; |
| 20 const std::wstring kCrashPage = L"files/find_in_page/crash_1341577.html"; | 21 const std::wstring kCrashPage = L"files/find_in_page/crash_1341577.html"; |
| 21 const std::wstring kTooFewMatchesPage = L"files/find_in_page/bug_1155639.html"; | 22 const std::wstring kTooFewMatchesPage = L"files/find_in_page/bug_1155639.html"; |
| 22 | 23 |
| 23 class FindInPageNotificationObserver : public NotificationObserver { | 24 class FindInPageNotificationObserver : public NotificationObserver { |
| 24 public: | 25 public: |
| 25 explicit FindInPageNotificationObserver(TabContents* parent_tab) | 26 explicit FindInPageNotificationObserver(TabContents* parent_tab) |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 // we need to preserve it so we can send it later. | 73 // we need to preserve it so we can send it later. |
| 73 int active_match_ordinal_; | 74 int active_match_ordinal_; |
| 74 int number_of_matches_; | 75 int number_of_matches_; |
| 75 }; | 76 }; |
| 76 | 77 |
| 77 typedef enum FindInPageDirection { BACK = 0, FWD = 1 }; | 78 typedef enum FindInPageDirection { BACK = 0, FWD = 1 }; |
| 78 typedef enum FindInPageCase { IGNORE_CASE = 0, CASE_SENSITIVE = 1 }; | 79 typedef enum FindInPageCase { IGNORE_CASE = 0, CASE_SENSITIVE = 1 }; |
| 79 | 80 |
| 80 class FindInPageControllerTest : public InProcessBrowserTest { | 81 class FindInPageControllerTest : public InProcessBrowserTest { |
| 81 public: | 82 public: |
| 82 FindInPageControllerTest() {} | 83 FindInPageControllerTest() { |
| 84 host_mapper_ = new net::RuleBasedHostMapper(); |
| 85 // Avoid making external DNS lookups. In this test we don't need this |
| 86 // to succeed. |
| 87 host_mapper_->AddSimulatedFailure("*.google.com"); |
| 88 scoped_host_mapper_.Init(host_mapper_.get()); |
| 89 } |
| 83 | 90 |
| 84 protected: | 91 protected: |
| 85 int FindInPage(const std::wstring& search_string, | 92 int FindInPage(const std::wstring& search_string, |
| 86 FindInPageDirection forward, | 93 FindInPageDirection forward, |
| 87 FindInPageCase match_case, | 94 FindInPageCase match_case, |
| 88 bool find_next) { | 95 bool find_next) { |
| 89 WebContents* web_contents = | 96 WebContents* web_contents = |
| 90 browser()->GetSelectedTabContents()->AsWebContents(); | 97 browser()->GetSelectedTabContents()->AsWebContents(); |
| 91 if (web_contents) { | 98 if (web_contents) { |
| 92 web_contents->set_current_find_request_id( | 99 web_contents->set_current_find_request_id( |
| 93 FindInPageNotificationObserver::kFindInPageRequestId); | 100 FindInPageNotificationObserver::kFindInPageRequestId); |
| 94 web_contents->render_view_host()->StartFinding( | 101 web_contents->render_view_host()->StartFinding( |
| 95 FindInPageNotificationObserver::kFindInPageRequestId, | 102 FindInPageNotificationObserver::kFindInPageRequestId, |
| 96 search_string, forward == FWD, match_case == CASE_SENSITIVE, | 103 search_string, forward == FWD, match_case == CASE_SENSITIVE, |
| 97 find_next); | 104 find_next); |
| 98 return FindInPageNotificationObserver(web_contents).number_of_matches(); | 105 return FindInPageNotificationObserver(web_contents).number_of_matches(); |
| 99 } | 106 } |
| 100 return 0; | 107 return 0; |
| 101 } | 108 } |
| 109 |
| 110 private: |
| 111 scoped_refptr<net::RuleBasedHostMapper> host_mapper_; |
| 112 net::ScopedHostMapper scoped_host_mapper_; |
| 102 }; | 113 }; |
| 103 | 114 |
| 104 // This test loads a page with frames and starts FindInPage requests | 115 // This test loads a page with frames and starts FindInPage requests |
| 105 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageFrames) { | 116 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageFrames) { |
| 106 HTTPTestServer* server = StartHTTPServer(); | 117 HTTPTestServer* server = StartHTTPServer(); |
| 107 | 118 |
| 108 // First we navigate to our frames page. | 119 // First we navigate to our frames page. |
| 109 GURL url = server->TestServerPageW(kFramePage); | 120 GURL url = server->TestServerPageW(kFramePage); |
| 110 ui_test_utils::NavigateToURL(browser(), url); | 121 ui_test_utils::NavigateToURL(browser(), url); |
| 111 | 122 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 137 EXPECT_EQ(0, FindInPage(L"CAT", FWD, CASE_SENSITIVE, false)); | 148 EXPECT_EQ(0, FindInPage(L"CAT", FWD, CASE_SENSITIVE, false)); |
| 138 | 149 |
| 139 // Try again case sensitive, but this time with right case. | 150 // Try again case sensitive, but this time with right case. |
| 140 EXPECT_EQ(1, FindInPage(L"dog", FWD, CASE_SENSITIVE, false)); | 151 EXPECT_EQ(1, FindInPage(L"dog", FWD, CASE_SENSITIVE, false)); |
| 141 | 152 |
| 142 // Try non-Latin characters ('Hreggvidur' with 'eth' for 'd' in left frame). | 153 // Try non-Latin characters ('Hreggvidur' with 'eth' for 'd' in left frame). |
| 143 EXPECT_EQ(1, FindInPage(L"Hreggvi\u00F0ur", FWD, IGNORE_CASE, false)); | 154 EXPECT_EQ(1, FindInPage(L"Hreggvi\u00F0ur", FWD, IGNORE_CASE, false)); |
| 144 EXPECT_EQ(1, FindInPage(L"Hreggvi\u00F0ur", FWD, CASE_SENSITIVE, false)); | 155 EXPECT_EQ(1, FindInPage(L"Hreggvi\u00F0ur", FWD, CASE_SENSITIVE, false)); |
| 145 EXPECT_EQ(0, FindInPage(L"hreggvi\u00F0ur", FWD, CASE_SENSITIVE, false)); | 156 EXPECT_EQ(0, FindInPage(L"hreggvi\u00F0ur", FWD, CASE_SENSITIVE, false)); |
| 146 } | 157 } |
| OLD | NEW |