| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 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/keyboard_codes.h" | |
| 6 #include "base/message_loop.h" | |
| 7 #include "chrome/browser/browser.h" | |
| 8 #include "chrome/browser/browser_window.h" | |
| 9 #include "chrome/browser/find_bar_controller.h" | |
| 10 #include "chrome/browser/find_notification_details.h" | |
| 11 #include "chrome/browser/renderer_host/render_view_host.h" | |
| 12 #include "chrome/browser/tab_contents/tab_contents.h" | |
| 13 #include "chrome/browser/tab_contents/tab_contents_view.h" | |
| 14 #include "chrome/browser/views/find_bar_host.h" | |
| 15 #include "chrome/common/notification_service.h" | |
| 16 #include "chrome/test/in_process_browser_test.h" | |
| 17 #include "chrome/test/ui_test_utils.h" | |
| 18 #include "views/focus/focus_manager.h" | |
| 19 | |
| 20 const std::wstring kSimplePage = L"404_is_enough_for_us.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"; | |
| 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"; | |
| 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"; | |
| 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"; | |
| 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"; | |
| 32 const std::wstring kSimple = L"files/find_in_page/simple.html"; | |
| 33 | |
| 34 const bool kBack = false; | |
| 35 const bool kFwd = true; | |
| 36 | |
| 37 const bool kIgnoreCase = false; | |
| 38 const bool kCaseSensitive = true; | |
| 39 | |
| 40 const int kMoveIterations = 30; | |
| 41 | |
| 42 class FindInPageControllerTest : public InProcessBrowserTest { | |
| 43 public: | |
| 44 FindInPageControllerTest() { | |
| 45 EnableDOMAutomation(); | |
| 46 } | |
| 47 | |
| 48 protected: | |
| 49 bool GetFindBarWindowInfo(gfx::Point* position, bool* fully_visible) { | |
| 50 FindBarTesting* find_bar = | |
| 51 browser()->GetFindBarController()->find_bar()->GetFindBarTesting(); | |
| 52 return find_bar->GetFindBarWindowInfo(position, fully_visible); | |
| 53 } | |
| 54 }; | |
| 55 | |
| 56 // Platform independent FindInPage that takes |const wchat_t*| | |
| 57 // as an input. | |
| 58 int FindInPageWchar(TabContents* tab, | |
| 59 const wchar_t* search_str, | |
| 60 bool forward, | |
| 61 bool case_sensitive, | |
| 62 int* ordinal) { | |
| 63 return ui_test_utils::FindInPage( | |
| 64 tab, WideToUTF16(std::wstring(search_str)), | |
| 65 forward, case_sensitive, ordinal); | |
| 66 } | |
| 67 | |
| 68 // This test loads a page with frames and starts FindInPage requests. | |
| 69 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageFrames) { | |
| 70 HTTPTestServer* server = StartHTTPServer(); | |
| 71 | |
| 72 // First we navigate to our frames page. | |
| 73 GURL url = server->TestServerPageW(kFramePage); | |
| 74 ui_test_utils::NavigateToURL(browser(), url); | |
| 75 | |
| 76 // Try incremental search (mimicking user typing in). | |
| 77 int ordinal = 0; | |
| 78 TabContents* tab = browser()->GetSelectedTabContents(); | |
| 79 EXPECT_EQ(18, FindInPageWchar(tab, L"g", | |
| 80 kFwd, kIgnoreCase, &ordinal)); | |
| 81 EXPECT_EQ(1, ordinal); | |
| 82 EXPECT_EQ(11, FindInPageWchar(tab, L"go", | |
| 83 kFwd, kIgnoreCase, &ordinal)); | |
| 84 EXPECT_EQ(1, ordinal); | |
| 85 EXPECT_EQ(04, FindInPageWchar(tab, L"goo", | |
| 86 kFwd, kIgnoreCase, &ordinal)); | |
| 87 EXPECT_EQ(1, ordinal); | |
| 88 EXPECT_EQ(03, FindInPageWchar(tab, L"goog", | |
| 89 kFwd, kIgnoreCase, &ordinal)); | |
| 90 EXPECT_EQ(1, ordinal); | |
| 91 EXPECT_EQ(02, FindInPageWchar(tab, L"googl", | |
| 92 kFwd, kIgnoreCase, &ordinal)); | |
| 93 EXPECT_EQ(1, ordinal); | |
| 94 EXPECT_EQ(01, FindInPageWchar(tab, L"google", | |
| 95 kFwd, kIgnoreCase, &ordinal)); | |
| 96 EXPECT_EQ(1, ordinal); | |
| 97 EXPECT_EQ(00, FindInPageWchar(tab, L"google!", | |
| 98 kFwd, kIgnoreCase, &ordinal)); | |
| 99 EXPECT_EQ(0, ordinal); | |
| 100 | |
| 101 // Negative test (no matches should be found). | |
| 102 EXPECT_EQ(0, FindInPageWchar(tab, L"Non-existing string", | |
| 103 kFwd, kIgnoreCase, &ordinal)); | |
| 104 EXPECT_EQ(0, ordinal); | |
| 105 | |
| 106 // 'horse' only exists in the three right frames. | |
| 107 EXPECT_EQ(3, FindInPageWchar(tab, L"horse", | |
| 108 kFwd, kIgnoreCase, &ordinal)); | |
| 109 EXPECT_EQ(1, ordinal); | |
| 110 | |
| 111 // 'cat' only exists in the first frame. | |
| 112 EXPECT_EQ(1, FindInPageWchar(tab, L"cat", | |
| 113 kFwd, kIgnoreCase, &ordinal)); | |
| 114 EXPECT_EQ(1, ordinal); | |
| 115 | |
| 116 // Try searching again, should still come up with 1 match. | |
| 117 EXPECT_EQ(1, FindInPageWchar(tab, L"cat", | |
| 118 kFwd, kIgnoreCase, &ordinal)); | |
| 119 EXPECT_EQ(1, ordinal); | |
| 120 | |
| 121 // Try searching backwards, ignoring case, should still come up with 1 match. | |
| 122 EXPECT_EQ(1, FindInPageWchar(tab, L"CAT", | |
| 123 kBack, kIgnoreCase, &ordinal)); | |
| 124 EXPECT_EQ(1, ordinal); | |
| 125 | |
| 126 // Try case sensitive, should NOT find it. | |
| 127 EXPECT_EQ(0, FindInPageWchar(tab, L"CAT", | |
| 128 kFwd, kCaseSensitive, &ordinal)); | |
| 129 EXPECT_EQ(0, ordinal); | |
| 130 | |
| 131 // Try again case sensitive, but this time with right case. | |
| 132 EXPECT_EQ(1, FindInPageWchar(tab, L"dog", | |
| 133 kFwd, kCaseSensitive, &ordinal)); | |
| 134 EXPECT_EQ(1, ordinal); | |
| 135 | |
| 136 // Try non-Latin characters ('Hreggvidur' with 'eth' for 'd' in left frame). | |
| 137 EXPECT_EQ(1, FindInPageWchar(tab, L"Hreggvi\u00F0ur", | |
| 138 kFwd, kIgnoreCase, &ordinal)); | |
| 139 EXPECT_EQ(1, ordinal); | |
| 140 EXPECT_EQ(1, FindInPageWchar(tab, L"Hreggvi\u00F0ur", | |
| 141 kFwd, kCaseSensitive, &ordinal)); | |
| 142 EXPECT_EQ(1, ordinal); | |
| 143 EXPECT_EQ(0, FindInPageWchar(tab, L"hreggvi\u00F0ur", | |
| 144 kFwd, kCaseSensitive, &ordinal)); | |
| 145 EXPECT_EQ(0, ordinal); | |
| 146 } | |
| 147 | |
| 148 std::string FocusedOnPage(TabContents* tab_contents) { | |
| 149 std::string result; | |
| 150 ui_test_utils::ExecuteJavaScriptAndExtractString( | |
| 151 tab_contents->render_view_host(), | |
| 152 L"", | |
| 153 L"window.domAutomationController.send(getFocusedElement());", | |
| 154 &result); | |
| 155 return result; | |
| 156 } | |
| 157 | |
| 158 // This tests the FindInPage end-state, in other words: what is focused when you | |
| 159 // close the Find box (ie. if you find within a link the link should be | |
| 160 // focused). | |
| 161 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageEndState) { | |
| 162 HTTPTestServer* server = StartHTTPServer(); | |
| 163 | |
| 164 // First we navigate to our special focus tracking page. | |
| 165 GURL url = server->TestServerPageW(kEndState); | |
| 166 ui_test_utils::NavigateToURL(browser(), url); | |
| 167 | |
| 168 TabContents* tab_contents = browser()->GetSelectedTabContents(); | |
| 169 ASSERT_TRUE(NULL != tab_contents); | |
| 170 | |
| 171 // Verify that nothing has focus. | |
| 172 ASSERT_STREQ("{nothing focused}", FocusedOnPage(tab_contents).c_str()); | |
| 173 | |
| 174 // Search for a text that exists within a link on the page. | |
| 175 int ordinal = 0; | |
| 176 EXPECT_EQ(1, FindInPageWchar(tab_contents, L"nk", | |
| 177 kFwd, kIgnoreCase, &ordinal)); | |
| 178 EXPECT_EQ(1, ordinal); | |
| 179 | |
| 180 // End the find session, which should set focus to the link. | |
| 181 tab_contents->StopFinding(false); | |
| 182 | |
| 183 // Verify that the link is focused. | |
| 184 EXPECT_STREQ("link1", FocusedOnPage(tab_contents).c_str()); | |
| 185 | |
| 186 // Search for a text that exists within a link on the page. | |
| 187 EXPECT_EQ(1, FindInPageWchar(tab_contents, L"Google", | |
| 188 kFwd, kIgnoreCase, &ordinal)); | |
| 189 EXPECT_EQ(1, ordinal); | |
| 190 | |
| 191 // Move the selection to link 1, after searching. | |
| 192 std::string result; | |
| 193 ui_test_utils::ExecuteJavaScriptAndExtractString( | |
| 194 tab_contents->render_view_host(), | |
| 195 L"", | |
| 196 L"window.domAutomationController.send(selectLink1());", | |
| 197 &result); | |
| 198 | |
| 199 // End the find session. | |
| 200 tab_contents->StopFinding(false); | |
| 201 | |
| 202 // Verify that link2 is not focused. | |
| 203 EXPECT_STREQ("", FocusedOnPage(tab_contents).c_str()); | |
| 204 } | |
| 205 | |
| 206 // This test loads a single-frame page and makes sure the ordinal returned makes | |
| 207 // sense as we FindNext over all the items. | |
| 208 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageOrdinal) { | |
| 209 HTTPTestServer* server = StartHTTPServer(); | |
| 210 | |
| 211 // First we navigate to our page. | |
| 212 GURL url = server->TestServerPageW(kFrameData); | |
| 213 ui_test_utils::NavigateToURL(browser(), url); | |
| 214 | |
| 215 // Search for 'o', which should make the first item active and return | |
| 216 // '1 in 3' (1st ordinal of a total of 3 matches). | |
| 217 TabContents* tab = browser()->GetSelectedTabContents(); | |
| 218 int ordinal = 0; | |
| 219 EXPECT_EQ(3, FindInPageWchar(tab, L"o", | |
| 220 kFwd, kIgnoreCase, &ordinal)); | |
| 221 EXPECT_EQ(1, ordinal); | |
| 222 EXPECT_EQ(3, FindInPageWchar(tab, L"o", | |
| 223 kFwd, kIgnoreCase, &ordinal)); | |
| 224 EXPECT_EQ(2, ordinal); | |
| 225 EXPECT_EQ(3, FindInPageWchar(tab, L"o", | |
| 226 kFwd, kIgnoreCase, &ordinal)); | |
| 227 EXPECT_EQ(3, ordinal); | |
| 228 // Go back one match. | |
| 229 EXPECT_EQ(3, FindInPageWchar(tab, L"o", | |
| 230 kBack, kIgnoreCase, &ordinal)); | |
| 231 EXPECT_EQ(2, ordinal); | |
| 232 EXPECT_EQ(3, FindInPageWchar(tab, L"o", | |
| 233 kFwd, kIgnoreCase, &ordinal)); | |
| 234 EXPECT_EQ(3, ordinal); | |
| 235 // This should wrap to the top. | |
| 236 EXPECT_EQ(3, FindInPageWchar(tab, L"o", | |
| 237 kFwd, kIgnoreCase, &ordinal)); | |
| 238 EXPECT_EQ(1, ordinal); | |
| 239 // This should go back to the end. | |
| 240 EXPECT_EQ(3, FindInPageWchar(tab, L"o", | |
| 241 kBack, kIgnoreCase, &ordinal)); | |
| 242 EXPECT_EQ(3, ordinal); | |
| 243 } | |
| 244 | |
| 245 // This tests that the ordinal is correctly adjusted after a selection | |
| 246 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, | |
| 247 SelectChangesOrdinal_Issue20883) { | |
| 248 HTTPTestServer* server = StartHTTPServer(); | |
| 249 | |
| 250 // First we navigate to our test content. | |
| 251 GURL url = server->TestServerPageW(kSelectChangesOrdinal); | |
| 252 ui_test_utils::NavigateToURL(browser(), url); | |
| 253 | |
| 254 TabContents* tab_contents = browser()->GetSelectedTabContents(); | |
| 255 ASSERT_TRUE(NULL != tab_contents); | |
| 256 | |
| 257 // Search for a text that exists within a link on the page. | |
| 258 TabContents* tab = browser()->GetSelectedTabContents(); | |
| 259 int ordinal = 0; | |
| 260 EXPECT_EQ(4, FindInPageWchar(tab_contents, | |
| 261 L"google", | |
| 262 kFwd, kIgnoreCase, &ordinal)); | |
| 263 EXPECT_EQ(1, ordinal); | |
| 264 | |
| 265 // Move the selection to link 1, after searching. | |
| 266 std::string result; | |
| 267 ui_test_utils::ExecuteJavaScriptAndExtractString( | |
| 268 tab_contents->render_view_host(), | |
| 269 L"", | |
| 270 L"window.domAutomationController.send(selectLink1());", | |
| 271 &result); | |
| 272 | |
| 273 // Do a find-next after the selection. This should move forward | |
| 274 // from there to the 3rd instance of 'google'. | |
| 275 EXPECT_EQ(4, FindInPageWchar(tab, | |
| 276 L"google", | |
| 277 kFwd, kIgnoreCase, &ordinal)); | |
| 278 EXPECT_EQ(3, ordinal); | |
| 279 | |
| 280 // End the find session. | |
| 281 tab_contents->StopFinding(false); | |
| 282 } | |
| 283 | |
| 284 // This test loads a page with frames and makes sure the ordinal returned makes | |
| 285 // sense. | |
| 286 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageMultiFramesOrdinal) { | |
| 287 HTTPTestServer* server = StartHTTPServer(); | |
| 288 | |
| 289 // First we navigate to our page. | |
| 290 GURL url = server->TestServerPageW(kFramePage); | |
| 291 ui_test_utils::NavigateToURL(browser(), url); | |
| 292 | |
| 293 // Search for 'a', which should make the first item active and return | |
| 294 // '1 in 7' (1st ordinal of a total of 7 matches). | |
| 295 TabContents* tab = browser()->GetSelectedTabContents(); | |
| 296 int ordinal = 0; | |
| 297 EXPECT_EQ(7, | |
| 298 FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal)); | |
| 299 EXPECT_EQ(1, ordinal); | |
| 300 EXPECT_EQ(7, | |
| 301 FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal)); | |
| 302 EXPECT_EQ(2, ordinal); | |
| 303 EXPECT_EQ(7, | |
| 304 FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal)); | |
| 305 EXPECT_EQ(3, ordinal); | |
| 306 EXPECT_EQ(7, | |
| 307 FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal)); | |
| 308 EXPECT_EQ(4, ordinal); | |
| 309 // Go back one, which should go back one frame. | |
| 310 EXPECT_EQ(7, | |
| 311 FindInPageWchar(tab, L"a", kBack, kIgnoreCase, &ordinal)); | |
| 312 EXPECT_EQ(3, ordinal); | |
| 313 EXPECT_EQ(7, | |
| 314 FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal)); | |
| 315 EXPECT_EQ(4, ordinal); | |
| 316 EXPECT_EQ(7, | |
| 317 FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal)); | |
| 318 EXPECT_EQ(5, ordinal); | |
| 319 EXPECT_EQ(7, | |
| 320 FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal)); | |
| 321 EXPECT_EQ(6, ordinal); | |
| 322 EXPECT_EQ(7, | |
| 323 FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal)); | |
| 324 EXPECT_EQ(7, ordinal); | |
| 325 // Now we should wrap back to frame 1. | |
| 326 EXPECT_EQ(7, | |
| 327 FindInPageWchar(tab, L"a", kFwd, kIgnoreCase, &ordinal)); | |
| 328 EXPECT_EQ(1, ordinal); | |
| 329 // Now we should wrap back to frame last frame. | |
| 330 EXPECT_EQ(7, | |
| 331 FindInPageWchar(tab, L"a", kBack, kIgnoreCase, &ordinal)); | |
| 332 EXPECT_EQ(7, ordinal); | |
| 333 } | |
| 334 | |
| 335 // We could get ordinals out of whack when restarting search in subframes. | |
| 336 // See http://crbug.com/5132. | |
| 337 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPage_Issue5132) { | |
| 338 HTTPTestServer* server = StartHTTPServer(); | |
| 339 | |
| 340 // First we navigate to our page. | |
| 341 GURL url = server->TestServerPageW(kFramePage); | |
| 342 ui_test_utils::NavigateToURL(browser(), url); | |
| 343 | |
| 344 // Search for 'goa' three times (6 matches on page). | |
| 345 int ordinal = 0; | |
| 346 TabContents* tab = browser()->GetSelectedTabContents(); | |
| 347 EXPECT_EQ(6, FindInPageWchar(tab, L"goa", | |
| 348 kFwd, kIgnoreCase, &ordinal)); | |
| 349 EXPECT_EQ(1, ordinal); | |
| 350 EXPECT_EQ(6, FindInPageWchar(tab, L"goa", | |
| 351 kFwd, kIgnoreCase, &ordinal)); | |
| 352 EXPECT_EQ(2, ordinal); | |
| 353 EXPECT_EQ(6, FindInPageWchar(tab, L"goa", | |
| 354 kFwd, kIgnoreCase, &ordinal)); | |
| 355 EXPECT_EQ(3, ordinal); | |
| 356 // Add space to search (should result in no matches). | |
| 357 EXPECT_EQ(0, FindInPageWchar(tab, L"goa ", | |
| 358 kFwd, kIgnoreCase, &ordinal)); | |
| 359 EXPECT_EQ(0, ordinal); | |
| 360 // Remove the space, should be back to '3 out of 6') | |
| 361 EXPECT_EQ(6, FindInPageWchar(tab, L"goa", | |
| 362 kFwd, kIgnoreCase, &ordinal)); | |
| 363 EXPECT_EQ(3, ordinal); | |
| 364 } | |
| 365 | |
| 366 // Load a page with no selectable text and make sure we don't crash. | |
| 367 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindUnSelectableText) { | |
| 368 HTTPTestServer* server = StartHTTPServer(); | |
| 369 | |
| 370 // First we navigate to our page. | |
| 371 GURL url = server->TestServerPageW(kUserSelectPage); | |
| 372 ui_test_utils::NavigateToURL(browser(), url); | |
| 373 | |
| 374 int ordinal = 0; | |
| 375 TabContents* tab = browser()->GetSelectedTabContents(); | |
| 376 EXPECT_EQ(0, FindInPageWchar(tab, L"text", | |
| 377 kFwd, kIgnoreCase, &ordinal)); | |
| 378 EXPECT_EQ(-1, ordinal); // Nothing is selected. | |
| 379 EXPECT_EQ(0, FindInPageWchar(tab, L"Non-existing string", | |
| 380 kFwd, kIgnoreCase, &ordinal)); | |
| 381 EXPECT_EQ(0, ordinal); | |
| 382 } | |
| 383 | |
| 384 // Try to reproduce the crash seen in issue 1341577. | |
| 385 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindCrash_Issue1341577) { | |
| 386 HTTPTestServer* server = StartHTTPServer(); | |
| 387 | |
| 388 // First we navigate to our page. | |
| 389 GURL url = server->TestServerPageW(kCrashPage); | |
| 390 ui_test_utils::NavigateToURL(browser(), url); | |
| 391 | |
| 392 // This would crash the tab. These must be the first two find requests issued | |
| 393 // against the frame, otherwise an active frame pointer is set and it wont | |
| 394 // produce the crash. | |
| 395 // We used to check the return value and |ordinal|. With ICU 4.2, FiP does | |
| 396 // not find a stand-alone dependent vowel sign of Indic scripts. So, the | |
| 397 // exptected values are all 0. To make this test pass regardless of | |
| 398 // ICU version, we just call FiP and see if there's any crash. | |
| 399 // TODO(jungshik): According to a native Malayalam speaker, it's ok not | |
| 400 // to find U+0D4C. Still need to investigate further this issue. | |
| 401 int ordinal = 0; | |
| 402 TabContents* tab = browser()->GetSelectedTabContents(); | |
| 403 FindInPageWchar(tab, L"\u0D4C", kFwd, kIgnoreCase, &ordinal); | |
| 404 FindInPageWchar(tab, L"\u0D4C", kFwd, kIgnoreCase, &ordinal); | |
| 405 | |
| 406 // This should work fine. | |
| 407 EXPECT_EQ(1, FindInPageWchar(tab, L"\u0D24\u0D46", | |
| 408 kFwd, kIgnoreCase, &ordinal)); | |
| 409 EXPECT_EQ(1, ordinal); | |
| 410 EXPECT_EQ(0, FindInPageWchar(tab, L"nostring", | |
| 411 kFwd, kIgnoreCase, &ordinal)); | |
| 412 EXPECT_EQ(0, ordinal); | |
| 413 } | |
| 414 | |
| 415 // Try to reproduce the crash seen in http://crbug.com/14491, where an assert | |
| 416 // hits in the BitStack size comparison in WebKit. | |
| 417 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindCrash_Issue14491) { | |
| 418 HTTPTestServer* server = StartHTTPServer(); | |
| 419 | |
| 420 // First we navigate to our page. | |
| 421 GURL url = server->TestServerPageW(kBitstackCrash); | |
| 422 ui_test_utils::NavigateToURL(browser(), url); | |
| 423 | |
| 424 // This used to crash the tab. | |
| 425 int ordinal = 0; | |
| 426 EXPECT_EQ(0, FindInPageWchar(browser()->GetSelectedTabContents(), | |
| 427 L"s", kFwd, kIgnoreCase, &ordinal)); | |
| 428 EXPECT_EQ(0, ordinal); | |
| 429 } | |
| 430 | |
| 431 // Test to make sure Find does the right thing when restarting from a timeout. | |
| 432 // We used to have a problem where we'd stop finding matches when all of the | |
| 433 // following conditions were true: | |
| 434 // 1) The page has a lot of text to search. | |
| 435 // 2) The page contains more than one match. | |
| 436 // 3) It takes longer than the time-slice given to each Find operation (100 | |
| 437 // ms) to find one or more of those matches (so Find times out and has to try | |
| 438 // again from where it left off). | |
| 439 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindRestarts_Issue1155639) { | |
| 440 HTTPTestServer* server = StartHTTPServer(); | |
| 441 | |
| 442 // First we navigate to our page. | |
| 443 GURL url = server->TestServerPageW(kTooFewMatchesPage); | |
| 444 ui_test_utils::NavigateToURL(browser(), url); | |
| 445 | |
| 446 // This string appears 5 times at the bottom of a long page. If Find restarts | |
| 447 // properly after a timeout, it will find 5 matches, not just 1. | |
| 448 int ordinal = 0; | |
| 449 EXPECT_EQ(5, FindInPageWchar(browser()->GetSelectedTabContents(), | |
| 450 L"008.xml", | |
| 451 kFwd, kIgnoreCase, &ordinal)); | |
| 452 EXPECT_EQ(1, ordinal); | |
| 453 } | |
| 454 | |
| 455 // This tests bug 11761: FindInPage terminates search prematurely. | |
| 456 // This test will be enabled once the bug is fixed. | |
| 457 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, | |
| 458 DISABLED_FindInPagePrematureEnd) { | |
| 459 HTTPTestServer* server = StartHTTPServer(); | |
| 460 | |
| 461 // First we navigate to our special focus tracking page. | |
| 462 GURL url = server->TestServerPageW(kPrematureEnd); | |
| 463 ui_test_utils::NavigateToURL(browser(), url); | |
| 464 | |
| 465 TabContents* tab_contents = browser()->GetSelectedTabContents(); | |
| 466 ASSERT_TRUE(NULL != tab_contents); | |
| 467 | |
| 468 // Search for a text that exists within a link on the page. | |
| 469 int ordinal = 0; | |
| 470 EXPECT_EQ(2, FindInPageWchar(tab_contents, L"html ", | |
| 471 kFwd, kIgnoreCase, &ordinal)); | |
| 472 EXPECT_EQ(1, ordinal); | |
| 473 } | |
| 474 | |
| 475 // Make sure Find box disappears on Navigate but not on Refresh. | |
| 476 #if defined(OS_LINUX) && defined(TOOLKIT_VIEWS) | |
| 477 // The last EXPECT_FALSE(fully_visible) is failing all the time on | |
| 478 // the linux_views bot. See bug: http://crbug.com/28629. | |
| 479 #define FindDisappearOnNavigate DISABLED_FindDisappearOnNavigate | |
| 480 #endif | |
| 481 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindDisappearOnNavigate) { | |
| 482 HTTPTestServer* server = StartHTTPServer(); | |
| 483 | |
| 484 // First we navigate to our special focus tracking page. | |
| 485 GURL url = server->TestServerPageW(kSimplePage); | |
| 486 GURL url2 = server->TestServerPageW(kFramePage); | |
| 487 ui_test_utils::NavigateToURL(browser(), url); | |
| 488 | |
| 489 // Open the Find window with animations disabled. | |
| 490 DropdownBarHost::disable_animations_during_testing_ = true; | |
| 491 browser()->ShowFindBar(); | |
| 492 | |
| 493 gfx::Point position; | |
| 494 bool fully_visible = false; | |
| 495 | |
| 496 // Make sure it is open. | |
| 497 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); | |
| 498 EXPECT_TRUE(fully_visible); | |
| 499 | |
| 500 // Reload the tab and make sure Find window doesn't go away. | |
| 501 browser()->Reload(); | |
| 502 | |
| 503 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); | |
| 504 EXPECT_TRUE(fully_visible); | |
| 505 | |
| 506 // Navigate and make sure the Find window goes away. | |
| 507 ui_test_utils::NavigateToURL(browser(), url2); | |
| 508 | |
| 509 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); | |
| 510 EXPECT_FALSE(fully_visible); | |
| 511 } | |
| 512 | |
| 513 // Make sure Find box disappears when History/Downloads page is opened, and | |
| 514 // when a New Tab is opened. | |
| 515 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, | |
| 516 FindDisappearOnNewTabAndHistory) { | |
| 517 HTTPTestServer* server = StartHTTPServer(); | |
| 518 | |
| 519 // First we navigate to our special focus tracking page. | |
| 520 GURL url = server->TestServerPageW(kSimplePage); | |
| 521 ui_test_utils::NavigateToURL(browser(), url); | |
| 522 | |
| 523 // Open the Find window with animations disabled. | |
| 524 DropdownBarHost::disable_animations_during_testing_ = true; | |
| 525 browser()->ShowFindBar(); | |
| 526 | |
| 527 gfx::Point position; | |
| 528 bool fully_visible = false; | |
| 529 | |
| 530 // Make sure it is open. | |
| 531 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); | |
| 532 EXPECT_TRUE(fully_visible); | |
| 533 | |
| 534 // Open another tab (tab B). | |
| 535 browser()->NewTab(); | |
| 536 ui_test_utils::NavigateToURL(browser(), url); | |
| 537 | |
| 538 // Make sure Find box is closed. | |
| 539 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); | |
| 540 EXPECT_FALSE(fully_visible); | |
| 541 | |
| 542 // Close tab B. | |
| 543 browser()->CloseTab(); | |
| 544 | |
| 545 // Make sure Find window appears again. | |
| 546 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); | |
| 547 EXPECT_TRUE(fully_visible); | |
| 548 | |
| 549 browser()->ShowHistoryTab(); | |
| 550 | |
| 551 // Make sure Find box is closed. | |
| 552 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); | |
| 553 EXPECT_FALSE(fully_visible); | |
| 554 } | |
| 555 | |
| 556 // Make sure Find box moves out of the way if it is obscuring the active match. | |
| 557 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindMovesWhenObscuring) { | |
| 558 HTTPTestServer* server = StartHTTPServer(); | |
| 559 | |
| 560 GURL url = server->TestServerPageW(kMoveIfOver); | |
| 561 ui_test_utils::NavigateToURL(browser(), url); | |
| 562 | |
| 563 // Open the Find window with animations disabled. | |
| 564 DropdownBarHost::disable_animations_during_testing_ = true; | |
| 565 browser()->ShowFindBar(); | |
| 566 | |
| 567 gfx::Point start_position; | |
| 568 gfx::Point position; | |
| 569 bool fully_visible = false; | |
| 570 | |
| 571 // Make sure it is open. | |
| 572 EXPECT_TRUE(GetFindBarWindowInfo(&start_position, &fully_visible)); | |
| 573 EXPECT_TRUE(fully_visible); | |
| 574 | |
| 575 // Search for 'Chromium' which the Find box is obscuring. | |
| 576 int ordinal = 0; | |
| 577 TabContents* tab = browser()->GetSelectedTabContents(); | |
| 578 int index = 0; | |
| 579 for (; index < kMoveIterations; ++index) { | |
| 580 EXPECT_EQ(kMoveIterations, FindInPageWchar(tab, L"Chromium", | |
| 581 kFwd, kIgnoreCase, &ordinal)); | |
| 582 | |
| 583 // Check the position. | |
| 584 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); | |
| 585 EXPECT_TRUE(fully_visible); | |
| 586 | |
| 587 // If the Find box has moved then we are done. | |
| 588 if (position.x() != start_position.x()) | |
| 589 break; | |
| 590 } | |
| 591 | |
| 592 // We should not have reached the end. | |
| 593 ASSERT_GT(kMoveIterations, index); | |
| 594 | |
| 595 // Search for something guaranteed not to be obscured by the Find box. | |
| 596 EXPECT_EQ(1, FindInPageWchar(tab, L"Done", | |
| 597 kFwd, kIgnoreCase, &ordinal)); | |
| 598 // Check the position. | |
| 599 EXPECT_TRUE(GetFindBarWindowInfo(&position, &fully_visible)); | |
| 600 EXPECT_TRUE(fully_visible); | |
| 601 | |
| 602 // Make sure Find box has moved back to its original location. | |
| 603 EXPECT_EQ(position.x(), start_position.x()); | |
| 604 } | |
| 605 | |
| 606 // Make sure F3 in a new tab works if Find has previous string to search for. | |
| 607 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, | |
| 608 FindNextInNewTabUsesPrepopulate) { | |
| 609 HTTPTestServer* server = StartHTTPServer(); | |
| 610 | |
| 611 // First we navigate to any page. | |
| 612 GURL url = server->TestServerPageW(kSimplePage); | |
| 613 ui_test_utils::NavigateToURL(browser(), url); | |
| 614 | |
| 615 // Search for 'no_match'. No matches should be found. | |
| 616 int ordinal = 0; | |
| 617 TabContents* tab = browser()->GetSelectedTabContents(); | |
| 618 EXPECT_EQ(0, FindInPageWchar(tab, L"no_match", | |
| 619 kFwd, kIgnoreCase, &ordinal)); | |
| 620 EXPECT_EQ(0, ordinal); | |
| 621 | |
| 622 // Open another tab (tab B). | |
| 623 browser()->NewTab(); | |
| 624 ui_test_utils::NavigateToURL(browser(), url); | |
| 625 | |
| 626 // Simulate what happens when you press F3 for FindNext. We should get a | |
| 627 // response here (a hang means search was aborted). | |
| 628 EXPECT_EQ(0, ui_test_utils::FindInPage(tab, string16(), | |
| 629 kFwd, kIgnoreCase, &ordinal)); | |
| 630 EXPECT_EQ(0, ordinal); | |
| 631 | |
| 632 // Open another tab (tab C). | |
| 633 browser()->NewTab(); | |
| 634 ui_test_utils::NavigateToURL(browser(), url); | |
| 635 | |
| 636 // Simulate what happens when you press F3 for FindNext. We should get a | |
| 637 // response here (a hang means search was aborted). | |
| 638 EXPECT_EQ(0, ui_test_utils::FindInPage(tab, string16(), | |
| 639 kFwd, kIgnoreCase, &ordinal)); | |
| 640 EXPECT_EQ(0, ordinal); | |
| 641 } | |
| 642 | |
| 643 // Make sure Find box grabs the Esc accelerator and restores it again. | |
| 644 #if defined(OS_LINUX) | |
| 645 // TODO(oshima): On Gtk/Linux, a focus out event is asynchronous and | |
| 646 // hiding a find bar does not immediately update the target | |
| 647 // accelerator. The last condition fails in most cases due to this | |
| 648 // behavior. See http://crbug.com/26870. | |
| 649 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, | |
| 650 DISABLED_AcceleratorRestoring) { | |
| 651 #else | |
| 652 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, AcceleratorRestoring) { | |
| 653 #endif | |
| 654 HTTPTestServer* server = StartHTTPServer(); | |
| 655 | |
| 656 // First we navigate to any page. | |
| 657 GURL url = server->TestServerPageW(kSimplePage); | |
| 658 ui_test_utils::NavigateToURL(browser(), url); | |
| 659 | |
| 660 #if defined(OS_WIN) | |
| 661 // TODO(oshima): Windows code assumes that NativeView is | |
| 662 // assignable from NativeWindow, which is not true on other platforms. | |
| 663 // This has to be fixed, probably by having explicit | |
| 664 // GetNativeView / GetNativewWindow methods on BrowserWindow. | |
| 665 // See http://crbug.com/26873. | |
| 666 gfx::NativeView browser_view = browser()->window()->GetNativeHandle(); | |
| 667 #elif defined(OS_LINUX) | |
| 668 gfx::NativeView browser_view = | |
| 669 GTK_WIDGET(browser()->window()->GetNativeHandle()); | |
| 670 #else | |
| 671 // Mac does not use views. | |
| 672 NOTREACHED(); | |
| 673 #endif | |
| 674 | |
| 675 views::FocusManager* focus_manager = | |
| 676 views::FocusManager::GetFocusManagerForNativeView(browser_view); | |
| 677 | |
| 678 // See where Escape is registered. | |
| 679 views::Accelerator escape(base::VKEY_ESCAPE, false, false, false); | |
| 680 views::AcceleratorTarget* old_target = | |
| 681 focus_manager->GetCurrentTargetForAccelerator(escape); | |
| 682 EXPECT_TRUE(old_target != NULL); | |
| 683 | |
| 684 // Open the Find window with animations disabled. | |
| 685 DropdownBarHost::disable_animations_during_testing_ = true; | |
| 686 browser()->ShowFindBar(); | |
| 687 | |
| 688 // Our Find bar should be the new target. | |
| 689 views::AcceleratorTarget* new_target = | |
| 690 focus_manager->GetCurrentTargetForAccelerator(escape); | |
| 691 | |
| 692 EXPECT_TRUE(new_target != NULL); | |
| 693 EXPECT_NE(new_target, old_target); | |
| 694 | |
| 695 // Close the Find box. | |
| 696 browser()->GetFindBarController()->EndFindSession(); | |
| 697 | |
| 698 // The accelerator for Escape should be back to what it was before. | |
| 699 EXPECT_EQ(old_target, | |
| 700 focus_manager->GetCurrentTargetForAccelerator(escape)); | |
| 701 } | |
| 702 | |
| 703 // Make sure Find box does not become UI-inactive when no text is in the box as | |
| 704 // we switch to a tab contents with an empty find string. See issue 13570. | |
| 705 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, StayActive) { | |
| 706 HTTPTestServer* server = StartHTTPServer(); | |
| 707 | |
| 708 // First we navigate to any page. | |
| 709 GURL url = server->TestServerPageW(kSimplePage); | |
| 710 ui_test_utils::NavigateToURL(browser(), url); | |
| 711 | |
| 712 // Open the Find window with animations disabled. | |
| 713 DropdownBarHost::disable_animations_during_testing_ = true; | |
| 714 browser()->ShowFindBar(); | |
| 715 | |
| 716 // Simulate a user clearing the search string. Ideally, we should be | |
| 717 // simulating keypresses here for searching for something and pressing | |
| 718 // backspace, but that's been proven flaky in the past, so we go straight to | |
| 719 // tab_contents. | |
| 720 TabContents* tab_contents = browser()->GetSelectedTabContents(); | |
| 721 // Stop the (non-existing) find operation, and clear the selection (which | |
| 722 // signals the UI is still active). | |
| 723 tab_contents->StopFinding(true); | |
| 724 // Make sure the Find UI flag hasn't been cleared, it must be so that the UI | |
| 725 // still responds to browser window resizing. | |
| 726 ASSERT_TRUE(tab_contents->find_ui_active()); | |
| 727 } | |
| 728 | |
| 729 // Make sure F3 works after you FindNext a couple of times and end the Find | |
| 730 // session. See issue http://crbug.com/28306. | |
| 731 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, RestartSearchFromF3) { | |
| 732 HTTPTestServer* server = StartHTTPServer(); | |
| 733 | |
| 734 // First we navigate to a simple page. | |
| 735 GURL url = server->TestServerPageW(kSimple); | |
| 736 ui_test_utils::NavigateToURL(browser(), url); | |
| 737 | |
| 738 // Search for 'page'. Should have 1 match. | |
| 739 int ordinal = 0; | |
| 740 TabContents* tab = browser()->GetSelectedTabContents(); | |
| 741 EXPECT_EQ(1, FindInPageWchar(tab, L"page", kFwd, kIgnoreCase, &ordinal)); | |
| 742 EXPECT_EQ(1, ordinal); | |
| 743 | |
| 744 // Simulate what happens when you press F3 for FindNext. Still should show | |
| 745 // one match. This cleared the pre-populate string at one point (see bug). | |
| 746 EXPECT_EQ(1, ui_test_utils::FindInPage(tab, string16(), | |
| 747 kFwd, kIgnoreCase, &ordinal)); | |
| 748 EXPECT_EQ(1, ordinal); | |
| 749 | |
| 750 // End the Find session, thereby making the next F3 start afresh. | |
| 751 browser()->GetFindBarController()->EndFindSession(); | |
| 752 | |
| 753 // Simulate F3 while Find box is closed. Should have 1 match. | |
| 754 EXPECT_EQ(1, FindInPageWchar(tab, L"", kFwd, kIgnoreCase, &ordinal)); | |
| 755 EXPECT_EQ(1, ordinal); | |
| 756 } | |
| 757 | |
| 758 // When re-opening the find bar with F3, the find bar should be re-populated | |
| 759 // with the last search from the same tab rather than the last overall search. | |
| 760 // http://crbug.com/30006 | |
| 761 #if defined(OS_CHROMEOS) | |
| 762 #define PreferPreviousSearch FLAKY_PreferPreviousSearch | |
| 763 #endif | |
| 764 IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, PreferPreviousSearch) { | |
| 765 HTTPTestServer* server = StartHTTPServer(); | |
| 766 | |
| 767 DropdownBarHost::disable_animations_during_testing_ = true; | |
| 768 | |
| 769 // First we navigate to any page. | |
| 770 GURL url = server->TestServerPageW(kSimplePage); | |
| 771 ui_test_utils::NavigateToURL(browser(), url); | |
| 772 | |
| 773 // Find "Default". | |
| 774 int ordinal = 0; | |
| 775 TabContents* tab1 = browser()->GetSelectedTabContents(); | |
| 776 EXPECT_EQ(1, FindInPageWchar(tab1, L"Default", kFwd, kIgnoreCase, &ordinal)); | |
| 777 | |
| 778 // Create a second tab. | |
| 779 browser()->AddTabWithURL(url, GURL(), PageTransition::TYPED, true, -1, | |
| 780 false, NULL); | |
| 781 browser()->SelectTabContentsAt(1, false); | |
| 782 TabContents* tab2 = browser()->GetSelectedTabContents(); | |
| 783 EXPECT_NE(tab1, tab2); | |
| 784 | |
| 785 // Find "given". | |
| 786 FindInPageWchar(tab2, L"given", kFwd, kIgnoreCase, &ordinal); | |
| 787 | |
| 788 // Switch back to first tab. | |
| 789 browser()->SelectTabContentsAt(0, false); | |
| 790 browser()->GetFindBarController()->EndFindSession(); | |
| 791 // Simulate F3. | |
| 792 ui_test_utils::FindInPage(tab1, string16(), kFwd, kIgnoreCase, &ordinal); | |
| 793 EXPECT_EQ(tab1->find_text(), WideToUTF16(L"Default")); | |
| 794 } | |
| OLD | NEW |