| 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" |
| 6 |
| 7 #include <set> |
| 8 #include <string> |
| 9 |
| 5 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 6 #include "chrome/browser/infobars/infobar_delegate.h" | 11 #include "chrome/browser/infobars/infobar_delegate.h" |
| 7 #include "chrome/browser/google/google_url_tracker.h" | |
| 8 #include "chrome/browser/google/google_url_tracker_factory.h" | 12 #include "chrome/browser/google/google_url_tracker_factory.h" |
| 9 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
| 10 #include "chrome/common/chrome_notification_types.h" | 14 #include "chrome/common/chrome_notification_types.h" |
| 11 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
| 12 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
| 13 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
| 14 #include "content/public/common/url_fetcher.h" | 18 #include "content/public/common/url_fetcher.h" |
| 15 #include "content/test/test_browser_thread.h" | 19 #include "content/test/test_browser_thread.h" |
| 16 #include "content/test/test_url_fetcher_factory.h" | 20 #include "content/test/test_url_fetcher_factory.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 // test_url_fetcher_factory.h). | 146 // test_url_fetcher_factory.h). |
| 143 MessageLoop message_loop_; | 147 MessageLoop message_loop_; |
| 144 content::TestBrowserThread io_thread_; | 148 content::TestBrowserThread io_thread_; |
| 145 // Creating this allows us to call | 149 // Creating this allows us to call |
| 146 // net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(). | 150 // net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(). |
| 147 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | 151 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
| 148 TestURLFetcherFactory fetcher_factory_; | 152 TestURLFetcherFactory fetcher_factory_; |
| 149 content::NotificationRegistrar registrar_; | 153 content::NotificationRegistrar registrar_; |
| 150 TestingProfile profile_; | 154 TestingProfile profile_; |
| 151 scoped_ptr<GoogleURLTracker> google_url_tracker_; | 155 scoped_ptr<GoogleURLTracker> google_url_tracker_; |
| 156 // This tracks the different "tabs" a test has "opened", so we can close them |
| 157 // properly before shutting down |google_url_tracker_|, which expects that. |
| 158 std::set<int> unique_ids_seen_; |
| 152 }; | 159 }; |
| 153 | 160 |
| 154 GoogleURLTrackerTest::GoogleURLTrackerTest() | 161 GoogleURLTrackerTest::GoogleURLTrackerTest() |
| 155 : observer_(new TestNotificationObserver), | 162 : observer_(new TestNotificationObserver), |
| 156 message_loop_(MessageLoop::TYPE_IO), | 163 message_loop_(MessageLoop::TYPE_IO), |
| 157 io_thread_(content::BrowserThread::IO, &message_loop_) { | 164 io_thread_(content::BrowserThread::IO, &message_loop_) { |
| 158 GoogleURLTrackerFactory::GetInstance()->RegisterUserPrefsOnProfile(&profile_); | 165 GoogleURLTrackerFactory::GetInstance()->RegisterUserPrefsOnProfile(&profile_); |
| 159 } | 166 } |
| 160 | 167 |
| 161 GoogleURLTrackerTest::~GoogleURLTrackerTest() { | 168 GoogleURLTrackerTest::~GoogleURLTrackerTest() { |
| 162 } | 169 } |
| 163 | 170 |
| 164 void GoogleURLTrackerTest::SetUp() { | 171 void GoogleURLTrackerTest::SetUp() { |
| 165 network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock()); | 172 network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock()); |
| 166 google_url_tracker_.reset( | 173 google_url_tracker_.reset( |
| 167 new GoogleURLTracker(&profile_, GoogleURLTracker::UNIT_TEST_MODE)); | 174 new GoogleURLTracker(&profile_, GoogleURLTracker::UNIT_TEST_MODE)); |
| 168 google_url_tracker_->infobar_creator_ = &CreateTestInfobar; | 175 google_url_tracker_->infobar_creator_ = &CreateTestInfobar; |
| 169 } | 176 } |
| 170 | 177 |
| 171 void GoogleURLTrackerTest::TearDown() { | 178 void GoogleURLTrackerTest::TearDown() { |
| 179 while (!unique_ids_seen_.empty()) |
| 180 CloseTab(*unique_ids_seen_.begin()); |
| 181 |
| 172 google_url_tracker_.reset(); | 182 google_url_tracker_.reset(); |
| 173 network_change_notifier_.reset(); | 183 network_change_notifier_.reset(); |
| 174 } | 184 } |
| 175 | 185 |
| 176 TestURLFetcher* GoogleURLTrackerTest::GetFetcher() { | 186 TestURLFetcher* GoogleURLTrackerTest::GetFetcher() { |
| 177 // This will return the last fetcher created. If no fetchers have been | 187 // This will return the last fetcher created. If no fetchers have been |
| 178 // created, we'll pass GetFetcherByID() "-1", and it will return NULL. | 188 // created, we'll pass GetFetcherByID() "-1", and it will return NULL. |
| 179 return fetcher_factory_.GetFetcherByID(google_url_tracker_->fetcher_id_ - 1); | 189 return fetcher_factory_.GetFetcherByID(google_url_tracker_->fetcher_id_ - 1); |
| 180 } | 190 } |
| 181 | 191 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 void GoogleURLTrackerTest::SetLastPromptedGoogleURL(const GURL& url) { | 226 void GoogleURLTrackerTest::SetLastPromptedGoogleURL(const GURL& url) { |
| 217 profile_.GetPrefs()->SetString(prefs::kLastPromptedGoogleURL, url.spec()); | 227 profile_.GetPrefs()->SetString(prefs::kLastPromptedGoogleURL, url.spec()); |
| 218 } | 228 } |
| 219 | 229 |
| 220 GURL GoogleURLTrackerTest::GetLastPromptedGoogleURL() { | 230 GURL GoogleURLTrackerTest::GetLastPromptedGoogleURL() { |
| 221 return GURL(profile_.GetPrefs()->GetString(prefs::kLastPromptedGoogleURL)); | 231 return GURL(profile_.GetPrefs()->GetString(prefs::kLastPromptedGoogleURL)); |
| 222 } | 232 } |
| 223 | 233 |
| 224 void GoogleURLTrackerTest::SetSearchPending(const GURL& search_url, | 234 void GoogleURLTrackerTest::SetSearchPending(const GURL& search_url, |
| 225 int unique_id) { | 235 int unique_id) { |
| 236 unique_ids_seen_.insert(unique_id); |
| 226 google_url_tracker_->SearchCommitted(); | 237 google_url_tracker_->SearchCommitted(); |
| 227 if (google_url_tracker_->registrar_.IsRegistered(google_url_tracker_.get(), | 238 if (google_url_tracker_->registrar_.IsRegistered(google_url_tracker_.get(), |
| 228 content::NOTIFICATION_NAV_ENTRY_PENDING, | 239 content::NOTIFICATION_NAV_ENTRY_PENDING, |
| 229 content::NotificationService::AllBrowserContextsAndSources())) { | 240 content::NotificationService::AllBrowserContextsAndSources())) { |
| 230 google_url_tracker_->OnNavigationPending( | 241 google_url_tracker_->OnNavigationPending( |
| 231 content::Source<content::NavigationController>( | 242 content::Source<content::NavigationController>( |
| 232 reinterpret_cast<content::NavigationController*>(unique_id)), | 243 reinterpret_cast<content::NavigationController*>(unique_id)), |
| 233 content::Source<content::WebContents>( | 244 content::Source<content::WebContents>( |
| 234 reinterpret_cast<content::WebContents*>(unique_id)), | 245 reinterpret_cast<content::WebContents*>(unique_id)), |
| 235 reinterpret_cast<InfoBarTabHelper*>(unique_id), search_url); | 246 reinterpret_cast<InfoBarTabHelper*>(unique_id), search_url); |
| 236 } | 247 } |
| 237 } | 248 } |
| 238 | 249 |
| 239 void GoogleURLTrackerTest::CommitSearch(int unique_id) { | 250 void GoogleURLTrackerTest::CommitSearch(int unique_id) { |
| 240 content::Source<content::NavigationController> source( | 251 content::Source<content::NavigationController> source( |
| 241 reinterpret_cast<content::NavigationController*>(unique_id)); | 252 reinterpret_cast<content::NavigationController*>(unique_id)); |
| 242 if (google_url_tracker_->registrar_.IsRegistered(google_url_tracker_.get(), | 253 if (google_url_tracker_->registrar_.IsRegistered(google_url_tracker_.get(), |
| 243 content::NOTIFICATION_NAV_ENTRY_COMMITTED, source)) { | 254 content::NOTIFICATION_NAV_ENTRY_COMMITTED, source)) { |
| 244 google_url_tracker_->OnNavigationCommittedOrTabClosed(source, | 255 google_url_tracker_->OnNavigationCommittedOrTabClosed(source, |
| 245 content::Source<content::WebContents>( | 256 content::Source<content::WebContents>( |
| 246 reinterpret_cast<content::WebContents*>(unique_id)), | 257 reinterpret_cast<content::WebContents*>(unique_id)), |
| 247 reinterpret_cast<InfoBarTabHelper*>(unique_id), true); | 258 reinterpret_cast<InfoBarTabHelper*>(unique_id), true); |
| 248 } | 259 } |
| 249 } | 260 } |
| 250 | 261 |
| 251 void GoogleURLTrackerTest::CloseTab(int unique_id) { | 262 void GoogleURLTrackerTest::CloseTab(int unique_id) { |
| 263 unique_ids_seen_.erase(unique_id); |
| 252 content::Source<content::WebContents> source( | 264 content::Source<content::WebContents> source( |
| 253 reinterpret_cast<content::WebContents*>(unique_id)); | 265 reinterpret_cast<content::WebContents*>(unique_id)); |
| 254 InfoBarTabHelper* infobar_helper = | 266 InfoBarTabHelper* infobar_helper = |
| 255 reinterpret_cast<InfoBarTabHelper*>(unique_id); | 267 reinterpret_cast<InfoBarTabHelper*>(unique_id); |
| 256 if (google_url_tracker_->registrar_.IsRegistered(google_url_tracker_.get(), | 268 if (google_url_tracker_->registrar_.IsRegistered(google_url_tracker_.get(), |
| 257 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, source)) { | 269 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, source)) { |
| 258 google_url_tracker_->OnNavigationCommittedOrTabClosed( | 270 google_url_tracker_->OnNavigationCommittedOrTabClosed( |
| 259 content::Source<content::NavigationController>( | 271 content::Source<content::NavigationController>( |
| 260 reinterpret_cast<content::NavigationController*>(unique_id)), | 272 reinterpret_cast<content::NavigationController*>(unique_id)), |
| 261 source, infobar_helper, false); | 273 source, infobar_helper, false); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 288 } | 300 } |
| 289 | 301 |
| 290 | 302 |
| 291 // Tests ---------------------------------------------------------------------- | 303 // Tests ---------------------------------------------------------------------- |
| 292 | 304 |
| 293 TEST_F(GoogleURLTrackerTest, DontFetchWhenNoOneRequestsCheck) { | 305 TEST_F(GoogleURLTrackerTest, DontFetchWhenNoOneRequestsCheck) { |
| 294 ExpectDefaultURLs(); | 306 ExpectDefaultURLs(); |
| 295 FinishSleep(); | 307 FinishSleep(); |
| 296 // No one called RequestServerCheck() so nothing should have happened. | 308 // No one called RequestServerCheck() so nothing should have happened. |
| 297 EXPECT_FALSE(GetFetcher()); | 309 EXPECT_FALSE(GetFetcher()); |
| 298 MockSearchDomainCheckResponse(".google.co.uk"); | 310 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
| 299 ExpectDefaultURLs(); | 311 ExpectDefaultURLs(); |
| 300 EXPECT_FALSE(observer_->notified()); | 312 EXPECT_FALSE(observer_->notified()); |
| 301 } | 313 } |
| 302 | 314 |
| 303 TEST_F(GoogleURLTrackerTest, UpdateOnFirstRun) { | 315 TEST_F(GoogleURLTrackerTest, UpdateOnFirstRun) { |
| 304 RequestServerCheck(); | 316 RequestServerCheck(); |
| 305 EXPECT_FALSE(GetFetcher()); | 317 EXPECT_FALSE(GetFetcher()); |
| 306 ExpectDefaultURLs(); | 318 ExpectDefaultURLs(); |
| 307 EXPECT_FALSE(observer_->notified()); | 319 EXPECT_FALSE(observer_->notified()); |
| 308 | 320 |
| 309 FinishSleep(); | 321 FinishSleep(); |
| 310 MockSearchDomainCheckResponse(".google.co.uk"); | 322 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
| 311 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 323 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
| 312 // GoogleURL should be updated, becase there was no last prompted URL. | 324 // GoogleURL should be updated, becase there was no last prompted URL. |
| 313 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 325 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
| 314 EXPECT_TRUE(observer_->notified()); | 326 EXPECT_TRUE(observer_->notified()); |
| 315 } | 327 } |
| 316 | 328 |
| 317 TEST_F(GoogleURLTrackerTest, DontUpdateWhenUnchanged) { | 329 TEST_F(GoogleURLTrackerTest, DontUpdateWhenUnchanged) { |
| 318 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 330 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
| 319 | 331 |
| 320 RequestServerCheck(); | 332 RequestServerCheck(); |
| 321 EXPECT_FALSE(GetFetcher()); | 333 EXPECT_FALSE(GetFetcher()); |
| 322 ExpectDefaultURLs(); | 334 ExpectDefaultURLs(); |
| 323 EXPECT_FALSE(observer_->notified()); | 335 EXPECT_FALSE(observer_->notified()); |
| 324 | 336 |
| 325 FinishSleep(); | 337 FinishSleep(); |
| 326 MockSearchDomainCheckResponse(".google.co.uk"); | 338 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
| 327 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 339 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
| 328 // GoogleURL should not be updated, because the fetched and prompted URLs | 340 // GoogleURL should not be updated, because the fetched and prompted URLs |
| 329 // match. | 341 // match. |
| 330 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 342 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 331 EXPECT_FALSE(observer_->notified()); | 343 EXPECT_FALSE(observer_->notified()); |
| 332 } | 344 } |
| 333 | 345 |
| 346 TEST_F(GoogleURLTrackerTest, DontPromptOnBadReplies) { |
| 347 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
| 348 |
| 349 RequestServerCheck(); |
| 350 EXPECT_FALSE(GetFetcher()); |
| 351 ExpectDefaultURLs(); |
| 352 EXPECT_FALSE(observer_->notified()); |
| 353 |
| 354 // Old-style domain string. |
| 355 FinishSleep(); |
| 356 MockSearchDomainCheckResponse(".google.co.in"); |
| 357 EXPECT_EQ(GURL(), fetched_google_url()); |
| 358 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 359 EXPECT_FALSE(observer_->notified()); |
| 360 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); |
| 361 CommitSearch(1); |
| 362 EXPECT_TRUE(GetInfoBar(1) == NULL); |
| 363 |
| 364 // Bad subdomain. |
| 365 NotifyIPAddressChanged(); |
| 366 MockSearchDomainCheckResponse("http://mail.google.com/"); |
| 367 EXPECT_EQ(GURL(), fetched_google_url()); |
| 368 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 369 EXPECT_FALSE(observer_->notified()); |
| 370 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); |
| 371 CommitSearch(1); |
| 372 EXPECT_TRUE(GetInfoBar(1) == NULL); |
| 373 |
| 374 // Non-empty path. |
| 375 NotifyIPAddressChanged(); |
| 376 MockSearchDomainCheckResponse("http://www.google.com/search"); |
| 377 EXPECT_EQ(GURL(), fetched_google_url()); |
| 378 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 379 EXPECT_FALSE(observer_->notified()); |
| 380 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); |
| 381 CommitSearch(1); |
| 382 EXPECT_TRUE(GetInfoBar(1) == NULL); |
| 383 |
| 384 // Non-empty query. |
| 385 NotifyIPAddressChanged(); |
| 386 MockSearchDomainCheckResponse("http://www.google.com/?q=foo"); |
| 387 EXPECT_EQ(GURL(), fetched_google_url()); |
| 388 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 389 EXPECT_FALSE(observer_->notified()); |
| 390 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); |
| 391 CommitSearch(1); |
| 392 EXPECT_TRUE(GetInfoBar(1) == NULL); |
| 393 |
| 394 // Non-empty ref. |
| 395 NotifyIPAddressChanged(); |
| 396 MockSearchDomainCheckResponse("http://www.google.com/#anchor"); |
| 397 EXPECT_EQ(GURL(), fetched_google_url()); |
| 398 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 399 EXPECT_FALSE(observer_->notified()); |
| 400 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); |
| 401 CommitSearch(1); |
| 402 EXPECT_TRUE(GetInfoBar(1) == NULL); |
| 403 |
| 404 // Complete garbage. |
| 405 NotifyIPAddressChanged(); |
| 406 MockSearchDomainCheckResponse("HJ)*qF)_*&@f1"); |
| 407 EXPECT_EQ(GURL(), fetched_google_url()); |
| 408 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 409 EXPECT_FALSE(observer_->notified()); |
| 410 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); |
| 411 CommitSearch(1); |
| 412 EXPECT_TRUE(GetInfoBar(1) == NULL); |
| 413 } |
| 414 |
| 334 TEST_F(GoogleURLTrackerTest, UpdatePromptedURLOnReturnToPreviousLocation) { | 415 TEST_F(GoogleURLTrackerTest, UpdatePromptedURLOnReturnToPreviousLocation) { |
| 335 SetLastPromptedGoogleURL(GURL("http://www.google.co.jp/")); | 416 SetLastPromptedGoogleURL(GURL("http://www.google.co.jp/")); |
| 336 set_google_url(GURL("http://www.google.co.uk/")); | 417 set_google_url(GURL("http://www.google.co.uk/")); |
| 337 RequestServerCheck(); | 418 RequestServerCheck(); |
| 338 FinishSleep(); | 419 FinishSleep(); |
| 339 MockSearchDomainCheckResponse(".google.co.uk"); | 420 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
| 340 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 421 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
| 341 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 422 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
| 342 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 423 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 343 EXPECT_FALSE(observer_->notified()); | 424 EXPECT_FALSE(observer_->notified()); |
| 344 } | 425 } |
| 345 | 426 |
| 427 TEST_F(GoogleURLTrackerTest, SilentlyAcceptSchemeChange) { |
| 428 // We should auto-accept changes to the current Google URL that merely change |
| 429 // the scheme, regardless of what the last prompted URL was. |
| 430 SetLastPromptedGoogleURL(GURL("http://www.google.co.jp/")); |
| 431 set_google_url(GURL("http://www.google.co.uk/")); |
| 432 RequestServerCheck(); |
| 433 FinishSleep(); |
| 434 MockSearchDomainCheckResponse("https://www.google.co.uk/"); |
| 435 EXPECT_EQ(GURL("https://www.google.co.uk/"), fetched_google_url()); |
| 436 EXPECT_EQ(GURL("https://www.google.co.uk/"), google_url()); |
| 437 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 438 EXPECT_TRUE(observer_->notified()); |
| 439 |
| 440 NotifyIPAddressChanged(); |
| 441 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
| 442 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
| 443 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
| 444 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 445 EXPECT_TRUE(observer_->notified()); |
| 446 } |
| 447 |
| 346 TEST_F(GoogleURLTrackerTest, RefetchOnIPAddressChange) { | 448 TEST_F(GoogleURLTrackerTest, RefetchOnIPAddressChange) { |
| 347 RequestServerCheck(); | 449 RequestServerCheck(); |
| 348 FinishSleep(); | 450 FinishSleep(); |
| 349 MockSearchDomainCheckResponse(".google.co.uk"); | 451 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
| 350 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 452 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
| 351 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 453 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
| 352 EXPECT_TRUE(observer_->notified()); | 454 EXPECT_TRUE(observer_->notified()); |
| 353 observer_->clear_notified(); | 455 observer_->clear_notified(); |
| 354 | 456 |
| 355 NotifyIPAddressChanged(); | 457 NotifyIPAddressChanged(); |
| 356 MockSearchDomainCheckResponse(".google.co.in"); | 458 MockSearchDomainCheckResponse("http://www.google.co.in/"); |
| 357 EXPECT_EQ(GURL("http://www.google.co.in/"), fetched_google_url()); | 459 EXPECT_EQ(GURL("http://www.google.co.in/"), fetched_google_url()); |
| 358 // Just fetching a new URL shouldn't reset things without a prompt. | 460 // Just fetching a new URL shouldn't reset things without a prompt. |
| 359 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 461 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
| 360 EXPECT_FALSE(observer_->notified()); | 462 EXPECT_FALSE(observer_->notified()); |
| 361 } | 463 } |
| 362 | 464 |
| 363 TEST_F(GoogleURLTrackerTest, DontRefetchWhenNoOneRequestsCheck) { | 465 TEST_F(GoogleURLTrackerTest, DontRefetchWhenNoOneRequestsCheck) { |
| 364 FinishSleep(); | 466 FinishSleep(); |
| 365 NotifyIPAddressChanged(); | 467 NotifyIPAddressChanged(); |
| 366 // No one called RequestServerCheck() so nothing should have happened. | 468 // No one called RequestServerCheck() so nothing should have happened. |
| 367 EXPECT_FALSE(GetFetcher()); | 469 EXPECT_FALSE(GetFetcher()); |
| 368 MockSearchDomainCheckResponse(".google.co.uk"); | 470 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
| 369 ExpectDefaultURLs(); | 471 ExpectDefaultURLs(); |
| 370 EXPECT_FALSE(observer_->notified()); | 472 EXPECT_FALSE(observer_->notified()); |
| 371 } | 473 } |
| 372 | 474 |
| 373 TEST_F(GoogleURLTrackerTest, FetchOnLateRequest) { | 475 TEST_F(GoogleURLTrackerTest, FetchOnLateRequest) { |
| 374 FinishSleep(); | 476 FinishSleep(); |
| 375 NotifyIPAddressChanged(); | 477 NotifyIPAddressChanged(); |
| 376 MockSearchDomainCheckResponse(".google.co.jp"); | 478 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
| 377 | 479 |
| 378 RequestServerCheck(); | 480 RequestServerCheck(); |
| 379 // The first request for a check should trigger a fetch if it hasn't happened | 481 // The first request for a check should trigger a fetch if it hasn't happened |
| 380 // already. | 482 // already. |
| 381 MockSearchDomainCheckResponse(".google.co.uk"); | 483 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
| 382 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 484 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
| 383 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 485 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
| 384 EXPECT_TRUE(observer_->notified()); | 486 EXPECT_TRUE(observer_->notified()); |
| 385 } | 487 } |
| 386 | 488 |
| 387 TEST_F(GoogleURLTrackerTest, DontFetchTwiceOnLateRequests) { | 489 TEST_F(GoogleURLTrackerTest, DontFetchTwiceOnLateRequests) { |
| 388 FinishSleep(); | 490 FinishSleep(); |
| 389 NotifyIPAddressChanged(); | 491 NotifyIPAddressChanged(); |
| 390 MockSearchDomainCheckResponse(".google.co.jp"); | 492 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
| 391 | 493 |
| 392 RequestServerCheck(); | 494 RequestServerCheck(); |
| 393 // The first request for a check should trigger a fetch if it hasn't happened | 495 // The first request for a check should trigger a fetch if it hasn't happened |
| 394 // already. | 496 // already. |
| 395 MockSearchDomainCheckResponse(".google.co.uk"); | 497 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
| 396 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 498 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
| 397 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 499 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
| 398 EXPECT_TRUE(observer_->notified()); | 500 EXPECT_TRUE(observer_->notified()); |
| 399 observer_->clear_notified(); | 501 observer_->clear_notified(); |
| 400 | 502 |
| 401 RequestServerCheck(); | 503 RequestServerCheck(); |
| 402 // The second request should be ignored. | 504 // The second request should be ignored. |
| 403 EXPECT_FALSE(GetFetcher()); | 505 EXPECT_FALSE(GetFetcher()); |
| 404 MockSearchDomainCheckResponse(".google.co.in"); | 506 MockSearchDomainCheckResponse("http://www.google.co.in/"); |
| 405 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 507 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
| 406 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 508 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
| 407 EXPECT_FALSE(observer_->notified()); | 509 EXPECT_FALSE(observer_->notified()); |
| 408 } | 510 } |
| 409 | 511 |
| 410 TEST_F(GoogleURLTrackerTest, SearchingDoesNothingIfNoNeedToPrompt) { | 512 TEST_F(GoogleURLTrackerTest, SearchingDoesNothingIfNoNeedToPrompt) { |
| 411 RequestServerCheck(); | 513 RequestServerCheck(); |
| 412 FinishSleep(); | 514 FinishSleep(); |
| 413 MockSearchDomainCheckResponse(".google.co.uk"); | 515 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
| 414 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 516 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
| 415 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 517 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
| 416 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 518 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 417 EXPECT_TRUE(observer_->notified()); | 519 EXPECT_TRUE(observer_->notified()); |
| 418 observer_->clear_notified(); | 520 observer_->clear_notified(); |
| 419 | 521 |
| 420 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); | 522 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); |
| 421 CommitSearch(1); | 523 CommitSearch(1); |
| 422 TestInfoBarDelegate* infobar = GetInfoBar(1); | 524 TestInfoBarDelegate* infobar = GetInfoBar(1); |
| 423 ASSERT_TRUE(infobar == NULL); | 525 EXPECT_TRUE(infobar == NULL); |
| 424 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 526 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
| 425 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 527 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
| 426 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 528 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 427 EXPECT_FALSE(observer_->notified()); | 529 EXPECT_FALSE(observer_->notified()); |
| 428 } | 530 } |
| 429 | 531 |
| 430 TEST_F(GoogleURLTrackerTest, TabClosedOnPendingSearch) { | 532 TEST_F(GoogleURLTrackerTest, TabClosedOnPendingSearch) { |
| 431 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 533 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
| 432 RequestServerCheck(); | 534 RequestServerCheck(); |
| 433 FinishSleep(); | 535 FinishSleep(); |
| 434 MockSearchDomainCheckResponse(".google.co.jp"); | 536 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
| 435 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 537 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 436 EXPECT_EQ(GURL("http://www.google.co.jp/"), fetched_google_url()); | 538 EXPECT_EQ(GURL("http://www.google.co.jp/"), fetched_google_url()); |
| 437 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 539 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 438 EXPECT_FALSE(observer_->notified()); | 540 EXPECT_FALSE(observer_->notified()); |
| 439 | 541 |
| 440 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); | 542 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); |
| 441 TestInfoBarDelegate* infobar = GetInfoBar(1); | 543 TestInfoBarDelegate* infobar = GetInfoBar(1); |
| 442 ASSERT_FALSE(infobar == NULL); | 544 ASSERT_FALSE(infobar == NULL); |
| 443 EXPECT_FALSE(infobar->showing()); | 545 EXPECT_FALSE(infobar->showing()); |
| 444 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 546 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 445 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test"), | 547 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test"), |
| 446 infobar->search_url()); | 548 infobar->search_url()); |
| 447 EXPECT_EQ(GURL("http://www.google.co.jp/"), infobar->new_google_url()); | 549 EXPECT_EQ(GURL("http://www.google.co.jp/"), infobar->new_google_url()); |
| 448 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 550 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 449 EXPECT_FALSE(observer_->notified()); | 551 EXPECT_FALSE(observer_->notified()); |
| 450 | 552 |
| 451 CloseTab(1); | 553 CloseTab(1); |
| 452 EXPECT_TRUE(GetInfoBar(1) == NULL); | 554 EXPECT_TRUE(GetInfoBar(1) == NULL); |
| 453 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 555 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 454 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 556 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 455 EXPECT_FALSE(observer_->notified()); | 557 EXPECT_FALSE(observer_->notified()); |
| 456 } | 558 } |
| 457 | 559 |
| 458 TEST_F(GoogleURLTrackerTest, TabClosedOnCommittedSearch) { | 560 TEST_F(GoogleURLTrackerTest, TabClosedOnCommittedSearch) { |
| 459 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 561 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
| 460 RequestServerCheck(); | 562 RequestServerCheck(); |
| 461 FinishSleep(); | 563 FinishSleep(); |
| 462 MockSearchDomainCheckResponse(".google.co.jp"); | 564 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
| 463 | 565 |
| 464 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); | 566 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); |
| 465 CommitSearch(1); | 567 CommitSearch(1); |
| 466 TestInfoBarDelegate* infobar = GetInfoBar(1); | 568 TestInfoBarDelegate* infobar = GetInfoBar(1); |
| 467 ASSERT_FALSE(infobar == NULL); | 569 ASSERT_FALSE(infobar == NULL); |
| 468 EXPECT_TRUE(infobar->showing()); | 570 EXPECT_TRUE(infobar->showing()); |
| 469 | 571 |
| 470 CloseTab(1); | 572 CloseTab(1); |
| 471 EXPECT_TRUE(GetInfoBar(1) == NULL); | 573 EXPECT_TRUE(GetInfoBar(1) == NULL); |
| 472 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 574 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 473 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 575 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 474 EXPECT_FALSE(observer_->notified()); | 576 EXPECT_FALSE(observer_->notified()); |
| 475 } | 577 } |
| 476 | 578 |
| 477 TEST_F(GoogleURLTrackerTest, InfobarClosed) { | 579 TEST_F(GoogleURLTrackerTest, InfobarClosed) { |
| 478 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 580 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
| 479 RequestServerCheck(); | 581 RequestServerCheck(); |
| 480 FinishSleep(); | 582 FinishSleep(); |
| 481 MockSearchDomainCheckResponse(".google.co.jp"); | 583 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
| 482 | 584 |
| 483 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); | 585 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); |
| 484 CommitSearch(1); | 586 CommitSearch(1); |
| 485 TestInfoBarDelegate* infobar = GetInfoBar(1); | 587 TestInfoBarDelegate* infobar = GetInfoBar(1); |
| 486 ASSERT_FALSE(infobar == NULL); | 588 ASSERT_FALSE(infobar == NULL); |
| 487 | 589 |
| 488 infobar->InfoBarClosed(); | 590 infobar->InfoBarClosed(); |
| 489 EXPECT_TRUE(GetInfoBar(1) == NULL); | 591 EXPECT_TRUE(GetInfoBar(1) == NULL); |
| 490 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 592 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 491 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 593 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 492 EXPECT_FALSE(observer_->notified()); | 594 EXPECT_FALSE(observer_->notified()); |
| 493 } | 595 } |
| 494 | 596 |
| 495 TEST_F(GoogleURLTrackerTest, InfobarRefused) { | 597 TEST_F(GoogleURLTrackerTest, InfobarRefused) { |
| 496 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 598 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
| 497 RequestServerCheck(); | 599 RequestServerCheck(); |
| 498 FinishSleep(); | 600 FinishSleep(); |
| 499 MockSearchDomainCheckResponse(".google.co.jp"); | 601 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
| 500 | 602 |
| 501 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); | 603 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); |
| 502 CommitSearch(1); | 604 CommitSearch(1); |
| 503 TestInfoBarDelegate* infobar = GetInfoBar(1); | 605 TestInfoBarDelegate* infobar = GetInfoBar(1); |
| 504 ASSERT_FALSE(infobar == NULL); | 606 ASSERT_FALSE(infobar == NULL); |
| 505 | 607 |
| 506 infobar->Cancel(); | 608 infobar->Cancel(); |
| 507 EXPECT_TRUE(GetInfoBar(1) == NULL); | 609 EXPECT_TRUE(GetInfoBar(1) == NULL); |
| 508 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 610 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 509 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); | 611 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); |
| 510 EXPECT_FALSE(observer_->notified()); | 612 EXPECT_FALSE(observer_->notified()); |
| 511 } | 613 } |
| 512 | 614 |
| 513 TEST_F(GoogleURLTrackerTest, InfobarAccepted) { | 615 TEST_F(GoogleURLTrackerTest, InfobarAccepted) { |
| 514 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 616 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
| 515 RequestServerCheck(); | 617 RequestServerCheck(); |
| 516 FinishSleep(); | 618 FinishSleep(); |
| 517 MockSearchDomainCheckResponse(".google.co.jp"); | 619 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
| 518 | 620 |
| 519 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); | 621 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); |
| 520 CommitSearch(1); | 622 CommitSearch(1); |
| 521 TestInfoBarDelegate* infobar = GetInfoBar(1); | 623 TestInfoBarDelegate* infobar = GetInfoBar(1); |
| 522 ASSERT_FALSE(infobar == NULL); | 624 ASSERT_FALSE(infobar == NULL); |
| 523 | 625 |
| 524 infobar->Accept(); | 626 infobar->Accept(); |
| 525 EXPECT_TRUE(GetInfoBar(1) == NULL); | 627 EXPECT_TRUE(GetInfoBar(1) == NULL); |
| 526 EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url()); | 628 EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url()); |
| 527 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); | 629 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); |
| 528 EXPECT_TRUE(observer_->notified()); | 630 EXPECT_TRUE(observer_->notified()); |
| 529 } | 631 } |
| 530 | 632 |
| 633 TEST_F(GoogleURLTrackerTest, FetchesCanAutomaticallyCloseInfobars) { |
| 634 RequestServerCheck(); |
| 635 FinishSleep(); |
| 636 MockSearchDomainCheckResponse(google_url().spec()); |
| 637 |
| 638 // Re-fetching the accepted URL after showing an infobar for another URL |
| 639 // should close the infobar. |
| 640 NotifyIPAddressChanged(); |
| 641 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
| 642 SetSearchPending(GURL("http://www.google.com/search?q=test"), 1); |
| 643 CommitSearch(1); |
| 644 EXPECT_FALSE(GetInfoBar(1) == NULL); |
| 645 NotifyIPAddressChanged(); |
| 646 MockSearchDomainCheckResponse(google_url().spec()); |
| 647 EXPECT_EQ(google_url(), GetLastPromptedGoogleURL()); |
| 648 EXPECT_TRUE(GetInfoBar(1) == NULL); |
| 649 |
| 650 // As should fetching a URL that differs from the accepted only by the scheme. |
| 651 NotifyIPAddressChanged(); |
| 652 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
| 653 SetSearchPending(GURL("http://www.google.com/search?q=test"), 1); |
| 654 CommitSearch(1); |
| 655 EXPECT_FALSE(GetInfoBar(1) == NULL); |
| 656 NotifyIPAddressChanged(); |
| 657 url_canon::Replacements<char> replacements; |
| 658 const std::string& scheme("https"); |
| 659 replacements.SetScheme(scheme.data(), |
| 660 url_parse::Component(0, scheme.length())); |
| 661 GURL new_google_url(google_url().ReplaceComponents(replacements)); |
| 662 MockSearchDomainCheckResponse(new_google_url.spec()); |
| 663 EXPECT_EQ(new_google_url, GetLastPromptedGoogleURL()); |
| 664 EXPECT_TRUE(GetInfoBar(1) == NULL); |
| 665 |
| 666 // As should re-fetching the last prompted URL. |
| 667 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
| 668 NotifyIPAddressChanged(); |
| 669 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
| 670 SetSearchPending(GURL("http://www.google.com/search?q=test"), 1); |
| 671 CommitSearch(1); |
| 672 EXPECT_FALSE(GetInfoBar(1) == NULL); |
| 673 NotifyIPAddressChanged(); |
| 674 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
| 675 EXPECT_EQ(new_google_url, google_url()); |
| 676 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 677 EXPECT_TRUE(GetInfoBar(1) == NULL); |
| 678 |
| 679 // And one that differs from the last prompted URL only by the scheme. |
| 680 NotifyIPAddressChanged(); |
| 681 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
| 682 SetSearchPending(GURL("http://www.google.com/search?q=test"), 1); |
| 683 CommitSearch(1); |
| 684 EXPECT_FALSE(GetInfoBar(1) == NULL); |
| 685 NotifyIPAddressChanged(); |
| 686 MockSearchDomainCheckResponse("https://www.google.co.uk/"); |
| 687 EXPECT_EQ(new_google_url, google_url()); |
| 688 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 689 EXPECT_TRUE(GetInfoBar(1) == NULL); |
| 690 |
| 691 // And fetching a different URL entirely. |
| 692 NotifyIPAddressChanged(); |
| 693 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
| 694 SetSearchPending(GURL("http://www.google.com/search?q=test"), 1); |
| 695 CommitSearch(1); |
| 696 EXPECT_FALSE(GetInfoBar(1) == NULL); |
| 697 NotifyIPAddressChanged(); |
| 698 MockSearchDomainCheckResponse("https://www.google.co.in/"); |
| 699 EXPECT_EQ(new_google_url, google_url()); |
| 700 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 701 EXPECT_TRUE(GetInfoBar(1) == NULL); |
| 702 } |
| 703 |
| 704 TEST_F(GoogleURLTrackerTest, ResetInfobarGoogleURLs) { |
| 705 RequestServerCheck(); |
| 706 FinishSleep(); |
| 707 MockSearchDomainCheckResponse(google_url().spec()); |
| 708 |
| 709 NotifyIPAddressChanged(); |
| 710 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
| 711 SetSearchPending(GURL("http://www.google.com/search?q=test"), 1); |
| 712 CommitSearch(1); |
| 713 TestInfoBarDelegate* infobar = GetInfoBar(1); |
| 714 ASSERT_FALSE(infobar == NULL); |
| 715 EXPECT_EQ(GURL("http://www.google.co.uk/"), infobar->new_google_url()); |
| 716 |
| 717 // If while an infobar is showing we fetch a new URL that differs from the |
| 718 // infobar's only by scheme, the infobar should stay open but have its Google |
| 719 // URL reset. |
| 720 NotifyIPAddressChanged(); |
| 721 MockSearchDomainCheckResponse("https://www.google.co.uk/"); |
| 722 TestInfoBarDelegate* new_infobar = GetInfoBar(1); |
| 723 ASSERT_FALSE(new_infobar == NULL); |
| 724 EXPECT_EQ(infobar, new_infobar); |
| 725 EXPECT_EQ(GURL("https://www.google.co.uk/"), new_infobar->new_google_url()); |
| 726 } |
| 727 |
| 531 TEST_F(GoogleURLTrackerTest, InfobarShownAgainOnSearchAfterPendingSearch) { | 728 TEST_F(GoogleURLTrackerTest, InfobarShownAgainOnSearchAfterPendingSearch) { |
| 532 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 729 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
| 533 RequestServerCheck(); | 730 RequestServerCheck(); |
| 534 FinishSleep(); | 731 FinishSleep(); |
| 535 MockSearchDomainCheckResponse(".google.co.jp"); | 732 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
| 536 | 733 |
| 537 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); | 734 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); |
| 538 TestInfoBarDelegate* infobar = GetInfoBar(1); | 735 TestInfoBarDelegate* infobar = GetInfoBar(1); |
| 539 ASSERT_FALSE(infobar == NULL); | 736 ASSERT_FALSE(infobar == NULL); |
| 540 EXPECT_FALSE(infobar->showing()); | 737 EXPECT_FALSE(infobar->showing()); |
| 541 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test"), | 738 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test"), |
| 542 infobar->search_url()); | 739 infobar->search_url()); |
| 543 | 740 |
| 544 SetSearchPending(GURL("http://www.google.co.uk/search?q=test2"), 1); | 741 SetSearchPending(GURL("http://www.google.co.uk/search?q=test2"), 1); |
| 545 TestInfoBarDelegate* infobar2 = GetInfoBar(1); | 742 TestInfoBarDelegate* infobar2 = GetInfoBar(1); |
| 546 ASSERT_FALSE(infobar2 == NULL); | 743 ASSERT_FALSE(infobar2 == NULL); |
| 547 EXPECT_FALSE(infobar2->showing()); | 744 EXPECT_FALSE(infobar2->showing()); |
| 548 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test2"), | 745 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test2"), |
| 549 infobar2->search_url()); | 746 infobar2->search_url()); |
| 550 | 747 |
| 551 CommitSearch(1); | 748 CommitSearch(1); |
| 552 EXPECT_TRUE(infobar2->showing()); | 749 EXPECT_TRUE(infobar2->showing()); |
| 553 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 750 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 554 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 751 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 555 EXPECT_FALSE(observer_->notified()); | 752 EXPECT_FALSE(observer_->notified()); |
| 556 | |
| 557 CloseTab(1); | |
| 558 } | 753 } |
| 559 | 754 |
| 560 TEST_F(GoogleURLTrackerTest, InfobarShownAgainOnSearchAfterCommittedSearch) { | 755 TEST_F(GoogleURLTrackerTest, InfobarShownAgainOnSearchAfterCommittedSearch) { |
| 561 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 756 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
| 562 RequestServerCheck(); | 757 RequestServerCheck(); |
| 563 FinishSleep(); | 758 FinishSleep(); |
| 564 MockSearchDomainCheckResponse(".google.co.jp"); | 759 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
| 565 | 760 |
| 566 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); | 761 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); |
| 567 CommitSearch(1); | 762 CommitSearch(1); |
| 568 TestInfoBarDelegate* infobar = GetInfoBar(1); | 763 TestInfoBarDelegate* infobar = GetInfoBar(1); |
| 569 ASSERT_FALSE(infobar == NULL); | 764 ASSERT_FALSE(infobar == NULL); |
| 570 EXPECT_TRUE(infobar->showing()); | 765 EXPECT_TRUE(infobar->showing()); |
| 571 | 766 |
| 572 // In real usage, the upcoming pending navigation for "test2" would close | 767 // In real usage, the upcoming pending navigation for "test2" would close |
| 573 // |infobar|. Since we're not actually doing navigations, we need to clean it | 768 // |infobar|. Since we're not actually doing navigations, we need to clean it |
| 574 // up manually to prevent leaks. | 769 // up manually to prevent leaks. |
| 575 delete infobar; | 770 delete infobar; |
| 576 | 771 |
| 577 SetSearchPending(GURL("http://www.google.co.uk/search?q=test2"), 1); | 772 SetSearchPending(GURL("http://www.google.co.uk/search?q=test2"), 1); |
| 578 TestInfoBarDelegate* infobar2 = GetInfoBar(1); | 773 TestInfoBarDelegate* infobar2 = GetInfoBar(1); |
| 579 ASSERT_FALSE(infobar2 == NULL); | 774 ASSERT_FALSE(infobar2 == NULL); |
| 580 EXPECT_FALSE(infobar2->showing()); | 775 EXPECT_FALSE(infobar2->showing()); |
| 581 | 776 |
| 582 CommitSearch(1); | 777 CommitSearch(1); |
| 583 EXPECT_TRUE(infobar2->showing()); | 778 EXPECT_TRUE(infobar2->showing()); |
| 584 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 779 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
| 585 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 780 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
| 586 EXPECT_FALSE(observer_->notified()); | 781 EXPECT_FALSE(observer_->notified()); |
| 587 | |
| 588 CloseTab(1); | |
| 589 } | 782 } |
| 590 | 783 |
| 591 TEST_F(GoogleURLTrackerTest, MultipleInfobars) { | 784 TEST_F(GoogleURLTrackerTest, MultipleInfobars) { |
| 592 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 785 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
| 593 RequestServerCheck(); | 786 RequestServerCheck(); |
| 594 FinishSleep(); | 787 FinishSleep(); |
| 595 MockSearchDomainCheckResponse(".google.co.jp"); | 788 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
| 596 | 789 |
| 597 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); | 790 SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); |
| 598 TestInfoBarDelegate* infobar = GetInfoBar(1); | 791 TestInfoBarDelegate* infobar = GetInfoBar(1); |
| 599 ASSERT_FALSE(infobar == NULL); | 792 ASSERT_FALSE(infobar == NULL); |
| 600 EXPECT_FALSE(infobar->showing()); | 793 EXPECT_FALSE(infobar->showing()); |
| 601 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test"), | 794 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test"), |
| 602 infobar->search_url()); | 795 infobar->search_url()); |
| 603 | 796 |
| 604 SetSearchPending(GURL("http://www.google.co.uk/search?q=test2"), 2); | 797 SetSearchPending(GURL("http://www.google.co.uk/search?q=test2"), 2); |
| 605 CommitSearch(2); | 798 CommitSearch(2); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 632 EXPECT_FALSE(observer_->notified()); | 825 EXPECT_FALSE(observer_->notified()); |
| 633 | 826 |
| 634 infobar4->Accept(); | 827 infobar4->Accept(); |
| 635 EXPECT_TRUE(GetInfoBar(1) == NULL); | 828 EXPECT_TRUE(GetInfoBar(1) == NULL); |
| 636 EXPECT_TRUE(GetInfoBar(3) == NULL); | 829 EXPECT_TRUE(GetInfoBar(3) == NULL); |
| 637 EXPECT_TRUE(GetInfoBar(4) == NULL); | 830 EXPECT_TRUE(GetInfoBar(4) == NULL); |
| 638 EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url()); | 831 EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url()); |
| 639 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); | 832 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); |
| 640 EXPECT_TRUE(observer_->notified()); | 833 EXPECT_TRUE(observer_->notified()); |
| 641 } | 834 } |
| OLD | NEW |