Renamed namespaces in src/chrome.
[chromium-blink-merge.git] / chrome / browser / google / google_url_tracker_unittest.cc
blob1ebe61369cfad3fc5d09681fe5f7d55e12707313
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
3 // found in the LICENSE file.
5 #include "chrome/browser/google/google_url_tracker.h"
7 #include <set>
8 #include <string>
10 #include "base/message_loop/message_loop.h"
11 #include "base/prefs/pref_service.h"
12 #include "chrome/browser/chrome_notification_types.h"
13 #include "chrome/browser/google/google_url_tracker_factory.h"
14 #include "chrome/browser/google/google_url_tracker_infobar_delegate.h"
15 #include "chrome/browser/google/google_url_tracker_navigation_helper.h"
16 #include "chrome/common/pref_names.h"
17 #include "chrome/test/base/testing_profile.h"
18 #include "components/infobars/core/infobar.h"
19 #include "components/infobars/core/infobar_delegate.h"
20 #include "content/public/browser/notification_service.h"
21 #include "content/public/test/test_browser_thread_bundle.h"
22 #include "net/url_request/test_url_fetcher_factory.h"
23 #include "net/url_request/url_fetcher.h"
24 #include "testing/gtest/include/gtest/gtest.h"
26 class GoogleURLTrackerTest;
28 namespace {
30 // TestInfoBarDelegate --------------------------------------------------------
32 class TestInfoBarDelegate : public GoogleURLTrackerInfoBarDelegate {
33 public:
34 // Creates a test infobar and delegate and returns the infobar. Unlike the
35 // parent class, this does not add the infobar to |infobar_service|, since
36 // that "pointer" is really just a magic number. Thus there is no
37 // InfoBarService ownership of the returned object; and since the caller
38 // doesn't own the returned object, we rely on |test_harness| cleaning this up
39 // eventually in GoogleURLTrackerTest::OnInfoBarClosed() to avoid leaks.
40 static infobars::InfoBar* Create(GoogleURLTrackerTest* test_harness,
41 InfoBarService* infobar_service,
42 GoogleURLTracker* google_url_tracker,
43 const GURL& search_url);
45 private:
46 TestInfoBarDelegate(GoogleURLTrackerTest* test_harness,
47 InfoBarService* infobar_service,
48 GoogleURLTracker* google_url_tracker,
49 const GURL& search_url);
50 virtual ~TestInfoBarDelegate();
52 // GoogleURLTrackerInfoBarDelegate:
53 virtual void Update(const GURL& search_url) OVERRIDE;
54 virtual void Close(bool redo_search) OVERRIDE;
56 GoogleURLTrackerTest* test_harness_;
57 InfoBarService* infobar_service_;
59 DISALLOW_COPY_AND_ASSIGN(TestInfoBarDelegate);
62 // The member function definitions come after the declaration of
63 // GoogleURLTrackerTest, so they can call members on it.
66 // TestNotificationObserver ---------------------------------------------------
68 class TestNotificationObserver : public content::NotificationObserver {
69 public:
70 TestNotificationObserver();
71 virtual ~TestNotificationObserver();
73 virtual void Observe(int type,
74 const content::NotificationSource& source,
75 const content::NotificationDetails& details) OVERRIDE;
76 bool notified() const { return notified_; }
77 void clear_notified() { notified_ = false; }
79 private:
80 bool notified_;
83 TestNotificationObserver::TestNotificationObserver() : notified_(false) {
86 TestNotificationObserver::~TestNotificationObserver() {
89 void TestNotificationObserver::Observe(
90 int type,
91 const content::NotificationSource& source,
92 const content::NotificationDetails& details) {
93 notified_ = true;
97 // TestGoogleURLTrackerNavigationHelper -------------------------------------
99 class TestGoogleURLTrackerNavigationHelper
100 : public GoogleURLTrackerNavigationHelper {
101 public:
102 TestGoogleURLTrackerNavigationHelper();
103 virtual ~TestGoogleURLTrackerNavigationHelper();
105 virtual void SetGoogleURLTracker(GoogleURLTracker* tracker) OVERRIDE;
106 virtual void SetListeningForNavigationStart(bool listen) OVERRIDE;
107 virtual bool IsListeningForNavigationStart() OVERRIDE;
108 virtual void SetListeningForNavigationCommit(
109 const content::NavigationController* nav_controller,
110 bool listen) OVERRIDE;
111 virtual bool IsListeningForNavigationCommit(
112 const content::NavigationController* nav_controller) OVERRIDE;
113 virtual void SetListeningForTabDestruction(
114 const content::NavigationController* nav_controller,
115 bool listen) OVERRIDE;
116 virtual bool IsListeningForTabDestruction(
117 const content::NavigationController* nav_controller) OVERRIDE;
119 private:
120 GoogleURLTracker* tracker_;
121 bool observe_nav_start_;
122 std::set<const content::NavigationController*>
123 nav_controller_commit_listeners_;
124 std::set<const content::NavigationController*>
125 nav_controller_tab_close_listeners_;
128 TestGoogleURLTrackerNavigationHelper::TestGoogleURLTrackerNavigationHelper()
129 : tracker_(NULL),
130 observe_nav_start_(false) {
133 TestGoogleURLTrackerNavigationHelper::
134 ~TestGoogleURLTrackerNavigationHelper() {
137 void TestGoogleURLTrackerNavigationHelper::SetGoogleURLTracker(
138 GoogleURLTracker* tracker) {
139 tracker_ = tracker;
142 void TestGoogleURLTrackerNavigationHelper::SetListeningForNavigationStart(
143 bool listen) {
144 observe_nav_start_ = listen;
147 bool TestGoogleURLTrackerNavigationHelper::IsListeningForNavigationStart() {
148 return observe_nav_start_;
151 void TestGoogleURLTrackerNavigationHelper::SetListeningForNavigationCommit(
152 const content::NavigationController* nav_controller,
153 bool listen) {
154 if (listen)
155 nav_controller_commit_listeners_.insert(nav_controller);
156 else
157 nav_controller_commit_listeners_.erase(nav_controller);
160 bool TestGoogleURLTrackerNavigationHelper::IsListeningForNavigationCommit(
161 const content::NavigationController* nav_controller) {
162 return nav_controller_commit_listeners_.count(nav_controller) > 0;
165 void TestGoogleURLTrackerNavigationHelper::SetListeningForTabDestruction(
166 const content::NavigationController* nav_controller,
167 bool listen) {
168 if (listen)
169 nav_controller_tab_close_listeners_.insert(nav_controller);
170 else
171 nav_controller_tab_close_listeners_.erase(nav_controller);
174 bool TestGoogleURLTrackerNavigationHelper::IsListeningForTabDestruction(
175 const content::NavigationController* nav_controller) {
176 return nav_controller_tab_close_listeners_.count(nav_controller) > 0;
179 } // namespace
182 // GoogleURLTrackerTest -------------------------------------------------------
184 // Ths class exercises GoogleURLTracker. In order to avoid instantiating more
185 // of the Chrome infrastructure than necessary, the GoogleURLTracker functions
186 // are carefully written so that many of the functions which take
187 // NavigationController* or InfoBarService* do not actually dereference the
188 // objects, merely use them for comparisons and lookups, e.g. in |entry_map_|.
189 // This then allows the test code here to not create any of these objects, and
190 // instead supply "pointers" that are actually reinterpret_cast<>()ed magic
191 // numbers. Then we write the necessary stubs/hooks, here and in
192 // TestInfoBarDelegate above, to make everything continue to work.
194 // Technically, the C++98 spec defines the result of casting
195 // T* -> intptr_t -> T* to be an identity, but intptr_t -> T* -> intptr_t (what
196 // we use here) is "implementation-defined". Since I've never seen a compiler
197 // break this, though, and the result would simply be a failing test rather than
198 // a bug in Chrome, we'll use it anyway.
199 class GoogleURLTrackerTest : public testing::Test {
200 public:
201 // Called by TestInfoBarDelegate::Close().
202 void OnInfoBarClosed(scoped_ptr<infobars::InfoBar> infobar,
203 InfoBarService* infobar_service);
205 protected:
206 GoogleURLTrackerTest();
207 virtual ~GoogleURLTrackerTest();
209 // testing::Test
210 virtual void SetUp() OVERRIDE;
211 virtual void TearDown() OVERRIDE;
213 net::TestURLFetcher* GetFetcher();
214 void MockSearchDomainCheckResponse(const std::string& domain);
215 void RequestServerCheck();
216 void FinishSleep();
217 void NotifyIPAddressChanged();
218 GURL fetched_google_url() const {
219 return google_url_tracker_->fetched_google_url();
221 void set_google_url(const GURL& url) {
222 google_url_tracker_->google_url_ = url;
224 GURL google_url() const { return google_url_tracker_->google_url(); }
225 void SetLastPromptedGoogleURL(const GURL& url);
226 GURL GetLastPromptedGoogleURL();
227 void SetNavigationPending(intptr_t unique_id, bool is_search);
228 void CommitNonSearch(intptr_t unique_id);
229 void CommitSearch(intptr_t unique_id, const GURL& search_url);
230 void CloseTab(intptr_t unique_id);
231 GoogleURLTrackerMapEntry* GetMapEntry(intptr_t unique_id);
232 GoogleURLTrackerInfoBarDelegate* GetInfoBarDelegate(intptr_t unique_id);
233 void ExpectDefaultURLs() const;
234 void ExpectListeningForCommit(intptr_t unique_id, bool listening);
235 bool observer_notified() const { return observer_.notified(); }
236 void clear_observer_notified() { observer_.clear_notified(); }
238 private:
239 // 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
241 // any helper<->infobar interaction necessary. The returned object will be
242 // cleaned up in OnInfoBarClosed().
243 infobars::InfoBar* CreateTestInfoBar(InfoBarService* infobar_service,
244 GoogleURLTracker* google_url_tracker,
245 const GURL& search_url);
247 // These are required by the TestURLFetchers GoogleURLTracker will create (see
248 // test_url_fetcher_factory.h).
249 content::TestBrowserThreadBundle thread_bundle_;
250 // Creating this allows us to call
251 // net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests().
252 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
253 net::TestURLFetcherFactory fetcher_factory_;
254 content::NotificationRegistrar registrar_;
255 TestNotificationObserver observer_;
256 GoogleURLTrackerNavigationHelper* nav_helper_;
257 TestingProfile profile_;
258 scoped_ptr<GoogleURLTracker> google_url_tracker_;
259 // 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.
261 std::set<int> unique_ids_seen_;
264 void GoogleURLTrackerTest::OnInfoBarClosed(
265 scoped_ptr<infobars::InfoBar> infobar,
266 InfoBarService* infobar_service) {
267 // First, simulate the InfoBarService firing INFOBAR_REMOVED.
268 infobars::InfoBar::RemovedDetails removed_details(infobar.get(), false);
269 GoogleURLTracker::EntryMap::const_iterator i =
270 google_url_tracker_->entry_map_.find(infobar_service);
271 ASSERT_FALSE(i == google_url_tracker_->entry_map_.end());
272 GoogleURLTrackerMapEntry* map_entry = i->second;
273 ASSERT_EQ(infobar->delegate(), map_entry->infobar_delegate());
274 map_entry->Observe(
275 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
276 content::Source<InfoBarService>(infobar_service),
277 content::Details<infobars::InfoBar::RemovedDetails>(&removed_details));
279 // Second, simulate the infobar container closing the infobar in response.
280 // This happens automatically as |infobar| goes out of scope.
283 GoogleURLTrackerTest::GoogleURLTrackerTest()
284 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {
285 GoogleURLTrackerFactory::GetInstance()->
286 RegisterUserPrefsOnBrowserContextForTest(&profile_);
289 GoogleURLTrackerTest::~GoogleURLTrackerTest() {
292 void GoogleURLTrackerTest::SetUp() {
293 network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock());
294 // Ownership is passed to google_url_tracker_, but a weak pointer is kept;
295 // this is safe since GoogleURLTracker keeps the observer for its lifetime.
296 nav_helper_ = new TestGoogleURLTrackerNavigationHelper();
297 scoped_ptr<GoogleURLTrackerNavigationHelper> nav_helper(nav_helper_);
298 google_url_tracker_.reset(
299 new GoogleURLTracker(&profile_, nav_helper.Pass(),
300 GoogleURLTracker::UNIT_TEST_MODE));
301 google_url_tracker_->infobar_creator_ = base::Bind(
302 &GoogleURLTrackerTest::CreateTestInfoBar, base::Unretained(this));
305 void GoogleURLTrackerTest::TearDown() {
306 while (!unique_ids_seen_.empty())
307 CloseTab(*unique_ids_seen_.begin());
309 nav_helper_ = NULL;
310 google_url_tracker_.reset();
311 network_change_notifier_.reset();
314 net::TestURLFetcher* GoogleURLTrackerTest::GetFetcher() {
315 // This will return the last fetcher created. If no fetchers have been
316 // created, we'll pass GetFetcherByID() "-1", and it will return NULL.
317 return fetcher_factory_.GetFetcherByID(google_url_tracker_->fetcher_id_ - 1);
320 void GoogleURLTrackerTest::MockSearchDomainCheckResponse(
321 const std::string& domain) {
322 net::TestURLFetcher* fetcher = GetFetcher();
323 if (!fetcher)
324 return;
325 fetcher_factory_.RemoveFetcherFromMap(fetcher->id());
326 fetcher->set_url(GURL(GoogleURLTracker::kSearchDomainCheckURL));
327 fetcher->set_response_code(200);
328 fetcher->SetResponseString(domain);
329 fetcher->delegate()->OnURLFetchComplete(fetcher);
330 // At this point, |fetcher| is deleted.
333 void GoogleURLTrackerTest::RequestServerCheck() {
334 if (!registrar_.IsRegistered(&observer_,
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_));
340 google_url_tracker_->SetNeedToFetch();
343 void GoogleURLTrackerTest::FinishSleep() {
344 google_url_tracker_->FinishSleep();
347 void GoogleURLTrackerTest::NotifyIPAddressChanged() {
348 net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests();
349 // For thread safety, the NCN queues tasks to do the actual notifications, so
350 // we need to spin the message loop so the tracker will actually be notified.
351 base::MessageLoop::current()->RunUntilIdle();
354 void GoogleURLTrackerTest::SetLastPromptedGoogleURL(const GURL& url) {
355 profile_.GetPrefs()->SetString(prefs::kLastPromptedGoogleURL, url.spec());
358 GURL GoogleURLTrackerTest::GetLastPromptedGoogleURL() {
359 return GURL(profile_.GetPrefs()->GetString(prefs::kLastPromptedGoogleURL));
362 void GoogleURLTrackerTest::SetNavigationPending(intptr_t unique_id,
363 bool is_search) {
364 if (is_search) {
365 google_url_tracker_->SearchCommitted();
366 // Note that the call above might not have actually registered a listener
367 // for navigation starts if the searchdomaincheck response was bogus.
369 unique_ids_seen_.insert(unique_id);
370 if (nav_helper_->IsListeningForNavigationStart()) {
371 google_url_tracker_->OnNavigationPending(
372 reinterpret_cast<content::NavigationController*>(unique_id),
373 reinterpret_cast<InfoBarService*>(unique_id), unique_id);
377 void GoogleURLTrackerTest::CommitNonSearch(intptr_t unique_id) {
378 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(unique_id);
379 if (!map_entry)
380 return;
382 ExpectListeningForCommit(unique_id, false);
384 // The infobar should be showing; otherwise the pending non-search should
385 // have closed it.
386 ASSERT_TRUE(map_entry->has_infobar_delegate());
388 // The pending_id should have been reset to 0 when the non-search became
389 // pending.
390 EXPECT_EQ(0, map_entry->infobar_delegate()->pending_id());
392 // Committing the navigation would close the infobar.
393 map_entry->infobar_delegate()->Close(false);
396 void GoogleURLTrackerTest::CommitSearch(intptr_t unique_id,
397 const GURL& search_url) {
398 DCHECK(search_url.is_valid());
399 if (nav_helper_->IsListeningForNavigationCommit(
400 reinterpret_cast<content::NavigationController*>(unique_id))) {
401 google_url_tracker_->OnNavigationCommitted(
402 reinterpret_cast<InfoBarService*>(unique_id), search_url);
406 void GoogleURLTrackerTest::CloseTab(intptr_t unique_id) {
407 unique_ids_seen_.erase(unique_id);
408 content::NavigationController* nav_controller =
409 reinterpret_cast<content::NavigationController*>(unique_id);
410 if (nav_helper_->IsListeningForTabDestruction(nav_controller)) {
411 google_url_tracker_->OnTabClosed(nav_controller);
412 } else {
413 // Closing a tab with an infobar showing would close the infobar.
414 GoogleURLTrackerInfoBarDelegate* delegate = GetInfoBarDelegate(unique_id);
415 if (delegate)
416 delegate->Close(false);
420 GoogleURLTrackerMapEntry* GoogleURLTrackerTest::GetMapEntry(
421 intptr_t unique_id) {
422 GoogleURLTracker::EntryMap::const_iterator i =
423 google_url_tracker_->entry_map_.find(
424 reinterpret_cast<InfoBarService*>(unique_id));
425 return (i == google_url_tracker_->entry_map_.end()) ? NULL : i->second;
428 GoogleURLTrackerInfoBarDelegate* GoogleURLTrackerTest::GetInfoBarDelegate(
429 intptr_t unique_id) {
430 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(unique_id);
431 return map_entry ? map_entry->infobar_delegate() : NULL;
434 void GoogleURLTrackerTest::ExpectDefaultURLs() const {
435 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
436 EXPECT_EQ(GURL(), fetched_google_url());
439 void GoogleURLTrackerTest::ExpectListeningForCommit(intptr_t unique_id,
440 bool listening) {
441 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(unique_id);
442 if (map_entry) {
443 EXPECT_EQ(listening, nav_helper_->IsListeningForNavigationCommit(
444 map_entry->navigation_controller()));
445 } else {
446 EXPECT_FALSE(listening);
450 infobars::InfoBar* GoogleURLTrackerTest::CreateTestInfoBar(
451 InfoBarService* infobar_service,
452 GoogleURLTracker* google_url_tracker,
453 const GURL& search_url) {
454 return TestInfoBarDelegate::Create(this, infobar_service, google_url_tracker,
455 search_url);
459 // TestInfoBarDelegate --------------------------------------------------------
461 namespace {
463 // static
464 infobars::InfoBar* TestInfoBarDelegate::Create(
465 GoogleURLTrackerTest* test_harness,
466 InfoBarService* infobar_service,
467 GoogleURLTracker* google_url_tracker,
468 const GURL& search_url) {
469 return ConfirmInfoBarDelegate::CreateInfoBar(
470 scoped_ptr<ConfirmInfoBarDelegate>(new TestInfoBarDelegate(
471 test_harness, infobar_service, google_url_tracker,
472 search_url))).release();
475 TestInfoBarDelegate::TestInfoBarDelegate(GoogleURLTrackerTest* test_harness,
476 InfoBarService* infobar_service,
477 GoogleURLTracker* google_url_tracker,
478 const GURL& search_url)
479 : GoogleURLTrackerInfoBarDelegate(google_url_tracker, search_url),
480 test_harness_(test_harness),
481 infobar_service_(infobar_service) {
484 TestInfoBarDelegate::~TestInfoBarDelegate() {
487 void TestInfoBarDelegate::Update(const GURL& search_url) {
488 set_search_url(search_url);
489 set_pending_id(0);
492 void TestInfoBarDelegate::Close(bool redo_search) {
493 test_harness_->OnInfoBarClosed(scoped_ptr<infobars::InfoBar>(infobar()),
494 infobar_service_);
495 // WARNING: At this point |this| has been deleted!
498 } // namespace
501 // Tests ----------------------------------------------------------------------
503 TEST_F(GoogleURLTrackerTest, DontFetchWhenNoOneRequestsCheck) {
504 ExpectDefaultURLs();
505 FinishSleep();
506 // No one called RequestServerCheck() so nothing should have happened.
507 EXPECT_FALSE(GetFetcher());
508 MockSearchDomainCheckResponse("http://www.google.co.uk/");
509 ExpectDefaultURLs();
510 EXPECT_FALSE(observer_notified());
513 TEST_F(GoogleURLTrackerTest, UpdateOnFirstRun) {
514 RequestServerCheck();
515 EXPECT_FALSE(GetFetcher());
516 ExpectDefaultURLs();
517 EXPECT_FALSE(observer_notified());
519 FinishSleep();
520 MockSearchDomainCheckResponse("http://www.google.co.uk/");
521 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url());
522 // GoogleURL should be updated, becase there was no last prompted URL.
523 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url());
524 EXPECT_TRUE(observer_notified());
527 TEST_F(GoogleURLTrackerTest, DontUpdateWhenUnchanged) {
528 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
530 RequestServerCheck();
531 EXPECT_FALSE(GetFetcher());
532 ExpectDefaultURLs();
533 EXPECT_FALSE(observer_notified());
535 FinishSleep();
536 MockSearchDomainCheckResponse("http://www.google.co.uk/");
537 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url());
538 // GoogleURL should not be updated, because the fetched and prompted URLs
539 // match.
540 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
541 EXPECT_FALSE(observer_notified());
544 TEST_F(GoogleURLTrackerTest, DontPromptOnBadReplies) {
545 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
547 RequestServerCheck();
548 EXPECT_FALSE(GetFetcher());
549 ExpectDefaultURLs();
550 EXPECT_FALSE(observer_notified());
552 // Old-style domain string.
553 FinishSleep();
554 MockSearchDomainCheckResponse(".google.co.in");
555 EXPECT_EQ(GURL(), fetched_google_url());
556 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
557 EXPECT_FALSE(observer_notified());
558 SetNavigationPending(1, true);
559 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test"));
560 EXPECT_TRUE(GetMapEntry(1) == NULL);
562 // Bad subdomain.
563 NotifyIPAddressChanged();
564 MockSearchDomainCheckResponse("http://mail.google.com/");
565 EXPECT_EQ(GURL(), fetched_google_url());
566 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
567 EXPECT_FALSE(observer_notified());
568 SetNavigationPending(1, true);
569 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test"));
570 EXPECT_TRUE(GetMapEntry(1) == NULL);
572 // Non-empty path.
573 NotifyIPAddressChanged();
574 MockSearchDomainCheckResponse("http://www.google.com/search");
575 EXPECT_EQ(GURL(), fetched_google_url());
576 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
577 EXPECT_FALSE(observer_notified());
578 SetNavigationPending(1, true);
579 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test"));
580 EXPECT_TRUE(GetMapEntry(1) == NULL);
582 // Non-empty query.
583 NotifyIPAddressChanged();
584 MockSearchDomainCheckResponse("http://www.google.com/?q=foo");
585 EXPECT_EQ(GURL(), fetched_google_url());
586 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
587 EXPECT_FALSE(observer_notified());
588 SetNavigationPending(1, true);
589 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test"));
590 EXPECT_TRUE(GetMapEntry(1) == NULL);
592 // Non-empty ref.
593 NotifyIPAddressChanged();
594 MockSearchDomainCheckResponse("http://www.google.com/#anchor");
595 EXPECT_EQ(GURL(), fetched_google_url());
596 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
597 EXPECT_FALSE(observer_notified());
598 SetNavigationPending(1, true);
599 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test"));
600 EXPECT_TRUE(GetMapEntry(1) == NULL);
602 // Complete garbage.
603 NotifyIPAddressChanged();
604 MockSearchDomainCheckResponse("HJ)*qF)_*&@f1");
605 EXPECT_EQ(GURL(), fetched_google_url());
606 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
607 EXPECT_FALSE(observer_notified());
608 SetNavigationPending(1, true);
609 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test"));
610 EXPECT_TRUE(GetMapEntry(1) == NULL);
613 TEST_F(GoogleURLTrackerTest, UpdatePromptedURLOnReturnToPreviousLocation) {
614 SetLastPromptedGoogleURL(GURL("http://www.google.co.jp/"));
615 set_google_url(GURL("http://www.google.co.uk/"));
616 RequestServerCheck();
617 FinishSleep();
618 MockSearchDomainCheckResponse("http://www.google.co.uk/");
619 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url());
620 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url());
621 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
622 EXPECT_FALSE(observer_notified());
625 TEST_F(GoogleURLTrackerTest, SilentlyAcceptSchemeChange) {
626 // We should auto-accept changes to the current Google URL that merely change
627 // the scheme, regardless of what the last prompted URL was.
628 SetLastPromptedGoogleURL(GURL("http://www.google.co.jp/"));
629 set_google_url(GURL("http://www.google.co.uk/"));
630 RequestServerCheck();
631 FinishSleep();
632 MockSearchDomainCheckResponse("https://www.google.co.uk/");
633 EXPECT_EQ(GURL("https://www.google.co.uk/"), fetched_google_url());
634 EXPECT_EQ(GURL("https://www.google.co.uk/"), google_url());
635 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL());
636 EXPECT_TRUE(observer_notified());
638 NotifyIPAddressChanged();
639 MockSearchDomainCheckResponse("http://www.google.co.uk/");
640 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url());
641 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url());
642 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
643 EXPECT_TRUE(observer_notified());
646 TEST_F(GoogleURLTrackerTest, RefetchOnIPAddressChange) {
647 RequestServerCheck();
648 FinishSleep();
649 MockSearchDomainCheckResponse("http://www.google.co.uk/");
650 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url());
651 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url());
652 EXPECT_TRUE(observer_notified());
653 clear_observer_notified();
655 NotifyIPAddressChanged();
656 MockSearchDomainCheckResponse("http://www.google.co.in/");
657 EXPECT_EQ(GURL("http://www.google.co.in/"), fetched_google_url());
658 // Just fetching a new URL shouldn't reset things without a prompt.
659 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url());
660 EXPECT_FALSE(observer_notified());
663 TEST_F(GoogleURLTrackerTest, DontRefetchWhenNoOneRequestsCheck) {
664 FinishSleep();
665 NotifyIPAddressChanged();
666 // No one called RequestServerCheck() so nothing should have happened.
667 EXPECT_FALSE(GetFetcher());
668 MockSearchDomainCheckResponse("http://www.google.co.uk/");
669 ExpectDefaultURLs();
670 EXPECT_FALSE(observer_notified());
673 TEST_F(GoogleURLTrackerTest, FetchOnLateRequest) {
674 FinishSleep();
675 NotifyIPAddressChanged();
676 MockSearchDomainCheckResponse("http://www.google.co.jp/");
678 RequestServerCheck();
679 // The first request for a check should trigger a fetch if it hasn't happened
680 // already.
681 MockSearchDomainCheckResponse("http://www.google.co.uk/");
682 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url());
683 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url());
684 EXPECT_TRUE(observer_notified());
687 TEST_F(GoogleURLTrackerTest, DontFetchTwiceOnLateRequests) {
688 FinishSleep();
689 NotifyIPAddressChanged();
690 MockSearchDomainCheckResponse("http://www.google.co.jp/");
692 RequestServerCheck();
693 // The first request for a check should trigger a fetch if it hasn't happened
694 // already.
695 MockSearchDomainCheckResponse("http://www.google.co.uk/");
696 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url());
697 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url());
698 EXPECT_TRUE(observer_notified());
699 clear_observer_notified();
701 RequestServerCheck();
702 // The second request should be ignored.
703 EXPECT_FALSE(GetFetcher());
704 MockSearchDomainCheckResponse("http://www.google.co.in/");
705 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url());
706 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url());
707 EXPECT_FALSE(observer_notified());
710 TEST_F(GoogleURLTrackerTest, SearchingDoesNothingIfNoNeedToPrompt) {
711 RequestServerCheck();
712 FinishSleep();
713 MockSearchDomainCheckResponse("http://www.google.co.uk/");
714 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url());
715 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url());
716 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
717 EXPECT_TRUE(observer_notified());
718 clear_observer_notified();
720 SetNavigationPending(1, true);
721 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test"));
722 EXPECT_TRUE(GetMapEntry(1) == NULL);
723 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url());
724 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url());
725 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
726 EXPECT_FALSE(observer_notified());
729 TEST_F(GoogleURLTrackerTest, TabClosedOnPendingSearch) {
730 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
731 RequestServerCheck();
732 FinishSleep();
733 MockSearchDomainCheckResponse("http://www.google.co.jp/");
734 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
735 EXPECT_EQ(GURL("http://www.google.co.jp/"), fetched_google_url());
736 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
737 EXPECT_FALSE(observer_notified());
739 SetNavigationPending(1, true);
740 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(1);
741 ASSERT_FALSE(map_entry == NULL);
742 EXPECT_FALSE(map_entry->has_infobar_delegate());
743 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
744 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
745 EXPECT_FALSE(observer_notified());
747 CloseTab(1);
748 EXPECT_TRUE(GetMapEntry(1) == NULL);
749 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
750 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
751 EXPECT_FALSE(observer_notified());
754 TEST_F(GoogleURLTrackerTest, TabClosedOnCommittedSearch) {
755 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
756 RequestServerCheck();
757 FinishSleep();
758 MockSearchDomainCheckResponse("http://www.google.co.jp/");
760 SetNavigationPending(1, true);
761 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test"));
762 EXPECT_FALSE(GetInfoBarDelegate(1) == NULL);
764 CloseTab(1);
765 EXPECT_TRUE(GetMapEntry(1) == NULL);
766 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
767 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
768 EXPECT_FALSE(observer_notified());
771 TEST_F(GoogleURLTrackerTest, InfoBarClosed) {
772 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
773 RequestServerCheck();
774 FinishSleep();
775 MockSearchDomainCheckResponse("http://www.google.co.jp/");
777 SetNavigationPending(1, true);
778 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test"));
779 GoogleURLTrackerInfoBarDelegate* infobar = GetInfoBarDelegate(1);
780 ASSERT_FALSE(infobar == NULL);
782 infobar->Close(false);
783 EXPECT_TRUE(GetMapEntry(1) == NULL);
784 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
785 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
786 EXPECT_FALSE(observer_notified());
789 TEST_F(GoogleURLTrackerTest, InfoBarRefused) {
790 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
791 RequestServerCheck();
792 FinishSleep();
793 MockSearchDomainCheckResponse("http://www.google.co.jp/");
795 SetNavigationPending(1, true);
796 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test"));
797 GoogleURLTrackerInfoBarDelegate* infobar = GetInfoBarDelegate(1);
798 ASSERT_FALSE(infobar == NULL);
800 infobar->Cancel();
801 EXPECT_TRUE(GetMapEntry(1) == NULL);
802 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
803 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL());
804 EXPECT_FALSE(observer_notified());
807 TEST_F(GoogleURLTrackerTest, InfoBarAccepted) {
808 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
809 RequestServerCheck();
810 FinishSleep();
811 MockSearchDomainCheckResponse("http://www.google.co.jp/");
813 SetNavigationPending(1, true);
814 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test"));
815 GoogleURLTrackerInfoBarDelegate* infobar = GetInfoBarDelegate(1);
816 ASSERT_FALSE(infobar == NULL);
818 infobar->Accept();
819 EXPECT_TRUE(GetMapEntry(1) == NULL);
820 EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url());
821 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL());
822 EXPECT_TRUE(observer_notified());
825 TEST_F(GoogleURLTrackerTest, FetchesCanAutomaticallyCloseInfoBars) {
826 RequestServerCheck();
827 FinishSleep();
828 MockSearchDomainCheckResponse(google_url().spec());
830 // Re-fetching the accepted URL after showing an infobar for another URL
831 // should close the infobar.
832 NotifyIPAddressChanged();
833 MockSearchDomainCheckResponse("http://www.google.co.uk/");
834 SetNavigationPending(1, true);
835 CommitSearch(1, GURL("http://www.google.com/search?q=test"));
836 EXPECT_FALSE(GetInfoBarDelegate(1) == NULL);
837 NotifyIPAddressChanged();
838 MockSearchDomainCheckResponse(google_url().spec());
839 EXPECT_EQ(google_url(), GetLastPromptedGoogleURL());
840 EXPECT_TRUE(GetMapEntry(1) == NULL);
842 // As should fetching a URL that differs from the accepted only by the scheme.
843 NotifyIPAddressChanged();
844 MockSearchDomainCheckResponse("http://www.google.co.uk/");
845 SetNavigationPending(1, true);
846 CommitSearch(1, GURL("http://www.google.com/search?q=test"));
847 EXPECT_FALSE(GetInfoBarDelegate(1) == NULL);
848 NotifyIPAddressChanged();
849 url::Replacements<char> replacements;
850 const std::string& scheme("https");
851 replacements.SetScheme(scheme.data(), url::Component(0, scheme.length()));
852 GURL new_google_url(google_url().ReplaceComponents(replacements));
853 MockSearchDomainCheckResponse(new_google_url.spec());
854 EXPECT_EQ(new_google_url, GetLastPromptedGoogleURL());
855 EXPECT_TRUE(GetMapEntry(1) == NULL);
857 // As should re-fetching the last prompted URL.
858 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
859 NotifyIPAddressChanged();
860 MockSearchDomainCheckResponse("http://www.google.co.jp/");
861 SetNavigationPending(1, true);
862 CommitSearch(1, GURL("http://www.google.com/search?q=test"));
863 EXPECT_FALSE(GetInfoBarDelegate(1) == NULL);
864 NotifyIPAddressChanged();
865 MockSearchDomainCheckResponse("http://www.google.co.uk/");
866 EXPECT_EQ(new_google_url, google_url());
867 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
868 EXPECT_TRUE(GetMapEntry(1) == NULL);
870 // And one that differs from the last prompted URL only by the scheme.
871 NotifyIPAddressChanged();
872 MockSearchDomainCheckResponse("http://www.google.co.jp/");
873 SetNavigationPending(1, true);
874 CommitSearch(1, GURL("http://www.google.com/search?q=test"));
875 EXPECT_FALSE(GetInfoBarDelegate(1) == NULL);
876 NotifyIPAddressChanged();
877 MockSearchDomainCheckResponse("https://www.google.co.uk/");
878 EXPECT_EQ(new_google_url, google_url());
879 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL());
880 EXPECT_TRUE(GetMapEntry(1) == NULL);
882 // And fetching a different URL entirely.
883 NotifyIPAddressChanged();
884 MockSearchDomainCheckResponse("http://www.google.co.jp/");
885 SetNavigationPending(1, true);
886 CommitSearch(1, GURL("http://www.google.com/search?q=test"));
887 EXPECT_FALSE(GetInfoBarDelegate(1) == NULL);
888 NotifyIPAddressChanged();
889 MockSearchDomainCheckResponse("https://www.google.co.in/");
890 EXPECT_EQ(new_google_url, google_url());
891 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL());
892 EXPECT_TRUE(GetMapEntry(1) == NULL);
895 TEST_F(GoogleURLTrackerTest, ResetInfoBarGoogleURLs) {
896 RequestServerCheck();
897 FinishSleep();
898 MockSearchDomainCheckResponse(google_url().spec());
900 NotifyIPAddressChanged();
901 MockSearchDomainCheckResponse("http://www.google.co.uk/");
902 SetNavigationPending(1, true);
903 CommitSearch(1, GURL("http://www.google.com/search?q=test"));
904 GoogleURLTrackerInfoBarDelegate* delegate = GetInfoBarDelegate(1);
905 ASSERT_FALSE(delegate == NULL);
906 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url());
908 // If while an infobar is showing we fetch a new URL that differs from the
909 // infobar's only by scheme, the infobar should stay showing.
910 NotifyIPAddressChanged();
911 MockSearchDomainCheckResponse("https://www.google.co.uk/");
912 EXPECT_EQ(delegate, GetInfoBarDelegate(1));
913 EXPECT_EQ(GURL("https://www.google.co.uk/"), fetched_google_url());
916 TEST_F(GoogleURLTrackerTest, NavigationsAfterPendingSearch) {
917 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
918 RequestServerCheck();
919 FinishSleep();
920 MockSearchDomainCheckResponse("http://www.google.co.jp/");
922 // A pending non-search after a pending search should delete the map entry.
923 SetNavigationPending(1, true);
924 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(1);
925 ASSERT_FALSE(map_entry == NULL);
926 EXPECT_FALSE(map_entry->has_infobar_delegate());
927 SetNavigationPending(1, false);
928 EXPECT_TRUE(GetMapEntry(1) == NULL);
930 // A pending search after a pending search should leave the map entry alive.
931 SetNavigationPending(1, true);
932 map_entry = GetMapEntry(1);
933 ASSERT_FALSE(map_entry == NULL);
934 EXPECT_FALSE(map_entry->has_infobar_delegate());
935 SetNavigationPending(1, true);
936 ASSERT_EQ(map_entry, GetMapEntry(1));
937 EXPECT_FALSE(map_entry->has_infobar_delegate());
938 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true));
940 // Committing this search should show an infobar.
941 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test2"));
942 EXPECT_TRUE(map_entry->has_infobar_delegate());
943 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
944 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
945 EXPECT_FALSE(observer_notified());
946 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false));
949 TEST_F(GoogleURLTrackerTest, NavigationsAfterCommittedSearch) {
950 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
951 RequestServerCheck();
952 FinishSleep();
953 MockSearchDomainCheckResponse("http://www.google.co.jp/");
954 SetNavigationPending(1, true);
955 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test"));
956 GoogleURLTrackerInfoBarDelegate* delegate = GetInfoBarDelegate(1);
957 ASSERT_FALSE(delegate == NULL);
958 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false));
960 // A pending non-search on a visible infobar should basically do nothing.
961 SetNavigationPending(1, false);
962 ASSERT_EQ(delegate, GetInfoBarDelegate(1));
963 EXPECT_EQ(0, delegate->pending_id());
964 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false));
966 // As should another pending non-search after the first.
967 SetNavigationPending(1, false);
968 ASSERT_EQ(delegate, GetInfoBarDelegate(1));
969 EXPECT_EQ(0, delegate->pending_id());
970 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false));
972 // Committing this non-search should close the infobar. The control flow in
973 // these tests is not really comparable to in the real browser, but at least a
974 // few sanity-checks will be performed.
975 ASSERT_NO_FATAL_FAILURE(CommitNonSearch(1));
976 EXPECT_TRUE(GetMapEntry(1) == NULL);
978 // A pending search on a visible infobar should cause the infobar to listen
979 // for the search to commit.
980 SetNavigationPending(1, true);
981 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test"));
982 delegate = GetInfoBarDelegate(1);
983 ASSERT_FALSE(delegate == NULL);
984 SetNavigationPending(1, true);
985 ASSERT_EQ(delegate, GetInfoBarDelegate(1));
986 EXPECT_EQ(1, delegate->pending_id());
987 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true));
989 // But a non-search after this should cancel that state.
990 SetNavigationPending(1, false);
991 ASSERT_EQ(delegate, GetInfoBarDelegate(1));
992 EXPECT_EQ(0, delegate->pending_id());
993 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false));
995 // Another pending search after the non-search should put us back into
996 // "waiting for commit" mode.
997 SetNavigationPending(1, true);
998 ASSERT_EQ(delegate, GetInfoBarDelegate(1));
999 EXPECT_EQ(1, delegate->pending_id());
1000 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true));
1002 // A second pending search after the first should not really change anything.
1003 SetNavigationPending(1, true);
1004 ASSERT_EQ(delegate, GetInfoBarDelegate(1));
1005 EXPECT_EQ(1, delegate->pending_id());
1006 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true));
1008 // Committing this search should change the visible infobar's search_url.
1009 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test2"));
1010 ASSERT_EQ(delegate, GetInfoBarDelegate(1));
1011 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test2"),
1012 delegate->search_url());
1013 EXPECT_EQ(0, delegate->pending_id());
1014 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false));
1015 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
1016 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
1017 EXPECT_FALSE(observer_notified());
1020 TEST_F(GoogleURLTrackerTest, MultipleMapEntries) {
1021 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
1022 RequestServerCheck();
1023 FinishSleep();
1024 MockSearchDomainCheckResponse("http://www.google.co.jp/");
1026 SetNavigationPending(1, true);
1027 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(1);
1028 ASSERT_FALSE(map_entry == NULL);
1029 EXPECT_FALSE(map_entry->has_infobar_delegate());
1031 SetNavigationPending(2, true);
1032 CommitSearch(2, GURL("http://www.google.co.uk/search?q=test2"));
1033 GoogleURLTrackerInfoBarDelegate* delegate2 = GetInfoBarDelegate(2);
1034 ASSERT_FALSE(delegate2 == NULL);
1035 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test2"),
1036 delegate2->search_url());
1038 SetNavigationPending(3, true);
1039 GoogleURLTrackerMapEntry* map_entry3 = GetMapEntry(3);
1040 ASSERT_FALSE(map_entry3 == NULL);
1041 EXPECT_FALSE(map_entry3->has_infobar_delegate());
1043 SetNavigationPending(4, true);
1044 CommitSearch(4, GURL("http://www.google.co.uk/search?q=test4"));
1045 GoogleURLTrackerInfoBarDelegate* delegate4 = GetInfoBarDelegate(4);
1046 ASSERT_FALSE(delegate4 == NULL);
1047 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test4"),
1048 delegate4->search_url());
1050 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test"));
1051 EXPECT_TRUE(map_entry->has_infobar_delegate());
1053 delegate2->Close(false);
1054 EXPECT_TRUE(GetMapEntry(2) == NULL);
1055 EXPECT_FALSE(observer_notified());
1057 delegate4->Accept();
1058 EXPECT_TRUE(GetMapEntry(1) == NULL);
1059 EXPECT_TRUE(GetMapEntry(3) == NULL);
1060 EXPECT_TRUE(GetMapEntry(4) == NULL);
1061 EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url());
1062 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL());
1063 EXPECT_TRUE(observer_notified());
1066 TEST_F(GoogleURLTrackerTest, IgnoreIrrelevantNavigation) {
1067 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
1068 RequestServerCheck();
1069 FinishSleep();
1070 MockSearchDomainCheckResponse("http://www.google.co.jp/");
1072 // This tests a particularly gnarly sequence of events that used to cause us
1073 // to erroneously listen for a non-search navigation to commit.
1074 SetNavigationPending(1, true);
1075 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test"));
1076 SetNavigationPending(2, true);
1077 CommitSearch(2, GURL("http://www.google.co.uk/search?q=test2"));
1078 EXPECT_FALSE(GetInfoBarDelegate(1) == NULL);
1079 GoogleURLTrackerInfoBarDelegate* delegate2 = GetInfoBarDelegate(2);
1080 ASSERT_FALSE(delegate2 == NULL);
1081 SetNavigationPending(1, true);
1082 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true));
1083 delegate2->Close(false);
1084 SetNavigationPending(1, false);
1085 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false));