Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
[Search] Identity check for New Tab Page should use canonicalized form
Browse files Browse the repository at this point in the history
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 ed8d517)

Review URL: https://codereview.chromium.org/886233003

Cr-Commit-Position: refs/branch-heads/2272@{#172}
Cr-Branched-From: 827a380-refs/heads/master@{#310958}
  • Loading branch information
Mathieu Perreault committed Jan 31, 2015
1 parent 1e87387 commit 2ddc774
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 4 deletions.
7 changes: 4 additions & 3 deletions chrome/browser/ui/search/search_tab_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
}
Expand Down
5 changes: 4 additions & 1 deletion chrome/browser/ui/search/search_tab_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
47 changes: 47 additions & 0 deletions chrome/browser/ui/search/search_tab_helper_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,53 @@ TEST_F(SearchTabHelperTest, OnChromeIdentityCheckMatch) {
ASSERT_TRUE(get<1>(params));
}

TEST_F(SearchTabHelperTest, OnChromeIdentityCheckMatchSlightlyDifferentGmail) {
NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
CreateSigninManager(std::string("[email protected]"));
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("[email protected]");
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("[email protected]");
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("[email protected]"));
Expand Down

0 comments on commit 2ddc774

Please sign in to comment.