diff options
author | ukai@chromium.org <ukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-06 02:09:14 +0000 |
---|---|---|
committer | ukai@chromium.org <ukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-06 02:09:14 +0000 |
commit | ba56560d692519545de5ec15af06898acadcb17e (patch) | |
tree | fc552a7c24f9c886891acf6dd90c50d6a36e2f79 /chrome/browser/google | |
parent | 07487b946aa0b8704214f7b3e595d9aa6908dcc1 (diff) | |
download | chromium_src-ba56560d692519545de5ec15af06898acadcb17e.zip chromium_src-ba56560d692519545de5ec15af06898acadcb17e.tar.gz chromium_src-ba56560d692519545de5ec15af06898acadcb17e.tar.bz2 |
Update last prompted URL when user choosed "yes" or "no".
BUG=54274
TEST=GoogleURLTrackerTest passes
Review URL: http://codereview.chromium.org/3330008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58619 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/google')
-rw-r--r-- | chrome/browser/google/google_url_tracker.cc | 14 | ||||
-rw-r--r-- | chrome/browser/google/google_url_tracker.h | 1 | ||||
-rw-r--r-- | chrome/browser/google/google_url_tracker_unittest.cc | 52 |
3 files changed, 63 insertions, 4 deletions
diff --git a/chrome/browser/google/google_url_tracker.cc b/chrome/browser/google/google_url_tracker.cc index 6760483..606cc27 100644 --- a/chrome/browser/google/google_url_tracker.cc +++ b/chrome/browser/google/google_url_tracker.cc @@ -63,6 +63,11 @@ class GoogleURLTrackerInfoBarDelegate : public ConfirmInfoBarDelegate { return true; } + virtual bool Cancel() { + google_url_tracker_->CancelGoogleURL(new_google_url_); + return true; + } + virtual void InfoBarClosed() { google_url_tracker_->InfoBarClosed(); delete this; @@ -251,12 +256,19 @@ 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, + new_google_url.spec()); NotificationService::current()->Notify(NotificationType::GOOGLE_URL_UPDATED, NotificationService::AllSources(), 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()); +} + void GoogleURLTracker::InfoBarClosed() { registrar_.RemoveAll(); controller_ = NULL; @@ -343,6 +355,4 @@ void GoogleURLTracker::ShowGoogleURLInfoBarIfNecessary( infobar_ = infobar_factory_->CreateInfoBar(tab_contents, this, fetched_google_url_); - g_browser_process->local_state()->SetString(prefs::kLastPromptedGoogleURL, - fetched_google_url_.spec()); } diff --git a/chrome/browser/google/google_url_tracker.h b/chrome/browser/google/google_url_tracker.h index 4b9ba57..b00bd25 100644 --- a/chrome/browser/google/google_url_tracker.h +++ b/chrome/browser/google/google_url_tracker.h @@ -85,6 +85,7 @@ class GoogleURLTracker : public URLFetcher::Delegate, // Methods called from InfoBar delegate. void AcceptGoogleURL(const GURL& google_url); + void CancelGoogleURL(const GURL& google_url); void InfoBarClosed(); void RedoSearch(); diff --git a/chrome/browser/google/google_url_tracker_unittest.cc b/chrome/browser/google/google_url_tracker_unittest.cc index d23e9ea..08ec605 100644 --- a/chrome/browser/google/google_url_tracker_unittest.cc +++ b/chrome/browser/google/google_url_tracker_unittest.cc @@ -203,6 +203,14 @@ class GoogleURLTrackerTest : public testing::Test { infobar->google_url_tracker()->AcceptGoogleURL(infobar->new_google_url()); } + void CancelGoogleURL() { + TestInfoBar* infobar = static_cast<TestInfoBar*>( + g_browser_process->google_url_tracker()->infobar_); + ASSERT_TRUE(infobar); + ASSERT_TRUE(infobar->google_url_tracker()); + infobar->google_url_tracker()->CancelGoogleURL(infobar->new_google_url()); + } + void InfoBarClosed() { TestInfoBar* infobar = static_cast<TestInfoBar*>( g_browser_process->google_url_tracker()->infobar_); @@ -340,6 +348,40 @@ TEST_F(GoogleURLTrackerTest, NoSearchCommitedAndPromptedNotChanged) { EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); } +TEST_F(GoogleURLTrackerTest, SearchCommitedAndUserCloseInfoBar) { + 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()); +} + TEST_F(GoogleURLTrackerTest, SearchCommitedAndUserSayNo) { CreateRequestContext(); SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); @@ -365,6 +407,10 @@ TEST_F(GoogleURLTrackerTest, SearchCommitedAndUserSayNo) { 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(); @@ -399,11 +445,13 @@ TEST_F(GoogleURLTrackerTest, SearchCommitedAndUserSayYes) { EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), GoogleURLTracker::GoogleURL()); EXPECT_EQ(GURL("http://www.google.co.jp/"), GetInfoBarShowingURL()); - EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); + EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); AcceptGoogleURL(); - InfoBarClosed(); + 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()); |