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

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

Issue 1963703002: Add delay when scheduling next status upload (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change tests to match the new behavior Created 4 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
« no previous file with comments | « chrome/browser/chromeos/policy/status_uploader.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 ui::UserActivityDetector detector_; 135 ui::UserActivityDetector detector_;
136 MockCloudPolicyClient client_; 136 MockCloudPolicyClient client_;
137 MockDeviceManagementService device_management_service_; 137 MockDeviceManagementService device_management_service_;
138 TestingPrefServiceSimple prefs_; 138 TestingPrefServiceSimple prefs_;
139 }; 139 };
140 140
141 TEST_F(StatusUploaderTest, BasicTest) { 141 TEST_F(StatusUploaderTest, BasicTest) {
142 EXPECT_TRUE(task_runner_->GetPendingTasks().empty()); 142 EXPECT_TRUE(task_runner_->GetPendingTasks().empty());
143 StatusUploader uploader(&client_, std::move(collector_), task_runner_); 143 StatusUploader uploader(&client_, std::move(collector_), task_runner_);
144 EXPECT_EQ(1U, task_runner_->GetPendingTasks().size()); 144 EXPECT_EQ(1U, task_runner_->GetPendingTasks().size());
145 // On startup, first update should happen immediately. 145 // On startup, first update should happen in 1 minute.
146 EXPECT_EQ(base::TimeDelta(), task_runner_->NextPendingTaskDelay()); 146 EXPECT_EQ(base::TimeDelta::FromMinutes(1),
147 task_runner_->NextPendingTaskDelay());
147 } 148 }
148 149
149 TEST_F(StatusUploaderTest, DifferentFrequencyAtStart) { 150 TEST_F(StatusUploaderTest, DifferentFrequencyAtStart) {
150 // Keep a pointer to the mock collector because collector_ gets cleared 151 // Keep a pointer to the mock collector because collector_ gets cleared
151 // when it is passed to the StatusUploader constructor below. 152 // when it is passed to the StatusUploader constructor below.
152 MockDeviceStatusCollector* const mock_collector = collector_.get(); 153 MockDeviceStatusCollector* const mock_collector = collector_.get();
153 const int new_delay = StatusUploader::kDefaultUploadDelayMs * 2; 154 const int new_delay = StatusUploader::kDefaultUploadDelayMs * 2;
154 settings_helper_.SetInteger(chromeos::kReportUploadFrequency, new_delay); 155 settings_helper_.SetInteger(chromeos::kReportUploadFrequency, new_delay);
155 const base::TimeDelta expected_delay = base::TimeDelta::FromMilliseconds( 156 const base::TimeDelta expected_delay = base::TimeDelta::FromMilliseconds(
156 new_delay); 157 new_delay);
157 EXPECT_TRUE(task_runner_->GetPendingTasks().empty()); 158 EXPECT_TRUE(task_runner_->GetPendingTasks().empty());
158 StatusUploader uploader(&client_, std::move(collector_), task_runner_); 159 StatusUploader uploader(&client_, std::move(collector_), task_runner_);
159 ASSERT_EQ(1U, task_runner_->GetPendingTasks().size()); 160 ASSERT_EQ(1U, task_runner_->GetPendingTasks().size());
160 // On startup, first update should happen immediately. 161 // On startup, first update should happen in 1 minute.
161 EXPECT_EQ(base::TimeDelta(), task_runner_->NextPendingTaskDelay()); 162 EXPECT_EQ(base::TimeDelta::FromMinutes(1),
163 task_runner_->NextPendingTaskDelay());
162 164
163 EXPECT_CALL(*mock_collector, GetDeviceStatus(_)).WillRepeatedly(Return(true)); 165 EXPECT_CALL(*mock_collector, GetDeviceStatus(_)).WillRepeatedly(Return(true));
164 EXPECT_CALL(*mock_collector, GetDeviceSessionStatus(_)).WillRepeatedly( 166 EXPECT_CALL(*mock_collector, GetDeviceSessionStatus(_)).WillRepeatedly(
165 Return(true)); 167 Return(true));
166 // Second update should use the delay specified in settings. 168 // Second update should use the delay specified in settings.
167 RunPendingUploadTaskAndCheckNext(uploader, expected_delay); 169 RunPendingUploadTaskAndCheckNext(uploader, expected_delay);
168 } 170 }
169 171
170 TEST_F(StatusUploaderTest, ResetTimerAfterStatusCollection) { 172 TEST_F(StatusUploaderTest, ResetTimerAfterStatusCollection) {
171 // Keep a pointer to the mock collector because collector_ gets cleared 173 // Keep a pointer to the mock collector because collector_ gets cleared
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 // Now mock video capture, and no session data should be allowed. 257 // Now mock video capture, and no session data should be allowed.
256 MediaCaptureDevicesDispatcher::GetInstance()->OnMediaRequestStateChanged( 258 MediaCaptureDevicesDispatcher::GetInstance()->OnMediaRequestStateChanged(
257 0, 0, 0, GURL("http://www.google.com"), 259 0, 0, 0, GURL("http://www.google.com"),
258 content::MEDIA_DEVICE_VIDEO_CAPTURE, 260 content::MEDIA_DEVICE_VIDEO_CAPTURE,
259 content::MEDIA_REQUEST_STATE_OPENING); 261 content::MEDIA_REQUEST_STATE_OPENING);
260 base::RunLoop().RunUntilIdle(); 262 base::RunLoop().RunUntilIdle();
261 EXPECT_FALSE(uploader.IsSessionDataUploadAllowed()); 263 EXPECT_FALSE(uploader.IsSessionDataUploadAllowed());
262 } 264 }
263 265
264 } // namespace policy 266 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/policy/status_uploader.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698