Commit 615297f1 authored by antrim@chromium.org's avatar antrim@chromium.org

Tests for supervised users password sync:

First two test cases:
  password change detected when SU is signed in, only su is signed in after
  password change is detected when manager is signed in.

R=nkostylev@chromium.org

BUG=354607

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266892 0039d316-1c4b-4281-b951-d872f2087c98
parent e33e7118
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <string>
#include "base/compiler_specific.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/sequenced_worker_pool.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/login/login_display_host_impl.h"
#include "chrome/browser/chromeos/login/login_manager_test.h"
#include "chrome/browser/chromeos/login/managed/managed_user_test_base.h"
#include "chrome/browser/chromeos/login/managed/supervised_user_authentication.h"
#include "chrome/browser/chromeos/login/startup_utils.h"
#include "chrome/browser/chromeos/login/supervised_user_manager.h"
#include "chrome/browser/chromeos/login/webui_login_view.h"
#include "chrome/browser/chromeos/net/network_portal_detector_test_impl.h"
#include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h"
#include "chrome/browser/managed_mode/managed_user_constants.h"
#include "chrome/browser/managed_mode/managed_user_registration_utility.h"
#include "chrome/browser/managed_mode/managed_user_registration_utility_stub.h"
#include "chrome/browser/managed_mode/managed_user_shared_settings_service.h"
#include "chrome/browser/managed_mode/managed_user_shared_settings_service_factory.h"
#include "chrome/browser/managed_mode/managed_user_sync_service.h"
#include "chrome/browser/managed_mode/managed_user_sync_service_factory.h"
#include "chromeos/cryptohome/mock_async_method_caller.h"
#include "chromeos/cryptohome/mock_homedir_methods.h"
#include "content/public/browser/notification_service.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "sync/api/attachments/attachment_service_proxy_for_test.h"
#include "sync/api/fake_sync_change_processor.h"
#include "sync/api/sync_change.h"
#include "sync/api/sync_error_factory_mock.h"
#include "sync/protocol/sync.pb.h"
using testing::_;
using chromeos::testing::ManagedUserTestBase;
using chromeos::testing::kTestSupervisedUserDisplayName;
using chromeos::testing::kTestManager;
namespace chromeos {
class SupervisedUserCreationTest : public ManagedUserTestBase {
public:
SupervisedUserCreationTest() : ManagedUserTestBase() {}
private:
DISALLOW_COPY_AND_ASSIGN(SupervisedUserCreationTest);
};
class SupervisedUserTransactionCleanupTest : public ManagedUserTestBase {
public:
SupervisedUserTransactionCleanupTest() : ManagedUserTestBase() {}
private:
DISALLOW_COPY_AND_ASSIGN(SupervisedUserTransactionCleanupTest);
};
class SupervisedUserOwnerCreationTest : public ManagedUserTestBase {
public:
SupervisedUserOwnerCreationTest() : ManagedUserTestBase() {}
virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
ManagedUserTestBase::SetUpInProcessBrowserTestFixture();
cros_settings_provider_.reset(new StubCrosSettingsProvider());
cros_settings_provider_->Set(kDeviceOwner, base::StringValue(kTestManager));
}
private:
scoped_ptr<StubCrosSettingsProvider> cros_settings_provider_;
DISALLOW_COPY_AND_ASSIGN(SupervisedUserOwnerCreationTest);
};
class SupervisedUserTransactionCleanupTest2
: public SupervisedUserTransactionCleanupTest {
public:
SupervisedUserTransactionCleanupTest2()
: SupervisedUserTransactionCleanupTest() {}
virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
SupervisedUserTransactionCleanupTest::SetUpInProcessBrowserTestFixture();
EXPECT_CALL(*mock_async_method_caller_, AsyncRemove(_, _)).Times(1);
}
private:
DISALLOW_COPY_AND_ASSIGN(SupervisedUserTransactionCleanupTest2);
};
IN_PROC_BROWSER_TEST_F(SupervisedUserCreationTest,
PRE_PRE_PRE_CreateAndRemoveSupervisedUser) {
PrepareUsers();
}
IN_PROC_BROWSER_TEST_F(SupervisedUserCreationTest,
PRE_PRE_CreateAndRemoveSupervisedUser) {
StartFlowLoginAsManager();
FillNewUserData(kTestSupervisedUserDisplayName);
StartUserCreation("managed-user-creation-next-button",
kTestSupervisedUserDisplayName);
}
IN_PROC_BROWSER_TEST_F(SupervisedUserCreationTest,
PRE_CreateAndRemoveSupervisedUser) {
SigninAsSupervisedUser(true, 0, kTestSupervisedUserDisplayName);
}
IN_PROC_BROWSER_TEST_F(SupervisedUserCreationTest,
CreateAndRemoveSupervisedUser) {
RemoveSupervisedUser(3, 0, kTestSupervisedUserDisplayName);
}
IN_PROC_BROWSER_TEST_F(SupervisedUserOwnerCreationTest,
PRE_PRE_PRE_CreateAndRemoveSupervisedUser) {
PrepareUsers();
}
IN_PROC_BROWSER_TEST_F(SupervisedUserOwnerCreationTest,
PRE_PRE_CreateAndRemoveSupervisedUser) {
StartFlowLoginAsManager();
FillNewUserData(kTestSupervisedUserDisplayName);
StartUserCreation("managed-user-creation-next-button",
kTestSupervisedUserDisplayName);
}
IN_PROC_BROWSER_TEST_F(SupervisedUserOwnerCreationTest,
PRE_CreateAndRemoveSupervisedUser) {
SigninAsSupervisedUser(true, 0, kTestSupervisedUserDisplayName);
}
IN_PROC_BROWSER_TEST_F(SupervisedUserOwnerCreationTest,
CreateAndRemoveSupervisedUser) {
RemoveSupervisedUser(3, 0, kTestSupervisedUserDisplayName);
}
IN_PROC_BROWSER_TEST_F(SupervisedUserTransactionCleanupTest,
PRE_PRE_CreateAndCancelSupervisedUser) {
PrepareUsers();
}
IN_PROC_BROWSER_TEST_F(SupervisedUserTransactionCleanupTest,
PRE_CreateAndCancelSupervisedUser) {
StartFlowLoginAsManager();
FillNewUserData(kTestSupervisedUserDisplayName);
EXPECT_CALL(*mock_homedir_methods_, MountEx(_, _, _, _)).Times(1);
EXPECT_CALL(*mock_homedir_methods_, AddKeyEx(_, _, _, _, _)).Times(1);
JSEval("$('managed-user-creation-next-button').click()");
::testing::Mock::VerifyAndClearExpectations(mock_homedir_methods_);
EXPECT_TRUE(registration_utility_stub_->register_was_called());
EXPECT_EQ(registration_utility_stub_->display_name(),
base::UTF8ToUTF16(kTestSupervisedUserDisplayName));
std::string user_id = registration_utility_stub_->managed_user_id();
// Make sure user is already in list.
ASSERT_EQ(3UL, UserManager::Get()->GetUsers().size());
// We wait for token now. Press cancel button at this point.
JSEval("$('cancel-add-user-button').click()");
}
IN_PROC_BROWSER_TEST_(
SupervisedUserTransactionCleanupTest,
CreateAndCancelSupervisedUser,
SupervisedUserTransactionCleanupTest2,
::testing::internal::GetTypeId<SupervisedUserTransactionCleanupTest>()) {
// Make sure there is no supervised user in list.
ASSERT_EQ(2UL, UserManager::Get()->GetUsers().size());
}
} // namespace chromeos
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <string>
#include "base/compiler_specific.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/sequenced_worker_pool.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/login/login_display_host_impl.h"
#include "chrome/browser/chromeos/login/login_manager_test.h"
#include "chrome/browser/chromeos/login/managed/managed_user_test_base.h"
#include "chrome/browser/chromeos/login/managed/supervised_user_authentication.h"
#include "chrome/browser/chromeos/login/startup_utils.h"
#include "chrome/browser/chromeos/login/supervised_user_manager.h"
#include "chrome/browser/chromeos/login/webui_login_view.h"
#include "chrome/browser/chromeos/net/network_portal_detector_test_impl.h"
#include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h"
#include "chrome/browser/managed_mode/managed_user_constants.h"
#include "chrome/browser/managed_mode/managed_user_registration_utility.h"
#include "chrome/browser/managed_mode/managed_user_registration_utility_stub.h"
#include "chrome/browser/managed_mode/managed_user_shared_settings_service.h"
#include "chrome/browser/managed_mode/managed_user_shared_settings_service_factory.h"
#include "chrome/browser/managed_mode/managed_user_sync_service.h"
#include "chrome/browser/managed_mode/managed_user_sync_service_factory.h"
#include "chromeos/cryptohome/mock_async_method_caller.h"
#include "chromeos/cryptohome/mock_homedir_methods.h"
#include "content/public/browser/notification_service.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "sync/api/attachments/attachment_service_proxy_for_test.h"
#include "sync/api/fake_sync_change_processor.h"
#include "sync/api/sync_change.h"
#include "sync/api/sync_error_factory_mock.h"
#include "sync/protocol/sync.pb.h"
using testing::_;
using chromeos::testing::ManagedUserTestBase;
using chromeos::testing::kTestSupervisedUserDisplayName;
using chromeos::testing::kTestManager;
namespace chromeos {
class SupervisedUserPasswordTest : public ManagedUserTestBase {
public:
SupervisedUserPasswordTest() : ManagedUserTestBase() {}
private:
DISALLOW_COPY_AND_ASSIGN(SupervisedUserPasswordTest);
};
class SupervisedUserPasswordManagerTest : public ManagedUserTestBase {
public:
SupervisedUserPasswordManagerTest() : ManagedUserTestBase() {}
private:
DISALLOW_COPY_AND_ASSIGN(SupervisedUserPasswordManagerTest);
};
IN_PROC_BROWSER_TEST_F(SupervisedUserPasswordTest,
PRE_PRE_PRE_PasswordChangeFromUserTest) {
PrepareUsers();
}
IN_PROC_BROWSER_TEST_F(SupervisedUserPasswordTest,
PRE_PRE_PasswordChangeFromUserTest) {
StartFlowLoginAsManager();
FillNewUserData(kTestSupervisedUserDisplayName);
StartUserCreation("managed-user-creation-next-button",
kTestSupervisedUserDisplayName);
}
// Supervised user signs in, get sync notification about password update, and
// schedules password migration.
IN_PROC_BROWSER_TEST_F(SupervisedUserPasswordTest,
PRE_PasswordChangeFromUserTest) {
SigninAsSupervisedUser(true, 0, kTestSupervisedUserDisplayName);
const User* user = UserManager::Get()->GetUsers().at(0);
std::string sync_id =
UserManager::Get()->GetSupervisedUserManager()->GetUserSyncId(
user->email());
base::DictionaryValue password;
password.SetIntegerWithoutPathExpansion(
kSchemaVersion, SupervisedUserAuthentication::SCHEMA_SALT_HASHED);
password.SetIntegerWithoutPathExpansion(kPasswordRevision, 2);
password.SetStringWithoutPathExpansion(kPasswordSignature, "signature");
password.SetStringWithoutPathExpansion(kEncryptedPassword,
"new-encrypted-password");
shared_settings_adapter_->AddChange(
sync_id, managed_users::kChromeOSPasswordData, password, true, false);
content::RunAllPendingInMessageLoop();
}
// Supervised user signs in for second time, and actual password migration takes
// place.
IN_PROC_BROWSER_TEST_F(SupervisedUserPasswordTest, PasswordChangeFromUserTest) {
EXPECT_CALL(*mock_homedir_methods_, MountEx(_, _, _, _)).Times(1);
EXPECT_CALL(*mock_homedir_methods_, UpdateKeyEx(_, _, _, _, _)).Times(1);
SigninAsSupervisedUser(false, 0, kTestSupervisedUserDisplayName);
::testing::Mock::VerifyAndClearExpectations(mock_homedir_methods_);
}
IN_PROC_BROWSER_TEST_F(SupervisedUserPasswordTest,
PRE_PRE_PRE_PasswordChangeFromManagerTest) {
PrepareUsers();
}
IN_PROC_BROWSER_TEST_F(SupervisedUserPasswordTest,
PRE_PRE_PasswordChangeFromManagerTest) {
StartFlowLoginAsManager();
FillNewUserData(kTestSupervisedUserDisplayName);
StartUserCreation("managed-user-creation-next-button",
kTestSupervisedUserDisplayName);
}
// Manager signs in, gets sync notification about supervised user password
// update, and performs migration.
IN_PROC_BROWSER_TEST_F(SupervisedUserPasswordTest,
PRE_PasswordChangeFromManagerTest) {
const User* managed_user = UserManager::Get()->GetUsers().at(0);
SigninAsManager(1);
EXPECT_CALL(*mock_homedir_methods_, AddKeyEx(_, _, _, _, _)).Times(1);
std::string sync_id =
UserManager::Get()->GetSupervisedUserManager()->GetUserSyncId(
managed_user->email());
::sync_pb::ManagedUserSpecifics managed_user_proto;
managed_user_proto.set_id(sync_id);
managed_user_proto.set_name(kTestSupervisedUserDisplayName);
managed_user_proto.set_acknowledged(true);
managed_user_proto.set_master_key("master key");
managed_user_proto.set_password_signature_key("signature_key");
managed_user_proto.set_password_encryption_key("encryption_key");
managed_users_adapter_->AddChange(managed_user_proto, false);
content::RunAllPendingInMessageLoop();
base::DictionaryValue password;
password.SetIntegerWithoutPathExpansion(
kSchemaVersion, SupervisedUserAuthentication::SCHEMA_SALT_HASHED);
password.SetIntegerWithoutPathExpansion(kPasswordRevision, 2);
password.SetStringWithoutPathExpansion(kPasswordSignature, "signature");
password.SetStringWithoutPathExpansion(kEncryptedPassword,
"new-encrypted-password");
shared_settings_adapter_->AddChange(
sync_id, managed_users::kChromeOSPasswordData, password, true, false);
content::RunAllPendingInMessageLoop();
::testing::Mock::VerifyAndClearExpectations(mock_homedir_methods_);
}
// After that supervised user signs in, and no password change happens.
IN_PROC_BROWSER_TEST_F(SupervisedUserPasswordTest,
PasswordChangeFromManagerTest) {
EXPECT_CALL(*mock_homedir_methods_, MountEx(_, _, _, _)).Times(1);
EXPECT_CALL(*mock_homedir_methods_, UpdateKeyEx(_, _, _, _, _)).Times(0);
SigninAsSupervisedUser(false, 1, kTestSupervisedUserDisplayName);
::testing::Mock::VerifyAndClearExpectations(mock_homedir_methods_);
}
IN_PROC_BROWSER_TEST_F(SupervisedUserPasswordTest,
PRE_PRE_PRE_PRE_PasswordChangeUserAndManagerTest) {
PrepareUsers();
}
IN_PROC_BROWSER_TEST_F(SupervisedUserPasswordTest,
PRE_PRE_PRE_PasswordChangeUserAndManagerTest) {
StartFlowLoginAsManager();
FillNewUserData(kTestSupervisedUserDisplayName);
StartUserCreation("managed-user-creation-next-button",
kTestSupervisedUserDisplayName);
}
// Supervised user signs in, get sync notification about password update, and
// schedules password migration.
IN_PROC_BROWSER_TEST_F(SupervisedUserPasswordTest,
PRE_PRE_PasswordChangeUserAndManagerTest) {
SigninAsSupervisedUser(true, 0, kTestSupervisedUserDisplayName);
const User* user = UserManager::Get()->GetUsers().at(0);
std::string sync_id =
UserManager::Get()->GetSupervisedUserManager()->GetUserSyncId(
user->email());
base::DictionaryValue password;
password.SetIntegerWithoutPathExpansion(
kSchemaVersion, SupervisedUserAuthentication::SCHEMA_SALT_HASHED);
password.SetIntegerWithoutPathExpansion(kPasswordRevision, 2);
password.SetStringWithoutPathExpansion(kPasswordSignature, "signature");
password.SetStringWithoutPathExpansion(kEncryptedPassword,
"new-encrypted-password");
shared_settings_adapter_->AddChange(
sync_id, managed_users::kChromeOSPasswordData, password, true, false);
content::RunAllPendingInMessageLoop();
}
// After that manager signs in, and also detects password change. Manager
// performs the migration.
IN_PROC_BROWSER_TEST_F(SupervisedUserPasswordTest,
PRE_PasswordChangeUserAndManagerTest) {
const User* managed_user = UserManager::Get()->GetUsers().at(0);
SigninAsManager(1);
EXPECT_CALL(*mock_homedir_methods_, AddKeyEx(_, _, _, _, _)).Times(1);
std::string sync_id =
UserManager::Get()->GetSupervisedUserManager()->GetUserSyncId(
managed_user->email());
::sync_pb::ManagedUserSpecifics managed_user_proto;
managed_user_proto.set_id(sync_id);
managed_user_proto.set_name(kTestSupervisedUserDisplayName);
managed_user_proto.set_acknowledged(true);
managed_user_proto.set_master_key("master key");
managed_user_proto.set_password_signature_key("signature_key");
managed_user_proto.set_password_encryption_key("encryption_key");
managed_users_adapter_->AddChange(managed_user_proto, false);
content::RunAllPendingInMessageLoop();
base::DictionaryValue password;
password.SetIntegerWithoutPathExpansion(
kSchemaVersion, SupervisedUserAuthentication::SCHEMA_SALT_HASHED);
password.SetIntegerWithoutPathExpansion(kPasswordRevision, 2);
password.SetStringWithoutPathExpansion(kPasswordSignature, "signature");
password.SetStringWithoutPathExpansion(kEncryptedPassword,
"new-encrypted-password");
shared_settings_adapter_->AddChange(
sync_id, managed_users::kChromeOSPasswordData, password, true, false);
content::RunAllPendingInMessageLoop();
::testing::Mock::VerifyAndClearExpectations(mock_homedir_methods_);
}
// When supervised user signs in, password is already migrated, so no migration
// should be attempted.
IN_PROC_BROWSER_TEST_F(SupervisedUserPasswordTest,
PasswordChangeUserAndManagerTest) {
EXPECT_CALL(*mock_homedir_methods_, MountEx(_, _, _, _)).Times(1);
EXPECT_CALL(*mock_homedir_methods_, UpdateKeyEx(_, _, _, _, _)).Times(0);
SigninAsSupervisedUser(false, 1, kTestSupervisedUserDisplayName);
::testing::Mock::VerifyAndClearExpectations(mock_homedir_methods_);
}
} // namespace chromeos
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/login/managed/managed_user_test_base.h"
#include <string>
#include "base/compiler_specific.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/sequenced_worker_pool.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/login/login_display_host_impl.h"
#include "chrome/browser/chromeos/login/login_manager_test.h"
#include "chrome/browser/chromeos/login/managed/supervised_user_authentication.h"
#include "chrome/browser/chromeos/login/startup_utils.h"
#include "chrome/browser/chromeos/login/supervised_user_manager.h"
#include "chrome/browser/chromeos/login/webui_login_view.h"
#include "chrome/browser/chromeos/net/network_portal_detector_test_impl.h"
#include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h"
#include "chrome/browser/managed_mode/managed_user_constants.h"
#include "chrome/browser/managed_mode/managed_user_registration_utility.h"
#include "chrome/browser/managed_mode/managed_user_registration_utility_stub.h"
#include "chrome/browser/managed_mode/managed_user_shared_settings_service.h"
#include "chrome/browser/managed_mode/managed_user_shared_settings_service_factory.h"
#include "chrome/browser/managed_mode/managed_user_sync_service.h"
#include "chrome/browser/managed_mode/managed_user_sync_service_factory.h"
#include "chromeos/cryptohome/mock_async_method_caller.h"
#include "chromeos/cryptohome/mock_homedir_methods.h"
#include "content/public/browser/notification_service.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "sync/api/attachments/attachment_service_proxy_for_test.h"
#include "sync/api/fake_sync_change_processor.h"
#include "sync/api/sync_change.h"
#include "sync/api/sync_error_factory_mock.h"
#include "sync/protocol/sync.pb.h"
using testing::_;
using base::StringPrintf;
namespace chromeos {
namespace testing {
namespace {
const char kCurrentPage[] = "$('managed-user-creation').currentPage_";
}
ManagedUsersSyncTestAdapter::ManagedUsersSyncTestAdapter(Profile* profile)
: processor_(), next_sync_data_id_(0) {
service_ = ManagedUserSyncServiceFactory::GetForProfile(profile);
processor_ = new syncer::FakeSyncChangeProcessor();
service_->MergeDataAndStartSyncing(
syncer::MANAGED_USERS,
syncer::SyncDataList(),
scoped_ptr<syncer::SyncChangeProcessor>(processor_),
scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock));
}
scoped_ptr< ::sync_pb::ManagedUserSpecifics>
ManagedUsersSyncTestAdapter::GetFirstChange() {
scoped_ptr< ::sync_pb::ManagedUserSpecifics> result(
new ::sync_pb::ManagedUserSpecifics);
CHECK(HasChanges())
<< "GetFirstChange() should only be callled if HasChanges() is true";
const syncer::SyncData& data = processor_->changes().front().sync_data();
EXPECT_EQ(syncer::MANAGED_USERS, data.GetDataType());
result->CopyFrom(data.GetSpecifics().managed_user());
return result.Pass();
}
void ManagedUsersSyncTestAdapter::AddChange(
const ::sync_pb::ManagedUserSpecifics& proto,
bool update) {
sync_pb::EntitySpecifics specifics;
specifics.mutable_managed_user()->CopyFrom(proto);
syncer::SyncData change_data = syncer::SyncData::CreateRemoteData(
++next_sync_data_id_,
specifics,
base::Time(),
syncer::AttachmentIdList(),
syncer::AttachmentServiceProxyForTest::Create());
syncer::SyncChange change(FROM_HERE,
update ? syncer::SyncChange::ACTION_UPDATE
: syncer::SyncChange::ACTION_ADD,
change_data);
syncer::SyncChangeList change_list;
change_list.push_back(change);
service_->ProcessSyncChanges(FROM_HERE, change_list);
}
ManagedUsersSharedSettingsSyncTestAdapter::
ManagedUsersSharedSettingsSyncTestAdapter(Profile* profile)
: processor_(), next_sync_data_id_(0) {
service_ =
ManagedUserSharedSettingsServiceFactory::GetForBrowserContext(profile);
processor_ = new syncer::FakeSyncChangeProcessor();
service_->MergeDataAndStartSyncing(
syncer::MANAGED_USER_SHARED_SETTINGS,
syncer::SyncDataList(),
scoped_ptr<syncer::SyncChangeProcessor>(processor_),
scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock));
}
scoped_ptr< ::sync_pb::ManagedUserSharedSettingSpecifics>
ManagedUsersSharedSettingsSyncTestAdapter::GetFirstChange() {
scoped_ptr< ::sync_pb::ManagedUserSharedSettingSpecifics> result(
new ::sync_pb::ManagedUserSharedSettingSpecifics);
CHECK(HasChanges())
<< "GetFirstChange() should only be callled if HasChanges() is true";
const syncer::SyncData& data = processor_->changes().front().sync_data();
EXPECT_EQ(syncer::MANAGED_USER_SHARED_SETTINGS, data.GetDataType());
result->CopyFrom(data.GetSpecifics().managed_user_shared_setting());
return result.Pass();
}
void ManagedUsersSharedSettingsSyncTestAdapter::AddChange(
const ::sync_pb::ManagedUserSharedSettingSpecifics& proto,
bool update) {
sync_pb::EntitySpecifics specifics;
specifics.mutable_managed_user_shared_setting()->CopyFrom(proto);
syncer::SyncData change_data = syncer::SyncData::CreateRemoteData(
++next_sync_data_id_,
specifics,
base::Time(),
syncer::AttachmentIdList(),
syncer::AttachmentServiceProxyForTest::Create());
syncer::SyncChange change(FROM_HERE,
update ? syncer::SyncChange::ACTION_UPDATE
: syncer::SyncChange::ACTION_ADD,
change_data);
syncer::SyncChangeList change_list;
change_list.push_back(change);
service_->ProcessSyncChanges(FROM_HERE, change_list);
}
void ManagedUsersSharedSettingsSyncTestAdapter::AddChange(
const std::string& mu_id,
const std::string& key,
const base::Value& value,
bool acknowledged,
bool update) {
syncer::SyncData data =
ManagedUserSharedSettingsService::CreateSyncDataForSetting(
mu_id, key, value, acknowledged);
AddChange(data.GetSpecifics().managed_user_shared_setting(), update);
}
ManagedUserTestBase::ManagedUserTestBase()
: LoginManagerTest(true),
mock_async_method_caller_(NULL),
mock_homedir_methods_(NULL),
network_portal_detector_(NULL),
registration_utility_stub_(NULL) {
}
ManagedUserTestBase::~ManagedUserTestBase() {
}
void ManagedUserTestBase::SetUpInProcessBrowserTestFixture() {
LoginManagerTest::SetUpInProcessBrowserTestFixture();
mock_async_method_caller_ = new cryptohome::MockAsyncMethodCaller;
mock_async_method_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE);
cryptohome::AsyncMethodCaller::InitializeForTesting(
mock_async_method_caller_);
mock_homedir_methods_ = new cryptohome::MockHomedirMethods;
mock_homedir_methods_->SetUp(true, cryptohome::MOUNT_ERROR_NONE);
cryptohome::HomedirMethods::InitializeForTesting(mock_homedir_methods_);
registration_utility_stub_ = new ManagedUserRegistrationUtilityStub();
scoped_utility_.reset(new ScopedTestingManagedUserRegistrationUtility(
registration_utility_stub_));
// Setup network portal detector to return online state for both
// ethernet and wifi networks. Ethernet is an active network by
// default.
network_portal_detector_ = new NetworkPortalDetectorTestImpl();
NetworkPortalDetector::InitializeForTesting(network_portal_detector_);
NetworkPortalDetector::CaptivePortalState online_state;
online_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE;
online_state.response_code = 204;
network_portal_detector_->SetDefaultNetworkPathForTesting(
kStubEthernetServicePath);
network_portal_detector_->SetDetectionResultsForTesting(
kStubEthernetServicePath, online_state);
}
void ManagedUserTestBase::CleanUpOnMainThread() {
LoginManagerTest::CleanUpOnMainThread();
}
void ManagedUserTestBase::TearDown() {
cryptohome::AsyncMethodCaller::Shutdown();
cryptohome::HomedirMethods::Shutdown();
mock_homedir_methods_ = NULL;
mock_async_method_caller_ = NULL;
LoginManagerTest::TearDown();
}
void ManagedUserTestBase::TearDownInProcessBrowserTestFixture() {
NetworkPortalDetector::Shutdown();
}
void ManagedUserTestBase::JSEval(const std::string& script) {
EXPECT_TRUE(content::ExecuteScript(web_contents(), script));
}
void ManagedUserTestBase::JSExpectAsync(const std::string& function) {
bool result;
EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
web_contents(),
StringPrintf(
"(%s)(function() { window.domAutomationController.send(true); });",
function.c_str()),
&result));
EXPECT_TRUE(result);
}
void ManagedUserTestBase::JSSetTextField(const std::string& element_selector,
const std::string& value) {
std::string function =
StringPrintf("document.querySelector('%s').value = '%s'",
element_selector.c_str(),
value.c_str());
JSEval(function);
}
void ManagedUserTestBase::PrepareUsers() {
RegisterUser(kTestManager);
RegisterUser(kTestOtherUser);
chromeos::StartupUtils::MarkOobeCompleted();
}
void ManagedUserTestBase::StartFlowLoginAsManager() {
// Navigate to supervised user creation screen.
JSEval("chrome.send('showLocallyManagedUserCreationScreen')");
// Read intro and proceed.
JSExpect(StringPrintf("%s == 'intro'", kCurrentPage));
JSEval("$('managed-user-creation-start-button').click()");
// Check that both users appear as managers, and test-manager@gmail.com is
// the first one.
JSExpect(StringPrintf("%s == 'manager'", kCurrentPage));
std::string manager_pods =
"document.querySelectorAll('#managed-user-creation-managers-pane "
".manager-pod')";
std::string selected_manager_pods =
"document.querySelectorAll('#managed-user-creation-managers-pane "
".manager-pod.focused')";
int managers_on_device = 2;
JSExpect(StringPrintf("%s.length == 1", selected_manager_pods.c_str()));
JSExpect(
StringPrintf("$('managed-user-creation').managerList_.pods.length == %d",
managers_on_device));
JSExpect(StringPrintf(
"%s.length == %d", manager_pods.c_str(), managers_on_device));
JSExpect(StringPrintf("%s[%d].user.emailAddress == '%s'",
manager_pods.c_str(),
0,
kTestManager));
// Select the first user as manager, and enter password.
JSExpect("$('managed-user-creation-next-button').disabled");
JSSetTextField("#managed-user-creation .manager-pod.focused input",
kTestManagerPassword);
JSEval("$('managed-user-creation').updateNextButtonForManager_()");
// Next button is now enabled.
JSExpect("!$('managed-user-creation-next-button').disabled");
SetExpectedCredentials(kTestManager, kTestManagerPassword);
content::WindowedNotificationObserver login_observer(
chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED,
content::NotificationService::AllSources());
// Log in as manager.
JSEval("$('managed-user-creation-next-button').click()");
login_observer.Wait();
// OAuth token is valid.
UserManager::Get()->SaveUserOAuthStatus(kTestManager,
User::OAUTH2_TOKEN_STATUS_VALID);
base::RunLoop().RunUntilIdle();
// Check the page have changed.
JSExpect(StringPrintf("%s == 'username'", kCurrentPage));
}
void ManagedUserTestBase::FillNewUserData(const std::string& display_name) {
JSExpect("$('managed-user-creation-next-button').disabled");
JSSetTextField("#managed-user-creation-name", display_name);
JSEval("$('managed-user-creation').checkUserName_()");
base::RunLoop().RunUntilIdle();
JSSetTextField("#managed-user-creation-password",
kTestSupervisedUserPassword);
JSSetTextField("#managed-user-creation-password-confirm",
kTestSupervisedUserPassword);
JSEval("$('managed-user-creation').updateNextButtonForUser_()");
JSExpect("!$('managed-user-creation-next-button').disabled");
}
void ManagedUserTestBase::StartUserCreation(
const std::string& button_id,
const std::string& expected_display_name) {
EXPECT_CALL(*mock_homedir_methods_, MountEx(_, _, _, _)).Times(1);
EXPECT_CALL(*mock_homedir_methods_, AddKeyEx(_, _, _, _, _)).Times(1);
JSEval(std::string("$('").append(button_id).append("').click()"));
::testing::Mock::VerifyAndClearExpectations(mock_homedir_methods_);
EXPECT_TRUE(registration_utility_stub_->register_was_called());
EXPECT_EQ(registration_utility_stub_->display_name(),
base::UTF8ToUTF16(expected_display_name));
registration_utility_stub_->RunSuccessCallback("token");
// Token writing moves control to BlockingPool and back.
base::RunLoop().RunUntilIdle();
content::BrowserThread::GetBlockingPool()->FlushForTesting();
base::RunLoop().RunUntilIdle();
JSExpect(StringPrintf("%s == 'created'", kCurrentPage));
JSEval("$('managed-user-creation-gotit-button').click()");
}
void ManagedUserTestBase::SigninAsSupervisedUser(
bool check_homedir_calls,
int user_index,
const std::string& expected_display_name) {
if (check_homedir_calls)
EXPECT_CALL(*mock_homedir_methods_, MountEx(_, _, _, _)).Times(1);
// Log in as supervised user, make sure that everything works.
ASSERT_EQ(3UL, UserManager::Get()->GetUsers().size());
// Created supervised user have to be first in a list.
const User* user = UserManager::Get()->GetUsers().at(user_index);
ASSERT_EQ(base::UTF8ToUTF16(expected_display_name), user->display_name());
LoginUser(user->email());
if (check_homedir_calls)
::testing::Mock::VerifyAndClearExpectations(mock_homedir_methods_);
Profile* profile = UserManager::Get()->GetProfileByUser(user);
shared_settings_adapter_.reset(
new ManagedUsersSharedSettingsSyncTestAdapter(profile));
}
void ManagedUserTestBase::SigninAsManager(int user_index) {
// Log in as supervised user, make sure that everything works.
ASSERT_EQ(3UL, UserManager::Get()->GetUsers().size());
// Created supervised user have to be first in a list.
const User* user = UserManager::Get()->GetUsers().at(user_index);
LoginUser(user->email());
Profile* profile = UserManager::Get()->GetProfileByUser(user);
shared_settings_adapter_.reset(
new ManagedUsersSharedSettingsSyncTestAdapter(profile));
managed_users_adapter_.reset(new ManagedUsersSyncTestAdapter(profile));
}
void ManagedUserTestBase::RemoveSupervisedUser(
unsigned long original_user_count,
int user_index,
const std::string& expected_display_name) {
// Remove supervised user.
ASSERT_EQ(original_user_count, UserManager::Get()->GetUsers().size());
// Created supervised user have to be first in a list.
const User* user = UserManager::Get()->GetUsers().at(user_index);
ASSERT_EQ(base::UTF8ToUTF16(expected_display_name), user->display_name());
// Open pod menu.
JSExpect(
StringPrintf("!$('pod-row').pods[%d].isActionBoxMenuActive", user_index));
JSEval(StringPrintf(
"$('pod-row').pods[%d].querySelector('.action-box-button').click()",
user_index));
JSExpect(
StringPrintf("$('pod-row').pods[%d].isActionBoxMenuActive", user_index));
// Select "Remove user" element.
JSExpect(StringPrintf(
"$('pod-row').pods[%d].actionBoxRemoveUserWarningElement.hidden",
user_index));
JSEval(StringPrintf(
"$('pod-row').pods[%d].querySelector('.action-box-menu-remove').click()",
user_index));
JSExpect(StringPrintf(
"!$('pod-row').pods[%d].actionBoxRemoveUserWarningElement.hidden",
user_index));
EXPECT_CALL(*mock_async_method_caller_, AsyncRemove(_, _)).Times(1);
// Confirm deletion.
JSEval(StringPrintf(
"$('pod-row').pods[%d].querySelector('.remove-warning-button').click()",
user_index));
// Make sure there is no supervised user in list.
ASSERT_EQ(original_user_count - 1, UserManager::Get()->GetUsers().size());
}
} // namespace testing
} // namespace chromeos
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_MANAGED_MANAGED_USER_TEST_BASE_H_
#define CHROME_BROWSER_CHROMEOS_LOGIN_MANAGED_MANAGED_USER_TEST_BASE_H_
#include <string>
#include "base/compiler_specific.h"
#include "chrome/browser/chromeos/login/login_manager_test.h"
#include "chrome/browser/chromeos/net/network_portal_detector_test_impl.h"
#include "chrome/browser/managed_mode/managed_user_registration_utility_stub.h"
#include "chrome/browser/profiles/profile.h"
#include "chromeos/cryptohome/mock_async_method_caller.h"
#include "chromeos/cryptohome/mock_homedir_methods.h"
#include "sync/api/fake_sync_change_processor.h"
#include "sync/api/sync_change.h"
#include "sync/api/sync_error_factory_mock.h"
#include "sync/protocol/sync.pb.h"
namespace chromeos {
namespace testing {
const char kStubEthernetServicePath[] = "eth0";
const char kTestManager[] = "test-manager@gmail.com";
const char kTestOtherUser[] = "test-user@gmail.com";
const char kTestManagerPassword[] = "password";
const char kTestSupervisedUserDisplayName[] = "John Doe";
const char kTestSupervisedUserPassword[] = "simplepassword";
class ManagedUsersSyncTestAdapter {
public:
explicit ManagedUsersSyncTestAdapter(Profile* profile);
bool HasChanges() { return !processor_->changes().empty(); }
scoped_ptr< ::sync_pb::ManagedUserSpecifics> GetFirstChange();
void AddChange(const ::sync_pb::ManagedUserSpecifics& proto, bool update);
syncer::FakeSyncChangeProcessor* processor_;
ManagedUserSyncService* service_;
int next_sync_data_id_;
};
class ManagedUsersSharedSettingsSyncTestAdapter {
public:
explicit ManagedUsersSharedSettingsSyncTestAdapter(Profile* profile);
bool HasChanges() { return !processor_->changes().empty(); }
scoped_ptr< ::sync_pb::ManagedUserSharedSettingSpecifics> GetFirstChange();
void AddChange(const ::sync_pb::ManagedUserSharedSettingSpecifics& proto,
bool update);
void AddChange(const std::string& mu_id,
const std::string& key,
const base::Value& value,
bool acknowledged,
bool update);
syncer::FakeSyncChangeProcessor* processor_;
ManagedUserSharedSettingsService* service_;
int next_sync_data_id_;
};
class ManagedUserTestBase : public chromeos::LoginManagerTest {
public:
ManagedUserTestBase();
virtual ~ManagedUserTestBase();
virtual void SetUpInProcessBrowserTestFixture() OVERRIDE;
virtual void CleanUpOnMainThread() OVERRIDE;
protected:
virtual void TearDown() OVERRIDE;
virtual void TearDownInProcessBrowserTestFixture() OVERRIDE;
void JSEval(const std::string& script);
void JSExpectAsync(const std::string& function);
void JSSetTextField(const std::string& element_selector,
const std::string& value);
void PrepareUsers();
void StartFlowLoginAsManager();
void FillNewUserData(const std::string& display_name);
void StartUserCreation(const std::string& button_id,
const std::string& expected_display_name);
void SigninAsSupervisedUser(bool check_homedir_calls,
int user_index,
const std::string& expected_display_name);
void SigninAsManager(int user_index);
void RemoveSupervisedUser(unsigned long original_user_count,
int user_index,
const std::string& expected_display_name);
cryptohome::MockAsyncMethodCaller* mock_async_method_caller_;
cryptohome::MockHomedirMethods* mock_homedir_methods_;
NetworkPortalDetectorTestImpl* network_portal_detector_;
ManagedUserRegistrationUtilityStub* registration_utility_stub_;
scoped_ptr<ScopedTestingManagedUserRegistrationUtility> scoped_utility_;
scoped_ptr<ManagedUsersSharedSettingsSyncTestAdapter>
shared_settings_adapter_;
scoped_ptr<ManagedUsersSyncTestAdapter> managed_users_adapter_;
private:
DISALLOW_COPY_AND_ASSIGN(ManagedUserTestBase);
};
} // namespace testing
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_LOGIN_MANAGED_MANAGED_USER_TEST_BASE_H_
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <string>
#include "base/compiler_specific.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/sequenced_worker_pool.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/login/login_display_host_impl.h"
#include "chrome/browser/chromeos/login/login_manager_test.h"
#include "chrome/browser/chromeos/login/startup_utils.h"
#include "chrome/browser/chromeos/login/webui_login_view.h"
#include "chrome/browser/chromeos/net/network_portal_detector_test_impl.h"
#include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h"
#include "chrome/browser/managed_mode/managed_user_registration_utility.h"
#include "chrome/browser/managed_mode/managed_user_registration_utility_stub.h"
#include "chromeos/cryptohome/mock_async_method_caller.h"
#include "chromeos/cryptohome/mock_homedir_methods.h"
#include "content/public/browser/notification_service.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h"
using testing::_;
namespace chromeos {
namespace {
const char kStubEthernetServicePath[] = "eth0";
const char kTestManager[] = "test-manager@gmail.com";
const char kTestOtherUser[] = "test-user@gmail.com";
const char kTestManagerPassword[] = "password";
const char kSupervisedUserDisplayName[] = "John Doe";
const char kSupervisedUserPassword[] = "simplepassword";
} // namespace
class SupervisedUserTest : public chromeos::LoginManagerTest {
protected:
SupervisedUserTest() : LoginManagerTest(true),
mock_async_method_caller_(NULL),
mock_homedir_methods_(NULL),
network_portal_detector_(NULL),
registration_utility_stub_(NULL) {
}
virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
LoginManagerTest::SetUpInProcessBrowserTestFixture();
mock_async_method_caller_ = new cryptohome::MockAsyncMethodCaller;
mock_async_method_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE);
cryptohome::AsyncMethodCaller::InitializeForTesting(
mock_async_method_caller_);
mock_homedir_methods_ = new cryptohome::MockHomedirMethods;
mock_homedir_methods_->SetUp(true, cryptohome::MOUNT_ERROR_NONE);
cryptohome::HomedirMethods::InitializeForTesting(mock_homedir_methods_);
registration_utility_stub_ = new ManagedUserRegistrationUtilityStub();
scoped_utility_.reset(
new ScopedTestingManagedUserRegistrationUtility(
registration_utility_stub_));
// Setup network portal detector to return online state for both
// ethernet and wifi networks. Ethernet is an active network by
// default.
network_portal_detector_ = new NetworkPortalDetectorTestImpl();
NetworkPortalDetector::InitializeForTesting(network_portal_detector_);
NetworkPortalDetector::CaptivePortalState online_state;
online_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE;
online_state.response_code = 204;
network_portal_detector_->SetDefaultNetworkPathForTesting(
kStubEthernetServicePath);
network_portal_detector_->SetDetectionResultsForTesting(
kStubEthernetServicePath, online_state);
}
virtual void CleanUpOnMainThread() OVERRIDE {
LoginManagerTest::CleanUpOnMainThread();
scoped_utility_.reset(NULL);
}
virtual void TearDown() OVERRIDE {
cryptohome::AsyncMethodCaller::Shutdown();
cryptohome::HomedirMethods::Shutdown();
mock_homedir_methods_ = NULL;
mock_async_method_caller_ = NULL;
LoginManagerTest::TearDown();
}
virtual void TearDownInProcessBrowserTestFixture() OVERRIDE {
NetworkPortalDetector::Shutdown();
}
void JSEval(const std::string& script) {
EXPECT_TRUE(content::ExecuteScript(web_contents(), script));
}
void JSExpectAsync(const std::string& function) {
bool result;
EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
web_contents(),
"(" + function + ")(function() {"
" window.domAutomationController.send(true);"
"});",
&result));
EXPECT_TRUE(result);
}
void JSSetTextField(const std::string& element_selector,
const std::string& value) {
std::string function;
function.append("document.querySelector('");
function.append(element_selector);
function.append("').value = '");
function.append(value);
function.append("'");
JSEval(function);
}
void PrepareUsers();
void CreateSupervisedUser();
void SigninAsSupervisedUser();
void RemoveSupervisedUser();
void LogInAsManagerAndFillUserData();
protected:
cryptohome::MockAsyncMethodCaller* mock_async_method_caller_;
cryptohome::MockHomedirMethods* mock_homedir_methods_;
NetworkPortalDetectorTestImpl* network_portal_detector_;
ManagedUserRegistrationUtilityStub* registration_utility_stub_;
scoped_ptr<ScopedTestingManagedUserRegistrationUtility> scoped_utility_;
private:
DISALLOW_COPY_AND_ASSIGN(SupervisedUserTest);
};
void SupervisedUserTest::PrepareUsers() {
RegisterUser(kTestManager);
RegisterUser(kTestOtherUser);
chromeos::StartupUtils::MarkOobeCompleted();
}
void SupervisedUserTest::LogInAsManagerAndFillUserData() {
// Create supervised user.
// Navigate to supervised user creation screen.
JSEval("chrome.send('showLocallyManagedUserCreationScreen')");
// Read intro and proceed.
JSExpect("$('managed-user-creation').currentPage_ == 'intro'");
JSEval("$('managed-user-creation-start-button').click()");
// Check that both users appear as managers, and test-manager@gmail.com is
// the first one.
JSExpect("$('managed-user-creation').currentPage_ == 'manager'");
JSExpect(std::string("document.querySelectorAll(")
.append("'#managed-user-creation-managers-pane .manager-pod.focused')")
.append(".length == 1"));
JSExpect("$('managed-user-creation').managerList_.pods.length == 2");
JSExpect(std::string("document.querySelectorAll(")
.append("'#managed-user-creation-managers-pane .manager-pod')")
.append(".length == 2"));
JSExpect(std::string("document.querySelectorAll(")
.append("'#managed-user-creation-managers-pane .manager-pod')")
.append("[0].user.emailAddress == '").append(kTestManager).append("'"));
// Select the first user as manager, and enter password.
JSExpect("$('managed-user-creation-next-button').disabled");
JSSetTextField(
"#managed-user-creation .manager-pod.focused input",
kTestManagerPassword);
JSEval("$('managed-user-creation').updateNextButtonForManager_()");
// Next button is now enabled.
JSExpect("!$('managed-user-creation-next-button').disabled");
SetExpectedCredentials(kTestManager, kTestManagerPassword);
content::WindowedNotificationObserver login_observer(
chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED,
content::NotificationService::AllSources());
// Log in as manager.
JSEval("$('managed-user-creation-next-button').click()");
login_observer.Wait();
// OAuth token is valid.
UserManager::Get()->
SaveUserOAuthStatus(kTestManager, User::OAUTH2_TOKEN_STATUS_VALID);
base::RunLoop().RunUntilIdle();
// Enter managed user details.
JSExpect("$('managed-user-creation').currentPage_ == 'username'");
JSExpect("$('managed-user-creation-next-button').disabled");
JSSetTextField(
"#managed-user-creation-name",
kSupervisedUserDisplayName);
JSEval("$('managed-user-creation').checkUserName_()");
base::RunLoop().RunUntilIdle();
JSSetTextField(
"#managed-user-creation-password",
kSupervisedUserPassword);
JSSetTextField(
"#managed-user-creation-password-confirm",
kSupervisedUserPassword);
JSEval("$('managed-user-creation').updateNextButtonForUser_()");
JSExpect("!$('managed-user-creation-next-button').disabled");
}
void SupervisedUserTest::CreateSupervisedUser() {
LogInAsManagerAndFillUserData();
EXPECT_CALL(*mock_homedir_methods_, MountEx(_, _, _, _)).Times(1);
EXPECT_CALL(*mock_homedir_methods_, AddKeyEx(_, _, _, _, _)).Times(1);
JSEval("$('managed-user-creation-next-button').click()");
testing::Mock::VerifyAndClearExpectations(mock_homedir_methods_);
EXPECT_TRUE(registration_utility_stub_->register_was_called());
EXPECT_EQ(registration_utility_stub_->display_name(),
base::UTF8ToUTF16(kSupervisedUserDisplayName));
registration_utility_stub_->RunSuccessCallback("token");
// Token writing moves control to BlockingPool and back.
base::RunLoop().RunUntilIdle();
content::BrowserThread::GetBlockingPool()->FlushForTesting();
base::RunLoop().RunUntilIdle();
JSExpect("$('managed-user-creation').currentPage_ == 'created'");
JSEval("$('managed-user-creation-gotit-button').click()");
}
void SupervisedUserTest::SigninAsSupervisedUser() {
EXPECT_CALL(*mock_homedir_methods_, MountEx(_, _, _, _)).Times(1);
// Log in as supervised user, make sure that everything works.
ASSERT_EQ(3UL, UserManager::Get()->GetUsers().size());
// Created supervised user have to be first in a list.
const User* user = UserManager::Get()->GetUsers().at(0);
ASSERT_EQ(base::UTF8ToUTF16(kSupervisedUserDisplayName),
user->display_name());
LoginUser(user->email());
testing::Mock::VerifyAndClearExpectations(mock_homedir_methods_);
}
void SupervisedUserTest::RemoveSupervisedUser() {
// Remove supervised user.
ASSERT_EQ(3UL, UserManager::Get()->GetUsers().size());
// Created supervised user have to be first in a list.
const User* user = UserManager::Get()->GetUsers().at(0);
ASSERT_EQ(base::UTF8ToUTF16(kSupervisedUserDisplayName),
user->display_name());
// Open pod menu.
JSExpect("!$('pod-row').pods[0].isActionBoxMenuActive");
JSEval("$('pod-row').pods[0].querySelector('.action-box-button').click()");
JSExpect("$('pod-row').pods[0].isActionBoxMenuActive");
// Select "Remove user" element.
JSExpect("$('pod-row').pods[0].actionBoxRemoveUserWarningElement.hidden");
JSEval(std::string("$('pod-row').pods[0].")
.append("querySelector('.action-box-menu-remove').click()"));
JSExpect("!$('pod-row').pods[0].actionBoxRemoveUserWarningElement.hidden");
EXPECT_CALL(*mock_async_method_caller_, AsyncRemove(_, _)).Times(1);
// Confirm deletion.
JSEval(std::string("$('pod-row').pods[0].")
.append("querySelector('.remove-warning-button').click()"));
// Make sure there is no supervised user in list.
ASSERT_EQ(2UL, UserManager::Get()->GetUsers().size());
}
class SupervisedUserCreationTest : public SupervisedUserTest {
public:
SupervisedUserCreationTest() : SupervisedUserTest() {}
private:
DISALLOW_COPY_AND_ASSIGN(SupervisedUserCreationTest);
};
class SupervisedUserTransactionCleanupTest : public SupervisedUserTest {
public:
SupervisedUserTransactionCleanupTest() : SupervisedUserTest () {}
private:
DISALLOW_COPY_AND_ASSIGN(SupervisedUserTransactionCleanupTest);
};
class SupervisedUserOwnerCreationTest : public SupervisedUserTest {
public:
SupervisedUserOwnerCreationTest() : SupervisedUserTest() {}
virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
SupervisedUserTest::SetUpInProcessBrowserTestFixture();
cros_settings_provider_.reset(new StubCrosSettingsProvider());
cros_settings_provider_->Set(kDeviceOwner, base::StringValue(kTestManager));
}
private:
scoped_ptr<StubCrosSettingsProvider> cros_settings_provider_;
DISALLOW_COPY_AND_ASSIGN(SupervisedUserOwnerCreationTest);
};
IN_PROC_BROWSER_TEST_F(SupervisedUserCreationTest,
PRE_PRE_PRE_CreateAndRemoveSupervisedUser) {
PrepareUsers();
}
IN_PROC_BROWSER_TEST_F(SupervisedUserCreationTest,
PRE_PRE_CreateAndRemoveSupervisedUser) {
CreateSupervisedUser();
}
IN_PROC_BROWSER_TEST_F(SupervisedUserCreationTest,
PRE_CreateAndRemoveSupervisedUser) {
SigninAsSupervisedUser();
}
IN_PROC_BROWSER_TEST_F(SupervisedUserCreationTest,
CreateAndRemoveSupervisedUser) {
RemoveSupervisedUser();
}
IN_PROC_BROWSER_TEST_F(SupervisedUserOwnerCreationTest,
PRE_PRE_PRE_CreateAndRemoveSupervisedUser) {
PrepareUsers();
}
IN_PROC_BROWSER_TEST_F(SupervisedUserOwnerCreationTest,
PRE_PRE_CreateAndRemoveSupervisedUser) {
CreateSupervisedUser();
}
IN_PROC_BROWSER_TEST_F(SupervisedUserOwnerCreationTest,
PRE_CreateAndRemoveSupervisedUser) {
SigninAsSupervisedUser();
}
IN_PROC_BROWSER_TEST_F(SupervisedUserOwnerCreationTest,
CreateAndRemoveSupervisedUser) {
RemoveSupervisedUser();
}
IN_PROC_BROWSER_TEST_F(SupervisedUserTransactionCleanupTest,
PRE_PRE_CreateAndCancelSupervisedUser) {
PrepareUsers();
}
IN_PROC_BROWSER_TEST_F(SupervisedUserTransactionCleanupTest,
PRE_CreateAndCancelSupervisedUser) {
LogInAsManagerAndFillUserData();
EXPECT_CALL(*mock_homedir_methods_, MountEx(_, _, _, _)).Times(1);
EXPECT_CALL(*mock_homedir_methods_, AddKeyEx(_, _, _, _, _)).Times(1);
JSEval("$('managed-user-creation-next-button').click()");
testing::Mock::VerifyAndClearExpectations(mock_homedir_methods_);
EXPECT_TRUE(registration_utility_stub_->register_was_called());
EXPECT_EQ(registration_utility_stub_->display_name(),
base::UTF8ToUTF16(kSupervisedUserDisplayName));
std::string user_id = registration_utility_stub_->managed_user_id();
// Make sure user is already in list.
ASSERT_EQ(3UL, UserManager::Get()->GetUsers().size());
// We wait for token now. Press cancel button at this point.
JSEval("$('cancel-add-user-button').click()");
}
IN_PROC_BROWSER_TEST_F(SupervisedUserTransactionCleanupTest,
CreateAndCancelSupervisedUser) {
// Make sure there is no supervised user in list.
ASSERT_EQ(2UL, UserManager::Get()->GetUsers().size());
}
} // namespace chromeos
......@@ -911,7 +911,10 @@
'browser/chromeos/login/login_utils_browsertest.cc',
'browser/chromeos/login/login_manager_test.cc',
'browser/chromeos/login/login_manager_test.h',
'browser/chromeos/login/managed/supervised_user_creation_browsertest.cc',
'browser/chromeos/login/managed/managed_user_creation_browsertest.cc',
'browser/chromeos/login/managed/managed_user_password_browsertest.cc',
'browser/chromeos/login/managed/managed_user_test_base.cc',
'browser/chromeos/login/managed/managed_user_test_base.h',
'browser/chromeos/login/mock_authenticator.cc',
'browser/chromeos/login/mock_authenticator.h',
'browser/chromeos/login/oauth2_browsertest.cc',
......
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