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

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

Issue 2338733002: Use TestSimpleTaskRunner::HasPendingTask instead of GetPendingTasks().empty() (Closed)
Patch Set: +bluetooth_adapter_win_unittest.cc Created 4 years, 3 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" 5 #include "chrome/browser/chromeos/policy/status_uploader.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/test/test_simple_task_runner.h" 10 #include "base/test/test_simple_task_runner.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 99
100 void TearDown() override { 100 void TearDown() override {
101 content::RunAllBlockingPoolTasksUntilIdle(); 101 content::RunAllBlockingPoolTasksUntilIdle();
102 } 102 }
103 103
104 // Given a pending task to upload status, mocks out a server response. 104 // Given a pending task to upload status, mocks out a server response.
105 void RunPendingUploadTaskAndCheckNext(const StatusUploader& uploader, 105 void RunPendingUploadTaskAndCheckNext(const StatusUploader& uploader,
106 base::TimeDelta expected_delay) { 106 base::TimeDelta expected_delay) {
107 // Running the task should pass two callbacks into GetDeviceStatusAsync 107 // Running the task should pass two callbacks into GetDeviceStatusAsync
108 // and GetDeviceSessionStatusAsync. We'll grab these two callbacks. 108 // and GetDeviceSessionStatusAsync. We'll grab these two callbacks.
109 EXPECT_FALSE(task_runner_->GetPendingTasks().empty()); 109 EXPECT_TRUE(task_runner_->HasPendingTask());
110 DeviceStatusCollector::DeviceStatusCallback ds_callback; 110 DeviceStatusCollector::DeviceStatusCallback ds_callback;
111 DeviceStatusCollector::DeviceSessionStatusCallback ss_callback; 111 DeviceStatusCollector::DeviceSessionStatusCallback ss_callback;
112 EXPECT_CALL(*collector_ptr_, GetDeviceStatusAsync(_)) 112 EXPECT_CALL(*collector_ptr_, GetDeviceStatusAsync(_))
113 .WillOnce(SaveArg<0>(&ds_callback)); 113 .WillOnce(SaveArg<0>(&ds_callback));
114 EXPECT_CALL(*collector_ptr_, GetDeviceSessionStatusAsync(_)) 114 EXPECT_CALL(*collector_ptr_, GetDeviceSessionStatusAsync(_))
115 .WillOnce(SaveArg<0>(&ss_callback)); 115 .WillOnce(SaveArg<0>(&ss_callback));
116 task_runner_->RunPendingTasks(); 116 task_runner_->RunPendingTasks();
117 testing::Mock::VerifyAndClearExpectations(&device_management_service_); 117 testing::Mock::VerifyAndClearExpectations(&device_management_service_);
118 118
119 // Send some "valid" (read: non-nullptr) to the device/session callbacks 119 // Send some "valid" (read: non-nullptr) to the device/session callbacks
120 // in order to simulate valid status data. 120 // in order to simulate valid status data.
121 std::unique_ptr<em::DeviceStatusReportRequest> device_status = 121 std::unique_ptr<em::DeviceStatusReportRequest> device_status =
122 base::MakeUnique<em::DeviceStatusReportRequest>(); 122 base::MakeUnique<em::DeviceStatusReportRequest>();
123 std::unique_ptr<em::SessionStatusReportRequest> session_status = 123 std::unique_ptr<em::SessionStatusReportRequest> session_status =
124 base::MakeUnique<em::SessionStatusReportRequest>(); 124 base::MakeUnique<em::SessionStatusReportRequest>();
125 125
126 // Running the session and device callbacks should trigger 126 // Running the session and device callbacks should trigger
127 // CloudPolicyClient::UploadDeviceStatus. 127 // CloudPolicyClient::UploadDeviceStatus.
128 CloudPolicyClient::StatusCallback callback; 128 CloudPolicyClient::StatusCallback callback;
129 EXPECT_CALL(client_, UploadDeviceStatus(_, _, _)) 129 EXPECT_CALL(client_, UploadDeviceStatus(_, _, _))
130 .WillOnce(SaveArg<2>(&callback)); 130 .WillOnce(SaveArg<2>(&callback));
131 ds_callback.Run(std::move(device_status)); 131 ds_callback.Run(std::move(device_status));
132 ss_callback.Run(std::move(session_status)); 132 ss_callback.Run(std::move(session_status));
133 testing::Mock::VerifyAndClearExpectations(&device_management_service_); 133 testing::Mock::VerifyAndClearExpectations(&device_management_service_);
134 134
135 // Make sure no status upload is queued up yet (since an upload is in 135 // Make sure no status upload is queued up yet (since an upload is in
136 // progress). 136 // progress).
137 EXPECT_TRUE(task_runner_->GetPendingTasks().empty()); 137 EXPECT_FALSE(task_runner_->HasPendingTask());
138 138
139 // Now invoke the response. 139 // Now invoke the response.
140 callback.Run(true); 140 callback.Run(true);
141 141
142 // Now that the previous request was satisfied, a task to do the next 142 // Now that the previous request was satisfied, a task to do the next
143 // upload should be queued. 143 // upload should be queued.
144 EXPECT_EQ(1U, task_runner_->NumPendingTasks()); 144 EXPECT_EQ(1U, task_runner_->NumPendingTasks());
145 145
146 CheckPendingTaskDelay(uploader, expected_delay); 146 CheckPendingTaskDelay(uploader, expected_delay);
147 } 147 }
(...skipping 14 matching lines...) Expand all
162 chromeos::ScopedCrosSettingsTestHelper settings_helper_; 162 chromeos::ScopedCrosSettingsTestHelper settings_helper_;
163 std::unique_ptr<MockDeviceStatusCollector> collector_; 163 std::unique_ptr<MockDeviceStatusCollector> collector_;
164 MockDeviceStatusCollector* collector_ptr_; 164 MockDeviceStatusCollector* collector_ptr_;
165 ui::UserActivityDetector detector_; 165 ui::UserActivityDetector detector_;
166 MockCloudPolicyClient client_; 166 MockCloudPolicyClient client_;
167 MockDeviceManagementService device_management_service_; 167 MockDeviceManagementService device_management_service_;
168 TestingPrefServiceSimple prefs_; 168 TestingPrefServiceSimple prefs_;
169 }; 169 };
170 170
171 TEST_F(StatusUploaderTest, BasicTest) { 171 TEST_F(StatusUploaderTest, BasicTest) {
172 EXPECT_TRUE(task_runner_->GetPendingTasks().empty()); 172 EXPECT_FALSE(task_runner_->HasPendingTask());
173 StatusUploader uploader(&client_, std::move(collector_), task_runner_); 173 StatusUploader uploader(&client_, std::move(collector_), task_runner_);
174 EXPECT_EQ(1U, task_runner_->NumPendingTasks()); 174 EXPECT_EQ(1U, task_runner_->NumPendingTasks());
175 // On startup, first update should happen in 1 minute. 175 // On startup, first update should happen in 1 minute.
176 EXPECT_EQ(base::TimeDelta::FromMinutes(1), 176 EXPECT_EQ(base::TimeDelta::FromMinutes(1),
177 task_runner_->NextPendingTaskDelay()); 177 task_runner_->NextPendingTaskDelay());
178 } 178 }
179 179
180 TEST_F(StatusUploaderTest, DifferentFrequencyAtStart) { 180 TEST_F(StatusUploaderTest, DifferentFrequencyAtStart) {
181 const int new_delay = StatusUploader::kDefaultUploadDelayMs * 2; 181 const int new_delay = StatusUploader::kDefaultUploadDelayMs * 2;
182 settings_helper_.SetInteger(chromeos::kReportUploadFrequency, new_delay); 182 settings_helper_.SetInteger(chromeos::kReportUploadFrequency, new_delay);
183 const base::TimeDelta expected_delay = base::TimeDelta::FromMilliseconds( 183 const base::TimeDelta expected_delay = base::TimeDelta::FromMilliseconds(
184 new_delay); 184 new_delay);
185 EXPECT_TRUE(task_runner_->GetPendingTasks().empty()); 185 EXPECT_FALSE(task_runner_->HasPendingTask());
186 StatusUploader uploader(&client_, std::move(collector_), task_runner_); 186 StatusUploader uploader(&client_, std::move(collector_), task_runner_);
187 ASSERT_EQ(1U, task_runner_->NumPendingTasks()); 187 ASSERT_EQ(1U, task_runner_->NumPendingTasks());
188 // On startup, first update should happen in 1 minute. 188 // On startup, first update should happen in 1 minute.
189 EXPECT_EQ(base::TimeDelta::FromMinutes(1), 189 EXPECT_EQ(base::TimeDelta::FromMinutes(1),
190 task_runner_->NextPendingTaskDelay()); 190 task_runner_->NextPendingTaskDelay());
191 191
192 // Second update should use the delay specified in settings. 192 // Second update should use the delay specified in settings.
193 RunPendingUploadTaskAndCheckNext(uploader, expected_delay); 193 RunPendingUploadTaskAndCheckNext(uploader, expected_delay);
194 } 194 }
195 195
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 // Now mock video capture, and no session data should be allowed. 285 // Now mock video capture, and no session data should be allowed.
286 MediaCaptureDevicesDispatcher::GetInstance()->OnMediaRequestStateChanged( 286 MediaCaptureDevicesDispatcher::GetInstance()->OnMediaRequestStateChanged(
287 0, 0, 0, GURL("http://www.google.com"), 287 0, 0, 0, GURL("http://www.google.com"),
288 content::MEDIA_DEVICE_VIDEO_CAPTURE, 288 content::MEDIA_DEVICE_VIDEO_CAPTURE,
289 content::MEDIA_REQUEST_STATE_OPENING); 289 content::MEDIA_REQUEST_STATE_OPENING);
290 base::RunLoop().RunUntilIdle(); 290 base::RunLoop().RunUntilIdle();
291 EXPECT_FALSE(uploader.IsSessionDataUploadAllowed()); 291 EXPECT_FALSE(uploader.IsSessionDataUploadAllowed());
292 } 292 }
293 293
294 } // namespace policy 294 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698