Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include <gtest/gtest.h> |
| 6 | |
| 7 | #include "update_engine/update_attempter_mock.h" |
| 8 | #include "update_engine/update_check_scheduler.h" |
| 9 | |
| 10 | using std::string; |
| 11 | using testing::_; |
| 12 | using testing::AllOf; |
Darin Petkov | 2a0e633 | 2010-09-24 14:43:41 -0700 | [diff] [blame] | 13 | using testing::Assign; |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 14 | using testing::Ge; |
| 15 | using testing::Le; |
| 16 | using testing::MockFunction; |
| 17 | using testing::Return; |
| 18 | |
| 19 | namespace chromeos_update_engine { |
| 20 | |
| 21 | namespace { |
| 22 | void FuzzRange(int interval, int fuzz, int* interval_min, int* interval_max) { |
| 23 | *interval_min = interval - fuzz / 2; |
| 24 | *interval_max = interval + fuzz - fuzz / 2; |
| 25 | } |
| 26 | } // namespace {} |
| 27 | |
| 28 | // Test a subclass rather than the main class directly so that we can mock out |
| 29 | // GLib and utils in tests. There're explicit unit test for the wrapper methods. |
| 30 | class UpdateCheckSchedulerUnderTest : public UpdateCheckScheduler { |
| 31 | public: |
| 32 | UpdateCheckSchedulerUnderTest(UpdateAttempter* update_attempter) |
| 33 | : UpdateCheckScheduler(update_attempter) {} |
| 34 | |
| 35 | MOCK_METHOD2(GTimeoutAddSeconds, guint(guint seconds, GSourceFunc function)); |
| 36 | MOCK_METHOD0(IsBootDeviceRemovable, bool()); |
| 37 | MOCK_METHOD0(IsOfficialBuild, bool()); |
Darin Petkov | 2a0e633 | 2010-09-24 14:43:41 -0700 | [diff] [blame] | 38 | MOCK_METHOD0(IsOOBEComplete, bool()); |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | class UpdateCheckSchedulerTest : public ::testing::Test { |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 42 | public: |
Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 43 | UpdateCheckSchedulerTest() : scheduler_(&attempter_), attempter_(&dbus_) {} |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 44 | |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 45 | protected: |
| 46 | virtual void SetUp() { |
| 47 | test_ = this; |
| 48 | loop_ = NULL; |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 49 | EXPECT_EQ(&attempter_, scheduler_.update_attempter_); |
| 50 | EXPECT_FALSE(scheduler_.enabled_); |
| 51 | EXPECT_FALSE(scheduler_.scheduled_); |
| 52 | EXPECT_EQ(0, scheduler_.last_interval_); |
Darin Petkov | 85ced13 | 2010-09-01 10:20:56 -0700 | [diff] [blame] | 53 | EXPECT_EQ(0, scheduler_.poll_interval_); |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | virtual void TearDown() { |
| 57 | test_ = NULL; |
| 58 | loop_ = NULL; |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | static gboolean SourceCallback(gpointer data) { |
| 62 | g_main_loop_quit(test_->loop_); |
| 63 | // Forwards the call to the function mock so that expectations can be set. |
| 64 | return test_->source_callback_.Call(data); |
| 65 | } |
| 66 | |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 67 | UpdateCheckSchedulerUnderTest scheduler_; |
Andrew de los Reyes | 000d895 | 2011-03-02 15:21:14 -0800 | [diff] [blame] | 68 | MockDbusGlib dbus_; |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 69 | UpdateAttempterMock attempter_; |
| 70 | MockFunction<gboolean(gpointer data)> source_callback_; |
| 71 | GMainLoop* loop_; |
| 72 | static UpdateCheckSchedulerTest* test_; |
| 73 | }; |
| 74 | |
| 75 | UpdateCheckSchedulerTest* UpdateCheckSchedulerTest::test_ = NULL; |
| 76 | |
| 77 | TEST_F(UpdateCheckSchedulerTest, CanScheduleTest) { |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 78 | EXPECT_FALSE(scheduler_.CanSchedule()); |
| 79 | scheduler_.enabled_ = true; |
| 80 | EXPECT_TRUE(scheduler_.CanSchedule()); |
| 81 | scheduler_.scheduled_ = true; |
| 82 | EXPECT_FALSE(scheduler_.CanSchedule()); |
| 83 | scheduler_.enabled_ = false; |
| 84 | EXPECT_FALSE(scheduler_.CanSchedule()); |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | TEST_F(UpdateCheckSchedulerTest, ComputeNextIntervalAndFuzzBackoffTest) { |
| 88 | int interval, fuzz; |
| 89 | attempter_.set_http_response_code(500); |
Gilad Arnold | 1ebd813 | 2012-03-05 10:19:29 -0800 | [diff] [blame] | 90 | int last_interval = UpdateCheckScheduler::kTimeoutPeriodicInterval + 50; |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 91 | scheduler_.last_interval_ = last_interval; |
Gilad Arnold | 1ebd813 | 2012-03-05 10:19:29 -0800 | [diff] [blame] | 92 | scheduler_.ComputeNextIntervalAndFuzz(0, &interval, &fuzz); |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 93 | EXPECT_EQ(2 * last_interval, interval); |
| 94 | EXPECT_EQ(2 * last_interval, fuzz); |
| 95 | |
| 96 | attempter_.set_http_response_code(503); |
Gilad Arnold | 1ebd813 | 2012-03-05 10:19:29 -0800 | [diff] [blame] | 97 | scheduler_.last_interval_ = |
| 98 | UpdateCheckScheduler::kTimeoutMaxBackoffInterval / 2 + 1; |
| 99 | scheduler_.ComputeNextIntervalAndFuzz(0, &interval, &fuzz); |
| 100 | EXPECT_EQ(UpdateCheckScheduler::kTimeoutMaxBackoffInterval, interval); |
| 101 | EXPECT_EQ(UpdateCheckScheduler::kTimeoutMaxBackoffInterval, fuzz); |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Darin Petkov | 85ced13 | 2010-09-01 10:20:56 -0700 | [diff] [blame] | 104 | TEST_F(UpdateCheckSchedulerTest, ComputeNextIntervalAndFuzzPollTest) { |
| 105 | int interval, fuzz; |
Gilad Arnold | 1ebd813 | 2012-03-05 10:19:29 -0800 | [diff] [blame] | 106 | int poll_interval = UpdateCheckScheduler::kTimeoutPeriodicInterval + 50; |
Darin Petkov | 85ced13 | 2010-09-01 10:20:56 -0700 | [diff] [blame] | 107 | scheduler_.set_poll_interval(poll_interval); |
Gilad Arnold | 1ebd813 | 2012-03-05 10:19:29 -0800 | [diff] [blame] | 108 | scheduler_.ComputeNextIntervalAndFuzz(0, &interval, &fuzz); |
Darin Petkov | 85ced13 | 2010-09-01 10:20:56 -0700 | [diff] [blame] | 109 | EXPECT_EQ(poll_interval, interval); |
| 110 | EXPECT_EQ(poll_interval, fuzz); |
| 111 | |
Gilad Arnold | 1ebd813 | 2012-03-05 10:19:29 -0800 | [diff] [blame] | 112 | scheduler_.set_poll_interval( |
| 113 | UpdateCheckScheduler::kTimeoutMaxBackoffInterval + 1); |
| 114 | scheduler_.ComputeNextIntervalAndFuzz(0, &interval, &fuzz); |
| 115 | EXPECT_EQ(UpdateCheckScheduler::kTimeoutMaxBackoffInterval, interval); |
| 116 | EXPECT_EQ(UpdateCheckScheduler::kTimeoutMaxBackoffInterval, fuzz); |
Darin Petkov | 85ced13 | 2010-09-01 10:20:56 -0700 | [diff] [blame] | 117 | |
Gilad Arnold | 1ebd813 | 2012-03-05 10:19:29 -0800 | [diff] [blame] | 118 | scheduler_.set_poll_interval( |
| 119 | UpdateCheckScheduler::kTimeoutPeriodicInterval - 1); |
| 120 | scheduler_.ComputeNextIntervalAndFuzz(0, &interval, &fuzz); |
| 121 | EXPECT_EQ(UpdateCheckScheduler::kTimeoutPeriodicInterval, interval); |
Darin Petkov | 85ced13 | 2010-09-01 10:20:56 -0700 | [diff] [blame] | 122 | EXPECT_EQ(UpdateCheckScheduler::kTimeoutRegularFuzz, fuzz); |
| 123 | } |
| 124 | |
| 125 | TEST_F(UpdateCheckSchedulerTest, ComputeNextIntervalAndFuzzPriorityTest) { |
| 126 | int interval, fuzz; |
| 127 | attempter_.set_http_response_code(500); |
Gilad Arnold | 1ebd813 | 2012-03-05 10:19:29 -0800 | [diff] [blame] | 128 | scheduler_.last_interval_ = |
| 129 | UpdateCheckScheduler::kTimeoutPeriodicInterval + 50; |
| 130 | int poll_interval = UpdateCheckScheduler::kTimeoutPeriodicInterval + 100; |
Darin Petkov | 85ced13 | 2010-09-01 10:20:56 -0700 | [diff] [blame] | 131 | scheduler_.set_poll_interval(poll_interval); |
Gilad Arnold | 1ebd813 | 2012-03-05 10:19:29 -0800 | [diff] [blame] | 132 | scheduler_.ComputeNextIntervalAndFuzz(0, &interval, &fuzz); |
Darin Petkov | 85ced13 | 2010-09-01 10:20:56 -0700 | [diff] [blame] | 133 | EXPECT_EQ(poll_interval, interval); |
| 134 | EXPECT_EQ(poll_interval, fuzz); |
| 135 | } |
| 136 | |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 137 | TEST_F(UpdateCheckSchedulerTest, ComputeNextIntervalAndFuzzTest) { |
| 138 | int interval, fuzz; |
Gilad Arnold | 1ebd813 | 2012-03-05 10:19:29 -0800 | [diff] [blame] | 139 | scheduler_.ComputeNextIntervalAndFuzz(0, &interval, &fuzz); |
| 140 | EXPECT_EQ(UpdateCheckScheduler::kTimeoutPeriodicInterval, interval); |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 141 | EXPECT_EQ(UpdateCheckScheduler::kTimeoutRegularFuzz, fuzz); |
| 142 | } |
| 143 | |
| 144 | TEST_F(UpdateCheckSchedulerTest, GTimeoutAddSecondsTest) { |
| 145 | loop_ = g_main_loop_new(g_main_context_default(), FALSE); |
| 146 | // Invokes the actual GLib wrapper method rather than the subclass mock. |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 147 | scheduler_.UpdateCheckScheduler::GTimeoutAddSeconds(0, SourceCallback); |
| 148 | EXPECT_CALL(source_callback_, Call(&scheduler_)).Times(1); |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 149 | g_main_loop_run(loop_); |
| 150 | g_main_loop_unref(loop_); |
| 151 | } |
| 152 | |
| 153 | TEST_F(UpdateCheckSchedulerTest, IsBootDeviceRemovableTest) { |
| 154 | // Invokes the actual utils wrapper method rather than the subclass mock. |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 155 | EXPECT_FALSE(scheduler_.UpdateCheckScheduler::IsBootDeviceRemovable()); |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 156 | } |
| 157 | |
Darin Petkov | 2a0e633 | 2010-09-24 14:43:41 -0700 | [diff] [blame] | 158 | TEST_F(UpdateCheckSchedulerTest, IsOOBECompleteTest) { |
| 159 | // Invokes the actual utils wrapper method rather than the subclass mock. |
| 160 | EXPECT_FALSE(scheduler_.UpdateCheckScheduler::IsOOBEComplete()); |
| 161 | } |
| 162 | |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 163 | TEST_F(UpdateCheckSchedulerTest, IsOfficialBuildTest) { |
| 164 | // Invokes the actual utils wrapper method rather than the subclass mock. |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 165 | EXPECT_TRUE(scheduler_.UpdateCheckScheduler::IsOfficialBuild()); |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | TEST_F(UpdateCheckSchedulerTest, RunBootDeviceRemovableTest) { |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 169 | scheduler_.enabled_ = true; |
| 170 | EXPECT_CALL(scheduler_, IsOfficialBuild()).Times(1).WillOnce(Return(true)); |
| 171 | EXPECT_CALL(scheduler_, IsBootDeviceRemovable()) |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 172 | .Times(1) |
| 173 | .WillOnce(Return(true)); |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 174 | scheduler_.Run(); |
| 175 | EXPECT_FALSE(scheduler_.enabled_); |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 176 | EXPECT_EQ(NULL, attempter_.update_check_scheduler()); |
| 177 | } |
| 178 | |
| 179 | TEST_F(UpdateCheckSchedulerTest, RunNonOfficialBuildTest) { |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 180 | scheduler_.enabled_ = true; |
| 181 | EXPECT_CALL(scheduler_, IsOfficialBuild()).Times(1).WillOnce(Return(false)); |
| 182 | scheduler_.Run(); |
| 183 | EXPECT_FALSE(scheduler_.enabled_); |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 184 | EXPECT_EQ(NULL, attempter_.update_check_scheduler()); |
| 185 | } |
| 186 | |
| 187 | TEST_F(UpdateCheckSchedulerTest, RunTest) { |
| 188 | int interval_min, interval_max; |
Gilad Arnold | 1ebd813 | 2012-03-05 10:19:29 -0800 | [diff] [blame] | 189 | FuzzRange(UpdateCheckScheduler::kTimeoutInitialInterval, |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 190 | UpdateCheckScheduler::kTimeoutRegularFuzz, |
| 191 | &interval_min, |
| 192 | &interval_max); |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 193 | EXPECT_CALL(scheduler_, IsOfficialBuild()).Times(1).WillOnce(Return(true)); |
| 194 | EXPECT_CALL(scheduler_, IsBootDeviceRemovable()) |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 195 | .Times(1) |
| 196 | .WillOnce(Return(false)); |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 197 | EXPECT_CALL(scheduler_, |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 198 | GTimeoutAddSeconds(AllOf(Ge(interval_min), Le(interval_max)), |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 199 | scheduler_.StaticCheck)).Times(1); |
| 200 | scheduler_.Run(); |
| 201 | EXPECT_TRUE(scheduler_.enabled_); |
| 202 | EXPECT_EQ(&scheduler_, attempter_.update_check_scheduler()); |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | TEST_F(UpdateCheckSchedulerTest, ScheduleCheckDisabledTest) { |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 206 | EXPECT_CALL(scheduler_, GTimeoutAddSeconds(_, _)).Times(0); |
| 207 | scheduler_.ScheduleCheck(250, 30); |
| 208 | EXPECT_EQ(0, scheduler_.last_interval_); |
| 209 | EXPECT_FALSE(scheduler_.scheduled_); |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | TEST_F(UpdateCheckSchedulerTest, ScheduleCheckEnabledTest) { |
| 213 | int interval_min, interval_max; |
| 214 | FuzzRange(100, 10, &interval_min,&interval_max); |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 215 | EXPECT_CALL(scheduler_, |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 216 | GTimeoutAddSeconds(AllOf(Ge(interval_min), Le(interval_max)), |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 217 | scheduler_.StaticCheck)).Times(1); |
| 218 | scheduler_.enabled_ = true; |
| 219 | scheduler_.ScheduleCheck(100, 10); |
| 220 | EXPECT_EQ(100, scheduler_.last_interval_); |
| 221 | EXPECT_TRUE(scheduler_.scheduled_); |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | TEST_F(UpdateCheckSchedulerTest, ScheduleCheckNegativeIntervalTest) { |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 225 | EXPECT_CALL(scheduler_, GTimeoutAddSeconds(0, scheduler_.StaticCheck)) |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 226 | .Times(1); |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 227 | scheduler_.enabled_ = true; |
| 228 | scheduler_.ScheduleCheck(-50, 20); |
| 229 | EXPECT_TRUE(scheduler_.scheduled_); |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | TEST_F(UpdateCheckSchedulerTest, ScheduleNextCheckDisabledTest) { |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 233 | EXPECT_CALL(scheduler_, GTimeoutAddSeconds(_, _)).Times(0); |
Gilad Arnold | 1ebd813 | 2012-03-05 10:19:29 -0800 | [diff] [blame] | 234 | scheduler_.ScheduleNextCheck(false); |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | TEST_F(UpdateCheckSchedulerTest, ScheduleNextCheckEnabledTest) { |
| 238 | int interval_min, interval_max; |
Gilad Arnold | 1ebd813 | 2012-03-05 10:19:29 -0800 | [diff] [blame] | 239 | FuzzRange(UpdateCheckScheduler::kTimeoutPeriodicInterval, |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 240 | UpdateCheckScheduler::kTimeoutRegularFuzz, |
| 241 | &interval_min, |
| 242 | &interval_max); |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 243 | EXPECT_CALL(scheduler_, |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 244 | GTimeoutAddSeconds(AllOf(Ge(interval_min), Le(interval_max)), |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 245 | scheduler_.StaticCheck)).Times(1); |
| 246 | scheduler_.enabled_ = true; |
Gilad Arnold | 1ebd813 | 2012-03-05 10:19:29 -0800 | [diff] [blame] | 247 | scheduler_.ScheduleNextCheck(false); |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | TEST_F(UpdateCheckSchedulerTest, SetUpdateStatusIdleDisabledTest) { |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 251 | EXPECT_CALL(scheduler_, GTimeoutAddSeconds(_, _)).Times(0); |
Gilad Arnold | 1ebd813 | 2012-03-05 10:19:29 -0800 | [diff] [blame] | 252 | scheduler_.SetUpdateStatus(UPDATE_STATUS_IDLE, kUpdateNoticeUnspecified); |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | TEST_F(UpdateCheckSchedulerTest, SetUpdateStatusIdleEnabledTest) { |
| 256 | int interval_min, interval_max; |
Gilad Arnold | 1ebd813 | 2012-03-05 10:19:29 -0800 | [diff] [blame] | 257 | FuzzRange(UpdateCheckScheduler::kTimeoutPeriodicInterval, |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 258 | UpdateCheckScheduler::kTimeoutRegularFuzz, |
| 259 | &interval_min, |
| 260 | &interval_max); |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 261 | EXPECT_CALL(scheduler_, |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 262 | GTimeoutAddSeconds(AllOf(Ge(interval_min), Le(interval_max)), |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 263 | scheduler_.StaticCheck)).Times(1); |
| 264 | scheduler_.enabled_ = true; |
Gilad Arnold | 1ebd813 | 2012-03-05 10:19:29 -0800 | [diff] [blame] | 265 | scheduler_.SetUpdateStatus(UPDATE_STATUS_IDLE, kUpdateNoticeUnspecified); |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | TEST_F(UpdateCheckSchedulerTest, SetUpdateStatusNonIdleTest) { |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 269 | EXPECT_CALL(scheduler_, GTimeoutAddSeconds(_, _)).Times(0); |
Gilad Arnold | 1ebd813 | 2012-03-05 10:19:29 -0800 | [diff] [blame] | 270 | scheduler_.SetUpdateStatus(UPDATE_STATUS_DOWNLOADING, |
| 271 | kUpdateNoticeUnspecified); |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 272 | scheduler_.enabled_ = true; |
Gilad Arnold | 1ebd813 | 2012-03-05 10:19:29 -0800 | [diff] [blame] | 273 | scheduler_.SetUpdateStatus(UPDATE_STATUS_DOWNLOADING, |
| 274 | kUpdateNoticeUnspecified); |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 275 | } |
| 276 | |
Darin Petkov | 2a0e633 | 2010-09-24 14:43:41 -0700 | [diff] [blame] | 277 | TEST_F(UpdateCheckSchedulerTest, StaticCheckOOBECompleteTest) { |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 278 | scheduler_.scheduled_ = true; |
Darin Petkov | 2a0e633 | 2010-09-24 14:43:41 -0700 | [diff] [blame] | 279 | EXPECT_CALL(scheduler_, IsOOBEComplete()).Times(1).WillOnce(Return(true)); |
Gilad Arnold | 1ebd813 | 2012-03-05 10:19:29 -0800 | [diff] [blame] | 280 | EXPECT_CALL(attempter_, Update("", "", false, false, false)) |
Darin Petkov | 2a0e633 | 2010-09-24 14:43:41 -0700 | [diff] [blame] | 281 | .Times(1) |
| 282 | .WillOnce(Assign(&scheduler_.scheduled_, true)); |
| 283 | scheduler_.enabled_ = true; |
| 284 | EXPECT_CALL(scheduler_, GTimeoutAddSeconds(_, _)).Times(0); |
| 285 | UpdateCheckSchedulerUnderTest::StaticCheck(&scheduler_); |
| 286 | } |
| 287 | |
| 288 | TEST_F(UpdateCheckSchedulerTest, StaticCheckOOBENotCompleteTest) { |
| 289 | scheduler_.scheduled_ = true; |
| 290 | EXPECT_CALL(scheduler_, IsOOBEComplete()).Times(1).WillOnce(Return(false)); |
Gilad Arnold | 1ebd813 | 2012-03-05 10:19:29 -0800 | [diff] [blame] | 291 | EXPECT_CALL(attempter_, Update("", "", _, _, _)).Times(0); |
Darin Petkov | 2a0e633 | 2010-09-24 14:43:41 -0700 | [diff] [blame] | 292 | int interval_min, interval_max; |
Gilad Arnold | 1ebd813 | 2012-03-05 10:19:29 -0800 | [diff] [blame] | 293 | FuzzRange(UpdateCheckScheduler::kTimeoutInitialInterval, |
Darin Petkov | 2a0e633 | 2010-09-24 14:43:41 -0700 | [diff] [blame] | 294 | UpdateCheckScheduler::kTimeoutRegularFuzz, |
| 295 | &interval_min, |
| 296 | &interval_max); |
| 297 | scheduler_.enabled_ = true; |
| 298 | EXPECT_CALL(scheduler_, |
| 299 | GTimeoutAddSeconds(AllOf(Ge(interval_min), Le(interval_max)), |
| 300 | scheduler_.StaticCheck)).Times(1); |
Darin Petkov | f42cc1c | 2010-09-01 09:03:02 -0700 | [diff] [blame] | 301 | UpdateCheckSchedulerUnderTest::StaticCheck(&scheduler_); |
Darin Petkov | 1023a60 | 2010-08-30 13:47:51 -0700 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | } // namespace chromeos_update_engine |