| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/google/google_url_tracker.h" | 5 #include "chrome/browser/google/google_url_tracker.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "chrome/browser/api/infobars/infobar_delegate.h" | 11 #include "chrome/browser/api/infobars/infobar_delegate.h" |
| 12 #include "chrome/browser/google/google_url_tracker_factory.h" | 12 #include "chrome/browser/google/google_url_tracker_factory.h" |
| 13 #include "chrome/browser/google/google_url_tracker_infobar_delegate.h" | 13 #include "chrome/browser/google/google_url_tracker_infobar_delegate.h" |
| 14 #include "chrome/browser/infobars/infobar.h" |
| 14 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
| 15 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
| 16 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 17 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
| 18 #include "content/public/browser/notification_service.h" | 19 #include "content/public/browser/notification_service.h" |
| 19 #include "content/public/test/test_browser_thread.h" | 20 #include "content/public/test/test_browser_thread.h" |
| 20 #include "net/url_request/test_url_fetcher_factory.h" | 21 #include "net/url_request/test_url_fetcher_factory.h" |
| 21 #include "net/url_request/url_fetcher.h" | 22 #include "net/url_request/url_fetcher.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 24 |
| 24 // TestNotificationObserver --------------------------------------------------- | 25 class GoogleURLTrackerTest; |
| 26 |
| 25 | 27 |
| 26 namespace { | 28 namespace { |
| 27 | 29 |
| 30 // TestInfoBarDelegate -------------------------------------------------------- |
| 31 |
| 32 class TestInfoBarDelegate : public GoogleURLTrackerInfoBarDelegate { |
| 33 public: |
| 34 TestInfoBarDelegate(GoogleURLTrackerTest* test_harness, |
| 35 InfoBarTabHelper* infobar_helper, |
| 36 GoogleURLTracker* google_url_tracker, |
| 37 const GURL& search_url); |
| 38 virtual ~TestInfoBarDelegate(); |
| 39 |
| 40 private: |
| 41 // GoogleURLTrackerInfoBarDelegate: |
| 42 virtual void Update(const GURL& search_url) OVERRIDE; |
| 43 virtual void Close(bool redo_search) OVERRIDE; |
| 44 |
| 45 GoogleURLTrackerTest* test_harness_; |
| 46 InfoBarTabHelper* infobar_helper_; |
| 47 |
| 48 DISALLOW_COPY_AND_ASSIGN(TestInfoBarDelegate); |
| 49 }; |
| 50 |
| 51 // The member function definitions come after the declaration of |
| 52 // GoogleURLTrackerTest, so they can call members on it. |
| 53 |
| 54 |
| 55 // TestNotificationObserver --------------------------------------------------- |
| 56 |
| 28 class TestNotificationObserver : public content::NotificationObserver { | 57 class TestNotificationObserver : public content::NotificationObserver { |
| 29 public: | 58 public: |
| 30 TestNotificationObserver(); | 59 TestNotificationObserver(); |
| 31 virtual ~TestNotificationObserver(); | 60 virtual ~TestNotificationObserver(); |
| 32 | 61 |
| 33 virtual void Observe(int type, | 62 virtual void Observe(int type, |
| 34 const content::NotificationSource& source, | 63 const content::NotificationSource& source, |
| 35 const content::NotificationDetails& details); | 64 const content::NotificationDetails& details); |
| 36 bool notified() const { return notified_; } | 65 bool notified() const { return notified_; } |
| 37 void clear_notified() { notified_ = false; } | 66 void clear_notified() { notified_ = false; } |
| 38 | 67 |
| 39 private: | 68 private: |
| 40 bool notified_; | 69 bool notified_; |
| 41 }; | 70 }; |
| 42 | 71 |
| 43 TestNotificationObserver::TestNotificationObserver() : notified_(false) { | 72 TestNotificationObserver::TestNotificationObserver() : notified_(false) { |
| 44 } | 73 } |
| 45 | 74 |
| 46 TestNotificationObserver::~TestNotificationObserver() { | 75 TestNotificationObserver::~TestNotificationObserver() { |
| 47 } | 76 } |
| 48 | 77 |
| 49 void TestNotificationObserver::Observe( | 78 void TestNotificationObserver::Observe( |
| 50 int type, | 79 int type, |
| 51 const content::NotificationSource& source, | 80 const content::NotificationSource& source, |
| 52 const content::NotificationDetails& details) { | 81 const content::NotificationDetails& details) { |
| 53 notified_ = true; | 82 notified_ = true; |
| 54 } | 83 } |
| 55 | 84 |
| 56 | |
| 57 // TestInfoBarDelegate -------------------------------------------------------- | |
| 58 | |
| 59 class TestInfoBarDelegate : public GoogleURLTrackerInfoBarDelegate { | |
| 60 public: | |
| 61 TestInfoBarDelegate(InfoBarTabHelper* infobar_helper, | |
| 62 GoogleURLTracker* google_url_tracker, | |
| 63 const GURL& new_google_url); | |
| 64 virtual ~TestInfoBarDelegate(); | |
| 65 | |
| 66 GURL search_url() const { return search_url_; } | |
| 67 GURL new_google_url() const { return new_google_url_; } | |
| 68 int pending_id() const { return pending_id_; } | |
| 69 | |
| 70 private: | |
| 71 // GoogleURLTrackerInfoBarDelegate: | |
| 72 virtual void Show(const GURL& search_url) OVERRIDE; | |
| 73 virtual void Close(bool redo_search) OVERRIDE; | |
| 74 }; | |
| 75 | |
| 76 TestInfoBarDelegate::TestInfoBarDelegate(InfoBarTabHelper* infobar_helper, | |
| 77 GoogleURLTracker* google_url_tracker, | |
| 78 const GURL& new_google_url) | |
| 79 : GoogleURLTrackerInfoBarDelegate(NULL, google_url_tracker, new_google_url) { | |
| 80 // We set |map_key_| here instead of in the superclass constructor so that the | |
| 81 // InfoBarDelegate base class will not try to dereference it, which would fail | |
| 82 // since this is really a magic number and not an actual pointer. | |
| 83 map_key_ = infobar_helper; | |
| 84 } | |
| 85 | |
| 86 void TestInfoBarDelegate::Show(const GURL& search_url) { | |
| 87 search_url_ = search_url; | |
| 88 pending_id_ = 0; | |
| 89 showing_ = true; | |
| 90 } | |
| 91 | |
| 92 void TestInfoBarDelegate::Close(bool redo_search) { | |
| 93 InfoBarClosed(); | |
| 94 } | |
| 95 | |
| 96 TestInfoBarDelegate::~TestInfoBarDelegate() { | |
| 97 } | |
| 98 | |
| 99 GoogleURLTrackerInfoBarDelegate* CreateTestInfobar( | |
| 100 InfoBarTabHelper* infobar_helper, | |
| 101 GoogleURLTracker* google_url_tracker, | |
| 102 const GURL& new_google_url) { | |
| 103 return new TestInfoBarDelegate(infobar_helper, google_url_tracker, | |
| 104 new_google_url); | |
| 105 } | |
| 106 | |
| 107 } // namespace | 85 } // namespace |
| 108 | 86 |
| 109 | 87 |
| 110 // GoogleURLTrackerTest ------------------------------------------------------- | 88 // GoogleURLTrackerTest ------------------------------------------------------- |
| 111 | 89 |
| 90 // Ths class exercises GoogleURLTracker. In order to avoid instantiating more |
| 91 // of the Chrome infrastructure than necessary, the GoogleURLTracker functions |
| 92 // are carefully written so that many of the functions which take WebContents*, |
| 93 // NavigationController*, InfoBarTabHelper*, or objects containing such pointers |
| 94 // (e.g. NotificationSource) do not actually dereference the objects, merely use |
| 95 // them for comparisons and lookups, e.g. in an InfoBarMap. This then allows |
| 96 // the test code here to not create any of these objects, and instead supply |
| 97 // "pointers" that are actually reinterpret_cast<>()ed magic numbers. Then we |
| 98 // write the necessary stubs/hooks, here and in TestInfoBarDelegate above, to |
| 99 // make everything continue to work. |
| 100 // |
| 101 // Technically, the C++98 spec defines the result of casting |
| 102 // T* -> intptr_t -> T* to be an identity, but intptr_t -> T* -> intptr_t (what |
| 103 // we use here) is "implementation-defined". Since I've never seen a compiler |
| 104 // break this, though, and the result would simply be a failing test rather than |
| 105 // a bug in Chrome, we'll use it anyway. |
| 112 class GoogleURLTrackerTest : public testing::Test { | 106 class GoogleURLTrackerTest : public testing::Test { |
| 107 public: |
| 108 // Called by TestInfoBarDelegate::Close(). |
| 109 void OnInfoBarClosed(GoogleURLTrackerInfoBarDelegate* infobar, |
| 110 InfoBarTabHelper* infobar_helper); |
| 111 |
| 113 protected: | 112 protected: |
| 114 GoogleURLTrackerTest(); | 113 GoogleURLTrackerTest(); |
| 115 virtual ~GoogleURLTrackerTest(); | 114 virtual ~GoogleURLTrackerTest(); |
| 116 | 115 |
| 117 // testing::Test | 116 // testing::Test |
| 118 virtual void SetUp(); | 117 virtual void SetUp() OVERRIDE; |
| 119 virtual void TearDown(); | 118 virtual void TearDown() OVERRIDE; |
| 120 | 119 |
| 121 net::TestURLFetcher* GetFetcher(); | 120 net::TestURLFetcher* GetFetcher(); |
| 122 void MockSearchDomainCheckResponse(const std::string& domain); | 121 void MockSearchDomainCheckResponse(const std::string& domain); |
| 123 void RequestServerCheck(); | 122 void RequestServerCheck(); |
| 124 void FinishSleep(); | 123 void FinishSleep(); |
| 125 void NotifyIPAddressChanged(); | 124 void NotifyIPAddressChanged(); |
| 126 GURL fetched_google_url() const { | 125 GURL fetched_google_url() const { |
| 127 return google_url_tracker_->fetched_google_url_; | 126 return google_url_tracker_->fetched_google_url(); |
| 128 } | 127 } |
| 129 void set_google_url(const GURL& url) { | 128 void set_google_url(const GURL& url) { |
| 130 google_url_tracker_->google_url_ = url; | 129 google_url_tracker_->google_url_ = url; |
| 131 } | 130 } |
| 132 GURL google_url() const { return google_url_tracker_->google_url_; } | 131 GURL google_url() const { return google_url_tracker_->google_url(); } |
| 133 void SetLastPromptedGoogleURL(const GURL& url); | 132 void SetLastPromptedGoogleURL(const GURL& url); |
| 134 GURL GetLastPromptedGoogleURL(); | 133 GURL GetLastPromptedGoogleURL(); |
| 135 void SetNavigationPending(int unique_id, bool is_search); | 134 void SetNavigationPending(intptr_t unique_id, bool is_search); |
| 136 void CommitNonSearch(int unique_id); | 135 void CommitNonSearch(intptr_t unique_id); |
| 137 void CommitSearch(int unique_id, const GURL& search_url); | 136 void CommitSearch(intptr_t unique_id, const GURL& search_url); |
| 138 void DoInstantNavigation(int unique_id, const GURL& search_url); | 137 void DoInstantNavigation(intptr_t unique_id, const GURL& search_url); |
| 139 void CloseTab(int unique_id); | 138 void CloseTab(intptr_t unique_id); |
| 140 TestInfoBarDelegate* GetInfoBar(int unique_id); | 139 GoogleURLTrackerMapEntry* GetMapEntry(intptr_t unique_id); |
| 140 GoogleURLTrackerInfoBarDelegate* GetInfoBar(intptr_t unique_id); |
| 141 void ExpectDefaultURLs() const; | 141 void ExpectDefaultURLs() const; |
| 142 void ExpectListeningForCommit(int unique_id, bool listening) const; | 142 void ExpectListeningForCommit(intptr_t unique_id, bool listening); |
| 143 | 143 bool observer_notified() const { return observer_.notified(); } |
| 144 scoped_ptr<TestNotificationObserver> observer_; | 144 void clear_observer_notified() { observer_.clear_notified(); } |
| 145 | 145 |
| 146 private: | 146 private: |
| 147 // Since |infobar_helper| is really a magic number rather than an actual |
| 148 // object, we don't add the created infobar to it. Instead we will simulate |
| 149 // any helper<->infobar interaction necessary. The returned object will be |
| 150 // cleaned up in CloseTab(). |
| 151 GoogleURLTrackerInfoBarDelegate* CreateTestInfoBar( |
| 152 InfoBarTabHelper* infobar_helper, |
| 153 GoogleURLTracker* google_url_tracker, |
| 154 const GURL& search_url); |
| 155 |
| 147 // These are required by the TestURLFetchers GoogleURLTracker will create (see | 156 // These are required by the TestURLFetchers GoogleURLTracker will create (see |
| 148 // test_url_fetcher_factory.h). | 157 // test_url_fetcher_factory.h). |
| 149 MessageLoop message_loop_; | 158 MessageLoop message_loop_; |
| 150 content::TestBrowserThread io_thread_; | 159 content::TestBrowserThread io_thread_; |
| 151 // Creating this allows us to call | 160 // Creating this allows us to call |
| 152 // net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(). | 161 // net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(). |
| 153 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | 162 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
| 154 net::TestURLFetcherFactory fetcher_factory_; | 163 net::TestURLFetcherFactory fetcher_factory_; |
| 155 content::NotificationRegistrar registrar_; | 164 content::NotificationRegistrar registrar_; |
| 165 TestNotificationObserver observer_; |
| 156 TestingProfile profile_; | 166 TestingProfile profile_; |
| 157 scoped_ptr<GoogleURLTracker> google_url_tracker_; | 167 scoped_ptr<GoogleURLTracker> google_url_tracker_; |
| 158 // This tracks the different "tabs" a test has "opened", so we can close them | 168 // This tracks the different "tabs" a test has "opened", so we can close them |
| 159 // properly before shutting down |google_url_tracker_|, which expects that. | 169 // properly before shutting down |google_url_tracker_|, which expects that. |
| 160 std::set<int> unique_ids_seen_; | 170 std::set<int> unique_ids_seen_; |
| 161 }; | 171 }; |
| 162 | 172 |
| 173 void GoogleURLTrackerTest::OnInfoBarClosed( |
| 174 GoogleURLTrackerInfoBarDelegate* infobar, |
| 175 InfoBarTabHelper* infobar_helper) { |
| 176 // First, simulate the InfoBarTabHelper firing INFOBAR_REMOVED. |
| 177 InfoBarRemovedDetails removed_details(infobar, false); |
| 178 GoogleURLTracker::InfoBarMap::const_iterator i = |
| 179 google_url_tracker_->infobar_map_.find(infobar_helper); |
| 180 ASSERT_FALSE(i == google_url_tracker_->infobar_map_.end()); |
| 181 GoogleURLTrackerMapEntry* map_entry = i->second; |
| 182 ASSERT_EQ(infobar, map_entry->infobar()); |
| 183 map_entry->Observe(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
| 184 content::Source<InfoBarTabHelper>(infobar_helper), |
| 185 content::Details<InfoBarRemovedDetails>(&removed_details)); |
| 186 |
| 187 // Second, simulate the infobar container closing the infobar in response. |
| 188 infobar->InfoBarClosed(); |
| 189 } |
| 190 |
| 163 GoogleURLTrackerTest::GoogleURLTrackerTest() | 191 GoogleURLTrackerTest::GoogleURLTrackerTest() |
| 164 : observer_(new TestNotificationObserver), | 192 : message_loop_(MessageLoop::TYPE_IO), |
| 165 message_loop_(MessageLoop::TYPE_IO), | |
| 166 io_thread_(content::BrowserThread::IO, &message_loop_) { | 193 io_thread_(content::BrowserThread::IO, &message_loop_) { |
| 167 GoogleURLTrackerFactory::GetInstance()->RegisterUserPrefsOnProfile(&profile_); | 194 GoogleURLTrackerFactory::GetInstance()->RegisterUserPrefsOnProfile(&profile_); |
| 168 } | 195 } |
| 169 | 196 |
| 170 GoogleURLTrackerTest::~GoogleURLTrackerTest() { | 197 GoogleURLTrackerTest::~GoogleURLTrackerTest() { |
| 171 } | 198 } |
| 172 | 199 |
| 173 void GoogleURLTrackerTest::SetUp() { | 200 void GoogleURLTrackerTest::SetUp() { |
| 174 network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock()); | 201 network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock()); |
| 175 google_url_tracker_.reset( | 202 google_url_tracker_.reset( |
| 176 new GoogleURLTracker(&profile_, GoogleURLTracker::UNIT_TEST_MODE)); | 203 new GoogleURLTracker(&profile_, GoogleURLTracker::UNIT_TEST_MODE)); |
| 177 google_url_tracker_->infobar_creator_ = &CreateTestInfobar; | 204 google_url_tracker_->infobar_creator_ = base::Bind( |
| 205 &GoogleURLTrackerTest::CreateTestInfoBar, base::Unretained(this)); |
| 178 } | 206 } |
| 179 | 207 |
| 180 void GoogleURLTrackerTest::TearDown() { | 208 void GoogleURLTrackerTest::TearDown() { |
| 181 while (!unique_ids_seen_.empty()) | 209 while (!unique_ids_seen_.empty()) |
| 182 CloseTab(*unique_ids_seen_.begin()); | 210 CloseTab(*unique_ids_seen_.begin()); |
| 183 | 211 |
| 184 google_url_tracker_.reset(); | 212 google_url_tracker_.reset(); |
| 185 network_change_notifier_.reset(); | 213 network_change_notifier_.reset(); |
| 186 } | 214 } |
| 187 | 215 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 198 return; | 226 return; |
| 199 fetcher_factory_.RemoveFetcherFromMap(fetcher->id()); | 227 fetcher_factory_.RemoveFetcherFromMap(fetcher->id()); |
| 200 fetcher->set_url(GURL(GoogleURLTracker::kSearchDomainCheckURL)); | 228 fetcher->set_url(GURL(GoogleURLTracker::kSearchDomainCheckURL)); |
| 201 fetcher->set_response_code(200); | 229 fetcher->set_response_code(200); |
| 202 fetcher->SetResponseString(domain); | 230 fetcher->SetResponseString(domain); |
| 203 fetcher->delegate()->OnURLFetchComplete(fetcher); | 231 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 204 // At this point, |fetcher| is deleted. | 232 // At this point, |fetcher| is deleted. |
| 205 } | 233 } |
| 206 | 234 |
| 207 void GoogleURLTrackerTest::RequestServerCheck() { | 235 void GoogleURLTrackerTest::RequestServerCheck() { |
| 208 if (!registrar_.IsRegistered(observer_.get(), | 236 if (!registrar_.IsRegistered(&observer_, |
| 209 chrome::NOTIFICATION_GOOGLE_URL_UPDATED, | 237 chrome::NOTIFICATION_GOOGLE_URL_UPDATED, |
| 210 content::Source<Profile>(&profile_))) { | 238 content::Source<Profile>(&profile_))) { |
| 211 registrar_.Add(observer_.get(), chrome::NOTIFICATION_GOOGLE_URL_UPDATED, | 239 registrar_.Add(&observer_, chrome::NOTIFICATION_GOOGLE_URL_UPDATED, |
| 212 content::Source<Profile>(&profile_)); | 240 content::Source<Profile>(&profile_)); |
| 213 } | 241 } |
| 214 google_url_tracker_->SetNeedToFetch(); | 242 google_url_tracker_->SetNeedToFetch(); |
| 215 } | 243 } |
| 216 | 244 |
| 217 void GoogleURLTrackerTest::FinishSleep() { | 245 void GoogleURLTrackerTest::FinishSleep() { |
| 218 google_url_tracker_->FinishSleep(); | 246 google_url_tracker_->FinishSleep(); |
| 219 } | 247 } |
| 220 | 248 |
| 221 void GoogleURLTrackerTest::NotifyIPAddressChanged() { | 249 void GoogleURLTrackerTest::NotifyIPAddressChanged() { |
| 222 net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 250 net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
| 223 // For thread safety, the NCN queues tasks to do the actual notifications, so | 251 // For thread safety, the NCN queues tasks to do the actual notifications, so |
| 224 // we need to spin the message loop so the tracker will actually be notified. | 252 // we need to spin the message loop so the tracker will actually be notified. |
| 225 MessageLoop::current()->RunAllPending(); | 253 MessageLoop::current()->RunAllPending(); |
| 226 } | 254 } |
| 227 | 255 |
| 228 void GoogleURLTrackerTest::SetLastPromptedGoogleURL(const GURL& url) { | 256 void GoogleURLTrackerTest::SetLastPromptedGoogleURL(const GURL& url) { |
| 229 profile_.GetPrefs()->SetString(prefs::kLastPromptedGoogleURL, url.spec()); | 257 profile_.GetPrefs()->SetString(prefs::kLastPromptedGoogleURL, url.spec()); |
| 230 } | 258 } |
| 231 | 259 |
| 232 GURL GoogleURLTrackerTest::GetLastPromptedGoogleURL() { | 260 GURL GoogleURLTrackerTest::GetLastPromptedGoogleURL() { |
| 233 return GURL(profile_.GetPrefs()->GetString(prefs::kLastPromptedGoogleURL)); | 261 return GURL(profile_.GetPrefs()->GetString(prefs::kLastPromptedGoogleURL)); |
| 234 } | 262 } |
| 235 | 263 |
| 236 void GoogleURLTrackerTest::SetNavigationPending(int unique_id, bool is_search) { | 264 void GoogleURLTrackerTest::SetNavigationPending(intptr_t unique_id, |
| 265 bool is_search) { |
| 237 if (is_search) { | 266 if (is_search) { |
| 238 google_url_tracker_->SearchCommitted(); | 267 google_url_tracker_->SearchCommitted(); |
| 239 // Note that the call above might not have actually registered a listener | 268 // Note that the call above might not have actually registered a listener |
| 240 // for NOTIFICATION_NAV_ENTRY_PENDING if the searchdomaincheck response was | 269 // for NOTIFICATION_NAV_ENTRY_PENDING if the searchdomaincheck response was |
| 241 // bogus. | 270 // bogus. |
| 242 } | 271 } |
| 243 unique_ids_seen_.insert(unique_id); | 272 unique_ids_seen_.insert(unique_id); |
| 244 if (google_url_tracker_->registrar_.IsRegistered(google_url_tracker_.get(), | 273 if (google_url_tracker_->registrar_.IsRegistered(google_url_tracker_.get(), |
| 245 content::NOTIFICATION_NAV_ENTRY_PENDING, | 274 content::NOTIFICATION_NAV_ENTRY_PENDING, |
| 246 content::NotificationService::AllBrowserContextsAndSources())) { | 275 content::NotificationService::AllBrowserContextsAndSources())) { |
| 247 google_url_tracker_->OnNavigationPending( | 276 google_url_tracker_->OnNavigationPending( |
| 248 content::Source<content::NavigationController>( | 277 content::Source<content::NavigationController>( |
| 249 reinterpret_cast<content::NavigationController*>(unique_id)), | 278 reinterpret_cast<content::NavigationController*>(unique_id)), |
| 250 content::Source<content::WebContents>( | 279 content::Source<content::WebContents>( |
| 251 reinterpret_cast<content::WebContents*>(unique_id)), | 280 reinterpret_cast<content::WebContents*>(unique_id)), |
| 252 reinterpret_cast<InfoBarTabHelper*>(unique_id), unique_id); | 281 reinterpret_cast<InfoBarTabHelper*>(unique_id), unique_id); |
| 253 } | 282 } |
| 254 } | 283 } |
| 255 | 284 |
| 256 void GoogleURLTrackerTest::CommitNonSearch(int unique_id) { | 285 void GoogleURLTrackerTest::CommitNonSearch(intptr_t unique_id) { |
| 257 GoogleURLTracker::InfoBarMap::iterator i = | 286 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(unique_id); |
| 258 google_url_tracker_->infobar_map_.find( | 287 if (!map_entry) |
| 259 reinterpret_cast<InfoBarTabHelper*>(unique_id)); | 288 return; |
| 260 if (i != google_url_tracker_->infobar_map_.end()) { | 289 |
| 261 ExpectListeningForCommit(unique_id, false); | 290 ExpectListeningForCommit(unique_id, false); |
| 262 TestInfoBarDelegate* infobar = | 291 |
| 263 static_cast<TestInfoBarDelegate*>(i->second.infobar); | 292 // The infobar should be showing; otherwise the pending non-search should |
| 264 // The infobar should be showing; otherwise the pending non-search should | 293 // have closed it. |
| 265 // have closed it. | 294 ASSERT_TRUE(map_entry->has_infobar()); |
| 266 EXPECT_TRUE(infobar->showing()); | 295 |
| 267 // The pending_id should have been reset to 0 when the non-search became | 296 // The pending_id should have been reset to 0 when the non-search became |
| 268 // pending. | 297 // pending. |
| 269 EXPECT_EQ(0, infobar->pending_id()); | 298 EXPECT_EQ(0, map_entry->infobar()->pending_id()); |
| 270 infobar->InfoBarClosed(); | 299 |
| 271 } | 300 // Committing the navigation would close the infobar. |
| 301 map_entry->infobar()->Close(false); |
| 272 } | 302 } |
| 273 | 303 |
| 274 void GoogleURLTrackerTest::CommitSearch(int unique_id, const GURL& search_url) { | 304 void GoogleURLTrackerTest::CommitSearch(intptr_t unique_id, |
| 305 const GURL& search_url) { |
| 275 if (google_url_tracker_->registrar_.IsRegistered(google_url_tracker_.get(), | 306 if (google_url_tracker_->registrar_.IsRegistered(google_url_tracker_.get(), |
| 276 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 307 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 277 content::Source<content::NavigationController>( | 308 content::Source<content::NavigationController>( |
| 278 reinterpret_cast<content::NavigationController*>(unique_id)))) { | 309 reinterpret_cast<content::NavigationController*>(unique_id)))) { |
| 279 google_url_tracker_->OnNavigationCommittedOrTabClosed( | 310 google_url_tracker_->OnNavigationCommittedOrTabClosed( |
| 280 reinterpret_cast<InfoBarTabHelper*>(unique_id), | 311 reinterpret_cast<InfoBarTabHelper*>(unique_id), |
| 281 search_url); | 312 search_url); |
| 282 } | 313 } |
| 283 } | 314 } |
| 284 | 315 |
| 285 void GoogleURLTrackerTest::DoInstantNavigation(int unique_id, | 316 void GoogleURLTrackerTest::DoInstantNavigation(intptr_t unique_id, |
| 286 const GURL& search_url) { | 317 const GURL& search_url) { |
| 287 if (!search_url.is_empty()) { | 318 if (!search_url.is_empty()) { |
| 288 google_url_tracker_->SearchCommitted(); | 319 google_url_tracker_->SearchCommitted(); |
| 289 // Note that the call above might not have actually registered a listener | 320 // Note that the call above might not have actually registered a listener |
| 290 // for NOTIFICATION_INSTANT_COMMITTED if the searchdomaincheck response was | 321 // for NOTIFICATION_INSTANT_COMMITTED if the searchdomaincheck response was |
| 291 // bogus. | 322 // bogus. |
| 292 } | 323 } |
| 293 unique_ids_seen_.insert(unique_id); | 324 unique_ids_seen_.insert(unique_id); |
| 294 if (google_url_tracker_->registrar_.IsRegistered(google_url_tracker_.get(), | 325 if (google_url_tracker_->registrar_.IsRegistered(google_url_tracker_.get(), |
| 295 chrome::NOTIFICATION_INSTANT_COMMITTED, | 326 chrome::NOTIFICATION_INSTANT_COMMITTED, |
| 296 content::NotificationService::AllBrowserContextsAndSources())) { | 327 content::NotificationService::AllBrowserContextsAndSources())) { |
| 297 google_url_tracker_->OnInstantCommitted( | 328 google_url_tracker_->OnInstantCommitted( |
| 298 content::Source<content::NavigationController>( | 329 content::Source<content::NavigationController>( |
| 299 reinterpret_cast<content::NavigationController*>(unique_id)), | 330 reinterpret_cast<content::NavigationController*>(unique_id)), |
| 300 content::Source<content::WebContents>( | 331 content::Source<content::WebContents>( |
| 301 reinterpret_cast<content::WebContents*>(unique_id)), | 332 reinterpret_cast<content::WebContents*>(unique_id)), |
| 302 reinterpret_cast<InfoBarTabHelper*>(unique_id), search_url); | 333 reinterpret_cast<InfoBarTabHelper*>(unique_id), search_url); |
| 303 } | 334 } |
| 304 } | 335 } |
| 305 | 336 |
| 306 void GoogleURLTrackerTest::CloseTab(int unique_id) { | 337 void GoogleURLTrackerTest::CloseTab(intptr_t unique_id) { |
| 307 unique_ids_seen_.erase(unique_id); | 338 unique_ids_seen_.erase(unique_id); |
| 308 InfoBarTabHelper* infobar_helper = | 339 InfoBarTabHelper* infobar_helper = |
| 309 reinterpret_cast<InfoBarTabHelper*>(unique_id); | 340 reinterpret_cast<InfoBarTabHelper*>(unique_id); |
| 310 if (google_url_tracker_->registrar_.IsRegistered( | 341 if (google_url_tracker_->registrar_.IsRegistered( |
| 311 google_url_tracker_.get(), | 342 google_url_tracker_.get(), content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 312 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 343 content::Source<content::WebContents>( |
| 313 content::Source<content::WebContents>( | 344 reinterpret_cast<content::WebContents*>(unique_id)))) { |
| 314 reinterpret_cast<content::WebContents*>(unique_id)))) { | |
| 315 google_url_tracker_->OnNavigationCommittedOrTabClosed(infobar_helper, | 345 google_url_tracker_->OnNavigationCommittedOrTabClosed(infobar_helper, |
| 316 GURL()); | 346 GURL()); |
| 317 } else { | 347 } else { |
| 318 // Normally, closing a tab with an infobar showing will close the infobar. | 348 // Closing a tab with an infobar showing would close the infobar. |
| 319 // Since we don't have real tabs and are just faking things with magic | 349 GoogleURLTrackerInfoBarDelegate* infobar = GetInfoBar(unique_id); |
| 320 // numbers, we have to manually close the infobar, if any. | 350 if (infobar) |
| 321 GoogleURLTracker::InfoBarMap::iterator i = | 351 infobar->Close(false); |
| 322 google_url_tracker_->infobar_map_.find(infobar_helper); | |
| 323 if (i != google_url_tracker_->infobar_map_.end()) { | |
| 324 TestInfoBarDelegate* infobar = | |
| 325 static_cast<TestInfoBarDelegate*>(i->second.infobar); | |
| 326 EXPECT_TRUE(infobar->showing()); | |
| 327 infobar->InfoBarClosed(); | |
| 328 } | |
| 329 } | 352 } |
| 330 } | 353 } |
| 331 | 354 |
| 332 TestInfoBarDelegate* GoogleURLTrackerTest::GetInfoBar(int unique_id) { | 355 GoogleURLTrackerMapEntry* GoogleURLTrackerTest::GetMapEntry( |
| 356 intptr_t unique_id) { |
| 333 GoogleURLTracker::InfoBarMap::const_iterator i = | 357 GoogleURLTracker::InfoBarMap::const_iterator i = |
| 334 google_url_tracker_->infobar_map_.find( | 358 google_url_tracker_->infobar_map_.find( |
| 335 reinterpret_cast<InfoBarTabHelper*>(unique_id)); | 359 reinterpret_cast<InfoBarTabHelper*>(unique_id)); |
| 336 return (i == google_url_tracker_->infobar_map_.end()) ? | 360 return (i == google_url_tracker_->infobar_map_.end()) ? NULL : i->second; |
| 337 NULL : static_cast<TestInfoBarDelegate*>(i->second.infobar); | 361 } |
| 362 |
| 363 GoogleURLTrackerInfoBarDelegate* GoogleURLTrackerTest::GetInfoBar( |
| 364 intptr_t unique_id) { |
| 365 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(unique_id); |
| 366 return map_entry ? map_entry->infobar() : NULL; |
| 338 } | 367 } |
| 339 | 368 |
| 340 void GoogleURLTrackerTest::ExpectDefaultURLs() const { | 369 void GoogleURLTrackerTest::ExpectDefaultURLs() const { |
| 341 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 370 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 342 EXPECT_EQ(GURL(), fetched_google_url()); | 371 EXPECT_EQ(GURL(), fetched_google_url()); |
| 343 } | 372 } |
| 344 | 373 |
| 345 void GoogleURLTrackerTest::ExpectListeningForCommit(int unique_id, | 374 void GoogleURLTrackerTest::ExpectListeningForCommit(intptr_t unique_id, |
| 346 bool listening) const { | 375 bool listening) { |
| 347 GoogleURLTracker::InfoBarMap::iterator i = | 376 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(unique_id); |
| 348 google_url_tracker_->infobar_map_.find( | 377 if (map_entry) { |
| 349 reinterpret_cast<InfoBarTabHelper*>(unique_id)); | 378 EXPECT_EQ(listening, google_url_tracker_->registrar_.IsRegistered( |
| 350 if (i == google_url_tracker_->infobar_map_.end()) { | 379 google_url_tracker_.get(), content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 380 map_entry->navigation_controller_source())); |
| 381 } else { |
| 351 EXPECT_FALSE(listening); | 382 EXPECT_FALSE(listening); |
| 352 return; | |
| 353 } | 383 } |
| 354 EXPECT_EQ(listening, google_url_tracker_->registrar_.IsRegistered( | |
| 355 google_url_tracker_.get(), content::NOTIFICATION_NAV_ENTRY_COMMITTED, | |
| 356 i->second.navigation_controller_source)); | |
| 357 } | 384 } |
| 358 | 385 |
| 386 GoogleURLTrackerInfoBarDelegate* GoogleURLTrackerTest::CreateTestInfoBar( |
| 387 InfoBarTabHelper* infobar_helper, |
| 388 GoogleURLTracker* google_url_tracker, |
| 389 const GURL& search_url) { |
| 390 return new TestInfoBarDelegate(this, infobar_helper, google_url_tracker, |
| 391 search_url); |
| 392 } |
| 393 |
| 394 |
| 395 // TestInfoBarDelegate -------------------------------------------------------- |
| 396 |
| 397 namespace { |
| 398 |
| 399 TestInfoBarDelegate::TestInfoBarDelegate(GoogleURLTrackerTest* test_harness, |
| 400 InfoBarTabHelper* infobar_helper, |
| 401 GoogleURLTracker* google_url_tracker, |
| 402 const GURL& search_url) |
| 403 : GoogleURLTrackerInfoBarDelegate(NULL, google_url_tracker, search_url), |
| 404 test_harness_(test_harness), |
| 405 infobar_helper_(infobar_helper) { |
| 406 } |
| 407 |
| 408 TestInfoBarDelegate::~TestInfoBarDelegate() { |
| 409 } |
| 410 |
| 411 void TestInfoBarDelegate::Update(const GURL& search_url) { |
| 412 set_search_url(search_url); |
| 413 set_pending_id(0); |
| 414 } |
| 415 |
| 416 void TestInfoBarDelegate::Close(bool redo_search) { |
| 417 test_harness_->OnInfoBarClosed(this, infobar_helper_); |
| 418 } |
| 419 |
| 420 } // namespace |
| 421 |
| 359 | 422 |
| 360 // Tests ---------------------------------------------------------------------- | 423 // Tests ---------------------------------------------------------------------- |
| 361 | 424 |
| 362 TEST_F(GoogleURLTrackerTest, DontFetchWhenNoOneRequestsCheck) { | 425 TEST_F(GoogleURLTrackerTest, DontFetchWhenNoOneRequestsCheck) { |
| 363 ExpectDefaultURLs(); | 426 ExpectDefaultURLs(); |
| 364 FinishSleep(); | 427 FinishSleep(); |
| 365 // No one called RequestServerCheck() so nothing should have happened. | 428 // No one called RequestServerCheck() so nothing should have happened. |
| 366 EXPECT_FALSE(GetFetcher()); | 429 EXPECT_FALSE(GetFetcher()); |
| 367 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 430 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
| 368 ExpectDefaultURLs(); | 431 ExpectDefaultURLs(); |
| 369 EXPECT_FALSE(observer_->notified()); | 432 EXPECT_FALSE(observer_notified()); |
| 370 } | 433 } |
| 371 | 434 |
| 372 TEST_F(GoogleURLTrackerTest, UpdateOnFirstRun) { | 435 TEST_F(GoogleURLTrackerTest, UpdateOnFirstRun) { |
| 373 RequestServerCheck(); | 436 RequestServerCheck(); |
| 374 EXPECT_FALSE(GetFetcher()); | 437 EXPECT_FALSE(GetFetcher()); |
| 375 ExpectDefaultURLs(); | 438 ExpectDefaultURLs(); |
| 376 EXPECT_FALSE(observer_->notified()); | 439 EXPECT_FALSE(observer_notified()); |
| 377 | 440 |
| 378 FinishSleep(); | 441 FinishSleep(); |
| 379 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 442 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
| 380 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 443 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
| 381 // GoogleURL should be updated, becase there was no last prompted URL. | 444 // GoogleURL should be updated, becase there was no last prompted URL. |
| 382 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 445 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
| 383 EXPECT_TRUE(observer_->notified()); | 446 EXPECT_TRUE(observer_notified()); |
| 384 } | 447 } |
| 385 | 448 |
| 386 TEST_F(GoogleURLTrackerTest, DontUpdateWhenUnchanged) { | 449 TEST_F(GoogleURLTrackerTest, DontUpdateWhenUnchanged) { |
| 387 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 450 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
| 388 | 451 |
| 389 RequestServerCheck(); | 452 RequestServerCheck(); |
| 390 EXPECT_FALSE(GetFetcher()); | 453 EXPECT_FALSE(GetFetcher()); |
| 391 ExpectDefaultURLs(); | 454 ExpectDefaultURLs(); |
| 392 EXPECT_FALSE(observer_->notified()); | 455 EXPECT_FALSE(observer_notified()); |
| 393 | 456 |
| 394 FinishSleep(); | 457 FinishSleep(); |
| 395 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 458 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
| 396 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 459 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
| 397 // GoogleURL should not be updated, because the fetched and prompted URLs | 460 // GoogleURL should not be updated, because the fetched and prompted URLs |
| 398 // match. | 461 // match. |
| 399 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 462 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 400 EXPECT_FALSE(observer_->notified()); | 463 EXPECT_FALSE(observer_notified()); |
| 401 } | 464 } |
| 402 | 465 |
| 403 TEST_F(GoogleURLTrackerTest, DontPromptOnBadReplies) { | 466 TEST_F(GoogleURLTrackerTest, DontPromptOnBadReplies) { |
| 404 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 467 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
| 405 | 468 |
| 406 RequestServerCheck(); | 469 RequestServerCheck(); |
| 407 EXPECT_FALSE(GetFetcher()); | 470 EXPECT_FALSE(GetFetcher()); |
| 408 ExpectDefaultURLs(); | 471 ExpectDefaultURLs(); |
| 409 EXPECT_FALSE(observer_->notified()); | 472 EXPECT_FALSE(observer_notified()); |
| 410 | 473 |
| 411 // Old-style domain string. | 474 // Old-style domain string. |
| 412 FinishSleep(); | 475 FinishSleep(); |
| 413 MockSearchDomainCheckResponse(".google.co.in"); | 476 MockSearchDomainCheckResponse(".google.co.in"); |
| 414 EXPECT_EQ(GURL(), fetched_google_url()); | 477 EXPECT_EQ(GURL(), fetched_google_url()); |
| 415 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 478 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 416 EXPECT_FALSE(observer_->notified()); | 479 EXPECT_FALSE(observer_notified()); |
| 417 SetNavigationPending(1, true); | 480 SetNavigationPending(1, true); |
| 418 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 481 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
| 419 EXPECT_TRUE(GetInfoBar(1) == NULL); | 482 EXPECT_TRUE(GetMapEntry(1) == NULL); |
| 420 | 483 |
| 421 // Bad subdomain. | 484 // Bad subdomain. |
| 422 NotifyIPAddressChanged(); | 485 NotifyIPAddressChanged(); |
| 423 MockSearchDomainCheckResponse("http://mail.google.com/"); | 486 MockSearchDomainCheckResponse("http://mail.google.com/"); |
| 424 EXPECT_EQ(GURL(), fetched_google_url()); | 487 EXPECT_EQ(GURL(), fetched_google_url()); |
| 425 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 488 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 426 EXPECT_FALSE(observer_->notified()); | 489 EXPECT_FALSE(observer_notified()); |
| 427 SetNavigationPending(1, true); | 490 SetNavigationPending(1, true); |
| 428 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 491 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
| 429 EXPECT_TRUE(GetInfoBar(1) == NULL); | 492 EXPECT_TRUE(GetMapEntry(1) == NULL); |
| 430 | 493 |
| 431 // Non-empty path. | 494 // Non-empty path. |
| 432 NotifyIPAddressChanged(); | 495 NotifyIPAddressChanged(); |
| 433 MockSearchDomainCheckResponse("http://www.google.com/search"); | 496 MockSearchDomainCheckResponse("http://www.google.com/search"); |
| 434 EXPECT_EQ(GURL(), fetched_google_url()); | 497 EXPECT_EQ(GURL(), fetched_google_url()); |
| 435 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 498 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 436 EXPECT_FALSE(observer_->notified()); | 499 EXPECT_FALSE(observer_notified()); |
| 437 SetNavigationPending(1, true); | 500 SetNavigationPending(1, true); |
| 438 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 501 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
| 439 EXPECT_TRUE(GetInfoBar(1) == NULL); | 502 EXPECT_TRUE(GetMapEntry(1) == NULL); |
| 440 | 503 |
| 441 // Non-empty query. | 504 // Non-empty query. |
| 442 NotifyIPAddressChanged(); | 505 NotifyIPAddressChanged(); |
| 443 MockSearchDomainCheckResponse("http://www.google.com/?q=foo"); | 506 MockSearchDomainCheckResponse("http://www.google.com/?q=foo"); |
| 444 EXPECT_EQ(GURL(), fetched_google_url()); | 507 EXPECT_EQ(GURL(), fetched_google_url()); |
| 445 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 508 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 446 EXPECT_FALSE(observer_->notified()); | 509 EXPECT_FALSE(observer_notified()); |
| 447 SetNavigationPending(1, true); | 510 SetNavigationPending(1, true); |
| 448 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 511 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
| 449 EXPECT_TRUE(GetInfoBar(1) == NULL); | 512 EXPECT_TRUE(GetMapEntry(1) == NULL); |
| 450 | 513 |
| 451 // Non-empty ref. | 514 // Non-empty ref. |
| 452 NotifyIPAddressChanged(); | 515 NotifyIPAddressChanged(); |
| 453 MockSearchDomainCheckResponse("http://www.google.com/#anchor"); | 516 MockSearchDomainCheckResponse("http://www.google.com/#anchor"); |
| 454 EXPECT_EQ(GURL(), fetched_google_url()); | 517 EXPECT_EQ(GURL(), fetched_google_url()); |
| 455 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 518 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 456 EXPECT_FALSE(observer_->notified()); | 519 EXPECT_FALSE(observer_notified()); |
| 457 SetNavigationPending(1, true); | 520 SetNavigationPending(1, true); |
| 458 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 521 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
| 459 EXPECT_TRUE(GetInfoBar(1) == NULL); | 522 EXPECT_TRUE(GetMapEntry(1) == NULL); |
| 460 | 523 |
| 461 // Complete garbage. | 524 // Complete garbage. |
| 462 NotifyIPAddressChanged(); | 525 NotifyIPAddressChanged(); |
| 463 MockSearchDomainCheckResponse("HJ)*qF)_*&@f1"); | 526 MockSearchDomainCheckResponse("HJ)*qF)_*&@f1"); |
| 464 EXPECT_EQ(GURL(), fetched_google_url()); | 527 EXPECT_EQ(GURL(), fetched_google_url()); |
| 465 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 528 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 466 EXPECT_FALSE(observer_->notified()); | 529 EXPECT_FALSE(observer_notified()); |
| 467 SetNavigationPending(1, true); | 530 SetNavigationPending(1, true); |
| 468 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 531 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
| 469 EXPECT_TRUE(GetInfoBar(1) == NULL); | 532 EXPECT_TRUE(GetMapEntry(1) == NULL); |
| 470 } | 533 } |
| 471 | 534 |
| 472 TEST_F(GoogleURLTrackerTest, UpdatePromptedURLOnReturnToPreviousLocation) { | 535 TEST_F(GoogleURLTrackerTest, UpdatePromptedURLOnReturnToPreviousLocation) { |
| 473 SetLastPromptedGoogleURL(GURL("http://www.google.co.jp/")); | 536 SetLastPromptedGoogleURL(GURL("http://www.google.co.jp/")); |
| 474 set_google_url(GURL("http://www.google.co.uk/")); | 537 set_google_url(GURL("http://www.google.co.uk/")); |
| 475 RequestServerCheck(); | 538 RequestServerCheck(); |
| 476 FinishSleep(); | 539 FinishSleep(); |
| 477 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 540 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
| 478 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 541 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
| 479 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 542 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
| 480 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 543 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 481 EXPECT_FALSE(observer_->notified()); | 544 EXPECT_FALSE(observer_notified()); |
| 482 } | 545 } |
| 483 | 546 |
| 484 TEST_F(GoogleURLTrackerTest, SilentlyAcceptSchemeChange) { | 547 TEST_F(GoogleURLTrackerTest, SilentlyAcceptSchemeChange) { |
| 485 // We should auto-accept changes to the current Google URL that merely change | 548 // We should auto-accept changes to the current Google URL that merely change |
| 486 // the scheme, regardless of what the last prompted URL was. | 549 // the scheme, regardless of what the last prompted URL was. |
| 487 SetLastPromptedGoogleURL(GURL("http://www.google.co.jp/")); | 550 SetLastPromptedGoogleURL(GURL("http://www.google.co.jp/")); |
| 488 set_google_url(GURL("http://www.google.co.uk/")); | 551 set_google_url(GURL("http://www.google.co.uk/")); |
| 489 RequestServerCheck(); | 552 RequestServerCheck(); |
| 490 FinishSleep(); | 553 FinishSleep(); |
| 491 MockSearchDomainCheckResponse("https://www.google.co.uk/"); | 554 MockSearchDomainCheckResponse("https://www.google.co.uk/"); |
| 492 EXPECT_EQ(GURL("https://www.google.co.uk/"), fetched_google_url()); | 555 EXPECT_EQ(GURL("https://www.google.co.uk/"), fetched_google_url()); |
| 493 EXPECT_EQ(GURL("https://www.google.co.uk/"), google_url()); | 556 EXPECT_EQ(GURL("https://www.google.co.uk/"), google_url()); |
| 494 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 557 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 495 EXPECT_TRUE(observer_->notified()); | 558 EXPECT_TRUE(observer_notified()); |
| 496 | 559 |
| 497 NotifyIPAddressChanged(); | 560 NotifyIPAddressChanged(); |
| 498 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 561 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
| 499 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 562 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
| 500 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 563 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
| 501 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 564 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 502 EXPECT_TRUE(observer_->notified()); | 565 EXPECT_TRUE(observer_notified()); |
| 503 } | 566 } |
| 504 | 567 |
| 505 TEST_F(GoogleURLTrackerTest, RefetchOnIPAddressChange) { | 568 TEST_F(GoogleURLTrackerTest, RefetchOnIPAddressChange) { |
| 506 RequestServerCheck(); | 569 RequestServerCheck(); |
| 507 FinishSleep(); | 570 FinishSleep(); |
| 508 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 571 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
| 509 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 572 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
| 510 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 573 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
| 511 EXPECT_TRUE(observer_->notified()); | 574 EXPECT_TRUE(observer_notified()); |
| 512 observer_->clear_notified(); | 575 clear_observer_notified(); |
| 513 | 576 |
| 514 NotifyIPAddressChanged(); | 577 NotifyIPAddressChanged(); |
| 515 MockSearchDomainCheckResponse("http://www.google.co.in/"); | 578 MockSearchDomainCheckResponse("http://www.google.co.in/"); |
| 516 EXPECT_EQ(GURL("http://www.google.co.in/"), fetched_google_url()); | 579 EXPECT_EQ(GURL("http://www.google.co.in/"), fetched_google_url()); |
| 517 // Just fetching a new URL shouldn't reset things without a prompt. | 580 // Just fetching a new URL shouldn't reset things without a prompt. |
| 518 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 581 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
| 519 EXPECT_FALSE(observer_->notified()); | 582 EXPECT_FALSE(observer_notified()); |
| 520 } | 583 } |
| 521 | 584 |
| 522 TEST_F(GoogleURLTrackerTest, DontRefetchWhenNoOneRequestsCheck) { | 585 TEST_F(GoogleURLTrackerTest, DontRefetchWhenNoOneRequestsCheck) { |
| 523 FinishSleep(); | 586 FinishSleep(); |
| 524 NotifyIPAddressChanged(); | 587 NotifyIPAddressChanged(); |
| 525 // No one called RequestServerCheck() so nothing should have happened. | 588 // No one called RequestServerCheck() so nothing should have happened. |
| 526 EXPECT_FALSE(GetFetcher()); | 589 EXPECT_FALSE(GetFetcher()); |
| 527 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 590 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
| 528 ExpectDefaultURLs(); | 591 ExpectDefaultURLs(); |
| 529 EXPECT_FALSE(observer_->notified()); | 592 EXPECT_FALSE(observer_notified()); |
| 530 } | 593 } |
| 531 | 594 |
| 532 TEST_F(GoogleURLTrackerTest, FetchOnLateRequest) { | 595 TEST_F(GoogleURLTrackerTest, FetchOnLateRequest) { |
| 533 FinishSleep(); | 596 FinishSleep(); |
| 534 NotifyIPAddressChanged(); | 597 NotifyIPAddressChanged(); |
| 535 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 598 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
| 536 | 599 |
| 537 RequestServerCheck(); | 600 RequestServerCheck(); |
| 538 // The first request for a check should trigger a fetch if it hasn't happened | 601 // The first request for a check should trigger a fetch if it hasn't happened |
| 539 // already. | 602 // already. |
| 540 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 603 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
| 541 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 604 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
| 542 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 605 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
| 543 EXPECT_TRUE(observer_->notified()); | 606 EXPECT_TRUE(observer_notified()); |
| 544 } | 607 } |
| 545 | 608 |
| 546 TEST_F(GoogleURLTrackerTest, DontFetchTwiceOnLateRequests) { | 609 TEST_F(GoogleURLTrackerTest, DontFetchTwiceOnLateRequests) { |
| 547 FinishSleep(); | 610 FinishSleep(); |
| 548 NotifyIPAddressChanged(); | 611 NotifyIPAddressChanged(); |
| 549 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 612 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
| 550 | 613 |
| 551 RequestServerCheck(); | 614 RequestServerCheck(); |
| 552 // The first request for a check should trigger a fetch if it hasn't happened | 615 // The first request for a check should trigger a fetch if it hasn't happened |
| 553 // already. | 616 // already. |
| 554 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 617 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
| 555 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 618 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
| 556 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 619 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
| 557 EXPECT_TRUE(observer_->notified()); | 620 EXPECT_TRUE(observer_notified()); |
| 558 observer_->clear_notified(); | 621 clear_observer_notified(); |
| 559 | 622 |
| 560 RequestServerCheck(); | 623 RequestServerCheck(); |
| 561 // The second request should be ignored. | 624 // The second request should be ignored. |
| 562 EXPECT_FALSE(GetFetcher()); | 625 EXPECT_FALSE(GetFetcher()); |
| 563 MockSearchDomainCheckResponse("http://www.google.co.in/"); | 626 MockSearchDomainCheckResponse("http://www.google.co.in/"); |
| 564 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 627 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
| 565 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 628 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
| 566 EXPECT_FALSE(observer_->notified()); | 629 EXPECT_FALSE(observer_notified()); |
| 567 } | 630 } |
| 568 | 631 |
| 569 TEST_F(GoogleURLTrackerTest, SearchingDoesNothingIfNoNeedToPrompt) { | 632 TEST_F(GoogleURLTrackerTest, SearchingDoesNothingIfNoNeedToPrompt) { |
| 570 RequestServerCheck(); | 633 RequestServerCheck(); |
| 571 FinishSleep(); | 634 FinishSleep(); |
| 572 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 635 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
| 573 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 636 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
| 574 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 637 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
| 575 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 638 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 576 EXPECT_TRUE(observer_->notified()); | 639 EXPECT_TRUE(observer_notified()); |
| 577 observer_->clear_notified(); | 640 clear_observer_notified(); |
| 578 | 641 |
| 579 SetNavigationPending(1, true); | 642 SetNavigationPending(1, true); |
| 580 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 643 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
| 581 TestInfoBarDelegate* infobar = GetInfoBar(1); | 644 EXPECT_TRUE(GetMapEntry(1) == NULL); |
| 582 EXPECT_TRUE(infobar == NULL); | |
| 583 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 645 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
| 584 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 646 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
| 585 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 647 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 586 EXPECT_FALSE(observer_->notified()); | 648 EXPECT_FALSE(observer_notified()); |
| 587 } | 649 } |
| 588 | 650 |
| 589 TEST_F(GoogleURLTrackerTest, TabClosedOnPendingSearch) { | 651 TEST_F(GoogleURLTrackerTest, TabClosedOnPendingSearch) { |
| 590 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 652 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
| 591 RequestServerCheck(); | 653 RequestServerCheck(); |
| 592 FinishSleep(); | 654 FinishSleep(); |
| 593 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 655 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
| 594 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 656 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 595 EXPECT_EQ(GURL("http://www.google.co.jp/"), fetched_google_url()); | 657 EXPECT_EQ(GURL("http://www.google.co.jp/"), fetched_google_url()); |
| 596 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 658 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 597 EXPECT_FALSE(observer_->notified()); | 659 EXPECT_FALSE(observer_notified()); |
| 598 | 660 |
| 599 SetNavigationPending(1, true); | 661 SetNavigationPending(1, true); |
| 600 TestInfoBarDelegate* infobar = GetInfoBar(1); | 662 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(1); |
| 601 ASSERT_FALSE(infobar == NULL); | 663 ASSERT_FALSE(map_entry == NULL); |
| 602 EXPECT_FALSE(infobar->showing()); | 664 EXPECT_FALSE(map_entry->has_infobar()); |
| 603 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 665 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 604 EXPECT_EQ(GURL("http://www.google.co.jp/"), infobar->new_google_url()); | |
| 605 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 666 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 606 EXPECT_FALSE(observer_->notified()); | 667 EXPECT_FALSE(observer_notified()); |
| 607 | 668 |
| 608 CloseTab(1); | 669 CloseTab(1); |
| 609 EXPECT_TRUE(GetInfoBar(1) == NULL); | 670 EXPECT_TRUE(GetMapEntry(1) == NULL); |
| 610 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 671 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 611 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 672 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 612 EXPECT_FALSE(observer_->notified()); | 673 EXPECT_FALSE(observer_notified()); |
| 613 } | 674 } |
| 614 | 675 |
| 615 TEST_F(GoogleURLTrackerTest, TabClosedOnCommittedSearch) { | 676 TEST_F(GoogleURLTrackerTest, TabClosedOnCommittedSearch) { |
| 616 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 677 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
| 617 RequestServerCheck(); | 678 RequestServerCheck(); |
| 618 FinishSleep(); | 679 FinishSleep(); |
| 619 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 680 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
| 620 | 681 |
| 621 SetNavigationPending(1, true); | 682 SetNavigationPending(1, true); |
| 622 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 683 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
| 623 TestInfoBarDelegate* infobar = GetInfoBar(1); | 684 EXPECT_FALSE(GetInfoBar(1) == NULL); |
| 624 ASSERT_FALSE(infobar == NULL); | |
| 625 EXPECT_TRUE(infobar->showing()); | |
| 626 | 685 |
| 627 CloseTab(1); | 686 CloseTab(1); |
| 628 EXPECT_TRUE(GetInfoBar(1) == NULL); | 687 EXPECT_TRUE(GetMapEntry(1) == NULL); |
| 629 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 688 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 630 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 689 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 631 EXPECT_FALSE(observer_->notified()); | 690 EXPECT_FALSE(observer_notified()); |
| 632 } | 691 } |
| 633 | 692 |
| 634 TEST_F(GoogleURLTrackerTest, InfobarClosed) { | 693 TEST_F(GoogleURLTrackerTest, InfoBarClosed) { |
| 635 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 694 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
| 636 RequestServerCheck(); | 695 RequestServerCheck(); |
| 637 FinishSleep(); | 696 FinishSleep(); |
| 638 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 697 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
| 639 | 698 |
| 640 SetNavigationPending(1, true); | 699 SetNavigationPending(1, true); |
| 641 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 700 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
| 642 TestInfoBarDelegate* infobar = GetInfoBar(1); | 701 GoogleURLTrackerInfoBarDelegate* infobar = GetInfoBar(1); |
| 643 ASSERT_FALSE(infobar == NULL); | 702 ASSERT_FALSE(infobar == NULL); |
| 644 | 703 |
| 645 infobar->InfoBarClosed(); | 704 infobar->Close(false); |
| 646 EXPECT_TRUE(GetInfoBar(1) == NULL); | 705 EXPECT_TRUE(GetMapEntry(1) == NULL); |
| 647 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 706 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 648 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 707 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 649 EXPECT_FALSE(observer_->notified()); | 708 EXPECT_FALSE(observer_notified()); |
| 650 } | 709 } |
| 651 | 710 |
| 652 TEST_F(GoogleURLTrackerTest, InfobarRefused) { | 711 TEST_F(GoogleURLTrackerTest, InfoBarRefused) { |
| 653 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 712 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
| 654 RequestServerCheck(); | 713 RequestServerCheck(); |
| 655 FinishSleep(); | 714 FinishSleep(); |
| 656 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 715 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
| 657 | 716 |
| 658 SetNavigationPending(1, true); | 717 SetNavigationPending(1, true); |
| 659 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 718 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
| 660 TestInfoBarDelegate* infobar = GetInfoBar(1); | 719 GoogleURLTrackerInfoBarDelegate* infobar = GetInfoBar(1); |
| 661 ASSERT_FALSE(infobar == NULL); | 720 ASSERT_FALSE(infobar == NULL); |
| 662 | 721 |
| 663 infobar->Cancel(); | 722 infobar->Cancel(); |
| 664 EXPECT_TRUE(GetInfoBar(1) == NULL); | 723 EXPECT_TRUE(GetMapEntry(1) == NULL); |
| 665 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 724 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 666 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); | 725 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); |
| 667 EXPECT_FALSE(observer_->notified()); | 726 EXPECT_FALSE(observer_notified()); |
| 668 } | 727 } |
| 669 | 728 |
| 670 TEST_F(GoogleURLTrackerTest, InfobarAccepted) { | 729 TEST_F(GoogleURLTrackerTest, InfoBarAccepted) { |
| 671 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 730 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
| 672 RequestServerCheck(); | 731 RequestServerCheck(); |
| 673 FinishSleep(); | 732 FinishSleep(); |
| 674 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 733 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
| 675 | 734 |
| 676 SetNavigationPending(1, true); | 735 SetNavigationPending(1, true); |
| 677 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 736 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
| 678 TestInfoBarDelegate* infobar = GetInfoBar(1); | 737 GoogleURLTrackerInfoBarDelegate* infobar = GetInfoBar(1); |
| 679 ASSERT_FALSE(infobar == NULL); | 738 ASSERT_FALSE(infobar == NULL); |
| 680 | 739 |
| 681 infobar->Accept(); | 740 infobar->Accept(); |
| 682 EXPECT_TRUE(GetInfoBar(1) == NULL); | 741 EXPECT_TRUE(GetMapEntry(1) == NULL); |
| 683 EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url()); | 742 EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url()); |
| 684 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); | 743 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); |
| 685 EXPECT_TRUE(observer_->notified()); | 744 EXPECT_TRUE(observer_notified()); |
| 686 } | 745 } |
| 687 | 746 |
| 688 TEST_F(GoogleURLTrackerTest, InfobarForInstant) { | 747 TEST_F(GoogleURLTrackerTest, InfoBarForInstant) { |
| 689 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 748 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
| 690 RequestServerCheck(); | 749 RequestServerCheck(); |
| 691 FinishSleep(); | 750 FinishSleep(); |
| 692 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 751 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
| 693 | 752 |
| 694 DoInstantNavigation(1, GURL("http://www.google.co.uk/search?q=test")); | 753 DoInstantNavigation(1, GURL("http://www.google.co.uk/search?q=test")); |
| 695 TestInfoBarDelegate* infobar = GetInfoBar(1); | 754 EXPECT_FALSE(GetInfoBar(1) == NULL); |
| 696 ASSERT_FALSE(infobar == NULL); | |
| 697 EXPECT_TRUE(infobar->showing()); | |
| 698 } | 755 } |
| 699 | 756 |
| 700 TEST_F(GoogleURLTrackerTest, FetchesCanAutomaticallyCloseInfobars) { | 757 TEST_F(GoogleURLTrackerTest, FetchesCanAutomaticallyCloseInfoBars) { |
| 701 RequestServerCheck(); | 758 RequestServerCheck(); |
| 702 FinishSleep(); | 759 FinishSleep(); |
| 703 MockSearchDomainCheckResponse(google_url().spec()); | 760 MockSearchDomainCheckResponse(google_url().spec()); |
| 704 | 761 |
| 705 // Re-fetching the accepted URL after showing an infobar for another URL | 762 // Re-fetching the accepted URL after showing an infobar for another URL |
| 706 // should close the infobar. | 763 // should close the infobar. |
| 707 NotifyIPAddressChanged(); | 764 NotifyIPAddressChanged(); |
| 708 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 765 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
| 709 SetNavigationPending(1, true); | 766 SetNavigationPending(1, true); |
| 710 CommitSearch(1, GURL("http://www.google.com/search?q=test")); | 767 CommitSearch(1, GURL("http://www.google.com/search?q=test")); |
| 711 EXPECT_FALSE(GetInfoBar(1) == NULL); | 768 EXPECT_FALSE(GetInfoBar(1) == NULL); |
| 712 NotifyIPAddressChanged(); | 769 NotifyIPAddressChanged(); |
| 713 MockSearchDomainCheckResponse(google_url().spec()); | 770 MockSearchDomainCheckResponse(google_url().spec()); |
| 714 EXPECT_EQ(google_url(), GetLastPromptedGoogleURL()); | 771 EXPECT_EQ(google_url(), GetLastPromptedGoogleURL()); |
| 715 EXPECT_TRUE(GetInfoBar(1) == NULL); | 772 EXPECT_TRUE(GetMapEntry(1) == NULL); |
| 716 | 773 |
| 717 // As should fetching a URL that differs from the accepted only by the scheme. | 774 // As should fetching a URL that differs from the accepted only by the scheme. |
| 718 NotifyIPAddressChanged(); | 775 NotifyIPAddressChanged(); |
| 719 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 776 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
| 720 SetNavigationPending(1, true); | 777 SetNavigationPending(1, true); |
| 721 CommitSearch(1, GURL("http://www.google.com/search?q=test")); | 778 CommitSearch(1, GURL("http://www.google.com/search?q=test")); |
| 722 EXPECT_FALSE(GetInfoBar(1) == NULL); | 779 EXPECT_FALSE(GetInfoBar(1) == NULL); |
| 723 NotifyIPAddressChanged(); | 780 NotifyIPAddressChanged(); |
| 724 url_canon::Replacements<char> replacements; | 781 url_canon::Replacements<char> replacements; |
| 725 const std::string& scheme("https"); | 782 const std::string& scheme("https"); |
| 726 replacements.SetScheme(scheme.data(), | 783 replacements.SetScheme(scheme.data(), |
| 727 url_parse::Component(0, scheme.length())); | 784 url_parse::Component(0, scheme.length())); |
| 728 GURL new_google_url(google_url().ReplaceComponents(replacements)); | 785 GURL new_google_url(google_url().ReplaceComponents(replacements)); |
| 729 MockSearchDomainCheckResponse(new_google_url.spec()); | 786 MockSearchDomainCheckResponse(new_google_url.spec()); |
| 730 EXPECT_EQ(new_google_url, GetLastPromptedGoogleURL()); | 787 EXPECT_EQ(new_google_url, GetLastPromptedGoogleURL()); |
| 731 EXPECT_TRUE(GetInfoBar(1) == NULL); | 788 EXPECT_TRUE(GetMapEntry(1) == NULL); |
| 732 | 789 |
| 733 // As should re-fetching the last prompted URL. | 790 // As should re-fetching the last prompted URL. |
| 734 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 791 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
| 735 NotifyIPAddressChanged(); | 792 NotifyIPAddressChanged(); |
| 736 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 793 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
| 737 SetNavigationPending(1, true); | 794 SetNavigationPending(1, true); |
| 738 CommitSearch(1, GURL("http://www.google.com/search?q=test")); | 795 CommitSearch(1, GURL("http://www.google.com/search?q=test")); |
| 739 EXPECT_FALSE(GetInfoBar(1) == NULL); | 796 EXPECT_FALSE(GetInfoBar(1) == NULL); |
| 740 NotifyIPAddressChanged(); | 797 NotifyIPAddressChanged(); |
| 741 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 798 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
| 742 EXPECT_EQ(new_google_url, google_url()); | 799 EXPECT_EQ(new_google_url, google_url()); |
| 743 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 800 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 744 EXPECT_TRUE(GetInfoBar(1) == NULL); | 801 EXPECT_TRUE(GetMapEntry(1) == NULL); |
| 745 | 802 |
| 746 // And one that differs from the last prompted URL only by the scheme. | 803 // And one that differs from the last prompted URL only by the scheme. |
| 747 NotifyIPAddressChanged(); | 804 NotifyIPAddressChanged(); |
| 748 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 805 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
| 749 SetNavigationPending(1, true); | 806 SetNavigationPending(1, true); |
| 750 CommitSearch(1, GURL("http://www.google.com/search?q=test")); | 807 CommitSearch(1, GURL("http://www.google.com/search?q=test")); |
| 751 EXPECT_FALSE(GetInfoBar(1) == NULL); | 808 EXPECT_FALSE(GetInfoBar(1) == NULL); |
| 752 NotifyIPAddressChanged(); | 809 NotifyIPAddressChanged(); |
| 753 MockSearchDomainCheckResponse("https://www.google.co.uk/"); | 810 MockSearchDomainCheckResponse("https://www.google.co.uk/"); |
| 754 EXPECT_EQ(new_google_url, google_url()); | 811 EXPECT_EQ(new_google_url, google_url()); |
| 755 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 812 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 756 EXPECT_TRUE(GetInfoBar(1) == NULL); | 813 EXPECT_TRUE(GetMapEntry(1) == NULL); |
| 757 | 814 |
| 758 // And fetching a different URL entirely. | 815 // And fetching a different URL entirely. |
| 759 NotifyIPAddressChanged(); | 816 NotifyIPAddressChanged(); |
| 760 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 817 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
| 761 SetNavigationPending(1, true); | 818 SetNavigationPending(1, true); |
| 762 CommitSearch(1, GURL("http://www.google.com/search?q=test")); | 819 CommitSearch(1, GURL("http://www.google.com/search?q=test")); |
| 763 EXPECT_FALSE(GetInfoBar(1) == NULL); | 820 EXPECT_FALSE(GetInfoBar(1) == NULL); |
| 764 NotifyIPAddressChanged(); | 821 NotifyIPAddressChanged(); |
| 765 MockSearchDomainCheckResponse("https://www.google.co.in/"); | 822 MockSearchDomainCheckResponse("https://www.google.co.in/"); |
| 766 EXPECT_EQ(new_google_url, google_url()); | 823 EXPECT_EQ(new_google_url, google_url()); |
| 767 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 824 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 768 EXPECT_TRUE(GetInfoBar(1) == NULL); | 825 EXPECT_TRUE(GetMapEntry(1) == NULL); |
| 769 } | 826 } |
| 770 | 827 |
| 771 TEST_F(GoogleURLTrackerTest, ResetInfobarGoogleURLs) { | 828 TEST_F(GoogleURLTrackerTest, ResetInfoBarGoogleURLs) { |
| 772 RequestServerCheck(); | 829 RequestServerCheck(); |
| 773 FinishSleep(); | 830 FinishSleep(); |
| 774 MockSearchDomainCheckResponse(google_url().spec()); | 831 MockSearchDomainCheckResponse(google_url().spec()); |
| 775 | 832 |
| 776 NotifyIPAddressChanged(); | 833 NotifyIPAddressChanged(); |
| 777 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 834 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
| 778 SetNavigationPending(1, true); | 835 SetNavigationPending(1, true); |
| 779 TestInfoBarDelegate* infobar = GetInfoBar(1); | 836 CommitSearch(1, GURL("http://www.google.com/search?q=test")); |
| 837 GoogleURLTrackerInfoBarDelegate* infobar = GetInfoBar(1); |
| 780 ASSERT_FALSE(infobar == NULL); | 838 ASSERT_FALSE(infobar == NULL); |
| 781 EXPECT_EQ(GURL("http://www.google.co.uk/"), infobar->new_google_url()); | 839 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
| 782 | 840 |
| 783 // If while an infobar is pending we fetch a new URL that differs from the | 841 // If while an infobar is showing we fetch a new URL that differs from the |
| 784 // infobar's only by scheme, the infobar should stay pending but have its | 842 // infobar's only by scheme, the infobar should stay showing. |
| 785 // Google URL reset. | |
| 786 NotifyIPAddressChanged(); | 843 NotifyIPAddressChanged(); |
| 787 MockSearchDomainCheckResponse("https://www.google.co.uk/"); | 844 MockSearchDomainCheckResponse("https://www.google.co.uk/"); |
| 788 TestInfoBarDelegate* new_infobar = GetInfoBar(1); | 845 EXPECT_EQ(infobar, GetInfoBar(1)); |
| 789 ASSERT_FALSE(new_infobar == NULL); | 846 EXPECT_EQ(GURL("https://www.google.co.uk/"), fetched_google_url()); |
| 790 EXPECT_EQ(infobar, new_infobar); | |
| 791 EXPECT_EQ(GURL("https://www.google.co.uk/"), new_infobar->new_google_url()); | |
| 792 | |
| 793 // Same with an infobar that is showing. | |
| 794 CommitSearch(1, GURL("http://www.google.com/search?q=test")); | |
| 795 EXPECT_TRUE(infobar->showing()); | |
| 796 NotifyIPAddressChanged(); | |
| 797 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | |
| 798 new_infobar = GetInfoBar(1); | |
| 799 ASSERT_FALSE(new_infobar == NULL); | |
| 800 EXPECT_EQ(infobar, new_infobar); | |
| 801 EXPECT_EQ(GURL("http://www.google.co.uk/"), infobar->new_google_url()); | |
| 802 EXPECT_TRUE(infobar->showing()); | |
| 803 } | 847 } |
| 804 | 848 |
| 805 TEST_F(GoogleURLTrackerTest, NavigationsAfterPendingSearch) { | 849 TEST_F(GoogleURLTrackerTest, NavigationsAfterPendingSearch) { |
| 806 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 850 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
| 807 RequestServerCheck(); | 851 RequestServerCheck(); |
| 808 FinishSleep(); | 852 FinishSleep(); |
| 809 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 853 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
| 810 | 854 |
| 811 // A pending non-search after a pending search should close the infobar. | 855 // A pending non-search after a pending search should delete the map entry. |
| 812 SetNavigationPending(1, true); | 856 SetNavigationPending(1, true); |
| 813 TestInfoBarDelegate* infobar = GetInfoBar(1); | 857 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(1); |
| 814 ASSERT_FALSE(infobar == NULL); | 858 ASSERT_FALSE(map_entry == NULL); |
| 815 EXPECT_FALSE(infobar->showing()); | 859 EXPECT_FALSE(map_entry->has_infobar()); |
| 816 SetNavigationPending(1, false); | 860 SetNavigationPending(1, false); |
| 817 infobar = GetInfoBar(1); | 861 EXPECT_TRUE(GetMapEntry(1) == NULL); |
| 818 EXPECT_TRUE(infobar == NULL); | |
| 819 | 862 |
| 820 // A pending search after a pending search should leave the infobar alive. | 863 // A pending search after a pending search should leave the map entry alive. |
| 821 SetNavigationPending(1, true); | 864 SetNavigationPending(1, true); |
| 822 infobar = GetInfoBar(1); | 865 map_entry = GetMapEntry(1); |
| 823 ASSERT_FALSE(infobar == NULL); | 866 ASSERT_FALSE(map_entry == NULL); |
| 824 EXPECT_FALSE(infobar->showing()); | 867 EXPECT_FALSE(map_entry->has_infobar()); |
| 825 SetNavigationPending(1, true); | 868 SetNavigationPending(1, true); |
| 826 TestInfoBarDelegate* new_infobar = GetInfoBar(1); | 869 ASSERT_EQ(map_entry, GetMapEntry(1)); |
| 827 ASSERT_FALSE(new_infobar == NULL); | 870 EXPECT_FALSE(map_entry->has_infobar()); |
| 828 EXPECT_EQ(infobar, new_infobar); | |
| 829 EXPECT_FALSE(infobar->showing()); | |
| 830 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); | 871 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); |
| 831 | 872 |
| 832 // Committing this search should show the infobar. | 873 // Committing this search should show an infobar. |
| 833 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test2")); | 874 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test2")); |
| 834 EXPECT_TRUE(infobar->showing()); | 875 EXPECT_TRUE(map_entry->has_infobar()); |
| 835 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 876 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 836 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 877 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 837 EXPECT_FALSE(observer_->notified()); | 878 EXPECT_FALSE(observer_notified()); |
| 838 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); | 879 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); |
| 839 } | 880 } |
| 840 | 881 |
| 841 TEST_F(GoogleURLTrackerTest, NavigationsAfterCommittedSearch) { | 882 TEST_F(GoogleURLTrackerTest, NavigationsAfterCommittedSearch) { |
| 842 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 883 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
| 843 RequestServerCheck(); | 884 RequestServerCheck(); |
| 844 FinishSleep(); | 885 FinishSleep(); |
| 845 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 886 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
| 846 SetNavigationPending(1, true); | 887 SetNavigationPending(1, true); |
| 847 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 888 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
| 848 TestInfoBarDelegate* infobar = GetInfoBar(1); | 889 GoogleURLTrackerInfoBarDelegate* infobar = GetInfoBar(1); |
| 849 ASSERT_FALSE(infobar == NULL); | 890 ASSERT_FALSE(infobar == NULL); |
| 850 EXPECT_TRUE(infobar->showing()); | |
| 851 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); | 891 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); |
| 852 | 892 |
| 853 // A pending non-search on a visible infobar should basically do nothing. | 893 // A pending non-search on a visible infobar should basically do nothing. |
| 854 SetNavigationPending(1, false); | 894 SetNavigationPending(1, false); |
| 855 TestInfoBarDelegate* new_infobar = GetInfoBar(1); | 895 ASSERT_EQ(infobar, GetInfoBar(1)); |
| 856 ASSERT_FALSE(new_infobar == NULL); | |
| 857 EXPECT_EQ(infobar, new_infobar); | |
| 858 EXPECT_TRUE(infobar->showing()); | |
| 859 EXPECT_EQ(0, infobar->pending_id()); | 896 EXPECT_EQ(0, infobar->pending_id()); |
| 860 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); | 897 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); |
| 861 | 898 |
| 862 // As should another pending non-search after the first. | 899 // As should another pending non-search after the first. |
| 863 SetNavigationPending(1, false); | 900 SetNavigationPending(1, false); |
| 864 new_infobar = GetInfoBar(1); | 901 ASSERT_EQ(infobar, GetInfoBar(1)); |
| 865 ASSERT_FALSE(new_infobar == NULL); | |
| 866 EXPECT_EQ(infobar, new_infobar); | |
| 867 EXPECT_TRUE(infobar->showing()); | |
| 868 EXPECT_EQ(0, infobar->pending_id()); | 902 EXPECT_EQ(0, infobar->pending_id()); |
| 869 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); | 903 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); |
| 870 | 904 |
| 871 // Committing this non-search should close the infobar. The control flow in | 905 // Committing this non-search should close the infobar. The control flow in |
| 872 // these tests is not really comparable to in the real browser, but at least a | 906 // these tests is not really comparable to in the real browser, but at least a |
| 873 // few sanity-checks will be performed. | 907 // few sanity-checks will be performed. |
| 874 ASSERT_NO_FATAL_FAILURE(CommitNonSearch(1)); | 908 ASSERT_NO_FATAL_FAILURE(CommitNonSearch(1)); |
| 875 new_infobar = GetInfoBar(1); | 909 EXPECT_TRUE(GetMapEntry(1) == NULL); |
| 876 EXPECT_TRUE(new_infobar == NULL); | |
| 877 | 910 |
| 878 // A pending search on a visible infobar should cause the infobar to listen | 911 // A pending search on a visible infobar should cause the infobar to listen |
| 879 // for the search to commit. | 912 // for the search to commit. |
| 880 SetNavigationPending(1, true); | 913 SetNavigationPending(1, true); |
| 881 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 914 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
| 882 infobar = GetInfoBar(1); | 915 infobar = GetInfoBar(1); |
| 883 ASSERT_FALSE(infobar == NULL); | 916 ASSERT_FALSE(infobar == NULL); |
| 884 EXPECT_TRUE(infobar->showing()); | |
| 885 SetNavigationPending(1, true); | 917 SetNavigationPending(1, true); |
| 886 new_infobar = GetInfoBar(1); | 918 ASSERT_EQ(infobar, GetInfoBar(1)); |
| 887 ASSERT_FALSE(new_infobar == NULL); | |
| 888 EXPECT_EQ(infobar, new_infobar); | |
| 889 EXPECT_TRUE(infobar->showing()); | |
| 890 EXPECT_EQ(1, infobar->pending_id()); | 919 EXPECT_EQ(1, infobar->pending_id()); |
| 891 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); | 920 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); |
| 892 | 921 |
| 893 // But a non-search after this should cancel that state. | 922 // But a non-search after this should cancel that state. |
| 894 SetNavigationPending(1, false); | 923 SetNavigationPending(1, false); |
| 895 new_infobar = GetInfoBar(1); | 924 ASSERT_EQ(infobar, GetInfoBar(1)); |
| 896 ASSERT_FALSE(new_infobar == NULL); | |
| 897 EXPECT_EQ(infobar, new_infobar); | |
| 898 EXPECT_TRUE(infobar->showing()); | |
| 899 EXPECT_EQ(0, infobar->pending_id()); | 925 EXPECT_EQ(0, infobar->pending_id()); |
| 900 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); | 926 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); |
| 901 | 927 |
| 902 // Another pending search after the non-search should put us back into | 928 // Another pending search after the non-search should put us back into |
| 903 // "waiting for commit" mode. | 929 // "waiting for commit" mode. |
| 904 SetNavigationPending(1, true); | 930 SetNavigationPending(1, true); |
| 905 new_infobar = GetInfoBar(1); | 931 ASSERT_EQ(infobar, GetInfoBar(1)); |
| 906 ASSERT_FALSE(new_infobar == NULL); | |
| 907 EXPECT_EQ(infobar, new_infobar); | |
| 908 EXPECT_TRUE(infobar->showing()); | |
| 909 EXPECT_EQ(1, infobar->pending_id()); | 932 EXPECT_EQ(1, infobar->pending_id()); |
| 910 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); | 933 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); |
| 911 | 934 |
| 912 // A second pending search after the first should not really change anything. | 935 // A second pending search after the first should not really change anything. |
| 913 SetNavigationPending(1, true); | 936 SetNavigationPending(1, true); |
| 914 new_infobar = GetInfoBar(1); | 937 ASSERT_EQ(infobar, GetInfoBar(1)); |
| 915 ASSERT_FALSE(new_infobar == NULL); | |
| 916 EXPECT_EQ(infobar, new_infobar); | |
| 917 EXPECT_TRUE(infobar->showing()); | |
| 918 EXPECT_EQ(1, infobar->pending_id()); | 938 EXPECT_EQ(1, infobar->pending_id()); |
| 919 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); | 939 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); |
| 920 | 940 |
| 921 // Committing this search should change the visible infobar's search_url. | 941 // Committing this search should change the visible infobar's search_url. |
| 922 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test2")); | 942 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test2")); |
| 923 new_infobar = GetInfoBar(1); | 943 ASSERT_EQ(infobar, GetInfoBar(1)); |
| 924 ASSERT_FALSE(new_infobar == NULL); | 944 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test2"), |
| 925 EXPECT_EQ(infobar, new_infobar); | 945 infobar->search_url()); |
| 926 EXPECT_TRUE(infobar->showing()); | |
| 927 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test2"), infobar->search_url(
)); | |
| 928 EXPECT_EQ(0, infobar->pending_id()); | 946 EXPECT_EQ(0, infobar->pending_id()); |
| 929 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); | 947 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); |
| 930 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 948 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 931 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 949 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 932 EXPECT_FALSE(observer_->notified()); | 950 EXPECT_FALSE(observer_notified()); |
| 933 } | 951 } |
| 934 | 952 |
| 935 TEST_F(GoogleURLTrackerTest, MultipleInfobars) { | 953 TEST_F(GoogleURLTrackerTest, MultipleMapEntries) { |
| 936 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 954 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
| 937 RequestServerCheck(); | 955 RequestServerCheck(); |
| 938 FinishSleep(); | 956 FinishSleep(); |
| 939 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 957 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
| 940 | 958 |
| 941 SetNavigationPending(1, true); | 959 SetNavigationPending(1, true); |
| 942 TestInfoBarDelegate* infobar = GetInfoBar(1); | 960 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(1); |
| 943 ASSERT_FALSE(infobar == NULL); | 961 ASSERT_FALSE(map_entry == NULL); |
| 944 EXPECT_FALSE(infobar->showing()); | 962 EXPECT_FALSE(map_entry->has_infobar()); |
| 945 | 963 |
| 946 SetNavigationPending(2, true); | 964 SetNavigationPending(2, true); |
| 947 CommitSearch(2, GURL("http://www.google.co.uk/search?q=test2")); | 965 CommitSearch(2, GURL("http://www.google.co.uk/search?q=test2")); |
| 948 TestInfoBarDelegate* infobar2 = GetInfoBar(2); | 966 GoogleURLTrackerInfoBarDelegate* infobar2 = GetInfoBar(2); |
| 949 ASSERT_FALSE(infobar2 == NULL); | 967 ASSERT_FALSE(infobar2 == NULL); |
| 950 EXPECT_TRUE(infobar2->showing()); | |
| 951 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test2"), | 968 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test2"), |
| 952 infobar2->search_url()); | 969 infobar2->search_url()); |
| 953 | 970 |
| 954 SetNavigationPending(3, true); | 971 SetNavigationPending(3, true); |
| 955 TestInfoBarDelegate* infobar3 = GetInfoBar(3); | 972 GoogleURLTrackerMapEntry* map_entry3 = GetMapEntry(3); |
| 956 ASSERT_FALSE(infobar3 == NULL); | 973 ASSERT_FALSE(map_entry3 == NULL); |
| 957 EXPECT_FALSE(infobar3->showing()); | 974 EXPECT_FALSE(map_entry3->has_infobar()); |
| 958 | 975 |
| 959 SetNavigationPending(4, true); | 976 SetNavigationPending(4, true); |
| 960 CommitSearch(4, GURL("http://www.google.co.uk/search?q=test4")); | 977 CommitSearch(4, GURL("http://www.google.co.uk/search?q=test4")); |
| 961 TestInfoBarDelegate* infobar4 = GetInfoBar(4); | 978 GoogleURLTrackerInfoBarDelegate* infobar4 = GetInfoBar(4); |
| 962 ASSERT_FALSE(infobar4 == NULL); | 979 ASSERT_FALSE(infobar4 == NULL); |
| 963 EXPECT_TRUE(infobar4->showing()); | |
| 964 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test4"), | 980 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test4"), |
| 965 infobar4->search_url()); | 981 infobar4->search_url()); |
| 966 | 982 |
| 967 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 983 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
| 968 EXPECT_TRUE(infobar->showing()); | 984 EXPECT_TRUE(map_entry->has_infobar()); |
| 969 | 985 |
| 970 infobar2->InfoBarClosed(); | 986 infobar2->Close(false); |
| 971 EXPECT_TRUE(GetInfoBar(2) == NULL); | 987 EXPECT_TRUE(GetMapEntry(2) == NULL); |
| 972 EXPECT_FALSE(observer_->notified()); | 988 EXPECT_FALSE(observer_notified()); |
| 973 | 989 |
| 974 infobar4->Accept(); | 990 infobar4->Accept(); |
| 975 EXPECT_TRUE(GetInfoBar(1) == NULL); | 991 EXPECT_TRUE(GetMapEntry(1) == NULL); |
| 976 EXPECT_TRUE(GetInfoBar(3) == NULL); | 992 EXPECT_TRUE(GetMapEntry(3) == NULL); |
| 977 EXPECT_TRUE(GetInfoBar(4) == NULL); | 993 EXPECT_TRUE(GetMapEntry(4) == NULL); |
| 978 EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url()); | 994 EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url()); |
| 979 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); | 995 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); |
| 980 EXPECT_TRUE(observer_->notified()); | 996 EXPECT_TRUE(observer_notified()); |
| 981 } | 997 } |
| 982 | 998 |
| 983 TEST_F(GoogleURLTrackerTest, IgnoreIrrelevantInstantNavigation) { | 999 TEST_F(GoogleURLTrackerTest, IgnoreIrrelevantInstantNavigation) { |
| 984 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 1000 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
| 985 RequestServerCheck(); | 1001 RequestServerCheck(); |
| 986 FinishSleep(); | 1002 FinishSleep(); |
| 987 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 1003 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
| 988 | 1004 |
| 989 // Starting a search pending on any tab should cause us to listen for pending | 1005 // Starting a search pending on any tab should cause us to listen for pending |
| 990 // and instant navigations on all tabs, but we should ignore these when they | 1006 // and instant navigations on all tabs, but we should ignore these when they |
| 991 // are for tabs that we don't care about. | 1007 // are for tabs that we don't care about. |
| 992 SetNavigationPending(1, true); | 1008 SetNavigationPending(1, true); |
| 993 TestInfoBarDelegate* infobar = GetInfoBar(1); | 1009 EXPECT_FALSE(GetMapEntry(1) == NULL); |
| 994 ASSERT_FALSE(infobar == NULL); | |
| 995 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); | 1010 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); |
| 996 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(2, false)); | 1011 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(2, false)); |
| 997 | 1012 |
| 998 DoInstantNavigation(2, GURL()); | 1013 DoInstantNavigation(2, GURL()); |
| 999 TestInfoBarDelegate* infobar2 = GetInfoBar(2); | 1014 EXPECT_TRUE(GetMapEntry(2) == NULL); |
| 1000 ASSERT_TRUE(infobar2 == NULL); | |
| 1001 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); | 1015 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); |
| 1002 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(2, false)); | 1016 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(2, false)); |
| 1003 } | 1017 } |
| 1004 | 1018 |
| 1005 TEST_F(GoogleURLTrackerTest, IgnoreIrrelevantNavigation) { | 1019 TEST_F(GoogleURLTrackerTest, IgnoreIrrelevantNavigation) { |
| 1006 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 1020 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
| 1007 RequestServerCheck(); | 1021 RequestServerCheck(); |
| 1008 FinishSleep(); | 1022 FinishSleep(); |
| 1009 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 1023 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
| 1010 | 1024 |
| 1011 // This tests a particularly gnarly sequence of events that used to cause us | 1025 // This tests a particularly gnarly sequence of events that used to cause us |
| 1012 // to erroneously listen for a non-search navigation to commit. | 1026 // to erroneously listen for a non-search navigation to commit. |
| 1013 SetNavigationPending(1, true); | 1027 SetNavigationPending(1, true); |
| 1014 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 1028 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
| 1015 SetNavigationPending(2, true); | 1029 SetNavigationPending(2, true); |
| 1016 CommitSearch(2, GURL("http://www.google.co.uk/search?q=test2")); | 1030 CommitSearch(2, GURL("http://www.google.co.uk/search?q=test2")); |
| 1017 TestInfoBarDelegate* infobar = GetInfoBar(1); | 1031 EXPECT_FALSE(GetInfoBar(1) == NULL); |
| 1018 ASSERT_FALSE(infobar == NULL); | 1032 GoogleURLTrackerInfoBarDelegate* infobar2 = GetInfoBar(2); |
| 1019 EXPECT_TRUE(infobar->showing()); | |
| 1020 TestInfoBarDelegate* infobar2 = GetInfoBar(2); | |
| 1021 ASSERT_FALSE(infobar2 == NULL); | 1033 ASSERT_FALSE(infobar2 == NULL); |
| 1022 EXPECT_TRUE(infobar2->showing()); | |
| 1023 SetNavigationPending(1, true); | 1034 SetNavigationPending(1, true); |
| 1024 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); | 1035 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); |
| 1025 infobar2->InfoBarClosed(); | 1036 infobar2->Close(false); |
| 1026 SetNavigationPending(1, false); | 1037 SetNavigationPending(1, false); |
| 1027 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); | 1038 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); |
| 1028 } | 1039 } |
| OLD | NEW |