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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 } | 240 } |
241 | 241 |
242 void SupervisedUserTestBase::PrepareUsers() { | 242 void SupervisedUserTestBase::PrepareUsers() { |
243 RegisterUser(kTestManager); | 243 RegisterUser(kTestManager); |
244 RegisterUser(kTestOtherUser); | 244 RegisterUser(kTestOtherUser); |
245 chromeos::StartupUtils::MarkOobeCompleted(); | 245 chromeos::StartupUtils::MarkOobeCompleted(); |
246 } | 246 } |
247 | 247 |
248 void SupervisedUserTestBase::StartFlowLoginAsManager() { | 248 void SupervisedUserTestBase::StartFlowLoginAsManager() { |
249 // Navigate to supervised user creation screen. | 249 // Navigate to supervised user creation screen. |
250 JSEval("chrome.send('showLocallyManagedUserCreationScreen')"); | 250 JSEval("chrome.send('showSupervisedUserCreationScreen')"); |
251 | 251 |
252 // Read intro and proceed. | 252 // Read intro and proceed. |
253 JSExpect(StringPrintf("%s == 'intro'", kCurrentPage)); | 253 JSExpect(StringPrintf("%s == 'intro'", kCurrentPage)); |
254 | 254 |
255 JSEval("$('managed-user-creation-start-button').click()"); | 255 JSEval("$('supervised-user-creation-start-button').click()"); |
256 | 256 |
257 // Check that both users appear as managers, and test-manager@gmail.com is | 257 // Check that both users appear as managers, and test-manager@gmail.com is |
258 // the first one. | 258 // the first one. |
259 JSExpect(StringPrintf("%s == 'manager'", kCurrentPage)); | 259 JSExpect(StringPrintf("%s == 'manager'", kCurrentPage)); |
260 | 260 |
261 std::string manager_pods = | 261 std::string manager_pods = |
262 "document.querySelectorAll('#managed-user-creation-managers-pane " | 262 "document.querySelectorAll('#supervised-user-creation-managers-pane " |
263 ".manager-pod')"; | 263 ".manager-pod')"; |
264 std::string selected_manager_pods = | 264 std::string selected_manager_pods = |
265 "document.querySelectorAll('#managed-user-creation-managers-pane " | 265 "document.querySelectorAll('#supervised-user-creation-managers-pane " |
266 ".manager-pod.focused')"; | 266 ".manager-pod.focused')"; |
267 | 267 |
268 int managers_on_device = 2; | 268 int managers_on_device = 2; |
269 | 269 |
270 JSExpect(StringPrintf("%s.length == 1", selected_manager_pods.c_str())); | 270 JSExpect(StringPrintf("%s.length == 1", selected_manager_pods.c_str())); |
271 | 271 |
272 JSExpect( | 272 JSExpect(StringPrintf( |
273 StringPrintf("$('managed-user-creation').managerList_.pods.length == %d", | 273 "$('supervised-user-creation').managerList_.pods.length == %d", |
274 managers_on_device)); | 274 managers_on_device)); |
275 JSExpect(StringPrintf( | 275 JSExpect(StringPrintf( |
276 "%s.length == %d", manager_pods.c_str(), managers_on_device)); | 276 "%s.length == %d", manager_pods.c_str(), managers_on_device)); |
277 JSExpect(StringPrintf("%s[%d].user.emailAddress == '%s'", | 277 JSExpect(StringPrintf("%s[%d].user.emailAddress == '%s'", |
278 manager_pods.c_str(), | 278 manager_pods.c_str(), |
279 0, | 279 0, |
280 kTestManager)); | 280 kTestManager)); |
281 | 281 |
282 // Select the first user as manager, and enter password. | 282 // Select the first user as manager, and enter password. |
283 JSExpect("$('managed-user-creation-next-button').disabled"); | 283 JSExpect("$('supervised-user-creation-next-button').disabled"); |
284 JSSetTextField("#managed-user-creation .manager-pod.focused input", | 284 JSSetTextField("#supervised-user-creation .manager-pod.focused input", |
285 kTestManagerPassword); | 285 kTestManagerPassword); |
286 | 286 |
287 JSEval("$('managed-user-creation').updateNextButtonForManager_()"); | 287 JSEval("$('supervised-user-creation').updateNextButtonForManager_()"); |
288 | 288 |
289 // Next button is now enabled. | 289 // Next button is now enabled. |
290 JSExpect("!$('managed-user-creation-next-button').disabled"); | 290 JSExpect("!$('supervised-user-creation-next-button').disabled"); |
291 UserContext user_context(kTestManager); | 291 UserContext user_context(kTestManager); |
292 user_context.SetKey(Key(kTestManagerPassword)); | 292 user_context.SetKey(Key(kTestManagerPassword)); |
293 SetExpectedCredentials(user_context); | 293 SetExpectedCredentials(user_context); |
294 content::WindowedNotificationObserver login_observer( | 294 content::WindowedNotificationObserver login_observer( |
295 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, | 295 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, |
296 content::NotificationService::AllSources()); | 296 content::NotificationService::AllSources()); |
297 | 297 |
298 // Log in as manager. | 298 // Log in as manager. |
299 JSEval("$('managed-user-creation-next-button').click()"); | 299 JSEval("$('supervised-user-creation-next-button').click()"); |
300 login_observer.Wait(); | 300 login_observer.Wait(); |
301 | 301 |
302 // OAuth token is valid. | 302 // OAuth token is valid. |
303 UserManager::Get()->SaveUserOAuthStatus( | 303 UserManager::Get()->SaveUserOAuthStatus( |
304 kTestManager, user_manager::User::OAUTH2_TOKEN_STATUS_VALID); | 304 kTestManager, user_manager::User::OAUTH2_TOKEN_STATUS_VALID); |
305 base::RunLoop().RunUntilIdle(); | 305 base::RunLoop().RunUntilIdle(); |
306 | 306 |
307 // Check the page have changed. | 307 // Check the page have changed. |
308 JSExpect(StringPrintf("%s == 'username'", kCurrentPage)); | 308 JSExpect(StringPrintf("%s == 'username'", kCurrentPage)); |
309 } | 309 } |
310 | 310 |
311 void SupervisedUserTestBase::FillNewUserData(const std::string& display_name) { | 311 void SupervisedUserTestBase::FillNewUserData(const std::string& display_name) { |
312 JSExpect("$('managed-user-creation-next-button').disabled"); | 312 JSExpect("$('supervised-user-creation-next-button').disabled"); |
313 JSSetTextField("#managed-user-creation-name", display_name); | 313 JSSetTextField("#supervised-user-creation-name", display_name); |
314 JSEval("$('managed-user-creation').checkUserName_()"); | 314 JSEval("$('supervised-user-creation').checkUserName_()"); |
315 | 315 |
316 base::RunLoop().RunUntilIdle(); | 316 base::RunLoop().RunUntilIdle(); |
317 | 317 |
318 JSSetTextField("#managed-user-creation-password", | 318 JSSetTextField("#supervised-user-creation-password", |
319 kTestSupervisedUserPassword); | 319 kTestSupervisedUserPassword); |
320 JSSetTextField("#managed-user-creation-password-confirm", | 320 JSSetTextField("#supervised-user-creation-password-confirm", |
321 kTestSupervisedUserPassword); | 321 kTestSupervisedUserPassword); |
322 | 322 |
323 JSEval("$('managed-user-creation').updateNextButtonForUser_()"); | 323 JSEval("$('supervised-user-creation').updateNextButtonForUser_()"); |
324 JSExpect("!$('managed-user-creation-next-button').disabled"); | 324 JSExpect("!$('supervised-user-creation-next-button').disabled"); |
325 } | 325 } |
326 | 326 |
327 void SupervisedUserTestBase::StartUserCreation( | 327 void SupervisedUserTestBase::StartUserCreation( |
328 const std::string& button_id, | 328 const std::string& button_id, |
329 const std::string& expected_display_name) { | 329 const std::string& expected_display_name) { |
330 EXPECT_CALL(*mock_homedir_methods_, MountEx(_, _, _, _)).Times(1); | 330 EXPECT_CALL(*mock_homedir_methods_, MountEx(_, _, _, _)).Times(1); |
331 EXPECT_CALL(*mock_homedir_methods_, AddKeyEx(_, _, _, _, _)).Times(1); | 331 EXPECT_CALL(*mock_homedir_methods_, AddKeyEx(_, _, _, _, _)).Times(1); |
332 | 332 |
333 JSEval(std::string("$('").append(button_id).append("').click()")); | 333 JSEval(std::string("$('").append(button_id).append("').click()")); |
334 | 334 |
335 ::testing::Mock::VerifyAndClearExpectations(mock_homedir_methods_); | 335 ::testing::Mock::VerifyAndClearExpectations(mock_homedir_methods_); |
336 | 336 |
337 EXPECT_TRUE(registration_utility_stub_->register_was_called()); | 337 EXPECT_TRUE(registration_utility_stub_->register_was_called()); |
338 EXPECT_EQ(registration_utility_stub_->display_name(), | 338 EXPECT_EQ(registration_utility_stub_->display_name(), |
339 base::UTF8ToUTF16(expected_display_name)); | 339 base::UTF8ToUTF16(expected_display_name)); |
340 | 340 |
341 registration_utility_stub_->RunSuccessCallback("token"); | 341 registration_utility_stub_->RunSuccessCallback("token"); |
342 | 342 |
343 // Token writing moves control to BlockingPool and back. | 343 // Token writing moves control to BlockingPool and back. |
344 base::RunLoop().RunUntilIdle(); | 344 base::RunLoop().RunUntilIdle(); |
345 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 345 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
346 base::RunLoop().RunUntilIdle(); | 346 base::RunLoop().RunUntilIdle(); |
347 | 347 |
348 JSExpect(StringPrintf("%s == 'created'", kCurrentPage)); | 348 JSExpect(StringPrintf("%s == 'created'", kCurrentPage)); |
349 JSEval("$('managed-user-creation-gotit-button').click()"); | 349 JSEval("$('supervised-user-creation-gotit-button').click()"); |
350 } | 350 } |
351 | 351 |
352 void SupervisedUserTestBase::SigninAsSupervisedUser( | 352 void SupervisedUserTestBase::SigninAsSupervisedUser( |
353 bool check_homedir_calls, | 353 bool check_homedir_calls, |
354 int user_index, | 354 int user_index, |
355 const std::string& expected_display_name) { | 355 const std::string& expected_display_name) { |
356 if (check_homedir_calls) | 356 if (check_homedir_calls) |
357 EXPECT_CALL(*mock_homedir_methods_, MountEx(_, _, _, _)).Times(1); | 357 EXPECT_CALL(*mock_homedir_methods_, MountEx(_, _, _, _)).Times(1); |
358 | 358 |
359 // Log in as supervised user, make sure that everything works. | 359 // Log in as supervised user, make sure that everything works. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 // Confirm deletion. | 426 // Confirm deletion. |
427 JSEval(StringPrintf( | 427 JSEval(StringPrintf( |
428 "$('pod-row').pods[%d].querySelector('.remove-warning-button').click()", | 428 "$('pod-row').pods[%d].querySelector('.remove-warning-button').click()", |
429 user_index)); | 429 user_index)); |
430 | 430 |
431 // Make sure there is no supervised user in list. | 431 // Make sure there is no supervised user in list. |
432 ASSERT_EQ(original_user_count - 1, UserManager::Get()->GetUsers().size()); | 432 ASSERT_EQ(original_user_count - 1, UserManager::Get()->GetUsers().size()); |
433 } | 433 } |
434 | 434 |
435 } // namespace chromeos | 435 } // namespace chromeos |
OLD | NEW |