Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(683)

Side by Side Diff: chrome/browser/chromeos/login/login_utils_browsertest.cc

Issue 14179007: Move cryptohome_library to src/chromeos (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/prefs/pref_registry_simple.h" 13 #include "base/prefs/pref_registry_simple.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "base/string_util.h" 15 #include "base/string_util.h"
16 #include "base/synchronization/waitable_event.h" 16 #include "base/synchronization/waitable_event.h"
17 #include "base/threading/sequenced_worker_pool.h" 17 #include "base/threading/sequenced_worker_pool.h"
18 #include "base/threading/thread.h" 18 #include "base/threading/thread.h"
19 #include "chrome/browser/chromeos/cros/cros_library.h" 19 #include "chrome/browser/chromeos/cros/cros_library.h"
20 #include "chrome/browser/chromeos/cros/mock_cryptohome_library.h"
21 #include "chrome/browser/chromeos/input_method/input_method_configuration.h" 20 #include "chrome/browser/chromeos/input_method/input_method_configuration.h"
22 #include "chrome/browser/chromeos/input_method/mock_input_method_manager.h" 21 #include "chrome/browser/chromeos/input_method/mock_input_method_manager.h"
23 #include "chrome/browser/chromeos/login/authenticator.h" 22 #include "chrome/browser/chromeos/login/authenticator.h"
24 #include "chrome/browser/chromeos/login/login_status_consumer.h" 23 #include "chrome/browser/chromeos/login/login_status_consumer.h"
25 #include "chrome/browser/chromeos/login/user_manager.h" 24 #include "chrome/browser/chromeos/login/user_manager.h"
26 #include "chrome/browser/chromeos/net/connectivity_state_helper.h" 25 #include "chrome/browser/chromeos/net/connectivity_state_helper.h"
27 #include "chrome/browser/chromeos/net/mock_connectivity_state_helper.h" 26 #include "chrome/browser/chromeos/net/mock_connectivity_state_helper.h"
28 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" 27 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h"
29 #include "chrome/browser/chromeos/settings/cros_settings.h" 28 #include "chrome/browser/chromeos/settings/cros_settings.h"
30 #include "chrome/browser/chromeos/settings/device_settings_service.h" 29 #include "chrome/browser/chromeos/settings/device_settings_service.h"
31 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" 30 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h"
32 #include "chrome/browser/chromeos/settings/mock_owner_key_util.h" 31 #include "chrome/browser/chromeos/settings/mock_owner_key_util.h"
33 #include "chrome/browser/io_thread.h" 32 #include "chrome/browser/io_thread.h"
34 #include "chrome/browser/net/predictor.h" 33 #include "chrome/browser/net/predictor.h"
35 #include "chrome/browser/policy/browser_policy_connector.h" 34 #include "chrome/browser/policy/browser_policy_connector.h"
36 #include "chrome/browser/policy/cloud/device_management_service.h" 35 #include "chrome/browser/policy/cloud/device_management_service.h"
37 #include "chrome/browser/policy/cloud/proto/device_management_backend.pb.h" 36 #include "chrome/browser/policy/cloud/proto/device_management_backend.pb.h"
38 #include "chrome/browser/policy/policy_service.h" 37 #include "chrome/browser/policy/policy_service.h"
39 #include "chrome/browser/profiles/profile_manager.h" 38 #include "chrome/browser/profiles/profile_manager.h"
40 #include "chrome/browser/rlz/rlz.h" 39 #include "chrome/browser/rlz/rlz.h"
41 #include "chrome/common/chrome_notification_types.h" 40 #include "chrome/common/chrome_notification_types.h"
42 #include "chrome/common/chrome_paths.h" 41 #include "chrome/common/chrome_paths.h"
43 #include "chrome/common/chrome_switches.h" 42 #include "chrome/common/chrome_switches.h"
44 #include "chrome/common/pref_names.h" 43 #include "chrome/common/pref_names.h"
45 #include "chrome/test/base/scoped_testing_local_state.h" 44 #include "chrome/test/base/scoped_testing_local_state.h"
46 #include "chrome/test/base/testing_browser_process.h" 45 #include "chrome/test/base/testing_browser_process.h"
47 #include "chromeos/chromeos_switches.h" 46 #include "chromeos/chromeos_switches.h"
48 #include "chromeos/cryptohome/mock_async_method_caller.h" 47 #include "chromeos/cryptohome/mock_async_method_caller.h"
48 #include "chromeos/cryptohome/mock_cryptohome_library.h"
49 #include "chromeos/dbus/mock_cryptohome_client.h" 49 #include "chromeos/dbus/mock_cryptohome_client.h"
50 #include "chromeos/dbus/mock_dbus_thread_manager.h" 50 #include "chromeos/dbus/mock_dbus_thread_manager.h"
51 #include "chromeos/dbus/mock_session_manager_client.h" 51 #include "chromeos/dbus/mock_session_manager_client.h"
52 #include "chromeos/disks/disk_mount_manager.h" 52 #include "chromeos/disks/disk_mount_manager.h"
53 #include "chromeos/disks/mock_disk_mount_manager.h" 53 #include "chromeos/disks/mock_disk_mount_manager.h"
54 #include "chromeos/login/login_state.h" 54 #include "chromeos/login/login_state.h"
55 #include "content/public/browser/browser_thread.h" 55 #include "content/public/browser/browser_thread.h"
56 #include "content/public/test/test_browser_thread.h" 56 #include "content/public/test/test_browser_thread.h"
57 #include "content/public/test/test_utils.h" 57 #include "content/public/test/test_utils.h"
58 #include "google_apis/gaia/gaia_auth_consumer.h" 58 #include "google_apis/gaia/gaia_auth_consumer.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 // loop for the IO thread. 167 // loop for the IO thread.
168 LoginUtilsTest() 168 LoginUtilsTest()
169 : fake_io_thread_completion_(false, false), 169 : fake_io_thread_completion_(false, false),
170 fake_io_thread_("fake_io_thread"), 170 fake_io_thread_("fake_io_thread"),
171 loop_(MessageLoop::TYPE_IO), 171 loop_(MessageLoop::TYPE_IO),
172 browser_process_(TestingBrowserProcess::GetGlobal()), 172 browser_process_(TestingBrowserProcess::GetGlobal()),
173 local_state_(browser_process_), 173 local_state_(browser_process_),
174 ui_thread_(BrowserThread::UI, &loop_), 174 ui_thread_(BrowserThread::UI, &loop_),
175 db_thread_(BrowserThread::DB, &loop_), 175 db_thread_(BrowserThread::DB, &loop_),
176 file_thread_(BrowserThread::FILE, &loop_), 176 file_thread_(BrowserThread::FILE, &loop_),
177 mock_input_method_manager_(NULL),
177 mock_async_method_caller_(NULL), 178 mock_async_method_caller_(NULL),
178 connector_(NULL), 179 connector_(NULL),
179 cryptohome_(NULL), 180 cryptohome_(NULL),
180 cryptohome_client_(NULL), 181 cryptohome_client_(NULL),
181 prepared_profile_(NULL) {} 182 prepared_profile_(NULL) {}
182 183
183 virtual void SetUp() OVERRIDE { 184 virtual void SetUp() OVERRIDE {
184 // This test is not a full blown InProcessBrowserTest, and doesn't have 185 // This test is not a full blown InProcessBrowserTest, and doesn't have
185 // all the usual threads running. However a lot of subsystems pulled from 186 // all the usual threads running. However a lot of subsystems pulled from
186 // ProfileImpl post to IO (usually from ProfileIOData), and DCHECK that 187 // ProfileImpl post to IO (usually from ProfileIOData), and DCHECK that
(...skipping 28 matching lines...) Expand all
215 CommandLine* command_line = CommandLine::ForCurrentProcess(); 216 CommandLine* command_line = CommandLine::ForCurrentProcess();
216 command_line->AppendSwitchASCII( 217 command_line->AppendSwitchASCII(
217 ::switches::kDeviceManagementUrl, kDMServer); 218 ::switches::kDeviceManagementUrl, kDMServer);
218 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); 219 command_line->AppendSwitchASCII(switches::kLoginProfile, "user");
219 220
220 // DBusThreadManager should be initialized before io_thread_state_, as 221 // DBusThreadManager should be initialized before io_thread_state_, as
221 // DBusThreadManager is used from chromeos::ProxyConfigServiceImpl, 222 // DBusThreadManager is used from chromeos::ProxyConfigServiceImpl,
222 // which is part of io_thread_state_. 223 // which is part of io_thread_state_.
223 DBusThreadManager::InitializeForTesting(&mock_dbus_thread_manager_); 224 DBusThreadManager::InitializeForTesting(&mock_dbus_thread_manager_);
224 225
226 CryptohomeLibrary::Initialize();
225 LoginState::Initialize(); 227 LoginState::Initialize();
226 ConnectivityStateHelper::InitializeForTesting( 228 ConnectivityStateHelper::SetForTest(&mock_connectivity_state_helper_);
227 &mock_connectivity_state_helper_);
228 229
229 input_method::InitializeForTesting(&mock_input_method_manager_); 230 mock_input_method_manager_ = new input_method::MockInputMethodManager();
231 input_method::InitializeForTesting(mock_input_method_manager_);
230 disks::DiskMountManager::InitializeForTesting(&mock_disk_mount_manager_); 232 disks::DiskMountManager::InitializeForTesting(&mock_disk_mount_manager_);
231 mock_disk_mount_manager_.SetupDefaultReplies(); 233 mock_disk_mount_manager_.SetupDefaultReplies();
232 234
233 // Likewise, SessionManagerClient should also be initialized before 235 // Likewise, SessionManagerClient should also be initialized before
234 // io_thread_state_. 236 // io_thread_state_.
235 MockSessionManagerClient* session_managed_client = 237 MockSessionManagerClient* session_managed_client =
236 mock_dbus_thread_manager_.mock_session_manager_client(); 238 mock_dbus_thread_manager_.mock_session_manager_client();
237 EXPECT_CALL(*session_managed_client, RetrieveDevicePolicy(_)) 239 EXPECT_CALL(*session_managed_client, RetrieveDevicePolicy(_))
238 .WillRepeatedly( 240 .WillRepeatedly(
239 MockSessionManagerClientRetrievePolicyCallback(&device_policy_)); 241 MockSessionManagerClientRetrievePolicyCallback(&device_policy_));
240 EXPECT_CALL(*session_managed_client, RetrieveUserPolicy(_)) 242 EXPECT_CALL(*session_managed_client, RetrieveUserPolicy(_))
241 .WillRepeatedly( 243 .WillRepeatedly(
242 MockSessionManagerClientRetrievePolicyCallback(&user_policy_)); 244 MockSessionManagerClientRetrievePolicyCallback(&user_policy_));
243 EXPECT_CALL(*session_managed_client, StoreUserPolicy(_, _)) 245 EXPECT_CALL(*session_managed_client, StoreUserPolicy(_, _))
244 .WillRepeatedly( 246 .WillRepeatedly(
245 DoAll(SaveArg<0>(&user_policy_), 247 DoAll(SaveArg<0>(&user_policy_),
246 MockSessionManagerClientStorePolicyCallback(true))); 248 MockSessionManagerClientStorePolicyCallback(true)));
247 249
248 mock_async_method_caller_ = new cryptohome::MockAsyncMethodCaller; 250 mock_async_method_caller_ = new cryptohome::MockAsyncMethodCaller;
249 cryptohome::AsyncMethodCaller::InitializeForTesting( 251 cryptohome::AsyncMethodCaller::InitializeForTesting(
250 mock_async_method_caller_); 252 mock_async_method_caller_);
251 253
252 CrosLibrary::TestApi* test_api = CrosLibrary::Get()->GetTestApi(); 254 cryptohome_.reset(new MockCryptohomeLibrary());
253 ASSERT_TRUE(test_api);
254
255 cryptohome_ = new MockCryptohomeLibrary();
256 EXPECT_CALL(*cryptohome_, InstallAttributesIsInvalid()) 255 EXPECT_CALL(*cryptohome_, InstallAttributesIsInvalid())
257 .WillRepeatedly(Return(false)); 256 .WillRepeatedly(Return(false));
258 EXPECT_CALL(*cryptohome_, InstallAttributesIsFirstInstall()) 257 EXPECT_CALL(*cryptohome_, InstallAttributesIsFirstInstall())
259 .WillRepeatedly(Return(true)); 258 .WillRepeatedly(Return(true));
260 EXPECT_CALL(*cryptohome_, TpmIsEnabled()) 259 EXPECT_CALL(*cryptohome_, TpmIsEnabled())
261 .WillRepeatedly(Return(false)); 260 .WillRepeatedly(Return(false));
262 EXPECT_CALL(*cryptohome_, InstallAttributesSet(kAttributeOwned, kTrue)) 261 EXPECT_CALL(*cryptohome_, InstallAttributesSet(kAttributeOwned, kTrue))
263 .WillRepeatedly(Return(true)); 262 .WillRepeatedly(Return(true));
264 EXPECT_CALL(*cryptohome_, InstallAttributesSet(kAttributeOwner, 263 EXPECT_CALL(*cryptohome_, InstallAttributesSet(kAttributeOwner,
265 kUsername)) 264 kUsername))
(...skipping 17 matching lines...) Expand all
283 Return(true))); 282 Return(true)));
284 EXPECT_CALL(*cryptohome_, InstallAttributesGet(kAttrEnterpriseDomain, _)) 283 EXPECT_CALL(*cryptohome_, InstallAttributesGet(kAttrEnterpriseDomain, _))
285 .WillRepeatedly(DoAll(SetArgPointee<1>(kDomain), 284 .WillRepeatedly(DoAll(SetArgPointee<1>(kDomain),
286 Return(true))); 285 Return(true)));
287 EXPECT_CALL(*cryptohome_, InstallAttributesGet(kAttrEnterpriseMode, _)) 286 EXPECT_CALL(*cryptohome_, InstallAttributesGet(kAttrEnterpriseMode, _))
288 .WillRepeatedly(DoAll(SetArgPointee<1>(kMode), 287 .WillRepeatedly(DoAll(SetArgPointee<1>(kMode),
289 Return(true))); 288 Return(true)));
290 EXPECT_CALL(*cryptohome_, InstallAttributesGet(kAttrEnterpriseDeviceId, _)) 289 EXPECT_CALL(*cryptohome_, InstallAttributesGet(kAttrEnterpriseDeviceId, _))
291 .WillRepeatedly(DoAll(SetArgPointee<1>(kDeviceId), 290 .WillRepeatedly(DoAll(SetArgPointee<1>(kDeviceId),
292 Return(true))); 291 Return(true)));
293 test_api->SetCryptohomeLibrary(cryptohome_, true); 292 CryptohomeLibrary::SetForTest(cryptohome_.get());
294 293
295 cryptohome_client_ = mock_dbus_thread_manager_.mock_cryptohome_client(); 294 cryptohome_client_ = mock_dbus_thread_manager_.mock_cryptohome_client();
296 EXPECT_CALL(*cryptohome_client_, IsMounted(_)); 295 EXPECT_CALL(*cryptohome_client_, IsMounted(_));
297 296
298 test_device_settings_service_.reset(new ScopedTestDeviceSettingsService); 297 test_device_settings_service_.reset(new ScopedTestDeviceSettingsService);
299 test_cros_settings_.reset(new ScopedTestCrosSettings); 298 test_cros_settings_.reset(new ScopedTestCrosSettings);
300 test_user_manager_.reset(new ScopedTestUserManager); 299 test_user_manager_.reset(new ScopedTestUserManager);
301 300
302 browser_process_->SetProfileManager( 301 browser_process_->SetProfileManager(
303 new ProfileManagerWithoutInit(scoped_temp_dir_.path())); 302 new ProfileManagerWithoutInit(scoped_temp_dir_.path()));
(...skipping 20 matching lines...) Expand all
324 mock_async_method_caller_ = NULL; 323 mock_async_method_caller_ = NULL;
325 324
326 test_user_manager_.reset(); 325 test_user_manager_.reset();
327 326
328 InvokeOnIO( 327 InvokeOnIO(
329 base::Bind(&LoginUtilsTest::TearDownOnIO, base::Unretained(this))); 328 base::Bind(&LoginUtilsTest::TearDownOnIO, base::Unretained(this)));
330 329
331 // LoginUtils instance must not outlive Profile instances. 330 // LoginUtils instance must not outlive Profile instances.
332 LoginUtils::Set(NULL); 331 LoginUtils::Set(NULL);
333 332
333 input_method::Shutdown();
334 ConnectivityStateHelper::SetForTest(NULL);
334 LoginState::Shutdown(); 335 LoginState::Shutdown();
336 CryptohomeLibrary::Shutdown();
335 337
336 // These trigger some tasks that have to run while BrowserThread::UI 338 // These trigger some tasks that have to run while BrowserThread::UI
337 // exists. Delete all the profiles before deleting the connector. 339 // exists. Delete all the profiles before deleting the connector.
338 browser_process_->SetProfileManager(NULL); 340 browser_process_->SetProfileManager(NULL);
339 connector_ = NULL; 341 connector_ = NULL;
340 browser_process_->SetBrowserPolicyConnector(NULL); 342 browser_process_->SetBrowserPolicyConnector(NULL);
341 QuitIOLoop(); 343 QuitIOLoop();
342 RunUntilIdle(); 344 RunUntilIdle();
345
346 CryptohomeLibrary::SetForTest(NULL);
343 } 347 }
344 348
345 void TearDownOnIO() { 349 void TearDownOnIO() {
346 // chrome_browser_net::Predictor usually skips its shutdown routines on 350 // chrome_browser_net::Predictor usually skips its shutdown routines on
347 // unit_tests, but does the full thing when 351 // unit_tests, but does the full thing when
348 // g_browser_process->profile_manager() is valid during initialization. 352 // g_browser_process->profile_manager() is valid during initialization.
349 // That includes a WaitableEvent on UI waiting for a task on IO, so that 353 // That includes a WaitableEvent on UI waiting for a task on IO, so that
350 // task must execute. Do it directly from here now. 354 // task must execute. Do it directly from here now.
351 std::vector<Profile*> profiles = 355 std::vector<Profile*> profiles =
352 browser_process_->profile_manager()->GetLoadedProfiles(); 356 browser_process_->profile_manager()->GetLoadedProfiles();
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 TestingBrowserProcess* browser_process_; 532 TestingBrowserProcess* browser_process_;
529 ScopedTestingLocalState local_state_; 533 ScopedTestingLocalState local_state_;
530 534
531 content::TestBrowserThread ui_thread_; 535 content::TestBrowserThread ui_thread_;
532 content::TestBrowserThread db_thread_; 536 content::TestBrowserThread db_thread_;
533 content::TestBrowserThread file_thread_; 537 content::TestBrowserThread file_thread_;
534 scoped_ptr<content::TestBrowserThread> io_thread_; 538 scoped_ptr<content::TestBrowserThread> io_thread_;
535 scoped_ptr<IOThread> io_thread_state_; 539 scoped_ptr<IOThread> io_thread_state_;
536 540
537 MockDBusThreadManager mock_dbus_thread_manager_; 541 MockDBusThreadManager mock_dbus_thread_manager_;
538 input_method::MockInputMethodManager mock_input_method_manager_; 542 input_method::MockInputMethodManager* mock_input_method_manager_;
539 disks::MockDiskMountManager mock_disk_mount_manager_; 543 disks::MockDiskMountManager mock_disk_mount_manager_;
540 net::TestURLFetcherFactory test_url_fetcher_factory_; 544 net::TestURLFetcherFactory test_url_fetcher_factory_;
541 MockConnectivityStateHelper mock_connectivity_state_helper_; 545 MockConnectivityStateHelper mock_connectivity_state_helper_;
542 546
543 cryptohome::MockAsyncMethodCaller* mock_async_method_caller_; 547 cryptohome::MockAsyncMethodCaller* mock_async_method_caller_;
544 548
545 policy::BrowserPolicyConnector* connector_; 549 policy::BrowserPolicyConnector* connector_;
546 MockCryptohomeLibrary* cryptohome_; 550 scoped_ptr<MockCryptohomeLibrary> cryptohome_;
547 MockCryptohomeClient* cryptohome_client_; 551 MockCryptohomeClient* cryptohome_client_;
548 552
549 // Initialized after |mock_dbus_thread_manager_| and |cryptohome_| are set up. 553 // Initialized after |mock_dbus_thread_manager_| and |cryptohome_| are set up.
550 scoped_ptr<ScopedTestDeviceSettingsService> test_device_settings_service_; 554 scoped_ptr<ScopedTestDeviceSettingsService> test_device_settings_service_;
551 scoped_ptr<ScopedTestCrosSettings> test_cros_settings_; 555 scoped_ptr<ScopedTestCrosSettings> test_cros_settings_;
552 scoped_ptr<ScopedTestUserManager> test_user_manager_; 556 scoped_ptr<ScopedTestUserManager> test_user_manager_;
553 557
554 Profile* prepared_profile_; 558 Profile* prepared_profile_;
555 559
556 base::Closure rlz_initialized_cb_; 560 base::Closure rlz_initialized_cb_;
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 } 747 }
744 748
745 INSTANTIATE_TEST_CASE_P( 749 INSTANTIATE_TEST_CASE_P(
746 LoginUtilsBlockingLoginTestInstance, 750 LoginUtilsBlockingLoginTestInstance,
747 LoginUtilsBlockingLoginTest, 751 LoginUtilsBlockingLoginTest,
748 testing::Values(0, 1, 2, 3, 4, 5)); 752 testing::Values(0, 1, 2, 3, 4, 5));
749 753
750 } // namespace 754 } // namespace
751 755
752 } 756 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698