| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/google/google_url_tracker.h" | 5 #include "chrome/browser/google/google_url_tracker.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 } // namespace | 498 } // namespace |
| 499 | 499 |
| 500 | 500 |
| 501 // Tests ---------------------------------------------------------------------- | 501 // Tests ---------------------------------------------------------------------- |
| 502 | 502 |
| 503 TEST_F(GoogleURLTrackerTest, DontFetchWhenNoOneRequestsCheck) { | 503 TEST_F(GoogleURLTrackerTest, DontFetchWhenNoOneRequestsCheck) { |
| 504 ExpectDefaultURLs(); | 504 ExpectDefaultURLs(); |
| 505 FinishSleep(); | 505 FinishSleep(); |
| 506 // No one called RequestServerCheck() so nothing should have happened. | 506 // No one called RequestServerCheck() so nothing should have happened. |
| 507 EXPECT_FALSE(GetFetcher()); | 507 EXPECT_FALSE(GetFetcher()); |
| 508 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 508 MockSearchDomainCheckResponse(".google.co.uk"); |
| 509 ExpectDefaultURLs(); | 509 ExpectDefaultURLs(); |
| 510 EXPECT_FALSE(observer_notified()); | 510 EXPECT_FALSE(observer_notified()); |
| 511 } | 511 } |
| 512 | 512 |
| 513 TEST_F(GoogleURLTrackerTest, UpdateOnFirstRun) { | 513 TEST_F(GoogleURLTrackerTest, UpdateOnFirstRun) { |
| 514 RequestServerCheck(); | 514 RequestServerCheck(); |
| 515 EXPECT_FALSE(GetFetcher()); | 515 EXPECT_FALSE(GetFetcher()); |
| 516 ExpectDefaultURLs(); | 516 ExpectDefaultURLs(); |
| 517 EXPECT_FALSE(observer_notified()); | 517 EXPECT_FALSE(observer_notified()); |
| 518 | 518 |
| 519 FinishSleep(); | 519 FinishSleep(); |
| 520 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 520 MockSearchDomainCheckResponse(".google.co.uk"); |
| 521 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 521 EXPECT_EQ(GURL("https://www.google.co.uk/"), fetched_google_url()); |
| 522 // GoogleURL should be updated, becase there was no last prompted URL. | 522 // GoogleURL should be updated, becase there was no last prompted URL. |
| 523 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 523 EXPECT_EQ(GURL("https://www.google.co.uk/"), google_url()); |
| 524 EXPECT_TRUE(observer_notified()); | 524 EXPECT_TRUE(observer_notified()); |
| 525 } | 525 } |
| 526 | 526 |
| 527 TEST_F(GoogleURLTrackerTest, DontUpdateWhenUnchanged) { | 527 TEST_F(GoogleURLTrackerTest, DontUpdateWhenUnchanged) { |
| 528 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 528 SetLastPromptedGoogleURL(GURL("https://www.google.co.uk/")); |
| 529 | 529 |
| 530 RequestServerCheck(); | 530 RequestServerCheck(); |
| 531 EXPECT_FALSE(GetFetcher()); | 531 EXPECT_FALSE(GetFetcher()); |
| 532 ExpectDefaultURLs(); | 532 ExpectDefaultURLs(); |
| 533 EXPECT_FALSE(observer_notified()); | 533 EXPECT_FALSE(observer_notified()); |
| 534 | 534 |
| 535 FinishSleep(); | 535 FinishSleep(); |
| 536 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 536 MockSearchDomainCheckResponse(".google.co.uk"); |
| 537 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 537 EXPECT_EQ(GURL("https://www.google.co.uk/"), fetched_google_url()); |
| 538 // GoogleURL should not be updated, because the fetched and prompted URLs | 538 // GoogleURL should not be updated, because the fetched and prompted URLs |
| 539 // match. | 539 // match. |
| 540 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 540 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 541 EXPECT_FALSE(observer_notified()); | 541 EXPECT_FALSE(observer_notified()); |
| 542 } | 542 } |
| 543 | 543 |
| 544 TEST_F(GoogleURLTrackerTest, DontPromptOnBadReplies) { | 544 TEST_F(GoogleURLTrackerTest, DontPromptOnBadReplies) { |
| 545 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 545 SetLastPromptedGoogleURL(GURL("https://www.google.co.uk/")); |
| 546 | 546 |
| 547 RequestServerCheck(); | 547 RequestServerCheck(); |
| 548 EXPECT_FALSE(GetFetcher()); | 548 EXPECT_FALSE(GetFetcher()); |
| 549 ExpectDefaultURLs(); | 549 ExpectDefaultURLs(); |
| 550 EXPECT_FALSE(observer_notified()); | 550 EXPECT_FALSE(observer_notified()); |
| 551 | 551 |
| 552 // Old-style domain string. | 552 // Not a Google domain. |
| 553 FinishSleep(); | 553 FinishSleep(); |
| 554 MockSearchDomainCheckResponse(".google.co.in"); | 554 MockSearchDomainCheckResponse(".google.evil.com"); |
| 555 EXPECT_EQ(GURL(), fetched_google_url()); | 555 EXPECT_EQ(GURL(), fetched_google_url()); |
| 556 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 556 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 557 EXPECT_FALSE(observer_notified()); | 557 EXPECT_FALSE(observer_notified()); |
| 558 SetNavigationPending(1, true); | 558 SetNavigationPending(1, true); |
| 559 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 559 CommitSearch(1, GURL("https://www.google.co.uk/search?q=test")); |
| 560 EXPECT_TRUE(GetMapEntry(1) == NULL); | 560 EXPECT_TRUE(GetMapEntry(1) == NULL); |
| 561 | 561 |
| 562 // Bad subdomain. | 562 // Doesn't start with .google. |
| 563 NotifyIPAddressChanged(); | 563 FinishSleep(); |
| 564 MockSearchDomainCheckResponse("http://mail.google.com/"); | 564 MockSearchDomainCheckResponse(".mail.google.com"); |
| 565 EXPECT_EQ(GURL(), fetched_google_url()); | 565 EXPECT_EQ(GURL(), fetched_google_url()); |
| 566 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 566 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 567 EXPECT_FALSE(observer_notified()); | 567 EXPECT_FALSE(observer_notified()); |
| 568 SetNavigationPending(1, true); | 568 SetNavigationPending(1, true); |
| 569 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 569 CommitSearch(1, GURL("https://www.google.co.uk/search?q=test")); |
| 570 EXPECT_TRUE(GetMapEntry(1) == NULL); | 570 EXPECT_TRUE(GetMapEntry(1) == NULL); |
| 571 | 571 |
| 572 // Non-empty path. | 572 // Non-empty path. |
| 573 NotifyIPAddressChanged(); | 573 NotifyIPAddressChanged(); |
| 574 MockSearchDomainCheckResponse("http://www.google.com/search"); | 574 MockSearchDomainCheckResponse(".google.com/search"); |
| 575 EXPECT_EQ(GURL(), fetched_google_url()); | 575 EXPECT_EQ(GURL(), fetched_google_url()); |
| 576 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 576 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 577 EXPECT_FALSE(observer_notified()); | 577 EXPECT_FALSE(observer_notified()); |
| 578 SetNavigationPending(1, true); | 578 SetNavigationPending(1, true); |
| 579 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 579 CommitSearch(1, GURL("https://www.google.co.uk/search?q=test")); |
| 580 EXPECT_TRUE(GetMapEntry(1) == NULL); | 580 EXPECT_TRUE(GetMapEntry(1) == NULL); |
| 581 | 581 |
| 582 // Non-empty query. | 582 // Non-empty query. |
| 583 NotifyIPAddressChanged(); | 583 NotifyIPAddressChanged(); |
| 584 MockSearchDomainCheckResponse("http://www.google.com/?q=foo"); | 584 MockSearchDomainCheckResponse(".google.com/?q=foo"); |
| 585 EXPECT_EQ(GURL(), fetched_google_url()); | 585 EXPECT_EQ(GURL(), fetched_google_url()); |
| 586 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 586 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 587 EXPECT_FALSE(observer_notified()); | 587 EXPECT_FALSE(observer_notified()); |
| 588 SetNavigationPending(1, true); | 588 SetNavigationPending(1, true); |
| 589 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 589 CommitSearch(1, GURL("https://www.google.co.uk/search?q=test")); |
| 590 EXPECT_TRUE(GetMapEntry(1) == NULL); | 590 EXPECT_TRUE(GetMapEntry(1) == NULL); |
| 591 | 591 |
| 592 // Non-empty ref. | 592 // Non-empty ref. |
| 593 NotifyIPAddressChanged(); | 593 NotifyIPAddressChanged(); |
| 594 MockSearchDomainCheckResponse("http://www.google.com/#anchor"); | 594 MockSearchDomainCheckResponse(".google.com/#anchor"); |
| 595 EXPECT_EQ(GURL(), fetched_google_url()); | 595 EXPECT_EQ(GURL(), fetched_google_url()); |
| 596 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 596 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 597 EXPECT_FALSE(observer_notified()); | 597 EXPECT_FALSE(observer_notified()); |
| 598 SetNavigationPending(1, true); | 598 SetNavigationPending(1, true); |
| 599 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 599 CommitSearch(1, GURL("https://www.google.co.uk/search?q=test")); |
| 600 EXPECT_TRUE(GetMapEntry(1) == NULL); | |
| 601 | |
| 602 // Complete garbage. | |
| 603 NotifyIPAddressChanged(); | |
| 604 MockSearchDomainCheckResponse("HJ)*qF)_*&@f1"); | |
| 605 EXPECT_EQ(GURL(), fetched_google_url()); | |
| 606 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | |
| 607 EXPECT_FALSE(observer_notified()); | |
| 608 SetNavigationPending(1, true); | |
| 609 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | |
| 610 EXPECT_TRUE(GetMapEntry(1) == NULL); | 600 EXPECT_TRUE(GetMapEntry(1) == NULL); |
| 611 } | 601 } |
| 612 | 602 |
| 613 TEST_F(GoogleURLTrackerTest, UpdatePromptedURLOnReturnToPreviousLocation) { | 603 TEST_F(GoogleURLTrackerTest, UpdatePromptedURLOnReturnToPreviousLocation) { |
| 614 SetLastPromptedGoogleURL(GURL("http://www.google.co.jp/")); | 604 SetLastPromptedGoogleURL(GURL("https://www.google.co.jp/")); |
| 615 set_google_url(GURL("http://www.google.co.uk/")); | 605 set_google_url(GURL("https://www.google.co.uk/")); |
| 616 RequestServerCheck(); | 606 RequestServerCheck(); |
| 617 FinishSleep(); | 607 FinishSleep(); |
| 618 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 608 MockSearchDomainCheckResponse(".google.co.uk"); |
| 619 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | |
| 620 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | |
| 621 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | |
| 622 EXPECT_FALSE(observer_notified()); | |
| 623 } | |
| 624 | |
| 625 TEST_F(GoogleURLTrackerTest, SilentlyAcceptSchemeChange) { | |
| 626 // We should auto-accept changes to the current Google URL that merely change | |
| 627 // the scheme, regardless of what the last prompted URL was. | |
| 628 SetLastPromptedGoogleURL(GURL("http://www.google.co.jp/")); | |
| 629 set_google_url(GURL("http://www.google.co.uk/")); | |
| 630 RequestServerCheck(); | |
| 631 FinishSleep(); | |
| 632 MockSearchDomainCheckResponse("https://www.google.co.uk/"); | |
| 633 EXPECT_EQ(GURL("https://www.google.co.uk/"), fetched_google_url()); | 609 EXPECT_EQ(GURL("https://www.google.co.uk/"), fetched_google_url()); |
| 634 EXPECT_EQ(GURL("https://www.google.co.uk/"), google_url()); | 610 EXPECT_EQ(GURL("https://www.google.co.uk/"), google_url()); |
| 635 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 611 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 636 EXPECT_TRUE(observer_notified()); | 612 EXPECT_FALSE(observer_notified()); |
| 637 | |
| 638 NotifyIPAddressChanged(); | |
| 639 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | |
| 640 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | |
| 641 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | |
| 642 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | |
| 643 EXPECT_TRUE(observer_notified()); | |
| 644 } | 613 } |
| 645 | 614 |
| 646 TEST_F(GoogleURLTrackerTest, RefetchOnIPAddressChange) { | 615 TEST_F(GoogleURLTrackerTest, RefetchOnIPAddressChange) { |
| 647 RequestServerCheck(); | 616 RequestServerCheck(); |
| 648 FinishSleep(); | 617 FinishSleep(); |
| 649 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 618 MockSearchDomainCheckResponse(".google.co.uk"); |
| 650 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 619 EXPECT_EQ(GURL("https://www.google.co.uk/"), fetched_google_url()); |
| 651 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 620 EXPECT_EQ(GURL("https://www.google.co.uk/"), google_url()); |
| 652 EXPECT_TRUE(observer_notified()); | 621 EXPECT_TRUE(observer_notified()); |
| 653 clear_observer_notified(); | 622 clear_observer_notified(); |
| 654 | 623 |
| 655 NotifyIPAddressChanged(); | 624 NotifyIPAddressChanged(); |
| 656 MockSearchDomainCheckResponse("http://www.google.co.in/"); | 625 MockSearchDomainCheckResponse(".google.co.in"); |
| 657 EXPECT_EQ(GURL("http://www.google.co.in/"), fetched_google_url()); | 626 EXPECT_EQ(GURL("https://www.google.co.in/"), fetched_google_url()); |
| 658 // Just fetching a new URL shouldn't reset things without a prompt. | 627 // Just fetching a new URL shouldn't reset things without a prompt. |
| 659 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 628 EXPECT_EQ(GURL("https://www.google.co.uk/"), google_url()); |
| 660 EXPECT_FALSE(observer_notified()); | 629 EXPECT_FALSE(observer_notified()); |
| 661 } | 630 } |
| 662 | 631 |
| 663 TEST_F(GoogleURLTrackerTest, DontRefetchWhenNoOneRequestsCheck) { | 632 TEST_F(GoogleURLTrackerTest, DontRefetchWhenNoOneRequestsCheck) { |
| 664 FinishSleep(); | 633 FinishSleep(); |
| 665 NotifyIPAddressChanged(); | 634 NotifyIPAddressChanged(); |
| 666 // No one called RequestServerCheck() so nothing should have happened. | 635 // No one called RequestServerCheck() so nothing should have happened. |
| 667 EXPECT_FALSE(GetFetcher()); | 636 EXPECT_FALSE(GetFetcher()); |
| 668 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 637 MockSearchDomainCheckResponse(".google.co.uk"); |
| 669 ExpectDefaultURLs(); | 638 ExpectDefaultURLs(); |
| 670 EXPECT_FALSE(observer_notified()); | 639 EXPECT_FALSE(observer_notified()); |
| 671 } | 640 } |
| 672 | 641 |
| 673 TEST_F(GoogleURLTrackerTest, FetchOnLateRequest) { | 642 TEST_F(GoogleURLTrackerTest, FetchOnLateRequest) { |
| 674 FinishSleep(); | 643 FinishSleep(); |
| 675 NotifyIPAddressChanged(); | 644 NotifyIPAddressChanged(); |
| 676 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 645 MockSearchDomainCheckResponse(".google.co.jp"); |
| 677 | 646 |
| 678 RequestServerCheck(); | 647 RequestServerCheck(); |
| 679 // The first request for a check should trigger a fetch if it hasn't happened | 648 // The first request for a check should trigger a fetch if it hasn't happened |
| 680 // already. | 649 // already. |
| 681 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 650 MockSearchDomainCheckResponse(".google.co.uk"); |
| 682 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 651 EXPECT_EQ(GURL("https://www.google.co.uk/"), fetched_google_url()); |
| 683 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 652 EXPECT_EQ(GURL("https://www.google.co.uk/"), google_url()); |
| 684 EXPECT_TRUE(observer_notified()); | 653 EXPECT_TRUE(observer_notified()); |
| 685 } | 654 } |
| 686 | 655 |
| 687 TEST_F(GoogleURLTrackerTest, DontFetchTwiceOnLateRequests) { | 656 TEST_F(GoogleURLTrackerTest, DontFetchTwiceOnLateRequests) { |
| 688 FinishSleep(); | 657 FinishSleep(); |
| 689 NotifyIPAddressChanged(); | 658 NotifyIPAddressChanged(); |
| 690 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 659 MockSearchDomainCheckResponse(".google.co.jp"); |
| 691 | 660 |
| 692 RequestServerCheck(); | 661 RequestServerCheck(); |
| 693 // The first request for a check should trigger a fetch if it hasn't happened | 662 // The first request for a check should trigger a fetch if it hasn't happened |
| 694 // already. | 663 // already. |
| 695 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 664 MockSearchDomainCheckResponse(".google.co.uk"); |
| 696 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 665 EXPECT_EQ(GURL("https://www.google.co.uk/"), fetched_google_url()); |
| 697 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 666 EXPECT_EQ(GURL("https://www.google.co.uk/"), google_url()); |
| 698 EXPECT_TRUE(observer_notified()); | 667 EXPECT_TRUE(observer_notified()); |
| 699 clear_observer_notified(); | 668 clear_observer_notified(); |
| 700 | 669 |
| 701 RequestServerCheck(); | 670 RequestServerCheck(); |
| 702 // The second request should be ignored. | 671 // The second request should be ignored. |
| 703 EXPECT_FALSE(GetFetcher()); | 672 EXPECT_FALSE(GetFetcher()); |
| 704 MockSearchDomainCheckResponse("http://www.google.co.in/"); | 673 MockSearchDomainCheckResponse(".google.co.in"); |
| 705 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 674 EXPECT_EQ(GURL("https://www.google.co.uk/"), fetched_google_url()); |
| 706 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 675 EXPECT_EQ(GURL("https://www.google.co.uk/"), google_url()); |
| 707 EXPECT_FALSE(observer_notified()); | 676 EXPECT_FALSE(observer_notified()); |
| 708 } | 677 } |
| 709 | 678 |
| 710 TEST_F(GoogleURLTrackerTest, SearchingDoesNothingIfNoNeedToPrompt) { | 679 TEST_F(GoogleURLTrackerTest, SearchingDoesNothingIfNoNeedToPrompt) { |
| 711 RequestServerCheck(); | 680 RequestServerCheck(); |
| 712 FinishSleep(); | 681 FinishSleep(); |
| 713 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 682 MockSearchDomainCheckResponse(".google.co.uk"); |
| 714 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 683 EXPECT_EQ(GURL("https://www.google.co.uk/"), fetched_google_url()); |
| 715 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 684 EXPECT_EQ(GURL("https://www.google.co.uk/"), google_url()); |
| 716 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 685 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 717 EXPECT_TRUE(observer_notified()); | 686 EXPECT_TRUE(observer_notified()); |
| 718 clear_observer_notified(); | 687 clear_observer_notified(); |
| 719 | 688 |
| 720 SetNavigationPending(1, true); | 689 SetNavigationPending(1, true); |
| 721 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 690 CommitSearch(1, GURL("https://www.google.co.uk/search?q=test")); |
| 722 EXPECT_TRUE(GetMapEntry(1) == NULL); | 691 EXPECT_TRUE(GetMapEntry(1) == NULL); |
| 723 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 692 EXPECT_EQ(GURL("https://www.google.co.uk/"), fetched_google_url()); |
| 724 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 693 EXPECT_EQ(GURL("https://www.google.co.uk/"), google_url()); |
| 725 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 694 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 726 EXPECT_FALSE(observer_notified()); | 695 EXPECT_FALSE(observer_notified()); |
| 727 } | 696 } |
| 728 | 697 |
| 729 TEST_F(GoogleURLTrackerTest, TabClosedOnPendingSearch) { | 698 TEST_F(GoogleURLTrackerTest, TabClosedOnPendingSearch) { |
| 730 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 699 SetLastPromptedGoogleURL(GURL("https://www.google.co.uk/")); |
| 731 RequestServerCheck(); | 700 RequestServerCheck(); |
| 732 FinishSleep(); | 701 FinishSleep(); |
| 733 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 702 MockSearchDomainCheckResponse(".google.co.jp"); |
| 734 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 703 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 735 EXPECT_EQ(GURL("http://www.google.co.jp/"), fetched_google_url()); | 704 EXPECT_EQ(GURL("https://www.google.co.jp/"), fetched_google_url()); |
| 736 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 705 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 737 EXPECT_FALSE(observer_notified()); | 706 EXPECT_FALSE(observer_notified()); |
| 738 | 707 |
| 739 SetNavigationPending(1, true); | 708 SetNavigationPending(1, true); |
| 740 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(1); | 709 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(1); |
| 741 ASSERT_FALSE(map_entry == NULL); | 710 ASSERT_FALSE(map_entry == NULL); |
| 742 EXPECT_FALSE(map_entry->has_infobar_delegate()); | 711 EXPECT_FALSE(map_entry->has_infobar_delegate()); |
| 743 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 712 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 744 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 713 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 745 EXPECT_FALSE(observer_notified()); | 714 EXPECT_FALSE(observer_notified()); |
| 746 | 715 |
| 747 CloseTab(1); | 716 CloseTab(1); |
| 748 EXPECT_TRUE(GetMapEntry(1) == NULL); | 717 EXPECT_TRUE(GetMapEntry(1) == NULL); |
| 749 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 718 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 750 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 719 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 751 EXPECT_FALSE(observer_notified()); | 720 EXPECT_FALSE(observer_notified()); |
| 752 } | 721 } |
| 753 | 722 |
| 754 TEST_F(GoogleURLTrackerTest, TabClosedOnCommittedSearch) { | 723 TEST_F(GoogleURLTrackerTest, TabClosedOnCommittedSearch) { |
| 755 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 724 SetLastPromptedGoogleURL(GURL("https://www.google.co.uk/")); |
| 756 RequestServerCheck(); | 725 RequestServerCheck(); |
| 757 FinishSleep(); | 726 FinishSleep(); |
| 758 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 727 MockSearchDomainCheckResponse(".google.co.jp"); |
| 759 | 728 |
| 760 SetNavigationPending(1, true); | 729 SetNavigationPending(1, true); |
| 761 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 730 CommitSearch(1, GURL("https://www.google.co.uk/search?q=test")); |
| 762 EXPECT_FALSE(GetInfoBarDelegate(1) == NULL); | 731 EXPECT_FALSE(GetInfoBarDelegate(1) == NULL); |
| 763 | 732 |
| 764 CloseTab(1); | 733 CloseTab(1); |
| 765 EXPECT_TRUE(GetMapEntry(1) == NULL); | 734 EXPECT_TRUE(GetMapEntry(1) == NULL); |
| 766 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 735 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 767 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 736 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 768 EXPECT_FALSE(observer_notified()); | 737 EXPECT_FALSE(observer_notified()); |
| 769 } | 738 } |
| 770 | 739 |
| 771 TEST_F(GoogleURLTrackerTest, InfoBarClosed) { | 740 TEST_F(GoogleURLTrackerTest, InfoBarClosed) { |
| 772 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 741 SetLastPromptedGoogleURL(GURL("https://www.google.co.uk/")); |
| 773 RequestServerCheck(); | 742 RequestServerCheck(); |
| 774 FinishSleep(); | 743 FinishSleep(); |
| 775 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 744 MockSearchDomainCheckResponse(".google.co.jp"); |
| 776 | 745 |
| 777 SetNavigationPending(1, true); | 746 SetNavigationPending(1, true); |
| 778 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 747 CommitSearch(1, GURL("https://www.google.co.uk/search?q=test")); |
| 779 GoogleURLTrackerInfoBarDelegate* infobar = GetInfoBarDelegate(1); | 748 GoogleURLTrackerInfoBarDelegate* infobar = GetInfoBarDelegate(1); |
| 780 ASSERT_FALSE(infobar == NULL); | 749 ASSERT_FALSE(infobar == NULL); |
| 781 | 750 |
| 782 infobar->Close(false); | 751 infobar->Close(false); |
| 783 EXPECT_TRUE(GetMapEntry(1) == NULL); | 752 EXPECT_TRUE(GetMapEntry(1) == NULL); |
| 784 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 753 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 785 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 754 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 786 EXPECT_FALSE(observer_notified()); | 755 EXPECT_FALSE(observer_notified()); |
| 787 } | 756 } |
| 788 | 757 |
| 789 TEST_F(GoogleURLTrackerTest, InfoBarRefused) { | 758 TEST_F(GoogleURLTrackerTest, InfoBarRefused) { |
| 790 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 759 SetLastPromptedGoogleURL(GURL("https://www.google.co.uk/")); |
| 791 RequestServerCheck(); | 760 RequestServerCheck(); |
| 792 FinishSleep(); | 761 FinishSleep(); |
| 793 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 762 MockSearchDomainCheckResponse(".google.co.jp"); |
| 794 | 763 |
| 795 SetNavigationPending(1, true); | 764 SetNavigationPending(1, true); |
| 796 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 765 CommitSearch(1, GURL("https://www.google.co.uk/search?q=test")); |
| 797 GoogleURLTrackerInfoBarDelegate* infobar = GetInfoBarDelegate(1); | 766 GoogleURLTrackerInfoBarDelegate* infobar = GetInfoBarDelegate(1); |
| 798 ASSERT_FALSE(infobar == NULL); | 767 ASSERT_FALSE(infobar == NULL); |
| 799 | 768 |
| 800 infobar->Cancel(); | 769 infobar->Cancel(); |
| 801 EXPECT_TRUE(GetMapEntry(1) == NULL); | 770 EXPECT_TRUE(GetMapEntry(1) == NULL); |
| 802 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 771 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 803 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); | 772 EXPECT_EQ(GURL("https://www.google.co.jp/"), GetLastPromptedGoogleURL()); |
| 804 EXPECT_FALSE(observer_notified()); | 773 EXPECT_FALSE(observer_notified()); |
| 805 } | 774 } |
| 806 | 775 |
| 807 TEST_F(GoogleURLTrackerTest, InfoBarAccepted) { | 776 TEST_F(GoogleURLTrackerTest, InfoBarAccepted) { |
| 808 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 777 SetLastPromptedGoogleURL(GURL("https://www.google.co.uk/")); |
| 809 RequestServerCheck(); | 778 RequestServerCheck(); |
| 810 FinishSleep(); | 779 FinishSleep(); |
| 811 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 780 MockSearchDomainCheckResponse(".google.co.jp"); |
| 812 | 781 |
| 813 SetNavigationPending(1, true); | 782 SetNavigationPending(1, true); |
| 814 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 783 CommitSearch(1, GURL("https://www.google.co.uk/search?q=test")); |
| 815 GoogleURLTrackerInfoBarDelegate* infobar = GetInfoBarDelegate(1); | 784 GoogleURLTrackerInfoBarDelegate* infobar = GetInfoBarDelegate(1); |
| 816 ASSERT_FALSE(infobar == NULL); | 785 ASSERT_FALSE(infobar == NULL); |
| 817 | 786 |
| 818 infobar->Accept(); | 787 infobar->Accept(); |
| 819 EXPECT_TRUE(GetMapEntry(1) == NULL); | 788 EXPECT_TRUE(GetMapEntry(1) == NULL); |
| 820 EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url()); | 789 EXPECT_EQ(GURL("https://www.google.co.jp/"), google_url()); |
| 821 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); | 790 EXPECT_EQ(GURL("https://www.google.co.jp/"), GetLastPromptedGoogleURL()); |
| 822 EXPECT_TRUE(observer_notified()); | 791 EXPECT_TRUE(observer_notified()); |
| 823 } | 792 } |
| 824 | 793 |
| 825 TEST_F(GoogleURLTrackerTest, FetchesCanAutomaticallyCloseInfoBars) { | 794 TEST_F(GoogleURLTrackerTest, FetchesCanAutomaticallyCloseInfoBars) { |
| 826 RequestServerCheck(); | 795 RequestServerCheck(); |
| 827 FinishSleep(); | 796 FinishSleep(); |
| 828 MockSearchDomainCheckResponse(google_url().spec()); | 797 MockSearchDomainCheckResponse(".google.com"); |
| 829 | 798 |
| 830 // Re-fetching the accepted URL after showing an infobar for another URL | 799 // Re-fetching the accepted URL after showing an infobar for another URL |
| 831 // should close the infobar. | 800 // should close the infobar. |
| 832 NotifyIPAddressChanged(); | 801 NotifyIPAddressChanged(); |
| 833 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 802 MockSearchDomainCheckResponse(".google.co.uk"); |
| 834 SetNavigationPending(1, true); | 803 SetNavigationPending(1, true); |
| 835 CommitSearch(1, GURL("http://www.google.com/search?q=test")); | 804 CommitSearch(1, GURL("https://www.google.com/search?q=test")); |
| 836 EXPECT_FALSE(GetInfoBarDelegate(1) == NULL); | 805 EXPECT_FALSE(GetInfoBarDelegate(1) == NULL); |
| 837 NotifyIPAddressChanged(); | 806 NotifyIPAddressChanged(); |
| 838 MockSearchDomainCheckResponse(google_url().spec()); | 807 MockSearchDomainCheckResponse(".google.com"); |
| 839 EXPECT_EQ(google_url(), GetLastPromptedGoogleURL()); | 808 EXPECT_EQ(google_url(), GetLastPromptedGoogleURL()); |
| 840 EXPECT_TRUE(GetMapEntry(1) == NULL); | 809 EXPECT_TRUE(GetMapEntry(1) == NULL); |
| 841 | 810 |
| 842 // As should fetching a URL that differs from the accepted only by the scheme. | 811 // As should re-fetching the last prompted URL. |
| 812 SetLastPromptedGoogleURL(GURL("https://www.google.co.uk/")); |
| 843 NotifyIPAddressChanged(); | 813 NotifyIPAddressChanged(); |
| 844 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 814 MockSearchDomainCheckResponse(".google.co.jp"); |
| 845 SetNavigationPending(1, true); | 815 SetNavigationPending(1, true); |
| 846 CommitSearch(1, GURL("http://www.google.com/search?q=test")); | 816 CommitSearch(1, GURL("https://www.google.com/search?q=test")); |
| 847 EXPECT_FALSE(GetInfoBarDelegate(1) == NULL); | 817 EXPECT_FALSE(GetInfoBarDelegate(1) == NULL); |
| 848 NotifyIPAddressChanged(); | 818 NotifyIPAddressChanged(); |
| 849 url::Replacements<char> replacements; | 819 MockSearchDomainCheckResponse(".google.co.uk"); |
| 850 const std::string& scheme("https"); | 820 EXPECT_EQ(GURL("https://www.google.com/"), google_url()); |
| 851 replacements.SetScheme(scheme.data(), url::Component(0, scheme.length())); | |
| 852 GURL new_google_url(google_url().ReplaceComponents(replacements)); | |
| 853 MockSearchDomainCheckResponse(new_google_url.spec()); | |
| 854 EXPECT_EQ(new_google_url, GetLastPromptedGoogleURL()); | |
| 855 EXPECT_TRUE(GetMapEntry(1) == NULL); | |
| 856 | |
| 857 // As should re-fetching the last prompted URL. | |
| 858 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | |
| 859 NotifyIPAddressChanged(); | |
| 860 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | |
| 861 SetNavigationPending(1, true); | |
| 862 CommitSearch(1, GURL("http://www.google.com/search?q=test")); | |
| 863 EXPECT_FALSE(GetInfoBarDelegate(1) == NULL); | |
| 864 NotifyIPAddressChanged(); | |
| 865 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | |
| 866 EXPECT_EQ(new_google_url, google_url()); | |
| 867 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | |
| 868 EXPECT_TRUE(GetMapEntry(1) == NULL); | |
| 869 | |
| 870 // And one that differs from the last prompted URL only by the scheme. | |
| 871 NotifyIPAddressChanged(); | |
| 872 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | |
| 873 SetNavigationPending(1, true); | |
| 874 CommitSearch(1, GURL("http://www.google.com/search?q=test")); | |
| 875 EXPECT_FALSE(GetInfoBarDelegate(1) == NULL); | |
| 876 NotifyIPAddressChanged(); | |
| 877 MockSearchDomainCheckResponse("https://www.google.co.uk/"); | |
| 878 EXPECT_EQ(new_google_url, google_url()); | |
| 879 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 821 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 880 EXPECT_TRUE(GetMapEntry(1) == NULL); | 822 EXPECT_TRUE(GetMapEntry(1) == NULL); |
| 881 | 823 |
| 882 // And fetching a different URL entirely. | 824 // And fetching a different URL entirely. |
| 883 NotifyIPAddressChanged(); | 825 NotifyIPAddressChanged(); |
| 884 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 826 MockSearchDomainCheckResponse(".google.co.jp"); |
| 885 SetNavigationPending(1, true); | 827 SetNavigationPending(1, true); |
| 886 CommitSearch(1, GURL("http://www.google.com/search?q=test")); | 828 CommitSearch(1, GURL("https://www.google.com/search?q=test")); |
| 887 EXPECT_FALSE(GetInfoBarDelegate(1) == NULL); | 829 EXPECT_FALSE(GetInfoBarDelegate(1) == NULL); |
| 888 NotifyIPAddressChanged(); | 830 NotifyIPAddressChanged(); |
| 889 MockSearchDomainCheckResponse("https://www.google.co.in/"); | 831 MockSearchDomainCheckResponse(".google.co.in"); |
| 890 EXPECT_EQ(new_google_url, google_url()); | 832 EXPECT_EQ(GURL("https://www.google.com/"), google_url()); |
| 891 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 833 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 892 EXPECT_TRUE(GetMapEntry(1) == NULL); | 834 EXPECT_TRUE(GetMapEntry(1) == NULL); |
| 893 } | 835 } |
| 894 | 836 |
| 895 TEST_F(GoogleURLTrackerTest, ResetInfoBarGoogleURLs) { | 837 TEST_F(GoogleURLTrackerTest, NavigationsAfterPendingSearch) { |
| 838 SetLastPromptedGoogleURL(GURL("https://www.google.co.uk/")); |
| 896 RequestServerCheck(); | 839 RequestServerCheck(); |
| 897 FinishSleep(); | 840 FinishSleep(); |
| 898 MockSearchDomainCheckResponse(google_url().spec()); | 841 MockSearchDomainCheckResponse(".google.co.jp"); |
| 899 | |
| 900 NotifyIPAddressChanged(); | |
| 901 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | |
| 902 SetNavigationPending(1, true); | |
| 903 CommitSearch(1, GURL("http://www.google.com/search?q=test")); | |
| 904 GoogleURLTrackerInfoBarDelegate* delegate = GetInfoBarDelegate(1); | |
| 905 ASSERT_FALSE(delegate == NULL); | |
| 906 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | |
| 907 | |
| 908 // If while an infobar is showing we fetch a new URL that differs from the | |
| 909 // infobar's only by scheme, the infobar should stay showing. | |
| 910 NotifyIPAddressChanged(); | |
| 911 MockSearchDomainCheckResponse("https://www.google.co.uk/"); | |
| 912 EXPECT_EQ(delegate, GetInfoBarDelegate(1)); | |
| 913 EXPECT_EQ(GURL("https://www.google.co.uk/"), fetched_google_url()); | |
| 914 } | |
| 915 | |
| 916 TEST_F(GoogleURLTrackerTest, NavigationsAfterPendingSearch) { | |
| 917 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | |
| 918 RequestServerCheck(); | |
| 919 FinishSleep(); | |
| 920 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | |
| 921 | 842 |
| 922 // A pending non-search after a pending search should delete the map entry. | 843 // A pending non-search after a pending search should delete the map entry. |
| 923 SetNavigationPending(1, true); | 844 SetNavigationPending(1, true); |
| 924 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(1); | 845 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(1); |
| 925 ASSERT_FALSE(map_entry == NULL); | 846 ASSERT_FALSE(map_entry == NULL); |
| 926 EXPECT_FALSE(map_entry->has_infobar_delegate()); | 847 EXPECT_FALSE(map_entry->has_infobar_delegate()); |
| 927 SetNavigationPending(1, false); | 848 SetNavigationPending(1, false); |
| 928 EXPECT_TRUE(GetMapEntry(1) == NULL); | 849 EXPECT_TRUE(GetMapEntry(1) == NULL); |
| 929 | 850 |
| 930 // A pending search after a pending search should leave the map entry alive. | 851 // A pending search after a pending search should leave the map entry alive. |
| 931 SetNavigationPending(1, true); | 852 SetNavigationPending(1, true); |
| 932 map_entry = GetMapEntry(1); | 853 map_entry = GetMapEntry(1); |
| 933 ASSERT_FALSE(map_entry == NULL); | 854 ASSERT_FALSE(map_entry == NULL); |
| 934 EXPECT_FALSE(map_entry->has_infobar_delegate()); | 855 EXPECT_FALSE(map_entry->has_infobar_delegate()); |
| 935 SetNavigationPending(1, true); | 856 SetNavigationPending(1, true); |
| 936 ASSERT_EQ(map_entry, GetMapEntry(1)); | 857 ASSERT_EQ(map_entry, GetMapEntry(1)); |
| 937 EXPECT_FALSE(map_entry->has_infobar_delegate()); | 858 EXPECT_FALSE(map_entry->has_infobar_delegate()); |
| 938 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); | 859 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); |
| 939 | 860 |
| 940 // Committing this search should show an infobar. | 861 // Committing this search should show an infobar. |
| 941 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test2")); | 862 CommitSearch(1, GURL("https://www.google.co.uk/search?q=test2")); |
| 942 EXPECT_TRUE(map_entry->has_infobar_delegate()); | 863 EXPECT_TRUE(map_entry->has_infobar_delegate()); |
| 943 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 864 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 944 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 865 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 945 EXPECT_FALSE(observer_notified()); | 866 EXPECT_FALSE(observer_notified()); |
| 946 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); | 867 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); |
| 947 } | 868 } |
| 948 | 869 |
| 949 TEST_F(GoogleURLTrackerTest, NavigationsAfterCommittedSearch) { | 870 TEST_F(GoogleURLTrackerTest, NavigationsAfterCommittedSearch) { |
| 950 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 871 SetLastPromptedGoogleURL(GURL("https://www.google.co.uk/")); |
| 951 RequestServerCheck(); | 872 RequestServerCheck(); |
| 952 FinishSleep(); | 873 FinishSleep(); |
| 953 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 874 MockSearchDomainCheckResponse(".google.co.jp"); |
| 954 SetNavigationPending(1, true); | 875 SetNavigationPending(1, true); |
| 955 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 876 CommitSearch(1, GURL("https://www.google.co.uk/search?q=test")); |
| 956 GoogleURLTrackerInfoBarDelegate* delegate = GetInfoBarDelegate(1); | 877 GoogleURLTrackerInfoBarDelegate* delegate = GetInfoBarDelegate(1); |
| 957 ASSERT_FALSE(delegate == NULL); | 878 ASSERT_FALSE(delegate == NULL); |
| 958 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); | 879 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); |
| 959 | 880 |
| 960 // A pending non-search on a visible infobar should basically do nothing. | 881 // A pending non-search on a visible infobar should basically do nothing. |
| 961 SetNavigationPending(1, false); | 882 SetNavigationPending(1, false); |
| 962 ASSERT_EQ(delegate, GetInfoBarDelegate(1)); | 883 ASSERT_EQ(delegate, GetInfoBarDelegate(1)); |
| 963 EXPECT_EQ(0, delegate->pending_id()); | 884 EXPECT_EQ(0, delegate->pending_id()); |
| 964 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); | 885 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); |
| 965 | 886 |
| 966 // As should another pending non-search after the first. | 887 // As should another pending non-search after the first. |
| 967 SetNavigationPending(1, false); | 888 SetNavigationPending(1, false); |
| 968 ASSERT_EQ(delegate, GetInfoBarDelegate(1)); | 889 ASSERT_EQ(delegate, GetInfoBarDelegate(1)); |
| 969 EXPECT_EQ(0, delegate->pending_id()); | 890 EXPECT_EQ(0, delegate->pending_id()); |
| 970 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); | 891 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); |
| 971 | 892 |
| 972 // Committing this non-search should close the infobar. The control flow in | 893 // Committing this non-search should close the infobar. The control flow in |
| 973 // these tests is not really comparable to in the real browser, but at least a | 894 // these tests is not really comparable to in the real browser, but at least a |
| 974 // few sanity-checks will be performed. | 895 // few sanity-checks will be performed. |
| 975 ASSERT_NO_FATAL_FAILURE(CommitNonSearch(1)); | 896 ASSERT_NO_FATAL_FAILURE(CommitNonSearch(1)); |
| 976 EXPECT_TRUE(GetMapEntry(1) == NULL); | 897 EXPECT_TRUE(GetMapEntry(1) == NULL); |
| 977 | 898 |
| 978 // A pending search on a visible infobar should cause the infobar to listen | 899 // A pending search on a visible infobar should cause the infobar to listen |
| 979 // for the search to commit. | 900 // for the search to commit. |
| 980 SetNavigationPending(1, true); | 901 SetNavigationPending(1, true); |
| 981 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 902 CommitSearch(1, GURL("https://www.google.co.uk/search?q=test")); |
| 982 delegate = GetInfoBarDelegate(1); | 903 delegate = GetInfoBarDelegate(1); |
| 983 ASSERT_FALSE(delegate == NULL); | 904 ASSERT_FALSE(delegate == NULL); |
| 984 SetNavigationPending(1, true); | 905 SetNavigationPending(1, true); |
| 985 ASSERT_EQ(delegate, GetInfoBarDelegate(1)); | 906 ASSERT_EQ(delegate, GetInfoBarDelegate(1)); |
| 986 EXPECT_EQ(1, delegate->pending_id()); | 907 EXPECT_EQ(1, delegate->pending_id()); |
| 987 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); | 908 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); |
| 988 | 909 |
| 989 // But a non-search after this should cancel that state. | 910 // But a non-search after this should cancel that state. |
| 990 SetNavigationPending(1, false); | 911 SetNavigationPending(1, false); |
| 991 ASSERT_EQ(delegate, GetInfoBarDelegate(1)); | 912 ASSERT_EQ(delegate, GetInfoBarDelegate(1)); |
| 992 EXPECT_EQ(0, delegate->pending_id()); | 913 EXPECT_EQ(0, delegate->pending_id()); |
| 993 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); | 914 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); |
| 994 | 915 |
| 995 // Another pending search after the non-search should put us back into | 916 // Another pending search after the non-search should put us back into |
| 996 // "waiting for commit" mode. | 917 // "waiting for commit" mode. |
| 997 SetNavigationPending(1, true); | 918 SetNavigationPending(1, true); |
| 998 ASSERT_EQ(delegate, GetInfoBarDelegate(1)); | 919 ASSERT_EQ(delegate, GetInfoBarDelegate(1)); |
| 999 EXPECT_EQ(1, delegate->pending_id()); | 920 EXPECT_EQ(1, delegate->pending_id()); |
| 1000 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); | 921 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); |
| 1001 | 922 |
| 1002 // A second pending search after the first should not really change anything. | 923 // A second pending search after the first should not really change anything. |
| 1003 SetNavigationPending(1, true); | 924 SetNavigationPending(1, true); |
| 1004 ASSERT_EQ(delegate, GetInfoBarDelegate(1)); | 925 ASSERT_EQ(delegate, GetInfoBarDelegate(1)); |
| 1005 EXPECT_EQ(1, delegate->pending_id()); | 926 EXPECT_EQ(1, delegate->pending_id()); |
| 1006 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); | 927 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); |
| 1007 | 928 |
| 1008 // Committing this search should change the visible infobar's search_url. | 929 // Committing this search should change the visible infobar's search_url. |
| 1009 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test2")); | 930 CommitSearch(1, GURL("https://www.google.co.uk/search?q=test2")); |
| 1010 ASSERT_EQ(delegate, GetInfoBarDelegate(1)); | 931 ASSERT_EQ(delegate, GetInfoBarDelegate(1)); |
| 1011 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test2"), | 932 EXPECT_EQ(GURL("https://www.google.co.uk/search?q=test2"), |
| 1012 delegate->search_url()); | 933 delegate->search_url()); |
| 1013 EXPECT_EQ(0, delegate->pending_id()); | 934 EXPECT_EQ(0, delegate->pending_id()); |
| 1014 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); | 935 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); |
| 1015 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 936 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 1016 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 937 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 1017 EXPECT_FALSE(observer_notified()); | 938 EXPECT_FALSE(observer_notified()); |
| 1018 } | 939 } |
| 1019 | 940 |
| 1020 TEST_F(GoogleURLTrackerTest, MultipleMapEntries) { | 941 TEST_F(GoogleURLTrackerTest, MultipleMapEntries) { |
| 1021 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 942 SetLastPromptedGoogleURL(GURL("https://www.google.co.uk/")); |
| 1022 RequestServerCheck(); | 943 RequestServerCheck(); |
| 1023 FinishSleep(); | 944 FinishSleep(); |
| 1024 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 945 MockSearchDomainCheckResponse(".google.co.jp"); |
| 1025 | 946 |
| 1026 SetNavigationPending(1, true); | 947 SetNavigationPending(1, true); |
| 1027 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(1); | 948 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(1); |
| 1028 ASSERT_FALSE(map_entry == NULL); | 949 ASSERT_FALSE(map_entry == NULL); |
| 1029 EXPECT_FALSE(map_entry->has_infobar_delegate()); | 950 EXPECT_FALSE(map_entry->has_infobar_delegate()); |
| 1030 | 951 |
| 1031 SetNavigationPending(2, true); | 952 SetNavigationPending(2, true); |
| 1032 CommitSearch(2, GURL("http://www.google.co.uk/search?q=test2")); | 953 CommitSearch(2, GURL("https://www.google.co.uk/search?q=test2")); |
| 1033 GoogleURLTrackerInfoBarDelegate* delegate2 = GetInfoBarDelegate(2); | 954 GoogleURLTrackerInfoBarDelegate* delegate2 = GetInfoBarDelegate(2); |
| 1034 ASSERT_FALSE(delegate2 == NULL); | 955 ASSERT_FALSE(delegate2 == NULL); |
| 1035 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test2"), | 956 EXPECT_EQ(GURL("https://www.google.co.uk/search?q=test2"), |
| 1036 delegate2->search_url()); | 957 delegate2->search_url()); |
| 1037 | 958 |
| 1038 SetNavigationPending(3, true); | 959 SetNavigationPending(3, true); |
| 1039 GoogleURLTrackerMapEntry* map_entry3 = GetMapEntry(3); | 960 GoogleURLTrackerMapEntry* map_entry3 = GetMapEntry(3); |
| 1040 ASSERT_FALSE(map_entry3 == NULL); | 961 ASSERT_FALSE(map_entry3 == NULL); |
| 1041 EXPECT_FALSE(map_entry3->has_infobar_delegate()); | 962 EXPECT_FALSE(map_entry3->has_infobar_delegate()); |
| 1042 | 963 |
| 1043 SetNavigationPending(4, true); | 964 SetNavigationPending(4, true); |
| 1044 CommitSearch(4, GURL("http://www.google.co.uk/search?q=test4")); | 965 CommitSearch(4, GURL("https://www.google.co.uk/search?q=test4")); |
| 1045 GoogleURLTrackerInfoBarDelegate* delegate4 = GetInfoBarDelegate(4); | 966 GoogleURLTrackerInfoBarDelegate* delegate4 = GetInfoBarDelegate(4); |
| 1046 ASSERT_FALSE(delegate4 == NULL); | 967 ASSERT_FALSE(delegate4 == NULL); |
| 1047 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test4"), | 968 EXPECT_EQ(GURL("https://www.google.co.uk/search?q=test4"), |
| 1048 delegate4->search_url()); | 969 delegate4->search_url()); |
| 1049 | 970 |
| 1050 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 971 CommitSearch(1, GURL("https://www.google.co.uk/search?q=test")); |
| 1051 EXPECT_TRUE(map_entry->has_infobar_delegate()); | 972 EXPECT_TRUE(map_entry->has_infobar_delegate()); |
| 1052 | 973 |
| 1053 delegate2->Close(false); | 974 delegate2->Close(false); |
| 1054 EXPECT_TRUE(GetMapEntry(2) == NULL); | 975 EXPECT_TRUE(GetMapEntry(2) == NULL); |
| 1055 EXPECT_FALSE(observer_notified()); | 976 EXPECT_FALSE(observer_notified()); |
| 1056 | 977 |
| 1057 delegate4->Accept(); | 978 delegate4->Accept(); |
| 1058 EXPECT_TRUE(GetMapEntry(1) == NULL); | 979 EXPECT_TRUE(GetMapEntry(1) == NULL); |
| 1059 EXPECT_TRUE(GetMapEntry(3) == NULL); | 980 EXPECT_TRUE(GetMapEntry(3) == NULL); |
| 1060 EXPECT_TRUE(GetMapEntry(4) == NULL); | 981 EXPECT_TRUE(GetMapEntry(4) == NULL); |
| 1061 EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url()); | 982 EXPECT_EQ(GURL("https://www.google.co.jp/"), google_url()); |
| 1062 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); | 983 EXPECT_EQ(GURL("https://www.google.co.jp/"), GetLastPromptedGoogleURL()); |
| 1063 EXPECT_TRUE(observer_notified()); | 984 EXPECT_TRUE(observer_notified()); |
| 1064 } | 985 } |
| 1065 | 986 |
| 1066 TEST_F(GoogleURLTrackerTest, IgnoreIrrelevantNavigation) { | 987 TEST_F(GoogleURLTrackerTest, IgnoreIrrelevantNavigation) { |
| 1067 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 988 SetLastPromptedGoogleURL(GURL("https://www.google.co.uk/")); |
| 1068 RequestServerCheck(); | 989 RequestServerCheck(); |
| 1069 FinishSleep(); | 990 FinishSleep(); |
| 1070 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 991 MockSearchDomainCheckResponse(".google.co.jp"); |
| 1071 | 992 |
| 1072 // This tests a particularly gnarly sequence of events that used to cause us | 993 // This tests a particularly gnarly sequence of events that used to cause us |
| 1073 // to erroneously listen for a non-search navigation to commit. | 994 // to erroneously listen for a non-search navigation to commit. |
| 1074 SetNavigationPending(1, true); | 995 SetNavigationPending(1, true); |
| 1075 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 996 CommitSearch(1, GURL("https://www.google.co.uk/search?q=test")); |
| 1076 SetNavigationPending(2, true); | 997 SetNavigationPending(2, true); |
| 1077 CommitSearch(2, GURL("http://www.google.co.uk/search?q=test2")); | 998 CommitSearch(2, GURL("https://www.google.co.uk/search?q=test2")); |
| 1078 EXPECT_FALSE(GetInfoBarDelegate(1) == NULL); | 999 EXPECT_FALSE(GetInfoBarDelegate(1) == NULL); |
| 1079 GoogleURLTrackerInfoBarDelegate* delegate2 = GetInfoBarDelegate(2); | 1000 GoogleURLTrackerInfoBarDelegate* delegate2 = GetInfoBarDelegate(2); |
| 1080 ASSERT_FALSE(delegate2 == NULL); | 1001 ASSERT_FALSE(delegate2 == NULL); |
| 1081 SetNavigationPending(1, true); | 1002 SetNavigationPending(1, true); |
| 1082 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); | 1003 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); |
| 1083 delegate2->Close(false); | 1004 delegate2->Close(false); |
| 1084 SetNavigationPending(1, false); | 1005 SetNavigationPending(1, false); |
| 1085 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); | 1006 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); |
| 1086 } | 1007 } |
| OLD | NEW |