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