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

Side by Side Diff: update_attempter_unittest.cc

Issue 3259011: AU: Start an UpdateAttempter unit test suite. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git
Patch Set: Created 10 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 | Annotate | Revision Log
« no previous file with comments | « update_attempter.cc ('k') | update_check_scheduler_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 <base/file_util.h>
6 #include <gtest/gtest.h>
7
8 #include "update_engine/action_mock.h"
9 #include "update_engine/action_processor_mock.h"
10 #include "update_engine/filesystem_copier_action.h"
11 #include "update_engine/postinstall_runner_action.h"
12 #include "update_engine/set_bootable_flag_action.h"
13 #include "update_engine/update_attempter.h"
14
15 using std::string;
16 using testing::InSequence;
17 using testing::Property;
18 using testing::Return;
19
20 namespace chromeos_update_engine {
21
22 // Test a subclass rather than the main class directly so that we can mock out
23 // methods within the class. There're explicit unit test for the mocked out
24 // methods.
25 class UpdateAttempterUnderTest : public UpdateAttempter {
26 public:
27 UpdateAttempterUnderTest()
28 : UpdateAttempter(NULL, NULL) {}
29 };
30
31 class UpdateAttempterTest : public ::testing::Test {
32 protected:
33 virtual void SetUp() {
34 EXPECT_EQ(NULL, attempter_.dbus_service_);
35 EXPECT_EQ(NULL, attempter_.prefs_);
36 EXPECT_EQ(NULL, attempter_.metrics_lib_);
37 EXPECT_EQ(NULL, attempter_.update_check_scheduler_);
38 EXPECT_EQ(0, attempter_.http_response_code_);
39 EXPECT_EQ(utils::kProcessPriorityNormal, attempter_.priority_);
40 EXPECT_EQ(NULL, attempter_.manage_priority_source_);
41 EXPECT_FALSE(attempter_.download_active_);
42 EXPECT_EQ(UPDATE_STATUS_IDLE, attempter_.status_);
43 EXPECT_EQ(0.0, attempter_.download_progress_);
44 EXPECT_EQ(0, attempter_.last_checked_time_);
45 EXPECT_EQ("0.0.0.0", attempter_.new_version_);
46 EXPECT_EQ(0, attempter_.new_size_);
47 processor_ = new ActionProcessorMock();
48 attempter_.processor_.reset(processor_); // Transfers ownership.
49 }
50
51 UpdateAttempterUnderTest attempter_;
52 ActionProcessorMock* processor_;
53 };
54
55 TEST_F(UpdateAttempterTest, ConstructWithUpdatedMarkerTest) {
56 extern const char* kUpdateCompletedMarker;
57 const FilePath kMarker(kUpdateCompletedMarker);
58 EXPECT_EQ(0, file_util::WriteFile(kMarker, "", 0));
59 UpdateAttempterUnderTest attempter;
60 EXPECT_EQ(UPDATE_STATUS_UPDATED_NEED_REBOOT, attempter.status());
61 EXPECT_TRUE(file_util::Delete(kMarker, false));
62 }
63
64 TEST_F(UpdateAttempterTest, GetErrorCodeForActionTest) {
65 extern ActionExitCode GetErrorCodeForAction(AbstractAction* action,
66 ActionExitCode code);
67 EXPECT_EQ(kActionCodeSuccess,
68 GetErrorCodeForAction(NULL, kActionCodeSuccess));
69
70 OmahaRequestParams params;
71 OmahaRequestAction omaha_request_action(NULL, params, NULL, NULL);
72 EXPECT_EQ(kActionCodeOmahaRequestError,
73 GetErrorCodeForAction(&omaha_request_action, kActionCodeError));
74 OmahaResponseHandlerAction omaha_response_handler_action;
75 EXPECT_EQ(kActionCodeOmahaResponseHandlerError,
76 GetErrorCodeForAction(&omaha_response_handler_action,
77 kActionCodeError));
78 FilesystemCopierAction filesystem_copier_action(false);
79 EXPECT_EQ(kActionCodeFilesystemCopierError,
80 GetErrorCodeForAction(&filesystem_copier_action, kActionCodeError));
81 PostinstallRunnerAction postinstall_runner_action(true);
82 EXPECT_EQ(kActionCodePostinstallRunnerError,
83 GetErrorCodeForAction(&postinstall_runner_action,
84 kActionCodeError));
85 SetBootableFlagAction set_bootable_flag_action;
86 EXPECT_EQ(kActionCodeSetBootableFlagError,
87 GetErrorCodeForAction(&set_bootable_flag_action,
88 kActionCodeError));
89 ActionMock action_mock;
90 EXPECT_CALL(action_mock, Type()).Times(1).WillOnce(Return("ActionMock"));
91 EXPECT_EQ(kActionCodeError,
92 GetErrorCodeForAction(&action_mock, kActionCodeError));
93 }
94
95 TEST_F(UpdateAttempterTest, UpdateStatusToStringTest) {
96 extern const char* UpdateStatusToString(UpdateStatus);
97 EXPECT_STREQ("UPDATE_STATUS_IDLE", UpdateStatusToString(UPDATE_STATUS_IDLE));
98 EXPECT_STREQ("UPDATE_STATUS_CHECKING_FOR_UPDATE",
99 UpdateStatusToString(UPDATE_STATUS_CHECKING_FOR_UPDATE));
100 EXPECT_STREQ("UPDATE_STATUS_UPDATE_AVAILABLE",
101 UpdateStatusToString(UPDATE_STATUS_UPDATE_AVAILABLE));
102 EXPECT_STREQ("UPDATE_STATUS_DOWNLOADING",
103 UpdateStatusToString(UPDATE_STATUS_DOWNLOADING));
104 EXPECT_STREQ("UPDATE_STATUS_VERIFYING",
105 UpdateStatusToString(UPDATE_STATUS_VERIFYING));
106 EXPECT_STREQ("UPDATE_STATUS_FINALIZING",
107 UpdateStatusToString(UPDATE_STATUS_FINALIZING));
108 EXPECT_STREQ("UPDATE_STATUS_UPDATED_NEED_REBOOT",
109 UpdateStatusToString(UPDATE_STATUS_UPDATED_NEED_REBOOT));
110 EXPECT_STREQ("UPDATE_STATUS_REPORTING_ERROR_EVENT",
111 UpdateStatusToString(UPDATE_STATUS_REPORTING_ERROR_EVENT));
112 EXPECT_STREQ("unknown status",
113 UpdateStatusToString(static_cast<UpdateStatus>(-1)));
114 }
115
116 TEST_F(UpdateAttempterTest, UpdateTest) {
117 attempter_.set_http_response_code(200);
118 InSequence s;
119 const string kActionTypes[] = {
120 OmahaRequestAction::StaticType(),
121 OmahaResponseHandlerAction::StaticType(),
122 FilesystemCopierAction::StaticType(),
123 FilesystemCopierAction::StaticType(),
124 OmahaRequestAction::StaticType(),
125 DownloadAction::StaticType(),
126 OmahaRequestAction::StaticType(),
127 PostinstallRunnerAction::StaticType(),
128 SetBootableFlagAction::StaticType(),
129 PostinstallRunnerAction::StaticType(),
130 OmahaRequestAction::StaticType()
131 };
132 for (size_t i = 0; i < arraysize(kActionTypes); ++i) {
133 EXPECT_CALL(*processor_,
134 EnqueueAction(Property(&AbstractAction::Type,
135 kActionTypes[i]))).Times(1);
136 }
137 EXPECT_CALL(*processor_, StartProcessing()).Times(1);
138
139 attempter_.Update("", "");
140
141 EXPECT_EQ(0, attempter_.http_response_code());
142 EXPECT_EQ(&attempter_, processor_->delegate());
143 EXPECT_EQ(arraysize(kActionTypes), attempter_.actions_.size());
144 for (size_t i = 0; i < arraysize(kActionTypes); ++i) {
145 EXPECT_EQ(kActionTypes[i], attempter_.actions_[i]->Type());
146 }
147 EXPECT_EQ(attempter_.response_handler_action_.get(),
148 attempter_.actions_[1].get());
149 DownloadAction* download_action =
150 dynamic_cast<DownloadAction*>(attempter_.actions_[5].get());
151 ASSERT_TRUE(download_action != NULL);
152 EXPECT_EQ(&attempter_, download_action->delegate());
153 EXPECT_EQ(UPDATE_STATUS_CHECKING_FOR_UPDATE, attempter_.status());
154 }
155
156 } // namespace chromeos_update_engine
OLDNEW
« no previous file with comments | « update_attempter.cc ('k') | update_check_scheduler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698