| Index: chrome/browser/google/google_url_tracker_unittest.cc
|
| ===================================================================
|
| --- chrome/browser/google/google_url_tracker_unittest.cc (revision 132905)
|
| +++ chrome/browser/google/google_url_tracker_unittest.cc (working copy)
|
| @@ -50,42 +50,54 @@
|
|
|
| // TestInfoBarDelegate --------------------------------------------------------
|
|
|
| -class TestInfoBarDelegate : public InfoBarDelegate {
|
| +class TestInfoBarDelegate : public GoogleURLTrackerInfoBarDelegate {
|
| public:
|
| - TestInfoBarDelegate(GoogleURLTracker* google_url_tracker,
|
| + TestInfoBarDelegate(InfoBarTabHelper* infobar_helper,
|
| + const GURL& search_url,
|
| + GoogleURLTracker* google_url_tracker,
|
| const GURL& new_google_url);
|
| virtual ~TestInfoBarDelegate();
|
|
|
| - GoogleURLTracker* google_url_tracker() const { return google_url_tracker_; }
|
| + GURL search_url() const { return search_url_; }
|
| GURL new_google_url() const { return new_google_url_; }
|
| + bool showing() const { return showing_; }
|
|
|
| private:
|
| - // InfoBarDelegate:
|
| - virtual InfoBar* CreateInfoBar(InfoBarTabHelper* infobar_helper) OVERRIDE;
|
| -
|
| - GoogleURLTracker* google_url_tracker_;
|
| - GURL new_google_url_;
|
| + // GoogleURLTrackerInfoBarDelegate:
|
| + virtual void Show() OVERRIDE;
|
| + virtual void Close(bool redo_search) OVERRIDE;
|
| };
|
|
|
| -TestInfoBarDelegate::TestInfoBarDelegate(GoogleURLTracker* google_url_tracker,
|
| +TestInfoBarDelegate::TestInfoBarDelegate(InfoBarTabHelper* infobar_helper,
|
| + const GURL& search_url,
|
| + GoogleURLTracker* google_url_tracker,
|
| const GURL& new_google_url)
|
| - : InfoBarDelegate(NULL),
|
| - google_url_tracker_(google_url_tracker),
|
| - new_google_url_(new_google_url) {
|
| + : GoogleURLTrackerInfoBarDelegate(NULL, search_url, google_url_tracker,
|
| + new_google_url) {
|
| + // We set |map_key_| here instead of in the superclass constructor so that the
|
| + // InfoBarDelegate base class will not try to dereference it, which would fail
|
| + // since this is really a magic number and not an actual pointer.
|
| + map_key_ = infobar_helper;
|
| }
|
|
|
| -TestInfoBarDelegate::~TestInfoBarDelegate() {
|
| +void TestInfoBarDelegate::Show() {
|
| + showing_ = true;
|
| }
|
|
|
| -InfoBar* TestInfoBarDelegate::CreateInfoBar(InfoBarTabHelper* infobar_helper) {
|
| - return NULL;
|
| +void TestInfoBarDelegate::Close(bool redo_search) {
|
| + InfoBarClosed();
|
| }
|
|
|
| -InfoBarDelegate* CreateTestInfobar(
|
| +TestInfoBarDelegate::~TestInfoBarDelegate() {
|
| +}
|
| +
|
| +GoogleURLTrackerInfoBarDelegate* CreateTestInfobar(
|
| InfoBarTabHelper* infobar_helper,
|
| + const GURL& search_url,
|
| GoogleURLTracker* google_url_tracker,
|
| const GURL& new_google_url) {
|
| - return new TestInfoBarDelegate(google_url_tracker, new_google_url);
|
| + return new TestInfoBarDelegate(infobar_helper, search_url, google_url_tracker,
|
| + new_google_url);
|
| }
|
|
|
| } // namespace
|
| @@ -102,9 +114,8 @@
|
| virtual void SetUp();
|
| virtual void TearDown();
|
|
|
| - TestURLFetcher* GetFetcherByID(int expected_id);
|
| - void MockSearchDomainCheckResponse(int expected_id,
|
| - const std::string& domain);
|
| + TestURLFetcher* GetFetcher();
|
| + void MockSearchDomainCheckResponse(const std::string& domain);
|
| void RequestServerCheck();
|
| void FinishSleep();
|
| void NotifyIPAddressChanged();
|
| @@ -117,18 +128,10 @@
|
| GURL google_url() const { return google_url_tracker_->google_url_; }
|
| void SetLastPromptedGoogleURL(const GURL& url);
|
| GURL GetLastPromptedGoogleURL();
|
| - void SearchCommitted(const GURL& search_url);
|
| - void NavEntryCommitted();
|
| - bool infobar_showing() const {
|
| - return (google_url_tracker_->infobar_ != NULL);
|
| - }
|
| - GURL infobar_url() const {
|
| - return static_cast<TestInfoBarDelegate*>(google_url_tracker_->infobar_)->
|
| - new_google_url();
|
| - }
|
| - void AcceptGoogleURL();
|
| - void CancelGoogleURL();
|
| - void InfoBarClosed();
|
| + void SetSearchPending(const GURL& search_url, int unique_id);
|
| + void CommitSearch(int unique_id);
|
| + void CloseTab(int unique_id);
|
| + TestInfoBarDelegate* GetInfoBar(int unique_id);
|
| void ExpectDefaultURLs();
|
|
|
| scoped_ptr<TestNotificationObserver> observer_;
|
| @@ -169,16 +172,18 @@
|
| network_change_notifier_.reset();
|
| }
|
|
|
| -TestURLFetcher* GoogleURLTrackerTest::GetFetcherByID(int expected_id) {
|
| - return fetcher_factory_.GetFetcherByID(expected_id);
|
| +TestURLFetcher* GoogleURLTrackerTest::GetFetcher() {
|
| + // This will return the last fetcher created. If no fetchers have been
|
| + // created, we'll pass GetFetcherByID() "-1", and it will return NULL.
|
| + return fetcher_factory_.GetFetcherByID(google_url_tracker_->fetcher_id_ - 1);
|
| }
|
|
|
| void GoogleURLTrackerTest::MockSearchDomainCheckResponse(
|
| - int expected_id,
|
| const std::string& domain) {
|
| - TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(expected_id);
|
| + TestURLFetcher* fetcher = GetFetcher();
|
| if (!fetcher)
|
| return;
|
| + fetcher_factory_.RemoveFetcherFromMap(fetcher->id());
|
| fetcher->set_url(GURL(GoogleURLTracker::kSearchDomainCheckURL));
|
| fetcher->set_response_code(200);
|
| fetcher->SetResponseString(domain);
|
| @@ -217,46 +222,68 @@
|
| prefs::kLastPromptedGoogleURL));
|
| }
|
|
|
| -void GoogleURLTrackerTest::SearchCommitted(const GURL& search_url) {
|
| +void GoogleURLTrackerTest::SetSearchPending(const GURL& search_url,
|
| + int unique_id) {
|
| google_url_tracker_->SearchCommitted();
|
| if (google_url_tracker_->registrar_.IsRegistered(google_url_tracker_.get(),
|
| content::NOTIFICATION_NAV_ENTRY_PENDING,
|
| - content::NotificationService::AllBrowserContextsAndSources()))
|
| - google_url_tracker_->search_url_ = search_url;
|
| + content::NotificationService::AllBrowserContextsAndSources())) {
|
| + google_url_tracker_->OnNavigationPending(
|
| + content::Source<content::NavigationController>(
|
| + reinterpret_cast<content::NavigationController*>(unique_id)),
|
| + content::Source<content::WebContents>(
|
| + reinterpret_cast<content::WebContents*>(unique_id)),
|
| + reinterpret_cast<InfoBarTabHelper*>(unique_id), search_url);
|
| + }
|
| }
|
|
|
| -void GoogleURLTrackerTest::NavEntryCommitted() {
|
| - google_url_tracker_->ShowGoogleURLInfoBarIfNecessary(NULL);
|
| +void GoogleURLTrackerTest::CommitSearch(int unique_id) {
|
| + content::Source<content::NavigationController> source(
|
| + reinterpret_cast<content::NavigationController*>(unique_id));
|
| + if (google_url_tracker_->registrar_.IsRegistered(google_url_tracker_.get(),
|
| + content::NOTIFICATION_NAV_ENTRY_COMMITTED, source)) {
|
| + google_url_tracker_->OnNavigationCommittedOrTabClosed(source,
|
| + content::Source<content::WebContents>(
|
| + reinterpret_cast<content::WebContents*>(unique_id)),
|
| + reinterpret_cast<InfoBarTabHelper*>(unique_id),
|
| + content::NOTIFICATION_NAV_ENTRY_COMMITTED);
|
| + }
|
| }
|
|
|
| -void GoogleURLTrackerTest::AcceptGoogleURL() {
|
| - TestInfoBarDelegate* infobar =
|
| - static_cast<TestInfoBarDelegate*>(google_url_tracker_->infobar_);
|
| - ASSERT_TRUE(infobar);
|
| - ASSERT_TRUE(infobar->google_url_tracker());
|
| - ASSERT_EQ(google_url_tracker_, infobar->google_url_tracker());
|
| - google_url_tracker_->AcceptGoogleURL(infobar->new_google_url());
|
| +void GoogleURLTrackerTest::CloseTab(int unique_id) {
|
| + content::Source<content::WebContents> source(
|
| + reinterpret_cast<content::WebContents*>(unique_id));
|
| + InfoBarTabHelper* infobar_helper =
|
| + reinterpret_cast<InfoBarTabHelper*>(unique_id);
|
| + if (google_url_tracker_->registrar_.IsRegistered(google_url_tracker_.get(),
|
| + content::NOTIFICATION_WEB_CONTENTS_DESTROYED, source)) {
|
| + google_url_tracker_->OnNavigationCommittedOrTabClosed(
|
| + content::Source<content::NavigationController>(
|
| + reinterpret_cast<content::NavigationController*>(unique_id)),
|
| + source, infobar_helper, content::NOTIFICATION_WEB_CONTENTS_DESTROYED);
|
| + } else {
|
| + // Normally, closing a tab with an infobar showing will close the infobar.
|
| + // Since we don't have real tabs and are just faking things with magic
|
| + // numbers, we have to manually close the infobar, if any.
|
| + GoogleURLTracker::InfoBars::iterator i =
|
| + google_url_tracker_->infobars_.find(infobar_helper);
|
| + if (i != google_url_tracker_->infobars_.end()) {
|
| + TestInfoBarDelegate* infobar =
|
| + static_cast<TestInfoBarDelegate*>(i->second);
|
| + DCHECK(infobar->showing());
|
| + infobar->InfoBarClosed();
|
| + }
|
| + }
|
| }
|
|
|
| -void GoogleURLTrackerTest::CancelGoogleURL() {
|
| - TestInfoBarDelegate* infobar =
|
| - static_cast<TestInfoBarDelegate*>(google_url_tracker_->infobar_);
|
| - ASSERT_TRUE(infobar);
|
| - ASSERT_TRUE(infobar->google_url_tracker());
|
| - ASSERT_EQ(google_url_tracker_, infobar->google_url_tracker());
|
| - google_url_tracker_->CancelGoogleURL(infobar->new_google_url());
|
| +TestInfoBarDelegate* GoogleURLTrackerTest::GetInfoBar(int unique_id) {
|
| + const GoogleURLTracker::InfoBars& infobars = google_url_tracker_->infobars_;
|
| + GoogleURLTracker::InfoBars::const_iterator i =
|
| + infobars.find(reinterpret_cast<InfoBarTabHelper*>(unique_id));
|
| + return (i == infobars.end()) ?
|
| + NULL : static_cast<TestInfoBarDelegate*>(i->second);
|
| }
|
|
|
| -void GoogleURLTrackerTest::InfoBarClosed() {
|
| - TestInfoBarDelegate* infobar =
|
| - static_cast<TestInfoBarDelegate*>(google_url_tracker_->infobar_);
|
| - ASSERT_TRUE(infobar);
|
| - ASSERT_TRUE(infobar->google_url_tracker());
|
| - ASSERT_EQ(google_url_tracker_, infobar->google_url_tracker());
|
| - google_url_tracker_->InfoBarClosed();
|
| - delete infobar;
|
| -}
|
| -
|
| void GoogleURLTrackerTest::ExpectDefaultURLs() {
|
| EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
|
| EXPECT_EQ(GURL(), fetched_google_url());
|
| @@ -269,19 +296,20 @@
|
| ExpectDefaultURLs();
|
| FinishSleep();
|
| // No one called RequestServerCheck() so nothing should have happened.
|
| - EXPECT_FALSE(GetFetcherByID(0));
|
| + EXPECT_FALSE(GetFetcher());
|
| + MockSearchDomainCheckResponse(".google.co.uk");
|
| ExpectDefaultURLs();
|
| EXPECT_FALSE(observer_->notified());
|
| }
|
|
|
| TEST_F(GoogleURLTrackerTest, UpdateOnFirstRun) {
|
| RequestServerCheck();
|
| - EXPECT_FALSE(GetFetcherByID(0));
|
| + EXPECT_FALSE(GetFetcher());
|
| ExpectDefaultURLs();
|
| EXPECT_FALSE(observer_->notified());
|
|
|
| FinishSleep();
|
| - MockSearchDomainCheckResponse(0, ".google.co.uk");
|
| + MockSearchDomainCheckResponse(".google.co.uk");
|
| EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url());
|
| // GoogleURL should be updated, becase there was no last prompted URL.
|
| EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url());
|
| @@ -292,12 +320,12 @@
|
| SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
|
|
|
| RequestServerCheck();
|
| - EXPECT_FALSE(GetFetcherByID(0));
|
| + EXPECT_FALSE(GetFetcher());
|
| ExpectDefaultURLs();
|
| EXPECT_FALSE(observer_->notified());
|
|
|
| FinishSleep();
|
| - MockSearchDomainCheckResponse(0, ".google.co.uk");
|
| + MockSearchDomainCheckResponse(".google.co.uk");
|
| EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url());
|
| // GoogleURL should not be updated, because the fetched and prompted URLs
|
| // match.
|
| @@ -310,7 +338,7 @@
|
| set_google_url(GURL("http://www.google.co.uk/"));
|
| RequestServerCheck();
|
| FinishSleep();
|
| - MockSearchDomainCheckResponse(0, ".google.co.uk");
|
| + MockSearchDomainCheckResponse(".google.co.uk");
|
| EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url());
|
| EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url());
|
| EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
|
| @@ -320,14 +348,14 @@
|
| TEST_F(GoogleURLTrackerTest, RefetchOnIPAddressChange) {
|
| RequestServerCheck();
|
| FinishSleep();
|
| - MockSearchDomainCheckResponse(0, ".google.co.uk");
|
| + MockSearchDomainCheckResponse(".google.co.uk");
|
| EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url());
|
| EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url());
|
| EXPECT_TRUE(observer_->notified());
|
| observer_->clear_notified();
|
|
|
| NotifyIPAddressChanged();
|
| - MockSearchDomainCheckResponse(1, ".google.co.in");
|
| + MockSearchDomainCheckResponse(".google.co.in");
|
| EXPECT_EQ(GURL("http://www.google.co.in/"), fetched_google_url());
|
| // Just fetching a new URL shouldn't reset things without a prompt.
|
| EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url());
|
| @@ -338,7 +366,8 @@
|
| FinishSleep();
|
| NotifyIPAddressChanged();
|
| // No one called RequestServerCheck() so nothing should have happened.
|
| - EXPECT_FALSE(GetFetcherByID(0));
|
| + EXPECT_FALSE(GetFetcher());
|
| + MockSearchDomainCheckResponse(".google.co.uk");
|
| ExpectDefaultURLs();
|
| EXPECT_FALSE(observer_->notified());
|
| }
|
| @@ -346,47 +375,120 @@
|
| TEST_F(GoogleURLTrackerTest, FetchOnLateRequest) {
|
| FinishSleep();
|
| NotifyIPAddressChanged();
|
| + MockSearchDomainCheckResponse(".google.co.jp");
|
|
|
| RequestServerCheck();
|
| // The first request for a check should trigger a fetch if it hasn't happened
|
| // already.
|
| - MockSearchDomainCheckResponse(0, ".google.co.uk");
|
| + MockSearchDomainCheckResponse(".google.co.uk");
|
| EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url());
|
| EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url());
|
| EXPECT_TRUE(observer_->notified());
|
| }
|
|
|
| +TEST_F(GoogleURLTrackerTest, DontFetchTwiceOnLateRequests) {
|
| + FinishSleep();
|
| + NotifyIPAddressChanged();
|
| + MockSearchDomainCheckResponse(".google.co.jp");
|
| +
|
| + RequestServerCheck();
|
| + // The first request for a check should trigger a fetch if it hasn't happened
|
| + // already.
|
| + MockSearchDomainCheckResponse(".google.co.uk");
|
| + EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url());
|
| + EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url());
|
| + EXPECT_TRUE(observer_->notified());
|
| + observer_->clear_notified();
|
| +
|
| + RequestServerCheck();
|
| + // The second request should be ignored.
|
| + EXPECT_FALSE(GetFetcher());
|
| + MockSearchDomainCheckResponse(".google.co.in");
|
| + EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url());
|
| + EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url());
|
| + EXPECT_FALSE(observer_->notified());
|
| +}
|
| +
|
| TEST_F(GoogleURLTrackerTest, SearchingDoesNothingIfNoNeedToPrompt) {
|
| RequestServerCheck();
|
| FinishSleep();
|
| - MockSearchDomainCheckResponse(0, ".google.co.uk");
|
| + MockSearchDomainCheckResponse(".google.co.uk");
|
| EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url());
|
| EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url());
|
| EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
|
| EXPECT_TRUE(observer_->notified());
|
| observer_->clear_notified();
|
|
|
| - SearchCommitted(GURL("http://www.google.co.uk/search?q=test"));
|
| - NavEntryCommitted();
|
| - EXPECT_FALSE(infobar_showing());
|
| + SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1);
|
| + CommitSearch(1);
|
| + TestInfoBarDelegate* infobar = GetInfoBar(1);
|
| + ASSERT_TRUE(infobar == NULL);
|
| EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url());
|
| EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url());
|
| EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
|
| EXPECT_FALSE(observer_->notified());
|
| }
|
|
|
| +TEST_F(GoogleURLTrackerTest, TabClosedOnPendingSearch) {
|
| + SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
|
| + RequestServerCheck();
|
| + FinishSleep();
|
| + MockSearchDomainCheckResponse(".google.co.jp");
|
| + EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
|
| + EXPECT_EQ(GURL("http://www.google.co.jp/"), fetched_google_url());
|
| + EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
|
| + EXPECT_FALSE(observer_->notified());
|
| +
|
| + SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1);
|
| + TestInfoBarDelegate* infobar = GetInfoBar(1);
|
| + ASSERT_FALSE(infobar == NULL);
|
| + EXPECT_FALSE(infobar->showing());
|
| + EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
|
| + EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test"),
|
| + infobar->search_url());
|
| + EXPECT_EQ(GURL("http://www.google.co.jp/"), infobar->new_google_url());
|
| + EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
|
| + EXPECT_FALSE(observer_->notified());
|
| +
|
| + CloseTab(1);
|
| + EXPECT_TRUE(GetInfoBar(1) == NULL);
|
| + EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
|
| + EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
|
| + EXPECT_FALSE(observer_->notified());
|
| +}
|
| +
|
| +TEST_F(GoogleURLTrackerTest, TabClosedOnCommittedSearch) {
|
| + SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
|
| + RequestServerCheck();
|
| + FinishSleep();
|
| + MockSearchDomainCheckResponse(".google.co.jp");
|
| +
|
| + SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1);
|
| + CommitSearch(1);
|
| + TestInfoBarDelegate* infobar = GetInfoBar(1);
|
| + ASSERT_FALSE(infobar == NULL);
|
| + EXPECT_TRUE(infobar->showing());
|
| +
|
| + CloseTab(1);
|
| + EXPECT_TRUE(GetInfoBar(1) == NULL);
|
| + EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
|
| + EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
|
| + EXPECT_FALSE(observer_->notified());
|
| +}
|
| +
|
| TEST_F(GoogleURLTrackerTest, InfobarClosed) {
|
| SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
|
| RequestServerCheck();
|
| FinishSleep();
|
| - MockSearchDomainCheckResponse(0, ".google.co.jp");
|
| + MockSearchDomainCheckResponse(".google.co.jp");
|
|
|
| - SearchCommitted(GURL("http://www.google.co.uk/search?q=test"));
|
| - NavEntryCommitted();
|
| - EXPECT_TRUE(infobar_showing());
|
| + SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1);
|
| + CommitSearch(1);
|
| + TestInfoBarDelegate* infobar = GetInfoBar(1);
|
| + ASSERT_FALSE(infobar == NULL);
|
|
|
| - InfoBarClosed();
|
| - EXPECT_FALSE(infobar_showing());
|
| + infobar->InfoBarClosed();
|
| + EXPECT_TRUE(GetInfoBar(1) == NULL);
|
| EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
|
| EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
|
| EXPECT_FALSE(observer_->notified());
|
| @@ -396,15 +498,15 @@
|
| SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
|
| RequestServerCheck();
|
| FinishSleep();
|
| - MockSearchDomainCheckResponse(0, ".google.co.jp");
|
| + MockSearchDomainCheckResponse(".google.co.jp");
|
|
|
| - SearchCommitted(GURL("http://www.google.co.uk/search?q=test"));
|
| - NavEntryCommitted();
|
| - EXPECT_TRUE(infobar_showing());
|
| + SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1);
|
| + CommitSearch(1);
|
| + TestInfoBarDelegate* infobar = GetInfoBar(1);
|
| + ASSERT_FALSE(infobar == NULL);
|
|
|
| - CancelGoogleURL();
|
| - InfoBarClosed();
|
| - EXPECT_FALSE(infobar_showing());
|
| + infobar->Cancel();
|
| + EXPECT_TRUE(GetInfoBar(1) == NULL);
|
| EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
|
| EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL());
|
| EXPECT_FALSE(observer_->notified());
|
| @@ -414,16 +516,123 @@
|
| SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
|
| RequestServerCheck();
|
| FinishSleep();
|
| - MockSearchDomainCheckResponse(0, ".google.co.jp");
|
| + MockSearchDomainCheckResponse(".google.co.jp");
|
|
|
| - SearchCommitted(GURL("http://www.google.co.uk/search?q=test"));
|
| - NavEntryCommitted();
|
| - EXPECT_TRUE(infobar_showing());
|
| + SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1);
|
| + CommitSearch(1);
|
| + TestInfoBarDelegate* infobar = GetInfoBar(1);
|
| + ASSERT_FALSE(infobar == NULL);
|
|
|
| - AcceptGoogleURL();
|
| - InfoBarClosed();
|
| - EXPECT_FALSE(infobar_showing());
|
| + infobar->Accept();
|
| + EXPECT_TRUE(GetInfoBar(1) == NULL);
|
| EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url());
|
| EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL());
|
| EXPECT_TRUE(observer_->notified());
|
| }
|
| +
|
| +TEST_F(GoogleURLTrackerTest, InfobarShownAgainOnSearchAfterPendingSearch) {
|
| + SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
|
| + RequestServerCheck();
|
| + FinishSleep();
|
| + MockSearchDomainCheckResponse(".google.co.jp");
|
| +
|
| + SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1);
|
| + TestInfoBarDelegate* infobar = GetInfoBar(1);
|
| + ASSERT_FALSE(infobar == NULL);
|
| + EXPECT_FALSE(infobar->showing());
|
| + EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test"),
|
| + infobar->search_url());
|
| +
|
| + SetSearchPending(GURL("http://www.google.co.uk/search?q=test2"), 1);
|
| + TestInfoBarDelegate* infobar2 = GetInfoBar(1);
|
| + ASSERT_FALSE(infobar2 == NULL);
|
| + EXPECT_FALSE(infobar2->showing());
|
| + EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test2"),
|
| + infobar2->search_url());
|
| +
|
| + CommitSearch(1);
|
| + EXPECT_TRUE(infobar2->showing());
|
| + EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
|
| + EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
|
| + EXPECT_FALSE(observer_->notified());
|
| +
|
| + CloseTab(1);
|
| +}
|
| +
|
| +TEST_F(GoogleURLTrackerTest, InfobarShownAgainOnSearchAfterCommittedSearch) {
|
| + SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
|
| + RequestServerCheck();
|
| + FinishSleep();
|
| + MockSearchDomainCheckResponse(".google.co.jp");
|
| +
|
| + SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1);
|
| + CommitSearch(1);
|
| + TestInfoBarDelegate* infobar = GetInfoBar(1);
|
| + ASSERT_FALSE(infobar == NULL);
|
| + EXPECT_TRUE(infobar->showing());
|
| +
|
| + SetSearchPending(GURL("http://www.google.co.uk/search?q=test2"), 1);
|
| + TestInfoBarDelegate* infobar2 = GetInfoBar(1);
|
| + ASSERT_FALSE(infobar2 == NULL);
|
| + EXPECT_FALSE(infobar2->showing());
|
| +
|
| + CommitSearch(1);
|
| + EXPECT_TRUE(infobar2->showing());
|
| + EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
|
| + EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
|
| + EXPECT_FALSE(observer_->notified());
|
| +
|
| + CloseTab(1);
|
| +}
|
| +
|
| +TEST_F(GoogleURLTrackerTest, MultipleInfobars) {
|
| + SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
|
| + RequestServerCheck();
|
| + FinishSleep();
|
| + MockSearchDomainCheckResponse(".google.co.jp");
|
| +
|
| + SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1);
|
| + TestInfoBarDelegate* infobar = GetInfoBar(1);
|
| + ASSERT_FALSE(infobar == NULL);
|
| + EXPECT_FALSE(infobar->showing());
|
| + EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test"),
|
| + infobar->search_url());
|
| +
|
| + SetSearchPending(GURL("http://www.google.co.uk/search?q=test2"), 2);
|
| + CommitSearch(2);
|
| + TestInfoBarDelegate* infobar2 = GetInfoBar(2);
|
| + ASSERT_FALSE(infobar2 == NULL);
|
| + EXPECT_TRUE(infobar2->showing());
|
| + EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test2"),
|
| + infobar2->search_url());
|
| +
|
| + SetSearchPending(GURL("http://www.google.co.uk/search?q=test3"), 3);
|
| + TestInfoBarDelegate* infobar3 = GetInfoBar(3);
|
| + ASSERT_FALSE(infobar3 == NULL);
|
| + EXPECT_FALSE(infobar3->showing());
|
| + EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test3"),
|
| + infobar3->search_url());
|
| +
|
| + SetSearchPending(GURL("http://www.google.co.uk/search?q=test4"), 4);
|
| + CommitSearch(4);
|
| + TestInfoBarDelegate* infobar4 = GetInfoBar(4);
|
| + ASSERT_FALSE(infobar4 == NULL);
|
| + EXPECT_TRUE(infobar4->showing());
|
| + EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test4"),
|
| + infobar4->search_url());
|
| +
|
| + CommitSearch(1);
|
| + EXPECT_TRUE(infobar->showing());
|
| +
|
| + infobar2->InfoBarClosed();
|
| + EXPECT_TRUE(GetInfoBar(2) == NULL);
|
| + EXPECT_FALSE(observer_->notified());
|
| +
|
| + infobar4->Accept();
|
| + EXPECT_TRUE(GetInfoBar(1) == NULL);
|
| + EXPECT_TRUE(GetInfoBar(3) == NULL);
|
| + EXPECT_TRUE(GetInfoBar(4) == NULL);
|
| + EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url());
|
| + EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL());
|
| + EXPECT_TRUE(observer_->notified());
|
| +}
|
|
|