diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-21 01:23:26 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-21 01:23:26 +0000 |
commit | 351c086e67d19caaa7367cae60915edf9003f4f2 (patch) | |
tree | e80cebd795aee44322cdeafd9bb718aa599120a3 /chrome | |
parent | e03b8aec8f922d774f9e97683dbe357792e6db76 (diff) | |
download | chromium_src-351c086e67d19caaa7367cae60915edf9003f4f2.zip chromium_src-351c086e67d19caaa7367cae60915edf9003f4f2.tar.gz chromium_src-351c086e67d19caaa7367cae60915edf9003f4f2.tar.bz2 |
Clean up GoogleURLTracker:
* Replace QueueWakeupTask() and |queue_wakeup_task_| with a "mode" argument to the constructor, which is simpler.
* Move some functions from public->private and add friends, to enforce that only the expected callers can access them.
* Reorder definitions to match declarations.
* Add/update a few comments.
* Change an AllSources() to AllBrowserContextsAndSources() to indicate that it's been reviewed and OKed for multiprofile.
* Remove some unneeded #includes.
* Disconnect unittests from |g_browser_process| and instead create and access a GoogleURLTracker directly. This removes a dependency that would have caused problems later when GoogleURLTracker moves off the browser process entirely.
* Remove a few apparently-unnecessary spins of the message loop.
BUG=none
TEST=none
Review URL: https://chromiumcodereview.appspot.com/9753017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127864 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/browser_process_impl.cc | 3 | ||||
-rw-r--r-- | chrome/browser/google/google_url_tracker.cc | 134 | ||||
-rw-r--r-- | chrome/browser/google/google_url_tracker.h | 30 | ||||
-rw-r--r-- | chrome/browser/google/google_url_tracker_unittest.cc | 180 |
4 files changed, 159 insertions, 188 deletions
diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc index b1e0199..7369e4cf 100644 --- a/chrome/browser/browser_process_impl.cc +++ b/chrome/browser/browser_process_impl.cc @@ -766,7 +766,8 @@ void BrowserProcessImpl::CreateIconManager() { void BrowserProcessImpl::CreateGoogleURLTracker() { DCHECK(google_url_tracker_.get() == NULL); - scoped_ptr<GoogleURLTracker> google_url_tracker(new GoogleURLTracker); + scoped_ptr<GoogleURLTracker> google_url_tracker( + new GoogleURLTracker(GoogleURLTracker::NORMAL_MODE)); google_url_tracker_.swap(google_url_tracker); } diff --git a/chrome/browser/google/google_url_tracker.cc b/chrome/browser/google/google_url_tracker.cc index dd2da73..6d515aa 100644 --- a/chrome/browser/google/google_url_tracker.cc +++ b/chrome/browser/google/google_url_tracker.cc @@ -107,7 +107,7 @@ string16 GoogleURLTrackerInfoBarDelegate::GetButtonLabel( string16 GoogleURLTrackerInfoBarDelegate::GetHost(bool new_host) const { return net::StripWWW(UTF8ToUTF16( - (new_host ? new_google_url_ : google_url_tracker_->GoogleURL()).host())); + (new_host ? new_google_url_ : google_url_tracker_->google_url_).host())); } @@ -118,13 +118,13 @@ const char GoogleURLTracker::kDefaultGoogleHomepage[] = const char GoogleURLTracker::kSearchDomainCheckURL[] = "https://www.google.com/searchdomaincheck?format=domain&type=chrome"; -GoogleURLTracker::GoogleURLTracker() +GoogleURLTracker::GoogleURLTracker(Mode mode) : infobar_creator_(&CreateInfobar), - google_url_(g_browser_process->local_state()->GetString( - prefs::kLastKnownGoogleURL)), + google_url_(mode == UNIT_TEST_MODE ? kDefaultGoogleHomepage : + g_browser_process->local_state()->GetString( + prefs::kLastKnownGoogleURL)), ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), fetcher_id_(0), - queue_wakeup_task_(true), in_startup_sleep_(true), already_fetched_(false), need_to_fetch_(false), @@ -133,9 +133,22 @@ GoogleURLTracker::GoogleURLTracker() infobar_(NULL) { net::NetworkChangeNotifier::AddIPAddressObserver(this); - MessageLoop::current()->PostTask(FROM_HERE, - base::Bind(&GoogleURLTracker::QueueWakeupTask, - weak_ptr_factory_.GetWeakPtr())); + // Because this function can be called during startup, when kicking off a URL + // fetch can eat up 20 ms of time, we delay five seconds, which is hopefully + // long enough to be after startup, but still get results back quickly. + // Ideally, instead of this timer, we'd do something like "check if the + // browser is starting up, and if so, come back later", but there is currently + // no function to do this. + // + // In UNIT_TEST mode, where we want to explicitly control when the tracker + // "wakes up", we do nothing at all. + if (mode == NORMAL_MODE) { + static const int kStartFetchDelayMS = 5000; + MessageLoop::current()->PostDelayedTask(FROM_HERE, + base::Bind(&GoogleURLTracker::FinishSleep, + weak_ptr_factory_.GetWeakPtr()), + base::TimeDelta::FromMilliseconds(kStartFetchDelayMS)); + } } GoogleURLTracker::~GoogleURLTracker() { @@ -170,29 +183,49 @@ void GoogleURLTracker::GoogleURLSearchCommitted() { tracker->SearchCommitted(); } -void GoogleURLTracker::SetNeedToFetch() { - need_to_fetch_ = true; - StartFetchIfDesirable(); +void GoogleURLTracker::AcceptGoogleURL(const GURL& new_google_url) { + google_url_ = new_google_url; + g_browser_process->local_state()->SetString(prefs::kLastKnownGoogleURL, + google_url_.spec()); + g_browser_process->local_state()->SetString(prefs::kLastPromptedGoogleURL, + google_url_.spec()); + content::NotificationService::current()->Notify( + chrome::NOTIFICATION_GOOGLE_URL_UPDATED, + content::NotificationService::AllSources(), + content::NotificationService::NoDetails()); + need_to_prompt_ = false; } -void GoogleURLTracker::QueueWakeupTask() { - // When testing, we want to wake from sleep at controlled times, not on a - // timer. - if (!queue_wakeup_task_) - return; +void GoogleURLTracker::CancelGoogleURL(const GURL& new_google_url) { + g_browser_process->local_state()->SetString(prefs::kLastPromptedGoogleURL, + new_google_url.spec()); + need_to_prompt_ = false; +} - // Because this function can be called during startup, when kicking off a URL - // fetch can eat up 20 ms of time, we delay five seconds, which is hopefully - // long enough to be after startup, but still get results back quickly. - // Ideally, instead of this timer, we'd do something like "check if the - // browser is starting up, and if so, come back later", but there is currently - // no function to do this. - static const int kStartFetchDelayMS = 5000; +void GoogleURLTracker::InfoBarClosed() { + registrar_.RemoveAll(); + controller_ = NULL; + infobar_ = NULL; + search_url_ = GURL(); +} - MessageLoop::current()->PostDelayedTask(FROM_HERE, - base::Bind(&GoogleURLTracker::FinishSleep, - weak_ptr_factory_.GetWeakPtr()), - base::TimeDelta::FromMilliseconds(kStartFetchDelayMS)); +void GoogleURLTracker::RedoSearch() { + // Re-do the user's search on the new domain. + DCHECK(controller_); + url_canon::Replacements<char> replacements; + replacements.SetHost(google_url_.host().data(), + url_parse::Component(0, google_url_.host().length())); + GURL new_search_url(search_url_.ReplaceComponents(replacements)); + if (new_search_url.is_valid()) { + OpenURLParams params(new_search_url, Referrer(), CURRENT_TAB, + content::PAGE_TRANSITION_GENERATED, false); + controller_->GetWebContents()->OpenURL(params); + } +} + +void GoogleURLTracker::SetNeedToFetch() { + need_to_fetch_ = true; + StartFetchIfDesirable(); } void GoogleURLTracker::FinishSleep() { @@ -219,9 +252,8 @@ void GoogleURLTracker::StartFetchIfDesirable() { fetcher_id_, GURL(kSearchDomainCheckURL), content::URLFetcher::GET, this)); ++fetcher_id_; - // We don't want this fetch to affect existing state in local_state. For - // example, if a user has no Google cookies, this automatic check should not - // cause one to be set, lest we alarm the user. + // We don't want this fetch to set new entries in the cache or cookies, lest + // we alarm the user. fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE | net::LOAD_DO_NOT_SAVE_COOKIES); fetcher_->SetRequestContext(g_browser_process->system_request_context()); @@ -280,46 +312,6 @@ void GoogleURLTracker::OnURLFetchComplete(const content::URLFetcher* source) { need_to_prompt_ = true; } -void GoogleURLTracker::AcceptGoogleURL(const GURL& new_google_url) { - google_url_ = new_google_url; - g_browser_process->local_state()->SetString(prefs::kLastKnownGoogleURL, - google_url_.spec()); - g_browser_process->local_state()->SetString(prefs::kLastPromptedGoogleURL, - google_url_.spec()); - content::NotificationService::current()->Notify( - chrome::NOTIFICATION_GOOGLE_URL_UPDATED, - content::NotificationService::AllSources(), - content::NotificationService::NoDetails()); - need_to_prompt_ = false; -} - -void GoogleURLTracker::CancelGoogleURL(const GURL& new_google_url) { - g_browser_process->local_state()->SetString(prefs::kLastPromptedGoogleURL, - new_google_url.spec()); - need_to_prompt_ = false; -} - -void GoogleURLTracker::InfoBarClosed() { - registrar_.RemoveAll(); - controller_ = NULL; - infobar_ = NULL; - search_url_ = GURL(); -} - -void GoogleURLTracker::RedoSearch() { - // Re-do the user's search on the new domain. - DCHECK(controller_); - url_canon::Replacements<char> replacements; - replacements.SetHost(google_url_.host().data(), - url_parse::Component(0, google_url_.host().length())); - GURL new_search_url(search_url_.ReplaceComponents(replacements)); - if (new_search_url.is_valid()) { - OpenURLParams params(new_search_url, Referrer(), CURRENT_TAB, - content::PAGE_TRANSITION_GENERATED, false); - controller_->GetWebContents()->OpenURL(params); - } -} - void GoogleURLTracker::Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details) { @@ -353,7 +345,7 @@ void GoogleURLTracker::SearchCommitted() { // This notification will fire a bit later in the same call chain we're // currently in. registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING, - content::NotificationService::AllSources()); + content::NotificationService::AllBrowserContextsAndSources()); } } diff --git a/chrome/browser/google/google_url_tracker.h b/chrome/browser/google/google_url_tracker.h index 7c179bf..62ef276 100644 --- a/chrome/browser/google/google_url_tracker.h +++ b/chrome/browser/google/google_url_tracker.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -12,12 +12,14 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" +#include "content/public/common/url_fetcher.h" #include "content/public/common/url_fetcher_delegate.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" #include "googleurl/src/gurl.h" #include "net/base/network_change_notifier.h" +class GoogleURLTrackerInfoBarDelegate; class PrefService; namespace content { @@ -42,13 +44,20 @@ class GoogleURLTracker : public content::URLFetcherDelegate, public content::NotificationObserver, public net::NetworkChangeNotifier::IPAddressObserver { public: + // The constructor does different things depending on which of these values + // you pass it. Hopefully these are self-explanatory. + enum Mode { + NORMAL_MODE, + UNIT_TEST_MODE, + }; + // Only the main browser process loop should call this, when setting up // g_browser_process->google_url_tracker_. No code other than the // GoogleURLTracker itself should actually use // g_browser_process->google_url_tracker() (which shouldn't be hard, since // there aren't useful public functions on this object for consumers to access // anyway). - GoogleURLTracker(); + explicit GoogleURLTracker(Mode mode); virtual ~GoogleURLTracker(); @@ -78,28 +87,24 @@ class GoogleURLTracker : public content::URLFetcherDelegate, static const char kDefaultGoogleHomepage[]; static const char kSearchDomainCheckURL[]; - // Methods called from InfoBar delegate. - void AcceptGoogleURL(const GURL& google_url); - void CancelGoogleURL(const GURL& google_url); - void InfoBarClosed(); - void RedoSearch(); - private: + friend class GoogleURLTrackerInfoBarDelegate; friend class GoogleURLTrackerTest; typedef InfoBarDelegate* (*InfobarCreator)(InfoBarTabHelper*, GoogleURLTracker*, const GURL&); + void AcceptGoogleURL(const GURL& google_url); + void CancelGoogleURL(const GURL& google_url); + void InfoBarClosed(); + void RedoSearch(); + // Registers consumer interest in getting an updated URL from the server. // It will be notified as chrome::GOOGLE_URL_UPDATED, so the // consumer should observe this notification before calling this. void SetNeedToFetch(); - // Begins the five-second startup sleep period, unless a test has cleared - // |queue_wakeup_task_|. - void QueueWakeupTask(); - // Called when the five second startup sleep has finished. Runs any pending // fetch. void FinishSleep(); @@ -136,7 +141,6 @@ class GoogleURLTracker : public content::URLFetcherDelegate, base::WeakPtrFactory<GoogleURLTracker> weak_ptr_factory_; scoped_ptr<content::URLFetcher> fetcher_; int fetcher_id_; - bool queue_wakeup_task_; bool in_startup_sleep_; // True if we're in the five-second "no fetching" // period that begins at browser start. bool already_fetched_; // True if we've already fetched a URL once this run; diff --git a/chrome/browser/google/google_url_tracker_unittest.cc b/chrome/browser/google/google_url_tracker_unittest.cc index 0ae50d1..8a3f931 100644 --- a/chrome/browser/google/google_url_tracker_unittest.cc +++ b/chrome/browser/google/google_url_tracker_unittest.cc @@ -1,14 +1,10 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/google/google_url_tracker.h" - -#include "base/command_line.h" #include "base/message_loop.h" -#include "chrome/browser/browser_process.h" +#include "chrome/browser/google/google_url_tracker.h" #include "chrome/browser/prefs/browser_prefs.h" -#include "chrome/browser/tab_contents/confirm_infobar_delegate.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/pref_names.h" #include "chrome/test/base/testing_browser_process.h" @@ -17,13 +13,8 @@ #include "content/public/common/url_fetcher.h" #include "content/test/test_browser_thread.h" #include "content/test/test_url_fetcher_factory.h" -#include "net/url_request/url_request.h" -#include "net/url_request/url_request_context_getter.h" -#include "net/url_request/url_request_test_util.h" #include "testing/gtest/include/gtest/gtest.h" -using content::BrowserThread; - // TestNotificationObserver --------------------------------------------------- namespace { @@ -63,13 +54,12 @@ class TestInfoBarDelegate : public InfoBarDelegate { public: TestInfoBarDelegate(GoogleURLTracker* google_url_tracker, const GURL& new_google_url); + virtual ~TestInfoBarDelegate(); GoogleURLTracker* google_url_tracker() const { return google_url_tracker_; } GURL new_google_url() const { return new_google_url_; } private: - virtual ~TestInfoBarDelegate(); - // InfoBarDelegate: virtual InfoBar* CreateInfoBar(InfoBarTabHelper* infobar_helper) OVERRIDE; @@ -118,14 +108,24 @@ class GoogleURLTrackerTest : public testing::Test { void RequestServerCheck(); void FinishSleep(); void NotifyIPAddressChanged(); - GURL GetFetchedGoogleURL(); - void SetGoogleURL(const GURL& url); + GURL fetched_google_url() const { + return google_url_tracker_->fetched_google_url_; + } + void set_google_url(const GURL& url) { + google_url_tracker_->google_url_ = url; + } + GURL google_url() const { return google_url_tracker_->google_url_; } void SetLastPromptedGoogleURL(const GURL& url); GURL GetLastPromptedGoogleURL(); void SearchCommitted(const GURL& search_url); void NavEntryCommitted(); - bool InfoBarIsShown(); - GURL GetInfoBarShowingURL(); + bool infobar_showing() const { + return (google_url_tracker_->infobar_ != NULL); + } + GURL infobar_url() const { + return static_cast<TestInfoBarDelegate*>(google_url_tracker_->infobar_)-> + new_google_url(); + } void AcceptGoogleURL(); void CancelGoogleURL(); void InfoBarClosed(); @@ -134,19 +134,23 @@ class GoogleURLTrackerTest : public testing::Test { scoped_ptr<TestNotificationObserver> observer_; private: + // These are required by the TestURLFetchers GoogleURLTracker will create (see + // test_url_fetcher_factory.h). MessageLoop message_loop_; content::TestBrowserThread io_thread_; + // Creating this allows us to call + // net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(). scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; ScopedTestingLocalState local_state_; - TestURLFetcherFactory fetcher_factory_; content::NotificationRegistrar registrar_; + scoped_ptr<GoogleURLTracker> google_url_tracker_; }; GoogleURLTrackerTest::GoogleURLTrackerTest() : observer_(new TestNotificationObserver), message_loop_(MessageLoop::TYPE_IO), - io_thread_(BrowserThread::IO, &message_loop_), + io_thread_(content::BrowserThread::IO, &message_loop_), local_state_(static_cast<TestingBrowserProcess*>(g_browser_process)) { } @@ -155,19 +159,13 @@ GoogleURLTrackerTest::~GoogleURLTrackerTest() { void GoogleURLTrackerTest::SetUp() { network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock()); - GoogleURLTracker* tracker = new GoogleURLTracker; - tracker->queue_wakeup_task_ = false; - MessageLoop::current()->RunAllPending(); - static_cast<TestingBrowserProcess*>(g_browser_process)->SetGoogleURLTracker( - tracker); - - g_browser_process->google_url_tracker()->infobar_creator_ = - &CreateTestInfobar; + google_url_tracker_.reset( + new GoogleURLTracker(GoogleURLTracker::UNIT_TEST_MODE)); + google_url_tracker_->infobar_creator_ = &CreateTestInfobar; } void GoogleURLTrackerTest::TearDown() { - static_cast<TestingBrowserProcess*>(g_browser_process)->SetGoogleURLTracker( - NULL); + google_url_tracker_.reset(); network_change_notifier_.reset(); } @@ -186,7 +184,6 @@ void GoogleURLTrackerTest::MockSearchDomainCheckResponse( fetcher->SetResponseString(domain); fetcher->delegate()->OnURLFetchComplete(fetcher); // At this point, |fetcher| is deleted. - MessageLoop::current()->RunAllPending(); } void GoogleURLTrackerTest::RequestServerCheck() { @@ -196,28 +193,20 @@ void GoogleURLTrackerTest::RequestServerCheck() { registrar_.Add(observer_.get(), chrome::NOTIFICATION_GOOGLE_URL_UPDATED, content::NotificationService::AllSources()); } - GoogleURLTracker::RequestServerCheck(); - MessageLoop::current()->RunAllPending(); + google_url_tracker_->SetNeedToFetch(); } void GoogleURLTrackerTest::FinishSleep() { - g_browser_process->google_url_tracker()->FinishSleep(); - MessageLoop::current()->RunAllPending(); + google_url_tracker_->FinishSleep(); } void GoogleURLTrackerTest::NotifyIPAddressChanged() { net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); + // For thread safety, the NCN queues tasks to do the actual notifications, so + // we need to spin the message loop so the tracker will actually be notified. MessageLoop::current()->RunAllPending(); } -GURL GoogleURLTrackerTest::GetFetchedGoogleURL() { - return g_browser_process->google_url_tracker()->fetched_google_url_; -} - -void GoogleURLTrackerTest::SetGoogleURL(const GURL& url) { - g_browser_process->google_url_tracker()->google_url_ = url; -} - void GoogleURLTrackerTest::SetLastPromptedGoogleURL(const GURL& url) { g_browser_process->local_state()->SetString( prefs::kLastPromptedGoogleURL, url.spec()); @@ -229,61 +218,49 @@ GURL GoogleURLTrackerTest::GetLastPromptedGoogleURL() { } void GoogleURLTrackerTest::SearchCommitted(const GURL& search_url) { - GoogleURLTracker* google_url_tracker = - g_browser_process->google_url_tracker(); - google_url_tracker->SearchCommitted(); - if (google_url_tracker->registrar_.IsRegistered(google_url_tracker, + google_url_tracker_->SearchCommitted(); + if (google_url_tracker_->registrar_.IsRegistered(google_url_tracker_.get(), content::NOTIFICATION_NAV_ENTRY_PENDING, content::NotificationService::AllSources())) - google_url_tracker->search_url_ = search_url; + google_url_tracker_->search_url_ = search_url; } void GoogleURLTrackerTest::NavEntryCommitted() { - GoogleURLTracker* google_url_tracker = - g_browser_process->google_url_tracker(); - google_url_tracker->ShowGoogleURLInfoBarIfNecessary(NULL); -} - -bool GoogleURLTrackerTest::InfoBarIsShown() { - return (g_browser_process->google_url_tracker()->infobar_ != NULL); -} - -GURL GoogleURLTrackerTest::GetInfoBarShowingURL() { - TestInfoBarDelegate* infobar = static_cast<TestInfoBarDelegate*>( - g_browser_process->google_url_tracker()->infobar_); - return infobar->new_google_url(); + google_url_tracker_->ShowGoogleURLInfoBarIfNecessary(NULL); } void GoogleURLTrackerTest::AcceptGoogleURL() { - TestInfoBarDelegate* infobar = static_cast<TestInfoBarDelegate*>( - g_browser_process->google_url_tracker()->infobar_); + TestInfoBarDelegate* infobar = + static_cast<TestInfoBarDelegate*>(google_url_tracker_->infobar_); ASSERT_TRUE(infobar); ASSERT_TRUE(infobar->google_url_tracker()); - infobar->google_url_tracker()->AcceptGoogleURL(infobar->new_google_url()); + ASSERT_EQ(google_url_tracker_, infobar->google_url_tracker()); + google_url_tracker_->AcceptGoogleURL(infobar->new_google_url()); } void GoogleURLTrackerTest::CancelGoogleURL() { - TestInfoBarDelegate* infobar = static_cast<TestInfoBarDelegate*>( - g_browser_process->google_url_tracker()->infobar_); + TestInfoBarDelegate* infobar = + static_cast<TestInfoBarDelegate*>(google_url_tracker_->infobar_); ASSERT_TRUE(infobar); ASSERT_TRUE(infobar->google_url_tracker()); - infobar->google_url_tracker()->CancelGoogleURL(infobar->new_google_url()); + ASSERT_EQ(google_url_tracker_, infobar->google_url_tracker()); + google_url_tracker_->CancelGoogleURL(infobar->new_google_url()); } void GoogleURLTrackerTest::InfoBarClosed() { - InfoBarDelegate* infobar = g_browser_process->google_url_tracker()->infobar_; + TestInfoBarDelegate* infobar = + static_cast<TestInfoBarDelegate*>(google_url_tracker_->infobar_); ASSERT_TRUE(infobar); - GoogleURLTracker* url_tracker = - static_cast<TestInfoBarDelegate*>(infobar)->google_url_tracker(); - ASSERT_TRUE(url_tracker); - url_tracker->InfoBarClosed(); + ASSERT_TRUE(infobar->google_url_tracker()); + ASSERT_EQ(google_url_tracker_, infobar->google_url_tracker()); + google_url_tracker_->InfoBarClosed(); delete infobar; } void GoogleURLTrackerTest::ExpectDefaultURLs() { EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), - GoogleURLTracker::GoogleURL()); - EXPECT_EQ(GURL(), GetFetchedGoogleURL()); + google_url_tracker_->google_url_); + EXPECT_EQ(GURL(), fetched_google_url()); } @@ -306,9 +283,9 @@ TEST_F(GoogleURLTrackerTest, UpdateOnFirstRun) { FinishSleep(); MockSearchDomainCheckResponse(0, ".google.co.uk"); - EXPECT_EQ(GURL("http://www.google.co.uk/"), GetFetchedGoogleURL()); + EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); // GoogleURL should be updated, becase there was no last prompted URL. - EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL()); + EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); EXPECT_TRUE(observer_->notified()); } @@ -322,22 +299,21 @@ TEST_F(GoogleURLTrackerTest, DontUpdateWhenUnchanged) { FinishSleep(); MockSearchDomainCheckResponse(0, ".google.co.uk"); - EXPECT_EQ(GURL("http://www.google.co.uk/"), GetFetchedGoogleURL()); + EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); // GoogleURL should not be updated, because the fetched and prompted URLs // match. - EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), - GoogleURLTracker::GoogleURL()); + EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); EXPECT_FALSE(observer_->notified()); } TEST_F(GoogleURLTrackerTest, UpdatePromptedURLOnReturnToPreviousLocation) { SetLastPromptedGoogleURL(GURL("http://www.google.co.jp/")); - SetGoogleURL(GURL("http://www.google.co.uk/")); + set_google_url(GURL("http://www.google.co.uk/")); RequestServerCheck(); FinishSleep(); MockSearchDomainCheckResponse(0, ".google.co.uk"); - EXPECT_EQ(GURL("http://www.google.co.uk/"), GetFetchedGoogleURL()); - EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL()); + EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); + EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); EXPECT_FALSE(observer_->notified()); } @@ -346,16 +322,16 @@ TEST_F(GoogleURLTrackerTest, RefetchOnIPAddressChange) { RequestServerCheck(); FinishSleep(); MockSearchDomainCheckResponse(0, ".google.co.uk"); - EXPECT_EQ(GURL("http://www.google.co.uk/"), GetFetchedGoogleURL()); - EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL()); + EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); + EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); EXPECT_TRUE(observer_->notified()); observer_->clear_notified(); NotifyIPAddressChanged(); MockSearchDomainCheckResponse(1, ".google.co.in"); - EXPECT_EQ(GURL("http://www.google.co.in/"), GetFetchedGoogleURL()); + EXPECT_EQ(GURL("http://www.google.co.in/"), fetched_google_url()); // Just fetching a new URL shouldn't reset things without a prompt. - EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL()); + EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); EXPECT_FALSE(observer_->notified()); } @@ -376,8 +352,8 @@ TEST_F(GoogleURLTrackerTest, FetchOnLateRequest) { // The first request for a check should trigger a fetch if it hasn't happened // already. MockSearchDomainCheckResponse(0, ".google.co.uk"); - EXPECT_EQ(GURL("http://www.google.co.uk/"), GetFetchedGoogleURL()); - EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL()); + EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); + EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); EXPECT_TRUE(observer_->notified()); } @@ -385,17 +361,17 @@ TEST_F(GoogleURLTrackerTest, SearchingDoesNothingIfNoNeedToPrompt) { RequestServerCheck(); FinishSleep(); MockSearchDomainCheckResponse(0, ".google.co.uk"); - EXPECT_EQ(GURL("http://www.google.co.uk/"), GetFetchedGoogleURL()); - EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL()); + EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); + EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); EXPECT_TRUE(observer_->notified()); observer_->clear_notified(); SearchCommitted(GURL("http://www.google.co.uk/search?q=test")); NavEntryCommitted(); - EXPECT_FALSE(InfoBarIsShown()); - EXPECT_EQ(GURL("http://www.google.co.uk/"), GetFetchedGoogleURL()); - EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL()); + EXPECT_FALSE(infobar_showing()); + EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); + EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); EXPECT_FALSE(observer_->notified()); } @@ -408,12 +384,11 @@ TEST_F(GoogleURLTrackerTest, InfobarClosed) { SearchCommitted(GURL("http://www.google.co.uk/search?q=test")); NavEntryCommitted(); - EXPECT_TRUE(InfoBarIsShown()); + EXPECT_TRUE(infobar_showing()); InfoBarClosed(); - EXPECT_FALSE(InfoBarIsShown()); - EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), - GoogleURLTracker::GoogleURL()); + EXPECT_FALSE(infobar_showing()); + EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); EXPECT_FALSE(observer_->notified()); } @@ -426,13 +401,12 @@ TEST_F(GoogleURLTrackerTest, InfobarRefused) { SearchCommitted(GURL("http://www.google.co.uk/search?q=test")); NavEntryCommitted(); - EXPECT_TRUE(InfoBarIsShown()); + EXPECT_TRUE(infobar_showing()); CancelGoogleURL(); InfoBarClosed(); - EXPECT_FALSE(InfoBarIsShown()); - EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), - GoogleURLTracker::GoogleURL()); + EXPECT_FALSE(infobar_showing()); + EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); EXPECT_FALSE(observer_->notified()); } @@ -445,12 +419,12 @@ TEST_F(GoogleURLTrackerTest, InfobarAccepted) { SearchCommitted(GURL("http://www.google.co.uk/search?q=test")); NavEntryCommitted(); - EXPECT_TRUE(InfoBarIsShown()); + EXPECT_TRUE(infobar_showing()); AcceptGoogleURL(); InfoBarClosed(); - EXPECT_FALSE(InfoBarIsShown()); - EXPECT_EQ(GURL("http://www.google.co.jp/"), GoogleURLTracker::GoogleURL()); + EXPECT_FALSE(infobar_showing()); + EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url()); EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); EXPECT_TRUE(observer_->notified()); } |