| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "content/browser/web_contents/web_contents_impl.h" | 7 #include "content/browser/web_contents/web_contents_impl.h" |
| 8 #include "content/public/browser/notification_types.h" | 8 #include "content/public/browser/notification_types.h" |
| 9 #include "content/public/common/content_switches.h" | 9 #include "content/public/common/content_switches.h" |
| 10 #include "content/public/test/content_browser_test.h" | 10 #include "content/public/test/content_browser_test.h" |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 INSTANTIATE_TEST_CASE_P( | 270 INSTANTIATE_TEST_CASE_P( |
| 271 FindRequestManagerTests, FindRequestManagerTest, testing::Values(false)); | 271 FindRequestManagerTests, FindRequestManagerTest, testing::Values(false)); |
| 272 #else | 272 #else |
| 273 INSTANTIATE_TEST_CASE_P( | 273 INSTANTIATE_TEST_CASE_P( |
| 274 FindRequestManagerTests, FindRequestManagerTest, testing::Bool()); | 274 FindRequestManagerTests, FindRequestManagerTest, testing::Bool()); |
| 275 #endif | 275 #endif |
| 276 | 276 |
| 277 // TODO(crbug.com/615291): These tests sometimes fail on the | 277 // TODO(crbug.com/615291): These tests sometimes fail on the |
| 278 // linux_android_rel_ng trybot. | 278 // linux_android_rel_ng trybot. |
| 279 #if defined(OS_ANDROID) && defined(NDEBUG) | 279 #if defined(OS_ANDROID) && defined(NDEBUG) |
| 280 #define MAYBE_Basic DISABLED_Basic | 280 #define MAYBE(x) DISABLED_##x |
| 281 #define MAYBE_CharacterByCharacter DISABLED_CharacterByCharacter | |
| 282 #define MAYBE_RapidFire DISABLED_RapidFire | |
| 283 #define MAYBE_RemoveFrame DISABLED_RemoveFrame | |
| 284 #define MAYBE_HiddenFrame DISABLED_HiddenFrame | |
| 285 #define MAYBE_FindMatchRects DISABLED_FindMatchRects | |
| 286 #define MAYBE_ActivateNearestFindMatch DISABLED_ActivateNearestFindMatch | |
| 287 #else | 281 #else |
| 288 #define MAYBE_Basic Basic | 282 #define MAYBE(x) x |
| 289 #define MAYBE_CharacterByCharacter CharacterByCharacter | |
| 290 #define MAYBE_RapidFire RapidFire | |
| 291 #define MAYBE_RemoveFrame RemoveFrame | |
| 292 #define MAYBE_HiddenFrame HiddenFrame | |
| 293 #define MAYBE_FindMatchRects FindMatchRects | |
| 294 #define MAYBE_ActivateNearestFindMatch ActivateNearestFindMatch | |
| 295 #endif | 283 #endif |
| 296 | 284 |
| 297 | 285 |
| 298 // Tests basic find-in-page functionality (such as searching forward and | 286 // Tests basic find-in-page functionality (such as searching forward and |
| 299 // backward) and check for correct results at each step. | 287 // backward) and check for correct results at each step. |
| 300 IN_PROC_BROWSER_TEST_P(FindRequestManagerTest, MAYBE_Basic) { | 288 IN_PROC_BROWSER_TEST_P(FindRequestManagerTest, MAYBE(Basic)) { |
| 301 LoadAndWait("/find_in_page.html"); | 289 LoadAndWait("/find_in_page.html"); |
| 302 if (GetParam()) | 290 if (GetParam()) |
| 303 MakeChildFrameCrossProcess(); | 291 MakeChildFrameCrossProcess(); |
| 304 | 292 |
| 305 blink::WebFindOptions options; | 293 blink::WebFindOptions options; |
| 306 Find("result", options); | 294 Find("result", options); |
| 307 WaitForFinalReply(); | 295 WaitForFinalReply(); |
| 308 | 296 |
| 309 FindResults results = delegate()->GetFindResults(); | 297 FindResults results = delegate()->GetFindResults(); |
| 310 EXPECT_EQ(last_request_id(), results.request_id); | 298 EXPECT_EQ(last_request_id(), results.request_id); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 329 | 317 |
| 330 results = delegate()->GetFindResults(); | 318 results = delegate()->GetFindResults(); |
| 331 EXPECT_EQ(last_request_id(), results.request_id); | 319 EXPECT_EQ(last_request_id(), results.request_id); |
| 332 EXPECT_EQ(19, results.number_of_matches); | 320 EXPECT_EQ(19, results.number_of_matches); |
| 333 EXPECT_EQ(i, results.active_match_ordinal); | 321 EXPECT_EQ(i, results.active_match_ordinal); |
| 334 } | 322 } |
| 335 } | 323 } |
| 336 | 324 |
| 337 // Tests searching for a word character-by-character, as would typically be done | 325 // Tests searching for a word character-by-character, as would typically be done |
| 338 // by a user typing into the find bar. | 326 // by a user typing into the find bar. |
| 339 IN_PROC_BROWSER_TEST_P(FindRequestManagerTest, MAYBE_CharacterByCharacter) { | 327 IN_PROC_BROWSER_TEST_P(FindRequestManagerTest, MAYBE(CharacterByCharacter)) { |
| 340 LoadAndWait("/find_in_page.html"); | 328 LoadAndWait("/find_in_page.html"); |
| 341 if (GetParam()) | 329 if (GetParam()) |
| 342 MakeChildFrameCrossProcess(); | 330 MakeChildFrameCrossProcess(); |
| 343 | 331 |
| 344 blink::WebFindOptions default_options; | 332 blink::WebFindOptions default_options; |
| 345 Find("r", default_options); | 333 Find("r", default_options); |
| 346 Find("re", default_options); | 334 Find("re", default_options); |
| 347 Find("res", default_options); | 335 Find("res", default_options); |
| 348 Find("resu", default_options); | 336 Find("resu", default_options); |
| 349 Find("resul", default_options); | 337 Find("resul", default_options); |
| 350 Find("result", default_options); | 338 Find("result", default_options); |
| 351 WaitForFinalReply(); | 339 WaitForFinalReply(); |
| 352 | 340 |
| 353 FindResults results = delegate()->GetFindResults(); | 341 FindResults results = delegate()->GetFindResults(); |
| 354 EXPECT_EQ(last_request_id(), results.request_id); | 342 EXPECT_EQ(last_request_id(), results.request_id); |
| 355 EXPECT_EQ(19, results.number_of_matches); | 343 EXPECT_EQ(19, results.number_of_matches); |
| 356 EXPECT_EQ(1, results.active_match_ordinal); | 344 EXPECT_EQ(1, results.active_match_ordinal); |
| 357 } | 345 } |
| 358 | 346 |
| 359 // Tests sending a large number of find requests subsequently. | 347 // Tests sending a large number of find requests subsequently. |
| 360 IN_PROC_BROWSER_TEST_P(FindRequestManagerTest, MAYBE_RapidFire) { | 348 IN_PROC_BROWSER_TEST_P(FindRequestManagerTest, MAYBE(RapidFire)) { |
| 361 LoadAndWait("/find_in_page.html"); | 349 LoadAndWait("/find_in_page.html"); |
| 362 if (GetParam()) | 350 if (GetParam()) |
| 363 MakeChildFrameCrossProcess(); | 351 MakeChildFrameCrossProcess(); |
| 364 | 352 |
| 365 blink::WebFindOptions options; | 353 blink::WebFindOptions options; |
| 366 Find("result", options); | 354 Find("result", options); |
| 367 | 355 |
| 368 options.findNext = true; | 356 options.findNext = true; |
| 369 for (int i = 2; i <= 1000; ++i) | 357 for (int i = 2; i <= 1000; ++i) |
| 370 Find("result", options); | 358 Find("result", options); |
| 371 WaitForFinalReply(); | 359 WaitForFinalReply(); |
| 372 | 360 |
| 373 FindResults results = delegate()->GetFindResults(); | 361 FindResults results = delegate()->GetFindResults(); |
| 374 EXPECT_EQ(last_request_id(), results.request_id); | 362 EXPECT_EQ(last_request_id(), results.request_id); |
| 375 EXPECT_EQ(19, results.number_of_matches); | 363 EXPECT_EQ(19, results.number_of_matches); |
| 376 EXPECT_EQ(last_request_id() % results.number_of_matches, | 364 EXPECT_EQ(last_request_id() % results.number_of_matches, |
| 377 results.active_match_ordinal); | 365 results.active_match_ordinal); |
| 378 } | 366 } |
| 379 | 367 |
| 380 // Tests removing a frame during a find session. | 368 // Tests removing a frame during a find session. |
| 381 IN_PROC_BROWSER_TEST_P(FindRequestManagerTest, MAYBE_RemoveFrame) { | 369 IN_PROC_BROWSER_TEST_P(FindRequestManagerTest, MAYBE(RemoveFrame)) { |
| 382 LoadMultiFramePage(2 /* height */, GetParam() /* cross_process */); | 370 LoadMultiFramePage(2 /* height */, GetParam() /* cross_process */); |
| 383 | 371 |
| 384 blink::WebFindOptions options; | 372 blink::WebFindOptions options; |
| 385 Find("result", options); | 373 Find("result", options); |
| 386 options.findNext = true; | 374 options.findNext = true; |
| 387 options.forward = false; | 375 options.forward = false; |
| 388 Find("result", options); | 376 Find("result", options); |
| 389 Find("result", options); | 377 Find("result", options); |
| 390 Find("result", options); | 378 Find("result", options); |
| 391 Find("result", options); | 379 Find("result", options); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 408 results = delegate()->GetFindResults(); | 396 results = delegate()->GetFindResults(); |
| 409 EXPECT_EQ(last_request_id(), results.request_id); | 397 EXPECT_EQ(last_request_id(), results.request_id); |
| 410 EXPECT_EQ(12, results.number_of_matches); | 398 EXPECT_EQ(12, results.number_of_matches); |
| 411 EXPECT_EQ(8, results.active_match_ordinal); | 399 EXPECT_EQ(8, results.active_match_ordinal); |
| 412 | 400 |
| 413 // TODO(paulemeyer): Once adding frames mid-session is handled, test that too. | 401 // TODO(paulemeyer): Once adding frames mid-session is handled, test that too. |
| 414 } | 402 } |
| 415 | 403 |
| 416 // Tests Searching in a hidden frame. Matches in the hidden frame should be | 404 // Tests Searching in a hidden frame. Matches in the hidden frame should be |
| 417 // ignored. | 405 // ignored. |
| 418 IN_PROC_BROWSER_TEST_F(FindRequestManagerTest, MAYBE_HiddenFrame) { | 406 IN_PROC_BROWSER_TEST_F(FindRequestManagerTest, MAYBE(HiddenFrame)) { |
| 419 LoadAndWait("/find_in_hidden_frame.html"); | 407 LoadAndWait("/find_in_hidden_frame.html"); |
| 420 | 408 |
| 421 blink::WebFindOptions default_options; | 409 blink::WebFindOptions default_options; |
| 422 Find("hello", default_options); | 410 Find("hello", default_options); |
| 423 WaitForFinalReply(); | 411 WaitForFinalReply(); |
| 424 FindResults results = delegate()->GetFindResults(); | 412 FindResults results = delegate()->GetFindResults(); |
| 425 | 413 |
| 426 EXPECT_EQ(last_request_id(), results.request_id); | 414 EXPECT_EQ(last_request_id(), results.request_id); |
| 427 EXPECT_EQ(1, results.number_of_matches); | 415 EXPECT_EQ(1, results.number_of_matches); |
| 428 EXPECT_EQ(1, results.active_match_ordinal); | 416 EXPECT_EQ(1, results.active_match_ordinal); |
| 429 } | 417 } |
| 430 | 418 |
| 431 #if defined(OS_ANDROID) | 419 #if defined(OS_ANDROID) |
| 432 // Tests requesting find match rects. | 420 // Tests requesting find match rects. |
| 433 IN_PROC_BROWSER_TEST_F(FindRequestManagerTest, MAYBE_FindMatchRects) { | 421 IN_PROC_BROWSER_TEST_F(FindRequestManagerTest, MAYBE(FindMatchRects)) { |
| 434 LoadAndWait("/find_in_page.html"); | 422 LoadAndWait("/find_in_page.html"); |
| 435 | 423 |
| 436 blink::WebFindOptions default_options; | 424 blink::WebFindOptions default_options; |
| 437 Find("result", default_options); | 425 Find("result", default_options); |
| 438 WaitForFinalReply(); | 426 WaitForFinalReply(); |
| 439 EXPECT_EQ(19, delegate()->GetFindResults().number_of_matches); | 427 EXPECT_EQ(19, delegate()->GetFindResults().number_of_matches); |
| 440 | 428 |
| 441 // Request the find match rects. | 429 // Request the find match rects. |
| 442 contents()->RequestFindMatchRects(-1); | 430 contents()->RequestFindMatchRects(-1); |
| 443 delegate()->WaitForMatchRects(); | 431 delegate()->WaitForMatchRects(); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 // Result 16 should be below result 15. | 492 // Result 16 should be below result 15. |
| 505 EXPECT_GT(rects[15].y(), rects[14].y()); | 493 EXPECT_GT(rects[15].y(), rects[14].y()); |
| 506 | 494 |
| 507 // Result 18 should be normalized with respect to the position:relative div, | 495 // Result 18 should be normalized with respect to the position:relative div, |
| 508 // and not it's immediate containing div. Consequently, result 18 should be | 496 // and not it's immediate containing div. Consequently, result 18 should be |
| 509 // above result 17. | 497 // above result 17. |
| 510 EXPECT_GT(rects[17].y(), rects[18].y()); | 498 EXPECT_GT(rects[17].y(), rects[18].y()); |
| 511 } | 499 } |
| 512 | 500 |
| 513 // Tests activating the find match nearest to a given point. | 501 // Tests activating the find match nearest to a given point. |
| 514 IN_PROC_BROWSER_TEST_F(FindRequestManagerTest, MAYBE_ActivateNearestFindMatch) { | 502 IN_PROC_BROWSER_TEST_F(FindRequestManagerTest, |
| 503 MAYBE(ActivateNearestFindMatch)) { |
| 515 LoadAndWait("/find_in_page.html"); | 504 LoadAndWait("/find_in_page.html"); |
| 516 | 505 |
| 517 blink::WebFindOptions default_options; | 506 blink::WebFindOptions default_options; |
| 518 Find("result", default_options); | 507 Find("result", default_options); |
| 519 WaitForFinalReply(); | 508 WaitForFinalReply(); |
| 520 EXPECT_EQ(19, delegate()->GetFindResults().number_of_matches); | 509 EXPECT_EQ(19, delegate()->GetFindResults().number_of_matches); |
| 521 | 510 |
| 522 // Get the find match rects. | 511 // Get the find match rects. |
| 523 contents()->RequestFindMatchRects(-1); | 512 contents()->RequestFindMatchRects(-1); |
| 524 delegate()->WaitForMatchRects(); | 513 delegate()->WaitForMatchRects(); |
| 525 const std::vector<gfx::RectF>& rects = delegate()->find_match_rects(); | 514 const std::vector<gfx::RectF>& rects = delegate()->find_match_rects(); |
| 526 | 515 |
| 527 // Activate matches via points inside each of the find match rects, in an | 516 // Activate matches via points inside each of the find match rects, in an |
| 528 // arbitrary order. Check that the correct match becomes active after each | 517 // arbitrary order. Check that the correct match becomes active after each |
| 529 // activation. | 518 // activation. |
| 530 int order[19] = | 519 int order[19] = |
| 531 {11, 13, 2, 0, 16, 5, 7, 10, 6, 1, 15, 14, 9, 17, 18, 3, 8, 12, 4}; | 520 {11, 13, 2, 0, 16, 5, 7, 10, 6, 1, 15, 14, 9, 17, 18, 3, 8, 12, 4}; |
| 532 for (int i = 0; i < 19; ++i) { | 521 for (int i = 0; i < 19; ++i) { |
| 533 contents()->ActivateNearestFindResult( | 522 contents()->ActivateNearestFindResult( |
| 534 rects[order[i]].CenterPoint().x(), rects[order[i]].CenterPoint().y()); | 523 rects[order[i]].CenterPoint().x(), rects[order[i]].CenterPoint().y()); |
| 535 delegate()->WaitForNextReply(); | 524 delegate()->WaitForNextReply(); |
| 536 EXPECT_EQ(order[i] + 1, delegate()->GetFindResults().active_match_ordinal); | 525 EXPECT_EQ(order[i] + 1, delegate()->GetFindResults().active_match_ordinal); |
| 537 } | 526 } |
| 538 } | 527 } |
| 539 #endif // defined(OS_ANDROID) | 528 #endif // defined(OS_ANDROID) |
| 540 | 529 |
| 541 } // namespace content | 530 } // namespace content |
| OLD | NEW |