OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/login_utils.h" | 5 #include "chrome/browser/chromeos/login/login_utils.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 #include "testing/gtest/include/gtest/gtest.h" | 42 #include "testing/gtest/include/gtest/gtest.h" |
43 | 43 |
44 namespace chromeos { | 44 namespace chromeos { |
45 | 45 |
46 namespace { | 46 namespace { |
47 | 47 |
48 namespace em = enterprise_management; | 48 namespace em = enterprise_management; |
49 | 49 |
50 using ::testing::DoAll; | 50 using ::testing::DoAll; |
51 using ::testing::Return; | 51 using ::testing::Return; |
| 52 using ::testing::SaveArg; |
52 using ::testing::SetArgPointee; | 53 using ::testing::SetArgPointee; |
53 using ::testing::_; | 54 using ::testing::_; |
54 using content::BrowserThread; | 55 using content::BrowserThread; |
55 | 56 |
56 const char kTrue[] = "true"; | 57 const char kTrue[] = "true"; |
57 const char kDomain[] = "domain.com"; | 58 const char kDomain[] = "domain.com"; |
58 const char kUsername[] = "user@domain.com"; | 59 const char kUsername[] = "user@domain.com"; |
59 const char kMode[] = "enterprise"; | 60 const char kMode[] = "enterprise"; |
60 const char kDeviceId[] = "100200300"; | 61 const char kDeviceId[] = "100200300"; |
61 const char kUsernameOtherDomain[] = "user@other.com"; | 62 const char kUsernameOtherDomain[] = "user@other.com"; |
(...skipping 10 matching lines...) Expand all Loading... |
72 "wrap_access_token=1234&wrap_access_token_expires_in=123456789"; | 73 "wrap_access_token=1234&wrap_access_token_expires_in=123456789"; |
73 | 74 |
74 const char kDMServer[] = "http://server/device_management"; | 75 const char kDMServer[] = "http://server/device_management"; |
75 const char kDMRegisterRequest[] = | 76 const char kDMRegisterRequest[] = |
76 "http://server/device_management?request=register"; | 77 "http://server/device_management?request=register"; |
77 const char kDMPolicyRequest[] = | 78 const char kDMPolicyRequest[] = |
78 "http://server/device_management?request=policy"; | 79 "http://server/device_management?request=policy"; |
79 | 80 |
80 const char kDMToken[] = "1234"; | 81 const char kDMToken[] = "1234"; |
81 | 82 |
82 ACTION_P(MockSessionManagerClientPolicyCallback, policy) { | 83 ACTION_P(MockSessionManagerClientRetrievePolicyCallback, policy) { |
83 arg0.Run(policy); | 84 arg0.Run(*policy); |
| 85 } |
| 86 |
| 87 ACTION_P(MockSessionManagerClientStorePolicyCallback, success) { |
| 88 arg1.Run(success); |
84 } | 89 } |
85 | 90 |
86 template<typename TESTBASE> | 91 template<typename TESTBASE> |
87 class LoginUtilsTestBase : public TESTBASE, | 92 class LoginUtilsTestBase : public TESTBASE, |
88 public LoginUtils::Delegate, | 93 public LoginUtils::Delegate, |
89 public LoginStatusConsumer { | 94 public LoginStatusConsumer { |
90 public: | 95 public: |
91 // Initialization here is important. The UI thread gets the test's | 96 // Initialization here is important. The UI thread gets the test's |
92 // message loop, as does the file thread (which never actually gets | 97 // message loop, as does the file thread (which never actually gets |
93 // started - so this is a way to fake multiple threads on a single | 98 // started - so this is a way to fake multiple threads on a single |
(...skipping 10 matching lines...) Expand all Loading... |
104 ui_thread_(content::BrowserThread::UI, &loop_), | 109 ui_thread_(content::BrowserThread::UI, &loop_), |
105 file_thread_(content::BrowserThread::FILE, &loop_), | 110 file_thread_(content::BrowserThread::FILE, &loop_), |
106 io_thread_(content::BrowserThread::IO), | 111 io_thread_(content::BrowserThread::IO), |
107 mock_async_method_caller_(NULL), | 112 mock_async_method_caller_(NULL), |
108 connector_(NULL), | 113 connector_(NULL), |
109 cryptohome_(NULL), | 114 cryptohome_(NULL), |
110 prepared_profile_(NULL) {} | 115 prepared_profile_(NULL) {} |
111 | 116 |
112 virtual void SetUp() OVERRIDE { | 117 virtual void SetUp() OVERRIDE { |
113 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); | 118 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); |
114 // BrowserPolicyConnector makes the UserPolicyCache read relative to this | |
115 // path. Make sure it's in a clean state. | |
116 PathService::Override(chrome::DIR_USER_DATA, scoped_temp_dir_.path()); | |
117 | 119 |
118 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 120 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
119 command_line->AppendSwitch(switches::kEnableDevicePolicy); | 121 command_line->AppendSwitch(switches::kEnableDevicePolicy); |
120 command_line->AppendSwitchASCII(switches::kDeviceManagementUrl, kDMServer); | 122 command_line->AppendSwitchASCII(switches::kDeviceManagementUrl, kDMServer); |
121 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); | 123 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); |
122 | 124 |
123 local_state_.Get()->RegisterStringPref(prefs::kApplicationLocale, ""); | 125 local_state_.Get()->RegisterStringPref(prefs::kApplicationLocale, ""); |
124 | 126 |
125 // DBusThreadManager should be initialized before io_thread_state_, as | 127 // DBusThreadManager should be initialized before io_thread_state_, as |
126 // DBusThreadManager is used from chromeos::ProxyConfigServiceImpl, | 128 // DBusThreadManager is used from chromeos::ProxyConfigServiceImpl, |
127 // which is part of io_thread_state_. | 129 // which is part of io_thread_state_. |
128 DBusThreadManager::InitializeForTesting(&mock_dbus_thread_manager_); | 130 DBusThreadManager::InitializeForTesting(&mock_dbus_thread_manager_); |
129 | 131 |
130 // Likewise, SessionManagerClient should also be initialized before | 132 // Likewise, SessionManagerClient should also be initialized before |
131 // io_thread_state_. | 133 // io_thread_state_. |
132 MockSessionManagerClient* session_managed_client = | 134 MockSessionManagerClient* session_managed_client = |
133 mock_dbus_thread_manager_.mock_session_manager_client(); | 135 mock_dbus_thread_manager_.mock_session_manager_client(); |
134 EXPECT_CALL(*session_managed_client, RetrieveDevicePolicy(_)) | 136 EXPECT_CALL(*session_managed_client, RetrieveDevicePolicy(_)) |
135 .WillRepeatedly(MockSessionManagerClientPolicyCallback("")); | 137 .WillRepeatedly( |
| 138 MockSessionManagerClientRetrievePolicyCallback(&device_policy_)); |
| 139 EXPECT_CALL(*session_managed_client, RetrieveUserPolicy(_)) |
| 140 .WillRepeatedly( |
| 141 MockSessionManagerClientRetrievePolicyCallback(&user_policy_)); |
| 142 EXPECT_CALL(*session_managed_client, StoreUserPolicy(_, _)) |
| 143 .WillRepeatedly( |
| 144 DoAll(SaveArg<0>(&user_policy_), |
| 145 MockSessionManagerClientStorePolicyCallback(true))); |
136 | 146 |
137 mock_async_method_caller_ = new cryptohome::MockAsyncMethodCaller; | 147 mock_async_method_caller_ = new cryptohome::MockAsyncMethodCaller; |
138 cryptohome::AsyncMethodCaller::InitializeForTesting( | 148 cryptohome::AsyncMethodCaller::InitializeForTesting( |
139 mock_async_method_caller_); | 149 mock_async_method_caller_); |
140 | 150 |
141 io_thread_state_.reset(new IOThread(local_state_.Get(), NULL, NULL)); | 151 io_thread_state_.reset(new IOThread(local_state_.Get(), NULL, NULL)); |
142 browser_process_->SetIOThread(io_thread_state_.get()); | 152 browser_process_->SetIOThread(io_thread_state_.get()); |
143 | 153 |
144 CrosLibrary::TestApi* test_api = CrosLibrary::Get()->GetTestApi(); | 154 CrosLibrary::TestApi* test_api = CrosLibrary::Get()->GetTestApi(); |
145 ASSERT_TRUE(test_api); | 155 ASSERT_TRUE(test_api); |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 | 367 |
358 cryptohome::MockAsyncMethodCaller* mock_async_method_caller_; | 368 cryptohome::MockAsyncMethodCaller* mock_async_method_caller_; |
359 | 369 |
360 policy::BrowserPolicyConnector* connector_; | 370 policy::BrowserPolicyConnector* connector_; |
361 MockCryptohomeLibrary* cryptohome_; | 371 MockCryptohomeLibrary* cryptohome_; |
362 Profile* prepared_profile_; | 372 Profile* prepared_profile_; |
363 | 373 |
364 private: | 374 private: |
365 ScopedTempDir scoped_temp_dir_; | 375 ScopedTempDir scoped_temp_dir_; |
366 | 376 |
| 377 std::string device_policy_; |
| 378 std::string user_policy_; |
| 379 |
367 DISALLOW_COPY_AND_ASSIGN(LoginUtilsTestBase); | 380 DISALLOW_COPY_AND_ASSIGN(LoginUtilsTestBase); |
368 }; | 381 }; |
369 | 382 |
370 class LoginUtilsTest : public LoginUtilsTestBase<testing::Test> { | 383 class LoginUtilsTest : public LoginUtilsTestBase<testing::Test> { |
371 }; | 384 }; |
372 | 385 |
373 class LoginUtilsBlockingLoginTest | 386 class LoginUtilsBlockingLoginTest |
374 : public LoginUtilsTestBase<testing::TestWithParam<int> > { | 387 : public LoginUtilsTestBase<testing::TestWithParam<int> > { |
375 }; | 388 }; |
376 | 389 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 } | 517 } |
505 | 518 |
506 INSTANTIATE_TEST_CASE_P( | 519 INSTANTIATE_TEST_CASE_P( |
507 LoginUtilsBlockingLoginTestInstance, | 520 LoginUtilsBlockingLoginTestInstance, |
508 LoginUtilsBlockingLoginTest, | 521 LoginUtilsBlockingLoginTest, |
509 testing::Values(0, 1, 2, 3, 4, 5)); | 522 testing::Values(0, 1, 2, 3, 4, 5)); |
510 | 523 |
511 } // namespace | 524 } // namespace |
512 | 525 |
513 } | 526 } |
OLD | NEW |