| 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/signed_settings.h" | 5 #include "chrome/browser/chromeos/login/signed_settings.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 ui_thread_(content::BrowserThread::UI, &message_loop_), | 37 ui_thread_(content::BrowserThread::UI, &message_loop_), |
| 38 file_thread_(content::BrowserThread::FILE, &message_loop_), | 38 file_thread_(content::BrowserThread::FILE, &message_loop_), |
| 39 pointer_factory_(this), | 39 pointer_factory_(this), |
| 40 local_state_(static_cast<TestingBrowserProcess*>(g_browser_process)) { | 40 local_state_(static_cast<TestingBrowserProcess*>(g_browser_process)) { |
| 41 } | 41 } |
| 42 | 42 |
| 43 virtual ~CrosSettingsTest() { | 43 virtual ~CrosSettingsTest() { |
| 44 } | 44 } |
| 45 | 45 |
| 46 virtual void SetUp() { | 46 virtual void SetUp() { |
| 47 mock_user_manager_.reset(new MockUserManager()); | 47 EXPECT_CALL(*mock_user_manager_.user_manager(), IsCurrentUserOwner()) |
| 48 old_user_manager_ = UserManager::Set(mock_user_manager_.get()); | |
| 49 EXPECT_CALL(*mock_user_manager_, IsCurrentUserOwner()) | |
| 50 .Times(AnyNumber()) | 48 .Times(AnyNumber()) |
| 51 .WillRepeatedly(Return(true)); | 49 .WillRepeatedly(Return(true)); |
| 52 // Reset the cache between tests. | 50 // Reset the cache between tests. |
| 53 ApplyEmptyPolicy(); | 51 ApplyEmptyPolicy(); |
| 54 } | 52 } |
| 55 | 53 |
| 56 virtual void TearDown() { | 54 virtual void TearDown() { |
| 57 message_loop_.RunAllPending(); | 55 message_loop_.RunAllPending(); |
| 58 ASSERT_TRUE(expected_props_.empty()); | 56 ASSERT_TRUE(expected_props_.empty()); |
| 59 // Reset the cache between tests. | 57 // Reset the cache between tests. |
| 60 ApplyEmptyPolicy(); | 58 ApplyEmptyPolicy(); |
| 61 STLDeleteValues(&expected_props_); | 59 STLDeleteValues(&expected_props_); |
| 62 UserManager::Set(old_user_manager_); | |
| 63 } | 60 } |
| 64 | 61 |
| 65 void FetchPref(const std::string& pref) { | 62 void FetchPref(const std::string& pref) { |
| 66 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 63 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 67 if (expected_props_.find(pref) == expected_props_.end()) | 64 if (expected_props_.find(pref) == expected_props_.end()) |
| 68 return; | 65 return; |
| 69 | 66 |
| 70 if (CrosSettings::Get()->PrepareTrustedValues( | 67 if (CrosSettings::Get()->PrepareTrustedValues( |
| 71 base::Bind(&CrosSettingsTest::FetchPref, | 68 base::Bind(&CrosSettingsTest::FetchPref, |
| 72 pointer_factory_.GetWeakPtr(), pref))) { | 69 pointer_factory_.GetWeakPtr(), pref))) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 std::map<std::string, base::Value*> expected_props_; | 113 std::map<std::string, base::Value*> expected_props_; |
| 117 | 114 |
| 118 MessageLoop message_loop_; | 115 MessageLoop message_loop_; |
| 119 content::TestBrowserThread ui_thread_; | 116 content::TestBrowserThread ui_thread_; |
| 120 content::TestBrowserThread file_thread_; | 117 content::TestBrowserThread file_thread_; |
| 121 | 118 |
| 122 base::WeakPtrFactory<CrosSettingsTest> pointer_factory_; | 119 base::WeakPtrFactory<CrosSettingsTest> pointer_factory_; |
| 123 | 120 |
| 124 ScopedTestingLocalState local_state_; | 121 ScopedTestingLocalState local_state_; |
| 125 | 122 |
| 126 scoped_ptr<MockUserManager> mock_user_manager_; | 123 ScopedMockUserManagerEnabler mock_user_manager_; |
| 127 UserManager* old_user_manager_; | |
| 128 ScopedStubCrosEnabler stub_cros_enabler_; | 124 ScopedStubCrosEnabler stub_cros_enabler_; |
| 129 }; | 125 }; |
| 130 | 126 |
| 131 TEST_F(CrosSettingsTest, SetPref) { | 127 TEST_F(CrosSettingsTest, SetPref) { |
| 132 // Change to something that is not the default. | 128 // Change to something that is not the default. |
| 133 AddExpectation(kAccountsPrefAllowGuest, | 129 AddExpectation(kAccountsPrefAllowGuest, |
| 134 base::Value::CreateBooleanValue(false)); | 130 base::Value::CreateBooleanValue(false)); |
| 135 SetPref(kAccountsPrefAllowGuest, expected_props_[kAccountsPrefAllowGuest]); | 131 SetPref(kAccountsPrefAllowGuest, expected_props_[kAccountsPrefAllowGuest]); |
| 136 FetchPref(kAccountsPrefAllowGuest); | 132 FetchPref(kAccountsPrefAllowGuest); |
| 137 message_loop_.RunAllPending(); | 133 message_loop_.RunAllPending(); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 | 235 |
| 240 TEST_F(CrosSettingsTest, SetEphemeralUsersEnabled) { | 236 TEST_F(CrosSettingsTest, SetEphemeralUsersEnabled) { |
| 241 base::FundamentalValue ephemeral_users_enabled(true); | 237 base::FundamentalValue ephemeral_users_enabled(true); |
| 242 AddExpectation(kAccountsPrefEphemeralUsersEnabled, | 238 AddExpectation(kAccountsPrefEphemeralUsersEnabled, |
| 243 base::Value::CreateBooleanValue(true)); | 239 base::Value::CreateBooleanValue(true)); |
| 244 SetPref(kAccountsPrefEphemeralUsersEnabled, &ephemeral_users_enabled); | 240 SetPref(kAccountsPrefEphemeralUsersEnabled, &ephemeral_users_enabled); |
| 245 FetchPref(kAccountsPrefEphemeralUsersEnabled); | 241 FetchPref(kAccountsPrefEphemeralUsersEnabled); |
| 246 } | 242 } |
| 247 | 243 |
| 248 } // namespace chromeos | 244 } // namespace chromeos |
| OLD | NEW |