Index: chrome/browser/google/google_url_tracker_unittest.cc |
diff --git a/chrome/browser/google/google_url_tracker_unittest.cc b/chrome/browser/google/google_url_tracker_unittest.cc |
index 81f9e82d35bc8b1358e8e0ec72bf5f6daff3ad30..6f29909bbb195ab99b97ec27bbbf97f61d5223c7 100644 |
--- a/chrome/browser/google/google_url_tracker_unittest.cc |
+++ b/chrome/browser/google/google_url_tracker_unittest.cc |
@@ -1,4 +1,4 @@ |
-// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Copyright 2012 The Chromium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
@@ -7,9 +7,9 @@ |
#include <set> |
#include <string> |
+#include "base/memory/scoped_ptr.h" |
#include "base/message_loop/message_loop.h" |
#include "base/prefs/pref_service.h" |
-#include "chrome/browser/chrome_notification_types.h" |
#include "chrome/browser/google/google_url_tracker_factory.h" |
#include "chrome/browser/google/google_url_tracker_infobar_delegate.h" |
#include "chrome/browser/google/google_url_tracker_navigation_helper.h" |
@@ -18,53 +18,13 @@ |
#include "components/google/core/browser/google_url_tracker_client.h" |
#include "components/infobars/core/infobar.h" |
#include "components/infobars/core/infobar_delegate.h" |
-#include "content/public/browser/notification_service.h" |
#include "content/public/test/test_browser_thread_bundle.h" |
#include "net/url_request/test_url_fetcher_factory.h" |
#include "net/url_request/url_fetcher.h" |
#include "testing/gtest/include/gtest/gtest.h" |
-class GoogleURLTrackerTest; |
- |
namespace { |
-// TestInfoBarDelegate -------------------------------------------------------- |
- |
-class TestInfoBarDelegate : public GoogleURLTrackerInfoBarDelegate { |
- public: |
- // Creates a test infobar and delegate and returns the infobar. Unlike the |
- // parent class, this does not add the infobar to |infobar_manager|, since |
- // that "pointer" is really just a magic number. Thus there is no |
- // InfoBarManager ownership of the returned object; and since the caller |
- // doesn't own the returned object, we rely on |test_harness| cleaning this |
- // up eventually in GoogleURLTrackerTest::OnInfoBarClosed() to avoid leaks. |
- static infobars::InfoBar* Create( |
- GoogleURLTrackerTest* test_harness, |
- infobars::InfoBarManager* infobar_manager, |
- GoogleURLTracker* google_url_tracker, |
- const GURL& search_url); |
- |
- private: |
- TestInfoBarDelegate(GoogleURLTrackerTest* test_harness, |
- infobars::InfoBarManager* infobar_manager, |
- GoogleURLTracker* google_url_tracker, |
- const GURL& search_url); |
- virtual ~TestInfoBarDelegate(); |
- |
- // GoogleURLTrackerInfoBarDelegate: |
- virtual void Update(const GURL& search_url) OVERRIDE; |
- virtual void Close(bool redo_search) OVERRIDE; |
- |
- GoogleURLTrackerTest* test_harness_; |
- infobars::InfoBarManager* infobar_manager_; |
- |
- DISALLOW_COPY_AND_ASSIGN(TestInfoBarDelegate); |
-}; |
- |
-// The member function definitions come after the declaration of |
-// GoogleURLTrackerTest, so they can call members on it. |
- |
- |
// TestCallbackListener --------------------------------------------------- |
class TestCallbackListener { |
@@ -201,33 +161,35 @@ void TestGoogleURLTrackerNavigationHelper::OpenURL( |
bool user_clicked_on_link) { |
} |
-} // namespace |
+// TestInfoBarManager --------------------------------------------------------- |
+ |
+class TestInfoBarManager : public infobars::InfoBarManager { |
+ public: |
+ explicit TestInfoBarManager(int unique_id); |
+ virtual ~TestInfoBarManager(); |
+ virtual int GetActiveEntryID() OVERRIDE; |
+ |
+ private: |
+ int unique_id_; |
+ DISALLOW_COPY_AND_ASSIGN(TestInfoBarManager); |
+}; |
+TestInfoBarManager::TestInfoBarManager(int unique_id) : unique_id_(unique_id) { |
+} |
+ |
+TestInfoBarManager::~TestInfoBarManager() { |
+ ShutDown(); |
+} |
+ |
+int TestInfoBarManager::GetActiveEntryID() { |
+ return unique_id_; |
+} |
+ |
+} // namespace |
// GoogleURLTrackerTest ------------------------------------------------------- |
-// Ths class exercises GoogleURLTracker. In order to avoid instantiating more |
-// of the Chrome infrastructure than necessary, the GoogleURLTracker functions |
-// are carefully written so that many of the functions which take |
-// NavigationController* or infobars::InfoBarManager* do not actually |
-// dereference the |
-// objects, merely use them for comparisons and lookups, e.g. in |entry_map_|. |
-// This then allows the test code here to not create any of these objects, and |
-// instead supply "pointers" that are actually reinterpret_cast<>()ed magic |
-// numbers. Then we write the necessary stubs/hooks, here and in |
-// TestInfoBarDelegate above, to make everything continue to work. |
-// |
-// Technically, the C++98 spec defines the result of casting |
-// T* -> intptr_t -> T* to be an identity, but intptr_t -> T* -> intptr_t (what |
-// we use here) is "implementation-defined". Since I've never seen a compiler |
-// break this, though, and the result would simply be a failing test rather than |
-// a bug in Chrome, we'll use it anyway. |
class GoogleURLTrackerTest : public testing::Test { |
- public: |
- // Called by TestInfoBarDelegate::Close(). |
- void OnInfoBarClosed(scoped_ptr<infobars::InfoBar> infobar, |
- infobars::InfoBarManager* infobar_manager); |
- |
protected: |
GoogleURLTrackerTest(); |
virtual ~GoogleURLTrackerTest(); |
@@ -250,31 +212,29 @@ class GoogleURLTrackerTest : public testing::Test { |
GURL google_url() const { return google_url_tracker_->google_url(); } |
void SetLastPromptedGoogleURL(const GURL& url); |
GURL GetLastPromptedGoogleURL(); |
- void SetNavigationPending(intptr_t unique_id, bool is_search); |
- void CommitNonSearch(intptr_t unique_id); |
- void CommitSearch(intptr_t unique_id, const GURL& search_url); |
- void CloseTab(intptr_t unique_id); |
- GoogleURLTrackerMapEntry* GetMapEntry(intptr_t unique_id); |
- GoogleURLTrackerInfoBarDelegate* GetInfoBarDelegate(intptr_t unique_id); |
- GoogleURLTrackerNavigationHelper* GetNavigationHelper(intptr_t unique_id); |
+ void SetNavigationPending(infobars::InfoBarManager* infobar_manager, |
+ bool is_search); |
+ void CommitNonSearch(infobars::InfoBarManager* infobar_manager); |
+ void CommitSearch(infobars::InfoBarManager* infobar_manager, |
+ const GURL& search_url); |
+ void CloseTab(infobars::InfoBarManager* infobar_manager); |
+ GoogleURLTrackerMapEntry* GetMapEntry( |
+ infobars::InfoBarManager* infobar_manager); |
+ GoogleURLTrackerInfoBarDelegate* GetInfoBarDelegate( |
+ infobars::InfoBarManager* infobar_manager); |
+ GoogleURLTrackerNavigationHelper* GetNavigationHelper( |
+ infobars::InfoBarManager* infobar_manager); |
void ExpectDefaultURLs() const; |
- void ExpectListeningForCommit(intptr_t unique_id, bool listening); |
+ void ExpectListeningForCommit(infobars::InfoBarManager* infobar_manager, |
+ bool listening); |
bool listener_notified() const { return listener_.notified(); } |
void clear_listener_notified() { listener_.clear_notified(); } |
private: |
- // Since |infobar_manager| is really a magic number rather than an actual |
- // object, we don't add the created infobar to it. Instead we will simulate |
- // any helper<->infobar interaction necessary. The returned object will be |
- // cleaned up in OnInfoBarClosed(). |
- infobars::InfoBar* CreateTestInfoBar( |
- infobars::InfoBarManager* infobar_manager, |
- GoogleURLTracker* google_url_tracker, |
- const GURL& search_url); |
- |
// These are required by the TestURLFetchers GoogleURLTracker will create (see |
// test_url_fetcher_factory.h). |
content::TestBrowserThreadBundle thread_bundle_; |
+ |
// Creating this allows us to call |
// net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(). |
scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
@@ -285,30 +245,9 @@ class GoogleURLTrackerTest : public testing::Test { |
TestCallbackListener listener_; |
// This tracks the different "tabs" a test has "opened", so we can close them |
// properly before shutting down |google_url_tracker_|, which expects that. |
- std::set<int> unique_ids_seen_; |
+ std::set<infobars::InfoBarManager*> infobar_managers_seen_; |
}; |
-void GoogleURLTrackerTest::OnInfoBarClosed( |
- scoped_ptr<infobars::InfoBar> infobar, |
- infobars::InfoBarManager* infobar_manager) { |
- // First, simulate the InfoBarManager firing INFOBAR_REMOVED. |
- // TODO(droger): Replace this flow with a call to the observer method once |
- // the map entry is observing InfoBarManager. crbug.com/373243 |
- infobars::InfoBar::RemovedDetails removed_details(infobar.get(), false); |
- GoogleURLTracker::EntryMap::const_iterator i = |
- google_url_tracker_->entry_map_.find(infobar_manager); |
- ASSERT_FALSE(i == google_url_tracker_->entry_map_.end()); |
- GoogleURLTrackerMapEntry* map_entry = i->second; |
- ASSERT_EQ(infobar->delegate(), map_entry->infobar_delegate()); |
- map_entry->Observe( |
- chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
- content::Source<infobars::InfoBarManager>(infobar_manager), |
- content::Details<infobars::InfoBar::RemovedDetails>(&removed_details)); |
- |
- // Second, simulate the infobar container closing the infobar in response. |
- // This happens automatically as |infobar| goes out of scope. |
-} |
- |
GoogleURLTrackerTest::GoogleURLTrackerTest() |
: thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { |
GoogleURLTrackerFactory::GetInstance()-> |
@@ -326,13 +265,11 @@ void GoogleURLTrackerTest::SetUp() { |
scoped_ptr<GoogleURLTrackerClient> client(client_); |
google_url_tracker_.reset(new GoogleURLTracker( |
&profile_, client.Pass(), GoogleURLTracker::UNIT_TEST_MODE)); |
- google_url_tracker_->infobar_creator_ = base::Bind( |
- &GoogleURLTrackerTest::CreateTestInfoBar, base::Unretained(this)); |
} |
void GoogleURLTrackerTest::TearDown() { |
- while (!unique_ids_seen_.empty()) |
- CloseTab(*unique_ids_seen_.begin()); |
+ while (!infobar_managers_seen_.empty()) |
+ CloseTab(*infobar_managers_seen_.begin()); |
google_url_tracker_->Shutdown(); |
} |
@@ -380,30 +317,32 @@ GURL GoogleURLTrackerTest::GetLastPromptedGoogleURL() { |
return GURL(profile_.GetPrefs()->GetString(prefs::kLastPromptedGoogleURL)); |
} |
-void GoogleURLTrackerTest::SetNavigationPending(intptr_t unique_id, |
- bool is_search) { |
+void GoogleURLTrackerTest::SetNavigationPending( |
+ infobars::InfoBarManager* infobar_manager, |
+ bool is_search) { |
if (is_search) { |
google_url_tracker_->SearchCommitted(); |
// Note that the call above might not have actually registered a listener |
// for navigation starts if the searchdomaincheck response was bogus. |
} |
- unique_ids_seen_.insert(unique_id); |
+ infobar_managers_seen_.insert(infobar_manager); |
if (client_->IsListeningForNavigationStart()) { |
google_url_tracker_->OnNavigationPending( |
scoped_ptr<GoogleURLTrackerNavigationHelper>( |
new TestGoogleURLTrackerNavigationHelper( |
google_url_tracker_.get())), |
- reinterpret_cast<infobars::InfoBarManager*>(unique_id), |
- unique_id); |
+ infobar_manager, |
+ infobar_manager->GetActiveEntryID()); |
} |
} |
-void GoogleURLTrackerTest::CommitNonSearch(intptr_t unique_id) { |
- GoogleURLTrackerMapEntry* map_entry = GetMapEntry(unique_id); |
+void GoogleURLTrackerTest::CommitNonSearch( |
+ infobars::InfoBarManager* infobar_manager) { |
+ GoogleURLTrackerMapEntry* map_entry = GetMapEntry(infobar_manager); |
if (!map_entry) |
return; |
- ExpectListeningForCommit(unique_id, false); |
+ ExpectListeningForCommit(infobar_manager, false); |
// The infobar should be showing; otherwise the pending non-search should |
// have closed it. |
@@ -417,46 +356,48 @@ void GoogleURLTrackerTest::CommitNonSearch(intptr_t unique_id) { |
map_entry->infobar_delegate()->Close(false); |
} |
-void GoogleURLTrackerTest::CommitSearch(intptr_t unique_id, |
- const GURL& search_url) { |
+void GoogleURLTrackerTest::CommitSearch( |
+ infobars::InfoBarManager* infobar_manager, |
+ const GURL& search_url) { |
DCHECK(search_url.is_valid()); |
- GoogleURLTrackerNavigationHelper* nav_helper = GetNavigationHelper(unique_id); |
+ GoogleURLTrackerNavigationHelper* nav_helper = |
+ GetNavigationHelper(infobar_manager); |
if (nav_helper && nav_helper->IsListeningForNavigationCommit()) { |
- google_url_tracker_->OnNavigationCommitted( |
- reinterpret_cast<infobars::InfoBarManager*>(unique_id), search_url); |
+ google_url_tracker_->OnNavigationCommitted(infobar_manager, search_url); |
} |
} |
-void GoogleURLTrackerTest::CloseTab(intptr_t unique_id) { |
- unique_ids_seen_.erase(unique_id); |
- GoogleURLTrackerNavigationHelper* nav_helper = GetNavigationHelper(unique_id); |
+void GoogleURLTrackerTest::CloseTab(infobars::InfoBarManager* infobar_manager) { |
+ infobar_managers_seen_.erase(infobar_manager); |
+ GoogleURLTrackerNavigationHelper* nav_helper = |
+ GetNavigationHelper(infobar_manager); |
if (nav_helper && nav_helper->IsListeningForTabDestruction()) { |
google_url_tracker_->OnTabClosed(nav_helper); |
} else { |
// Closing a tab with an infobar showing would close the infobar. |
- GoogleURLTrackerInfoBarDelegate* delegate = GetInfoBarDelegate(unique_id); |
+ GoogleURLTrackerInfoBarDelegate* delegate = |
+ GetInfoBarDelegate(infobar_manager); |
if (delegate) |
delegate->Close(false); |
} |
} |
GoogleURLTrackerMapEntry* GoogleURLTrackerTest::GetMapEntry( |
- intptr_t unique_id) { |
+ infobars::InfoBarManager* infobar_manager) { |
GoogleURLTracker::EntryMap::const_iterator i = |
- google_url_tracker_->entry_map_.find( |
- reinterpret_cast<infobars::InfoBarManager*>(unique_id)); |
+ google_url_tracker_->entry_map_.find(infobar_manager); |
return (i == google_url_tracker_->entry_map_.end()) ? NULL : i->second; |
} |
GoogleURLTrackerInfoBarDelegate* GoogleURLTrackerTest::GetInfoBarDelegate( |
- intptr_t unique_id) { |
- GoogleURLTrackerMapEntry* map_entry = GetMapEntry(unique_id); |
+ infobars::InfoBarManager* infobar_manager) { |
+ GoogleURLTrackerMapEntry* map_entry = GetMapEntry(infobar_manager); |
return map_entry ? map_entry->infobar_delegate() : NULL; |
} |
GoogleURLTrackerNavigationHelper* GoogleURLTrackerTest::GetNavigationHelper( |
- intptr_t unique_id) { |
- GoogleURLTrackerMapEntry* map_entry = GetMapEntry(unique_id); |
+ infobars::InfoBarManager* infobar_manager) { |
+ GoogleURLTrackerMapEntry* map_entry = GetMapEntry(infobar_manager); |
return map_entry ? map_entry->navigation_helper() : NULL; |
} |
@@ -465,9 +406,10 @@ void GoogleURLTrackerTest::ExpectDefaultURLs() const { |
EXPECT_EQ(GURL(), fetched_google_url()); |
} |
-void GoogleURLTrackerTest::ExpectListeningForCommit(intptr_t unique_id, |
- bool listening) { |
- GoogleURLTrackerMapEntry* map_entry = GetMapEntry(unique_id); |
+void GoogleURLTrackerTest::ExpectListeningForCommit( |
+ infobars::InfoBarManager* infobar_manager, |
+ bool listening) { |
+ GoogleURLTrackerMapEntry* map_entry = GetMapEntry(infobar_manager); |
if (map_entry) { |
EXPECT_EQ(listening, |
map_entry->navigation_helper()->IsListeningForNavigationCommit()); |
@@ -476,61 +418,6 @@ void GoogleURLTrackerTest::ExpectListeningForCommit(intptr_t unique_id, |
} |
} |
-infobars::InfoBar* GoogleURLTrackerTest::CreateTestInfoBar( |
- infobars::InfoBarManager* infobar_manager, |
- GoogleURLTracker* google_url_tracker, |
- const GURL& search_url) { |
- return TestInfoBarDelegate::Create( |
- this, infobar_manager, google_url_tracker, search_url); |
-} |
- |
- |
-// TestInfoBarDelegate -------------------------------------------------------- |
- |
-namespace { |
- |
-// static |
-infobars::InfoBar* TestInfoBarDelegate::Create( |
- GoogleURLTrackerTest* test_harness, |
- infobars::InfoBarManager* infobar_manager, |
- GoogleURLTracker* google_url_tracker, |
- const GURL& search_url) { |
- return ConfirmInfoBarDelegate::CreateInfoBar( |
- scoped_ptr<ConfirmInfoBarDelegate>(new TestInfoBarDelegate( |
- test_harness, |
- infobar_manager, |
- google_url_tracker, |
- search_url))).release(); |
-} |
- |
-TestInfoBarDelegate::TestInfoBarDelegate( |
- GoogleURLTrackerTest* test_harness, |
- infobars::InfoBarManager* infobar_manager, |
- GoogleURLTracker* google_url_tracker, |
- const GURL& search_url) |
- : GoogleURLTrackerInfoBarDelegate(google_url_tracker, |
- search_url), |
- test_harness_(test_harness), |
- infobar_manager_(infobar_manager) { |
-} |
- |
-TestInfoBarDelegate::~TestInfoBarDelegate() { |
-} |
- |
-void TestInfoBarDelegate::Update(const GURL& search_url) { |
- set_search_url(search_url); |
- set_pending_id(0); |
-} |
- |
-void TestInfoBarDelegate::Close(bool redo_search) { |
- test_harness_->OnInfoBarClosed(scoped_ptr<infobars::InfoBar>(infobar()), |
- infobar_manager_); |
- // WARNING: At this point |this| has been deleted! |
-} |
- |
-} // namespace |
- |
- |
// Tests ---------------------------------------------------------------------- |
TEST_F(GoogleURLTrackerTest, DontFetchWhenNoOneRequestsCheck) { |
@@ -575,6 +462,7 @@ TEST_F(GoogleURLTrackerTest, DontUpdateWhenUnchanged) { |
} |
TEST_F(GoogleURLTrackerTest, DontPromptOnBadReplies) { |
+ TestInfoBarManager infobar_manager(1); |
SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
RequestServerCheck(); |
@@ -588,9 +476,9 @@ TEST_F(GoogleURLTrackerTest, DontPromptOnBadReplies) { |
EXPECT_EQ(GURL(), fetched_google_url()); |
EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
EXPECT_FALSE(listener_notified()); |
- SetNavigationPending(1, true); |
- CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
- EXPECT_TRUE(GetMapEntry(1) == NULL); |
+ SetNavigationPending(&infobar_manager, true); |
+ CommitSearch(&infobar_manager, GURL("http://www.google.co.uk/search?q=test")); |
+ EXPECT_TRUE(GetMapEntry(&infobar_manager) == NULL); |
// Bad subdomain. |
NotifyIPAddressChanged(); |
@@ -598,9 +486,9 @@ TEST_F(GoogleURLTrackerTest, DontPromptOnBadReplies) { |
EXPECT_EQ(GURL(), fetched_google_url()); |
EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
EXPECT_FALSE(listener_notified()); |
- SetNavigationPending(1, true); |
- CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
- EXPECT_TRUE(GetMapEntry(1) == NULL); |
+ SetNavigationPending(&infobar_manager, true); |
+ CommitSearch(&infobar_manager, GURL("http://www.google.co.uk/search?q=test")); |
+ EXPECT_TRUE(GetMapEntry(&infobar_manager) == NULL); |
// Non-empty path. |
NotifyIPAddressChanged(); |
@@ -608,9 +496,9 @@ TEST_F(GoogleURLTrackerTest, DontPromptOnBadReplies) { |
EXPECT_EQ(GURL(), fetched_google_url()); |
EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
EXPECT_FALSE(listener_notified()); |
- SetNavigationPending(1, true); |
- CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
- EXPECT_TRUE(GetMapEntry(1) == NULL); |
+ SetNavigationPending(&infobar_manager, true); |
+ CommitSearch(&infobar_manager, GURL("http://www.google.co.uk/search?q=test")); |
+ EXPECT_TRUE(GetMapEntry(&infobar_manager) == NULL); |
// Non-empty query. |
NotifyIPAddressChanged(); |
@@ -618,9 +506,9 @@ TEST_F(GoogleURLTrackerTest, DontPromptOnBadReplies) { |
EXPECT_EQ(GURL(), fetched_google_url()); |
EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
EXPECT_FALSE(listener_notified()); |
- SetNavigationPending(1, true); |
- CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
- EXPECT_TRUE(GetMapEntry(1) == NULL); |
+ SetNavigationPending(&infobar_manager, true); |
+ CommitSearch(&infobar_manager, GURL("http://www.google.co.uk/search?q=test")); |
+ EXPECT_TRUE(GetMapEntry(&infobar_manager) == NULL); |
// Non-empty ref. |
NotifyIPAddressChanged(); |
@@ -628,9 +516,9 @@ TEST_F(GoogleURLTrackerTest, DontPromptOnBadReplies) { |
EXPECT_EQ(GURL(), fetched_google_url()); |
EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
EXPECT_FALSE(listener_notified()); |
- SetNavigationPending(1, true); |
- CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
- EXPECT_TRUE(GetMapEntry(1) == NULL); |
+ SetNavigationPending(&infobar_manager, true); |
+ CommitSearch(&infobar_manager, GURL("http://www.google.co.uk/search?q=test")); |
+ EXPECT_TRUE(GetMapEntry(&infobar_manager) == NULL); |
// Complete garbage. |
NotifyIPAddressChanged(); |
@@ -638,9 +526,9 @@ TEST_F(GoogleURLTrackerTest, DontPromptOnBadReplies) { |
EXPECT_EQ(GURL(), fetched_google_url()); |
EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
EXPECT_FALSE(listener_notified()); |
- SetNavigationPending(1, true); |
- CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
- EXPECT_TRUE(GetMapEntry(1) == NULL); |
+ SetNavigationPending(&infobar_manager, true); |
+ CommitSearch(&infobar_manager, GURL("http://www.google.co.uk/search?q=test")); |
+ EXPECT_TRUE(GetMapEntry(&infobar_manager) == NULL); |
} |
TEST_F(GoogleURLTrackerTest, UpdatePromptedURLOnReturnToPreviousLocation) { |
@@ -741,6 +629,7 @@ TEST_F(GoogleURLTrackerTest, DontFetchTwiceOnLateRequests) { |
} |
TEST_F(GoogleURLTrackerTest, SearchingDoesNothingIfNoNeedToPrompt) { |
+ TestInfoBarManager infobar_manager(1); |
RequestServerCheck(); |
FinishSleep(); |
MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
@@ -750,9 +639,9 @@ TEST_F(GoogleURLTrackerTest, SearchingDoesNothingIfNoNeedToPrompt) { |
EXPECT_TRUE(listener_notified()); |
clear_listener_notified(); |
- SetNavigationPending(1, true); |
- CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
- EXPECT_TRUE(GetMapEntry(1) == NULL); |
+ SetNavigationPending(&infobar_manager, true); |
+ CommitSearch(&infobar_manager, GURL("http://www.google.co.uk/search?q=test")); |
+ EXPECT_TRUE(GetMapEntry(&infobar_manager) == 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()); |
@@ -760,6 +649,7 @@ TEST_F(GoogleURLTrackerTest, SearchingDoesNothingIfNoNeedToPrompt) { |
} |
TEST_F(GoogleURLTrackerTest, TabClosedOnPendingSearch) { |
+ TestInfoBarManager infobar_manager(1); |
SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
RequestServerCheck(); |
FinishSleep(); |
@@ -769,93 +659,101 @@ TEST_F(GoogleURLTrackerTest, TabClosedOnPendingSearch) { |
EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
EXPECT_FALSE(listener_notified()); |
- SetNavigationPending(1, true); |
- GoogleURLTrackerMapEntry* map_entry = GetMapEntry(1); |
+ SetNavigationPending(&infobar_manager, true); |
+ GoogleURLTrackerMapEntry* map_entry = GetMapEntry(&infobar_manager); |
ASSERT_FALSE(map_entry == NULL); |
EXPECT_FALSE(map_entry->has_infobar_delegate()); |
EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
EXPECT_FALSE(listener_notified()); |
- CloseTab(1); |
- EXPECT_TRUE(GetMapEntry(1) == NULL); |
+ CloseTab(&infobar_manager); |
+ EXPECT_TRUE(GetMapEntry(&infobar_manager) == NULL); |
EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
EXPECT_FALSE(listener_notified()); |
} |
TEST_F(GoogleURLTrackerTest, TabClosedOnCommittedSearch) { |
+ TestInfoBarManager infobar_manager(1); |
SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
RequestServerCheck(); |
FinishSleep(); |
MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
- SetNavigationPending(1, true); |
- CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
- EXPECT_FALSE(GetInfoBarDelegate(1) == NULL); |
+ SetNavigationPending(&infobar_manager, true); |
+ CommitSearch(&infobar_manager, GURL("http://www.google.co.uk/search?q=test")); |
+ EXPECT_FALSE(GetInfoBarDelegate(&infobar_manager) == NULL); |
- CloseTab(1); |
- EXPECT_TRUE(GetMapEntry(1) == NULL); |
+ CloseTab(&infobar_manager); |
+ EXPECT_TRUE(GetMapEntry(&infobar_manager) == NULL); |
EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
EXPECT_FALSE(listener_notified()); |
} |
TEST_F(GoogleURLTrackerTest, InfoBarClosed) { |
+ TestInfoBarManager infobar_manager(1); |
SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
RequestServerCheck(); |
FinishSleep(); |
MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
- SetNavigationPending(1, true); |
- CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
- GoogleURLTrackerInfoBarDelegate* infobar = GetInfoBarDelegate(1); |
+ SetNavigationPending(&infobar_manager, true); |
+ CommitSearch(&infobar_manager, GURL("http://www.google.co.uk/search?q=test")); |
+ GoogleURLTrackerInfoBarDelegate* infobar = |
+ GetInfoBarDelegate(&infobar_manager); |
ASSERT_FALSE(infobar == NULL); |
infobar->Close(false); |
- EXPECT_TRUE(GetMapEntry(1) == NULL); |
+ EXPECT_TRUE(GetMapEntry(&infobar_manager) == NULL); |
EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
EXPECT_FALSE(listener_notified()); |
} |
TEST_F(GoogleURLTrackerTest, InfoBarRefused) { |
+ TestInfoBarManager infobar_manager(1); |
SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
RequestServerCheck(); |
FinishSleep(); |
MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
- SetNavigationPending(1, true); |
- CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
- GoogleURLTrackerInfoBarDelegate* infobar = GetInfoBarDelegate(1); |
+ SetNavigationPending(&infobar_manager, true); |
+ CommitSearch(&infobar_manager, GURL("http://www.google.co.uk/search?q=test")); |
+ GoogleURLTrackerInfoBarDelegate* infobar = |
+ GetInfoBarDelegate(&infobar_manager); |
ASSERT_FALSE(infobar == NULL); |
infobar->Cancel(); |
- EXPECT_TRUE(GetMapEntry(1) == NULL); |
+ EXPECT_TRUE(GetMapEntry(&infobar_manager) == NULL); |
EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); |
EXPECT_FALSE(listener_notified()); |
} |
TEST_F(GoogleURLTrackerTest, InfoBarAccepted) { |
+ TestInfoBarManager infobar_manager(1); |
SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
RequestServerCheck(); |
FinishSleep(); |
MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
- SetNavigationPending(1, true); |
- CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
- GoogleURLTrackerInfoBarDelegate* infobar = GetInfoBarDelegate(1); |
+ SetNavigationPending(&infobar_manager, true); |
+ CommitSearch(&infobar_manager, GURL("http://www.google.co.uk/search?q=test")); |
+ GoogleURLTrackerInfoBarDelegate* infobar = |
+ GetInfoBarDelegate(&infobar_manager); |
ASSERT_FALSE(infobar == NULL); |
infobar->Accept(); |
- EXPECT_TRUE(GetMapEntry(1) == NULL); |
+ EXPECT_TRUE(GetMapEntry(&infobar_manager) == NULL); |
EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url()); |
EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); |
EXPECT_TRUE(listener_notified()); |
} |
TEST_F(GoogleURLTrackerTest, FetchesCanAutomaticallyCloseInfoBars) { |
+ TestInfoBarManager infobar_manager(1); |
RequestServerCheck(); |
FinishSleep(); |
MockSearchDomainCheckResponse(google_url().spec()); |
@@ -864,20 +762,20 @@ TEST_F(GoogleURLTrackerTest, FetchesCanAutomaticallyCloseInfoBars) { |
// should close the infobar. |
NotifyIPAddressChanged(); |
MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
- SetNavigationPending(1, true); |
- CommitSearch(1, GURL("http://www.google.com/search?q=test")); |
- EXPECT_FALSE(GetInfoBarDelegate(1) == NULL); |
+ SetNavigationPending(&infobar_manager, true); |
+ CommitSearch(&infobar_manager, GURL("http://www.google.com/search?q=test")); |
+ EXPECT_FALSE(GetInfoBarDelegate(&infobar_manager) == NULL); |
NotifyIPAddressChanged(); |
MockSearchDomainCheckResponse(google_url().spec()); |
EXPECT_EQ(google_url(), GetLastPromptedGoogleURL()); |
- EXPECT_TRUE(GetMapEntry(1) == NULL); |
+ EXPECT_TRUE(GetMapEntry(&infobar_manager) == NULL); |
// As should fetching a URL that differs from the accepted only by the scheme. |
NotifyIPAddressChanged(); |
MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
- SetNavigationPending(1, true); |
- CommitSearch(1, GURL("http://www.google.com/search?q=test")); |
- EXPECT_FALSE(GetInfoBarDelegate(1) == NULL); |
+ SetNavigationPending(&infobar_manager, true); |
+ CommitSearch(&infobar_manager, GURL("http://www.google.com/search?q=test")); |
+ EXPECT_FALSE(GetInfoBarDelegate(&infobar_manager) == NULL); |
NotifyIPAddressChanged(); |
url::Replacements<char> replacements; |
const std::string& scheme("https"); |
@@ -885,56 +783,58 @@ TEST_F(GoogleURLTrackerTest, FetchesCanAutomaticallyCloseInfoBars) { |
GURL new_google_url(google_url().ReplaceComponents(replacements)); |
MockSearchDomainCheckResponse(new_google_url.spec()); |
EXPECT_EQ(new_google_url, GetLastPromptedGoogleURL()); |
- EXPECT_TRUE(GetMapEntry(1) == NULL); |
+ EXPECT_TRUE(GetMapEntry(&infobar_manager) == NULL); |
// As should re-fetching the last prompted URL. |
SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
NotifyIPAddressChanged(); |
MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
- SetNavigationPending(1, true); |
- CommitSearch(1, GURL("http://www.google.com/search?q=test")); |
- EXPECT_FALSE(GetInfoBarDelegate(1) == NULL); |
+ SetNavigationPending(&infobar_manager, true); |
+ CommitSearch(&infobar_manager, GURL("http://www.google.com/search?q=test")); |
+ EXPECT_FALSE(GetInfoBarDelegate(&infobar_manager) == NULL); |
NotifyIPAddressChanged(); |
MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
EXPECT_EQ(new_google_url, google_url()); |
EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
- EXPECT_TRUE(GetMapEntry(1) == NULL); |
+ EXPECT_TRUE(GetMapEntry(&infobar_manager) == NULL); |
// And one that differs from the last prompted URL only by the scheme. |
NotifyIPAddressChanged(); |
MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
- SetNavigationPending(1, true); |
- CommitSearch(1, GURL("http://www.google.com/search?q=test")); |
- EXPECT_FALSE(GetInfoBarDelegate(1) == NULL); |
+ SetNavigationPending(&infobar_manager, true); |
+ CommitSearch(&infobar_manager, GURL("http://www.google.com/search?q=test")); |
+ EXPECT_FALSE(GetInfoBarDelegate(&infobar_manager) == NULL); |
NotifyIPAddressChanged(); |
MockSearchDomainCheckResponse("https://www.google.co.uk/"); |
EXPECT_EQ(new_google_url, google_url()); |
EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
- EXPECT_TRUE(GetMapEntry(1) == NULL); |
+ EXPECT_TRUE(GetMapEntry(&infobar_manager) == NULL); |
// And fetching a different URL entirely. |
NotifyIPAddressChanged(); |
MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
- SetNavigationPending(1, true); |
- CommitSearch(1, GURL("http://www.google.com/search?q=test")); |
- EXPECT_FALSE(GetInfoBarDelegate(1) == NULL); |
+ SetNavigationPending(&infobar_manager, true); |
+ CommitSearch(&infobar_manager, GURL("http://www.google.com/search?q=test")); |
+ EXPECT_FALSE(GetInfoBarDelegate(&infobar_manager) == NULL); |
NotifyIPAddressChanged(); |
MockSearchDomainCheckResponse("https://www.google.co.in/"); |
EXPECT_EQ(new_google_url, google_url()); |
EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
- EXPECT_TRUE(GetMapEntry(1) == NULL); |
+ EXPECT_TRUE(GetMapEntry(&infobar_manager) == NULL); |
} |
TEST_F(GoogleURLTrackerTest, ResetInfoBarGoogleURLs) { |
+ TestInfoBarManager infobar_manager(1); |
RequestServerCheck(); |
FinishSleep(); |
MockSearchDomainCheckResponse(google_url().spec()); |
NotifyIPAddressChanged(); |
MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
- SetNavigationPending(1, true); |
- CommitSearch(1, GURL("http://www.google.com/search?q=test")); |
- GoogleURLTrackerInfoBarDelegate* delegate = GetInfoBarDelegate(1); |
+ SetNavigationPending(&infobar_manager, true); |
+ CommitSearch(&infobar_manager, GURL("http://www.google.com/search?q=test")); |
+ GoogleURLTrackerInfoBarDelegate* delegate = |
+ GetInfoBarDelegate(&infobar_manager); |
ASSERT_FALSE(delegate == NULL); |
EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
@@ -942,161 +842,176 @@ TEST_F(GoogleURLTrackerTest, ResetInfoBarGoogleURLs) { |
// infobar's only by scheme, the infobar should stay showing. |
NotifyIPAddressChanged(); |
MockSearchDomainCheckResponse("https://www.google.co.uk/"); |
- EXPECT_EQ(delegate, GetInfoBarDelegate(1)); |
+ EXPECT_EQ(delegate, GetInfoBarDelegate(&infobar_manager)); |
EXPECT_EQ(GURL("https://www.google.co.uk/"), fetched_google_url()); |
} |
TEST_F(GoogleURLTrackerTest, NavigationsAfterPendingSearch) { |
+ TestInfoBarManager infobar_manager(1); |
SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
RequestServerCheck(); |
FinishSleep(); |
MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
// A pending non-search after a pending search should delete the map entry. |
- SetNavigationPending(1, true); |
- GoogleURLTrackerMapEntry* map_entry = GetMapEntry(1); |
+ SetNavigationPending(&infobar_manager, true); |
+ GoogleURLTrackerMapEntry* map_entry = GetMapEntry(&infobar_manager); |
ASSERT_FALSE(map_entry == NULL); |
EXPECT_FALSE(map_entry->has_infobar_delegate()); |
- SetNavigationPending(1, false); |
- EXPECT_TRUE(GetMapEntry(1) == NULL); |
+ SetNavigationPending(&infobar_manager, false); |
+ EXPECT_TRUE(GetMapEntry(&infobar_manager) == NULL); |
// A pending search after a pending search should leave the map entry alive. |
- SetNavigationPending(1, true); |
- map_entry = GetMapEntry(1); |
+ SetNavigationPending(&infobar_manager, true); |
+ map_entry = GetMapEntry(&infobar_manager); |
ASSERT_FALSE(map_entry == NULL); |
EXPECT_FALSE(map_entry->has_infobar_delegate()); |
- SetNavigationPending(1, true); |
- ASSERT_EQ(map_entry, GetMapEntry(1)); |
+ SetNavigationPending(&infobar_manager, true); |
+ ASSERT_EQ(map_entry, GetMapEntry(&infobar_manager)); |
EXPECT_FALSE(map_entry->has_infobar_delegate()); |
- ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); |
+ ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(&infobar_manager, true)); |
// Committing this search should show an infobar. |
- CommitSearch(1, GURL("http://www.google.co.uk/search?q=test2")); |
+ CommitSearch(&infobar_manager, |
+ GURL("http://www.google.co.uk/search?q=test2")); |
EXPECT_TRUE(map_entry->has_infobar_delegate()); |
EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
EXPECT_FALSE(listener_notified()); |
- ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); |
+ ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(&infobar_manager, false)); |
} |
TEST_F(GoogleURLTrackerTest, NavigationsAfterCommittedSearch) { |
+ TestInfoBarManager infobar_manager(1); |
SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
RequestServerCheck(); |
FinishSleep(); |
MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
- SetNavigationPending(1, true); |
- CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
- GoogleURLTrackerInfoBarDelegate* delegate = GetInfoBarDelegate(1); |
+ SetNavigationPending(&infobar_manager, true); |
+ CommitSearch(&infobar_manager, GURL("http://www.google.co.uk/search?q=test")); |
+ GoogleURLTrackerInfoBarDelegate* delegate = |
+ GetInfoBarDelegate(&infobar_manager); |
ASSERT_FALSE(delegate == NULL); |
- ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); |
+ ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(&infobar_manager, false)); |
// A pending non-search on a visible infobar should basically do nothing. |
- SetNavigationPending(1, false); |
- ASSERT_EQ(delegate, GetInfoBarDelegate(1)); |
+ SetNavigationPending(&infobar_manager, false); |
+ ASSERT_EQ(delegate, GetInfoBarDelegate(&infobar_manager)); |
EXPECT_EQ(0, delegate->pending_id()); |
- ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); |
+ ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(&infobar_manager, false)); |
// As should another pending non-search after the first. |
- SetNavigationPending(1, false); |
- ASSERT_EQ(delegate, GetInfoBarDelegate(1)); |
+ SetNavigationPending(&infobar_manager, false); |
+ ASSERT_EQ(delegate, GetInfoBarDelegate(&infobar_manager)); |
EXPECT_EQ(0, delegate->pending_id()); |
- ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); |
+ ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(&infobar_manager, false)); |
// Committing this non-search should close the infobar. The control flow in |
// these tests is not really comparable to in the real browser, but at least a |
// few sanity-checks will be performed. |
- ASSERT_NO_FATAL_FAILURE(CommitNonSearch(1)); |
- EXPECT_TRUE(GetMapEntry(1) == NULL); |
+ ASSERT_NO_FATAL_FAILURE(CommitNonSearch(&infobar_manager)); |
+ EXPECT_TRUE(GetMapEntry(&infobar_manager) == NULL); |
// A pending search on a visible infobar should cause the infobar to listen |
// for the search to commit. |
- SetNavigationPending(1, true); |
- CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
- delegate = GetInfoBarDelegate(1); |
+ SetNavigationPending(&infobar_manager, true); |
+ CommitSearch(&infobar_manager, GURL("http://www.google.co.uk/search?q=test")); |
+ delegate = GetInfoBarDelegate(&infobar_manager); |
ASSERT_FALSE(delegate == NULL); |
- SetNavigationPending(1, true); |
- ASSERT_EQ(delegate, GetInfoBarDelegate(1)); |
+ SetNavigationPending(&infobar_manager, true); |
+ ASSERT_EQ(delegate, GetInfoBarDelegate(&infobar_manager)); |
EXPECT_EQ(1, delegate->pending_id()); |
- ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); |
+ ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(&infobar_manager, true)); |
// But a non-search after this should cancel that state. |
- SetNavigationPending(1, false); |
- ASSERT_EQ(delegate, GetInfoBarDelegate(1)); |
+ SetNavigationPending(&infobar_manager, false); |
+ ASSERT_EQ(delegate, GetInfoBarDelegate(&infobar_manager)); |
EXPECT_EQ(0, delegate->pending_id()); |
- ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); |
+ ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(&infobar_manager, false)); |
// Another pending search after the non-search should put us back into |
// "waiting for commit" mode. |
- SetNavigationPending(1, true); |
- ASSERT_EQ(delegate, GetInfoBarDelegate(1)); |
+ SetNavigationPending(&infobar_manager, true); |
+ ASSERT_EQ(delegate, GetInfoBarDelegate(&infobar_manager)); |
EXPECT_EQ(1, delegate->pending_id()); |
- ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); |
+ ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(&infobar_manager, true)); |
// A second pending search after the first should not really change anything. |
- SetNavigationPending(1, true); |
- ASSERT_EQ(delegate, GetInfoBarDelegate(1)); |
+ SetNavigationPending(&infobar_manager, true); |
+ ASSERT_EQ(delegate, GetInfoBarDelegate(&infobar_manager)); |
EXPECT_EQ(1, delegate->pending_id()); |
- ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); |
+ ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(&infobar_manager, true)); |
// Committing this search should change the visible infobar's search_url. |
- CommitSearch(1, GURL("http://www.google.co.uk/search?q=test2")); |
- ASSERT_EQ(delegate, GetInfoBarDelegate(1)); |
+ CommitSearch(&infobar_manager, |
+ GURL("http://www.google.co.uk/search?q=test2")); |
+ ASSERT_EQ(delegate, GetInfoBarDelegate(&infobar_manager)); |
EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test2"), |
delegate->search_url()); |
EXPECT_EQ(0, delegate->pending_id()); |
- ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); |
+ ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(&infobar_manager, false)); |
EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
EXPECT_FALSE(listener_notified()); |
} |
TEST_F(GoogleURLTrackerTest, MultipleMapEntries) { |
+ TestInfoBarManager infobar_manager(1); |
+ TestInfoBarManager infobar_manager2(2); |
+ TestInfoBarManager infobar_manager3(3); |
+ TestInfoBarManager infobar_manager4(4); |
SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
RequestServerCheck(); |
FinishSleep(); |
MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
- SetNavigationPending(1, true); |
- GoogleURLTrackerMapEntry* map_entry = GetMapEntry(1); |
+ SetNavigationPending(&infobar_manager, true); |
+ GoogleURLTrackerMapEntry* map_entry = GetMapEntry(&infobar_manager); |
ASSERT_FALSE(map_entry == NULL); |
EXPECT_FALSE(map_entry->has_infobar_delegate()); |
- SetNavigationPending(2, true); |
- CommitSearch(2, GURL("http://www.google.co.uk/search?q=test2")); |
- GoogleURLTrackerInfoBarDelegate* delegate2 = GetInfoBarDelegate(2); |
+ SetNavigationPending(&infobar_manager2, true); |
+ CommitSearch(&infobar_manager2, |
+ GURL("http://www.google.co.uk/search?q=test2")); |
+ GoogleURLTrackerInfoBarDelegate* delegate2 = |
+ GetInfoBarDelegate(&infobar_manager2); |
ASSERT_FALSE(delegate2 == NULL); |
EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test2"), |
delegate2->search_url()); |
- SetNavigationPending(3, true); |
- GoogleURLTrackerMapEntry* map_entry3 = GetMapEntry(3); |
+ SetNavigationPending(&infobar_manager3, true); |
+ GoogleURLTrackerMapEntry* map_entry3 = GetMapEntry(&infobar_manager3); |
ASSERT_FALSE(map_entry3 == NULL); |
EXPECT_FALSE(map_entry3->has_infobar_delegate()); |
- SetNavigationPending(4, true); |
- CommitSearch(4, GURL("http://www.google.co.uk/search?q=test4")); |
- GoogleURLTrackerInfoBarDelegate* delegate4 = GetInfoBarDelegate(4); |
+ SetNavigationPending(&infobar_manager4, true); |
+ CommitSearch(&infobar_manager4, |
+ GURL("http://www.google.co.uk/search?q=test4")); |
+ GoogleURLTrackerInfoBarDelegate* delegate4 = |
+ GetInfoBarDelegate(&infobar_manager4); |
ASSERT_FALSE(delegate4 == NULL); |
EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test4"), |
delegate4->search_url()); |
- CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
+ CommitSearch(&infobar_manager, GURL("http://www.google.co.uk/search?q=test")); |
EXPECT_TRUE(map_entry->has_infobar_delegate()); |
delegate2->Close(false); |
- EXPECT_TRUE(GetMapEntry(2) == NULL); |
+ EXPECT_TRUE(GetMapEntry(&infobar_manager2) == NULL); |
EXPECT_FALSE(listener_notified()); |
delegate4->Accept(); |
- EXPECT_TRUE(GetMapEntry(1) == NULL); |
- EXPECT_TRUE(GetMapEntry(3) == NULL); |
- EXPECT_TRUE(GetMapEntry(4) == NULL); |
+ EXPECT_TRUE(GetMapEntry(&infobar_manager) == NULL); |
+ EXPECT_TRUE(GetMapEntry(&infobar_manager3) == NULL); |
+ EXPECT_TRUE(GetMapEntry(&infobar_manager4) == NULL); |
EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url()); |
EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); |
EXPECT_TRUE(listener_notified()); |
} |
TEST_F(GoogleURLTrackerTest, IgnoreIrrelevantNavigation) { |
+ TestInfoBarManager infobar_manager(1); |
+ TestInfoBarManager infobar_manager2(2); |
SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
RequestServerCheck(); |
FinishSleep(); |
@@ -1104,16 +1019,18 @@ TEST_F(GoogleURLTrackerTest, IgnoreIrrelevantNavigation) { |
// This tests a particularly gnarly sequence of events that used to cause us |
// to erroneously listen for a non-search navigation to commit. |
- SetNavigationPending(1, true); |
- CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
- SetNavigationPending(2, true); |
- CommitSearch(2, GURL("http://www.google.co.uk/search?q=test2")); |
- EXPECT_FALSE(GetInfoBarDelegate(1) == NULL); |
- GoogleURLTrackerInfoBarDelegate* delegate2 = GetInfoBarDelegate(2); |
+ SetNavigationPending(&infobar_manager, true); |
+ CommitSearch(&infobar_manager, GURL("http://www.google.co.uk/search?q=test")); |
+ SetNavigationPending(&infobar_manager2, true); |
+ CommitSearch(&infobar_manager2, |
+ GURL("http://www.google.co.uk/search?q=test2")); |
+ EXPECT_FALSE(GetInfoBarDelegate(&infobar_manager) == NULL); |
+ GoogleURLTrackerInfoBarDelegate* delegate2 = |
+ GetInfoBarDelegate(&infobar_manager2); |
ASSERT_FALSE(delegate2 == NULL); |
- SetNavigationPending(1, true); |
- ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); |
+ SetNavigationPending(&infobar_manager, true); |
+ ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(&infobar_manager, true)); |
delegate2->Close(false); |
- SetNavigationPending(1, false); |
- ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); |
+ SetNavigationPending(&infobar_manager, false); |
+ ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(&infobar_manager, false)); |
} |