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

Side by Side Diff: update_attempter_unittest.cc

Issue 6594025: AU: Full proxy support (Closed) Base URL: http://git.chromium.org/git/update_engine.git@master
Patch Set: fixes for review Created 9 years, 9 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_mock.h ('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
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"
(...skipping 15 matching lines...) Expand all
26 using testing::Return; 26 using testing::Return;
27 using testing::SetArgumentPointee; 27 using testing::SetArgumentPointee;
28 28
29 namespace chromeos_update_engine { 29 namespace chromeos_update_engine {
30 30
31 // Test a subclass rather than the main class directly so that we can mock out 31 // Test a subclass rather than the main class directly so that we can mock out
32 // methods within the class. There're explicit unit tests for the mocked out 32 // methods within the class. There're explicit unit tests for the mocked out
33 // methods. 33 // methods.
34 class UpdateAttempterUnderTest : public UpdateAttempter { 34 class UpdateAttempterUnderTest : public UpdateAttempter {
35 public: 35 public:
36 UpdateAttempterUnderTest() 36 explicit UpdateAttempterUnderTest(MockDbusGlib* dbus)
37 : UpdateAttempter(NULL, NULL, &dbus_) {} 37 : UpdateAttempter(NULL, NULL, dbus) {}
38 MockDbusGlib dbus_;
39 }; 38 };
40 39
41 class UpdateAttempterTest : public ::testing::Test { 40 class UpdateAttempterTest : public ::testing::Test {
42 protected: 41 protected:
42 UpdateAttempterTest() : attempter_(&dbus_) {}
43 virtual void SetUp() { 43 virtual void SetUp() {
44 EXPECT_EQ(NULL, attempter_.dbus_service_); 44 EXPECT_EQ(NULL, attempter_.dbus_service_);
45 EXPECT_EQ(NULL, attempter_.prefs_); 45 EXPECT_EQ(NULL, attempter_.prefs_);
46 EXPECT_EQ(NULL, attempter_.metrics_lib_); 46 EXPECT_EQ(NULL, attempter_.metrics_lib_);
47 EXPECT_EQ(NULL, attempter_.update_check_scheduler_); 47 EXPECT_EQ(NULL, attempter_.update_check_scheduler_);
48 EXPECT_EQ(0, attempter_.http_response_code_); 48 EXPECT_EQ(0, attempter_.http_response_code_);
49 EXPECT_EQ(utils::kProcessPriorityNormal, attempter_.priority_); 49 EXPECT_EQ(utils::kProcessPriorityNormal, attempter_.priority_);
50 EXPECT_EQ(NULL, attempter_.manage_priority_source_); 50 EXPECT_EQ(NULL, attempter_.manage_priority_source_);
51 EXPECT_FALSE(attempter_.download_active_); 51 EXPECT_FALSE(attempter_.download_active_);
52 EXPECT_EQ(UPDATE_STATUS_IDLE, attempter_.status_); 52 EXPECT_EQ(UPDATE_STATUS_IDLE, attempter_.status_);
53 EXPECT_EQ(0.0, attempter_.download_progress_); 53 EXPECT_EQ(0.0, attempter_.download_progress_);
54 EXPECT_EQ(0, attempter_.last_checked_time_); 54 EXPECT_EQ(0, attempter_.last_checked_time_);
55 EXPECT_EQ("0.0.0.0", attempter_.new_version_); 55 EXPECT_EQ("0.0.0.0", attempter_.new_version_);
56 EXPECT_EQ(0, attempter_.new_size_); 56 EXPECT_EQ(0, attempter_.new_size_);
57 EXPECT_FALSE(attempter_.is_full_update_); 57 EXPECT_FALSE(attempter_.is_full_update_);
58 processor_ = new ActionProcessorMock(); 58 processor_ = new ActionProcessorMock();
59 attempter_.processor_.reset(processor_); // Transfers ownership. 59 attempter_.processor_.reset(processor_); // Transfers ownership.
60 attempter_.prefs_ = &prefs_; 60 attempter_.prefs_ = &prefs_;
61 } 61 }
62 62
63 MockDbusGlib dbus_;
63 UpdateAttempterUnderTest attempter_; 64 UpdateAttempterUnderTest attempter_;
64 ActionProcessorMock* processor_; 65 ActionProcessorMock* processor_;
65 NiceMock<PrefsMock> prefs_; 66 NiceMock<PrefsMock> prefs_;
66 }; 67 };
67 68
68 TEST_F(UpdateAttempterTest, ActionCompletedDownloadTest) { 69 TEST_F(UpdateAttempterTest, ActionCompletedDownloadTest) {
69 scoped_ptr<MockHttpFetcher> fetcher(new MockHttpFetcher("", 0, NULL)); 70 scoped_ptr<MockHttpFetcher> fetcher(new MockHttpFetcher("", 0, NULL));
70 fetcher->FailTransfer(503); // Sets the HTTP response code. 71 fetcher->FailTransfer(503); // Sets the HTTP response code.
71 DownloadAction action(&prefs_, fetcher.release()); 72 DownloadAction action(&prefs_, fetcher.release());
72 EXPECT_CALL(prefs_, GetInt64(kPrefsDeltaUpdateFailures, _)).Times(0); 73 EXPECT_CALL(prefs_, GetInt64(kPrefsDeltaUpdateFailures, _)).Times(0);
(...skipping 30 matching lines...) Expand all
103 EXPECT_EQ(500, attempter_.http_response_code()); 104 EXPECT_EQ(500, attempter_.http_response_code());
104 EXPECT_EQ(UPDATE_STATUS_IDLE, attempter_.status()); 105 EXPECT_EQ(UPDATE_STATUS_IDLE, attempter_.status());
105 EXPECT_EQ(234, scheduler.poll_interval()); 106 EXPECT_EQ(234, scheduler.poll_interval());
106 ASSERT_TRUE(attempter_.error_event_.get() == NULL); 107 ASSERT_TRUE(attempter_.error_event_.get() == NULL);
107 } 108 }
108 109
109 TEST_F(UpdateAttempterTest, RunAsRootConstructWithUpdatedMarkerTest) { 110 TEST_F(UpdateAttempterTest, RunAsRootConstructWithUpdatedMarkerTest) {
110 extern const char* kUpdateCompletedMarker; 111 extern const char* kUpdateCompletedMarker;
111 const FilePath kMarker(kUpdateCompletedMarker); 112 const FilePath kMarker(kUpdateCompletedMarker);
112 EXPECT_EQ(0, file_util::WriteFile(kMarker, "", 0)); 113 EXPECT_EQ(0, file_util::WriteFile(kMarker, "", 0));
113 UpdateAttempterUnderTest attempter; 114 MockDbusGlib dbus;
115 UpdateAttempterUnderTest attempter(&dbus);
114 EXPECT_EQ(UPDATE_STATUS_UPDATED_NEED_REBOOT, attempter.status()); 116 EXPECT_EQ(UPDATE_STATUS_UPDATED_NEED_REBOOT, attempter.status());
115 EXPECT_TRUE(file_util::Delete(kMarker, false)); 117 EXPECT_TRUE(file_util::Delete(kMarker, false));
116 } 118 }
117 119
118 TEST_F(UpdateAttempterTest, GetErrorCodeForActionTest) { 120 TEST_F(UpdateAttempterTest, GetErrorCodeForActionTest) {
119 extern ActionExitCode GetErrorCodeForAction(AbstractAction* action, 121 extern ActionExitCode GetErrorCodeForAction(AbstractAction* action,
120 ActionExitCode code); 122 ActionExitCode code);
121 EXPECT_EQ(kActionCodeSuccess, 123 EXPECT_EQ(kActionCodeSuccess,
122 GetErrorCodeForAction(NULL, kActionCodeSuccess)); 124 GetErrorCodeForAction(NULL, kActionCodeSuccess));
123 125
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 EXPECT_EQ(attempter_.response_handler_action_.get(), 261 EXPECT_EQ(attempter_.response_handler_action_.get(),
260 attempter_.actions_[1].get()); 262 attempter_.actions_[1].get());
261 DownloadAction* download_action = 263 DownloadAction* download_action =
262 dynamic_cast<DownloadAction*>(attempter_.actions_[5].get()); 264 dynamic_cast<DownloadAction*>(attempter_.actions_[5].get());
263 ASSERT_TRUE(download_action != NULL); 265 ASSERT_TRUE(download_action != NULL);
264 EXPECT_EQ(&attempter_, download_action->delegate()); 266 EXPECT_EQ(&attempter_, download_action->delegate());
265 EXPECT_EQ(UPDATE_STATUS_CHECKING_FOR_UPDATE, attempter_.status()); 267 EXPECT_EQ(UPDATE_STATUS_CHECKING_FOR_UPDATE, attempter_.status());
266 } 268 }
267 269
268 } // namespace chromeos_update_engine 270 } // namespace chromeos_update_engine
OLDNEW
« no previous file with comments | « update_attempter_mock.h ('k') | update_check_scheduler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698