OLD | NEW |
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 <base/file_util.h> | 5 #include <base/file_util.h> |
6 #include <gtest/gtest.h> | 6 #include <gtest/gtest.h> |
7 | 7 |
8 #include "update_engine/action_mock.h" | 8 #include "update_engine/action_mock.h" |
9 #include "update_engine/action_processor_mock.h" | 9 #include "update_engine/action_processor_mock.h" |
10 #include "update_engine/filesystem_copier_action.h" | 10 #include "update_engine/filesystem_copier_action.h" |
| 11 #include "update_engine/mock_dbus_interface.h" |
11 #include "update_engine/postinstall_runner_action.h" | 12 #include "update_engine/postinstall_runner_action.h" |
12 #include "update_engine/prefs_mock.h" | 13 #include "update_engine/prefs_mock.h" |
13 #include "update_engine/update_attempter.h" | 14 #include "update_engine/update_attempter.h" |
14 | 15 |
15 using std::string; | 16 using std::string; |
16 using testing::_; | 17 using testing::_; |
17 using testing::DoAll; | 18 using testing::DoAll; |
18 using testing::InSequence; | 19 using testing::InSequence; |
19 using testing::Ne; | 20 using testing::Ne; |
20 using testing::NiceMock; | 21 using testing::NiceMock; |
21 using testing::Property; | 22 using testing::Property; |
22 using testing::Return; | 23 using testing::Return; |
23 using testing::SetArgumentPointee; | 24 using testing::SetArgumentPointee; |
24 | 25 |
25 namespace chromeos_update_engine { | 26 namespace chromeos_update_engine { |
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 // methods within the class. There're explicit unit tests for the mocked out | 29 // methods within the class. There're explicit unit tests for the mocked out |
29 // methods. | 30 // methods. |
30 class UpdateAttempterUnderTest : public UpdateAttempter { | 31 class UpdateAttempterUnderTest : public UpdateAttempter { |
31 public: | 32 public: |
32 UpdateAttempterUnderTest() | 33 UpdateAttempterUnderTest() |
33 : UpdateAttempter(NULL, NULL) {} | 34 : UpdateAttempter(NULL, NULL, &dbus_) {} |
| 35 MockDbusGlib dbus_; |
34 }; | 36 }; |
35 | 37 |
36 class UpdateAttempterTest : public ::testing::Test { | 38 class UpdateAttempterTest : public ::testing::Test { |
37 protected: | 39 protected: |
38 virtual void SetUp() { | 40 virtual void SetUp() { |
39 EXPECT_EQ(NULL, attempter_.dbus_service_); | 41 EXPECT_EQ(NULL, attempter_.dbus_service_); |
40 EXPECT_EQ(NULL, attempter_.prefs_); | 42 EXPECT_EQ(NULL, attempter_.prefs_); |
41 EXPECT_EQ(NULL, attempter_.metrics_lib_); | 43 EXPECT_EQ(NULL, attempter_.metrics_lib_); |
42 EXPECT_EQ(NULL, attempter_.update_check_scheduler_); | 44 EXPECT_EQ(NULL, attempter_.update_check_scheduler_); |
43 EXPECT_EQ(0, attempter_.http_response_code_); | 45 EXPECT_EQ(0, attempter_.http_response_code_); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 PostinstallRunnerAction::StaticType(), | 176 PostinstallRunnerAction::StaticType(), |
175 OmahaRequestAction::StaticType() | 177 OmahaRequestAction::StaticType() |
176 }; | 178 }; |
177 for (size_t i = 0; i < arraysize(kActionTypes); ++i) { | 179 for (size_t i = 0; i < arraysize(kActionTypes); ++i) { |
178 EXPECT_CALL(*processor_, | 180 EXPECT_CALL(*processor_, |
179 EnqueueAction(Property(&AbstractAction::Type, | 181 EnqueueAction(Property(&AbstractAction::Type, |
180 kActionTypes[i]))).Times(1); | 182 kActionTypes[i]))).Times(1); |
181 } | 183 } |
182 EXPECT_CALL(*processor_, StartProcessing()).Times(1); | 184 EXPECT_CALL(*processor_, StartProcessing()).Times(1); |
183 | 185 |
184 attempter_.Update("", ""); | 186 attempter_.Update("", "", false); |
185 | 187 |
186 EXPECT_EQ(0, attempter_.http_response_code()); | 188 EXPECT_EQ(0, attempter_.http_response_code()); |
187 EXPECT_EQ(&attempter_, processor_->delegate()); | 189 EXPECT_EQ(&attempter_, processor_->delegate()); |
188 EXPECT_EQ(arraysize(kActionTypes), attempter_.actions_.size()); | 190 EXPECT_EQ(arraysize(kActionTypes), attempter_.actions_.size()); |
189 for (size_t i = 0; i < arraysize(kActionTypes); ++i) { | 191 for (size_t i = 0; i < arraysize(kActionTypes); ++i) { |
190 EXPECT_EQ(kActionTypes[i], attempter_.actions_[i]->Type()); | 192 EXPECT_EQ(kActionTypes[i], attempter_.actions_[i]->Type()); |
191 } | 193 } |
192 EXPECT_EQ(attempter_.response_handler_action_.get(), | 194 EXPECT_EQ(attempter_.response_handler_action_.get(), |
193 attempter_.actions_[1].get()); | 195 attempter_.actions_[1].get()); |
194 DownloadAction* download_action = | 196 DownloadAction* download_action = |
195 dynamic_cast<DownloadAction*>(attempter_.actions_[5].get()); | 197 dynamic_cast<DownloadAction*>(attempter_.actions_[5].get()); |
196 ASSERT_TRUE(download_action != NULL); | 198 ASSERT_TRUE(download_action != NULL); |
197 EXPECT_EQ(&attempter_, download_action->delegate()); | 199 EXPECT_EQ(&attempter_, download_action->delegate()); |
198 EXPECT_EQ(UPDATE_STATUS_CHECKING_FOR_UPDATE, attempter_.status()); | 200 EXPECT_EQ(UPDATE_STATUS_CHECKING_FOR_UPDATE, attempter_.status()); |
199 } | 201 } |
200 | 202 |
201 } // namespace chromeos_update_engine | 203 } // namespace chromeos_update_engine |
OLD | NEW |