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

Side by Side Diff: chrome/browser/chromeos/policy/device_status_collector_browsertest.cc

Issue 247283007: Add ScopedStubEnterpriseInstallAttributes for tests to set test install attributes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 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
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/policy/device_status_collector.h" 5 #include "chrome/browser/chromeos/policy/device_status_collector.h"
6 6
7 #include "base/environment.h" 7 #include "base/environment.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 145
146 // Though it is a unit test, this test is linked with browser_tests so that it 146 // Though it is a unit test, this test is linked with browser_tests so that it
147 // runs in a separate process. The intention is to avoid overriding the timezone 147 // runs in a separate process. The intention is to avoid overriding the timezone
148 // environment variable for other tests. 148 // environment variable for other tests.
149 class DeviceStatusCollectorTest : public testing::Test { 149 class DeviceStatusCollectorTest : public testing::Test {
150 public: 150 public:
151 DeviceStatusCollectorTest() 151 DeviceStatusCollectorTest()
152 : ui_thread_(content::BrowserThread::UI, &message_loop_), 152 : ui_thread_(content::BrowserThread::UI, &message_loop_),
153 file_thread_(content::BrowserThread::FILE, &message_loop_), 153 file_thread_(content::BrowserThread::FILE, &message_loop_),
154 io_thread_(content::BrowserThread::IO, &message_loop_), 154 io_thread_(content::BrowserThread::IO, &message_loop_),
155 install_attributes_("managed.com",
156 "user@managed.com",
157 "device_id",
158 DEVICE_MODE_ENTERPRISE),
155 user_manager_(new chromeos::MockUserManager()), 159 user_manager_(new chromeos::MockUserManager()),
156 user_manager_enabler_(user_manager_) { 160 user_manager_enabler_(user_manager_) {
157 // Run this test with a well-known timezone so that Time::LocalMidnight() 161 // Run this test with a well-known timezone so that Time::LocalMidnight()
158 // returns the same values on all machines. 162 // returns the same values on all machines.
159 scoped_ptr<base::Environment> env(base::Environment::Create()); 163 scoped_ptr<base::Environment> env(base::Environment::Create());
160 env->SetVar("TZ", "UTC"); 164 env->SetVar("TZ", "UTC");
161 165
162 TestingDeviceStatusCollector::RegisterPrefs(prefs_.registry()); 166 TestingDeviceStatusCollector::RegisterPrefs(prefs_.registry());
163 167
164 EXPECT_CALL(statistics_provider_, GetMachineStatistic(_, NotNull())) 168 EXPECT_CALL(statistics_provider_, GetMachineStatistic(_, NotNull()))
165 .WillRepeatedly(Return(false)); 169 .WillRepeatedly(Return(false));
166 170
167 // Remove the real DeviceSettingsProvider and replace it with a stub. 171 // Remove the real DeviceSettingsProvider and replace it with a stub.
168 cros_settings_ = chromeos::CrosSettings::Get(); 172 cros_settings_ = chromeos::CrosSettings::Get();
169 device_settings_provider_ = 173 device_settings_provider_ =
170 cros_settings_->GetProvider(chromeos::kReportDeviceVersionInfo); 174 cros_settings_->GetProvider(chromeos::kReportDeviceVersionInfo);
171 EXPECT_TRUE(device_settings_provider_ != NULL); 175 EXPECT_TRUE(device_settings_provider_ != NULL);
172 EXPECT_TRUE( 176 EXPECT_TRUE(
173 cros_settings_->RemoveSettingsProvider(device_settings_provider_)); 177 cros_settings_->RemoveSettingsProvider(device_settings_provider_));
174 cros_settings_->AddSettingsProvider(&stub_settings_provider_); 178 cros_settings_->AddSettingsProvider(&stub_settings_provider_);
175 179
176 // Set up fake install attributes.
177 StubEnterpriseInstallAttributes* attributes =
178 new StubEnterpriseInstallAttributes();
179 attributes->SetDomain("managed.com");
180 attributes->SetRegistrationUser("user@managed.com");
181 BrowserPolicyConnectorChromeOS::SetInstallAttributesForTesting(attributes);
182
183 RestartStatusCollector(); 180 RestartStatusCollector();
184 } 181 }
185 182
186 virtual ~DeviceStatusCollectorTest() { 183 virtual ~DeviceStatusCollectorTest() {
187 // Finish pending tasks. 184 // Finish pending tasks.
188 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 185 content::BrowserThread::GetBlockingPool()->FlushForTesting();
189 message_loop_.RunUntilIdle(); 186 message_loop_.RunUntilIdle();
190 187
191 // Restore the real DeviceSettingsProvider. 188 // Restore the real DeviceSettingsProvider.
192 EXPECT_TRUE( 189 EXPECT_TRUE(
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 } 251 }
255 252
256 // Since this is a unit test running in browser_tests we must do additional 253 // Since this is a unit test running in browser_tests we must do additional
257 // unit test setup and make a TestingBrowserProcess. Must be first member. 254 // unit test setup and make a TestingBrowserProcess. Must be first member.
258 TestingBrowserProcessInitializer initializer_; 255 TestingBrowserProcessInitializer initializer_;
259 base::MessageLoopForUI message_loop_; 256 base::MessageLoopForUI message_loop_;
260 content::TestBrowserThread ui_thread_; 257 content::TestBrowserThread ui_thread_;
261 content::TestBrowserThread file_thread_; 258 content::TestBrowserThread file_thread_;
262 content::TestBrowserThread io_thread_; 259 content::TestBrowserThread io_thread_;
263 260
261 ScopedStubEnterpriseInstallAttributes install_attributes_;
264 TestingPrefServiceSimple prefs_; 262 TestingPrefServiceSimple prefs_;
265 chromeos::system::MockStatisticsProvider statistics_provider_; 263 chromeos::system::MockStatisticsProvider statistics_provider_;
266 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; 264 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
267 chromeos::ScopedTestCrosSettings test_cros_settings_; 265 chromeos::ScopedTestCrosSettings test_cros_settings_;
268 chromeos::CrosSettings* cros_settings_; 266 chromeos::CrosSettings* cros_settings_;
269 chromeos::CrosSettingsProvider* device_settings_provider_; 267 chromeos::CrosSettingsProvider* device_settings_provider_;
270 chromeos::StubCrosSettingsProvider stub_settings_provider_; 268 chromeos::StubCrosSettingsProvider stub_settings_provider_;
271 chromeos::MockUserManager* user_manager_; 269 chromeos::MockUserManager* user_manager_;
272 chromeos::ScopedUserManagerEnabler user_manager_enabler_; 270 chromeos::ScopedUserManagerEnabler user_manager_enabler_;
273 em::DeviceStatusReportRequest status_; 271 em::DeviceStatusReportRequest status_;
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 } 765 }
768 766
769 EXPECT_TRUE(found_match) << "No matching interface for fake device " << i; 767 EXPECT_TRUE(found_match) << "No matching interface for fake device " << i;
770 count++; 768 count++;
771 } 769 }
772 770
773 EXPECT_EQ(count, status_.network_interface_size()); 771 EXPECT_EQ(count, status_.network_interface_size());
774 } 772 }
775 773
776 } // namespace policy 774 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698