Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 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 <string> |
| 6 | #include <vector> |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 7 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 8 | #include <glib.h> |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 9 | |
| 10 | #include "base/string_util.h" |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 11 | #include "base/time.h" |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 12 | #include "gtest/gtest.h" |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 13 | #include "update_engine/action_pipe.h" |
| 14 | #include "update_engine/mock_http_fetcher.h" |
| 15 | #include "update_engine/omaha_hash_calculator.h" |
| 16 | #include "update_engine/omaha_request_action.h" |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 17 | #include "update_engine/omaha_request_params.h" |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 18 | #include "update_engine/prefs_mock.h" |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 19 | #include "update_engine/test_utils.h" |
| 20 | |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 21 | using base::Time; |
| 22 | using base::TimeDelta; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 23 | using std::string; |
| 24 | using std::vector; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 25 | using testing::_; |
| 26 | using testing::AllOf; |
| 27 | using testing::Ge; |
| 28 | using testing::Le; |
Darin Petkov | 9c096d6 | 2010-11-17 14:49:04 -0800 | [diff] [blame] | 29 | using testing::NiceMock; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 30 | using testing::Return; |
| 31 | using testing::SetArgumentPointee; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 32 | |
| 33 | namespace chromeos_update_engine { |
| 34 | |
| 35 | class OmahaRequestActionTest : public ::testing::Test { }; |
| 36 | |
| 37 | namespace { |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 38 | const OmahaRequestParams kDefaultTestParams( |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 39 | OmahaRequestParams::kOsPlatform, |
| 40 | OmahaRequestParams::kOsVersion, |
| 41 | "service_pack", |
| 42 | "x86-generic", |
| 43 | OmahaRequestParams::kAppId, |
| 44 | "0.1.0.0", |
| 45 | "en-US", |
| 46 | "unittest", |
Darin Petkov | fbb4009 | 2010-07-29 17:05:50 -0700 | [diff] [blame] | 47 | "OEM MODEL 09235 7471", |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 48 | false, // delta okay |
| 49 | "http://url"); |
| 50 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 51 | string GetNoUpdateResponse(const string& app_id) { |
| 52 | return string( |
| 53 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " |
| 54 | "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " |
| 55 | "appid=\"") + app_id + "\" status=\"ok\"><ping " |
| 56 | "status=\"ok\"/><updatecheck status=\"noupdate\"/></app></gupdate>"; |
| 57 | } |
| 58 | |
| 59 | string GetUpdateResponse(const string& app_id, |
| 60 | const string& display_version, |
| 61 | const string& more_info_url, |
| 62 | const string& prompt, |
| 63 | const string& codebase, |
| 64 | const string& hash, |
| 65 | const string& needsadmin, |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 66 | const string& size, |
| 67 | const string& deadline) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 68 | return string("<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " |
| 69 | "xmlns=\"http://www.google.com/update2/response\" " |
| 70 | "protocol=\"2.0\"><app " |
| 71 | "appid=\"") + app_id + "\" status=\"ok\"><ping " |
| 72 | "status=\"ok\"/><updatecheck DisplayVersion=\"" + display_version + "\" " |
| 73 | "MoreInfo=\"" + more_info_url + "\" Prompt=\"" + prompt + "\" " |
Andrew de los Reyes | 3270f74 | 2010-07-15 22:28:14 -0700 | [diff] [blame] | 74 | "IsDelta=\"true\" " |
Darin Petkov | d22cb29 | 2010-09-29 10:02:29 -0700 | [diff] [blame] | 75 | "codebase=\"" + codebase + "\" hash=\"not-applicable\" " |
| 76 | "sha256=\"" + hash + "\" needsadmin=\"" + needsadmin + "\" " |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 77 | "size=\"" + size + "\" deadline=\"" + deadline + |
| 78 | "\" status=\"ok\"/></app></gupdate>"; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | class OmahaRequestActionTestProcessorDelegate : public ActionProcessorDelegate { |
| 82 | public: |
| 83 | OmahaRequestActionTestProcessorDelegate() |
| 84 | : loop_(NULL), |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 85 | expected_code_(kActionCodeSuccess) {} |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 86 | virtual ~OmahaRequestActionTestProcessorDelegate() { |
| 87 | } |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 88 | virtual void ProcessingDone(const ActionProcessor* processor, |
| 89 | ActionExitCode code) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 90 | ASSERT_TRUE(loop_); |
| 91 | g_main_loop_quit(loop_); |
| 92 | } |
| 93 | |
| 94 | virtual void ActionCompleted(ActionProcessor* processor, |
| 95 | AbstractAction* action, |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 96 | ActionExitCode code) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 97 | // make sure actions always succeed |
| 98 | if (action->Type() == OmahaRequestAction::StaticType()) |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 99 | EXPECT_EQ(expected_code_, code); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 100 | else |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 101 | EXPECT_EQ(kActionCodeSuccess, code); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 102 | } |
| 103 | GMainLoop *loop_; |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 104 | ActionExitCode expected_code_; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | gboolean StartProcessorInRunLoop(gpointer data) { |
| 108 | ActionProcessor *processor = reinterpret_cast<ActionProcessor*>(data); |
| 109 | processor->StartProcessing(); |
| 110 | return FALSE; |
| 111 | } |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 112 | } // namespace {} |
| 113 | |
| 114 | class OutputObjectCollectorAction; |
| 115 | |
| 116 | template<> |
| 117 | class ActionTraits<OutputObjectCollectorAction> { |
| 118 | public: |
| 119 | // Does not take an object for input |
| 120 | typedef OmahaResponse InputObjectType; |
| 121 | // On success, puts the output path on output |
| 122 | typedef NoneType OutputObjectType; |
| 123 | }; |
| 124 | |
| 125 | class OutputObjectCollectorAction : public Action<OutputObjectCollectorAction> { |
| 126 | public: |
| 127 | OutputObjectCollectorAction() : has_input_object_(false) {} |
| 128 | void PerformAction() { |
| 129 | // copy input object |
| 130 | has_input_object_ = HasInputObject(); |
| 131 | if (has_input_object_) |
| 132 | omaha_response_ = GetInputObject(); |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 133 | processor_->ActionComplete(this, kActionCodeSuccess); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 134 | } |
| 135 | // Should never be called |
| 136 | void TerminateProcessing() { |
| 137 | CHECK(false); |
| 138 | } |
| 139 | // Debugging/logging |
| 140 | static std::string StaticType() { |
| 141 | return "OutputObjectCollectorAction"; |
| 142 | } |
| 143 | std::string Type() const { return StaticType(); } |
| 144 | bool has_input_object_; |
| 145 | OmahaResponse omaha_response_; |
| 146 | }; |
| 147 | |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 148 | // Returns true iff an output response was obtained from the |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 149 | // OmahaRequestAction. |prefs| may be NULL, in which case a local PrefsMock is |
| 150 | // used. out_response may be NULL. If |fail_http_response_code| is |
| 151 | // non-negative, the transfer will fail with that code. out_post_data may be |
| 152 | // null; if non-null, the post-data received by the mock HttpFetcher is |
| 153 | // returned. |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 154 | bool TestUpdateCheck(PrefsInterface* prefs, |
| 155 | const OmahaRequestParams& params, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 156 | const string& http_response, |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 157 | int fail_http_response_code, |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 158 | ActionExitCode expected_code, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 159 | OmahaResponse* out_response, |
| 160 | vector<char>* out_post_data) { |
| 161 | GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE); |
| 162 | MockHttpFetcher* fetcher = new MockHttpFetcher(http_response.data(), |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 163 | http_response.size(), |
| 164 | NULL); |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 165 | if (fail_http_response_code >= 0) { |
| 166 | fetcher->FailTransfer(fail_http_response_code); |
| 167 | } |
Darin Petkov | 9c096d6 | 2010-11-17 14:49:04 -0800 | [diff] [blame] | 168 | NiceMock<PrefsMock> local_prefs; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 169 | OmahaRequestAction action(prefs ? prefs : &local_prefs, |
| 170 | params, |
| 171 | NULL, |
| 172 | fetcher); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 173 | OmahaRequestActionTestProcessorDelegate delegate; |
| 174 | delegate.loop_ = loop; |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 175 | delegate.expected_code_ = expected_code; |
Darin Petkov | a4a8a8c | 2010-07-15 22:21:12 -0700 | [diff] [blame] | 176 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 177 | ActionProcessor processor; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 178 | processor.set_delegate(&delegate); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 179 | processor.EnqueueAction(&action); |
| 180 | |
| 181 | OutputObjectCollectorAction collector_action; |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 182 | BondActions(&action, &collector_action); |
| 183 | processor.EnqueueAction(&collector_action); |
| 184 | |
| 185 | g_timeout_add(0, &StartProcessorInRunLoop, &processor); |
| 186 | g_main_loop_run(loop); |
| 187 | g_main_loop_unref(loop); |
| 188 | if (collector_action.has_input_object_ && out_response) |
| 189 | *out_response = collector_action.omaha_response_; |
| 190 | if (out_post_data) |
| 191 | *out_post_data = fetcher->post_data(); |
| 192 | return collector_action.has_input_object_; |
| 193 | } |
| 194 | |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 195 | // Tests Event requests -- they should always succeed. |out_post_data| |
| 196 | // may be null; if non-null, the post-data received by the mock |
| 197 | // HttpFetcher is returned. |
| 198 | void TestEvent(const OmahaRequestParams& params, |
| 199 | OmahaEvent* event, |
| 200 | const string& http_response, |
| 201 | vector<char>* out_post_data) { |
| 202 | GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE); |
| 203 | MockHttpFetcher* fetcher = new MockHttpFetcher(http_response.data(), |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 204 | http_response.size(), |
| 205 | NULL); |
Darin Petkov | 9c096d6 | 2010-11-17 14:49:04 -0800 | [diff] [blame] | 206 | NiceMock<PrefsMock> prefs; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 207 | OmahaRequestAction action(&prefs, params, event, fetcher); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 208 | OmahaRequestActionTestProcessorDelegate delegate; |
| 209 | delegate.loop_ = loop; |
| 210 | ActionProcessor processor; |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 211 | processor.set_delegate(&delegate); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 212 | processor.EnqueueAction(&action); |
| 213 | |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 214 | g_timeout_add(0, &StartProcessorInRunLoop, &processor); |
| 215 | g_main_loop_run(loop); |
| 216 | g_main_loop_unref(loop); |
| 217 | if (out_post_data) |
| 218 | *out_post_data = fetcher->post_data(); |
| 219 | } |
| 220 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 221 | TEST(OmahaRequestActionTest, NoUpdateTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 222 | OmahaResponse response; |
| 223 | ASSERT_TRUE( |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 224 | TestUpdateCheck(NULL, // prefs |
| 225 | kDefaultTestParams, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 226 | GetNoUpdateResponse(OmahaRequestParams::kAppId), |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 227 | -1, |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 228 | kActionCodeSuccess, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 229 | &response, |
| 230 | NULL)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 231 | EXPECT_FALSE(response.update_exists); |
| 232 | } |
| 233 | |
| 234 | TEST(OmahaRequestActionTest, ValidUpdateTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 235 | OmahaResponse response; |
| 236 | ASSERT_TRUE( |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 237 | TestUpdateCheck(NULL, // prefs |
| 238 | kDefaultTestParams, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 239 | GetUpdateResponse(OmahaRequestParams::kAppId, |
| 240 | "1.2.3.4", // version |
| 241 | "http://more/info", |
| 242 | "true", // prompt |
| 243 | "http://code/base", // dl url |
| 244 | "HASH1234=", // checksum |
| 245 | "false", // needs admin |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 246 | "123", // size |
| 247 | "20101020"), // deadline |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 248 | -1, |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 249 | kActionCodeSuccess, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 250 | &response, |
| 251 | NULL)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 252 | EXPECT_TRUE(response.update_exists); |
| 253 | EXPECT_EQ("1.2.3.4", response.display_version); |
| 254 | EXPECT_EQ("http://code/base", response.codebase); |
| 255 | EXPECT_EQ("http://more/info", response.more_info_url); |
Andrew de los Reyes | 3270f74 | 2010-07-15 22:28:14 -0700 | [diff] [blame] | 256 | EXPECT_TRUE(response.is_delta); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 257 | EXPECT_EQ("HASH1234=", response.hash); |
| 258 | EXPECT_EQ(123, response.size); |
| 259 | EXPECT_FALSE(response.needs_admin); |
| 260 | EXPECT_TRUE(response.prompt); |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 261 | EXPECT_EQ("20101020", response.deadline); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | TEST(OmahaRequestActionTest, NoOutputPipeTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 265 | const string http_response(GetNoUpdateResponse(OmahaRequestParams::kAppId)); |
| 266 | |
| 267 | GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); |
| 268 | |
Darin Petkov | 9c096d6 | 2010-11-17 14:49:04 -0800 | [diff] [blame] | 269 | NiceMock<PrefsMock> prefs; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 270 | OmahaRequestAction action(&prefs, kDefaultTestParams, NULL, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 271 | new MockHttpFetcher(http_response.data(), |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 272 | http_response.size(), |
| 273 | NULL)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 274 | OmahaRequestActionTestProcessorDelegate delegate; |
| 275 | delegate.loop_ = loop; |
| 276 | ActionProcessor processor; |
| 277 | processor.set_delegate(&delegate); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 278 | processor.EnqueueAction(&action); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 279 | |
| 280 | g_timeout_add(0, &StartProcessorInRunLoop, &processor); |
| 281 | g_main_loop_run(loop); |
| 282 | g_main_loop_unref(loop); |
| 283 | EXPECT_FALSE(processor.IsRunning()); |
| 284 | } |
| 285 | |
| 286 | TEST(OmahaRequestActionTest, InvalidXmlTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 287 | OmahaResponse response; |
| 288 | ASSERT_FALSE( |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 289 | TestUpdateCheck(NULL, // prefs |
| 290 | kDefaultTestParams, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 291 | "invalid xml>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 292 | -1, |
| 293 | kActionCodeOmahaRequestXMLParseError, |
| 294 | &response, |
| 295 | NULL)); |
| 296 | EXPECT_FALSE(response.update_exists); |
| 297 | } |
| 298 | |
| 299 | TEST(OmahaRequestActionTest, EmptyResponseTest) { |
| 300 | OmahaResponse response; |
| 301 | ASSERT_FALSE( |
| 302 | TestUpdateCheck(NULL, // prefs |
| 303 | kDefaultTestParams, |
| 304 | "", |
| 305 | -1, |
| 306 | kActionCodeOmahaRequestEmptyResponseError, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 307 | &response, |
| 308 | NULL)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 309 | EXPECT_FALSE(response.update_exists); |
| 310 | } |
| 311 | |
| 312 | TEST(OmahaRequestActionTest, MissingStatusTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 313 | OmahaResponse response; |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 314 | ASSERT_FALSE(TestUpdateCheck( |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 315 | NULL, // prefs |
| 316 | kDefaultTestParams, |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 317 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " |
| 318 | "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " |
| 319 | "appid=\"foo\" status=\"ok\"><ping " |
| 320 | "status=\"ok\"/><updatecheck/></app></gupdate>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 321 | -1, |
| 322 | kActionCodeOmahaRequestNoUpdateCheckStatus, |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 323 | &response, |
| 324 | NULL)); |
| 325 | EXPECT_FALSE(response.update_exists); |
| 326 | } |
| 327 | |
| 328 | TEST(OmahaRequestActionTest, InvalidStatusTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 329 | OmahaResponse response; |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 330 | ASSERT_FALSE(TestUpdateCheck( |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 331 | NULL, // prefs |
| 332 | kDefaultTestParams, |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 333 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " |
| 334 | "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " |
| 335 | "appid=\"foo\" status=\"ok\"><ping " |
| 336 | "status=\"ok\"/><updatecheck status=\"foo\"/></app></gupdate>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 337 | -1, |
| 338 | kActionCodeOmahaRequestBadUpdateCheckStatus, |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 339 | &response, |
| 340 | NULL)); |
| 341 | EXPECT_FALSE(response.update_exists); |
| 342 | } |
| 343 | |
| 344 | TEST(OmahaRequestActionTest, MissingNodesetTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 345 | OmahaResponse response; |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 346 | ASSERT_FALSE(TestUpdateCheck( |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 347 | NULL, // prefs |
| 348 | kDefaultTestParams, |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 349 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " |
| 350 | "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " |
| 351 | "appid=\"foo\" status=\"ok\"><ping " |
| 352 | "status=\"ok\"/></app></gupdate>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 353 | -1, |
| 354 | kActionCodeOmahaRequestNoUpdateCheckNode, |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 355 | &response, |
| 356 | NULL)); |
| 357 | EXPECT_FALSE(response.update_exists); |
| 358 | } |
| 359 | |
| 360 | TEST(OmahaRequestActionTest, MissingFieldTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 361 | OmahaResponse response; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 362 | ASSERT_TRUE(TestUpdateCheck(NULL, // prefs |
| 363 | kDefaultTestParams, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 364 | string("<?xml version=\"1.0\" " |
| 365 | "encoding=\"UTF-8\"?><gupdate " |
| 366 | "xmlns=\"http://www.google.com/" |
| 367 | "update2/response\" " |
| 368 | "protocol=\"2.0\"><app appid=\"") + |
| 369 | OmahaRequestParams::kAppId |
| 370 | + "\" status=\"ok\"><ping " |
| 371 | "status=\"ok\"/><updatecheck " |
| 372 | "DisplayVersion=\"1.2.3.4\" " |
| 373 | "Prompt=\"false\" " |
Darin Petkov | d22cb29 | 2010-09-29 10:02:29 -0700 | [diff] [blame] | 374 | "codebase=\"http://code/base\" hash=\"foo\" " |
| 375 | "sha256=\"HASH1234=\" needsadmin=\"true\" " |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 376 | "size=\"123\" " |
| 377 | "status=\"ok\"/></app></gupdate>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 378 | -1, |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 379 | kActionCodeSuccess, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 380 | &response, |
| 381 | NULL)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 382 | EXPECT_TRUE(response.update_exists); |
| 383 | EXPECT_EQ("1.2.3.4", response.display_version); |
| 384 | EXPECT_EQ("http://code/base", response.codebase); |
| 385 | EXPECT_EQ("", response.more_info_url); |
Andrew de los Reyes | 3270f74 | 2010-07-15 22:28:14 -0700 | [diff] [blame] | 386 | EXPECT_FALSE(response.is_delta); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 387 | EXPECT_EQ("HASH1234=", response.hash); |
| 388 | EXPECT_EQ(123, response.size); |
| 389 | EXPECT_TRUE(response.needs_admin); |
| 390 | EXPECT_FALSE(response.prompt); |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 391 | EXPECT_TRUE(response.deadline.empty()); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | namespace { |
| 395 | class TerminateEarlyTestProcessorDelegate : public ActionProcessorDelegate { |
| 396 | public: |
| 397 | void ProcessingStopped(const ActionProcessor* processor) { |
| 398 | ASSERT_TRUE(loop_); |
| 399 | g_main_loop_quit(loop_); |
| 400 | } |
| 401 | GMainLoop *loop_; |
| 402 | }; |
| 403 | |
| 404 | gboolean TerminateTransferTestStarter(gpointer data) { |
| 405 | ActionProcessor *processor = reinterpret_cast<ActionProcessor*>(data); |
| 406 | processor->StartProcessing(); |
| 407 | CHECK(processor->IsRunning()); |
| 408 | processor->StopProcessing(); |
| 409 | return FALSE; |
| 410 | } |
| 411 | } // namespace {} |
| 412 | |
| 413 | TEST(OmahaRequestActionTest, TerminateTransferTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 414 | string http_response("doesn't matter"); |
| 415 | GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); |
| 416 | |
Darin Petkov | 9c096d6 | 2010-11-17 14:49:04 -0800 | [diff] [blame] | 417 | NiceMock<PrefsMock> prefs; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 418 | OmahaRequestAction action(&prefs, kDefaultTestParams, NULL, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 419 | new MockHttpFetcher(http_response.data(), |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 420 | http_response.size(), |
| 421 | NULL)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 422 | TerminateEarlyTestProcessorDelegate delegate; |
| 423 | delegate.loop_ = loop; |
| 424 | ActionProcessor processor; |
| 425 | processor.set_delegate(&delegate); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 426 | processor.EnqueueAction(&action); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 427 | |
| 428 | g_timeout_add(0, &TerminateTransferTestStarter, &processor); |
| 429 | g_main_loop_run(loop); |
| 430 | g_main_loop_unref(loop); |
| 431 | } |
| 432 | |
| 433 | TEST(OmahaRequestActionTest, XmlEncodeTest) { |
| 434 | EXPECT_EQ("ab", XmlEncode("ab")); |
| 435 | EXPECT_EQ("a<b", XmlEncode("a<b")); |
| 436 | EXPECT_EQ("foo-Ω", XmlEncode("foo-\xce\xa9")); |
| 437 | EXPECT_EQ("<&>", XmlEncode("<&>")); |
| 438 | EXPECT_EQ("&lt;&amp;&gt;", XmlEncode("<&>")); |
| 439 | |
| 440 | vector<char> post_data; |
| 441 | |
| 442 | // Make sure XML Encode is being called on the params |
Darin Petkov | 84c763c | 2010-07-29 16:27:58 -0700 | [diff] [blame] | 443 | OmahaRequestParams params(OmahaRequestParams::kOsPlatform, |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 444 | OmahaRequestParams::kOsVersion, |
| 445 | "testtheservice_pack>", |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 446 | "x86 generic<id", |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 447 | OmahaRequestParams::kAppId, |
| 448 | "0.1.0.0", |
| 449 | "en-US", |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 450 | "unittest_track<", |
Darin Petkov | fbb4009 | 2010-07-29 17:05:50 -0700 | [diff] [blame] | 451 | "<OEM MODEL>", |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 452 | false, // delta okay |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 453 | "http://url"); |
| 454 | OmahaResponse response; |
| 455 | ASSERT_FALSE( |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 456 | TestUpdateCheck(NULL, // prefs |
| 457 | params, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 458 | "invalid xml>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 459 | -1, |
| 460 | kActionCodeOmahaRequestXMLParseError, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 461 | &response, |
| 462 | &post_data)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 463 | // convert post_data to string |
| 464 | string post_str(&post_data[0], post_data.size()); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 465 | EXPECT_NE(post_str.find("testtheservice_pack>"), string::npos); |
| 466 | EXPECT_EQ(post_str.find("testtheservice_pack>"), string::npos); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 467 | EXPECT_NE(post_str.find("x86 generic<id"), string::npos); |
| 468 | EXPECT_EQ(post_str.find("x86 generic<id"), string::npos); |
| 469 | EXPECT_NE(post_str.find("unittest_track&lt;"), string::npos); |
| 470 | EXPECT_EQ(post_str.find("unittest_track<"), string::npos); |
Darin Petkov | fbb4009 | 2010-07-29 17:05:50 -0700 | [diff] [blame] | 471 | EXPECT_NE(post_str.find("<OEM MODEL>"), string::npos); |
| 472 | EXPECT_EQ(post_str.find("<OEM MODEL>"), string::npos); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | TEST(OmahaRequestActionTest, XmlDecodeTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 476 | OmahaResponse response; |
| 477 | ASSERT_TRUE( |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 478 | TestUpdateCheck(NULL, // prefs |
| 479 | kDefaultTestParams, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 480 | GetUpdateResponse(OmahaRequestParams::kAppId, |
| 481 | "1.2.3.4", // version |
| 482 | "testthe<url", // more info |
| 483 | "true", // prompt |
| 484 | "testthe&codebase", // dl url |
| 485 | "HASH1234=", // checksum |
| 486 | "false", // needs admin |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 487 | "123", // size |
| 488 | "<20110101"), // deadline |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 489 | -1, |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 490 | kActionCodeSuccess, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 491 | &response, |
| 492 | NULL)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 493 | |
| 494 | EXPECT_EQ(response.more_info_url, "testthe<url"); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 495 | EXPECT_EQ(response.codebase, "testthe&codebase"); |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 496 | EXPECT_EQ(response.deadline, "<20110101"); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | TEST(OmahaRequestActionTest, ParseIntTest) { |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 500 | OmahaResponse response; |
| 501 | ASSERT_TRUE( |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 502 | TestUpdateCheck(NULL, // prefs |
| 503 | kDefaultTestParams, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 504 | GetUpdateResponse(OmahaRequestParams::kAppId, |
| 505 | "1.2.3.4", // version |
| 506 | "theurl", // more info |
| 507 | "true", // prompt |
| 508 | "thecodebase", // dl url |
| 509 | "HASH1234=", // checksum |
| 510 | "false", // needs admin |
| 511 | // overflows int32: |
Darin Petkov | 6c11864 | 2010-10-21 12:06:30 -0700 | [diff] [blame] | 512 | "123123123123123", // size |
| 513 | "deadline"), |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 514 | -1, |
Darin Petkov | c1a8b42 | 2010-07-19 11:34:49 -0700 | [diff] [blame] | 515 | kActionCodeSuccess, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 516 | &response, |
| 517 | NULL)); |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 518 | |
| 519 | EXPECT_EQ(response.size, 123123123123123ll); |
| 520 | } |
| 521 | |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 522 | TEST(OmahaRequestActionTest, FormatUpdateCheckOutputTest) { |
| 523 | vector<char> post_data; |
Darin Petkov | 95508da | 2011-01-05 12:42:29 -0800 | [diff] [blame] | 524 | NiceMock<PrefsMock> prefs; |
| 525 | EXPECT_CALL(prefs, GetString(kPrefsPreviousVersion, _)) |
| 526 | .WillOnce(DoAll(SetArgumentPointee<1>(string("")), Return(true))); |
| 527 | EXPECT_CALL(prefs, SetString(kPrefsPreviousVersion, _)).Times(0); |
| 528 | ASSERT_FALSE(TestUpdateCheck(&prefs, |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 529 | kDefaultTestParams, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 530 | "invalid xml>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 531 | -1, |
| 532 | kActionCodeOmahaRequestXMLParseError, |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 533 | NULL, // response |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 534 | &post_data)); |
| 535 | // convert post_data to string |
| 536 | string post_str(&post_data[0], post_data.size()); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 537 | EXPECT_NE(post_str.find(" <o:ping a=\"-1\" r=\"-1\"></o:ping>\n" |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 538 | " <o:updatecheck></o:updatecheck>\n"), |
| 539 | string::npos); |
Darin Petkov | fbb4009 | 2010-07-29 17:05:50 -0700 | [diff] [blame] | 540 | EXPECT_NE(post_str.find("hardware_class=\"OEM MODEL 09235 7471\""), |
| 541 | string::npos); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 542 | EXPECT_EQ(post_str.find("o:event"), string::npos); |
| 543 | } |
| 544 | |
Darin Petkov | 95508da | 2011-01-05 12:42:29 -0800 | [diff] [blame] | 545 | TEST(OmahaRequestActionTest, FormatUpdateCheckPrevVersionOutputTest) { |
| 546 | vector<char> post_data; |
| 547 | NiceMock<PrefsMock> prefs; |
| 548 | EXPECT_CALL(prefs, GetString(kPrefsPreviousVersion, _)) |
Darin Petkov | 5c0f36e | 2011-01-13 14:02:36 -0800 | [diff] [blame] | 549 | .WillOnce(DoAll(SetArgumentPointee<1>(string("1.2>3.4")), Return(true))); |
Darin Petkov | 95508da | 2011-01-05 12:42:29 -0800 | [diff] [blame] | 550 | EXPECT_CALL(prefs, SetString(kPrefsPreviousVersion, "")) |
| 551 | .WillOnce(Return(true)); |
| 552 | ASSERT_FALSE(TestUpdateCheck(&prefs, |
| 553 | kDefaultTestParams, |
| 554 | "invalid xml>", |
| 555 | -1, |
| 556 | kActionCodeOmahaRequestXMLParseError, |
| 557 | NULL, // response |
| 558 | &post_data)); |
| 559 | // convert post_data to string |
| 560 | string post_str(&post_data[0], post_data.size()); |
| 561 | EXPECT_NE(post_str.find(" <o:ping a=\"-1\" r=\"-1\"></o:ping>\n" |
| 562 | " <o:updatecheck></o:updatecheck>\n"), |
| 563 | string::npos); |
| 564 | EXPECT_NE(post_str.find("hardware_class=\"OEM MODEL 09235 7471\""), |
| 565 | string::npos); |
| 566 | string prev_version_event = StringPrintf( |
| 567 | " <o:event eventtype=\"%d\" eventresult=\"%d\" " |
Darin Petkov | 5c0f36e | 2011-01-13 14:02:36 -0800 | [diff] [blame] | 568 | "previousversion=\"1.2>3.4\"></o:event>\n", |
Darin Petkov | 95508da | 2011-01-05 12:42:29 -0800 | [diff] [blame] | 569 | OmahaEvent::kTypeUpdateComplete, |
| 570 | OmahaEvent::kResultSuccessReboot); |
| 571 | EXPECT_NE(post_str.find(prev_version_event), string::npos); |
| 572 | } |
| 573 | |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 574 | TEST(OmahaRequestActionTest, FormatSuccessEventOutputTest) { |
| 575 | vector<char> post_data; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 576 | TestEvent(kDefaultTestParams, |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 577 | new OmahaEvent(OmahaEvent::kTypeUpdateDownloadStarted), |
| 578 | "invalid xml>", |
| 579 | &post_data); |
| 580 | // convert post_data to string |
| 581 | string post_str(&post_data[0], post_data.size()); |
| 582 | string expected_event = StringPrintf( |
| 583 | " <o:event eventtype=\"%d\" eventresult=\"%d\"></o:event>\n", |
| 584 | OmahaEvent::kTypeUpdateDownloadStarted, |
| 585 | OmahaEvent::kResultSuccess); |
| 586 | EXPECT_NE(post_str.find(expected_event), string::npos); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 587 | EXPECT_EQ(post_str.find("o:ping"), string::npos); |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 588 | EXPECT_EQ(post_str.find("o:updatecheck"), string::npos); |
| 589 | } |
| 590 | |
| 591 | TEST(OmahaRequestActionTest, FormatErrorEventOutputTest) { |
| 592 | vector<char> post_data; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 593 | TestEvent(kDefaultTestParams, |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 594 | new OmahaEvent(OmahaEvent::kTypeDownloadComplete, |
| 595 | OmahaEvent::kResultError, |
| 596 | kActionCodeError), |
| 597 | "invalid xml>", |
| 598 | &post_data); |
| 599 | // convert post_data to string |
| 600 | string post_str(&post_data[0], post_data.size()); |
| 601 | string expected_event = StringPrintf( |
| 602 | " <o:event eventtype=\"%d\" eventresult=\"%d\" " |
| 603 | "errorcode=\"%d\"></o:event>\n", |
| 604 | OmahaEvent::kTypeDownloadComplete, |
| 605 | OmahaEvent::kResultError, |
Darin Petkov | 44d98d9 | 2011-03-21 16:08:11 -0700 | [diff] [blame^] | 606 | kActionCodeError); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 607 | EXPECT_NE(post_str.find(expected_event), string::npos); |
| 608 | EXPECT_EQ(post_str.find("o:updatecheck"), string::npos); |
| 609 | } |
| 610 | |
| 611 | TEST(OmahaRequestActionTest, IsEventTest) { |
| 612 | string http_response("doesn't matter"); |
Darin Petkov | 9c096d6 | 2010-11-17 14:49:04 -0800 | [diff] [blame] | 613 | NiceMock<PrefsMock> prefs; |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 614 | OmahaRequestAction update_check_action( |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 615 | &prefs, |
| 616 | kDefaultTestParams, |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 617 | NULL, |
| 618 | new MockHttpFetcher(http_response.data(), |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 619 | http_response.size(), |
| 620 | NULL)); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 621 | EXPECT_FALSE(update_check_action.IsEvent()); |
| 622 | |
| 623 | OmahaRequestAction event_action( |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 624 | &prefs, |
| 625 | kDefaultTestParams, |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 626 | new OmahaEvent(OmahaEvent::kTypeUpdateComplete), |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 627 | new MockHttpFetcher(http_response.data(), |
Andrew de los Reyes | 4516810 | 2010-11-22 11:13:50 -0800 | [diff] [blame] | 628 | http_response.size(), |
| 629 | NULL)); |
Darin Petkov | 0dc8e9a | 2010-07-14 14:51:57 -0700 | [diff] [blame] | 630 | EXPECT_TRUE(event_action.IsEvent()); |
| 631 | } |
| 632 | |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 633 | TEST(OmahaRequestActionTest, FormatDeltaOkayOutputTest) { |
| 634 | for (int i = 0; i < 2; i++) { |
| 635 | bool delta_okay = i == 1; |
| 636 | const char* delta_okay_str = delta_okay ? "true" : "false"; |
| 637 | vector<char> post_data; |
Darin Petkov | 84c763c | 2010-07-29 16:27:58 -0700 | [diff] [blame] | 638 | OmahaRequestParams params(OmahaRequestParams::kOsPlatform, |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 639 | OmahaRequestParams::kOsVersion, |
| 640 | "service_pack", |
| 641 | "x86-generic", |
| 642 | OmahaRequestParams::kAppId, |
| 643 | "0.1.0.0", |
| 644 | "en-US", |
| 645 | "unittest_track", |
Darin Petkov | fbb4009 | 2010-07-29 17:05:50 -0700 | [diff] [blame] | 646 | "OEM MODEL REV 1234", |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 647 | delta_okay, |
| 648 | "http://url"); |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 649 | ASSERT_FALSE(TestUpdateCheck(NULL, // prefs |
| 650 | params, |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 651 | "invalid xml>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 652 | -1, |
| 653 | kActionCodeOmahaRequestXMLParseError, |
Andrew de los Reyes | 3f0303a | 2010-07-15 22:35:35 -0700 | [diff] [blame] | 654 | NULL, |
| 655 | &post_data)); |
| 656 | // convert post_data to string |
| 657 | string post_str(&post_data[0], post_data.size()); |
| 658 | EXPECT_NE(post_str.find(StringPrintf(" delta_okay=\"%s\"", delta_okay_str)), |
| 659 | string::npos) |
| 660 | << "i = " << i; |
| 661 | } |
| 662 | } |
| 663 | |
Darin Petkov | e17f86b | 2010-07-20 09:12:01 -0700 | [diff] [blame] | 664 | TEST(OmahaRequestActionTest, OmahaEventTest) { |
| 665 | OmahaEvent default_event; |
| 666 | EXPECT_EQ(OmahaEvent::kTypeUnknown, default_event.type); |
| 667 | EXPECT_EQ(OmahaEvent::kResultError, default_event.result); |
| 668 | EXPECT_EQ(kActionCodeError, default_event.error_code); |
| 669 | |
| 670 | OmahaEvent success_event(OmahaEvent::kTypeUpdateDownloadStarted); |
| 671 | EXPECT_EQ(OmahaEvent::kTypeUpdateDownloadStarted, success_event.type); |
| 672 | EXPECT_EQ(OmahaEvent::kResultSuccess, success_event.result); |
| 673 | EXPECT_EQ(kActionCodeSuccess, success_event.error_code); |
| 674 | |
| 675 | OmahaEvent error_event(OmahaEvent::kTypeUpdateDownloadFinished, |
| 676 | OmahaEvent::kResultError, |
| 677 | kActionCodeError); |
| 678 | EXPECT_EQ(OmahaEvent::kTypeUpdateDownloadFinished, error_event.type); |
| 679 | EXPECT_EQ(OmahaEvent::kResultError, error_event.result); |
| 680 | EXPECT_EQ(kActionCodeError, error_event.error_code); |
| 681 | } |
| 682 | |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 683 | TEST(OmahaRequestActionTest, PingTest) { |
Darin Petkov | 9c096d6 | 2010-11-17 14:49:04 -0800 | [diff] [blame] | 684 | NiceMock<PrefsMock> prefs; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 685 | // Add a few hours to the day difference to test no rounding, etc. |
| 686 | int64_t five_days_ago = |
| 687 | (Time::Now() - TimeDelta::FromHours(5 * 24 + 13)).ToInternalValue(); |
| 688 | int64_t six_days_ago = |
| 689 | (Time::Now() - TimeDelta::FromHours(6 * 24 + 11)).ToInternalValue(); |
| 690 | EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _)) |
| 691 | .WillOnce(DoAll(SetArgumentPointee<1>(six_days_ago), Return(true))); |
| 692 | EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _)) |
| 693 | .WillOnce(DoAll(SetArgumentPointee<1>(five_days_ago), Return(true))); |
| 694 | vector<char> post_data; |
| 695 | ASSERT_TRUE( |
| 696 | TestUpdateCheck(&prefs, |
| 697 | kDefaultTestParams, |
| 698 | GetNoUpdateResponse(OmahaRequestParams::kAppId), |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 699 | -1, |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 700 | kActionCodeSuccess, |
| 701 | NULL, |
| 702 | &post_data)); |
| 703 | string post_str(&post_data[0], post_data.size()); |
| 704 | EXPECT_NE(post_str.find("<o:ping a=\"6\" r=\"5\"></o:ping>"), string::npos); |
| 705 | } |
| 706 | |
| 707 | TEST(OmahaRequestActionTest, ActivePingTest) { |
Darin Petkov | 9c096d6 | 2010-11-17 14:49:04 -0800 | [diff] [blame] | 708 | NiceMock<PrefsMock> prefs; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 709 | int64_t three_days_ago = |
| 710 | (Time::Now() - TimeDelta::FromHours(3 * 24 + 12)).ToInternalValue(); |
| 711 | int64_t now = Time::Now().ToInternalValue(); |
| 712 | EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _)) |
| 713 | .WillOnce(DoAll(SetArgumentPointee<1>(three_days_ago), Return(true))); |
| 714 | EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _)) |
| 715 | .WillOnce(DoAll(SetArgumentPointee<1>(now), Return(true))); |
| 716 | vector<char> post_data; |
| 717 | ASSERT_TRUE( |
| 718 | TestUpdateCheck(&prefs, |
| 719 | kDefaultTestParams, |
| 720 | GetNoUpdateResponse(OmahaRequestParams::kAppId), |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 721 | -1, |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 722 | kActionCodeSuccess, |
| 723 | NULL, |
| 724 | &post_data)); |
| 725 | string post_str(&post_data[0], post_data.size()); |
| 726 | EXPECT_NE(post_str.find("<o:ping a=\"3\"></o:ping>"), string::npos); |
| 727 | } |
| 728 | |
| 729 | TEST(OmahaRequestActionTest, RollCallPingTest) { |
Darin Petkov | 9c096d6 | 2010-11-17 14:49:04 -0800 | [diff] [blame] | 730 | NiceMock<PrefsMock> prefs; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 731 | int64_t four_days_ago = |
| 732 | (Time::Now() - TimeDelta::FromHours(4 * 24)).ToInternalValue(); |
| 733 | int64_t now = Time::Now().ToInternalValue(); |
| 734 | EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _)) |
| 735 | .WillOnce(DoAll(SetArgumentPointee<1>(now), Return(true))); |
| 736 | EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _)) |
| 737 | .WillOnce(DoAll(SetArgumentPointee<1>(four_days_ago), Return(true))); |
| 738 | vector<char> post_data; |
| 739 | ASSERT_TRUE( |
| 740 | TestUpdateCheck(&prefs, |
| 741 | kDefaultTestParams, |
| 742 | GetNoUpdateResponse(OmahaRequestParams::kAppId), |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 743 | -1, |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 744 | kActionCodeSuccess, |
| 745 | NULL, |
| 746 | &post_data)); |
| 747 | string post_str(&post_data[0], post_data.size()); |
| 748 | EXPECT_NE(post_str.find("<o:ping r=\"4\"></o:ping>\n"), string::npos); |
| 749 | } |
| 750 | |
| 751 | TEST(OmahaRequestActionTest, NoPingTest) { |
Darin Petkov | 9c096d6 | 2010-11-17 14:49:04 -0800 | [diff] [blame] | 752 | NiceMock<PrefsMock> prefs; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 753 | int64_t one_hour_ago = |
| 754 | (Time::Now() - TimeDelta::FromHours(1)).ToInternalValue(); |
| 755 | EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _)) |
| 756 | .WillOnce(DoAll(SetArgumentPointee<1>(one_hour_ago), Return(true))); |
| 757 | EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _)) |
| 758 | .WillOnce(DoAll(SetArgumentPointee<1>(one_hour_ago), Return(true))); |
| 759 | EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)).Times(0); |
| 760 | EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)).Times(0); |
| 761 | vector<char> post_data; |
| 762 | ASSERT_TRUE( |
| 763 | TestUpdateCheck(&prefs, |
| 764 | kDefaultTestParams, |
| 765 | GetNoUpdateResponse(OmahaRequestParams::kAppId), |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 766 | -1, |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 767 | kActionCodeSuccess, |
| 768 | NULL, |
| 769 | &post_data)); |
| 770 | string post_str(&post_data[0], post_data.size()); |
| 771 | EXPECT_EQ(post_str.find("o:ping"), string::npos); |
| 772 | } |
| 773 | |
| 774 | TEST(OmahaRequestActionTest, BackInTimePingTest) { |
Darin Petkov | 9c096d6 | 2010-11-17 14:49:04 -0800 | [diff] [blame] | 775 | NiceMock<PrefsMock> prefs; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 776 | int64_t future = |
| 777 | (Time::Now() + TimeDelta::FromHours(3 * 24 + 4)).ToInternalValue(); |
| 778 | EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _)) |
| 779 | .WillOnce(DoAll(SetArgumentPointee<1>(future), Return(true))); |
| 780 | EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _)) |
| 781 | .WillOnce(DoAll(SetArgumentPointee<1>(future), Return(true))); |
| 782 | EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)) |
| 783 | .WillOnce(Return(true)); |
| 784 | EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)) |
| 785 | .WillOnce(Return(true)); |
| 786 | vector<char> post_data; |
| 787 | ASSERT_TRUE( |
| 788 | TestUpdateCheck(&prefs, |
| 789 | kDefaultTestParams, |
| 790 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " |
| 791 | "xmlns=\"http://www.google.com/update2/response\" " |
| 792 | "protocol=\"2.0\"><daystart elapsed_seconds=\"100\"/>" |
| 793 | "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>" |
| 794 | "<updatecheck status=\"noupdate\"/></app></gupdate>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 795 | -1, |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 796 | kActionCodeSuccess, |
| 797 | NULL, |
| 798 | &post_data)); |
| 799 | string post_str(&post_data[0], post_data.size()); |
| 800 | EXPECT_EQ(post_str.find("o:ping"), string::npos); |
| 801 | } |
| 802 | |
| 803 | TEST(OmahaRequestActionTest, LastPingDayUpdateTest) { |
| 804 | // This test checks that the action updates the last ping day to now |
Darin Petkov | 84c763c | 2010-07-29 16:27:58 -0700 | [diff] [blame] | 805 | // minus 200 seconds with a slack of 5 seconds. Therefore, the test |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 806 | // may fail if it runs for longer than 5 seconds. It shouldn't run |
| 807 | // that long though. |
| 808 | int64_t midnight = |
| 809 | (Time::Now() - TimeDelta::FromSeconds(200)).ToInternalValue(); |
| 810 | int64_t midnight_slack = |
| 811 | (Time::Now() - TimeDelta::FromSeconds(195)).ToInternalValue(); |
Darin Petkov | 9c096d6 | 2010-11-17 14:49:04 -0800 | [diff] [blame] | 812 | NiceMock<PrefsMock> prefs; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 813 | EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, |
| 814 | AllOf(Ge(midnight), Le(midnight_slack)))) |
| 815 | .WillOnce(Return(true)); |
| 816 | EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, |
| 817 | AllOf(Ge(midnight), Le(midnight_slack)))) |
| 818 | .WillOnce(Return(true)); |
| 819 | ASSERT_TRUE( |
| 820 | TestUpdateCheck(&prefs, |
| 821 | kDefaultTestParams, |
| 822 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " |
| 823 | "xmlns=\"http://www.google.com/update2/response\" " |
| 824 | "protocol=\"2.0\"><daystart elapsed_seconds=\"200\"/>" |
| 825 | "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>" |
| 826 | "<updatecheck status=\"noupdate\"/></app></gupdate>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 827 | -1, |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 828 | kActionCodeSuccess, |
| 829 | NULL, |
| 830 | NULL)); |
| 831 | } |
| 832 | |
| 833 | TEST(OmahaRequestActionTest, NoElapsedSecondsTest) { |
Darin Petkov | 9c096d6 | 2010-11-17 14:49:04 -0800 | [diff] [blame] | 834 | NiceMock<PrefsMock> prefs; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 835 | EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)).Times(0); |
| 836 | EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)).Times(0); |
| 837 | ASSERT_TRUE( |
| 838 | TestUpdateCheck(&prefs, |
| 839 | kDefaultTestParams, |
| 840 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " |
| 841 | "xmlns=\"http://www.google.com/update2/response\" " |
| 842 | "protocol=\"2.0\"><daystart blah=\"200\"/>" |
| 843 | "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>" |
| 844 | "<updatecheck status=\"noupdate\"/></app></gupdate>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 845 | -1, |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 846 | kActionCodeSuccess, |
| 847 | NULL, |
| 848 | NULL)); |
| 849 | } |
| 850 | |
| 851 | TEST(OmahaRequestActionTest, BadElapsedSecondsTest) { |
Darin Petkov | 9c096d6 | 2010-11-17 14:49:04 -0800 | [diff] [blame] | 852 | NiceMock<PrefsMock> prefs; |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 853 | EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)).Times(0); |
| 854 | EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)).Times(0); |
| 855 | ASSERT_TRUE( |
| 856 | TestUpdateCheck(&prefs, |
| 857 | kDefaultTestParams, |
| 858 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " |
| 859 | "xmlns=\"http://www.google.com/update2/response\" " |
| 860 | "protocol=\"2.0\"><daystart elapsed_seconds=\"x\"/>" |
| 861 | "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>" |
| 862 | "<updatecheck status=\"noupdate\"/></app></gupdate>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 863 | -1, |
Darin Petkov | 1cbd78f | 2010-07-29 12:38:34 -0700 | [diff] [blame] | 864 | kActionCodeSuccess, |
| 865 | NULL, |
| 866 | NULL)); |
| 867 | } |
| 868 | |
Darin Petkov | 84c763c | 2010-07-29 16:27:58 -0700 | [diff] [blame] | 869 | TEST(OmahaRequestActionTest, NoUniqueIDTest) { |
| 870 | vector<char> post_data; |
| 871 | ASSERT_FALSE(TestUpdateCheck(NULL, // prefs |
| 872 | kDefaultTestParams, |
| 873 | "invalid xml>", |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 874 | -1, |
| 875 | kActionCodeOmahaRequestXMLParseError, |
Darin Petkov | 84c763c | 2010-07-29 16:27:58 -0700 | [diff] [blame] | 876 | NULL, // response |
| 877 | &post_data)); |
| 878 | // convert post_data to string |
| 879 | string post_str(&post_data[0], post_data.size()); |
| 880 | EXPECT_EQ(post_str.find("machineid="), string::npos); |
| 881 | EXPECT_EQ(post_str.find("userid="), string::npos); |
| 882 | } |
| 883 | |
Darin Petkov | edc522e | 2010-11-05 09:35:17 -0700 | [diff] [blame] | 884 | TEST(OmahaRequestActionTest, NetworkFailureTest) { |
| 885 | OmahaResponse response; |
| 886 | ASSERT_FALSE( |
| 887 | TestUpdateCheck(NULL, // prefs |
| 888 | kDefaultTestParams, |
| 889 | "", |
| 890 | 501, |
| 891 | static_cast<ActionExitCode>( |
| 892 | kActionCodeOmahaRequestHTTPResponseBase + 501), |
| 893 | &response, |
| 894 | NULL)); |
| 895 | EXPECT_FALSE(response.update_exists); |
| 896 | } |
| 897 | |
| 898 | TEST(OmahaRequestActionTest, NetworkFailureBadHTTPCodeTest) { |
| 899 | OmahaResponse response; |
| 900 | ASSERT_FALSE( |
| 901 | TestUpdateCheck(NULL, // prefs |
| 902 | kDefaultTestParams, |
| 903 | "", |
| 904 | 1500, |
| 905 | static_cast<ActionExitCode>( |
| 906 | kActionCodeOmahaRequestHTTPResponseBase + 999), |
| 907 | &response, |
| 908 | NULL)); |
| 909 | EXPECT_FALSE(response.update_exists); |
| 910 | } |
| 911 | |
Darin Petkov | 6a5b322 | 2010-07-13 14:55:28 -0700 | [diff] [blame] | 912 | } // namespace chromeos_update_engine |