| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/login/managed/managed_user_test_base.h" | 5 #include "chrome/browser/chromeos/login/supervised/supervised_user_test_base.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/threading/sequenced_worker_pool.h" | 14 #include "base/threading/sequenced_worker_pool.h" |
| 15 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
| 16 #include "chrome/browser/chromeos/login/login_manager_test.h" | 16 #include "chrome/browser/chromeos/login/login_manager_test.h" |
| 17 #include "chrome/browser/chromeos/login/managed/supervised_user_authentication.h
" | |
| 18 #include "chrome/browser/chromeos/login/startup_utils.h" | 17 #include "chrome/browser/chromeos/login/startup_utils.h" |
| 18 #include "chrome/browser/chromeos/login/supervised/supervised_user_authenticatio
n.h" |
| 19 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" | 19 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" |
| 20 #include "chrome/browser/chromeos/login/ui/webui_login_view.h" | 20 #include "chrome/browser/chromeos/login/ui/webui_login_view.h" |
| 21 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h" | 21 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h" |
| 22 #include "chrome/browser/chromeos/net/network_portal_detector_test_impl.h" | 22 #include "chrome/browser/chromeos/net/network_portal_detector_test_impl.h" |
| 23 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 23 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 24 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" | 24 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" |
| 25 #include "chrome/browser/profiles/profile_impl.h" | 25 #include "chrome/browser/profiles/profile_impl.h" |
| 26 #include "chrome/browser/supervised_user/supervised_user_constants.h" | 26 #include "chrome/browser/supervised_user/supervised_user_constants.h" |
| 27 #include "chrome/browser/supervised_user/supervised_user_registration_utility.h" | 27 #include "chrome/browser/supervised_user/supervised_user_registration_utility.h" |
| 28 #include "chrome/browser/supervised_user/supervised_user_registration_utility_st
ub.h" | 28 #include "chrome/browser/supervised_user/supervised_user_registration_utility_st
ub.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 49 namespace chromeos { | 49 namespace chromeos { |
| 50 | 50 |
| 51 namespace { | 51 namespace { |
| 52 | 52 |
| 53 const char kCurrentPage[] = "$('managed-user-creation').currentPage_"; | 53 const char kCurrentPage[] = "$('managed-user-creation').currentPage_"; |
| 54 | 54 |
| 55 const char kStubEthernetGuid[] = "eth0"; | 55 const char kStubEthernetGuid[] = "eth0"; |
| 56 | 56 |
| 57 } | 57 } |
| 58 | 58 |
| 59 ManagedUsersSyncTestAdapter::ManagedUsersSyncTestAdapter(Profile* profile) | 59 SupervisedUsersSyncTestAdapter::SupervisedUsersSyncTestAdapter(Profile* profile) |
| 60 : processor_(), next_sync_data_id_(0) { | 60 : processor_(), next_sync_data_id_(0) { |
| 61 service_ = SupervisedUserSyncServiceFactory::GetForProfile(profile); | 61 service_ = SupervisedUserSyncServiceFactory::GetForProfile(profile); |
| 62 processor_ = new syncer::FakeSyncChangeProcessor(); | 62 processor_ = new syncer::FakeSyncChangeProcessor(); |
| 63 service_->MergeDataAndStartSyncing( | 63 service_->MergeDataAndStartSyncing( |
| 64 syncer::SUPERVISED_USERS, | 64 syncer::SUPERVISED_USERS, |
| 65 syncer::SyncDataList(), | 65 syncer::SyncDataList(), |
| 66 scoped_ptr<syncer::SyncChangeProcessor>(processor_), | 66 scoped_ptr<syncer::SyncChangeProcessor>(processor_), |
| 67 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock)); | 67 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock)); |
| 68 } | 68 } |
| 69 | 69 |
| 70 scoped_ptr< ::sync_pb::ManagedUserSpecifics> | 70 scoped_ptr< ::sync_pb::ManagedUserSpecifics> |
| 71 ManagedUsersSyncTestAdapter::GetFirstChange() { | 71 SupervisedUsersSyncTestAdapter::GetFirstChange() { |
| 72 scoped_ptr< ::sync_pb::ManagedUserSpecifics> result( | 72 scoped_ptr< ::sync_pb::ManagedUserSpecifics> result( |
| 73 new ::sync_pb::ManagedUserSpecifics); | 73 new ::sync_pb::ManagedUserSpecifics); |
| 74 CHECK(HasChanges()) | 74 CHECK(HasChanges()) |
| 75 << "GetFirstChange() should only be callled if HasChanges() is true"; | 75 << "GetFirstChange() should only be callled if HasChanges() is true"; |
| 76 const syncer::SyncData& data = processor_->changes().front().sync_data(); | 76 const syncer::SyncData& data = processor_->changes().front().sync_data(); |
| 77 EXPECT_EQ(syncer::SUPERVISED_USERS, data.GetDataType()); | 77 EXPECT_EQ(syncer::SUPERVISED_USERS, data.GetDataType()); |
| 78 result->CopyFrom(data.GetSpecifics().managed_user()); | 78 result->CopyFrom(data.GetSpecifics().managed_user()); |
| 79 return result.Pass(); | 79 return result.Pass(); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void ManagedUsersSyncTestAdapter::AddChange( | 82 void SupervisedUsersSyncTestAdapter::AddChange( |
| 83 const ::sync_pb::ManagedUserSpecifics& proto, | 83 const ::sync_pb::ManagedUserSpecifics& proto, |
| 84 bool update) { | 84 bool update) { |
| 85 sync_pb::EntitySpecifics specifics; | 85 sync_pb::EntitySpecifics specifics; |
| 86 | 86 |
| 87 specifics.mutable_managed_user()->CopyFrom(proto); | 87 specifics.mutable_managed_user()->CopyFrom(proto); |
| 88 | 88 |
| 89 syncer::SyncData change_data = syncer::SyncData::CreateRemoteData( | 89 syncer::SyncData change_data = syncer::SyncData::CreateRemoteData( |
| 90 ++next_sync_data_id_, | 90 ++next_sync_data_id_, |
| 91 specifics, | 91 specifics, |
| 92 base::Time(), | 92 base::Time(), |
| 93 syncer::AttachmentIdList(), | 93 syncer::AttachmentIdList(), |
| 94 syncer::AttachmentServiceProxyForTest::Create()); | 94 syncer::AttachmentServiceProxyForTest::Create()); |
| 95 syncer::SyncChange change(FROM_HERE, | 95 syncer::SyncChange change(FROM_HERE, |
| 96 update ? syncer::SyncChange::ACTION_UPDATE | 96 update ? syncer::SyncChange::ACTION_UPDATE |
| 97 : syncer::SyncChange::ACTION_ADD, | 97 : syncer::SyncChange::ACTION_ADD, |
| 98 change_data); | 98 change_data); |
| 99 | 99 |
| 100 syncer::SyncChangeList change_list; | 100 syncer::SyncChangeList change_list; |
| 101 change_list.push_back(change); | 101 change_list.push_back(change); |
| 102 | 102 |
| 103 service_->ProcessSyncChanges(FROM_HERE, change_list); | 103 service_->ProcessSyncChanges(FROM_HERE, change_list); |
| 104 } | 104 } |
| 105 | 105 |
| 106 ManagedUsersSharedSettingsSyncTestAdapter:: | 106 SupervisedUsersSharedSettingsSyncTestAdapter:: |
| 107 ManagedUsersSharedSettingsSyncTestAdapter(Profile* profile) | 107 SupervisedUsersSharedSettingsSyncTestAdapter(Profile* profile) |
| 108 : processor_(), next_sync_data_id_(0) { | 108 : processor_(), next_sync_data_id_(0) { |
| 109 service_ = | 109 service_ = |
| 110 SupervisedUserSharedSettingsServiceFactory::GetForBrowserContext(profile); | 110 SupervisedUserSharedSettingsServiceFactory::GetForBrowserContext(profile); |
| 111 processor_ = new syncer::FakeSyncChangeProcessor(); | 111 processor_ = new syncer::FakeSyncChangeProcessor(); |
| 112 service_->MergeDataAndStartSyncing( | 112 service_->MergeDataAndStartSyncing( |
| 113 syncer::SUPERVISED_USER_SHARED_SETTINGS, | 113 syncer::SUPERVISED_USER_SHARED_SETTINGS, |
| 114 syncer::SyncDataList(), | 114 syncer::SyncDataList(), |
| 115 scoped_ptr<syncer::SyncChangeProcessor>(processor_), | 115 scoped_ptr<syncer::SyncChangeProcessor>(processor_), |
| 116 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock)); | 116 scoped_ptr<syncer::SyncErrorFactory>(new syncer::SyncErrorFactoryMock)); |
| 117 } | 117 } |
| 118 | 118 |
| 119 scoped_ptr< ::sync_pb::ManagedUserSharedSettingSpecifics> | 119 scoped_ptr< ::sync_pb::ManagedUserSharedSettingSpecifics> |
| 120 ManagedUsersSharedSettingsSyncTestAdapter::GetFirstChange() { | 120 SupervisedUsersSharedSettingsSyncTestAdapter::GetFirstChange() { |
| 121 scoped_ptr< ::sync_pb::ManagedUserSharedSettingSpecifics> result( | 121 scoped_ptr< ::sync_pb::ManagedUserSharedSettingSpecifics> result( |
| 122 new ::sync_pb::ManagedUserSharedSettingSpecifics); | 122 new ::sync_pb::ManagedUserSharedSettingSpecifics); |
| 123 CHECK(HasChanges()) | 123 CHECK(HasChanges()) |
| 124 << "GetFirstChange() should only be callled if HasChanges() is true"; | 124 << "GetFirstChange() should only be callled if HasChanges() is true"; |
| 125 const syncer::SyncData& data = processor_->changes().front().sync_data(); | 125 const syncer::SyncData& data = processor_->changes().front().sync_data(); |
| 126 EXPECT_EQ(syncer::SUPERVISED_USER_SHARED_SETTINGS, data.GetDataType()); | 126 EXPECT_EQ(syncer::SUPERVISED_USER_SHARED_SETTINGS, data.GetDataType()); |
| 127 result->CopyFrom(data.GetSpecifics().managed_user_shared_setting()); | 127 result->CopyFrom(data.GetSpecifics().managed_user_shared_setting()); |
| 128 return result.Pass(); | 128 return result.Pass(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 void ManagedUsersSharedSettingsSyncTestAdapter::AddChange( | 131 void SupervisedUsersSharedSettingsSyncTestAdapter::AddChange( |
| 132 const ::sync_pb::ManagedUserSharedSettingSpecifics& proto, | 132 const ::sync_pb::ManagedUserSharedSettingSpecifics& proto, |
| 133 bool update) { | 133 bool update) { |
| 134 sync_pb::EntitySpecifics specifics; | 134 sync_pb::EntitySpecifics specifics; |
| 135 | 135 |
| 136 specifics.mutable_managed_user_shared_setting()->CopyFrom(proto); | 136 specifics.mutable_managed_user_shared_setting()->CopyFrom(proto); |
| 137 | 137 |
| 138 syncer::SyncData change_data = syncer::SyncData::CreateRemoteData( | 138 syncer::SyncData change_data = syncer::SyncData::CreateRemoteData( |
| 139 ++next_sync_data_id_, | 139 ++next_sync_data_id_, |
| 140 specifics, | 140 specifics, |
| 141 base::Time(), | 141 base::Time(), |
| 142 syncer::AttachmentIdList(), | 142 syncer::AttachmentIdList(), |
| 143 syncer::AttachmentServiceProxyForTest::Create()); | 143 syncer::AttachmentServiceProxyForTest::Create()); |
| 144 syncer::SyncChange change(FROM_HERE, | 144 syncer::SyncChange change(FROM_HERE, |
| 145 update ? syncer::SyncChange::ACTION_UPDATE | 145 update ? syncer::SyncChange::ACTION_UPDATE |
| 146 : syncer::SyncChange::ACTION_ADD, | 146 : syncer::SyncChange::ACTION_ADD, |
| 147 change_data); | 147 change_data); |
| 148 | 148 |
| 149 syncer::SyncChangeList change_list; | 149 syncer::SyncChangeList change_list; |
| 150 change_list.push_back(change); | 150 change_list.push_back(change); |
| 151 | 151 |
| 152 service_->ProcessSyncChanges(FROM_HERE, change_list); | 152 service_->ProcessSyncChanges(FROM_HERE, change_list); |
| 153 } | 153 } |
| 154 | 154 |
| 155 void ManagedUsersSharedSettingsSyncTestAdapter::AddChange( | 155 void SupervisedUsersSharedSettingsSyncTestAdapter::AddChange( |
| 156 const std::string& mu_id, | 156 const std::string& mu_id, |
| 157 const std::string& key, | 157 const std::string& key, |
| 158 const base::Value& value, | 158 const base::Value& value, |
| 159 bool acknowledged, | 159 bool acknowledged, |
| 160 bool update) { | 160 bool update) { |
| 161 syncer::SyncData data = | 161 syncer::SyncData data = |
| 162 SupervisedUserSharedSettingsService::CreateSyncDataForSetting( | 162 SupervisedUserSharedSettingsService::CreateSyncDataForSetting( |
| 163 mu_id, key, value, acknowledged); | 163 mu_id, key, value, acknowledged); |
| 164 AddChange(data.GetSpecifics().managed_user_shared_setting(), update); | 164 AddChange(data.GetSpecifics().managed_user_shared_setting(), update); |
| 165 } | 165 } |
| 166 | 166 |
| 167 ManagedUserTestBase::ManagedUserTestBase() | 167 SupervisedUserTestBase::SupervisedUserTestBase() |
| 168 : LoginManagerTest(true), | 168 : LoginManagerTest(true), |
| 169 mock_async_method_caller_(NULL), | 169 mock_async_method_caller_(NULL), |
| 170 mock_homedir_methods_(NULL), | 170 mock_homedir_methods_(NULL), |
| 171 network_portal_detector_(NULL), | 171 network_portal_detector_(NULL), |
| 172 registration_utility_stub_(NULL) { | 172 registration_utility_stub_(NULL) { |
| 173 } | 173 } |
| 174 | 174 |
| 175 ManagedUserTestBase::~ManagedUserTestBase() { | 175 SupervisedUserTestBase::~SupervisedUserTestBase() { |
| 176 } | 176 } |
| 177 | 177 |
| 178 void ManagedUserTestBase::SetUpInProcessBrowserTestFixture() { | 178 void SupervisedUserTestBase::SetUpInProcessBrowserTestFixture() { |
| 179 LoginManagerTest::SetUpInProcessBrowserTestFixture(); | 179 LoginManagerTest::SetUpInProcessBrowserTestFixture(); |
| 180 mock_async_method_caller_ = new cryptohome::MockAsyncMethodCaller; | 180 mock_async_method_caller_ = new cryptohome::MockAsyncMethodCaller; |
| 181 mock_async_method_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); | 181 mock_async_method_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); |
| 182 cryptohome::AsyncMethodCaller::InitializeForTesting( | 182 cryptohome::AsyncMethodCaller::InitializeForTesting( |
| 183 mock_async_method_caller_); | 183 mock_async_method_caller_); |
| 184 | 184 |
| 185 mock_homedir_methods_ = new cryptohome::MockHomedirMethods; | 185 mock_homedir_methods_ = new cryptohome::MockHomedirMethods; |
| 186 mock_homedir_methods_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); | 186 mock_homedir_methods_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); |
| 187 cryptohome::HomedirMethods::InitializeForTesting(mock_homedir_methods_); | 187 cryptohome::HomedirMethods::InitializeForTesting(mock_homedir_methods_); |
| 188 | 188 |
| 189 registration_utility_stub_ = new SupervisedUserRegistrationUtilityStub(); | 189 registration_utility_stub_ = new SupervisedUserRegistrationUtilityStub(); |
| 190 scoped_utility_.reset(new ScopedTestingSupervisedUserRegistrationUtility( | 190 scoped_utility_.reset(new ScopedTestingSupervisedUserRegistrationUtility( |
| 191 registration_utility_stub_)); | 191 registration_utility_stub_)); |
| 192 | 192 |
| 193 // Setup network portal detector to return online state for both | 193 // Setup network portal detector to return online state for both |
| 194 // ethernet and wifi networks. Ethernet is an active network by | 194 // ethernet and wifi networks. Ethernet is an active network by |
| 195 // default. | 195 // default. |
| 196 network_portal_detector_ = new NetworkPortalDetectorTestImpl(); | 196 network_portal_detector_ = new NetworkPortalDetectorTestImpl(); |
| 197 NetworkPortalDetector::InitializeForTesting(network_portal_detector_); | 197 NetworkPortalDetector::InitializeForTesting(network_portal_detector_); |
| 198 NetworkPortalDetector::CaptivePortalState online_state; | 198 NetworkPortalDetector::CaptivePortalState online_state; |
| 199 online_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE; | 199 online_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE; |
| 200 online_state.response_code = 204; | 200 online_state.response_code = 204; |
| 201 network_portal_detector_->SetDefaultNetworkForTesting(kStubEthernetGuid); | 201 network_portal_detector_->SetDefaultNetworkForTesting(kStubEthernetGuid); |
| 202 network_portal_detector_->SetDetectionResultsForTesting(kStubEthernetGuid, | 202 network_portal_detector_->SetDetectionResultsForTesting(kStubEthernetGuid, |
| 203 online_state); | 203 online_state); |
| 204 } | 204 } |
| 205 | 205 |
| 206 void ManagedUserTestBase::CleanUpOnMainThread() { | 206 void SupervisedUserTestBase::CleanUpOnMainThread() { |
| 207 LoginManagerTest::CleanUpOnMainThread(); | 207 LoginManagerTest::CleanUpOnMainThread(); |
| 208 } | 208 } |
| 209 | 209 |
| 210 void ManagedUserTestBase::TearDown() { | 210 void SupervisedUserTestBase::TearDown() { |
| 211 cryptohome::AsyncMethodCaller::Shutdown(); | 211 cryptohome::AsyncMethodCaller::Shutdown(); |
| 212 cryptohome::HomedirMethods::Shutdown(); | 212 cryptohome::HomedirMethods::Shutdown(); |
| 213 mock_homedir_methods_ = NULL; | 213 mock_homedir_methods_ = NULL; |
| 214 mock_async_method_caller_ = NULL; | 214 mock_async_method_caller_ = NULL; |
| 215 LoginManagerTest::TearDown(); | 215 LoginManagerTest::TearDown(); |
| 216 } | 216 } |
| 217 | 217 |
| 218 void ManagedUserTestBase::TearDownInProcessBrowserTestFixture() { | 218 void SupervisedUserTestBase::TearDownInProcessBrowserTestFixture() { |
| 219 NetworkPortalDetector::Shutdown(); | 219 NetworkPortalDetector::Shutdown(); |
| 220 } | 220 } |
| 221 | 221 |
| 222 void ManagedUserTestBase::JSEval(const std::string& script) { | 222 void SupervisedUserTestBase::JSEval(const std::string& script) { |
| 223 EXPECT_TRUE(content::ExecuteScript(web_contents(), script)) << script; | 223 EXPECT_TRUE(content::ExecuteScript(web_contents(), script)) << script; |
| 224 } | 224 } |
| 225 | 225 |
| 226 void ManagedUserTestBase::JSExpectAsync(const std::string& function) { | 226 void SupervisedUserTestBase::JSExpectAsync(const std::string& function) { |
| 227 bool result; | 227 bool result; |
| 228 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 228 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 229 web_contents(), | 229 web_contents(), |
| 230 StringPrintf( | 230 StringPrintf( |
| 231 "(%s)(function() { window.domAutomationController.send(true); });", | 231 "(%s)(function() { window.domAutomationController.send(true); });", |
| 232 function.c_str()), | 232 function.c_str()), |
| 233 &result)) << function; | 233 &result)) << function; |
| 234 EXPECT_TRUE(result); | 234 EXPECT_TRUE(result); |
| 235 } | 235 } |
| 236 | 236 |
| 237 void ManagedUserTestBase::JSSetTextField(const std::string& element_selector, | 237 void SupervisedUserTestBase::JSSetTextField(const std::string& element_selector, |
| 238 const std::string& value) { | 238 const std::string& value) { |
| 239 std::string function = | 239 std::string function = |
| 240 StringPrintf("document.querySelector('%s').value = '%s'", | 240 StringPrintf("document.querySelector('%s').value = '%s'", |
| 241 element_selector.c_str(), | 241 element_selector.c_str(), |
| 242 value.c_str()); | 242 value.c_str()); |
| 243 JSEval(function); | 243 JSEval(function); |
| 244 } | 244 } |
| 245 | 245 |
| 246 void ManagedUserTestBase::PrepareUsers() { | 246 void SupervisedUserTestBase::PrepareUsers() { |
| 247 RegisterUser(kTestManager); | 247 RegisterUser(kTestManager); |
| 248 RegisterUser(kTestOtherUser); | 248 RegisterUser(kTestOtherUser); |
| 249 chromeos::StartupUtils::MarkOobeCompleted(); | 249 chromeos::StartupUtils::MarkOobeCompleted(); |
| 250 } | 250 } |
| 251 | 251 |
| 252 void ManagedUserTestBase::StartFlowLoginAsManager() { | 252 void SupervisedUserTestBase::StartFlowLoginAsManager() { |
| 253 // Navigate to supervised user creation screen. | 253 // Navigate to supervised user creation screen. |
| 254 JSEval("chrome.send('showLocallyManagedUserCreationScreen')"); | 254 JSEval("chrome.send('showLocallyManagedUserCreationScreen')"); |
| 255 | 255 |
| 256 // Read intro and proceed. | 256 // Read intro and proceed. |
| 257 JSExpect(StringPrintf("%s == 'intro'", kCurrentPage)); | 257 JSExpect(StringPrintf("%s == 'intro'", kCurrentPage)); |
| 258 | 258 |
| 259 JSEval("$('managed-user-creation-start-button').click()"); | 259 JSEval("$('managed-user-creation-start-button').click()"); |
| 260 | 260 |
| 261 // Check that both users appear as managers, and test-manager@gmail.com is | 261 // Check that both users appear as managers, and test-manager@gmail.com is |
| 262 // the first one. | 262 // the first one. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 | 305 |
| 306 // OAuth token is valid. | 306 // OAuth token is valid. |
| 307 UserManager::Get()->SaveUserOAuthStatus(kTestManager, | 307 UserManager::Get()->SaveUserOAuthStatus(kTestManager, |
| 308 User::OAUTH2_TOKEN_STATUS_VALID); | 308 User::OAUTH2_TOKEN_STATUS_VALID); |
| 309 base::RunLoop().RunUntilIdle(); | 309 base::RunLoop().RunUntilIdle(); |
| 310 | 310 |
| 311 // Check the page have changed. | 311 // Check the page have changed. |
| 312 JSExpect(StringPrintf("%s == 'username'", kCurrentPage)); | 312 JSExpect(StringPrintf("%s == 'username'", kCurrentPage)); |
| 313 } | 313 } |
| 314 | 314 |
| 315 void ManagedUserTestBase::FillNewUserData(const std::string& display_name) { | 315 void SupervisedUserTestBase::FillNewUserData(const std::string& display_name) { |
| 316 JSExpect("$('managed-user-creation-next-button').disabled"); | 316 JSExpect("$('managed-user-creation-next-button').disabled"); |
| 317 JSSetTextField("#managed-user-creation-name", display_name); | 317 JSSetTextField("#managed-user-creation-name", display_name); |
| 318 JSEval("$('managed-user-creation').checkUserName_()"); | 318 JSEval("$('managed-user-creation').checkUserName_()"); |
| 319 | 319 |
| 320 base::RunLoop().RunUntilIdle(); | 320 base::RunLoop().RunUntilIdle(); |
| 321 | 321 |
| 322 JSSetTextField("#managed-user-creation-password", | 322 JSSetTextField("#managed-user-creation-password", |
| 323 kTestSupervisedUserPassword); | 323 kTestSupervisedUserPassword); |
| 324 JSSetTextField("#managed-user-creation-password-confirm", | 324 JSSetTextField("#managed-user-creation-password-confirm", |
| 325 kTestSupervisedUserPassword); | 325 kTestSupervisedUserPassword); |
| 326 | 326 |
| 327 JSEval("$('managed-user-creation').updateNextButtonForUser_()"); | 327 JSEval("$('managed-user-creation').updateNextButtonForUser_()"); |
| 328 JSExpect("!$('managed-user-creation-next-button').disabled"); | 328 JSExpect("!$('managed-user-creation-next-button').disabled"); |
| 329 } | 329 } |
| 330 | 330 |
| 331 void ManagedUserTestBase::StartUserCreation( | 331 void SupervisedUserTestBase::StartUserCreation( |
| 332 const std::string& button_id, | 332 const std::string& button_id, |
| 333 const std::string& expected_display_name) { | 333 const std::string& expected_display_name) { |
| 334 EXPECT_CALL(*mock_homedir_methods_, MountEx(_, _, _, _)).Times(1); | 334 EXPECT_CALL(*mock_homedir_methods_, MountEx(_, _, _, _)).Times(1); |
| 335 EXPECT_CALL(*mock_homedir_methods_, AddKeyEx(_, _, _, _, _)).Times(1); | 335 EXPECT_CALL(*mock_homedir_methods_, AddKeyEx(_, _, _, _, _)).Times(1); |
| 336 | 336 |
| 337 JSEval(std::string("$('").append(button_id).append("').click()")); | 337 JSEval(std::string("$('").append(button_id).append("').click()")); |
| 338 | 338 |
| 339 ::testing::Mock::VerifyAndClearExpectations(mock_homedir_methods_); | 339 ::testing::Mock::VerifyAndClearExpectations(mock_homedir_methods_); |
| 340 | 340 |
| 341 EXPECT_TRUE(registration_utility_stub_->register_was_called()); | 341 EXPECT_TRUE(registration_utility_stub_->register_was_called()); |
| 342 EXPECT_EQ(registration_utility_stub_->display_name(), | 342 EXPECT_EQ(registration_utility_stub_->display_name(), |
| 343 base::UTF8ToUTF16(expected_display_name)); | 343 base::UTF8ToUTF16(expected_display_name)); |
| 344 | 344 |
| 345 registration_utility_stub_->RunSuccessCallback("token"); | 345 registration_utility_stub_->RunSuccessCallback("token"); |
| 346 | 346 |
| 347 // Token writing moves control to BlockingPool and back. | 347 // Token writing moves control to BlockingPool and back. |
| 348 base::RunLoop().RunUntilIdle(); | 348 base::RunLoop().RunUntilIdle(); |
| 349 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 349 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 350 base::RunLoop().RunUntilIdle(); | 350 base::RunLoop().RunUntilIdle(); |
| 351 | 351 |
| 352 JSExpect(StringPrintf("%s == 'created'", kCurrentPage)); | 352 JSExpect(StringPrintf("%s == 'created'", kCurrentPage)); |
| 353 JSEval("$('managed-user-creation-gotit-button').click()"); | 353 JSEval("$('managed-user-creation-gotit-button').click()"); |
| 354 } | 354 } |
| 355 | 355 |
| 356 void ManagedUserTestBase::SigninAsSupervisedUser( | 356 void SupervisedUserTestBase::SigninAsSupervisedUser( |
| 357 bool check_homedir_calls, | 357 bool check_homedir_calls, |
| 358 int user_index, | 358 int user_index, |
| 359 const std::string& expected_display_name) { | 359 const std::string& expected_display_name) { |
| 360 if (check_homedir_calls) | 360 if (check_homedir_calls) |
| 361 EXPECT_CALL(*mock_homedir_methods_, MountEx(_, _, _, _)).Times(1); | 361 EXPECT_CALL(*mock_homedir_methods_, MountEx(_, _, _, _)).Times(1); |
| 362 | 362 |
| 363 // Log in as supervised user, make sure that everything works. | 363 // Log in as supervised user, make sure that everything works. |
| 364 ASSERT_EQ(3UL, UserManager::Get()->GetUsers().size()); | 364 ASSERT_EQ(3UL, UserManager::Get()->GetUsers().size()); |
| 365 | 365 |
| 366 // Created supervised user have to be first in a list. | 366 // Created supervised user have to be first in a list. |
| 367 const User* user = UserManager::Get()->GetUsers().at(user_index); | 367 const User* user = UserManager::Get()->GetUsers().at(user_index); |
| 368 ASSERT_EQ(base::UTF8ToUTF16(expected_display_name), user->display_name()); | 368 ASSERT_EQ(base::UTF8ToUTF16(expected_display_name), user->display_name()); |
| 369 LoginUser(user->email()); | 369 LoginUser(user->email()); |
| 370 if (check_homedir_calls) | 370 if (check_homedir_calls) |
| 371 ::testing::Mock::VerifyAndClearExpectations(mock_homedir_methods_); | 371 ::testing::Mock::VerifyAndClearExpectations(mock_homedir_methods_); |
| 372 Profile* profile = ProfileHelper::Get()->GetProfileByUser(user); | 372 Profile* profile = ProfileHelper::Get()->GetProfileByUser(user); |
| 373 shared_settings_adapter_.reset( | 373 shared_settings_adapter_.reset( |
| 374 new ManagedUsersSharedSettingsSyncTestAdapter(profile)); | 374 new SupervisedUsersSharedSettingsSyncTestAdapter(profile)); |
| 375 | 375 |
| 376 // Check ChromeOS preference is initialized. | 376 // Check ChromeOS preference is initialized. |
| 377 EXPECT_TRUE( | 377 EXPECT_TRUE( |
| 378 static_cast<ProfileImpl*>(profile)->chromeos_preferences_); | 378 static_cast<ProfileImpl*>(profile)->chromeos_preferences_); |
| 379 } | 379 } |
| 380 | 380 |
| 381 void ManagedUserTestBase::SigninAsManager(int user_index) { | 381 void SupervisedUserTestBase::SigninAsManager(int user_index) { |
| 382 // Log in as supervised user, make sure that everything works. | 382 // Log in as supervised user, make sure that everything works. |
| 383 ASSERT_EQ(3UL, UserManager::Get()->GetUsers().size()); | 383 ASSERT_EQ(3UL, UserManager::Get()->GetUsers().size()); |
| 384 | 384 |
| 385 // Created supervised user have to be first in a list. | 385 // Created supervised user have to be first in a list. |
| 386 const User* user = UserManager::Get()->GetUsers().at(user_index); | 386 const User* user = UserManager::Get()->GetUsers().at(user_index); |
| 387 LoginUser(user->email()); | 387 LoginUser(user->email()); |
| 388 Profile* profile = ProfileHelper::Get()->GetProfileByUser(user); | 388 Profile* profile = ProfileHelper::Get()->GetProfileByUser(user); |
| 389 shared_settings_adapter_.reset( | 389 shared_settings_adapter_.reset( |
| 390 new ManagedUsersSharedSettingsSyncTestAdapter(profile)); | 390 new SupervisedUsersSharedSettingsSyncTestAdapter(profile)); |
| 391 managed_users_adapter_.reset(new ManagedUsersSyncTestAdapter(profile)); | 391 supervised_users_adapter_.reset(new SupervisedUsersSyncTestAdapter(profile)); |
| 392 } | 392 } |
| 393 | 393 |
| 394 void ManagedUserTestBase::RemoveSupervisedUser( | 394 void SupervisedUserTestBase::RemoveSupervisedUser( |
| 395 unsigned long original_user_count, | 395 unsigned long original_user_count, |
| 396 int user_index, | 396 int user_index, |
| 397 const std::string& expected_display_name) { | 397 const std::string& expected_display_name) { |
| 398 // Remove supervised user. | 398 // Remove supervised user. |
| 399 ASSERT_EQ(original_user_count, UserManager::Get()->GetUsers().size()); | 399 ASSERT_EQ(original_user_count, UserManager::Get()->GetUsers().size()); |
| 400 | 400 |
| 401 // Created supervised user have to be first in a list. | 401 // Created supervised user have to be first in a list. |
| 402 const User* user = UserManager::Get()->GetUsers().at(user_index); | 402 const User* user = UserManager::Get()->GetUsers().at(user_index); |
| 403 ASSERT_EQ(base::UTF8ToUTF16(expected_display_name), user->display_name()); | 403 ASSERT_EQ(base::UTF8ToUTF16(expected_display_name), user->display_name()); |
| 404 | 404 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 427 // Confirm deletion. | 427 // Confirm deletion. |
| 428 JSEval(StringPrintf( | 428 JSEval(StringPrintf( |
| 429 "$('pod-row').pods[%d].querySelector('.remove-warning-button').click()", | 429 "$('pod-row').pods[%d].querySelector('.remove-warning-button').click()", |
| 430 user_index)); | 430 user_index)); |
| 431 | 431 |
| 432 // Make sure there is no supervised user in list. | 432 // Make sure there is no supervised user in list. |
| 433 ASSERT_EQ(original_user_count - 1, UserManager::Get()->GetUsers().size()); | 433 ASSERT_EQ(original_user_count - 1, UserManager::Get()->GetUsers().size()); |
| 434 } | 434 } |
| 435 | 435 |
| 436 } // namespace chromeos | 436 } // namespace chromeos |
| OLD | NEW |