Commit ed8d517f authored by mathp's avatar mathp Committed by Commit bot

[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}
parent 684f44bd
......@@ -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);
}
......
......@@ -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,
......
......@@ -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<SearchTabHelper*>(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, &params);
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<SearchTabHelper*>(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, &params);
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"));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment