Commit a5e709d6 authored by Xiaohui Chen's avatar Xiaohui Chen Committed by Commit Bot

assistant: enable @googlemail.com

Bug: None
Test: unittests
Change-Id: Ia0dd24b72d0ad3d1eebcdd33b1124c97e4ee4365
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1716170
Commit-Queue: Xiaohui Chen <xiaohuic@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#680524}
parent 9da229d1
...@@ -105,6 +105,8 @@ ash::mojom::AssistantAllowedState IsAssistantAllowedForProfile( ...@@ -105,6 +105,8 @@ ash::mojom::AssistantAllowedState IsAssistantAllowedForProfile(
const std::string email = identity_manager->GetPrimaryAccountInfo().email; const std::string email = identity_manager->GetPrimaryAccountInfo().email;
if (base::EndsWith(email, "@gmail.com", if (base::EndsWith(email, "@gmail.com",
base::CompareCase::INSENSITIVE_ASCII) || base::CompareCase::INSENSITIVE_ASCII) ||
base::EndsWith(email, "@googlemail.com",
base::CompareCase::INSENSITIVE_ASCII) ||
base::EndsWith(email, "@google.com", base::EndsWith(email, "@google.com",
base::CompareCase::INSENSITIVE_ASCII)) { base::CompareCase::INSENSITIVE_ASCII)) {
account_supported = true; account_supported = true;
......
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "chrome/browser/chromeos/login/demo_mode/demo_session.h" #include "chrome/browser/chromeos/login/demo_mode/demo_session.h"
#include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/signin/identity_test_environment_profile_adaptor.h"
#include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h" #include "chrome/test/base/testing_profile_manager.h"
...@@ -18,6 +20,9 @@ ...@@ -18,6 +20,9 @@
#include "components/account_id/account_id.h" #include "components/account_id/account_id.h"
#include "components/language/core/browser/pref_names.h" #include "components/language/core/browser/pref_names.h"
#include "components/prefs/testing_pref_service.h" #include "components/prefs/testing_pref_service.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "components/signin/public/identity_manager/identity_test_environment.h"
#include "components/signin/public/identity_manager/identity_test_utils.h"
#include "components/sync_preferences/testing_pref_service_syncable.h" #include "components/sync_preferences/testing_pref_service_syncable.h"
#include "components/user_manager/scoped_user_manager.h" #include "components/user_manager/scoped_user_manager.h"
#include "components/user_manager/user_manager.h" #include "components/user_manager/user_manager.h"
...@@ -64,9 +69,13 @@ class ScopedLogIn { ...@@ -64,9 +69,13 @@ class ScopedLogIn {
public: public:
ScopedLogIn( ScopedLogIn(
FakeUserManagerWithLocalState* fake_user_manager, FakeUserManagerWithLocalState* fake_user_manager,
signin::IdentityTestEnvironment* identity_test_env,
const AccountId& account_id, const AccountId& account_id,
user_manager::UserType user_type = user_manager::USER_TYPE_REGULAR) user_manager::UserType user_type = user_manager::USER_TYPE_REGULAR)
: fake_user_manager_(fake_user_manager), account_id_(account_id) { : fake_user_manager_(fake_user_manager),
identity_test_env_(identity_test_env),
account_id_(account_id) {
// Prevent access to DBus. This switch is reset in case set from test SetUp // Prevent access to DBus. This switch is reset in case set from test SetUp
// due massive usage of InitFromArgv. // due massive usage of InitFromArgv.
base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess(); base::CommandLine& command_line = *base::CommandLine::ForCurrentProcess();
...@@ -102,6 +111,10 @@ class ScopedLogIn { ...@@ -102,6 +111,10 @@ class ScopedLogIn {
void LogIn() { void LogIn() {
fake_user_manager_->AddUser(account_id_); fake_user_manager_->AddUser(account_id_);
fake_user_manager_->LoginUser(account_id_); fake_user_manager_->LoginUser(account_id_);
if (!identity_test_env_->identity_manager()->HasPrimaryAccount()) {
identity_test_env_->MakePrimaryAccountAvailable(
account_id_.GetUserEmail());
}
} }
void LogInAsPublicAccount() { void LogInAsPublicAccount() {
...@@ -122,6 +135,7 @@ class ScopedLogIn { ...@@ -122,6 +135,7 @@ class ScopedLogIn {
void LogOut() { fake_user_manager_->RemoveUserFromList(account_id_); } void LogOut() { fake_user_manager_->RemoveUserFromList(account_id_); }
FakeUserManagerWithLocalState* fake_user_manager_; FakeUserManagerWithLocalState* fake_user_manager_;
signin::IdentityTestEnvironment* identity_test_env_;
const AccountId account_id_; const AccountId account_id_;
DISALLOW_COPY_AND_ASSIGN(ScopedLogIn); DISALLOW_COPY_AND_ASSIGN(ScopedLogIn);
...@@ -143,43 +157,44 @@ class ChromeAssistantUtilTest : public testing::Test { ...@@ -143,43 +157,44 @@ class ChromeAssistantUtilTest : public testing::Test {
TestingBrowserProcess::GetGlobal()); TestingBrowserProcess::GetGlobal());
ASSERT_TRUE(profile_manager_->SetUp()); ASSERT_TRUE(profile_manager_->SetUp());
profile_ = profile_manager_->CreateTestingProfile(kTestProfileName);
identity_test_env_adaptor_ =
std::make_unique<IdentityTestEnvironmentProfileAdaptor>(profile_);
user_manager_enabler_ = std::make_unique<user_manager::ScopedUserManager>( user_manager_enabler_ = std::make_unique<user_manager::ScopedUserManager>(
std::make_unique<FakeUserManagerWithLocalState>( std::make_unique<FakeUserManagerWithLocalState>(
profile_manager_.get())); profile_manager_.get()));
ui::DeviceDataManager::CreateInstance(); ui::DeviceDataManager::CreateInstance();
profile_ = profile_manager_->CreateTestingProfile(kTestProfileName);
} }
void TearDown() override { void TearDown() override {
ui::DeviceDataManager::DeleteInstance(); ui::DeviceDataManager::DeleteInstance();
identity_test_env_adaptor_.reset();
user_manager_enabler_.reset();
profile_manager_->DeleteTestingProfile(kTestProfileName); profile_manager_->DeleteTestingProfile(kTestProfileName);
profile_ = nullptr; profile_ = nullptr;
user_manager_enabler_.reset();
profile_manager_.reset(); profile_manager_.reset();
command_line_.reset(); command_line_.reset();
} }
TestingProfile* profile() { return profile_; } TestingProfile* profile() { return profile_; }
signin::IdentityTestEnvironment* identity_test_env() {
return identity_test_env_adaptor_->identity_test_env();
}
FakeUserManagerWithLocalState* GetFakeUserManager() const { FakeUserManagerWithLocalState* GetFakeUserManager() const {
return static_cast<FakeUserManagerWithLocalState*>( return static_cast<FakeUserManagerWithLocalState*>(
user_manager::UserManager::Get()); user_manager::UserManager::Get());
} }
void LogIn() {
const auto account_id = AccountId::FromUserEmailGaiaId(
profile()->GetProfileUserName(), kTestGaiaId);
GetFakeUserManager()->AddUser(account_id);
GetFakeUserManager()->LoginUser(account_id);
}
private: private:
std::unique_ptr<base::test::ScopedCommandLine> command_line_; std::unique_ptr<base::test::ScopedCommandLine> command_line_;
base::test::ScopedFeatureList feature_list_; base::test::ScopedFeatureList feature_list_;
content::TestBrowserThreadBundle thread_bundle_; content::TestBrowserThreadBundle thread_bundle_;
base::ScopedTempDir data_dir_; base::ScopedTempDir data_dir_;
std::unique_ptr<IdentityTestEnvironmentProfileAdaptor>
identity_test_env_adaptor_;
std::unique_ptr<TestingProfileManager> profile_manager_; std::unique_ptr<TestingProfileManager> profile_manager_;
std::unique_ptr<user_manager::ScopedUserManager> user_manager_enabler_; std::unique_ptr<user_manager::ScopedUserManager> user_manager_enabler_;
// Owned by |profile_manager_| // Owned by |profile_manager_|
...@@ -190,9 +205,9 @@ class ChromeAssistantUtilTest : public testing::Test { ...@@ -190,9 +205,9 @@ class ChromeAssistantUtilTest : public testing::Test {
TEST_F(ChromeAssistantUtilTest, IsAssistantAllowedForProfile_SecondaryUser) { TEST_F(ChromeAssistantUtilTest, IsAssistantAllowedForProfile_SecondaryUser) {
ScopedLogIn login2( ScopedLogIn login2(
GetFakeUserManager(), GetFakeUserManager(), identity_test_env(),
AccountId::FromUserEmailGaiaId("user2@gmail.com", "0123456789")); AccountId::FromUserEmailGaiaId("user2@gmail.com", "0123456789"));
ScopedLogIn login(GetFakeUserManager(), ScopedLogIn login(GetFakeUserManager(), identity_test_env(),
AccountId::FromUserEmailGaiaId( AccountId::FromUserEmailGaiaId(
profile()->GetProfileUserName(), kTestGaiaId)); profile()->GetProfileUserName(), kTestGaiaId));
...@@ -201,7 +216,7 @@ TEST_F(ChromeAssistantUtilTest, IsAssistantAllowedForProfile_SecondaryUser) { ...@@ -201,7 +216,7 @@ TEST_F(ChromeAssistantUtilTest, IsAssistantAllowedForProfile_SecondaryUser) {
} }
TEST_F(ChromeAssistantUtilTest, IsAssistantAllowedForProfile_SupervisedUser) { TEST_F(ChromeAssistantUtilTest, IsAssistantAllowedForProfile_SupervisedUser) {
ScopedLogIn login(GetFakeUserManager(), ScopedLogIn login(GetFakeUserManager(), identity_test_env(),
AccountId::FromUserEmailGaiaId( AccountId::FromUserEmailGaiaId(
profile()->GetProfileUserName(), kTestGaiaId)); profile()->GetProfileUserName(), kTestGaiaId));
profile()->SetSupervisedUserId("foo"); profile()->SetSupervisedUserId("foo");
...@@ -215,7 +230,7 @@ TEST_F(ChromeAssistantUtilTest, IsAssistantAllowedForProfile_Locale) { ...@@ -215,7 +230,7 @@ TEST_F(ChromeAssistantUtilTest, IsAssistantAllowedForProfile_Locale) {
UErrorCode error_code = U_ZERO_ERROR; UErrorCode error_code = U_ZERO_ERROR;
const icu::Locale& old_locale = icu::Locale::getDefault(); const icu::Locale& old_locale = icu::Locale::getDefault();
icu::Locale::setDefault(icu::Locale("he"), error_code); icu::Locale::setDefault(icu::Locale("he"), error_code);
ScopedLogIn login(GetFakeUserManager(), ScopedLogIn login(GetFakeUserManager(), identity_test_env(),
AccountId::FromUserEmailGaiaId( AccountId::FromUserEmailGaiaId(
profile()->GetProfileUserName(), kTestGaiaId)); profile()->GetProfileUserName(), kTestGaiaId));
...@@ -227,7 +242,7 @@ TEST_F(ChromeAssistantUtilTest, IsAssistantAllowedForProfile_Locale) { ...@@ -227,7 +242,7 @@ TEST_F(ChromeAssistantUtilTest, IsAssistantAllowedForProfile_Locale) {
TEST_F(ChromeAssistantUtilTest, IsAssistantAllowedForProfile_DemoMode) { TEST_F(ChromeAssistantUtilTest, IsAssistantAllowedForProfile_DemoMode) {
chromeos::DemoSession::SetDemoConfigForTesting( chromeos::DemoSession::SetDemoConfigForTesting(
chromeos::DemoSession::DemoModeConfig::kOnline); chromeos::DemoSession::DemoModeConfig::kOnline);
ScopedLogIn login(GetFakeUserManager(), ScopedLogIn login(GetFakeUserManager(), identity_test_env(),
AccountId::FromUserEmail(profile()->GetProfileUserName()), AccountId::FromUserEmail(profile()->GetProfileUserName()),
user_manager::USER_TYPE_PUBLIC_ACCOUNT); user_manager::USER_TYPE_PUBLIC_ACCOUNT);
EXPECT_EQ(ash::mojom::AssistantAllowedState::DISALLOWED_BY_DEMO_MODE, EXPECT_EQ(ash::mojom::AssistantAllowedState::DISALLOWED_BY_DEMO_MODE,
...@@ -238,7 +253,7 @@ TEST_F(ChromeAssistantUtilTest, IsAssistantAllowedForProfile_DemoMode) { ...@@ -238,7 +253,7 @@ TEST_F(ChromeAssistantUtilTest, IsAssistantAllowedForProfile_DemoMode) {
} }
TEST_F(ChromeAssistantUtilTest, IsAssistantAllowedForProfile_PublicSession) { TEST_F(ChromeAssistantUtilTest, IsAssistantAllowedForProfile_PublicSession) {
ScopedLogIn login(GetFakeUserManager(), ScopedLogIn login(GetFakeUserManager(), identity_test_env(),
AccountId::FromUserEmail(profile()->GetProfileUserName()), AccountId::FromUserEmail(profile()->GetProfileUserName()),
user_manager::USER_TYPE_PUBLIC_ACCOUNT); user_manager::USER_TYPE_PUBLIC_ACCOUNT);
EXPECT_EQ(ash::mojom::AssistantAllowedState::DISALLOWED_BY_PUBLIC_SESSION, EXPECT_EQ(ash::mojom::AssistantAllowedState::DISALLOWED_BY_PUBLIC_SESSION,
...@@ -246,7 +261,7 @@ TEST_F(ChromeAssistantUtilTest, IsAssistantAllowedForProfile_PublicSession) { ...@@ -246,7 +261,7 @@ TEST_F(ChromeAssistantUtilTest, IsAssistantAllowedForProfile_PublicSession) {
} }
TEST_F(ChromeAssistantUtilTest, IsAssistantAllowedForProfile_NonGmail) { TEST_F(ChromeAssistantUtilTest, IsAssistantAllowedForProfile_NonGmail) {
ScopedLogIn login(GetFakeUserManager(), ScopedLogIn login(GetFakeUserManager(), identity_test_env(),
AccountId::FromUserEmailGaiaId("user2@someotherdomain.com", AccountId::FromUserEmailGaiaId("user2@someotherdomain.com",
"0123456789")); "0123456789"));
...@@ -254,8 +269,17 @@ TEST_F(ChromeAssistantUtilTest, IsAssistantAllowedForProfile_NonGmail) { ...@@ -254,8 +269,17 @@ TEST_F(ChromeAssistantUtilTest, IsAssistantAllowedForProfile_NonGmail) {
IsAssistantAllowedForProfile(profile())); IsAssistantAllowedForProfile(profile()));
} }
TEST_F(ChromeAssistantUtilTest, IsAssistantAllowedForProfile_GoogleMail) {
ScopedLogIn login(
GetFakeUserManager(), identity_test_env(),
AccountId::FromUserEmailGaiaId("user2@googlemail.com", "0123456789"));
EXPECT_EQ(ash::mojom::AssistantAllowedState::ALLOWED,
IsAssistantAllowedForProfile(profile()));
}
TEST_F(ChromeAssistantUtilTest, IsAssistantAllowedForKiosk_KioskApp) { TEST_F(ChromeAssistantUtilTest, IsAssistantAllowedForKiosk_KioskApp) {
ScopedLogIn login(GetFakeUserManager(), ScopedLogIn login(GetFakeUserManager(), identity_test_env(),
AccountId::FromUserEmail(profile()->GetProfileUserName()), AccountId::FromUserEmail(profile()->GetProfileUserName()),
user_manager::USER_TYPE_KIOSK_APP); user_manager::USER_TYPE_KIOSK_APP);
...@@ -264,7 +288,7 @@ TEST_F(ChromeAssistantUtilTest, IsAssistantAllowedForKiosk_KioskApp) { ...@@ -264,7 +288,7 @@ TEST_F(ChromeAssistantUtilTest, IsAssistantAllowedForKiosk_KioskApp) {
} }
TEST_F(ChromeAssistantUtilTest, IsAssistantAllowedForKiosk_ArcKioskApp) { TEST_F(ChromeAssistantUtilTest, IsAssistantAllowedForKiosk_ArcKioskApp) {
ScopedLogIn login(GetFakeUserManager(), ScopedLogIn login(GetFakeUserManager(), identity_test_env(),
AccountId::FromUserEmail(profile()->GetProfileUserName()), AccountId::FromUserEmail(profile()->GetProfileUserName()),
user_manager::USER_TYPE_ARC_KIOSK_APP); user_manager::USER_TYPE_ARC_KIOSK_APP);
......
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