Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Side by Side Diff: chrome/browser/google/google_url_tracker_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698