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/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
54 virtual void Close(bool redo_search) OVERRIDE; | 54 virtual void Close(bool redo_search) OVERRIDE; |
55 | 55 |
56 GoogleURLTrackerTest* test_harness_; | 56 GoogleURLTrackerTest* test_harness_; |
57 InfoBarService* infobar_service_; | 57 InfoBarService* infobar_service_; |
58 | 58 |
59 DISALLOW_COPY_AND_ASSIGN(TestInfoBarDelegate); | 59 DISALLOW_COPY_AND_ASSIGN(TestInfoBarDelegate); |
60 }; | 60 }; |
61 | 61 |
62 // The member function definitions come after the declaration of | 62 // The member function definitions come after the declaration of |
63 // GoogleURLTrackerTest, so they can call members on it. | 63 // GoogleURLTrackerTest, so they can call members on it. |
64 | 64 |
Peter Kasting
2014/05/16 23:23:45
Nit: Preserve two blank lines here
blundell
2014/05/17 11:25:36
Done.
| |
65 // TestCallbackListener --------------------------------------------------- | |
65 | 66 |
66 // TestNotificationObserver --------------------------------------------------- | 67 class TestCallbackListener { |
68 public: | |
69 TestCallbackListener(); | |
70 virtual ~TestCallbackListener(); | |
67 | 71 |
68 class TestNotificationObserver : public content::NotificationObserver { | 72 bool HasRegisteredCallback(); |
69 public: | 73 void RegisterCallback(GoogleURLTracker* google_url_tracker); |
70 TestNotificationObserver(); | |
71 virtual ~TestNotificationObserver(); | |
72 | 74 |
73 virtual void Observe(int type, | |
74 const content::NotificationSource& source, | |
75 const content::NotificationDetails& details) OVERRIDE; | |
76 bool notified() const { return notified_; } | 75 bool notified() const { return notified_; } |
77 void clear_notified() { notified_ = false; } | 76 void clear_notified() { notified_ = false; } |
78 | 77 |
79 private: | 78 private: |
79 void OnGoogleURLUpdated(GURL old_url, GURL new_url); | |
80 | |
80 bool notified_; | 81 bool notified_; |
82 scoped_ptr<GoogleURLTracker::Subscription> google_url_updated_subscription_; | |
81 }; | 83 }; |
82 | 84 |
83 TestNotificationObserver::TestNotificationObserver() : notified_(false) { | 85 TestCallbackListener::TestCallbackListener() : notified_(false) { |
84 } | 86 } |
85 | 87 |
86 TestNotificationObserver::~TestNotificationObserver() { | 88 TestCallbackListener::~TestCallbackListener() { |
87 } | 89 } |
88 | 90 |
89 void TestNotificationObserver::Observe( | 91 void TestCallbackListener::OnGoogleURLUpdated(GURL old_url, GURL new_url) { |
90 int type, | |
91 const content::NotificationSource& source, | |
92 const content::NotificationDetails& details) { | |
93 notified_ = true; | 92 notified_ = true; |
94 } | 93 } |
95 | 94 |
95 bool TestCallbackListener::HasRegisteredCallback() { | |
96 return google_url_updated_subscription_.get(); | |
97 } | |
98 | |
99 void TestCallbackListener::RegisterCallback( | |
100 GoogleURLTracker* google_url_tracker) { | |
101 google_url_updated_subscription_ = | |
102 google_url_tracker->RegisterCallback(base::Bind( | |
103 &TestCallbackListener::OnGoogleURLUpdated, base::Unretained(this))); | |
104 } | |
96 | 105 |
97 // TestGoogleURLTrackerNavigationHelper ------------------------------------- | 106 // TestGoogleURLTrackerNavigationHelper ------------------------------------- |
98 | 107 |
99 class TestGoogleURLTrackerNavigationHelper | 108 class TestGoogleURLTrackerNavigationHelper |
100 : public GoogleURLTrackerNavigationHelper { | 109 : public GoogleURLTrackerNavigationHelper { |
101 public: | 110 public: |
102 TestGoogleURLTrackerNavigationHelper(); | 111 TestGoogleURLTrackerNavigationHelper(); |
103 virtual ~TestGoogleURLTrackerNavigationHelper(); | 112 virtual ~TestGoogleURLTrackerNavigationHelper(); |
104 | 113 |
105 virtual void SetGoogleURLTracker(GoogleURLTracker* tracker) OVERRIDE; | 114 virtual void SetGoogleURLTracker(GoogleURLTracker* tracker) OVERRIDE; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
225 void SetLastPromptedGoogleURL(const GURL& url); | 234 void SetLastPromptedGoogleURL(const GURL& url); |
226 GURL GetLastPromptedGoogleURL(); | 235 GURL GetLastPromptedGoogleURL(); |
227 void SetNavigationPending(intptr_t unique_id, bool is_search); | 236 void SetNavigationPending(intptr_t unique_id, bool is_search); |
228 void CommitNonSearch(intptr_t unique_id); | 237 void CommitNonSearch(intptr_t unique_id); |
229 void CommitSearch(intptr_t unique_id, const GURL& search_url); | 238 void CommitSearch(intptr_t unique_id, const GURL& search_url); |
230 void CloseTab(intptr_t unique_id); | 239 void CloseTab(intptr_t unique_id); |
231 GoogleURLTrackerMapEntry* GetMapEntry(intptr_t unique_id); | 240 GoogleURLTrackerMapEntry* GetMapEntry(intptr_t unique_id); |
232 GoogleURLTrackerInfoBarDelegate* GetInfoBarDelegate(intptr_t unique_id); | 241 GoogleURLTrackerInfoBarDelegate* GetInfoBarDelegate(intptr_t unique_id); |
233 void ExpectDefaultURLs() const; | 242 void ExpectDefaultURLs() const; |
234 void ExpectListeningForCommit(intptr_t unique_id, bool listening); | 243 void ExpectListeningForCommit(intptr_t unique_id, bool listening); |
235 bool observer_notified() const { return observer_.notified(); } | 244 bool listener_notified() const { return listener_.notified(); } |
236 void clear_observer_notified() { observer_.clear_notified(); } | 245 void clear_listener_notified() { listener_.clear_notified(); } |
237 | 246 |
238 private: | 247 private: |
239 // Since |infobar_service| is really a magic number rather than an actual | 248 // Since |infobar_service| is really a magic number rather than an actual |
240 // object, we don't add the created infobar to it. Instead we will simulate | 249 // object, we don't add the created infobar to it. Instead we will simulate |
241 // any helper<->infobar interaction necessary. The returned object will be | 250 // any helper<->infobar interaction necessary. The returned object will be |
242 // cleaned up in OnInfoBarClosed(). | 251 // cleaned up in OnInfoBarClosed(). |
243 infobars::InfoBar* CreateTestInfoBar(InfoBarService* infobar_service, | 252 infobars::InfoBar* CreateTestInfoBar(InfoBarService* infobar_service, |
244 GoogleURLTracker* google_url_tracker, | 253 GoogleURLTracker* google_url_tracker, |
245 const GURL& search_url); | 254 const GURL& search_url); |
246 | 255 |
247 // These are required by the TestURLFetchers GoogleURLTracker will create (see | 256 // These are required by the TestURLFetchers GoogleURLTracker will create (see |
248 // test_url_fetcher_factory.h). | 257 // test_url_fetcher_factory.h). |
249 content::TestBrowserThreadBundle thread_bundle_; | 258 content::TestBrowserThreadBundle thread_bundle_; |
250 // Creating this allows us to call | 259 // Creating this allows us to call |
251 // net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(). | 260 // net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(). |
252 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | 261 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
253 net::TestURLFetcherFactory fetcher_factory_; | 262 net::TestURLFetcherFactory fetcher_factory_; |
254 content::NotificationRegistrar registrar_; | |
255 TestNotificationObserver observer_; | |
256 GoogleURLTrackerNavigationHelper* nav_helper_; | 263 GoogleURLTrackerNavigationHelper* nav_helper_; |
257 TestingProfile profile_; | 264 TestingProfile profile_; |
258 scoped_ptr<GoogleURLTracker> google_url_tracker_; | 265 scoped_ptr<GoogleURLTracker> google_url_tracker_; |
266 TestCallbackListener listener_; | |
259 // This tracks the different "tabs" a test has "opened", so we can close them | 267 // This tracks the different "tabs" a test has "opened", so we can close them |
260 // properly before shutting down |google_url_tracker_|, which expects that. | 268 // properly before shutting down |google_url_tracker_|, which expects that. |
261 std::set<int> unique_ids_seen_; | 269 std::set<int> unique_ids_seen_; |
262 }; | 270 }; |
263 | 271 |
264 void GoogleURLTrackerTest::OnInfoBarClosed( | 272 void GoogleURLTrackerTest::OnInfoBarClosed( |
265 scoped_ptr<infobars::InfoBar> infobar, | 273 scoped_ptr<infobars::InfoBar> infobar, |
266 InfoBarService* infobar_service) { | 274 InfoBarService* infobar_service) { |
267 // First, simulate the InfoBarService firing INFOBAR_REMOVED. | 275 // First, simulate the InfoBarService firing INFOBAR_REMOVED. |
268 infobars::InfoBar::RemovedDetails removed_details(infobar.get(), false); | 276 infobars::InfoBar::RemovedDetails removed_details(infobar.get(), false); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
300 GoogleURLTracker::UNIT_TEST_MODE)); | 308 GoogleURLTracker::UNIT_TEST_MODE)); |
301 google_url_tracker_->infobar_creator_ = base::Bind( | 309 google_url_tracker_->infobar_creator_ = base::Bind( |
302 &GoogleURLTrackerTest::CreateTestInfoBar, base::Unretained(this)); | 310 &GoogleURLTrackerTest::CreateTestInfoBar, base::Unretained(this)); |
303 } | 311 } |
304 | 312 |
305 void GoogleURLTrackerTest::TearDown() { | 313 void GoogleURLTrackerTest::TearDown() { |
306 while (!unique_ids_seen_.empty()) | 314 while (!unique_ids_seen_.empty()) |
307 CloseTab(*unique_ids_seen_.begin()); | 315 CloseTab(*unique_ids_seen_.begin()); |
308 | 316 |
309 nav_helper_ = NULL; | 317 nav_helper_ = NULL; |
310 google_url_tracker_.reset(); | |
311 network_change_notifier_.reset(); | 318 network_change_notifier_.reset(); |
312 } | 319 } |
313 | 320 |
314 net::TestURLFetcher* GoogleURLTrackerTest::GetFetcher() { | 321 net::TestURLFetcher* GoogleURLTrackerTest::GetFetcher() { |
315 // This will return the last fetcher created. If no fetchers have been | 322 // This will return the last fetcher created. If no fetchers have been |
316 // created, we'll pass GetFetcherByID() "-1", and it will return NULL. | 323 // created, we'll pass GetFetcherByID() "-1", and it will return NULL. |
317 return fetcher_factory_.GetFetcherByID(google_url_tracker_->fetcher_id_ - 1); | 324 return fetcher_factory_.GetFetcherByID(google_url_tracker_->fetcher_id_ - 1); |
318 } | 325 } |
319 | 326 |
320 void GoogleURLTrackerTest::MockSearchDomainCheckResponse( | 327 void GoogleURLTrackerTest::MockSearchDomainCheckResponse( |
321 const std::string& domain) { | 328 const std::string& domain) { |
322 net::TestURLFetcher* fetcher = GetFetcher(); | 329 net::TestURLFetcher* fetcher = GetFetcher(); |
323 if (!fetcher) | 330 if (!fetcher) |
324 return; | 331 return; |
325 fetcher_factory_.RemoveFetcherFromMap(fetcher->id()); | 332 fetcher_factory_.RemoveFetcherFromMap(fetcher->id()); |
326 fetcher->set_url(GURL(GoogleURLTracker::kSearchDomainCheckURL)); | 333 fetcher->set_url(GURL(GoogleURLTracker::kSearchDomainCheckURL)); |
327 fetcher->set_response_code(200); | 334 fetcher->set_response_code(200); |
328 fetcher->SetResponseString(domain); | 335 fetcher->SetResponseString(domain); |
329 fetcher->delegate()->OnURLFetchComplete(fetcher); | 336 fetcher->delegate()->OnURLFetchComplete(fetcher); |
330 // At this point, |fetcher| is deleted. | 337 // At this point, |fetcher| is deleted. |
331 } | 338 } |
332 | 339 |
333 void GoogleURLTrackerTest::RequestServerCheck() { | 340 void GoogleURLTrackerTest::RequestServerCheck() { |
334 if (!registrar_.IsRegistered(&observer_, | 341 if (!listener_.HasRegisteredCallback()) |
335 chrome::NOTIFICATION_GOOGLE_URL_UPDATED, | 342 listener_.RegisterCallback(google_url_tracker_.get()); |
336 content::Source<Profile>(&profile_))) { | |
337 registrar_.Add(&observer_, chrome::NOTIFICATION_GOOGLE_URL_UPDATED, | |
338 content::Source<Profile>(&profile_)); | |
339 } | |
340 google_url_tracker_->SetNeedToFetch(); | 343 google_url_tracker_->SetNeedToFetch(); |
341 } | 344 } |
342 | 345 |
343 void GoogleURLTrackerTest::FinishSleep() { | 346 void GoogleURLTrackerTest::FinishSleep() { |
344 google_url_tracker_->FinishSleep(); | 347 google_url_tracker_->FinishSleep(); |
345 } | 348 } |
346 | 349 |
347 void GoogleURLTrackerTest::NotifyIPAddressChanged() { | 350 void GoogleURLTrackerTest::NotifyIPAddressChanged() { |
348 net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 351 net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
349 // For thread safety, the NCN queues tasks to do the actual notifications, so | 352 // For thread safety, the NCN queues tasks to do the actual notifications, so |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
500 | 503 |
501 // Tests ---------------------------------------------------------------------- | 504 // Tests ---------------------------------------------------------------------- |
502 | 505 |
503 TEST_F(GoogleURLTrackerTest, DontFetchWhenNoOneRequestsCheck) { | 506 TEST_F(GoogleURLTrackerTest, DontFetchWhenNoOneRequestsCheck) { |
504 ExpectDefaultURLs(); | 507 ExpectDefaultURLs(); |
505 FinishSleep(); | 508 FinishSleep(); |
506 // No one called RequestServerCheck() so nothing should have happened. | 509 // No one called RequestServerCheck() so nothing should have happened. |
507 EXPECT_FALSE(GetFetcher()); | 510 EXPECT_FALSE(GetFetcher()); |
508 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 511 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
509 ExpectDefaultURLs(); | 512 ExpectDefaultURLs(); |
510 EXPECT_FALSE(observer_notified()); | 513 EXPECT_FALSE(listener_notified()); |
511 } | 514 } |
512 | 515 |
513 TEST_F(GoogleURLTrackerTest, UpdateOnFirstRun) { | 516 TEST_F(GoogleURLTrackerTest, UpdateOnFirstRun) { |
514 RequestServerCheck(); | 517 RequestServerCheck(); |
515 EXPECT_FALSE(GetFetcher()); | 518 EXPECT_FALSE(GetFetcher()); |
516 ExpectDefaultURLs(); | 519 ExpectDefaultURLs(); |
517 EXPECT_FALSE(observer_notified()); | 520 EXPECT_FALSE(listener_notified()); |
518 | 521 |
519 FinishSleep(); | 522 FinishSleep(); |
520 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 523 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
521 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 524 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
522 // GoogleURL should be updated, becase there was no last prompted URL. | 525 // GoogleURL should be updated, becase there was no last prompted URL. |
523 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 526 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
524 EXPECT_TRUE(observer_notified()); | 527 EXPECT_TRUE(listener_notified()); |
525 } | 528 } |
526 | 529 |
527 TEST_F(GoogleURLTrackerTest, DontUpdateWhenUnchanged) { | 530 TEST_F(GoogleURLTrackerTest, DontUpdateWhenUnchanged) { |
528 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 531 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
529 | 532 |
530 RequestServerCheck(); | 533 RequestServerCheck(); |
531 EXPECT_FALSE(GetFetcher()); | 534 EXPECT_FALSE(GetFetcher()); |
532 ExpectDefaultURLs(); | 535 ExpectDefaultURLs(); |
533 EXPECT_FALSE(observer_notified()); | 536 EXPECT_FALSE(listener_notified()); |
534 | 537 |
535 FinishSleep(); | 538 FinishSleep(); |
536 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 539 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
537 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 540 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
538 // GoogleURL should not be updated, because the fetched and prompted URLs | 541 // GoogleURL should not be updated, because the fetched and prompted URLs |
539 // match. | 542 // match. |
540 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 543 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
541 EXPECT_FALSE(observer_notified()); | 544 EXPECT_FALSE(listener_notified()); |
542 } | 545 } |
543 | 546 |
544 TEST_F(GoogleURLTrackerTest, DontPromptOnBadReplies) { | 547 TEST_F(GoogleURLTrackerTest, DontPromptOnBadReplies) { |
545 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 548 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
546 | 549 |
547 RequestServerCheck(); | 550 RequestServerCheck(); |
548 EXPECT_FALSE(GetFetcher()); | 551 EXPECT_FALSE(GetFetcher()); |
549 ExpectDefaultURLs(); | 552 ExpectDefaultURLs(); |
550 EXPECT_FALSE(observer_notified()); | 553 EXPECT_FALSE(listener_notified()); |
551 | 554 |
552 // Old-style domain string. | 555 // Old-style domain string. |
553 FinishSleep(); | 556 FinishSleep(); |
554 MockSearchDomainCheckResponse(".google.co.in"); | 557 MockSearchDomainCheckResponse(".google.co.in"); |
555 EXPECT_EQ(GURL(), fetched_google_url()); | 558 EXPECT_EQ(GURL(), fetched_google_url()); |
556 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 559 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
557 EXPECT_FALSE(observer_notified()); | 560 EXPECT_FALSE(listener_notified()); |
558 SetNavigationPending(1, true); | 561 SetNavigationPending(1, true); |
559 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 562 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
560 EXPECT_TRUE(GetMapEntry(1) == NULL); | 563 EXPECT_TRUE(GetMapEntry(1) == NULL); |
561 | 564 |
562 // Bad subdomain. | 565 // Bad subdomain. |
563 NotifyIPAddressChanged(); | 566 NotifyIPAddressChanged(); |
564 MockSearchDomainCheckResponse("http://mail.google.com/"); | 567 MockSearchDomainCheckResponse("http://mail.google.com/"); |
565 EXPECT_EQ(GURL(), fetched_google_url()); | 568 EXPECT_EQ(GURL(), fetched_google_url()); |
566 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 569 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
567 EXPECT_FALSE(observer_notified()); | 570 EXPECT_FALSE(listener_notified()); |
568 SetNavigationPending(1, true); | 571 SetNavigationPending(1, true); |
569 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 572 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
570 EXPECT_TRUE(GetMapEntry(1) == NULL); | 573 EXPECT_TRUE(GetMapEntry(1) == NULL); |
571 | 574 |
572 // Non-empty path. | 575 // Non-empty path. |
573 NotifyIPAddressChanged(); | 576 NotifyIPAddressChanged(); |
574 MockSearchDomainCheckResponse("http://www.google.com/search"); | 577 MockSearchDomainCheckResponse("http://www.google.com/search"); |
575 EXPECT_EQ(GURL(), fetched_google_url()); | 578 EXPECT_EQ(GURL(), fetched_google_url()); |
576 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 579 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
577 EXPECT_FALSE(observer_notified()); | 580 EXPECT_FALSE(listener_notified()); |
578 SetNavigationPending(1, true); | 581 SetNavigationPending(1, true); |
579 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 582 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
580 EXPECT_TRUE(GetMapEntry(1) == NULL); | 583 EXPECT_TRUE(GetMapEntry(1) == NULL); |
581 | 584 |
582 // Non-empty query. | 585 // Non-empty query. |
583 NotifyIPAddressChanged(); | 586 NotifyIPAddressChanged(); |
584 MockSearchDomainCheckResponse("http://www.google.com/?q=foo"); | 587 MockSearchDomainCheckResponse("http://www.google.com/?q=foo"); |
585 EXPECT_EQ(GURL(), fetched_google_url()); | 588 EXPECT_EQ(GURL(), fetched_google_url()); |
586 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 589 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
587 EXPECT_FALSE(observer_notified()); | 590 EXPECT_FALSE(listener_notified()); |
588 SetNavigationPending(1, true); | 591 SetNavigationPending(1, true); |
589 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 592 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
590 EXPECT_TRUE(GetMapEntry(1) == NULL); | 593 EXPECT_TRUE(GetMapEntry(1) == NULL); |
591 | 594 |
592 // Non-empty ref. | 595 // Non-empty ref. |
593 NotifyIPAddressChanged(); | 596 NotifyIPAddressChanged(); |
594 MockSearchDomainCheckResponse("http://www.google.com/#anchor"); | 597 MockSearchDomainCheckResponse("http://www.google.com/#anchor"); |
595 EXPECT_EQ(GURL(), fetched_google_url()); | 598 EXPECT_EQ(GURL(), fetched_google_url()); |
596 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 599 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
597 EXPECT_FALSE(observer_notified()); | 600 EXPECT_FALSE(listener_notified()); |
598 SetNavigationPending(1, true); | 601 SetNavigationPending(1, true); |
599 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 602 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
600 EXPECT_TRUE(GetMapEntry(1) == NULL); | 603 EXPECT_TRUE(GetMapEntry(1) == NULL); |
601 | 604 |
602 // Complete garbage. | 605 // Complete garbage. |
603 NotifyIPAddressChanged(); | 606 NotifyIPAddressChanged(); |
604 MockSearchDomainCheckResponse("HJ)*qF)_*&@f1"); | 607 MockSearchDomainCheckResponse("HJ)*qF)_*&@f1"); |
605 EXPECT_EQ(GURL(), fetched_google_url()); | 608 EXPECT_EQ(GURL(), fetched_google_url()); |
606 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 609 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
607 EXPECT_FALSE(observer_notified()); | 610 EXPECT_FALSE(listener_notified()); |
608 SetNavigationPending(1, true); | 611 SetNavigationPending(1, true); |
609 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 612 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
610 EXPECT_TRUE(GetMapEntry(1) == NULL); | 613 EXPECT_TRUE(GetMapEntry(1) == NULL); |
611 } | 614 } |
612 | 615 |
613 TEST_F(GoogleURLTrackerTest, UpdatePromptedURLOnReturnToPreviousLocation) { | 616 TEST_F(GoogleURLTrackerTest, UpdatePromptedURLOnReturnToPreviousLocation) { |
614 SetLastPromptedGoogleURL(GURL("http://www.google.co.jp/")); | 617 SetLastPromptedGoogleURL(GURL("http://www.google.co.jp/")); |
615 set_google_url(GURL("http://www.google.co.uk/")); | 618 set_google_url(GURL("http://www.google.co.uk/")); |
616 RequestServerCheck(); | 619 RequestServerCheck(); |
617 FinishSleep(); | 620 FinishSleep(); |
618 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 621 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
619 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 622 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
620 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 623 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
621 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 624 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
622 EXPECT_FALSE(observer_notified()); | 625 EXPECT_FALSE(listener_notified()); |
623 } | 626 } |
624 | 627 |
625 TEST_F(GoogleURLTrackerTest, SilentlyAcceptSchemeChange) { | 628 TEST_F(GoogleURLTrackerTest, SilentlyAcceptSchemeChange) { |
626 // We should auto-accept changes to the current Google URL that merely change | 629 // We should auto-accept changes to the current Google URL that merely change |
627 // the scheme, regardless of what the last prompted URL was. | 630 // the scheme, regardless of what the last prompted URL was. |
628 SetLastPromptedGoogleURL(GURL("http://www.google.co.jp/")); | 631 SetLastPromptedGoogleURL(GURL("http://www.google.co.jp/")); |
629 set_google_url(GURL("http://www.google.co.uk/")); | 632 set_google_url(GURL("http://www.google.co.uk/")); |
630 RequestServerCheck(); | 633 RequestServerCheck(); |
631 FinishSleep(); | 634 FinishSleep(); |
632 MockSearchDomainCheckResponse("https://www.google.co.uk/"); | 635 MockSearchDomainCheckResponse("https://www.google.co.uk/"); |
633 EXPECT_EQ(GURL("https://www.google.co.uk/"), fetched_google_url()); | 636 EXPECT_EQ(GURL("https://www.google.co.uk/"), fetched_google_url()); |
634 EXPECT_EQ(GURL("https://www.google.co.uk/"), google_url()); | 637 EXPECT_EQ(GURL("https://www.google.co.uk/"), google_url()); |
635 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 638 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
636 EXPECT_TRUE(observer_notified()); | 639 EXPECT_TRUE(listener_notified()); |
637 | 640 |
638 NotifyIPAddressChanged(); | 641 NotifyIPAddressChanged(); |
639 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 642 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
640 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 643 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
641 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 644 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
642 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 645 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
643 EXPECT_TRUE(observer_notified()); | 646 EXPECT_TRUE(listener_notified()); |
644 } | 647 } |
645 | 648 |
646 TEST_F(GoogleURLTrackerTest, RefetchOnIPAddressChange) { | 649 TEST_F(GoogleURLTrackerTest, RefetchOnIPAddressChange) { |
647 RequestServerCheck(); | 650 RequestServerCheck(); |
648 FinishSleep(); | 651 FinishSleep(); |
649 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 652 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
650 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 653 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
651 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 654 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
652 EXPECT_TRUE(observer_notified()); | 655 EXPECT_TRUE(listener_notified()); |
653 clear_observer_notified(); | 656 clear_listener_notified(); |
654 | 657 |
655 NotifyIPAddressChanged(); | 658 NotifyIPAddressChanged(); |
656 MockSearchDomainCheckResponse("http://www.google.co.in/"); | 659 MockSearchDomainCheckResponse("http://www.google.co.in/"); |
657 EXPECT_EQ(GURL("http://www.google.co.in/"), fetched_google_url()); | 660 EXPECT_EQ(GURL("http://www.google.co.in/"), fetched_google_url()); |
658 // Just fetching a new URL shouldn't reset things without a prompt. | 661 // Just fetching a new URL shouldn't reset things without a prompt. |
659 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 662 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
660 EXPECT_FALSE(observer_notified()); | 663 EXPECT_FALSE(listener_notified()); |
661 } | 664 } |
662 | 665 |
663 TEST_F(GoogleURLTrackerTest, DontRefetchWhenNoOneRequestsCheck) { | 666 TEST_F(GoogleURLTrackerTest, DontRefetchWhenNoOneRequestsCheck) { |
664 FinishSleep(); | 667 FinishSleep(); |
665 NotifyIPAddressChanged(); | 668 NotifyIPAddressChanged(); |
666 // No one called RequestServerCheck() so nothing should have happened. | 669 // No one called RequestServerCheck() so nothing should have happened. |
667 EXPECT_FALSE(GetFetcher()); | 670 EXPECT_FALSE(GetFetcher()); |
668 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 671 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
669 ExpectDefaultURLs(); | 672 ExpectDefaultURLs(); |
670 EXPECT_FALSE(observer_notified()); | 673 EXPECT_FALSE(listener_notified()); |
671 } | 674 } |
672 | 675 |
673 TEST_F(GoogleURLTrackerTest, FetchOnLateRequest) { | 676 TEST_F(GoogleURLTrackerTest, FetchOnLateRequest) { |
674 FinishSleep(); | 677 FinishSleep(); |
675 NotifyIPAddressChanged(); | 678 NotifyIPAddressChanged(); |
676 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 679 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
677 | 680 |
678 RequestServerCheck(); | 681 RequestServerCheck(); |
679 // The first request for a check should trigger a fetch if it hasn't happened | 682 // The first request for a check should trigger a fetch if it hasn't happened |
680 // already. | 683 // already. |
681 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 684 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
682 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 685 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
683 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 686 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
684 EXPECT_TRUE(observer_notified()); | 687 EXPECT_TRUE(listener_notified()); |
685 } | 688 } |
686 | 689 |
687 TEST_F(GoogleURLTrackerTest, DontFetchTwiceOnLateRequests) { | 690 TEST_F(GoogleURLTrackerTest, DontFetchTwiceOnLateRequests) { |
688 FinishSleep(); | 691 FinishSleep(); |
689 NotifyIPAddressChanged(); | 692 NotifyIPAddressChanged(); |
690 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 693 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
691 | 694 |
692 RequestServerCheck(); | 695 RequestServerCheck(); |
693 // The first request for a check should trigger a fetch if it hasn't happened | 696 // The first request for a check should trigger a fetch if it hasn't happened |
694 // already. | 697 // already. |
695 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 698 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
696 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 699 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
697 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 700 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
698 EXPECT_TRUE(observer_notified()); | 701 EXPECT_TRUE(listener_notified()); |
699 clear_observer_notified(); | 702 clear_listener_notified(); |
700 | 703 |
701 RequestServerCheck(); | 704 RequestServerCheck(); |
702 // The second request should be ignored. | 705 // The second request should be ignored. |
703 EXPECT_FALSE(GetFetcher()); | 706 EXPECT_FALSE(GetFetcher()); |
704 MockSearchDomainCheckResponse("http://www.google.co.in/"); | 707 MockSearchDomainCheckResponse("http://www.google.co.in/"); |
705 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 708 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
706 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 709 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
707 EXPECT_FALSE(observer_notified()); | 710 EXPECT_FALSE(listener_notified()); |
708 } | 711 } |
709 | 712 |
710 TEST_F(GoogleURLTrackerTest, SearchingDoesNothingIfNoNeedToPrompt) { | 713 TEST_F(GoogleURLTrackerTest, SearchingDoesNothingIfNoNeedToPrompt) { |
711 RequestServerCheck(); | 714 RequestServerCheck(); |
712 FinishSleep(); | 715 FinishSleep(); |
713 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 716 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
714 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 717 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
715 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 718 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
716 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 719 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
717 EXPECT_TRUE(observer_notified()); | 720 EXPECT_TRUE(listener_notified()); |
718 clear_observer_notified(); | 721 clear_listener_notified(); |
719 | 722 |
720 SetNavigationPending(1, true); | 723 SetNavigationPending(1, true); |
721 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 724 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
722 EXPECT_TRUE(GetMapEntry(1) == NULL); | 725 EXPECT_TRUE(GetMapEntry(1) == NULL); |
723 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 726 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
724 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 727 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
725 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 728 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
726 EXPECT_FALSE(observer_notified()); | 729 EXPECT_FALSE(listener_notified()); |
727 } | 730 } |
728 | 731 |
729 TEST_F(GoogleURLTrackerTest, TabClosedOnPendingSearch) { | 732 TEST_F(GoogleURLTrackerTest, TabClosedOnPendingSearch) { |
730 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 733 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
731 RequestServerCheck(); | 734 RequestServerCheck(); |
732 FinishSleep(); | 735 FinishSleep(); |
733 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 736 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
734 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 737 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
735 EXPECT_EQ(GURL("http://www.google.co.jp/"), fetched_google_url()); | 738 EXPECT_EQ(GURL("http://www.google.co.jp/"), fetched_google_url()); |
736 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 739 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
737 EXPECT_FALSE(observer_notified()); | 740 EXPECT_FALSE(listener_notified()); |
738 | 741 |
739 SetNavigationPending(1, true); | 742 SetNavigationPending(1, true); |
740 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(1); | 743 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(1); |
741 ASSERT_FALSE(map_entry == NULL); | 744 ASSERT_FALSE(map_entry == NULL); |
742 EXPECT_FALSE(map_entry->has_infobar_delegate()); | 745 EXPECT_FALSE(map_entry->has_infobar_delegate()); |
743 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 746 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
744 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 747 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
745 EXPECT_FALSE(observer_notified()); | 748 EXPECT_FALSE(listener_notified()); |
746 | 749 |
747 CloseTab(1); | 750 CloseTab(1); |
748 EXPECT_TRUE(GetMapEntry(1) == NULL); | 751 EXPECT_TRUE(GetMapEntry(1) == NULL); |
749 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 752 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
750 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 753 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
751 EXPECT_FALSE(observer_notified()); | 754 EXPECT_FALSE(listener_notified()); |
752 } | 755 } |
753 | 756 |
754 TEST_F(GoogleURLTrackerTest, TabClosedOnCommittedSearch) { | 757 TEST_F(GoogleURLTrackerTest, TabClosedOnCommittedSearch) { |
755 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 758 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
756 RequestServerCheck(); | 759 RequestServerCheck(); |
757 FinishSleep(); | 760 FinishSleep(); |
758 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 761 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
759 | 762 |
760 SetNavigationPending(1, true); | 763 SetNavigationPending(1, true); |
761 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 764 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
762 EXPECT_FALSE(GetInfoBarDelegate(1) == NULL); | 765 EXPECT_FALSE(GetInfoBarDelegate(1) == NULL); |
763 | 766 |
764 CloseTab(1); | 767 CloseTab(1); |
765 EXPECT_TRUE(GetMapEntry(1) == NULL); | 768 EXPECT_TRUE(GetMapEntry(1) == NULL); |
766 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 769 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
767 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 770 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
768 EXPECT_FALSE(observer_notified()); | 771 EXPECT_FALSE(listener_notified()); |
769 } | 772 } |
770 | 773 |
771 TEST_F(GoogleURLTrackerTest, InfoBarClosed) { | 774 TEST_F(GoogleURLTrackerTest, InfoBarClosed) { |
772 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 775 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
773 RequestServerCheck(); | 776 RequestServerCheck(); |
774 FinishSleep(); | 777 FinishSleep(); |
775 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 778 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
776 | 779 |
777 SetNavigationPending(1, true); | 780 SetNavigationPending(1, true); |
778 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 781 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
779 GoogleURLTrackerInfoBarDelegate* infobar = GetInfoBarDelegate(1); | 782 GoogleURLTrackerInfoBarDelegate* infobar = GetInfoBarDelegate(1); |
780 ASSERT_FALSE(infobar == NULL); | 783 ASSERT_FALSE(infobar == NULL); |
781 | 784 |
782 infobar->Close(false); | 785 infobar->Close(false); |
783 EXPECT_TRUE(GetMapEntry(1) == NULL); | 786 EXPECT_TRUE(GetMapEntry(1) == NULL); |
784 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 787 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
785 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 788 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
786 EXPECT_FALSE(observer_notified()); | 789 EXPECT_FALSE(listener_notified()); |
787 } | 790 } |
788 | 791 |
789 TEST_F(GoogleURLTrackerTest, InfoBarRefused) { | 792 TEST_F(GoogleURLTrackerTest, InfoBarRefused) { |
790 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 793 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
791 RequestServerCheck(); | 794 RequestServerCheck(); |
792 FinishSleep(); | 795 FinishSleep(); |
793 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 796 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
794 | 797 |
795 SetNavigationPending(1, true); | 798 SetNavigationPending(1, true); |
796 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 799 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
797 GoogleURLTrackerInfoBarDelegate* infobar = GetInfoBarDelegate(1); | 800 GoogleURLTrackerInfoBarDelegate* infobar = GetInfoBarDelegate(1); |
798 ASSERT_FALSE(infobar == NULL); | 801 ASSERT_FALSE(infobar == NULL); |
799 | 802 |
800 infobar->Cancel(); | 803 infobar->Cancel(); |
801 EXPECT_TRUE(GetMapEntry(1) == NULL); | 804 EXPECT_TRUE(GetMapEntry(1) == NULL); |
802 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 805 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
803 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); | 806 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); |
804 EXPECT_FALSE(observer_notified()); | 807 EXPECT_FALSE(listener_notified()); |
805 } | 808 } |
806 | 809 |
807 TEST_F(GoogleURLTrackerTest, InfoBarAccepted) { | 810 TEST_F(GoogleURLTrackerTest, InfoBarAccepted) { |
808 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 811 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
809 RequestServerCheck(); | 812 RequestServerCheck(); |
810 FinishSleep(); | 813 FinishSleep(); |
811 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 814 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
812 | 815 |
813 SetNavigationPending(1, true); | 816 SetNavigationPending(1, true); |
814 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 817 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
815 GoogleURLTrackerInfoBarDelegate* infobar = GetInfoBarDelegate(1); | 818 GoogleURLTrackerInfoBarDelegate* infobar = GetInfoBarDelegate(1); |
816 ASSERT_FALSE(infobar == NULL); | 819 ASSERT_FALSE(infobar == NULL); |
817 | 820 |
818 infobar->Accept(); | 821 infobar->Accept(); |
819 EXPECT_TRUE(GetMapEntry(1) == NULL); | 822 EXPECT_TRUE(GetMapEntry(1) == NULL); |
820 EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url()); | 823 EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url()); |
821 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); | 824 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); |
822 EXPECT_TRUE(observer_notified()); | 825 EXPECT_TRUE(listener_notified()); |
823 } | 826 } |
824 | 827 |
825 TEST_F(GoogleURLTrackerTest, FetchesCanAutomaticallyCloseInfoBars) { | 828 TEST_F(GoogleURLTrackerTest, FetchesCanAutomaticallyCloseInfoBars) { |
826 RequestServerCheck(); | 829 RequestServerCheck(); |
827 FinishSleep(); | 830 FinishSleep(); |
828 MockSearchDomainCheckResponse(google_url().spec()); | 831 MockSearchDomainCheckResponse(google_url().spec()); |
829 | 832 |
830 // Re-fetching the accepted URL after showing an infobar for another URL | 833 // Re-fetching the accepted URL after showing an infobar for another URL |
831 // should close the infobar. | 834 // should close the infobar. |
832 NotifyIPAddressChanged(); | 835 NotifyIPAddressChanged(); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
935 SetNavigationPending(1, true); | 938 SetNavigationPending(1, true); |
936 ASSERT_EQ(map_entry, GetMapEntry(1)); | 939 ASSERT_EQ(map_entry, GetMapEntry(1)); |
937 EXPECT_FALSE(map_entry->has_infobar_delegate()); | 940 EXPECT_FALSE(map_entry->has_infobar_delegate()); |
938 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); | 941 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); |
939 | 942 |
940 // Committing this search should show an infobar. | 943 // Committing this search should show an infobar. |
941 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test2")); | 944 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test2")); |
942 EXPECT_TRUE(map_entry->has_infobar_delegate()); | 945 EXPECT_TRUE(map_entry->has_infobar_delegate()); |
943 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 946 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
944 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 947 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
945 EXPECT_FALSE(observer_notified()); | 948 EXPECT_FALSE(listener_notified()); |
946 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); | 949 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); |
947 } | 950 } |
948 | 951 |
949 TEST_F(GoogleURLTrackerTest, NavigationsAfterCommittedSearch) { | 952 TEST_F(GoogleURLTrackerTest, NavigationsAfterCommittedSearch) { |
950 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 953 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
951 RequestServerCheck(); | 954 RequestServerCheck(); |
952 FinishSleep(); | 955 FinishSleep(); |
953 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 956 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
954 SetNavigationPending(1, true); | 957 SetNavigationPending(1, true); |
955 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 958 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1007 | 1010 |
1008 // Committing this search should change the visible infobar's search_url. | 1011 // Committing this search should change the visible infobar's search_url. |
1009 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test2")); | 1012 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test2")); |
1010 ASSERT_EQ(delegate, GetInfoBarDelegate(1)); | 1013 ASSERT_EQ(delegate, GetInfoBarDelegate(1)); |
1011 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test2"), | 1014 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test2"), |
1012 delegate->search_url()); | 1015 delegate->search_url()); |
1013 EXPECT_EQ(0, delegate->pending_id()); | 1016 EXPECT_EQ(0, delegate->pending_id()); |
1014 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); | 1017 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); |
1015 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 1018 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
1016 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 1019 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
1017 EXPECT_FALSE(observer_notified()); | 1020 EXPECT_FALSE(listener_notified()); |
1018 } | 1021 } |
1019 | 1022 |
1020 TEST_F(GoogleURLTrackerTest, MultipleMapEntries) { | 1023 TEST_F(GoogleURLTrackerTest, MultipleMapEntries) { |
1021 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 1024 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
1022 RequestServerCheck(); | 1025 RequestServerCheck(); |
1023 FinishSleep(); | 1026 FinishSleep(); |
1024 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 1027 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
1025 | 1028 |
1026 SetNavigationPending(1, true); | 1029 SetNavigationPending(1, true); |
1027 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(1); | 1030 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(1); |
(...skipping 17 matching lines...) Expand all Loading... | |
1045 GoogleURLTrackerInfoBarDelegate* delegate4 = GetInfoBarDelegate(4); | 1048 GoogleURLTrackerInfoBarDelegate* delegate4 = GetInfoBarDelegate(4); |
1046 ASSERT_FALSE(delegate4 == NULL); | 1049 ASSERT_FALSE(delegate4 == NULL); |
1047 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test4"), | 1050 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test4"), |
1048 delegate4->search_url()); | 1051 delegate4->search_url()); |
1049 | 1052 |
1050 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 1053 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
1051 EXPECT_TRUE(map_entry->has_infobar_delegate()); | 1054 EXPECT_TRUE(map_entry->has_infobar_delegate()); |
1052 | 1055 |
1053 delegate2->Close(false); | 1056 delegate2->Close(false); |
1054 EXPECT_TRUE(GetMapEntry(2) == NULL); | 1057 EXPECT_TRUE(GetMapEntry(2) == NULL); |
1055 EXPECT_FALSE(observer_notified()); | 1058 EXPECT_FALSE(listener_notified()); |
1056 | 1059 |
1057 delegate4->Accept(); | 1060 delegate4->Accept(); |
1058 EXPECT_TRUE(GetMapEntry(1) == NULL); | 1061 EXPECT_TRUE(GetMapEntry(1) == NULL); |
1059 EXPECT_TRUE(GetMapEntry(3) == NULL); | 1062 EXPECT_TRUE(GetMapEntry(3) == NULL); |
1060 EXPECT_TRUE(GetMapEntry(4) == NULL); | 1063 EXPECT_TRUE(GetMapEntry(4) == NULL); |
1061 EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url()); | 1064 EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url()); |
1062 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); | 1065 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); |
1063 EXPECT_TRUE(observer_notified()); | 1066 EXPECT_TRUE(listener_notified()); |
1064 } | 1067 } |
1065 | 1068 |
1066 TEST_F(GoogleURLTrackerTest, IgnoreIrrelevantNavigation) { | 1069 TEST_F(GoogleURLTrackerTest, IgnoreIrrelevantNavigation) { |
1067 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 1070 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
1068 RequestServerCheck(); | 1071 RequestServerCheck(); |
1069 FinishSleep(); | 1072 FinishSleep(); |
1070 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 1073 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
1071 | 1074 |
1072 // This tests a particularly gnarly sequence of events that used to cause us | 1075 // This tests a particularly gnarly sequence of events that used to cause us |
1073 // to erroneously listen for a non-search navigation to commit. | 1076 // to erroneously listen for a non-search navigation to commit. |
1074 SetNavigationPending(1, true); | 1077 SetNavigationPending(1, true); |
1075 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 1078 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
1076 SetNavigationPending(2, true); | 1079 SetNavigationPending(2, true); |
1077 CommitSearch(2, GURL("http://www.google.co.uk/search?q=test2")); | 1080 CommitSearch(2, GURL("http://www.google.co.uk/search?q=test2")); |
1078 EXPECT_FALSE(GetInfoBarDelegate(1) == NULL); | 1081 EXPECT_FALSE(GetInfoBarDelegate(1) == NULL); |
1079 GoogleURLTrackerInfoBarDelegate* delegate2 = GetInfoBarDelegate(2); | 1082 GoogleURLTrackerInfoBarDelegate* delegate2 = GetInfoBarDelegate(2); |
1080 ASSERT_FALSE(delegate2 == NULL); | 1083 ASSERT_FALSE(delegate2 == NULL); |
1081 SetNavigationPending(1, true); | 1084 SetNavigationPending(1, true); |
1082 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); | 1085 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); |
1083 delegate2->Close(false); | 1086 delegate2->Close(false); |
1084 SetNavigationPending(1, false); | 1087 SetNavigationPending(1, false); |
1085 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); | 1088 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); |
1086 } | 1089 } |
OLD | NEW |