| 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 <cstdlib> | 5 #include <cstdlib> |
| 6 #include <cstring> | 6 #include <cstring> |
| 7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop.h" | |
| 10 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 11 #include "base/prefs/testing_pref_service.h" | 10 #include "base/prefs/testing_pref_service.h" |
| 12 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 13 #include "base/values.h" | 12 #include "base/values.h" |
| 14 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/chromeos/cros/network_library.h" | 14 #include "chrome/browser/chromeos/cros/network_library.h" |
| 16 #include "chrome/browser/chromeos/login/user.h" | 15 #include "chrome/browser/chromeos/login/user.h" |
| 17 #include "chrome/browser/chromeos/login/user_manager.h" | 16 #include "chrome/browser/chromeos/login/user_manager.h" |
| 18 #include "chrome/browser/chromeos/login/user_manager_impl.h" | 17 #include "chrome/browser/chromeos/login/user_manager_impl.h" |
| 19 #include "chrome/browser/chromeos/settings/cros_settings.h" | 18 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 20 #include "chrome/browser/chromeos/settings/cros_settings_names.h" | 19 #include "chrome/browser/chromeos/settings/cros_settings_names.h" |
| 21 #include "chrome/browser/chromeos/settings/cros_settings_provider.h" | 20 #include "chrome/browser/chromeos/settings/cros_settings_provider.h" |
| 22 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 21 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 23 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" | 22 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" |
| 24 #include "chrome/test/base/testing_browser_process.h" | 23 #include "chrome/test/base/testing_browser_process.h" |
| 25 #include "content/public/test/test_browser_thread.h" | 24 #include "content/public/test/test_browser_thread_bundle.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 27 | 26 |
| 28 namespace chromeos { | 27 namespace chromeos { |
| 29 | 28 |
| 30 class UserManagerTest : public testing::Test { | 29 class UserManagerTest : public testing::Test { |
| 31 public: | 30 protected: |
| 32 UserManagerTest() | |
| 33 : message_loop_(base::MessageLoop::TYPE_UI), | |
| 34 ui_thread_(content::BrowserThread::UI, &message_loop_), | |
| 35 file_thread_(content::BrowserThread::FILE, &message_loop_) { | |
| 36 } | |
| 37 | |
| 38 virtual void SetUp() OVERRIDE { | 31 virtual void SetUp() OVERRIDE { |
| 39 cros_settings_ = CrosSettings::Get(); | 32 cros_settings_ = CrosSettings::Get(); |
| 40 | 33 |
| 41 // Replace the real DeviceSettingsProvider with a stub. | 34 // Replace the real DeviceSettingsProvider with a stub. |
| 42 device_settings_provider_ = | 35 device_settings_provider_ = |
| 43 cros_settings_->GetProvider(chromeos::kReportDeviceVersionInfo); | 36 cros_settings_->GetProvider(chromeos::kReportDeviceVersionInfo); |
| 44 EXPECT_TRUE(device_settings_provider_); | 37 EXPECT_TRUE(device_settings_provider_); |
| 45 EXPECT_TRUE( | 38 EXPECT_TRUE( |
| 46 cros_settings_->RemoveSettingsProvider(device_settings_provider_)); | 39 cros_settings_->RemoveSettingsProvider(device_settings_provider_)); |
| 47 cros_settings_->AddSettingsProvider(&stub_settings_provider_); | 40 cros_settings_->AddSettingsProvider(&stub_settings_provider_); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 stub_settings_provider_.Set(kDeviceOwner, owner_value); | 112 stub_settings_provider_.Set(kDeviceOwner, owner_value); |
| 120 stub_settings_provider_.Set(kAccountsPrefSupervisedUsersEnabled, | 113 stub_settings_provider_.Set(kAccountsPrefSupervisedUsersEnabled, |
| 121 base::FundamentalValue(locally_managed_users_enabled)); | 114 base::FundamentalValue(locally_managed_users_enabled)); |
| 122 } | 115 } |
| 123 | 116 |
| 124 void RetrieveTrustedDevicePolicies() { | 117 void RetrieveTrustedDevicePolicies() { |
| 125 GetUserManagerImpl()->RetrieveTrustedDevicePolicies(); | 118 GetUserManagerImpl()->RetrieveTrustedDevicePolicies(); |
| 126 } | 119 } |
| 127 | 120 |
| 128 protected: | 121 protected: |
| 129 base::MessageLoop message_loop_; | 122 content::TestBrowserThreadBundle thread_bundle_; |
| 130 content::TestBrowserThread ui_thread_; | |
| 131 content::TestBrowserThread file_thread_; | |
| 132 | 123 |
| 133 CrosSettings* cros_settings_; | 124 CrosSettings* cros_settings_; |
| 134 CrosSettingsProvider* device_settings_provider_; | 125 CrosSettingsProvider* device_settings_provider_; |
| 135 StubCrosSettingsProvider stub_settings_provider_; | 126 StubCrosSettingsProvider stub_settings_provider_; |
| 136 scoped_ptr<TestingPrefServiceSimple> local_state_; | 127 scoped_ptr<TestingPrefServiceSimple> local_state_; |
| 137 | 128 |
| 138 ScopedTestDeviceSettingsService test_device_settings_service_; | 129 ScopedTestDeviceSettingsService test_device_settings_service_; |
| 139 ScopedStubNetworkLibraryEnabler stub_network_library_enabler_; | 130 ScopedStubNetworkLibraryEnabler stub_network_library_enabler_; |
| 140 ScopedTestCrosSettings test_cros_settings_; | 131 ScopedTestCrosSettings test_cros_settings_; |
| 141 | 132 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 TEST_F(UserManagerTest, DisablingLMUByDeviceSettings) { | 188 TEST_F(UserManagerTest, DisablingLMUByDeviceSettings) { |
| 198 SetDeviceSettings(false, "owner@invalid.domain", false); | 189 SetDeviceSettings(false, "owner@invalid.domain", false); |
| 199 RetrieveTrustedDevicePolicies(); | 190 RetrieveTrustedDevicePolicies(); |
| 200 EXPECT_EQ(GetUserManagerLocallyManagedUsersEnabledByPolicy(), false); | 191 EXPECT_EQ(GetUserManagerLocallyManagedUsersEnabledByPolicy(), false); |
| 201 SetDeviceSettings(false, "owner@invalid.domain", true); | 192 SetDeviceSettings(false, "owner@invalid.domain", true); |
| 202 RetrieveTrustedDevicePolicies(); | 193 RetrieveTrustedDevicePolicies(); |
| 203 EXPECT_EQ(GetUserManagerLocallyManagedUsersEnabledByPolicy(), true); | 194 EXPECT_EQ(GetUserManagerLocallyManagedUsersEnabledByPolicy(), true); |
| 204 } | 195 } |
| 205 | 196 |
| 206 } // namespace chromeos | 197 } // namespace chromeos |
| OLD | NEW |