| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 | 7 |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/threading/sequenced_worker_pool.h" | 11 #include "base/threading/sequenced_worker_pool.h" |
| 12 #include "chrome/browser/chrome_notification_types.h" | 12 #include "chrome/browser/chrome_notification_types.h" |
| 13 #include "chrome/browser/chromeos/login/login_display_host_impl.h" | 13 #include "chrome/browser/chromeos/login/login_display_host_impl.h" |
| 14 #include "chrome/browser/chromeos/login/login_manager_test.h" | 14 #include "chrome/browser/chromeos/login/login_manager_test.h" |
| 15 #include "chrome/browser/chromeos/login/startup_utils.h" | 15 #include "chrome/browser/chromeos/login/startup_utils.h" |
| 16 #include "chrome/browser/chromeos/login/webui_login_view.h" | 16 #include "chrome/browser/chromeos/login/webui_login_view.h" |
| 17 #include "chrome/browser/chromeos/net/network_portal_detector_test_impl.h" | 17 #include "chrome/browser/chromeos/net/network_portal_detector_test_impl.h" |
| 18 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" | 18 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" |
| 19 #include "chrome/browser/managed_mode/managed_user_registration_utility.h" | 19 #include "chrome/browser/managed_mode/managed_user_registration_utility.h" |
| 20 #include "chrome/browser/managed_mode/managed_user_registration_utility_stub.h" | 20 #include "chrome/browser/managed_mode/managed_user_registration_utility_stub.h" |
| 21 #include "chromeos/cryptohome/mock_async_method_caller.h" | 21 #include "chromeos/cryptohome/mock_async_method_caller.h" |
| 22 #include "chromeos/cryptohome/mock_homedir_methods.h" |
| 22 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
| 23 #include "content/public/test/browser_test_utils.h" | 24 #include "content/public/test/browser_test_utils.h" |
| 24 #include "content/public/test/test_utils.h" | 25 #include "content/public/test/test_utils.h" |
| 25 | 26 |
| 26 using testing::_; | 27 using testing::_; |
| 27 | 28 |
| 28 namespace chromeos { | 29 namespace chromeos { |
| 29 | 30 |
| 30 namespace { | 31 namespace { |
| 31 | 32 |
| 32 const char kStubEthernetServicePath[] = "eth0"; | 33 const char kStubEthernetServicePath[] = "eth0"; |
| 33 | 34 |
| 34 const char kTestManager[] = "test-manager@gmail.com"; | 35 const char kTestManager[] = "test-manager@gmail.com"; |
| 35 const char kTestOtherUser[] = "test-user@gmail.com"; | 36 const char kTestOtherUser[] = "test-user@gmail.com"; |
| 36 | 37 |
| 37 const char kTestManagerPassword[] = "password"; | 38 const char kTestManagerPassword[] = "password"; |
| 38 const char kSupervisedUserDisplayName[] = "John Doe"; | 39 const char kSupervisedUserDisplayName[] = "John Doe"; |
| 39 const char kSupervisedUserPassword[] = "simplepassword"; | 40 const char kSupervisedUserPassword[] = "simplepassword"; |
| 40 | 41 |
| 41 } // namespace | 42 } // namespace |
| 42 | 43 |
| 43 class SupervisedUserTest : public chromeos::LoginManagerTest { | 44 class SupervisedUserTest : public chromeos::LoginManagerTest { |
| 44 protected: | 45 protected: |
| 45 SupervisedUserTest() : LoginManagerTest(true), | 46 SupervisedUserTest() : LoginManagerTest(true), |
| 46 mock_async_method_caller_(NULL), | 47 mock_async_method_caller_(NULL), |
| 48 mock_homedir_methods_(NULL), |
| 47 network_portal_detector_(NULL), | 49 network_portal_detector_(NULL), |
| 48 registration_utility_stub_(NULL) { | 50 registration_utility_stub_(NULL) { |
| 49 } | 51 } |
| 50 | 52 |
| 51 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 53 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 52 LoginManagerTest::SetUpInProcessBrowserTestFixture(); | 54 LoginManagerTest::SetUpInProcessBrowserTestFixture(); |
| 53 mock_async_method_caller_ = new cryptohome::MockAsyncMethodCaller; | 55 mock_async_method_caller_ = new cryptohome::MockAsyncMethodCaller; |
| 54 mock_async_method_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); | 56 mock_async_method_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); |
| 55 cryptohome::AsyncMethodCaller::InitializeForTesting( | 57 cryptohome::AsyncMethodCaller::InitializeForTesting( |
| 56 mock_async_method_caller_); | 58 mock_async_method_caller_); |
| 57 | 59 |
| 60 mock_homedir_methods_ = new cryptohome::MockHomedirMethods; |
| 61 mock_homedir_methods_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); |
| 62 cryptohome::HomedirMethods::InitializeForTesting(mock_homedir_methods_); |
| 63 |
| 58 registration_utility_stub_ = new ManagedUserRegistrationUtilityStub(); | 64 registration_utility_stub_ = new ManagedUserRegistrationUtilityStub(); |
| 59 scoped_utility_.reset( | 65 scoped_utility_.reset( |
| 60 new ScopedTestingManagedUserRegistrationUtility( | 66 new ScopedTestingManagedUserRegistrationUtility( |
| 61 registration_utility_stub_)); | 67 registration_utility_stub_)); |
| 62 | 68 |
| 63 // Setup network portal detector to return online state for both | 69 // Setup network portal detector to return online state for both |
| 64 // ethernet and wifi networks. Ethernet is an active network by | 70 // ethernet and wifi networks. Ethernet is an active network by |
| 65 // default. | 71 // default. |
| 66 network_portal_detector_ = new NetworkPortalDetectorTestImpl(); | 72 network_portal_detector_ = new NetworkPortalDetectorTestImpl(); |
| 67 NetworkPortalDetector::InitializeForTesting(network_portal_detector_); | 73 NetworkPortalDetector::InitializeForTesting(network_portal_detector_); |
| 68 NetworkPortalDetector::CaptivePortalState online_state; | 74 NetworkPortalDetector::CaptivePortalState online_state; |
| 69 online_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE; | 75 online_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE; |
| 70 online_state.response_code = 204; | 76 online_state.response_code = 204; |
| 71 network_portal_detector_->SetDefaultNetworkPathForTesting( | 77 network_portal_detector_->SetDefaultNetworkPathForTesting( |
| 72 kStubEthernetServicePath); | 78 kStubEthernetServicePath); |
| 73 network_portal_detector_->SetDetectionResultsForTesting( | 79 network_portal_detector_->SetDetectionResultsForTesting( |
| 74 kStubEthernetServicePath, online_state); | 80 kStubEthernetServicePath, online_state); |
| 75 } | 81 } |
| 76 | 82 |
| 77 virtual void CleanUpOnMainThread() OVERRIDE { | 83 virtual void CleanUpOnMainThread() OVERRIDE { |
| 78 LoginManagerTest::CleanUpOnMainThread(); | 84 LoginManagerTest::CleanUpOnMainThread(); |
| 79 scoped_utility_.reset(NULL); | 85 scoped_utility_.reset(NULL); |
| 80 } | 86 } |
| 81 | 87 |
| 82 virtual void TearDown() OVERRIDE { | 88 virtual void TearDown() OVERRIDE { |
| 83 cryptohome::AsyncMethodCaller::Shutdown(); | 89 cryptohome::AsyncMethodCaller::Shutdown(); |
| 90 cryptohome::HomedirMethods::Shutdown(); |
| 91 mock_homedir_methods_ = NULL; |
| 84 mock_async_method_caller_ = NULL; | 92 mock_async_method_caller_ = NULL; |
| 85 LoginManagerTest::TearDown(); | 93 LoginManagerTest::TearDown(); |
| 86 } | 94 } |
| 87 | 95 |
| 88 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE { | 96 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE { |
| 89 NetworkPortalDetector::Shutdown(); | 97 NetworkPortalDetector::Shutdown(); |
| 90 } | 98 } |
| 91 | 99 |
| 92 void JSEval(const std::string& script) { | 100 void JSEval(const std::string& script) { |
| 93 EXPECT_TRUE(content::ExecuteScript(web_contents(), script)); | 101 EXPECT_TRUE(content::ExecuteScript(web_contents(), script)); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 116 } | 124 } |
| 117 | 125 |
| 118 void PrepareUsers(); | 126 void PrepareUsers(); |
| 119 void CreateSupervisedUser(); | 127 void CreateSupervisedUser(); |
| 120 void SigninAsSupervisedUser(); | 128 void SigninAsSupervisedUser(); |
| 121 void RemoveSupervisedUser(); | 129 void RemoveSupervisedUser(); |
| 122 void LogInAsManagerAndFillUserData(); | 130 void LogInAsManagerAndFillUserData(); |
| 123 | 131 |
| 124 protected: | 132 protected: |
| 125 cryptohome::MockAsyncMethodCaller* mock_async_method_caller_; | 133 cryptohome::MockAsyncMethodCaller* mock_async_method_caller_; |
| 134 cryptohome::MockHomedirMethods* mock_homedir_methods_; |
| 126 NetworkPortalDetectorTestImpl* network_portal_detector_; | 135 NetworkPortalDetectorTestImpl* network_portal_detector_; |
| 127 ManagedUserRegistrationUtilityStub* registration_utility_stub_; | 136 ManagedUserRegistrationUtilityStub* registration_utility_stub_; |
| 128 scoped_ptr<ScopedTestingManagedUserRegistrationUtility> scoped_utility_; | 137 scoped_ptr<ScopedTestingManagedUserRegistrationUtility> scoped_utility_; |
| 129 | 138 |
| 130 private: | 139 private: |
| 131 DISALLOW_COPY_AND_ASSIGN(SupervisedUserTest); | 140 DISALLOW_COPY_AND_ASSIGN(SupervisedUserTest); |
| 132 }; | 141 }; |
| 133 | 142 |
| 134 void SupervisedUserTest::PrepareUsers() { | 143 void SupervisedUserTest::PrepareUsers() { |
| 135 RegisterUser(kTestManager); | 144 RegisterUser(kTestManager); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 "#managed-user-creation-password-confirm", | 211 "#managed-user-creation-password-confirm", |
| 203 kSupervisedUserPassword); | 212 kSupervisedUserPassword); |
| 204 | 213 |
| 205 JSEval("$('managed-user-creation').updateNextButtonForUser_()"); | 214 JSEval("$('managed-user-creation').updateNextButtonForUser_()"); |
| 206 JSExpect("!$('managed-user-creation-next-button').disabled"); | 215 JSExpect("!$('managed-user-creation-next-button').disabled"); |
| 207 } | 216 } |
| 208 | 217 |
| 209 void SupervisedUserTest::CreateSupervisedUser() { | 218 void SupervisedUserTest::CreateSupervisedUser() { |
| 210 LogInAsManagerAndFillUserData(); | 219 LogInAsManagerAndFillUserData(); |
| 211 | 220 |
| 212 EXPECT_CALL(*mock_async_method_caller_, AsyncMount(_, _, _, _)) | 221 EXPECT_CALL(*mock_homedir_methods_, MountEx(_, _, _, _)).Times(1); |
| 213 .Times(1); | 222 EXPECT_CALL(*mock_homedir_methods_, AddKeyEx(_, _, _, _, _)).Times(1); |
| 214 EXPECT_CALL(*mock_async_method_caller_, AsyncGetSanitizedUsername(_, _)) | |
| 215 .Times(1); | |
| 216 EXPECT_CALL(*mock_async_method_caller_, AsyncAddKey(_, _, _, _)) | |
| 217 .Times(1); | |
| 218 | 223 |
| 219 JSEval("$('managed-user-creation-next-button').click()"); | 224 JSEval("$('managed-user-creation-next-button').click()"); |
| 220 | 225 |
| 221 testing::Mock::VerifyAndClearExpectations(mock_async_method_caller_); | 226 testing::Mock::VerifyAndClearExpectations(mock_homedir_methods_); |
| 222 | 227 |
| 223 EXPECT_TRUE(registration_utility_stub_->register_was_called()); | 228 EXPECT_TRUE(registration_utility_stub_->register_was_called()); |
| 224 EXPECT_EQ(registration_utility_stub_->display_name(), | 229 EXPECT_EQ(registration_utility_stub_->display_name(), |
| 225 base::UTF8ToUTF16(kSupervisedUserDisplayName)); | 230 base::UTF8ToUTF16(kSupervisedUserDisplayName)); |
| 226 | 231 |
| 227 registration_utility_stub_->RunSuccessCallback("token"); | 232 registration_utility_stub_->RunSuccessCallback("token"); |
| 228 | 233 |
| 229 // Token writing moves control to BlockingPool and back. | 234 // Token writing moves control to BlockingPool and back. |
| 230 base::RunLoop().RunUntilIdle(); | 235 base::RunLoop().RunUntilIdle(); |
| 231 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 236 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 232 base::RunLoop().RunUntilIdle(); | 237 base::RunLoop().RunUntilIdle(); |
| 233 | 238 |
| 234 JSExpect("$('managed-user-creation').currentPage_ == 'created'"); | 239 JSExpect("$('managed-user-creation').currentPage_ == 'created'"); |
| 235 JSEval("$('managed-user-creation-gotit-button').click()"); | 240 JSEval("$('managed-user-creation-gotit-button').click()"); |
| 236 } | 241 } |
| 237 | 242 |
| 238 void SupervisedUserTest::SigninAsSupervisedUser() { | 243 void SupervisedUserTest::SigninAsSupervisedUser() { |
| 244 EXPECT_CALL(*mock_homedir_methods_, MountEx(_, _, _, _)).Times(1); |
| 239 // Log in as supervised user, make sure that everything works. | 245 // Log in as supervised user, make sure that everything works. |
| 240 ASSERT_EQ(3UL, UserManager::Get()->GetUsers().size()); | 246 ASSERT_EQ(3UL, UserManager::Get()->GetUsers().size()); |
| 241 // Created supervised user have to be first in a list. | 247 // Created supervised user have to be first in a list. |
| 242 const User* user = UserManager::Get()->GetUsers().at(0); | 248 const User* user = UserManager::Get()->GetUsers().at(0); |
| 243 ASSERT_EQ(base::UTF8ToUTF16(kSupervisedUserDisplayName), | 249 ASSERT_EQ(base::UTF8ToUTF16(kSupervisedUserDisplayName), |
| 244 user->display_name()); | 250 user->display_name()); |
| 245 LoginUser(user->email()); | 251 LoginUser(user->email()); |
| 252 testing::Mock::VerifyAndClearExpectations(mock_homedir_methods_); |
| 246 } | 253 } |
| 247 | 254 |
| 248 void SupervisedUserTest::RemoveSupervisedUser() { | 255 void SupervisedUserTest::RemoveSupervisedUser() { |
| 249 // Remove supervised user. | 256 // Remove supervised user. |
| 250 | 257 |
| 251 ASSERT_EQ(3UL, UserManager::Get()->GetUsers().size()); | 258 ASSERT_EQ(3UL, UserManager::Get()->GetUsers().size()); |
| 252 // Created supervised user have to be first in a list. | 259 // Created supervised user have to be first in a list. |
| 253 const User* user = UserManager::Get()->GetUsers().at(0); | 260 const User* user = UserManager::Get()->GetUsers().at(0); |
| 254 ASSERT_EQ(base::UTF8ToUTF16(kSupervisedUserDisplayName), | 261 ASSERT_EQ(base::UTF8ToUTF16(kSupervisedUserDisplayName), |
| 255 user->display_name()); | 262 user->display_name()); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 | 355 |
| 349 IN_PROC_BROWSER_TEST_F(SupervisedUserTransactionCleanupTest, | 356 IN_PROC_BROWSER_TEST_F(SupervisedUserTransactionCleanupTest, |
| 350 PRE_PRE_CreateAndCancelSupervisedUser) { | 357 PRE_PRE_CreateAndCancelSupervisedUser) { |
| 351 PrepareUsers(); | 358 PrepareUsers(); |
| 352 } | 359 } |
| 353 | 360 |
| 354 IN_PROC_BROWSER_TEST_F(SupervisedUserTransactionCleanupTest, | 361 IN_PROC_BROWSER_TEST_F(SupervisedUserTransactionCleanupTest, |
| 355 PRE_CreateAndCancelSupervisedUser) { | 362 PRE_CreateAndCancelSupervisedUser) { |
| 356 LogInAsManagerAndFillUserData(); | 363 LogInAsManagerAndFillUserData(); |
| 357 | 364 |
| 358 EXPECT_CALL(*mock_async_method_caller_, AsyncMount(_, _, _, _)) | 365 EXPECT_CALL(*mock_homedir_methods_, MountEx(_, _, _, _)).Times(1); |
| 359 .Times(1); | 366 EXPECT_CALL(*mock_homedir_methods_, AddKeyEx(_, _, _, _, _)).Times(1); |
| 360 EXPECT_CALL(*mock_async_method_caller_, AsyncGetSanitizedUsername(_, _)) | |
| 361 .Times(1); | |
| 362 EXPECT_CALL(*mock_async_method_caller_, AsyncAddKey(_, _, _, _)) | |
| 363 .Times(1); | |
| 364 | 367 |
| 365 JSEval("$('managed-user-creation-next-button').click()"); | 368 JSEval("$('managed-user-creation-next-button').click()"); |
| 366 | 369 |
| 367 testing::Mock::VerifyAndClearExpectations(mock_async_method_caller_); | 370 testing::Mock::VerifyAndClearExpectations(mock_homedir_methods_); |
| 368 | 371 |
| 369 EXPECT_TRUE(registration_utility_stub_->register_was_called()); | 372 EXPECT_TRUE(registration_utility_stub_->register_was_called()); |
| 370 EXPECT_EQ(registration_utility_stub_->display_name(), | 373 EXPECT_EQ(registration_utility_stub_->display_name(), |
| 371 base::UTF8ToUTF16(kSupervisedUserDisplayName)); | 374 base::UTF8ToUTF16(kSupervisedUserDisplayName)); |
| 372 | 375 |
| 373 std::string user_id = registration_utility_stub_->managed_user_id(); | 376 std::string user_id = registration_utility_stub_->managed_user_id(); |
| 374 // Make sure user is already in list. | 377 // Make sure user is already in list. |
| 375 ASSERT_EQ(3UL, UserManager::Get()->GetUsers().size()); | 378 ASSERT_EQ(3UL, UserManager::Get()->GetUsers().size()); |
| 376 // We wait for token now. Press cancel button at this point. | 379 // We wait for token now. Press cancel button at this point. |
| 377 JSEval("$('cancel-add-user-button').click()"); | 380 JSEval("$('cancel-add-user-button').click()"); |
| 378 } | 381 } |
| 379 | 382 |
| 380 IN_PROC_BROWSER_TEST_F(SupervisedUserTransactionCleanupTest, | 383 IN_PROC_BROWSER_TEST_F(SupervisedUserTransactionCleanupTest, |
| 381 CreateAndCancelSupervisedUser) { | 384 CreateAndCancelSupervisedUser) { |
| 382 // Make sure there is no supervised user in list. | 385 // Make sure there is no supervised user in list. |
| 383 ASSERT_EQ(2UL, UserManager::Get()->GetUsers().size()); | 386 ASSERT_EQ(2UL, UserManager::Get()->GetUsers().size()); |
| 384 } | 387 } |
| 385 | 388 |
| 386 } // namespace chromeos | 389 } // namespace chromeos |
| OLD | NEW |