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