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

Side by Side Diff: update_check_scheduler_unittest.cc

Issue 3398018: AU: Skip all automatic update checks if OOBE is not complete. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git
Patch Set: fix comment Created 10 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « update_check_scheduler.cc ('k') | utils.h » ('j') | 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) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS 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 <gtest/gtest.h> 5 #include <gtest/gtest.h>
6 6
7 #include "update_engine/update_attempter_mock.h" 7 #include "update_engine/update_attempter_mock.h"
8 #include "update_engine/update_check_scheduler.h" 8 #include "update_engine/update_check_scheduler.h"
9 9
10 using std::string; 10 using std::string;
11 using testing::_; 11 using testing::_;
12 using testing::AllOf; 12 using testing::AllOf;
13 using testing::Assign;
13 using testing::Ge; 14 using testing::Ge;
14 using testing::Le; 15 using testing::Le;
15 using testing::MockFunction; 16 using testing::MockFunction;
16 using testing::Return; 17 using testing::Return;
17 18
18 namespace chromeos_update_engine { 19 namespace chromeos_update_engine {
19 20
20 namespace { 21 namespace {
21 void FuzzRange(int interval, int fuzz, int* interval_min, int* interval_max) { 22 void FuzzRange(int interval, int fuzz, int* interval_min, int* interval_max) {
22 *interval_min = interval - fuzz / 2; 23 *interval_min = interval - fuzz / 2;
23 *interval_max = interval + fuzz - fuzz / 2; 24 *interval_max = interval + fuzz - fuzz / 2;
24 } 25 }
25 } // namespace {} 26 } // namespace {}
26 27
27 // Test a subclass rather than the main class directly so that we can mock out 28 // Test a subclass rather than the main class directly so that we can mock out
28 // GLib and utils in tests. There're explicit unit test for the wrapper methods. 29 // GLib and utils in tests. There're explicit unit test for the wrapper methods.
29 class UpdateCheckSchedulerUnderTest : public UpdateCheckScheduler { 30 class UpdateCheckSchedulerUnderTest : public UpdateCheckScheduler {
30 public: 31 public:
31 UpdateCheckSchedulerUnderTest(UpdateAttempter* update_attempter) 32 UpdateCheckSchedulerUnderTest(UpdateAttempter* update_attempter)
32 : UpdateCheckScheduler(update_attempter) {} 33 : UpdateCheckScheduler(update_attempter) {}
33 34
34 MOCK_METHOD2(GTimeoutAddSeconds, guint(guint seconds, GSourceFunc function)); 35 MOCK_METHOD2(GTimeoutAddSeconds, guint(guint seconds, GSourceFunc function));
35 MOCK_METHOD0(IsBootDeviceRemovable, bool()); 36 MOCK_METHOD0(IsBootDeviceRemovable, bool());
36 MOCK_METHOD0(IsOfficialBuild, bool()); 37 MOCK_METHOD0(IsOfficialBuild, bool());
38 MOCK_METHOD0(IsOOBEComplete, bool());
37 }; 39 };
38 40
39 class UpdateCheckSchedulerTest : public ::testing::Test { 41 class UpdateCheckSchedulerTest : public ::testing::Test {
40 public: 42 public:
41 UpdateCheckSchedulerTest() : scheduler_(&attempter_) {} 43 UpdateCheckSchedulerTest() : scheduler_(&attempter_) {}
42 44
43 protected: 45 protected:
44 virtual void SetUp() { 46 virtual void SetUp() {
45 test_ = this; 47 test_ = this;
46 loop_ = NULL; 48 loop_ = NULL;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 EXPECT_CALL(source_callback_, Call(&scheduler_)).Times(1); 143 EXPECT_CALL(source_callback_, Call(&scheduler_)).Times(1);
142 g_main_loop_run(loop_); 144 g_main_loop_run(loop_);
143 g_main_loop_unref(loop_); 145 g_main_loop_unref(loop_);
144 } 146 }
145 147
146 TEST_F(UpdateCheckSchedulerTest, IsBootDeviceRemovableTest) { 148 TEST_F(UpdateCheckSchedulerTest, IsBootDeviceRemovableTest) {
147 // Invokes the actual utils wrapper method rather than the subclass mock. 149 // Invokes the actual utils wrapper method rather than the subclass mock.
148 EXPECT_FALSE(scheduler_.UpdateCheckScheduler::IsBootDeviceRemovable()); 150 EXPECT_FALSE(scheduler_.UpdateCheckScheduler::IsBootDeviceRemovable());
149 } 151 }
150 152
153 TEST_F(UpdateCheckSchedulerTest, IsOOBECompleteTest) {
154 // Invokes the actual utils wrapper method rather than the subclass mock.
155 EXPECT_FALSE(scheduler_.UpdateCheckScheduler::IsOOBEComplete());
156 }
157
151 TEST_F(UpdateCheckSchedulerTest, IsOfficialBuildTest) { 158 TEST_F(UpdateCheckSchedulerTest, IsOfficialBuildTest) {
152 // Invokes the actual utils wrapper method rather than the subclass mock. 159 // Invokes the actual utils wrapper method rather than the subclass mock.
153 EXPECT_TRUE(scheduler_.UpdateCheckScheduler::IsOfficialBuild()); 160 EXPECT_TRUE(scheduler_.UpdateCheckScheduler::IsOfficialBuild());
154 } 161 }
155 162
156 TEST_F(UpdateCheckSchedulerTest, RunBootDeviceRemovableTest) { 163 TEST_F(UpdateCheckSchedulerTest, RunBootDeviceRemovableTest) {
157 scheduler_.enabled_ = true; 164 scheduler_.enabled_ = true;
158 EXPECT_CALL(scheduler_, IsOfficialBuild()).Times(1).WillOnce(Return(true)); 165 EXPECT_CALL(scheduler_, IsOfficialBuild()).Times(1).WillOnce(Return(true));
159 EXPECT_CALL(scheduler_, IsBootDeviceRemovable()) 166 EXPECT_CALL(scheduler_, IsBootDeviceRemovable())
160 .Times(1) 167 .Times(1)
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 scheduler_.SetUpdateStatus(UPDATE_STATUS_IDLE); 260 scheduler_.SetUpdateStatus(UPDATE_STATUS_IDLE);
254 } 261 }
255 262
256 TEST_F(UpdateCheckSchedulerTest, SetUpdateStatusNonIdleTest) { 263 TEST_F(UpdateCheckSchedulerTest, SetUpdateStatusNonIdleTest) {
257 EXPECT_CALL(scheduler_, GTimeoutAddSeconds(_, _)).Times(0); 264 EXPECT_CALL(scheduler_, GTimeoutAddSeconds(_, _)).Times(0);
258 scheduler_.SetUpdateStatus(UPDATE_STATUS_DOWNLOADING); 265 scheduler_.SetUpdateStatus(UPDATE_STATUS_DOWNLOADING);
259 scheduler_.enabled_ = true; 266 scheduler_.enabled_ = true;
260 scheduler_.SetUpdateStatus(UPDATE_STATUS_DOWNLOADING); 267 scheduler_.SetUpdateStatus(UPDATE_STATUS_DOWNLOADING);
261 } 268 }
262 269
263 TEST_F(UpdateCheckSchedulerTest, StaticCheckTest) { 270 TEST_F(UpdateCheckSchedulerTest, StaticCheckOOBECompleteTest) {
264 scheduler_.scheduled_ = true; 271 scheduler_.scheduled_ = true;
265 EXPECT_CALL(attempter_, Update("", "")).Times(1); 272 EXPECT_CALL(scheduler_, IsOOBEComplete()).Times(1).WillOnce(Return(true));
273 EXPECT_CALL(attempter_, Update("", ""))
274 .Times(1)
275 .WillOnce(Assign(&scheduler_.scheduled_, true));
276 scheduler_.enabled_ = true;
277 EXPECT_CALL(scheduler_, GTimeoutAddSeconds(_, _)).Times(0);
266 UpdateCheckSchedulerUnderTest::StaticCheck(&scheduler_); 278 UpdateCheckSchedulerUnderTest::StaticCheck(&scheduler_);
267 } 279 }
268 280
281 TEST_F(UpdateCheckSchedulerTest, StaticCheckOOBENotCompleteTest) {
282 scheduler_.scheduled_ = true;
283 EXPECT_CALL(scheduler_, IsOOBEComplete()).Times(1).WillOnce(Return(false));
284 EXPECT_CALL(attempter_, Update("", "")).Times(0);
285 int interval_min, interval_max;
286 FuzzRange(UpdateCheckScheduler::kTimeoutOnce,
287 UpdateCheckScheduler::kTimeoutRegularFuzz,
288 &interval_min,
289 &interval_max);
290 scheduler_.enabled_ = true;
291 EXPECT_CALL(scheduler_,
292 GTimeoutAddSeconds(AllOf(Ge(interval_min), Le(interval_max)),
293 scheduler_.StaticCheck)).Times(1);
294 UpdateCheckSchedulerUnderTest::StaticCheck(&scheduler_);
295 }
296
269 } // namespace chromeos_update_engine 297 } // namespace chromeos_update_engine
OLDNEW
« no previous file with comments | « update_check_scheduler.cc ('k') | utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698