summaryrefslogtreecommitdiffstats
path: root/chrome/browser/google
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-11 02:11:39 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-11 02:11:39 +0000
commitaec181ad3aabb00f55cc5e1120a6678736d46d03 (patch)
tree09797a2ee1ceba6ea83fd1dd88429f8e8a0bcc11 /chrome/browser/google
parent1f0047e6613da12a7f0b57241e594ddf866fd64a (diff)
downloadchromium_src-aec181ad3aabb00f55cc5e1120a6678736d46d03.zip
chromium_src-aec181ad3aabb00f55cc5e1120a6678736d46d03.tar.gz
chromium_src-aec181ad3aabb00f55cc5e1120a6678736d46d03.tar.bz2
Misc. cleanup and reorg in preparation for fixing bug 54274. None of this should change the functional behavior of the class or the tests, it just makes the upcoming functional patch smaller and clearer.
BUG=54274 TEST=none Review URL: http://codereview.chromium.org/4627001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65760 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/google')
-rw-r--r--chrome/browser/google/google_url_tracker.cc165
-rw-r--r--chrome/browser/google/google_url_tracker.h43
-rw-r--r--chrome/browser/google/google_url_tracker_unittest.cc185
3 files changed, 184 insertions, 209 deletions
diff --git a/chrome/browser/google/google_url_tracker.cc b/chrome/browser/google/google_url_tracker.cc
index afd9592..93c8a2c 100644
--- a/chrome/browser/google/google_url_tracker.cc
+++ b/chrome/browser/google/google_url_tracker.cc
@@ -15,7 +15,6 @@
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/search_engines/template_url.h"
-#include "chrome/browser/tab_contents/infobar_delegate.h"
#include "chrome/browser/tab_contents/navigation_controller.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/common/chrome_switches.h"
@@ -26,33 +25,20 @@
#include "net/base/load_flags.h"
#include "net/url_request/url_request_status.h"
-// GoogleURLTrackerInfoBarDelegate --------------------------------------------
-
-class GoogleURLTrackerInfoBarDelegate : public ConfirmInfoBarDelegate {
- public:
- GoogleURLTrackerInfoBarDelegate(TabContents* tab_contents,
- GoogleURLTracker* google_url_tracker,
- const GURL& new_google_url);
-
- // ConfirmInfoBarDelegate
- virtual bool Accept();
- virtual bool Cancel();
- virtual void InfoBarClosed();
+namespace {
- protected:
- virtual ~GoogleURLTrackerInfoBarDelegate();
-
- GoogleURLTracker* google_url_tracker_;
- const GURL new_google_url_;
+InfoBarDelegate* CreateInfobar(TabContents* tab_contents,
+ GoogleURLTracker* google_url_tracker,
+ const GURL& new_google_url) {
+ InfoBarDelegate* infobar = new GoogleURLTrackerInfoBarDelegate(tab_contents,
+ google_url_tracker, new_google_url);
+ tab_contents->AddInfoBar(infobar);
+ return infobar;
+}
- private:
- // ConfirmInfoBarDelegate
- virtual string16 GetMessageText() const;
- virtual int GetButtons() const;
- virtual string16 GetButtonLabel(InfoBarButton button) const;
+} // namespace
- DISALLOW_COPY_AND_ASSIGN(GoogleURLTrackerInfoBarDelegate);
-};
+// GoogleURLTrackerInfoBarDelegate --------------------------------------------
GoogleURLTrackerInfoBarDelegate::GoogleURLTrackerInfoBarDelegate(
TabContents* tab_contents,
@@ -99,15 +85,6 @@ string16 GoogleURLTrackerInfoBarDelegate::GetButtonLabel(
IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL);
}
-InfoBarDelegate* CreateInfobar(TabContents* tab_contents,
- GoogleURLTracker* google_url_tracker,
- const GURL& new_google_url) {
- InfoBarDelegate* infobar = new GoogleURLTrackerInfoBarDelegate(tab_contents,
- google_url_tracker, new_google_url);
- tab_contents->AddInfoBar(infobar);
- return infobar;
-}
-
// GoogleURLTracker -----------------------------------------------------------
@@ -122,6 +99,7 @@ GoogleURLTracker::GoogleURLTracker()
prefs::kLastKnownGoogleURL)),
ALLOW_THIS_IN_INITIALIZER_LIST(runnable_method_factory_(this)),
fetcher_id_(0),
+ queue_wakeup_task_(true),
in_startup_sleep_(true),
already_fetched_(false),
need_to_fetch_(false),
@@ -141,17 +119,9 @@ GoogleURLTracker::GoogleURLTracker()
static const int kMaxRetries = 5;
protect->SetMaxRetries(kMaxRetries);
- // 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;
- MessageLoop::current()->PostDelayedTask(FROM_HERE,
- runnable_method_factory_.NewRunnableMethod(
- &GoogleURLTracker::FinishSleep),
- kStartFetchDelayMS);
+ MessageLoop::current()->PostTask(FROM_HERE,
+ runnable_method_factory_.NewRunnableMethod(
+ &GoogleURLTracker::QueueWakeupTask));
}
GoogleURLTracker::~GoogleURLTracker() {
@@ -192,6 +162,25 @@ void GoogleURLTracker::SetNeedToFetch() {
StartFetchIfDesirable();
}
+void GoogleURLTracker::QueueWakeupTask() {
+ // When testing, we want to wake from sleep at controlled times, not on a
+ // timer.
+ if (!queue_wakeup_task_)
+ return;
+
+ // 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;
+ MessageLoop::current()->PostDelayedTask(FROM_HERE,
+ runnable_method_factory_.NewRunnableMethod(
+ &GoogleURLTracker::FinishSleep),
+ kStartFetchDelayMS);
+}
+
void GoogleURLTracker::FinishSleep() {
in_startup_sleep_ = false;
StartFetchIfDesirable();
@@ -253,23 +242,23 @@ void GoogleURLTracker::OnURLFetchComplete(const URLFetcher* source,
g_browser_process->local_state()->GetString(
prefs::kLastPromptedGoogleURL));
need_to_prompt_ = false;
- // On the very first run of Chrome, when we've never looked up the URL at all,
- // we should just silently switch over to whatever we get immediately.
+
if (last_prompted_url.is_empty()) {
+ // On the very first run of Chrome, when we've never looked up the URL at
+ // all, we should just silently switch over to whatever we get immediately.
AcceptGoogleURL(fetched_google_url_);
- // Set fetched_google_url_ as an initial value of last prompted URL.
- g_browser_process->local_state()->SetString(prefs::kLastPromptedGoogleURL,
- fetched_google_url_.spec());
return;
}
+ // If the URL hasn't changed, then whether |need_to_prompt_| is true or false,
+ // nothing has changed, so just bail.
if (fetched_google_url_ == last_prompted_url)
return;
+
if (fetched_google_url_ == google_url_) {
// The user came back to their original location after having temporarily
// moved. Reset the prompted URL so we'll prompt again if they move again.
- g_browser_process->local_state()->SetString(prefs::kLastPromptedGoogleURL,
- fetched_google_url_.spec());
+ CancelGoogleURL(fetched_google_url_);
return;
}
@@ -281,7 +270,7 @@ void GoogleURLTracker::AcceptGoogleURL(const GURL& new_google_url) {
g_browser_process->local_state()->SetString(prefs::kLastKnownGoogleURL,
google_url_.spec());
g_browser_process->local_state()->SetString(prefs::kLastPromptedGoogleURL,
- new_google_url.spec());
+ google_url_.spec());
NotificationService::current()->Notify(NotificationType::GOOGLE_URL_UPDATED,
NotificationService::AllSources(),
NotificationService::NoDetails());
@@ -301,14 +290,14 @@ void GoogleURLTracker::InfoBarClosed() {
}
void GoogleURLTracker::RedoSearch() {
- // re-do the user's search on the new domain.
+ // 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()));
- search_url_ = search_url_.ReplaceComponents(replacements);
- if (search_url_.is_valid())
- controller_->tab_contents()->OpenURL(search_url_, GURL(), CURRENT_TAB,
+ GURL new_search_url(search_url_.ReplaceComponents(replacements));
+ if (new_search_url.is_valid())
+ controller_->tab_contents()->OpenURL(new_search_url, GURL(), CURRENT_TAB,
PageTransition::GENERATED);
}
@@ -325,31 +314,14 @@ void GoogleURLTracker::Observe(NotificationType type,
break;
case NotificationType::NAV_ENTRY_PENDING:
- controller_ = Source<NavigationController>(source).ptr();
- search_url_ = controller_->pending_entry()->url();
- // We don't need to listen NAV_ENTRY_PENDING any more, until another
- // search is committed.
- registrar_.Remove(this, NotificationType::NAV_ENTRY_PENDING,
- NotificationService::AllSources());
- // Start listening for the commit notification. We also need to listen
- // for the tab close command since that means the load will never
- // commit!
- registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
- Source<NavigationController>(controller_));
- registrar_.Add(this, NotificationType::TAB_CLOSED,
- Source<NavigationController>(controller_));
+ OnNavigationPending(source, controller_->pending_entry()->url());
break;
case NotificationType::NAV_ENTRY_COMMITTED:
- registrar_.RemoveAll();
- DCHECK(controller_);
- ShowGoogleURLInfoBarIfNecessary(controller_->tab_contents());
- break;
-
case NotificationType::TAB_CLOSED:
- registrar_.RemoveAll();
- controller_ = NULL;
- infobar_ = NULL;
+ OnNavigationCommittedOrTabClosed(
+ Source<NavigationController>(source).ptr()->tab_contents(),
+ type.value);
break;
default:
@@ -363,10 +335,39 @@ void GoogleURLTracker::OnIPAddressChanged() {
}
void GoogleURLTracker::SearchCommitted() {
- if (!registrar_.IsEmpty() || (!need_to_prompt_ && !fetcher_.get()))
- return;
- registrar_.Add(this, NotificationType::NAV_ENTRY_PENDING,
- NotificationService::AllSources());
+ if (registrar_.IsEmpty() && (need_to_prompt_ || fetcher_.get())) {
+ // This notification will fire a bit later in the same call chain we're
+ // currently in.
+ registrar_.Add(this, NotificationType::NAV_ENTRY_PENDING,
+ NotificationService::AllSources());
+ }
+}
+
+void GoogleURLTracker::OnNavigationPending(const NotificationSource& source,
+ const GURL& pending_url) {
+ controller_ = Source<NavigationController>(source).ptr();
+ search_url_ = pending_url;
+ registrar_.Remove(this, NotificationType::NAV_ENTRY_PENDING,
+ NotificationService::AllSources());
+ // Start listening for the commit notification. We also need to listen for the
+ // tab close command since that means the load will never commit.
+ registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
+ Source<NavigationController>(controller_));
+ registrar_.Add(this, NotificationType::TAB_CLOSED,
+ Source<NavigationController>(controller_));
+}
+
+void GoogleURLTracker::OnNavigationCommittedOrTabClosed(
+ TabContents* tab_contents,
+ NotificationType::Type type) {
+ registrar_.RemoveAll();
+
+ if (type == NotificationType::NAV_ENTRY_COMMITTED) {
+ ShowGoogleURLInfoBarIfNecessary(tab_contents);
+ } else {
+ controller_ = NULL;
+ infobar_ = NULL;
+ }
}
void GoogleURLTracker::ShowGoogleURLInfoBarIfNecessary(
diff --git a/chrome/browser/google/google_url_tracker.h b/chrome/browser/google/google_url_tracker.h
index bf89a9c..590c6df 100644
--- a/chrome/browser/google/google_url_tracker.h
+++ b/chrome/browser/google/google_url_tracker.h
@@ -10,13 +10,13 @@
#include "base/gtest_prod_util.h"
#include "base/scoped_ptr.h"
+#include "chrome/browser/tab_contents/infobar_delegate.h"
#include "chrome/common/net/url_fetcher.h"
#include "chrome/common/notification_observer.h"
#include "chrome/common/notification_registrar.h"
#include "googleurl/src/gurl.h"
#include "net/base/network_change_notifier.h"
-class InfoBarDelegate;
class NavigationController;
class PrefService;
class TabContents;
@@ -81,8 +81,6 @@ class GoogleURLTracker : public URLFetcher::Delegate,
void InfoBarClosed();
void RedoSearch();
- NavigationController* controller() const { return controller_; }
-
private:
friend class GoogleURLTrackerTest;
@@ -95,6 +93,10 @@ class GoogleURLTracker : public URLFetcher::Delegate,
// 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();
@@ -120,7 +122,10 @@ class GoogleURLTracker : public URLFetcher::Delegate,
virtual void OnIPAddressChanged();
void SearchCommitted();
-
+ void OnNavigationPending(const NotificationSource& source,
+ const GURL& pending_url);
+ void OnNavigationCommittedOrTabClosed(TabContents* tab_contents,
+ NotificationType::Type type);
void ShowGoogleURLInfoBarIfNecessary(TabContents* tab_contents);
NotificationRegistrar registrar_;
@@ -133,6 +138,7 @@ class GoogleURLTracker : public URLFetcher::Delegate,
ScopedRunnableMethodFactory<GoogleURLTracker> runnable_method_factory_;
scoped_ptr<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;
@@ -156,4 +162,33 @@ class GoogleURLTracker : public URLFetcher::Delegate,
DISALLOW_COPY_AND_ASSIGN(GoogleURLTracker);
};
+
+// This infobar delegate is declared here (rather than in the .cc file) so test
+// code can subclass it.
+class GoogleURLTrackerInfoBarDelegate : public ConfirmInfoBarDelegate {
+ public:
+ GoogleURLTrackerInfoBarDelegate(TabContents* tab_contents,
+ GoogleURLTracker* google_url_tracker,
+ const GURL& new_google_url);
+
+ // ConfirmInfoBarDelegate
+ virtual bool Accept();
+ virtual bool Cancel();
+ virtual void InfoBarClosed();
+
+ protected:
+ virtual ~GoogleURLTrackerInfoBarDelegate();
+
+ GoogleURLTracker* google_url_tracker_;
+ const GURL new_google_url_;
+
+ private:
+ // ConfirmInfoBarDelegate
+ virtual string16 GetMessageText() const;
+ virtual int GetButtons() const;
+ virtual string16 GetButtonLabel(InfoBarButton button) const;
+
+ DISALLOW_COPY_AND_ASSIGN(GoogleURLTrackerInfoBarDelegate);
+};
+
#endif // CHROME_BROWSER_GOOGLE_GOOGLE_URL_TRACKER_H_
diff --git a/chrome/browser/google/google_url_tracker_unittest.cc b/chrome/browser/google/google_url_tracker_unittest.cc
index 94cc193..d9fe0c7 100644
--- a/chrome/browser/google/google_url_tracker_unittest.cc
+++ b/chrome/browser/google/google_url_tracker_unittest.cc
@@ -32,7 +32,7 @@ class TestNotificationObserver : public NotificationObserver {
const NotificationSource& source,
const NotificationDetails& details);
bool notified() const { return notified_; }
- void ClearNotified() { notified_ = false; }
+ void clear_notified() { notified_ = false; }
private:
bool notified_;
@@ -63,7 +63,7 @@ class TestInfoBarDelegate : public InfoBarDelegate {
virtual InfoBar* CreateInfoBar();
GoogleURLTracker* google_url_tracker() const { return google_url_tracker_; }
- const GURL& new_google_url() const { return new_google_url_; }
+ GURL new_google_url() const { return new_google_url_; }
private:
GoogleURLTracker* google_url_tracker_;
@@ -125,6 +125,8 @@ class GoogleURLTrackerTest : public testing::Test {
void InfoBarClosed();
void ExpectDefaultURLs();
+ scoped_ptr<TestNotificationObserver> observer_;
+
private:
MessageLoop* message_loop_;
BrowserThread* io_thread_;
@@ -133,13 +135,13 @@ class GoogleURLTrackerTest : public testing::Test {
TestURLFetcherFactory fetcher_factory_;
NotificationRegistrar registrar_;
- scoped_ptr<NotificationObserver> observer_;
URLRequestContextGetter* original_default_request_context_;
};
GoogleURLTrackerTest::GoogleURLTrackerTest()
- : message_loop_(NULL),
+ : observer_(new TestNotificationObserver),
+ message_loop_(NULL),
io_thread_(NULL),
original_default_request_context_(NULL) {
}
@@ -158,10 +160,12 @@ void GoogleURLTrackerTest::SetUp() {
static_cast<TestingBrowserProcess*>(g_browser_process);
PrefService* pref_service = testing_profile_->GetPrefs();
testing_browser_process->SetPrefService(pref_service);
- testing_browser_process->SetGoogleURLTracker(new GoogleURLTracker);
+ GoogleURLTracker* tracker = new GoogleURLTracker;
+ tracker->queue_wakeup_task_ = false;
+ MessageLoop::current()->RunAllPending();
+ testing_browser_process->SetGoogleURLTracker(tracker);
URLFetcher::set_factory(&fetcher_factory_);
- observer_.reset(new TestNotificationObserver);
g_browser_process->google_url_tracker()->infobar_creator_ =
&CreateTestInfobar;
}
@@ -196,20 +200,22 @@ void GoogleURLTrackerTest::MockSearchDomainCheckResponse(
int expected_id,
const std::string& domain) {
TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(expected_id);
- ASSERT_TRUE(fetcher);
- fetcher->delegate()->OnURLFetchComplete(
- fetcher,
- GURL(GoogleURLTracker::kSearchDomainCheckURL),
- URLRequestStatus(),
- 200,
- ResponseCookies(),
- domain);
+ if (!fetcher)
+ return;
+ fetcher->delegate()->OnURLFetchComplete(fetcher,
+ GURL(GoogleURLTracker::kSearchDomainCheckURL), URLRequestStatus(), 200,
+ ResponseCookies(), domain);
+ // At this point, |fetcher| is deleted.
MessageLoop::current()->RunAllPending();
}
void GoogleURLTrackerTest::RequestServerCheck() {
- registrar_.Add(observer_.get(), NotificationType::GOOGLE_URL_UPDATED,
- NotificationService::AllSources());
+ if (!registrar_.IsRegistered(observer_.get(),
+ NotificationType::GOOGLE_URL_UPDATED,
+ NotificationService::AllSources())) {
+ registrar_.Add(observer_.get(), NotificationType::GOOGLE_URL_UPDATED,
+ NotificationService::AllSources());
+ }
GoogleURLTracker::RequestServerCheck();
MessageLoop::current()->RunAllPending();
}
@@ -245,11 +251,11 @@ GURL GoogleURLTrackerTest::GetLastPromptedGoogleURL() {
void GoogleURLTrackerTest::SearchCommitted(const GURL& search_url) {
GoogleURLTracker* google_url_tracker =
g_browser_process->google_url_tracker();
-
google_url_tracker->SearchCommitted();
- // GoogleURLTracker wait for NAV_ENTRY_PENDING.
- // In NAV_ENTRY_PENDING, it will set search_url_.
- google_url_tracker->search_url_ = search_url;
+ if (google_url_tracker->registrar_.IsRegistered(google_url_tracker,
+ NotificationType::NAV_ENTRY_PENDING,
+ NotificationService::AllSources()))
+ google_url_tracker->search_url_ = search_url;
}
void GoogleURLTrackerTest::NavEntryCommitted() {
@@ -302,246 +308,179 @@ void GoogleURLTrackerTest::ExpectDefaultURLs() {
// Tests ----------------------------------------------------------------------
-TEST_F(GoogleURLTrackerTest, StartupSleepFinishNoObserver) {
+TEST_F(GoogleURLTrackerTest, DontFetchWhenNoOneRequestsCheck) {
CreateRequestContext();
-
ExpectDefaultURLs();
-
FinishSleep();
+ // No one called RequestServerCheck() so nothing should have happened.
EXPECT_FALSE(GetFetcherByID(0));
-
ExpectDefaultURLs();
+ EXPECT_FALSE(observer_->notified());
}
-TEST_F(GoogleURLTrackerTest, StartupSleepFinish) {
+TEST_F(GoogleURLTrackerTest, UpdateOnFirstRun) {
CreateRequestContext();
-
RequestServerCheck();
EXPECT_FALSE(GetFetcherByID(0));
ExpectDefaultURLs();
+ EXPECT_FALSE(observer_->notified());
FinishSleep();
MockSearchDomainCheckResponse(0, ".google.co.uk");
-
EXPECT_EQ(GURL("http://www.google.co.uk/"), GetFetchedGoogleURL());
- // GoogleURL is updated, becase it was not the last prompted URL.
+ // GoogleURL should be updated, becase there was no last prompted URL.
EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL());
+ EXPECT_TRUE(observer_->notified());
}
-TEST_F(GoogleURLTrackerTest, StartupSleepFinishWithLastPrompted) {
+TEST_F(GoogleURLTrackerTest, DontUpdateWhenUnchanged) {
CreateRequestContext();
SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
RequestServerCheck();
EXPECT_FALSE(GetFetcherByID(0));
ExpectDefaultURLs();
+ EXPECT_FALSE(observer_->notified());
FinishSleep();
MockSearchDomainCheckResponse(0, ".google.co.uk");
-
EXPECT_EQ(GURL("http://www.google.co.uk/"), GetFetchedGoogleURL());
- // GoogleURL should not be updated.
+ // GoogleURL should not be updated, because the fetched and prompted URLs
+ // match.
EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage),
GoogleURLTracker::GoogleURL());
+ EXPECT_FALSE(observer_->notified());
}
-TEST_F(GoogleURLTrackerTest, UpdatePromptedURLWhenBack) {
+TEST_F(GoogleURLTrackerTest, UpdatePromptedURLOnReturnToPreviousLocation) {
CreateRequestContext();
SetLastPromptedGoogleURL(GURL("http://www.google.co.jp/"));
SetGoogleURL(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/"), GetLastPromptedGoogleURL());
+ EXPECT_FALSE(observer_->notified());
}
-TEST_F(GoogleURLTrackerTest, MonitorNetworkChange) {
+TEST_F(GoogleURLTrackerTest, RefetchOnIPAddressChange) {
CreateRequestContext();
-
RequestServerCheck();
- EXPECT_FALSE(GetFetcherByID(0));
- ExpectDefaultURLs();
-
FinishSleep();
MockSearchDomainCheckResponse(0, ".google.co.uk");
-
EXPECT_EQ(GURL("http://www.google.co.uk/"), GetFetchedGoogleURL());
- // GoogleURL is updated, becase it was not the last prompted URL.
EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL());
+ EXPECT_TRUE(observer_->notified());
+ observer_->clear_notified();
NotifyIPAddressChanged();
MockSearchDomainCheckResponse(1, ".google.co.in");
-
EXPECT_EQ(GURL("http://www.google.co.in/"), GetFetchedGoogleURL());
- // Don't update GoogleURL.
+ // Just fetching a new URL shouldn't reset things without a prompt.
EXPECT_EQ(GURL("http://www.google.co.uk/"), GoogleURLTracker::GoogleURL());
+ EXPECT_FALSE(observer_->notified());
}
-TEST_F(GoogleURLTrackerTest, MonitorNetworkChangeNoObserver) {
+TEST_F(GoogleURLTrackerTest, DontRefetchWhenNoOneRequestsCheck) {
CreateRequestContext();
-
- ExpectDefaultURLs();
-
FinishSleep();
NotifyIPAddressChanged();
+ // No one called RequestServerCheck() so nothing should have happened.
EXPECT_FALSE(GetFetcherByID(0));
-
ExpectDefaultURLs();
+ EXPECT_FALSE(observer_->notified());
}
-TEST_F(GoogleURLTrackerTest, MonitorNetworkChangeAndObserverRegister) {
+TEST_F(GoogleURLTrackerTest, FetchOnLateRequest) {
CreateRequestContext();
-
- ExpectDefaultURLs();
-
FinishSleep();
NotifyIPAddressChanged();
- EXPECT_FALSE(GetFetcherByID(0));
-
- ExpectDefaultURLs();
RequestServerCheck();
+ // 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_TRUE(observer_->notified());
}
-TEST_F(GoogleURLTrackerTest, InitialUpdate) {
+TEST_F(GoogleURLTrackerTest, SearchingDoesNothingIfNoNeedToPrompt) {
CreateRequestContext();
- ExpectDefaultURLs();
- EXPECT_EQ(GURL(), GetLastPromptedGoogleURL());
-
RequestServerCheck();
- EXPECT_FALSE(GetFetcherByID(0));
- ExpectDefaultURLs();
- EXPECT_EQ(GURL(), GetLastPromptedGoogleURL());
-
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/"), 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_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
+ EXPECT_FALSE(observer_->notified());
}
-TEST_F(GoogleURLTrackerTest, SearchCommitedAndUserCloseInfoBar) {
+TEST_F(GoogleURLTrackerTest, InfobarClosed) {
CreateRequestContext();
SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
-
- ExpectDefaultURLs();
-
RequestServerCheck();
- EXPECT_FALSE(GetFetcherByID(0));
- ExpectDefaultURLs();
-
FinishSleep();
MockSearchDomainCheckResponse(0, ".google.co.jp");
- EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage),
- GoogleURLTracker::GoogleURL());
- EXPECT_EQ(GURL("http://www.google.co.jp/"), GetFetchedGoogleURL());
- EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
-
SearchCommitted(GURL("http://www.google.co.uk/search?q=test"));
NavEntryCommitted();
-
EXPECT_TRUE(InfoBarIsShown());
- EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage),
- GoogleURLTracker::GoogleURL());
- EXPECT_EQ(GURL("http://www.google.co.jp/"), GetInfoBarShowingURL());
- EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
InfoBarClosed();
EXPECT_FALSE(InfoBarIsShown());
EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage),
GoogleURLTracker::GoogleURL());
EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
+ EXPECT_FALSE(observer_->notified());
}
-TEST_F(GoogleURLTrackerTest, SearchCommitedAndUserSayNo) {
+TEST_F(GoogleURLTrackerTest, InfobarRefused) {
CreateRequestContext();
SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
-
- ExpectDefaultURLs();
-
RequestServerCheck();
- EXPECT_FALSE(GetFetcherByID(0));
- ExpectDefaultURLs();
-
FinishSleep();
MockSearchDomainCheckResponse(0, ".google.co.jp");
- EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage),
- GoogleURLTracker::GoogleURL());
- EXPECT_EQ(GURL("http://www.google.co.jp/"), GetFetchedGoogleURL());
- EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
-
SearchCommitted(GURL("http://www.google.co.uk/search?q=test"));
NavEntryCommitted();
-
EXPECT_TRUE(InfoBarIsShown());
- EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage),
- GoogleURLTracker::GoogleURL());
- EXPECT_EQ(GURL("http://www.google.co.jp/"), GetInfoBarShowingURL());
- EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
CancelGoogleURL();
- EXPECT_TRUE(InfoBarIsShown());
- EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL());
-
InfoBarClosed();
EXPECT_FALSE(InfoBarIsShown());
EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage),
GoogleURLTracker::GoogleURL());
EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL());
+ EXPECT_FALSE(observer_->notified());
}
-TEST_F(GoogleURLTrackerTest, SearchCommitedAndUserSayYes) {
+TEST_F(GoogleURLTrackerTest, InfobarAccepted) {
CreateRequestContext();
SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
-
- ExpectDefaultURLs();
-
RequestServerCheck();
- EXPECT_FALSE(GetFetcherByID(0));
- ExpectDefaultURLs();
-
FinishSleep();
MockSearchDomainCheckResponse(0, ".google.co.jp");
- EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage),
- GoogleURLTracker::GoogleURL());
- EXPECT_EQ(GURL("http://www.google.co.jp/"), GetFetchedGoogleURL());
- EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
-
SearchCommitted(GURL("http://www.google.co.uk/search?q=test"));
NavEntryCommitted();
-
EXPECT_TRUE(InfoBarIsShown());
- EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage),
- GoogleURLTracker::GoogleURL());
- EXPECT_EQ(GURL("http://www.google.co.jp/"), GetInfoBarShowingURL());
- EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
AcceptGoogleURL();
- EXPECT_TRUE(InfoBarIsShown());
- EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL());
-
InfoBarClosed();
EXPECT_FALSE(InfoBarIsShown());
EXPECT_EQ(GURL("http://www.google.co.jp/"), GoogleURLTracker::GoogleURL());
EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL());
+ EXPECT_TRUE(observer_->notified());
}