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

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

Issue 1557693002: Convert Pass()→std::move() in //chrome/browser/chromeos/policy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 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/status_uploader.h"
6
7 #include <utility>
8
5 #include "base/prefs/testing_pref_service.h" 9 #include "base/prefs/testing_pref_service.h"
6 #include "base/test/test_simple_task_runner.h" 10 #include "base/test/test_simple_task_runner.h"
7 #include "base/time/time.h" 11 #include "base/time/time.h"
8 #include "chrome/browser/chromeos/policy/device_local_account.h" 12 #include "chrome/browser/chromeos/policy/device_local_account.h"
9 #include "chrome/browser/chromeos/policy/device_status_collector.h" 13 #include "chrome/browser/chromeos/policy/device_status_collector.h"
10 #include "chrome/browser/chromeos/policy/status_uploader.h"
11 #include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h" 14 #include "chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h"
12 #include "chromeos/settings/cros_settings_names.h" 15 #include "chromeos/settings/cros_settings_names.h"
13 #include "components/policy/core/common/cloud/cloud_policy_client.h" 16 #include "components/policy/core/common/cloud/cloud_policy_client.h"
14 #include "components/policy/core/common/cloud/mock_cloud_policy_client.h" 17 #include "components/policy/core/common/cloud/mock_cloud_policy_client.h"
15 #include "components/policy/core/common/cloud/mock_device_management_service.h" 18 #include "components/policy/core/common/cloud/mock_device_management_service.h"
16 #include "content/public/test/test_browser_thread_bundle.h" 19 #include "content/public/test/test_browser_thread_bundle.h"
17 #include "content/public/test/test_utils.h" 20 #include "content/public/test/test_utils.h"
18 #include "net/url_request/url_request_context_getter.h" 21 #include "net/url_request/url_request_context_getter.h"
19 #include "testing/gmock/include/gmock/gmock.h" 22 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 chromeos::ScopedCrosSettingsTestHelper settings_helper_; 132 chromeos::ScopedCrosSettingsTestHelper settings_helper_;
130 scoped_ptr<MockDeviceStatusCollector> collector_; 133 scoped_ptr<MockDeviceStatusCollector> collector_;
131 ui::UserActivityDetector detector_; 134 ui::UserActivityDetector detector_;
132 MockCloudPolicyClient client_; 135 MockCloudPolicyClient client_;
133 MockDeviceManagementService device_management_service_; 136 MockDeviceManagementService device_management_service_;
134 TestingPrefServiceSimple prefs_; 137 TestingPrefServiceSimple prefs_;
135 }; 138 };
136 139
137 TEST_F(StatusUploaderTest, BasicTest) { 140 TEST_F(StatusUploaderTest, BasicTest) {
138 EXPECT_TRUE(task_runner_->GetPendingTasks().empty()); 141 EXPECT_TRUE(task_runner_->GetPendingTasks().empty());
139 StatusUploader uploader(&client_, collector_.Pass(), task_runner_); 142 StatusUploader uploader(&client_, std::move(collector_), task_runner_);
140 EXPECT_EQ(1U, task_runner_->GetPendingTasks().size()); 143 EXPECT_EQ(1U, task_runner_->GetPendingTasks().size());
141 // On startup, first update should happen immediately. 144 // On startup, first update should happen immediately.
142 EXPECT_EQ(base::TimeDelta(), task_runner_->NextPendingTaskDelay()); 145 EXPECT_EQ(base::TimeDelta(), task_runner_->NextPendingTaskDelay());
143 } 146 }
144 147
145 TEST_F(StatusUploaderTest, DifferentFrequencyAtStart) { 148 TEST_F(StatusUploaderTest, DifferentFrequencyAtStart) {
146 // Keep a pointer to the mock collector because collector_ gets cleared 149 // Keep a pointer to the mock collector because collector_ gets cleared
147 // when it is passed to the StatusUploader constructor below. 150 // when it is passed to the StatusUploader constructor below.
148 MockDeviceStatusCollector* const mock_collector = collector_.get(); 151 MockDeviceStatusCollector* const mock_collector = collector_.get();
149 const int new_delay = StatusUploader::kDefaultUploadDelayMs * 2; 152 const int new_delay = StatusUploader::kDefaultUploadDelayMs * 2;
150 settings_helper_.SetInteger(chromeos::kReportUploadFrequency, new_delay); 153 settings_helper_.SetInteger(chromeos::kReportUploadFrequency, new_delay);
151 const base::TimeDelta expected_delay = base::TimeDelta::FromMilliseconds( 154 const base::TimeDelta expected_delay = base::TimeDelta::FromMilliseconds(
152 new_delay); 155 new_delay);
153 EXPECT_TRUE(task_runner_->GetPendingTasks().empty()); 156 EXPECT_TRUE(task_runner_->GetPendingTasks().empty());
154 StatusUploader uploader(&client_, collector_.Pass(), task_runner_); 157 StatusUploader uploader(&client_, std::move(collector_), task_runner_);
155 ASSERT_EQ(1U, task_runner_->GetPendingTasks().size()); 158 ASSERT_EQ(1U, task_runner_->GetPendingTasks().size());
156 // On startup, first update should happen immediately. 159 // On startup, first update should happen immediately.
157 EXPECT_EQ(base::TimeDelta(), task_runner_->NextPendingTaskDelay()); 160 EXPECT_EQ(base::TimeDelta(), task_runner_->NextPendingTaskDelay());
158 161
159 EXPECT_CALL(*mock_collector, GetDeviceStatus(_)).WillRepeatedly(Return(true)); 162 EXPECT_CALL(*mock_collector, GetDeviceStatus(_)).WillRepeatedly(Return(true));
160 EXPECT_CALL(*mock_collector, GetDeviceSessionStatus(_)).WillRepeatedly( 163 EXPECT_CALL(*mock_collector, GetDeviceSessionStatus(_)).WillRepeatedly(
161 Return(true)); 164 Return(true));
162 // Second update should use the delay specified in settings. 165 // Second update should use the delay specified in settings.
163 RunPendingUploadTaskAndCheckNext(uploader, expected_delay); 166 RunPendingUploadTaskAndCheckNext(uploader, expected_delay);
164 } 167 }
165 168
166 TEST_F(StatusUploaderTest, ResetTimerAfterStatusCollection) { 169 TEST_F(StatusUploaderTest, ResetTimerAfterStatusCollection) {
167 // Keep a pointer to the mock collector because collector_ gets cleared 170 // Keep a pointer to the mock collector because collector_ gets cleared
168 // when it is passed to the StatusUploader constructor below. 171 // when it is passed to the StatusUploader constructor below.
169 MockDeviceStatusCollector* const mock_collector = collector_.get(); 172 MockDeviceStatusCollector* const mock_collector = collector_.get();
170 StatusUploader uploader(&client_, collector_.Pass(), task_runner_); 173 StatusUploader uploader(&client_, std::move(collector_), task_runner_);
171 EXPECT_CALL(*mock_collector, GetDeviceStatus(_)).WillRepeatedly(Return(true)); 174 EXPECT_CALL(*mock_collector, GetDeviceStatus(_)).WillRepeatedly(Return(true));
172 EXPECT_CALL(*mock_collector, GetDeviceSessionStatus(_)).WillRepeatedly( 175 EXPECT_CALL(*mock_collector, GetDeviceSessionStatus(_)).WillRepeatedly(
173 Return(true)); 176 Return(true));
174 const base::TimeDelta expected_delay = base::TimeDelta::FromMilliseconds( 177 const base::TimeDelta expected_delay = base::TimeDelta::FromMilliseconds(
175 StatusUploader::kDefaultUploadDelayMs); 178 StatusUploader::kDefaultUploadDelayMs);
176 RunPendingUploadTaskAndCheckNext(uploader, expected_delay); 179 RunPendingUploadTaskAndCheckNext(uploader, expected_delay);
177 180
178 // Handle this response also, and ensure new task is queued. 181 // Handle this response also, and ensure new task is queued.
179 RunPendingUploadTaskAndCheckNext(uploader, expected_delay); 182 RunPendingUploadTaskAndCheckNext(uploader, expected_delay);
180 183
181 // Now that the previous request was satisfied, a task to do the next 184 // Now that the previous request was satisfied, a task to do the next
182 // upload should be queued again. 185 // upload should be queued again.
183 EXPECT_EQ(1U, task_runner_->GetPendingTasks().size()); 186 EXPECT_EQ(1U, task_runner_->GetPendingTasks().size());
184 } 187 }
185 188
186 TEST_F(StatusUploaderTest, ResetTimerAfterFailedStatusCollection) { 189 TEST_F(StatusUploaderTest, ResetTimerAfterFailedStatusCollection) {
187 // Keep a pointer to the mock collector because collector_ gets cleared 190 // Keep a pointer to the mock collector because collector_ gets cleared
188 // when it is passed to the StatusUploader constructor below. 191 // when it is passed to the StatusUploader constructor below.
189 MockDeviceStatusCollector* mock_collector = collector_.get(); 192 MockDeviceStatusCollector* mock_collector = collector_.get();
190 StatusUploader uploader(&client_, collector_.Pass(), task_runner_); 193 StatusUploader uploader(&client_, std::move(collector_), task_runner_);
191 EXPECT_CALL(*mock_collector, GetDeviceStatus(_)).WillOnce(Return(false)); 194 EXPECT_CALL(*mock_collector, GetDeviceStatus(_)).WillOnce(Return(false));
192 EXPECT_CALL(*mock_collector, GetDeviceSessionStatus(_)).WillOnce( 195 EXPECT_CALL(*mock_collector, GetDeviceSessionStatus(_)).WillOnce(
193 Return(false)); 196 Return(false));
194 task_runner_->RunPendingTasks(); 197 task_runner_->RunPendingTasks();
195 198
196 // Make sure the next status upload is queued up. 199 // Make sure the next status upload is queued up.
197 EXPECT_EQ(1U, task_runner_->GetPendingTasks().size()); 200 EXPECT_EQ(1U, task_runner_->GetPendingTasks().size());
198 const base::TimeDelta expected_delay = base::TimeDelta::FromMilliseconds( 201 const base::TimeDelta expected_delay = base::TimeDelta::FromMilliseconds(
199 StatusUploader::kDefaultUploadDelayMs); 202 StatusUploader::kDefaultUploadDelayMs);
200 CheckPendingTaskDelay(uploader, expected_delay); 203 CheckPendingTaskDelay(uploader, expected_delay);
201 } 204 }
202 205
203 TEST_F(StatusUploaderTest, ChangeFrequency) { 206 TEST_F(StatusUploaderTest, ChangeFrequency) {
204 // Keep a pointer to the mock collector because collector_ gets cleared 207 // Keep a pointer to the mock collector because collector_ gets cleared
205 // when it is passed to the StatusUploader constructor below. 208 // when it is passed to the StatusUploader constructor below.
206 MockDeviceStatusCollector* const mock_collector = collector_.get(); 209 MockDeviceStatusCollector* const mock_collector = collector_.get();
207 StatusUploader uploader(&client_, collector_.Pass(), task_runner_); 210 StatusUploader uploader(&client_, std::move(collector_), task_runner_);
208 EXPECT_CALL(*mock_collector, GetDeviceStatus(_)).WillRepeatedly(Return(true)); 211 EXPECT_CALL(*mock_collector, GetDeviceStatus(_)).WillRepeatedly(Return(true));
209 EXPECT_CALL(*mock_collector, GetDeviceSessionStatus(_)).WillRepeatedly( 212 EXPECT_CALL(*mock_collector, GetDeviceSessionStatus(_)).WillRepeatedly(
210 Return(true)); 213 Return(true));
211 // Change the frequency. The new frequency should be reflected in the timing 214 // Change the frequency. The new frequency should be reflected in the timing
212 // used for the next callback. 215 // used for the next callback.
213 const int new_delay = StatusUploader::kDefaultUploadDelayMs * 2; 216 const int new_delay = StatusUploader::kDefaultUploadDelayMs * 2;
214 settings_helper_.SetInteger(chromeos::kReportUploadFrequency, new_delay); 217 settings_helper_.SetInteger(chromeos::kReportUploadFrequency, new_delay);
215 const base::TimeDelta expected_delay = base::TimeDelta::FromMilliseconds( 218 const base::TimeDelta expected_delay = base::TimeDelta::FromMilliseconds(
216 new_delay); 219 new_delay);
217 RunPendingUploadTaskAndCheckNext(uploader, expected_delay); 220 RunPendingUploadTaskAndCheckNext(uploader, expected_delay);
218 } 221 }
219 222
220 #if defined(USE_X11) || defined(USE_OZONE) 223 #if defined(USE_X11) || defined(USE_OZONE)
221 TEST_F(StatusUploaderTest, NoUploadAfterUserInput) { 224 TEST_F(StatusUploaderTest, NoUploadAfterUserInput) {
222 StatusUploader uploader(&client_, collector_.Pass(), task_runner_); 225 StatusUploader uploader(&client_, std::move(collector_), task_runner_);
223 // Should allow data upload before there is user input. 226 // Should allow data upload before there is user input.
224 EXPECT_TRUE(uploader.IsSessionDataUploadAllowed()); 227 EXPECT_TRUE(uploader.IsSessionDataUploadAllowed());
225 228
226 // Now mock user input, and no session data should be allowed. 229 // Now mock user input, and no session data should be allowed.
227 #if defined(USE_X11) 230 #if defined(USE_X11)
228 ui::ScopedXI2Event native_event; 231 ui::ScopedXI2Event native_event;
229 const int kPointerDeviceId = 10; 232 const int kPointerDeviceId = 10;
230 std::vector<int> device_list; 233 std::vector<int> device_list;
231 device_list.push_back(kPointerDeviceId); 234 device_list.push_back(kPointerDeviceId);
232 ui::TouchFactory::GetInstance()->SetPointerDeviceForTest(device_list); 235 ui::TouchFactory::GetInstance()->SetPointerDeviceForTest(device_list);
233 native_event.InitGenericButtonEvent( 236 native_event.InitGenericButtonEvent(
234 kPointerDeviceId, ui::ET_MOUSE_PRESSED, gfx::Point(), 237 kPointerDeviceId, ui::ET_MOUSE_PRESSED, gfx::Point(),
235 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_CONTROL_DOWN); 238 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_CONTROL_DOWN);
236 #elif defined(USE_OZONE) 239 #elif defined(USE_OZONE)
237 ui::MouseEvent e(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 240 ui::MouseEvent e(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(),
238 ui::EventTimeForNow(), 0, 0); 241 ui::EventTimeForNow(), 0, 0);
239 const ui::PlatformEvent& native_event = &e; 242 const ui::PlatformEvent& native_event = &e;
240 #endif 243 #endif
241 ui::UserActivityDetector::Get()->DidProcessEvent(native_event); 244 ui::UserActivityDetector::Get()->DidProcessEvent(native_event);
242 EXPECT_FALSE(uploader.IsSessionDataUploadAllowed()); 245 EXPECT_FALSE(uploader.IsSessionDataUploadAllowed());
243 } 246 }
244 #endif 247 #endif
245 248
246 TEST_F(StatusUploaderTest, NoUploadAfterVideoCapture) { 249 TEST_F(StatusUploaderTest, NoUploadAfterVideoCapture) {
247 StatusUploader uploader(&client_, collector_.Pass(), task_runner_); 250 StatusUploader uploader(&client_, std::move(collector_), task_runner_);
248 // Should allow data upload before there is video capture. 251 // Should allow data upload before there is video capture.
249 EXPECT_TRUE(uploader.IsSessionDataUploadAllowed()); 252 EXPECT_TRUE(uploader.IsSessionDataUploadAllowed());
250 253
251 // Now mock video capture, and no session data should be allowed. 254 // Now mock video capture, and no session data should be allowed.
252 MediaCaptureDevicesDispatcher::GetInstance()->OnMediaRequestStateChanged( 255 MediaCaptureDevicesDispatcher::GetInstance()->OnMediaRequestStateChanged(
253 0, 0, 0, GURL("http://www.google.com"), 256 0, 0, 0, GURL("http://www.google.com"),
254 content::MEDIA_DEVICE_VIDEO_CAPTURE, 257 content::MEDIA_DEVICE_VIDEO_CAPTURE,
255 content::MEDIA_REQUEST_STATE_OPENING); 258 content::MEDIA_REQUEST_STATE_OPENING);
256 base::RunLoop().RunUntilIdle(); 259 base::RunLoop().RunUntilIdle();
257 EXPECT_FALSE(uploader.IsSessionDataUploadAllowed()); 260 EXPECT_FALSE(uploader.IsSessionDataUploadAllowed());
258 } 261 }
259 262
260 } // namespace policy 263 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/policy/status_uploader.cc ('k') | chrome/browser/chromeos/policy/system_log_uploader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698