Index: chrome/browser/google/google_url_tracker_unittest.cc |
=================================================================== |
--- chrome/browser/google/google_url_tracker_unittest.cc (revision 65992) |
+++ chrome/browser/google/google_url_tracker_unittest.cc (working copy) |
@@ -8,7 +8,6 @@ |
#include "chrome/browser/profile.h" |
#include "chrome/browser/tab_contents/infobar_delegate.h" |
#include "chrome/common/net/url_fetcher.h" |
-#include "chrome/common/net/url_request_context_getter.h" |
#include "chrome/common/net/test_url_fetcher_factory.h" |
#include "chrome/common/notification_service.h" |
#include "chrome/common/pref_names.h" |
@@ -53,42 +52,60 @@ |
// TestInfoBarDelegate -------------------------------------------------------- |
-class TestInfoBarDelegate : public InfoBarDelegate { |
+class TestInfoBarDelegate : public GoogleURLTrackerInfoBarDelegate { |
public: |
- TestInfoBarDelegate(GoogleURLTracker* google_url_tracker, |
+ TestInfoBarDelegate(TabContents* tab_contents, |
+ const GURL& search_url, |
+ GoogleURLTracker* google_url_tracker, |
const GURL& new_google_url); |
- virtual ~TestInfoBarDelegate(); |
- // InfoBarDelegate |
- virtual InfoBar* CreateInfoBar(); |
+ // GoogleURLTrackerInfoBarDelegate |
+ virtual bool Accept(); // Overridden to avoid dereferencing |tab_contents_|. |
+ virtual void Show(); |
+ virtual void Close(bool redo_search); |
- 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: |
- GoogleURLTracker* google_url_tracker_; |
- GURL new_google_url_; |
+ virtual ~TestInfoBarDelegate(); |
}; |
-TestInfoBarDelegate::TestInfoBarDelegate(GoogleURLTracker* google_url_tracker, |
+TestInfoBarDelegate::TestInfoBarDelegate(TabContents* tab_contents, |
+ 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 |tab_contents_| here instead of in the superclass constructor so |
+ // that the base class will not try to dereference the bogus |tab_contents|. |
+ tab_contents_ = tab_contents; |
} |
-TestInfoBarDelegate::~TestInfoBarDelegate() { |
+bool TestInfoBarDelegate::Accept() { |
+ google_url_tracker_->AcceptGoogleURL(new_google_url_); |
+ return false; |
} |
-InfoBar* TestInfoBarDelegate::CreateInfoBar() { |
- return NULL; |
+void TestInfoBarDelegate::Show() { |
+ showing_ = true; |
} |
-InfoBarDelegate* CreateTestInfobar( |
+void TestInfoBarDelegate::Close(bool redo_search) { |
+ InfoBarClosed(); |
+} |
+ |
+TestInfoBarDelegate::~TestInfoBarDelegate() { |
+} |
+ |
+GoogleURLTrackerInfoBarDelegate* CreateTestInfobar( |
TabContents* tab_contents, |
+ 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(tab_contents, search_url, google_url_tracker, |
+ new_google_url); |
} |
} // namespace |
@@ -105,10 +122,8 @@ |
virtual void SetUp(); |
virtual void TearDown(); |
- void CreateRequestContext(); |
- 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(); |
@@ -116,13 +131,10 @@ |
void SetGoogleURL(const GURL& url); |
void SetLastPromptedGoogleURL(const GURL& url); |
GURL GetLastPromptedGoogleURL(); |
- void SearchCommitted(const GURL& search_url); |
- void NavEntryCommitted(); |
- bool InfoBarIsShown(); |
- GURL GetInfoBarShowingURL(); |
- 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_; |
@@ -135,23 +147,18 @@ |
TestURLFetcherFactory fetcher_factory_; |
NotificationRegistrar registrar_; |
- |
- URLRequestContextGetter* original_default_request_context_; |
}; |
GoogleURLTrackerTest::GoogleURLTrackerTest() |
: observer_(new TestNotificationObserver), |
message_loop_(NULL), |
- io_thread_(NULL), |
- original_default_request_context_(NULL) { |
+ io_thread_(NULL) { |
} |
GoogleURLTrackerTest::~GoogleURLTrackerTest() { |
} |
void GoogleURLTrackerTest::SetUp() { |
- original_default_request_context_ = Profile::GetDefaultRequestContext(); |
- Profile::set_default_request_context(NULL); |
message_loop_ = new MessageLoop(MessageLoop::TYPE_IO); |
io_thread_ = new BrowserThread(BrowserThread::IO, message_loop_); |
network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock()); |
@@ -164,6 +171,8 @@ |
tracker->queue_wakeup_task_ = false; |
MessageLoop::current()->RunAllPending(); |
testing_browser_process->SetGoogleURLTracker(tracker); |
+ testing_profile_->CreateRequestContext(); |
+ Profile::set_default_request_context(testing_profile_->GetRequestContext()); |
URLFetcher::set_factory(&fetcher_factory_); |
g_browser_process->google_url_tracker()->infobar_creator_ = |
@@ -180,28 +189,21 @@ |
network_change_notifier_.reset(); |
delete io_thread_; |
delete message_loop_; |
- Profile::set_default_request_context(original_default_request_context_); |
- original_default_request_context_ = NULL; |
} |
-void GoogleURLTrackerTest::CreateRequestContext() { |
- testing_profile_->CreateRequestContext(); |
- Profile::set_default_request_context(testing_profile_->GetRequestContext()); |
- NotificationService::current()->Notify( |
- NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE, |
- NotificationService::AllSources(), NotificationService::NoDetails()); |
+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( |
+ g_browser_process->google_url_tracker()->fetcher_id_ - 1); |
} |
-TestURLFetcher* GoogleURLTrackerTest::GetFetcherByID(int expected_id) { |
- return fetcher_factory_.GetFetcherByID(expected_id); |
-} |
- |
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->delegate()->OnURLFetchComplete(fetcher, |
GURL(GoogleURLTracker::kSearchDomainCheckURL), URLRequestStatus(), 200, |
ResponseCookies(), domain); |
@@ -248,57 +250,67 @@ |
prefs::kLastPromptedGoogleURL)); |
} |
-void GoogleURLTrackerTest::SearchCommitted(const GURL& search_url) { |
+void GoogleURLTrackerTest::SetSearchPending(const GURL& search_url, |
+ int unique_id) { |
GoogleURLTracker* google_url_tracker = |
g_browser_process->google_url_tracker(); |
google_url_tracker->SearchCommitted(); |
if (google_url_tracker->registrar_.IsRegistered(google_url_tracker, |
NotificationType::NAV_ENTRY_PENDING, |
- NotificationService::AllSources())) |
- google_url_tracker->search_url_ = search_url; |
+ NotificationService::AllSources())) { |
+ google_url_tracker->OnNavigationPending(Source<NavigationController>( |
+ reinterpret_cast<NavigationController*>(unique_id)), |
+ reinterpret_cast<TabContents*>(unique_id), search_url); |
+ } |
} |
-void GoogleURLTrackerTest::NavEntryCommitted() { |
+void GoogleURLTrackerTest::CommitSearch(int unique_id) { |
GoogleURLTracker* google_url_tracker = |
g_browser_process->google_url_tracker(); |
- google_url_tracker->ShowGoogleURLInfoBarIfNecessary(NULL); |
+ Source<NavigationController> source( |
+ reinterpret_cast<NavigationController*>(unique_id)); |
+ if (google_url_tracker->registrar_.IsRegistered(google_url_tracker, |
+ NotificationType::NAV_ENTRY_COMMITTED, source)) { |
+ google_url_tracker->OnNavigationCommittedOrTabClosed(source, |
+ reinterpret_cast<TabContents*>(unique_id), |
+ NotificationType::NAV_ENTRY_COMMITTED); |
+ } |
} |
-bool GoogleURLTrackerTest::InfoBarIsShown() { |
- return (g_browser_process->google_url_tracker()->infobar_ != NULL); |
+void GoogleURLTrackerTest::CloseTab(int unique_id) { |
+ GoogleURLTracker* google_url_tracker = |
+ g_browser_process->google_url_tracker(); |
+ Source<NavigationController> source( |
+ reinterpret_cast<NavigationController*>(unique_id)); |
+ TabContents* tab_contents = reinterpret_cast<TabContents*>(unique_id); |
+ if (google_url_tracker->registrar_.IsRegistered(google_url_tracker, |
+ NotificationType::TAB_CLOSED, source)) { |
+ google_url_tracker->OnNavigationCommittedOrTabClosed(source, tab_contents, |
+ NotificationType::TAB_CLOSED); |
+ } 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(tab_contents); |
+ if (i != google_url_tracker->infobars_.end()) { |
+ TestInfoBarDelegate* infobar = |
+ static_cast<TestInfoBarDelegate*>(i->second); |
+ DCHECK(infobar->showing()); |
+ infobar->InfoBarClosed(); |
+ } |
+ } |
} |
-GURL GoogleURLTrackerTest::GetInfoBarShowingURL() { |
- TestInfoBarDelegate* infobar = static_cast<TestInfoBarDelegate*>( |
- g_browser_process->google_url_tracker()->infobar_); |
- return infobar->new_google_url(); |
+TestInfoBarDelegate* GoogleURLTrackerTest::GetInfoBar(int unique_id) { |
+ const GoogleURLTracker::Infobars& infobars = |
+ g_browser_process->google_url_tracker()->infobars_; |
+ GoogleURLTracker::Infobars::const_iterator i = |
+ infobars.find(reinterpret_cast<TabContents*>(unique_id)); |
+ return (i == infobars.end()) ? |
+ NULL : static_cast<TestInfoBarDelegate*>(i->second); |
} |
-void GoogleURLTrackerTest::AcceptGoogleURL() { |
- TestInfoBarDelegate* infobar = static_cast<TestInfoBarDelegate*>( |
- g_browser_process->google_url_tracker()->infobar_); |
- ASSERT_TRUE(infobar); |
- ASSERT_TRUE(infobar->google_url_tracker()); |
- infobar->google_url_tracker()->AcceptGoogleURL(infobar->new_google_url()); |
-} |
- |
-void GoogleURLTrackerTest::CancelGoogleURL() { |
- TestInfoBarDelegate* infobar = static_cast<TestInfoBarDelegate*>( |
- g_browser_process->google_url_tracker()->infobar_); |
- ASSERT_TRUE(infobar); |
- ASSERT_TRUE(infobar->google_url_tracker()); |
- infobar->google_url_tracker()->CancelGoogleURL(infobar->new_google_url()); |
-} |
- |
-void GoogleURLTrackerTest::InfoBarClosed() { |
- TestInfoBarDelegate* infobar = static_cast<TestInfoBarDelegate*>( |
- g_browser_process->google_url_tracker()->infobar_); |
- ASSERT_TRUE(infobar); |
- ASSERT_TRUE(infobar->google_url_tracker()); |
- infobar->google_url_tracker()->InfoBarClosed(); |
- delete infobar; |
-} |
- |
void GoogleURLTrackerTest::ExpectDefaultURLs() { |
EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), |
GoogleURLTracker::GoogleURL()); |
@@ -309,24 +321,23 @@ |
// Tests ---------------------------------------------------------------------- |
TEST_F(GoogleURLTrackerTest, DontFetchWhenNoOneRequestsCheck) { |
- CreateRequestContext(); |
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) { |
- CreateRequestContext(); |
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/"), GetFetchedGoogleURL()); |
// GoogleURL should be updated, becase there was no last prompted URL. |
EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL()); |
@@ -334,16 +345,15 @@ |
} |
TEST_F(GoogleURLTrackerTest, DontUpdateWhenUnchanged) { |
- CreateRequestContext(); |
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/"), GetFetchedGoogleURL()); |
// GoogleURL should not be updated, because the fetched and prompted URLs |
// match. |
@@ -353,12 +363,11 @@ |
} |
TEST_F(GoogleURLTrackerTest, UpdatePromptedURLOnReturnToPreviousLocation) { |
- CreateRequestContext(); |
SetLastPromptedGoogleURL(GURL("http://www.google.co.jp/")); |
SetGoogleURL(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/"), GetFetchedGoogleURL()); |
EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL()); |
EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
@@ -366,17 +375,16 @@ |
} |
TEST_F(GoogleURLTrackerTest, RefetchOnIPAddressChange) { |
- CreateRequestContext(); |
RequestServerCheck(); |
FinishSleep(); |
- MockSearchDomainCheckResponse(0, ".google.co.uk"); |
+ MockSearchDomainCheckResponse(".google.co.uk"); |
EXPECT_EQ(GURL("http://www.google.co.uk/"), GetFetchedGoogleURL()); |
EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL()); |
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/"), GetFetchedGoogleURL()); |
// Just fetching a new URL shouldn't reset things without a prompt. |
EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL()); |
@@ -384,62 +392,136 @@ |
} |
TEST_F(GoogleURLTrackerTest, DontRefetchWhenNoOneRequestsCheck) { |
- CreateRequestContext(); |
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()); |
} |
TEST_F(GoogleURLTrackerTest, FetchOnLateRequest) { |
- CreateRequestContext(); |
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/"), GetFetchedGoogleURL()); |
EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL()); |
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/"), GetFetchedGoogleURL()); |
+ EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL()); |
+ 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/"), GetFetchedGoogleURL()); |
+ EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL()); |
+ EXPECT_FALSE(observer_->notified()); |
+} |
+ |
TEST_F(GoogleURLTrackerTest, SearchingDoesNothingIfNoNeedToPrompt) { |
- CreateRequestContext(); |
RequestServerCheck(); |
FinishSleep(); |
- MockSearchDomainCheckResponse(0, ".google.co.uk"); |
+ MockSearchDomainCheckResponse(".google.co.uk"); |
EXPECT_EQ(GURL("http://www.google.co.uk/"), GetFetchedGoogleURL()); |
EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL()); |
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(InfoBarIsShown()); |
+ 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/"), GetFetchedGoogleURL()); |
EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL()); |
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), |
+ GoogleURLTracker::GoogleURL()); |
+ EXPECT_EQ(GURL("http://www.google.co.jp/"), GetFetchedGoogleURL()); |
+ 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), |
+ GoogleURLTracker::GoogleURL()); |
+ 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), |
+ GoogleURLTracker::GoogleURL()); |
+ 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), |
+ GoogleURLTracker::GoogleURL()); |
+ EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
+ EXPECT_FALSE(observer_->notified()); |
+} |
+ |
TEST_F(GoogleURLTrackerTest, InfobarClosed) { |
- CreateRequestContext(); |
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(InfoBarIsShown()); |
+ SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); |
+ CommitSearch(1); |
+ TestInfoBarDelegate* infobar = GetInfoBar(1); |
+ ASSERT_FALSE(infobar == NULL); |
- InfoBarClosed(); |
- EXPECT_FALSE(InfoBarIsShown()); |
+ infobar->InfoBarClosed(); |
+ EXPECT_TRUE(GetInfoBar(1) == NULL); |
EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), |
GoogleURLTracker::GoogleURL()); |
EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
@@ -447,19 +529,18 @@ |
} |
TEST_F(GoogleURLTrackerTest, InfobarRefused) { |
- CreateRequestContext(); |
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(InfoBarIsShown()); |
+ 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(InfoBarIsShown()); |
+ infobar->Cancel(); |
+ EXPECT_TRUE(GetInfoBar(1) == NULL); |
EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), |
GoogleURLTracker::GoogleURL()); |
EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); |
@@ -467,20 +548,128 @@ |
} |
TEST_F(GoogleURLTrackerTest, InfobarAccepted) { |
- CreateRequestContext(); |
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(InfoBarIsShown()); |
+ 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(InfoBarIsShown()); |
+ infobar->Accept(); |
+ EXPECT_TRUE(GetInfoBar(1) == NULL); |
EXPECT_EQ(GURL("http://www.google.co.jp/"), GoogleURLTracker::GoogleURL()); |
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), |
+ GoogleURLTracker::GoogleURL()); |
+ 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), |
+ GoogleURLTracker::GoogleURL()); |
+ 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/"), GoogleURLTracker::GoogleURL()); |
+ EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); |
+ EXPECT_TRUE(observer_->notified()); |
+} |