diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-10 00:55:16 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-10 00:55:16 +0000 |
commit | f7e41ad98aa53249555f4992edeb76e2d62e0784 (patch) | |
tree | 80549a4fcb9dc56e9b6909348a2dd973268f8dc0 | |
parent | 49f7b7751dd53e71698a46fc80314688644e2590 (diff) | |
download | chromium_src-f7e41ad98aa53249555f4992edeb76e2d62e0784.zip chromium_src-f7e41ad98aa53249555f4992edeb76e2d62e0784.tar.gz chromium_src-f7e41ad98aa53249555f4992edeb76e2d62e0784.tar.bz2 |
Support scheme-setting for GoogleURLTracker.
This switches the searchdomaincheck request from format=domain (".google.com") to format=url ("http://www.google.com/"). This in turn allows the server to direct us to use HTTPS searches by default, which should save a redirect on each search over the current situation when it's applicable.
We hide this detail from the user; we continue to prompt about TLD changes, but we don't prompt about scheme changes.
BUG=96636
TEST=Make sure the cookie store has cookies such that you get HTTPS search by default on Google. After this patch, doing a search should not involve a redirect through HTTP.
Review URL: https://chromiumcodereview.appspot.com/10382091
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@136205 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/google/google_url_tracker.cc | 99 | ||||
-rw-r--r-- | chrome/browser/google/google_url_tracker.h | 13 | ||||
-rw-r--r-- | chrome/browser/google/google_url_tracker_unittest.cc | 247 |
3 files changed, 296 insertions, 63 deletions
diff --git a/chrome/browser/google/google_url_tracker.cc b/chrome/browser/google/google_url_tracker.cc index c751bd9..82a4283 100644 --- a/chrome/browser/google/google_url_tracker.cc +++ b/chrome/browser/google/google_url_tracker.cc @@ -45,6 +45,11 @@ GoogleURLTrackerInfoBarDelegate* CreateInfoBar( google_url_tracker, new_google_url); } +string16 GetHost(const GURL& url) { + DCHECK(url.is_valid()); + return net::StripWWW(UTF8ToUTF16(url.host())); +} + } // namespace // GoogleURLTrackerInfoBarDelegate -------------------------------------------- @@ -63,7 +68,7 @@ GoogleURLTrackerInfoBarDelegate::GoogleURLTrackerInfoBarDelegate( } bool GoogleURLTrackerInfoBarDelegate::Accept() { - google_url_tracker_->AcceptGoogleURL(new_google_url_); + google_url_tracker_->AcceptGoogleURL(new_google_url_, true); return false; } @@ -87,6 +92,11 @@ bool GoogleURLTrackerInfoBarDelegate::LinkClicked( return false; } +void GoogleURLTrackerInfoBarDelegate::SetGoogleURL(const GURL& new_google_url) { + DCHECK_EQ(GetHost(new_google_url_), GetHost(new_google_url)); + new_google_url_ = new_google_url; +} + void GoogleURLTrackerInfoBarDelegate::Show() { showing_ = true; owner()->AddInfoBar(this); // May delete |this| on failure! @@ -137,7 +147,7 @@ GoogleURLTrackerInfoBarDelegate::~GoogleURLTrackerInfoBarDelegate() { string16 GoogleURLTrackerInfoBarDelegate::GetMessageText() const { return l10n_util::GetStringFUTF16(IDS_GOOGLE_URL_TRACKER_INFOBAR_MESSAGE, - GetHost(true), GetHost(false)); + GetHost(new_google_url_), GetHost(google_url_tracker_->google_url_)); } string16 GoogleURLTrackerInfoBarDelegate::GetButtonLabel( @@ -145,12 +155,8 @@ string16 GoogleURLTrackerInfoBarDelegate::GetButtonLabel( bool new_host = (button == BUTTON_OK); return l10n_util::GetStringFUTF16(new_host ? IDS_GOOGLE_URL_TRACKER_INFOBAR_SWITCH : - IDS_GOOGLE_URL_TRACKER_INFOBAR_DONT_SWITCH, GetHost(new_host)); -} - -string16 GoogleURLTrackerInfoBarDelegate::GetHost(bool new_host) const { - return net::StripWWW(UTF8ToUTF16( - (new_host ? new_google_url_ : google_url_tracker_->google_url_).host())); + IDS_GOOGLE_URL_TRACKER_INFOBAR_DONT_SWITCH, + GetHost(new_host ? new_google_url_ : google_url_tracker_->google_url_)); } @@ -159,7 +165,7 @@ string16 GoogleURLTrackerInfoBarDelegate::GetHost(bool new_host) const { const char GoogleURLTracker::kDefaultGoogleHomepage[] = "http://www.google.com/"; const char GoogleURLTracker::kSearchDomainCheckURL[] = - "https://www.google.com/searchdomaincheck?format=domain&type=chrome"; + "https://www.google.com/searchdomaincheck?format=url&type=chrome"; GoogleURLTracker::GoogleURLTracker(Profile* profile, Mode mode) : profile_(profile), @@ -219,7 +225,8 @@ void GoogleURLTracker::GoogleURLSearchCommitted(Profile* profile) { tracker->SearchCommitted(); } -void GoogleURLTracker::AcceptGoogleURL(const GURL& new_google_url) { +void GoogleURLTracker::AcceptGoogleURL(const GURL& new_google_url, + bool redo_searches) { google_url_ = new_google_url; PrefService* prefs = profile_->GetPrefs(); prefs->SetString(prefs::kLastKnownGoogleURL, google_url_.spec()); @@ -229,7 +236,7 @@ void GoogleURLTracker::AcceptGoogleURL(const GURL& new_google_url) { content::Source<Profile>(profile_), content::Details<const GURL>(&new_google_url)); need_to_prompt_ = false; - CloseAllInfoBars(true); + CloseAllInfoBars(redo_searches); } void GoogleURLTracker::CancelGoogleURL(const GURL& new_google_url) { @@ -301,43 +308,73 @@ void GoogleURLTracker::OnURLFetchComplete(const content::URLFetcher* source) { return; } - // See if the response data was one we want to use, and if so, convert to the - // appropriate Google base URL. + // See if the response data was valid. It should be + // "<scheme>://[www.]google.<TLD>/". std::string url_str; source->GetResponseAsString(&url_str); TrimWhitespace(url_str, TRIM_ALL, &url_str); - - if (!StartsWithASCII(url_str, ".google.", false)) + GURL url(url_str); + if (!url.is_valid() || (url.path().length() > 1) || url.has_query() || + url.has_ref() || + !google_util::IsGoogleDomainUrl(url.spec(), + google_util::DISALLOW_SUBDOMAIN)) return; - fetched_google_url_ = GURL("http://www" + url_str); + std::swap(url, fetched_google_url_); GURL last_prompted_url( profile_->GetPrefs()->GetString(prefs::kLastPromptedGoogleURL)); 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_); + AcceptGoogleURL(fetched_google_url_, true); // Second arg is irrelevant. 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; - + string16 fetched_host(GetHost(fetched_google_url_)); 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. + // Either the user has continually been on this URL, or we prompted for a + // different URL but have now changed back before they responded to any of + // the prompts. In this latter case we want to close any open infobars and + // stop prompting. CancelGoogleURL(fetched_google_url_); - return; + } else if (fetched_host == GetHost(google_url_)) { + // Similar to the above case, but this time the new URL differs from the + // existing one, probably due to switching between HTTP and HTTPS searching. + // Like before we want to close any open infobars and stop prompting; we + // also want to silently accept the change in scheme. We don't redo open + // searches so as to avoid suddenly changing a page the user might be + // interacting with; it's enough to simply get future searches right. + AcceptGoogleURL(fetched_google_url_, false); + } else if (fetched_host == GetHost(last_prompted_url)) { + // We've re-fetched a TLD the user previously turned down. Although the new + // URL might have a different scheme than the old, we want to preserve the + // user's decision. Note that it's possible that, like in the above two + // cases, we fetched yet another different URL in the meantime, which we + // have open infobars prompting about; in this case, as in those above, we + // want to go ahead and close the infobars and stop prompting, since we've + // switched back away from that URL. + CancelGoogleURL(fetched_google_url_); + } else { + // We've fetched a URL with a different TLD than the user is currently using + // or was previously prompted about. This means we need to prompt again. + need_to_prompt_ = true; + + // As in all the above cases, there could be open infobars prompting about + // some URL. If these URLs have the same TLD, we can simply leave the + // existing infobars open and quietly point their "new Google URL"s at the + // new URL (for e.g. scheme changes). Otherwise we go ahead and close the + // existing infobars since their message is out-of-date. + if (!url.is_valid()) // Note: |url| is the previous |fetched_google_url_|. + return; + if (fetched_host != GetHost(url)) { + CloseAllInfoBars(false); + } else if (fetched_google_url_ != url) { + for (InfoBarMap::iterator i(infobar_map_.begin()); + i != infobar_map_.end(); ++i) + i->second->SetGoogleURL(fetched_google_url_); + } } - - need_to_prompt_ = true; - - // Any open infobars are pointing at the wrong Google URL. (This can happen - // if an infobar has been sitting open and then our IP address changes.) - CloseAllInfoBars(false); } void GoogleURLTracker::Observe(int type, diff --git a/chrome/browser/google/google_url_tracker.h b/chrome/browser/google/google_url_tracker.h index a30c84b..2b90452 100644 --- a/chrome/browser/google/google_url_tracker.h +++ b/chrome/browser/google/google_url_tracker.h @@ -100,7 +100,7 @@ class GoogleURLTracker : public content::URLFetcherDelegate, GoogleURLTracker* google_url_tracker, const GURL& new_google_url); - void AcceptGoogleURL(const GURL& google_url); + void AcceptGoogleURL(const GURL& google_url, bool redo_searches); void CancelGoogleURL(const GURL& google_url); void InfoBarClosed(const InfoBarTabHelper* infobar_helper); @@ -211,6 +211,12 @@ class GoogleURLTrackerInfoBarDelegate : public ConfirmInfoBarDelegate { virtual string16 GetLinkText() const OVERRIDE; virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE; + // Allows GoogleURLTracker to change the Google base URL after the infobar has + // been instantiated. This should only be called with an URL with the same + // TLD as the existing one, so that the prompt we're displaying will still be + // correct. + void SetGoogleURL(const GURL& new_google_url); + // These are virtual so test code can override them in a subclass. virtual void Show(); virtual void Close(bool redo_search); @@ -221,7 +227,7 @@ class GoogleURLTrackerInfoBarDelegate : public ConfirmInfoBarDelegate { InfoBarTabHelper* map_key_; // What |google_url_tracker_| uses to track us. const GURL search_url_; GoogleURLTracker* google_url_tracker_; - const GURL new_google_url_; + GURL new_google_url_; bool showing_; // True if this delegate has been added to a TabContents. private: @@ -229,9 +235,6 @@ class GoogleURLTrackerInfoBarDelegate : public ConfirmInfoBarDelegate { virtual string16 GetMessageText() const OVERRIDE; virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; - // Returns the portion of the appropriate hostname to display. - string16 GetHost(bool new_host) const; - DISALLOW_COPY_AND_ASSIGN(GoogleURLTrackerInfoBarDelegate); }; diff --git a/chrome/browser/google/google_url_tracker_unittest.cc b/chrome/browser/google/google_url_tracker_unittest.cc index b5d6a08..22192dc 100644 --- a/chrome/browser/google/google_url_tracker_unittest.cc +++ b/chrome/browser/google/google_url_tracker_unittest.cc @@ -2,9 +2,13 @@ // 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 <set> +#include <string> + #include "base/message_loop.h" #include "chrome/browser/infobars/infobar_delegate.h" -#include "chrome/browser/google/google_url_tracker.h" #include "chrome/browser/google/google_url_tracker_factory.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/common/chrome_notification_types.h" @@ -149,6 +153,9 @@ class GoogleURLTrackerTest : public testing::Test { content::NotificationRegistrar registrar_; TestingProfile profile_; scoped_ptr<GoogleURLTracker> google_url_tracker_; + // This tracks the different "tabs" a test has "opened", so we can close them + // properly before shutting down |google_url_tracker_|, which expects that. + std::set<int> unique_ids_seen_; }; GoogleURLTrackerTest::GoogleURLTrackerTest() @@ -169,6 +176,9 @@ void GoogleURLTrackerTest::SetUp() { } void GoogleURLTrackerTest::TearDown() { + while (!unique_ids_seen_.empty()) + CloseTab(*unique_ids_seen_.begin()); + google_url_tracker_.reset(); network_change_notifier_.reset(); } @@ -223,6 +233,7 @@ GURL GoogleURLTrackerTest::GetLastPromptedGoogleURL() { void GoogleURLTrackerTest::SetSearchPending(const GURL& search_url, int unique_id) { + unique_ids_seen_.insert(unique_id); google_url_tracker_->SearchCommitted(); if (google_url_tracker_->registrar_.IsRegistered(google_url_tracker_.get(), content::NOTIFICATION_NAV_ENTRY_PENDING, @@ -249,6 +260,7 @@ void GoogleURLTrackerTest::CommitSearch(int unique_id) { } void GoogleURLTrackerTest::CloseTab(int unique_id) { + unique_ids_seen_.erase(unique_id); content::Source<content::WebContents> source( reinterpret_cast<content::WebContents*>(unique_id)); InfoBarTabHelper* infobar_helper = @@ -295,7 +307,7 @@ TEST_F(GoogleURLTrackerTest, DontFetchWhenNoOneRequestsCheck) { FinishSleep(); // No one called RequestServerCheck() so nothing should have happened. EXPECT_FALSE(GetFetcher()); - MockSearchDomainCheckResponse(".google.co.uk"); + MockSearchDomainCheckResponse("http://www.google.co.uk/"); ExpectDefaultURLs(); EXPECT_FALSE(observer_->notified()); } @@ -307,7 +319,7 @@ TEST_F(GoogleURLTrackerTest, UpdateOnFirstRun) { EXPECT_FALSE(observer_->notified()); FinishSleep(); - MockSearchDomainCheckResponse(".google.co.uk"); + MockSearchDomainCheckResponse("http://www.google.co.uk/"); 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/"), google_url()); @@ -323,7 +335,7 @@ TEST_F(GoogleURLTrackerTest, DontUpdateWhenUnchanged) { EXPECT_FALSE(observer_->notified()); FinishSleep(); - MockSearchDomainCheckResponse(".google.co.uk"); + MockSearchDomainCheckResponse("http://www.google.co.uk/"); EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); // GoogleURL should not be updated, because the fetched and prompted URLs // match. @@ -331,29 +343,119 @@ TEST_F(GoogleURLTrackerTest, DontUpdateWhenUnchanged) { EXPECT_FALSE(observer_->notified()); } +TEST_F(GoogleURLTrackerTest, DontPromptOnBadReplies) { + SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); + + RequestServerCheck(); + EXPECT_FALSE(GetFetcher()); + ExpectDefaultURLs(); + EXPECT_FALSE(observer_->notified()); + + // Old-style domain string. + FinishSleep(); + MockSearchDomainCheckResponse(".google.co.in"); + EXPECT_EQ(GURL(), fetched_google_url()); + EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); + EXPECT_FALSE(observer_->notified()); + SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); + CommitSearch(1); + EXPECT_TRUE(GetInfoBar(1) == NULL); + + // Bad subdomain. + NotifyIPAddressChanged(); + MockSearchDomainCheckResponse("http://mail.google.com/"); + EXPECT_EQ(GURL(), fetched_google_url()); + EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); + EXPECT_FALSE(observer_->notified()); + SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); + CommitSearch(1); + EXPECT_TRUE(GetInfoBar(1) == NULL); + + // Non-empty path. + NotifyIPAddressChanged(); + MockSearchDomainCheckResponse("http://www.google.com/search"); + EXPECT_EQ(GURL(), fetched_google_url()); + EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); + EXPECT_FALSE(observer_->notified()); + SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); + CommitSearch(1); + EXPECT_TRUE(GetInfoBar(1) == NULL); + + // Non-empty query. + NotifyIPAddressChanged(); + MockSearchDomainCheckResponse("http://www.google.com/?q=foo"); + EXPECT_EQ(GURL(), fetched_google_url()); + EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); + EXPECT_FALSE(observer_->notified()); + SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); + CommitSearch(1); + EXPECT_TRUE(GetInfoBar(1) == NULL); + + // Non-empty ref. + NotifyIPAddressChanged(); + MockSearchDomainCheckResponse("http://www.google.com/#anchor"); + EXPECT_EQ(GURL(), fetched_google_url()); + EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); + EXPECT_FALSE(observer_->notified()); + SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); + CommitSearch(1); + EXPECT_TRUE(GetInfoBar(1) == NULL); + + // Complete garbage. + NotifyIPAddressChanged(); + MockSearchDomainCheckResponse("HJ)*qF)_*&@f1"); + EXPECT_EQ(GURL(), fetched_google_url()); + EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); + EXPECT_FALSE(observer_->notified()); + SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); + CommitSearch(1); + EXPECT_TRUE(GetInfoBar(1) == NULL); +} + TEST_F(GoogleURLTrackerTest, UpdatePromptedURLOnReturnToPreviousLocation) { SetLastPromptedGoogleURL(GURL("http://www.google.co.jp/")); set_google_url(GURL("http://www.google.co.uk/")); RequestServerCheck(); FinishSleep(); - MockSearchDomainCheckResponse(".google.co.uk"); + MockSearchDomainCheckResponse("http://www.google.co.uk/"); 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()); } +TEST_F(GoogleURLTrackerTest, SilentlyAcceptSchemeChange) { + // We should auto-accept changes to the current Google URL that merely change + // the scheme, regardless of what the last prompted URL was. + SetLastPromptedGoogleURL(GURL("http://www.google.co.jp/")); + set_google_url(GURL("http://www.google.co.uk/")); + RequestServerCheck(); + FinishSleep(); + MockSearchDomainCheckResponse("https://www.google.co.uk/"); + EXPECT_EQ(GURL("https://www.google.co.uk/"), fetched_google_url()); + EXPECT_EQ(GURL("https://www.google.co.uk/"), google_url()); + EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); + EXPECT_TRUE(observer_->notified()); + + NotifyIPAddressChanged(); + MockSearchDomainCheckResponse("http://www.google.co.uk/"); + 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()); +} + TEST_F(GoogleURLTrackerTest, RefetchOnIPAddressChange) { RequestServerCheck(); FinishSleep(); - MockSearchDomainCheckResponse(".google.co.uk"); + MockSearchDomainCheckResponse("http://www.google.co.uk/"); 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(".google.co.in"); + MockSearchDomainCheckResponse("http://www.google.co.in/"); 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/"), google_url()); @@ -365,7 +467,7 @@ TEST_F(GoogleURLTrackerTest, DontRefetchWhenNoOneRequestsCheck) { NotifyIPAddressChanged(); // No one called RequestServerCheck() so nothing should have happened. EXPECT_FALSE(GetFetcher()); - MockSearchDomainCheckResponse(".google.co.uk"); + MockSearchDomainCheckResponse("http://www.google.co.uk/"); ExpectDefaultURLs(); EXPECT_FALSE(observer_->notified()); } @@ -373,12 +475,12 @@ TEST_F(GoogleURLTrackerTest, DontRefetchWhenNoOneRequestsCheck) { TEST_F(GoogleURLTrackerTest, FetchOnLateRequest) { FinishSleep(); NotifyIPAddressChanged(); - MockSearchDomainCheckResponse(".google.co.jp"); + MockSearchDomainCheckResponse("http://www.google.co.jp/"); RequestServerCheck(); // The first request for a check should trigger a fetch if it hasn't happened // already. - MockSearchDomainCheckResponse(".google.co.uk"); + MockSearchDomainCheckResponse("http://www.google.co.uk/"); 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()); @@ -387,12 +489,12 @@ TEST_F(GoogleURLTrackerTest, FetchOnLateRequest) { TEST_F(GoogleURLTrackerTest, DontFetchTwiceOnLateRequests) { FinishSleep(); NotifyIPAddressChanged(); - MockSearchDomainCheckResponse(".google.co.jp"); + MockSearchDomainCheckResponse("http://www.google.co.jp/"); RequestServerCheck(); // The first request for a check should trigger a fetch if it hasn't happened // already. - MockSearchDomainCheckResponse(".google.co.uk"); + MockSearchDomainCheckResponse("http://www.google.co.uk/"); 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()); @@ -401,7 +503,7 @@ TEST_F(GoogleURLTrackerTest, DontFetchTwiceOnLateRequests) { RequestServerCheck(); // The second request should be ignored. EXPECT_FALSE(GetFetcher()); - MockSearchDomainCheckResponse(".google.co.in"); + MockSearchDomainCheckResponse("http://www.google.co.in/"); EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); EXPECT_FALSE(observer_->notified()); @@ -410,7 +512,7 @@ TEST_F(GoogleURLTrackerTest, DontFetchTwiceOnLateRequests) { TEST_F(GoogleURLTrackerTest, SearchingDoesNothingIfNoNeedToPrompt) { RequestServerCheck(); FinishSleep(); - MockSearchDomainCheckResponse(".google.co.uk"); + MockSearchDomainCheckResponse("http://www.google.co.uk/"); 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()); @@ -420,7 +522,7 @@ TEST_F(GoogleURLTrackerTest, SearchingDoesNothingIfNoNeedToPrompt) { SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); CommitSearch(1); TestInfoBarDelegate* infobar = GetInfoBar(1); - ASSERT_TRUE(infobar == NULL); + EXPECT_TRUE(infobar == NULL); 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()); @@ -431,7 +533,7 @@ TEST_F(GoogleURLTrackerTest, TabClosedOnPendingSearch) { SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); RequestServerCheck(); FinishSleep(); - MockSearchDomainCheckResponse(".google.co.jp"); + MockSearchDomainCheckResponse("http://www.google.co.jp/"); EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); EXPECT_EQ(GURL("http://www.google.co.jp/"), fetched_google_url()); EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); @@ -459,7 +561,7 @@ TEST_F(GoogleURLTrackerTest, TabClosedOnCommittedSearch) { SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); RequestServerCheck(); FinishSleep(); - MockSearchDomainCheckResponse(".google.co.jp"); + MockSearchDomainCheckResponse("http://www.google.co.jp/"); SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); CommitSearch(1); @@ -478,7 +580,7 @@ TEST_F(GoogleURLTrackerTest, InfobarClosed) { SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); RequestServerCheck(); FinishSleep(); - MockSearchDomainCheckResponse(".google.co.jp"); + MockSearchDomainCheckResponse("http://www.google.co.jp/"); SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); CommitSearch(1); @@ -496,7 +598,7 @@ TEST_F(GoogleURLTrackerTest, InfobarRefused) { SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); RequestServerCheck(); FinishSleep(); - MockSearchDomainCheckResponse(".google.co.jp"); + MockSearchDomainCheckResponse("http://www.google.co.jp/"); SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); CommitSearch(1); @@ -514,7 +616,7 @@ TEST_F(GoogleURLTrackerTest, InfobarAccepted) { SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); RequestServerCheck(); FinishSleep(); - MockSearchDomainCheckResponse(".google.co.jp"); + MockSearchDomainCheckResponse("http://www.google.co.jp/"); SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); CommitSearch(1); @@ -528,11 +630,106 @@ TEST_F(GoogleURLTrackerTest, InfobarAccepted) { EXPECT_TRUE(observer_->notified()); } +TEST_F(GoogleURLTrackerTest, FetchesCanAutomaticallyCloseInfobars) { + RequestServerCheck(); + FinishSleep(); + MockSearchDomainCheckResponse(google_url().spec()); + + // Re-fetching the accepted URL after showing an infobar for another URL + // should close the infobar. + NotifyIPAddressChanged(); + MockSearchDomainCheckResponse("http://www.google.co.uk/"); + SetSearchPending(GURL("http://www.google.com/search?q=test"), 1); + CommitSearch(1); + EXPECT_FALSE(GetInfoBar(1) == NULL); + NotifyIPAddressChanged(); + MockSearchDomainCheckResponse(google_url().spec()); + EXPECT_EQ(google_url(), GetLastPromptedGoogleURL()); + EXPECT_TRUE(GetInfoBar(1) == NULL); + + // As should fetching a URL that differs from the accepted only by the scheme. + NotifyIPAddressChanged(); + MockSearchDomainCheckResponse("http://www.google.co.uk/"); + SetSearchPending(GURL("http://www.google.com/search?q=test"), 1); + CommitSearch(1); + EXPECT_FALSE(GetInfoBar(1) == NULL); + NotifyIPAddressChanged(); + url_canon::Replacements<char> replacements; + const std::string& scheme("https"); + replacements.SetScheme(scheme.data(), + url_parse::Component(0, scheme.length())); + GURL new_google_url(google_url().ReplaceComponents(replacements)); + MockSearchDomainCheckResponse(new_google_url.spec()); + EXPECT_EQ(new_google_url, GetLastPromptedGoogleURL()); + EXPECT_TRUE(GetInfoBar(1) == NULL); + + // As should re-fetching the last prompted URL. + SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); + NotifyIPAddressChanged(); + MockSearchDomainCheckResponse("http://www.google.co.jp/"); + SetSearchPending(GURL("http://www.google.com/search?q=test"), 1); + CommitSearch(1); + EXPECT_FALSE(GetInfoBar(1) == NULL); + NotifyIPAddressChanged(); + MockSearchDomainCheckResponse("http://www.google.co.uk/"); + EXPECT_EQ(new_google_url, google_url()); + EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); + EXPECT_TRUE(GetInfoBar(1) == NULL); + + // And one that differs from the last prompted URL only by the scheme. + NotifyIPAddressChanged(); + MockSearchDomainCheckResponse("http://www.google.co.jp/"); + SetSearchPending(GURL("http://www.google.com/search?q=test"), 1); + CommitSearch(1); + EXPECT_FALSE(GetInfoBar(1) == NULL); + NotifyIPAddressChanged(); + MockSearchDomainCheckResponse("https://www.google.co.uk/"); + EXPECT_EQ(new_google_url, google_url()); + EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); + EXPECT_TRUE(GetInfoBar(1) == NULL); + + // And fetching a different URL entirely. + NotifyIPAddressChanged(); + MockSearchDomainCheckResponse("http://www.google.co.jp/"); + SetSearchPending(GURL("http://www.google.com/search?q=test"), 1); + CommitSearch(1); + EXPECT_FALSE(GetInfoBar(1) == NULL); + NotifyIPAddressChanged(); + MockSearchDomainCheckResponse("https://www.google.co.in/"); + EXPECT_EQ(new_google_url, google_url()); + EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); + EXPECT_TRUE(GetInfoBar(1) == NULL); +} + +TEST_F(GoogleURLTrackerTest, ResetInfobarGoogleURLs) { + RequestServerCheck(); + FinishSleep(); + MockSearchDomainCheckResponse(google_url().spec()); + + NotifyIPAddressChanged(); + MockSearchDomainCheckResponse("http://www.google.co.uk/"); + SetSearchPending(GURL("http://www.google.com/search?q=test"), 1); + CommitSearch(1); + TestInfoBarDelegate* infobar = GetInfoBar(1); + ASSERT_FALSE(infobar == NULL); + EXPECT_EQ(GURL("http://www.google.co.uk/"), infobar->new_google_url()); + + // If while an infobar is showing we fetch a new URL that differs from the + // infobar's only by scheme, the infobar should stay open but have its Google + // URL reset. + NotifyIPAddressChanged(); + MockSearchDomainCheckResponse("https://www.google.co.uk/"); + TestInfoBarDelegate* new_infobar = GetInfoBar(1); + ASSERT_FALSE(new_infobar == NULL); + EXPECT_EQ(infobar, new_infobar); + EXPECT_EQ(GURL("https://www.google.co.uk/"), new_infobar->new_google_url()); +} + TEST_F(GoogleURLTrackerTest, InfobarShownAgainOnSearchAfterPendingSearch) { SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); RequestServerCheck(); FinishSleep(); - MockSearchDomainCheckResponse(".google.co.jp"); + MockSearchDomainCheckResponse("http://www.google.co.jp/"); SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); TestInfoBarDelegate* infobar = GetInfoBar(1); @@ -553,15 +750,13 @@ TEST_F(GoogleURLTrackerTest, InfobarShownAgainOnSearchAfterPendingSearch) { EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); EXPECT_FALSE(observer_->notified()); - - CloseTab(1); } TEST_F(GoogleURLTrackerTest, InfobarShownAgainOnSearchAfterCommittedSearch) { SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); RequestServerCheck(); FinishSleep(); - MockSearchDomainCheckResponse(".google.co.jp"); + MockSearchDomainCheckResponse("http://www.google.co.jp/"); SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); CommitSearch(1); @@ -584,15 +779,13 @@ TEST_F(GoogleURLTrackerTest, InfobarShownAgainOnSearchAfterCommittedSearch) { EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); EXPECT_FALSE(observer_->notified()); - - CloseTab(1); } TEST_F(GoogleURLTrackerTest, MultipleInfobars) { SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); RequestServerCheck(); FinishSleep(); - MockSearchDomainCheckResponse(".google.co.jp"); + MockSearchDomainCheckResponse("http://www.google.co.jp/"); SetSearchPending(GURL("http://www.google.co.uk/search?q=test"), 1); TestInfoBarDelegate* infobar = GetInfoBar(1); |