| 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/supervised/supervised_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" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 #include "sync/api/sync_error_factory_mock.h" | 43 #include "sync/api/sync_error_factory_mock.h" |
| 44 #include "sync/protocol/sync.pb.h" | 44 #include "sync/protocol/sync.pb.h" |
| 45 | 45 |
| 46 using testing::_; | 46 using testing::_; |
| 47 using base::StringPrintf; | 47 using base::StringPrintf; |
| 48 | 48 |
| 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[] = "$('supervised-user-creation').currentPage_"; |
| 54 | 54 |
| 55 const char kStubEthernetGuid[] = "eth0"; | 55 const char kStubEthernetGuid[] = "eth0"; |
| 56 | 56 |
| 57 } | 57 } |
| 58 | 58 |
| 59 SupervisedUsersSyncTestAdapter::SupervisedUsersSyncTestAdapter(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( |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 } | 244 } |
| 245 | 245 |
| 246 void SupervisedUserTestBase::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 SupervisedUserTestBase::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('showSupervisedUserCreationScreen')"); |
| 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("$('supervised-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. |
| 263 JSExpect(StringPrintf("%s == 'manager'", kCurrentPage)); | 263 JSExpect(StringPrintf("%s == 'manager'", kCurrentPage)); |
| 264 | 264 |
| 265 std::string manager_pods = | 265 std::string manager_pods = |
| 266 "document.querySelectorAll('#managed-user-creation-managers-pane " | 266 "document.querySelectorAll('#supervised-user-creation-managers-pane " |
| 267 ".manager-pod')"; | 267 ".manager-pod')"; |
| 268 std::string selected_manager_pods = | 268 std::string selected_manager_pods = |
| 269 "document.querySelectorAll('#managed-user-creation-managers-pane " | 269 "document.querySelectorAll('#supervised-user-creation-managers-pane " |
| 270 ".manager-pod.focused')"; | 270 ".manager-pod.focused')"; |
| 271 | 271 |
| 272 int managers_on_device = 2; | 272 int managers_on_device = 2; |
| 273 | 273 |
| 274 JSExpect(StringPrintf("%s.length == 1", selected_manager_pods.c_str())); | 274 JSExpect(StringPrintf("%s.length == 1", selected_manager_pods.c_str())); |
| 275 | 275 |
| 276 JSExpect( | 276 JSExpect(StringPrintf( |
| 277 StringPrintf("$('managed-user-creation').managerList_.pods.length == %d", | 277 "$('supervised-user-creation').managerList_.pods.length == %d", |
| 278 managers_on_device)); | 278 managers_on_device)); |
| 279 JSExpect(StringPrintf( | 279 JSExpect(StringPrintf( |
| 280 "%s.length == %d", manager_pods.c_str(), managers_on_device)); | 280 "%s.length == %d", manager_pods.c_str(), managers_on_device)); |
| 281 JSExpect(StringPrintf("%s[%d].user.emailAddress == '%s'", | 281 JSExpect(StringPrintf("%s[%d].user.emailAddress == '%s'", |
| 282 manager_pods.c_str(), | 282 manager_pods.c_str(), |
| 283 0, | 283 0, |
| 284 kTestManager)); | 284 kTestManager)); |
| 285 | 285 |
| 286 // Select the first user as manager, and enter password. | 286 // Select the first user as manager, and enter password. |
| 287 JSExpect("$('managed-user-creation-next-button').disabled"); | 287 JSExpect("$('supervised-user-creation-next-button').disabled"); |
| 288 JSSetTextField("#managed-user-creation .manager-pod.focused input", | 288 JSSetTextField("#supervised-user-creation .manager-pod.focused input", |
| 289 kTestManagerPassword); | 289 kTestManagerPassword); |
| 290 | 290 |
| 291 JSEval("$('managed-user-creation').updateNextButtonForManager_()"); | 291 JSEval("$('supervised-user-creation').updateNextButtonForManager_()"); |
| 292 | 292 |
| 293 // Next button is now enabled. | 293 // Next button is now enabled. |
| 294 JSExpect("!$('managed-user-creation-next-button').disabled"); | 294 JSExpect("!$('supervised-user-creation-next-button').disabled"); |
| 295 UserContext user_context(kTestManager); | 295 UserContext user_context(kTestManager); |
| 296 user_context.SetKey(Key(kTestManagerPassword)); | 296 user_context.SetKey(Key(kTestManagerPassword)); |
| 297 SetExpectedCredentials(user_context); | 297 SetExpectedCredentials(user_context); |
| 298 content::WindowedNotificationObserver login_observer( | 298 content::WindowedNotificationObserver login_observer( |
| 299 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, | 299 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, |
| 300 content::NotificationService::AllSources()); | 300 content::NotificationService::AllSources()); |
| 301 | 301 |
| 302 // Log in as manager. | 302 // Log in as manager. |
| 303 JSEval("$('managed-user-creation-next-button').click()"); | 303 JSEval("$('supervised-user-creation-next-button').click()"); |
| 304 login_observer.Wait(); | 304 login_observer.Wait(); |
| 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 SupervisedUserTestBase::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("$('supervised-user-creation-next-button').disabled"); |
| 317 JSSetTextField("#managed-user-creation-name", display_name); | 317 JSSetTextField("#supervised-user-creation-name", display_name); |
| 318 JSEval("$('managed-user-creation').checkUserName_()"); | 318 JSEval("$('supervised-user-creation').checkUserName_()"); |
| 319 | 319 |
| 320 base::RunLoop().RunUntilIdle(); | 320 base::RunLoop().RunUntilIdle(); |
| 321 | 321 |
| 322 JSSetTextField("#managed-user-creation-password", | 322 JSSetTextField("#supervised-user-creation-password", |
| 323 kTestSupervisedUserPassword); | 323 kTestSupervisedUserPassword); |
| 324 JSSetTextField("#managed-user-creation-password-confirm", | 324 JSSetTextField("#supervised-user-creation-password-confirm", |
| 325 kTestSupervisedUserPassword); | 325 kTestSupervisedUserPassword); |
| 326 | 326 |
| 327 JSEval("$('managed-user-creation').updateNextButtonForUser_()"); | 327 JSEval("$('supervised-user-creation').updateNextButtonForUser_()"); |
| 328 JSExpect("!$('managed-user-creation-next-button').disabled"); | 328 JSExpect("!$('supervised-user-creation-next-button').disabled"); |
| 329 } | 329 } |
| 330 | 330 |
| 331 void SupervisedUserTestBase::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("$('supervised-user-creation-gotit-button').click()"); |
| 354 } | 354 } |
| 355 | 355 |
| 356 void SupervisedUserTestBase::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. |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 |