From 2ddc774397497fa680c8846e34a16629577a6c16 Mon Sep 17 00:00:00 2001 From: Mathieu Perreault Date: Sat, 31 Jan 2015 13:33:10 -0500 Subject: [PATCH] [Search] Identity check for New Tab Page should use canonicalized form Was causing a bug where identities were slightly different. BUG=453792 Review URL: https://codereview.chromium.org/864223006 Cr-Commit-Position: refs/heads/master@{#313955} (cherry picked from commit ed8d517fc97a8b0c3542669279b0482727255a32) Review URL: https://codereview.chromium.org/886233003 Cr-Commit-Position: refs/branch-heads/2272@{#172} Cr-Branched-From: 827a380cfdb31aa54c8d56e63ce2c3fd8c3ba4d4-refs/heads/master@{#310958} --- chrome/browser/ui/search/search_tab_helper.cc | 7 +-- chrome/browser/ui/search/search_tab_helper.h | 5 +- .../ui/search/search_tab_helper_unittest.cc | 47 +++++++++++++++++++ 3 files changed, 55 insertions(+), 4 deletions(-) diff --git a/chrome/browser/ui/search/search_tab_helper.cc b/chrome/browser/ui/search/search_tab_helper.cc index b610cee66d127..36cf06ab2574a 100644 --- a/chrome/browser/ui/search/search_tab_helper.cc +++ b/chrome/browser/ui/search/search_tab_helper.cc @@ -46,6 +46,7 @@ #include "content/public/browser/user_metrics.h" #include "content/public/browser/web_contents.h" #include "content/public/common/referrer.h" +#include "google_apis/gaia/gaia_auth_util.h" #include "net/base/net_errors.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/page_transition_types.h" @@ -563,9 +564,9 @@ void SearchTabHelper::PasteIntoOmnibox(const base::string16& text) { void SearchTabHelper::OnChromeIdentityCheck(const base::string16& identity) { SigninManagerBase* manager = SigninManagerFactory::GetForProfile(profile()); if (manager) { - const base::string16 username = - base::UTF8ToUTF16(manager->GetAuthenticatedUsername()); - ipc_router_.SendChromeIdentityCheckResult(identity, identity == username); + ipc_router_.SendChromeIdentityCheckResult( + identity, gaia::AreEmailsSame(base::UTF16ToUTF8(identity), + manager->GetAuthenticatedUsername())); } else { ipc_router_.SendChromeIdentityCheckResult(identity, false); } diff --git a/chrome/browser/ui/search/search_tab_helper.h b/chrome/browser/ui/search/search_tab_helper.h index 764afa188ee64..c5397bb4e42e3 100644 --- a/chrome/browser/ui/search/search_tab_helper.h +++ b/chrome/browser/ui/search/search_tab_helper.h @@ -113,7 +113,10 @@ class SearchTabHelper : public content::WebContentsObserver, FRIEND_TEST_ALL_PREFIXES(SearchTabHelperTest, OnChromeIdentityCheckMatch); FRIEND_TEST_ALL_PREFIXES(SearchTabHelperTest, - OnChromeIdentityCheckMismatch); + OnChromeIdentityCheckMatchSlightlyDifferentGmail); + FRIEND_TEST_ALL_PREFIXES(SearchTabHelperTest, + OnChromeIdentityCheckMatchSlightlyDifferentGmail2); + FRIEND_TEST_ALL_PREFIXES(SearchTabHelperTest, OnChromeIdentityCheckMismatch); FRIEND_TEST_ALL_PREFIXES(SearchTabHelperTest, OnChromeIdentityCheckSignedOutMatch); FRIEND_TEST_ALL_PREFIXES(SearchTabHelperTest, diff --git a/chrome/browser/ui/search/search_tab_helper_unittest.cc b/chrome/browser/ui/search/search_tab_helper_unittest.cc index 0264ae2118037..8b3f7789f3a68 100644 --- a/chrome/browser/ui/search/search_tab_helper_unittest.cc +++ b/chrome/browser/ui/search/search_tab_helper_unittest.cc @@ -193,6 +193,53 @@ TEST_F(SearchTabHelperTest, OnChromeIdentityCheckMatch) { ASSERT_TRUE(get<1>(params)); } +TEST_F(SearchTabHelperTest, OnChromeIdentityCheckMatchSlightlyDifferentGmail) { + NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); + CreateSigninManager(std::string("foobar123@gmail.com")); + SearchTabHelper* search_tab_helper = + SearchTabHelper::FromWebContents(web_contents()); + ASSERT_NE(static_cast(NULL), search_tab_helper); + + // For gmail, canonicalization is done so that email addresses have a + // standard form. + const base::string16 test_identity = + base::ASCIIToUTF16("Foo.Bar.123@gmail.com"); + search_tab_helper->OnChromeIdentityCheck(test_identity); + + const IPC::Message* message = process()->sink().GetUniqueMessageMatching( + ChromeViewMsg_ChromeIdentityCheckResult::ID); + ASSERT_TRUE(message != NULL); + + ChromeViewMsg_ChromeIdentityCheckResult::Param params; + ChromeViewMsg_ChromeIdentityCheckResult::Read(message, ¶ms); + EXPECT_EQ(test_identity, get<0>(params)); + ASSERT_TRUE(get<1>(params)); +} + +TEST_F(SearchTabHelperTest, OnChromeIdentityCheckMatchSlightlyDifferentGmail2) { + NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); + // + CreateSigninManager(std::string("chrome.guy.7FOREVER")); + SearchTabHelper* search_tab_helper = + SearchTabHelper::FromWebContents(web_contents()); + ASSERT_NE(static_cast(NULL), search_tab_helper); + + // For gmail/googlemail, canonicalization is done so that email addresses have + // a standard form. + const base::string16 test_identity = + base::ASCIIToUTF16("chromeguy7forever@googlemail.com"); + search_tab_helper->OnChromeIdentityCheck(test_identity); + + const IPC::Message* message = process()->sink().GetUniqueMessageMatching( + ChromeViewMsg_ChromeIdentityCheckResult::ID); + ASSERT_TRUE(message != NULL); + + ChromeViewMsg_ChromeIdentityCheckResult::Param params; + ChromeViewMsg_ChromeIdentityCheckResult::Read(message, ¶ms); + EXPECT_EQ(test_identity, get<0>(params)); + ASSERT_TRUE(get<1>(params)); +} + TEST_F(SearchTabHelperTest, OnChromeIdentityCheckMismatch) { NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); CreateSigninManager(std::string("foo@bar.com"));