| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/message_loop.h" | |
| 6 #include "chrome/browser/browser.h" | |
| 7 #include "chrome/browser/browser_window.h" | |
| 8 #include "chrome/browser/find_bar_controller.h" | |
| 9 #include "chrome/browser/find_notification_details.h" | |
| 10 #include "chrome/browser/renderer_host/render_view_host.h" | |
| 11 #include "chrome/browser/tab_contents/tab_contents.h" | |
| 12 #include "chrome/browser/tab_contents/tab_contents_view.h" | |
| 13 #include "chrome/browser/views/find_bar_win.h" | |
| 14 #include "chrome/common/notification_service.h" | |
| 15 #include "chrome/test/in_process_browser_test.h" | |
| 16 #include "chrome/test/ui_test_utils.h" | |
| 17 #include "views/focus/focus_manager.h" | |
| 18 | |
| 19 const std::wstring kSimplePage = L"404_is_enough_for_us.html"; | |
| 20 const std::wstring kFramePage = L"files/find_in_page/frames.html"; | |
| 21 const std::wstring kFrameData = L"files/find_in_page/framedata_general.html"; | |
| 22 const std::wstring kUserSelectPage = L"files/find_in_page/user-select.html"; | |
| 23 const std::wstring kCrashPage = L"files/find_in_page/crash_1341577.html"; | |
| 24 const std::wstring kTooFewMatchesPage = L"files/find_in_page/bug_1155639.html"; | |
| 25 const std::wstring kEndState = L"files/find_in_page/end_state.html"; | |
| 26 const std::wstring kPrematureEnd = L"files/find_in_page/premature_end.html"; | |
| 27 const std::wstring kMoveIfOver = L"files/find_in_page/move_if_obscuring.html"; | |
| 28 const std::wstring kBitstackCrash = L"files/find_in_page/crash_14491.html"; | |
| 29 | |
| 30 namespace { | |
| 31 | |
| 32 class FindInPageNotificationObserver : public NotificationObserver { | |
| 33 public: | |
| 34 explicit FindInPageNotificationObserver(TabContents* parent_tab) | |
| 35 : parent_tab_(parent_tab), | |
| 36 active_match_ordinal_(-1), | |
| 37 number_of_matches_(0) { | |
| 38 current_find_request_id_ = parent_tab->current_find_request_id(); | |
| 39 registrar_.Add(this, NotificationType::FIND_RESULT_AVAILABLE, | |
| 40 Source<TabContents>(parent_tab_)); | |
| 41 ui_test_utils::RunMessageLoop(); | |
| 42 } | |
| 43 | |
| 44 int active_match_ordinal() const { return active_match_ordinal_; } | |
| 45 | |
| 46 int number_of_matches() const { return number_of_matches_; } | |
| 47 | |
| 48 virtual void Observe(NotificationType type, const NotificationSource& source, | |
| 49 const NotificationDetails& details) { | |
| 50 if (type == NotificationType::FIND_RESULT_AVAILABLE) { | |
| 51 Details<FindNotificationDetails> find_details(details); | |
| 52 if (find_details->request_id() == current_find_request_id_) { | |
| 53 // We get multiple responses and one of those will contain the ordinal. | |
| 54 // This message comes to us before the final update is sent. | |
| 55 if (find_details->active_match_ordinal() > -1) | |
| 56 active_match_ordinal_ = find_details->active_match_ordinal(); | |
| 57 if (find_details->final_update()) { | |
| 58 number_of_matches_ = find_details->number_of_matches(); | |
| 59 MessageLoopForUI::current()->Quit(); | |
| 60 } else { | |
| 61 DLOG(INFO) << "Ignoring, since we only care about the final message"; | |
| 62 } | |
| 63 } | |
| 64 } else { | |
| 65 NOTREACHED(); | |
| 66 } | |
| 67 } | |
| 68 | |
| 69 private: | |
| 70 NotificationRegistrar registrar_; | |
| 71 TabContents* parent_tab_; | |
| 72 // We will at some point (before final update) be notified of the ordinal and | |
| 73 // we need to preserve it so we can send it later. | |
| 74 int active_match_ordinal_; | |
| 75 int number_of_matches_; | |
| 76 // The id of the current find request, obtained from TabContents. Allows us | |
| 77 // to monitor when the search completes. | |
| 78 int current_find_request_id_; | |
| 79 }; | |
| 80 | |
| 81 } // namespace | |
| 82 | |
| 83 typedef enum { BACK = 0, FWD = 1 } FindInPageDirection; | |
| 84 typedef enum { IGNORE_CASE = 0, CASE_SENSITIVE = 1 } FindInPageCase; | |
| 85 | |
| 86 class FindInPageControllerTest : public InProcessBrowserTest { | |
| 87 public: | |
| 88 FindInPageControllerTest() { | |
| 89 EnableDOMAutomation(); | |
| 90 } | |
| 91 | |
| 92 protected: | |
| 93 int FindInPage(const std::wstring& search_string, | |
| 94 FindInPageDirection forward, | |
| 95 FindInPageCase match_case, | |
| 96 int* ordinal) { | |
| 97 TabContents* tab_contents = browser()->GetSelectedTabContents(); | |
| 98 tab_contents->StartFinding(search_string, forward == FWD, | |
| 99 match_case == CASE_SENSITIVE); | |
| 100 | |
| 101 FindInPageNotificationObserver observer = | |
| 102 FindInPageNotificationObserver(tab_contents); | |
| 103 if (ordinal) | |
| 104 *ordinal = observer.active_match_ordinal(); | |
| 105 return observer.number_of_matches(); | |
| 106 } | |
| 107 | |
| 108 void GetFindBarWindowInfo(gfx::Point* position, bool* fully_visible) { | |
| 109 FindBarTesting* find_bar = | |
| 110 browser()->find_bar()->find_bar()->GetFindBarTesting(); | |
| 111 find_bar->GetFindBarWindowInfo(position, fully_visible); | |
| 112 } | |
| 113 }; | |
| 114 | |
| 115 // This test loads a page with frames and starts FindInPage requests. | |
| 116 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageFrames) { | |
| 117 HTTPTestServer* server = StartHTTPServer(); | |
| 118 | |
| 119 // First we navigate to our frames page. | |
| 120 GURL url = server->TestServerPageW(kFramePage); | |
| 121 ui_test_utils::NavigateToURL(browser(), url); | |
| 122 | |
| 123 // Try incremental search (mimicking user typing in). | |
| 124 int ordinal = 0; | |
| 125 EXPECT_EQ(18, FindInPage(L"g", FWD, IGNORE_CASE, &ordinal)); | |
| 126 EXPECT_EQ(1, ordinal); | |
| 127 EXPECT_EQ(11, FindInPage(L"go", FWD, IGNORE_CASE, &ordinal)); | |
| 128 EXPECT_EQ(1, ordinal); | |
| 129 EXPECT_EQ(04, FindInPage(L"goo", FWD, IGNORE_CASE, &ordinal)); | |
| 130 EXPECT_EQ(1, ordinal); | |
| 131 EXPECT_EQ(03, FindInPage(L"goog", FWD, IGNORE_CASE, &ordinal)); | |
| 132 EXPECT_EQ(1, ordinal); | |
| 133 EXPECT_EQ(02, FindInPage(L"googl", FWD, IGNORE_CASE, &ordinal)); | |
| 134 EXPECT_EQ(1, ordinal); | |
| 135 EXPECT_EQ(01, FindInPage(L"google", FWD, IGNORE_CASE, &ordinal)); | |
| 136 EXPECT_EQ(1, ordinal); | |
| 137 EXPECT_EQ(00, FindInPage(L"google!", FWD, IGNORE_CASE, &ordinal)); | |
| 138 EXPECT_EQ(0, ordinal); | |
| 139 | |
| 140 // Negative test (no matches should be found). | |
| 141 EXPECT_EQ(0, FindInPage(L"Non-existing string", FWD, IGNORE_CASE, &ordinal)); | |
| 142 EXPECT_EQ(0, ordinal); | |
| 143 | |
| 144 // 'horse' only exists in the three right frames. | |
| 145 EXPECT_EQ(3, FindInPage(L"horse", FWD, IGNORE_CASE, &ordinal)); | |
| 146 EXPECT_EQ(1, ordinal); | |
| 147 | |
| 148 // 'cat' only exists in the first frame. | |
| 149 EXPECT_EQ(1, FindInPage(L"cat", FWD, IGNORE_CASE, &ordinal)); | |
| 150 EXPECT_EQ(1, ordinal); | |
| 151 | |
| 152 // Try searching again, should still come up with 1 match. | |
| 153 EXPECT_EQ(1, FindInPage(L"cat", FWD, IGNORE_CASE, &ordinal)); | |
| 154 EXPECT_EQ(1, ordinal); | |
| 155 | |
| 156 // Try searching backwards, ignoring case, should still come up with 1 match. | |
| 157 EXPECT_EQ(1, FindInPage(L"CAT", BACK, IGNORE_CASE, &ordinal)); | |
| 158 EXPECT_EQ(1, ordinal); | |
| 159 | |
| 160 // Try case sensitive, should NOT find it. | |
| 161 EXPECT_EQ(0, FindInPage(L"CAT", FWD, CASE_SENSITIVE, &ordinal)); | |
| 162 EXPECT_EQ(0, ordinal); | |
| 163 | |
| 164 // Try again case sensitive, but this time with right case. | |
| 165 EXPECT_EQ(1, FindInPage(L"dog", FWD, CASE_SENSITIVE, &ordinal)); | |
| 166 EXPECT_EQ(1, ordinal); | |
| 167 | |
| 168 // Try non-Latin characters ('Hreggvidur' with 'eth' for 'd' in left frame). | |
| 169 EXPECT_EQ(1, FindInPage(L"Hreggvi\u00F0ur", FWD, IGNORE_CASE, &ordinal)); | |
| 170 EXPECT_EQ(1, ordinal); | |
| 171 EXPECT_EQ(1, FindInPage(L"Hreggvi\u00F0ur", FWD, CASE_SENSITIVE, &ordinal)); | |
| 172 EXPECT_EQ(1, ordinal); | |
| 173 EXPECT_EQ(0, FindInPage(L"hreggvi\u00F0ur", FWD, CASE_SENSITIVE, &ordinal)); | |
| 174 EXPECT_EQ(0, ordinal); | |
| 175 } | |
| 176 | |
| 177 std::string FocusedOnPage(TabContents* tab_contents) { | |
| 178 std::string result; | |
| 179 ui_test_utils::ExecuteJavaScriptAndExtractString( | |
| 180 tab_contents->render_view_host(), | |
| 181 L"", | |
| 182 L"window.domAutomationController.send(getFocusedElement());", | |
| 183 &result); | |
| 184 return result; | |
| 185 } | |
| 186 | |
| 187 // This tests the FindInPage end-state, in other words: what is focused when you | |
| 188 // close the Find box (ie. if you find within a link the link should be | |
| 189 // focused). | |
| 190 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageEndState) { | |
| 191 HTTPTestServer* server = StartHTTPServer(); | |
| 192 | |
| 193 // First we navigate to our special focus tracking page. | |
| 194 GURL url = server->TestServerPageW(kEndState); | |
| 195 ui_test_utils::NavigateToURL(browser(), url); | |
| 196 | |
| 197 TabContents* tab_contents = browser()->GetSelectedTabContents(); | |
| 198 ASSERT_TRUE(NULL != tab_contents); | |
| 199 | |
| 200 // Verify that nothing has focus. | |
| 201 ASSERT_STREQ("{nothing focused}", FocusedOnPage(tab_contents).c_str()); | |
| 202 | |
| 203 // Search for a text that exists within a link on the page. | |
| 204 int ordinal = 0; | |
| 205 EXPECT_EQ(1, FindInPage(L"nk", FWD, IGNORE_CASE, &ordinal)); | |
| 206 EXPECT_EQ(1, ordinal); | |
| 207 | |
| 208 // End the find session, which should set focus to the link. | |
| 209 tab_contents->StopFinding(false); | |
| 210 | |
| 211 // Verify that the link is focused. | |
| 212 EXPECT_STREQ("link1", FocusedOnPage(tab_contents).c_str()); | |
| 213 | |
| 214 // Search for a text that exists within a link on the page. | |
| 215 EXPECT_EQ(1, FindInPage(L"Google", FWD, IGNORE_CASE, &ordinal)); | |
| 216 EXPECT_EQ(1, ordinal); | |
| 217 | |
| 218 // Move the selection to link 1, after searching. | |
| 219 std::string result; | |
| 220 ui_test_utils::ExecuteJavaScriptAndExtractString( | |
| 221 tab_contents->render_view_host(), | |
| 222 L"", | |
| 223 L"window.domAutomationController.send(selectLink1());", | |
| 224 &result); | |
| 225 | |
| 226 // End the find session. | |
| 227 tab_contents->StopFinding(false); | |
| 228 | |
| 229 // Verify that link2 is not focused. | |
| 230 EXPECT_STREQ("", FocusedOnPage(tab_contents).c_str()); | |
| 231 } | |
| 232 | |
| 233 // This test loads a single-frame page and makes sure the ordinal returned makes | |
| 234 // sense as we FindNext over all the items. | |
| 235 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageOrdinal) { | |
| 236 HTTPTestServer* server = StartHTTPServer(); | |
| 237 | |
| 238 // First we navigate to our page. | |
| 239 GURL url = server->TestServerPageW(kFrameData); | |
| 240 ui_test_utils::NavigateToURL(browser(), url); | |
| 241 | |
| 242 // Search for 'o', which should make the first item active and return | |
| 243 // '1 in 3' (1st ordinal of a total of 3 matches). | |
| 244 int ordinal = 0; | |
| 245 EXPECT_EQ(3, FindInPage(L"o", FWD, IGNORE_CASE, &ordinal)); | |
| 246 EXPECT_EQ(1, ordinal); | |
| 247 EXPECT_EQ(3, FindInPage(L"o", FWD, IGNORE_CASE, &ordinal)); | |
| 248 EXPECT_EQ(2, ordinal); | |
| 249 EXPECT_EQ(3, FindInPage(L"o", FWD, IGNORE_CASE, &ordinal)); | |
| 250 EXPECT_EQ(3, ordinal); | |
| 251 // Go back one match. | |
| 252 EXPECT_EQ(3, FindInPage(L"o", BACK, IGNORE_CASE, &ordinal)); | |
| 253 EXPECT_EQ(2, ordinal); | |
| 254 EXPECT_EQ(3, FindInPage(L"o", FWD, IGNORE_CASE, &ordinal)); | |
| 255 EXPECT_EQ(3, ordinal); | |
| 256 // This should wrap to the top. | |
| 257 EXPECT_EQ(3, FindInPage(L"o", FWD, IGNORE_CASE, &ordinal)); | |
| 258 EXPECT_EQ(1, ordinal); | |
| 259 // This should go back to the end. | |
| 260 EXPECT_EQ(3, FindInPage(L"o", BACK, IGNORE_CASE, &ordinal)); | |
| 261 EXPECT_EQ(3, ordinal); | |
| 262 } | |
| 263 | |
| 264 // This test loads a page with frames and makes sure the ordinal returned makes | |
| 265 // sense. | |
| 266 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageMultiFramesOrdinal) { | |
| 267 HTTPTestServer* server = StartHTTPServer(); | |
| 268 | |
| 269 // First we navigate to our page. | |
| 270 GURL url = server->TestServerPageW(kFramePage); | |
| 271 ui_test_utils::NavigateToURL(browser(), url); | |
| 272 | |
| 273 // Search for 'a', which should make the first item active and return | |
| 274 // '1 in 7' (1st ordinal of a total of 7 matches). | |
| 275 int ordinal = 0; | |
| 276 EXPECT_EQ(7, FindInPage(L"a", FWD, IGNORE_CASE, &ordinal)); | |
| 277 EXPECT_EQ(1, ordinal); | |
| 278 EXPECT_EQ(7, FindInPage(L"a", FWD, IGNORE_CASE, &ordinal)); | |
| 279 EXPECT_EQ(2, ordinal); | |
| 280 EXPECT_EQ(7, FindInPage(L"a", FWD, IGNORE_CASE, &ordinal)); | |
| 281 EXPECT_EQ(3, ordinal); | |
| 282 EXPECT_EQ(7, FindInPage(L"a", FWD, IGNORE_CASE, &ordinal)); | |
| 283 EXPECT_EQ(4, ordinal); | |
| 284 // Go back one, which should go back one frame. | |
| 285 EXPECT_EQ(7, FindInPage(L"a", BACK, IGNORE_CASE, &ordinal)); | |
| 286 EXPECT_EQ(3, ordinal); | |
| 287 EXPECT_EQ(7, FindInPage(L"a", FWD, IGNORE_CASE, &ordinal)); | |
| 288 EXPECT_EQ(4, ordinal); | |
| 289 EXPECT_EQ(7, FindInPage(L"a", FWD, IGNORE_CASE, &ordinal)); | |
| 290 EXPECT_EQ(5, ordinal); | |
| 291 EXPECT_EQ(7, FindInPage(L"a", FWD, IGNORE_CASE, &ordinal)); | |
| 292 EXPECT_EQ(6, ordinal); | |
| 293 EXPECT_EQ(7, FindInPage(L"a", FWD, IGNORE_CASE, &ordinal)); | |
| 294 EXPECT_EQ(7, ordinal); | |
| 295 // Now we should wrap back to frame 1. | |
| 296 EXPECT_EQ(7, FindInPage(L"a", FWD, IGNORE_CASE, &ordinal)); | |
| 297 EXPECT_EQ(1, ordinal); | |
| 298 // Now we should wrap back to frame last frame. | |
| 299 EXPECT_EQ(7, FindInPage(L"a", BACK, IGNORE_CASE, &ordinal)); | |
| 300 EXPECT_EQ(7, ordinal); | |
| 301 } | |
| 302 | |
| 303 // We could get ordinals out of whack when restarting search in subframes. | |
| 304 // See http://crbug.com/5132 | |
| 305 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPage_Issue5132) { | |
| 306 HTTPTestServer* server = StartHTTPServer(); | |
| 307 | |
| 308 // First we navigate to our page. | |
| 309 GURL url = server->TestServerPageW(kFramePage); | |
| 310 ui_test_utils::NavigateToURL(browser(), url); | |
| 311 | |
| 312 // Search for 'goa' three times (6 matches on page). | |
| 313 int ordinal = 0; | |
| 314 EXPECT_EQ(6, FindInPage(L"goa", FWD, IGNORE_CASE, &ordinal)); | |
| 315 EXPECT_EQ(1, ordinal); | |
| 316 EXPECT_EQ(6, FindInPage(L"goa", FWD, IGNORE_CASE, &ordinal)); | |
| 317 EXPECT_EQ(2, ordinal); | |
| 318 EXPECT_EQ(6, FindInPage(L"goa", FWD, IGNORE_CASE, &ordinal)); | |
| 319 EXPECT_EQ(3, ordinal); | |
| 320 // Add space to search (should result in no matches). | |
| 321 EXPECT_EQ(0, FindInPage(L"goa ", FWD, IGNORE_CASE, &ordinal)); | |
| 322 EXPECT_EQ(0, ordinal); | |
| 323 // Remove the space, should be back to '3 out of 6') | |
| 324 EXPECT_EQ(6, FindInPage(L"goa", FWD, IGNORE_CASE, &ordinal)); | |
| 325 EXPECT_EQ(3, ordinal); | |
| 326 } | |
| 327 | |
| 328 // Load a page with no selectable text and make sure we don't crash. | |
| 329 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindUnSelectableText) { | |
| 330 HTTPTestServer* server = StartHTTPServer(); | |
| 331 | |
| 332 // First we navigate to our page. | |
| 333 GURL url = server->TestServerPageW(kUserSelectPage); | |
| 334 ui_test_utils::NavigateToURL(browser(), url); | |
| 335 | |
| 336 int ordinal = 0; | |
| 337 EXPECT_EQ(0, FindInPage(L"text", FWD, IGNORE_CASE, &ordinal)); | |
| 338 EXPECT_EQ(-1, ordinal); // Nothing is selected. | |
| 339 EXPECT_EQ(0, FindInPage(L"Non-existing string", FWD, IGNORE_CASE, &ordinal)); | |
| 340 EXPECT_EQ(0, ordinal); | |
| 341 } | |
| 342 | |
| 343 // Try to reproduce the crash seen in issue 1341577. | |
| 344 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindCrash_Issue1341577) { | |
| 345 HTTPTestServer* server = StartHTTPServer(); | |
| 346 | |
| 347 // First we navigate to our page. | |
| 348 GURL url = server->TestServerPageW(kCrashPage); | |
| 349 ui_test_utils::NavigateToURL(browser(), url); | |
| 350 | |
| 351 // This would crash the tab. These must be the first two find requests issued | |
| 352 // against the frame, otherwise an active frame pointer is set and it wont | |
| 353 // produce the crash. | |
| 354 // We used to check the return value and |ordinal|. With ICU 4.2, FiP does | |
| 355 // not find a stand-alone dependent vowel sign of Indic scripts. So, the | |
| 356 // exptected values are all 0. To make this test pass regardless of | |
| 357 // ICU version, we just call FiP and see if there's any crash. | |
| 358 // TODO(jungshik): According to a native Malayalam speaker, it's ok not | |
| 359 // to find U+0D4C. Still need to investigate further this issue. | |
| 360 int ordinal = 0; | |
| 361 FindInPage(L"\u0D4C", FWD, IGNORE_CASE, &ordinal); | |
| 362 FindInPage(L"\u0D4C", FWD, IGNORE_CASE, &ordinal); | |
| 363 | |
| 364 // This should work fine. | |
| 365 EXPECT_EQ(1, FindInPage(L"\u0D24\u0D46", FWD, IGNORE_CASE, &ordinal)); | |
| 366 EXPECT_EQ(1, ordinal); | |
| 367 EXPECT_EQ(0, FindInPage(L"nostring", FWD, IGNORE_CASE, &ordinal)); | |
| 368 EXPECT_EQ(0, ordinal); | |
| 369 } | |
| 370 | |
| 371 // Try to reproduce the crash seen in http://crbug.com/14491, where an assert | |
| 372 // hits in the BitStack size comparison in WebKit. | |
| 373 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindCrash_Issue14491) { | |
| 374 HTTPTestServer* server = StartHTTPServer(); | |
| 375 | |
| 376 // First we navigate to our page. | |
| 377 GURL url = server->TestServerPageW(kBitstackCrash); | |
| 378 ui_test_utils::NavigateToURL(browser(), url); | |
| 379 | |
| 380 // This used to crash the tab. | |
| 381 int ordinal = 0; | |
| 382 EXPECT_EQ(0, FindInPage(L"s", FWD, IGNORE_CASE, &ordinal)); | |
| 383 EXPECT_EQ(0, ordinal); | |
| 384 } | |
| 385 | |
| 386 // Test to make sure Find does the right thing when restarting from a timeout. | |
| 387 // We used to have a problem where we'd stop finding matches when all of the | |
| 388 // following conditions were true: | |
| 389 // 1) The page has a lot of text to search. | |
| 390 // 2) The page contains more than one match. | |
| 391 // 3) It takes longer than the time-slice given to each Find operation (100 | |
| 392 // ms) to find one or more of those matches (so Find times out and has to try | |
| 393 // again from where it left off). | |
| 394 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindRestarts_Issue1155639) { | |
| 395 HTTPTestServer* server = StartHTTPServer(); | |
| 396 | |
| 397 // First we navigate to our page. | |
| 398 GURL url = server->TestServerPageW(kTooFewMatchesPage); | |
| 399 ui_test_utils::NavigateToURL(browser(), url); | |
| 400 | |
| 401 // This string appears 5 times at the bottom of a long page. If Find restarts | |
| 402 // properly after a timeout, it will find 5 matches, not just 1. | |
| 403 int ordinal = 0; | |
| 404 EXPECT_EQ(5, FindInPage(L"008.xml", FWD, IGNORE_CASE, &ordinal)); | |
| 405 EXPECT_EQ(1, ordinal); | |
| 406 } | |
| 407 | |
| 408 // This tests bug 11761: FindInPage terminates search prematurely. | |
| 409 // This test will be enabled once the bug is fixed. | |
| 410 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, | |
| 411 DISABLED_FindInPagePrematureEnd) { | |
| 412 HTTPTestServer* server = StartHTTPServer(); | |
| 413 | |
| 414 // First we navigate to our special focus tracking page. | |
| 415 GURL url = server->TestServerPageW(kPrematureEnd); | |
| 416 ui_test_utils::NavigateToURL(browser(), url); | |
| 417 | |
| 418 TabContents* tab_contents = browser()->GetSelectedTabContents(); | |
| 419 ASSERT_TRUE(NULL != tab_contents); | |
| 420 | |
| 421 // Search for a text that exists within a link on the page. | |
| 422 int ordinal = 0; | |
| 423 EXPECT_EQ(2, FindInPage(L"html ", FWD, IGNORE_CASE, &ordinal)); | |
| 424 EXPECT_EQ(1, ordinal); | |
| 425 } | |
| 426 | |
| 427 // Make sure Find box disappears on Navigate but not on Refresh. | |
| 428 // Flaky, see http://crbug.com/16447. | |
| 429 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, | |
| 430 DISABLED_FindDisappearOnNavigate) { | |
| 431 HTTPTestServer* server = StartHTTPServer(); | |
| 432 | |
| 433 // First we navigate to our special focus tracking page. | |
| 434 GURL url = server->TestServerPageW(kSimplePage); | |
| 435 GURL url2 = server->TestServerPageW(kFramePage); | |
| 436 ui_test_utils::NavigateToURL(browser(), url); | |
| 437 | |
| 438 // Open the Find window with animations disabled. | |
| 439 FindBarWin::disable_animations_during_testing_ = true; | |
| 440 browser()->ShowFindBar(); | |
| 441 | |
| 442 gfx::Point position; | |
| 443 bool fully_visible = false; | |
| 444 | |
| 445 // Make sure it is open. | |
| 446 GetFindBarWindowInfo(&position, &fully_visible); | |
| 447 EXPECT_TRUE(fully_visible); | |
| 448 | |
| 449 // Reload the tab and make sure Find window doesn't go away. | |
| 450 browser()->Reload(); | |
| 451 | |
| 452 GetFindBarWindowInfo(&position, &fully_visible); | |
| 453 EXPECT_TRUE(fully_visible); | |
| 454 | |
| 455 // Navigate and make sure the Find window goes away. | |
| 456 ui_test_utils::NavigateToURL(browser(), url2); | |
| 457 | |
| 458 GetFindBarWindowInfo(&position, &fully_visible); | |
| 459 EXPECT_FALSE(fully_visible); | |
| 460 } | |
| 461 | |
| 462 // Make sure Find box disappears when History/Downloads page is opened, and | |
| 463 // when a New Tab is opened. | |
| 464 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, | |
| 465 FindDisappearOnNewTabAndHistory) { | |
| 466 HTTPTestServer* server = StartHTTPServer(); | |
| 467 | |
| 468 // First we navigate to our special focus tracking page. | |
| 469 GURL url = server->TestServerPageW(kSimplePage); | |
| 470 ui_test_utils::NavigateToURL(browser(), url); | |
| 471 | |
| 472 // Open the Find window with animations disabled. | |
| 473 FindBarWin::disable_animations_during_testing_ = true; | |
| 474 browser()->ShowFindBar(); | |
| 475 | |
| 476 gfx::Point position; | |
| 477 bool fully_visible = false; | |
| 478 | |
| 479 // Make sure it is open. | |
| 480 GetFindBarWindowInfo(&position, &fully_visible); | |
| 481 EXPECT_TRUE(fully_visible); | |
| 482 | |
| 483 // Open another tab (tab B). | |
| 484 browser()->NewTab(); | |
| 485 ui_test_utils::NavigateToURL(browser(), url); | |
| 486 | |
| 487 // Make sure Find box is closed. | |
| 488 GetFindBarWindowInfo(&position, &fully_visible); | |
| 489 EXPECT_FALSE(fully_visible); | |
| 490 | |
| 491 // Close tab B. | |
| 492 browser()->CloseTab(); | |
| 493 | |
| 494 // Make sure Find window appears again. | |
| 495 GetFindBarWindowInfo(&position, &fully_visible); | |
| 496 EXPECT_TRUE(fully_visible); | |
| 497 | |
| 498 browser()->ShowHistoryTab(); | |
| 499 | |
| 500 // Make sure Find box is closed. | |
| 501 GetFindBarWindowInfo(&position, &fully_visible); | |
| 502 EXPECT_FALSE(fully_visible); | |
| 503 } | |
| 504 | |
| 505 // Make sure Find box moves out of the way if it is obscuring the active match. | |
| 506 // Flaky, see http://crbug.com/16447. | |
| 507 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, | |
| 508 DISABLED_FindMovesWhenObscuring) { | |
| 509 HTTPTestServer* server = StartHTTPServer(); | |
| 510 | |
| 511 GURL url = server->TestServerPageW(kMoveIfOver); | |
| 512 ui_test_utils::NavigateToURL(browser(), url); | |
| 513 | |
| 514 // Open the Find window with animations disabled. | |
| 515 FindBarWin::disable_animations_during_testing_ = true; | |
| 516 browser()->ShowFindBar(); | |
| 517 | |
| 518 gfx::Point start_position; | |
| 519 gfx::Point position; | |
| 520 bool fully_visible = false; | |
| 521 | |
| 522 // Make sure it is open. | |
| 523 GetFindBarWindowInfo(&start_position, &fully_visible); | |
| 524 EXPECT_TRUE(fully_visible); | |
| 525 | |
| 526 // Search for 'dream' which the Find box is obscuring. | |
| 527 int ordinal = 0; | |
| 528 EXPECT_EQ(1, FindInPage(L"dream", FWD, IGNORE_CASE, &ordinal)); | |
| 529 EXPECT_EQ(1, ordinal); | |
| 530 | |
| 531 // Make sure Find box has moved. | |
| 532 GetFindBarWindowInfo(&position, &fully_visible); | |
| 533 EXPECT_EQ(start_position.y(), position.y()); | |
| 534 EXPECT_NE(start_position.x(), position.x()); | |
| 535 EXPECT_TRUE(fully_visible); | |
| 536 | |
| 537 // Search for 'Too much' which the Find box is not obscuring. | |
| 538 EXPECT_EQ(1, FindInPage(L"Too much", FWD, IGNORE_CASE, &ordinal)); | |
| 539 EXPECT_EQ(1, ordinal); | |
| 540 | |
| 541 // Make sure Find box has moved back to its original location. | |
| 542 GetFindBarWindowInfo(&position, &fully_visible); | |
| 543 EXPECT_EQ(start_position, position); | |
| 544 EXPECT_TRUE(fully_visible); | |
| 545 } | |
| 546 | |
| 547 // Make sure F3 in a new tab works if Find has previous string to search for. | |
| 548 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, | |
| 549 FindNextInNewTabUsesPrepopulate) { | |
| 550 HTTPTestServer* server = StartHTTPServer(); | |
| 551 | |
| 552 // First we navigate to any page. | |
| 553 GURL url = server->TestServerPageW(kSimplePage); | |
| 554 ui_test_utils::NavigateToURL(browser(), url); | |
| 555 | |
| 556 // Search for 'no_match'. No matches should be found. | |
| 557 int ordinal = 0; | |
| 558 EXPECT_EQ(0, FindInPage(L"no_match", FWD, IGNORE_CASE, &ordinal)); | |
| 559 EXPECT_EQ(0, ordinal); | |
| 560 | |
| 561 // Open another tab (tab B). | |
| 562 browser()->NewTab(); | |
| 563 ui_test_utils::NavigateToURL(browser(), url); | |
| 564 | |
| 565 // Simulate what happens when you press F3 for FindNext. We should get a | |
| 566 // response here (a hang means search was aborted). | |
| 567 EXPECT_EQ(0, FindInPage(std::wstring(), FWD, IGNORE_CASE, &ordinal)); | |
| 568 EXPECT_EQ(0, ordinal); | |
| 569 | |
| 570 // Open another tab (tab C). | |
| 571 browser()->NewTab(); | |
| 572 ui_test_utils::NavigateToURL(browser(), url); | |
| 573 | |
| 574 // Simulate what happens when you press F3 for FindNext. We should get a | |
| 575 // response here (a hang means search was aborted). | |
| 576 EXPECT_EQ(0, FindInPage(std::wstring(), FWD, IGNORE_CASE, &ordinal)); | |
| 577 EXPECT_EQ(0, ordinal); | |
| 578 } | |
| 579 | |
| 580 // Make sure Find box grabs the Esc accelerator and restores it again. | |
| 581 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, AcceleratorRestoring) { | |
| 582 HTTPTestServer* server = StartHTTPServer(); | |
| 583 | |
| 584 // First we navigate to any page. | |
| 585 GURL url = server->TestServerPageW(kSimplePage); | |
| 586 ui_test_utils::NavigateToURL(browser(), url); | |
| 587 | |
| 588 gfx::NativeView browser_view = browser()->window()->GetNativeHandle(); | |
| 589 views::FocusManager* focus_manager = | |
| 590 views::FocusManager::GetFocusManagerForNativeView(browser_view); | |
| 591 | |
| 592 // See where Escape is registered. | |
| 593 views::Accelerator escape(VK_ESCAPE, false, false, false); | |
| 594 views::AcceleratorTarget* old_target = | |
| 595 focus_manager->GetCurrentTargetForAccelerator(escape); | |
| 596 EXPECT_TRUE(old_target != NULL); | |
| 597 | |
| 598 // Open the Find box. | |
| 599 browser()->ShowFindBar(); | |
| 600 | |
| 601 // Our Find bar should be the new target. | |
| 602 views::AcceleratorTarget* new_target = | |
| 603 focus_manager->GetCurrentTargetForAccelerator(escape); | |
| 604 | |
| 605 EXPECT_TRUE(new_target != NULL); | |
| 606 EXPECT_NE(new_target, old_target); | |
| 607 | |
| 608 // Close the Find box. | |
| 609 browser()->find_bar()->EndFindSession(); | |
| 610 | |
| 611 // The accelerator for Escape should be back to what it was before. | |
| 612 EXPECT_EQ(old_target, focus_manager->GetCurrentTargetForAccelerator(escape)); | |
| 613 } | |
| 614 | |
| 615 // Make sure Find box does not become UI-inactive when no text is in the box as | |
| 616 // we switch to a tab contents with an empty find string. See issue 13570. | |
| 617 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, StayActive) { | |
| 618 HTTPTestServer* server = StartHTTPServer(); | |
| 619 | |
| 620 // First we navigate to any page. | |
| 621 GURL url = server->TestServerPageW(kSimplePage); | |
| 622 ui_test_utils::NavigateToURL(browser(), url); | |
| 623 | |
| 624 // Open the Find window with animations disabled. | |
| 625 FindBarWin::disable_animations_during_testing_ = true; | |
| 626 browser()->ShowFindBar(); | |
| 627 | |
| 628 // Simulate a user clearing the search string. Ideally, we should be | |
| 629 // simulating keypresses here for searching for something and pressing | |
| 630 // backspace, but that's been proven flaky in the past, so we go straight to | |
| 631 // tab_contents. | |
| 632 TabContents* tab_contents = browser()->GetSelectedTabContents(); | |
| 633 // Stop the (non-existing) find operation, and clear the selection (which | |
| 634 // signals the UI is still active). | |
| 635 tab_contents->StopFinding(true); | |
| 636 // Make sure the Find UI flag hasn't been cleared, it must be so that the UI | |
| 637 // still responds to browser window resizing. | |
| 638 ASSERT_TRUE(tab_contents->find_ui_active()); | |
| 639 } | |
| OLD | NEW |