blob: 9291e057937ab85fc72cb837394bfef594cb408e [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
2// Copyright (C) 2012 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
Darin Petkov6a5b3222010-07-13 14:55:28 -070016
Alex Deymo8427b4a2014-11-05 14:00:32 -080017#include "update_engine/omaha_request_action.h"
18
Ben Chan9abb7632014-08-07 00:10:53 -070019#include <stdint.h>
20
Darin Petkov6a5b3222010-07-13 14:55:28 -070021#include <string>
22#include <vector>
Darin Petkov0dc8e9a2010-07-14 14:51:57 -070023
Alex Deymo60ca1a72015-06-18 18:19:15 -070024#include <base/bind.h>
Alex Deymo110e0302015-10-19 20:35:21 -070025#include <base/files/file_util.h>
Sen Jiang297e5832016-03-17 14:45:51 -070026#include <base/files/scoped_temp_dir.h>
Alex Deymo8e18f932015-03-27 16:16:59 -070027#include <base/strings/string_number_conversions.h>
Alex Vakulenko75039d72014-03-25 12:36:28 -070028#include <base/strings/string_util.h>
29#include <base/strings/stringprintf.h>
30#include <base/time/time.h>
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070031#include <brillo/bind_lambda.h>
Alex Deymoc1c17b42015-11-23 03:53:15 -030032#include <brillo/make_unique_ptr.h>
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -070033#include <brillo/message_loops/fake_message_loop.h>
34#include <brillo/message_loops/message_loop.h>
35#include <brillo/message_loops/message_loop_utils.h>
Alex Deymoe1e3afe2014-10-30 13:02:49 -070036#include <gtest/gtest.h>
Jay Srinivasand29695d2013-04-08 15:08:05 -070037
Alex Deymo39910dc2015-11-09 17:04:30 -080038#include "update_engine/common/action_pipe.h"
39#include "update_engine/common/constants.h"
40#include "update_engine/common/fake_prefs.h"
41#include "update_engine/common/hash_calculator.h"
42#include "update_engine/common/mock_http_fetcher.h"
43#include "update_engine/common/platform_constants.h"
44#include "update_engine/common/prefs.h"
45#include "update_engine/common/test_utils.h"
Alex Deymoc1c17b42015-11-23 03:53:15 -030046#include "update_engine/fake_system_state.h"
Alex Deymo38429cf2015-11-11 18:27:22 -080047#include "update_engine/metrics.h"
Chris Sosa77f79e82014-06-02 18:16:24 -070048#include "update_engine/mock_connection_manager.h"
Gilad Arnold74b5f552014-10-07 08:17:16 -070049#include "update_engine/mock_payload_state.h"
Darin Petkova4a8a8c2010-07-15 22:21:12 -070050#include "update_engine/omaha_request_params.h"
Darin Petkov6a5b3222010-07-13 14:55:28 -070051
Darin Petkov1cbd78f2010-07-29 12:38:34 -070052using base::Time;
53using base::TimeDelta;
Darin Petkov6a5b3222010-07-13 14:55:28 -070054using std::string;
55using std::vector;
Darin Petkov1cbd78f2010-07-29 12:38:34 -070056using testing::AllOf;
Alex Deymof329b932014-10-30 01:37:48 -070057using testing::AnyNumber;
Jay Srinivasan34b5d862012-07-23 11:43:22 -070058using testing::DoAll;
Darin Petkov1cbd78f2010-07-29 12:38:34 -070059using testing::Ge;
60using testing::Le;
Darin Petkov9c096d62010-11-17 14:49:04 -080061using testing::NiceMock;
Darin Petkov1cbd78f2010-07-29 12:38:34 -070062using testing::Return;
Gilad Arnold74b5f552014-10-07 08:17:16 -070063using testing::ReturnPointee;
64using testing::SaveArg;
Darin Petkov1cbd78f2010-07-29 12:38:34 -070065using testing::SetArgumentPointee;
Alex Deymof329b932014-10-30 01:37:48 -070066using testing::_;
Darin Petkov6a5b3222010-07-13 14:55:28 -070067
Alex Deymo8e18f932015-03-27 16:16:59 -070068namespace {
69
Alex Deymo85616652015-10-15 18:48:31 -070070const char kTestAppId[] = "test-app-id";
71
Alex Deymo8e18f932015-03-27 16:16:59 -070072// This is a helper struct to allow unit tests build an update response with the
73// values they care about.
74struct FakeUpdateResponse {
75 string GetNoUpdateResponse() const {
76 string entity_str;
77 if (include_entity)
78 entity_str = "<!DOCTYPE response [<!ENTITY CrOS \"ChromeOS\">]>";
Alex Deymo00d79ac2015-06-29 15:41:49 -070079 return
80 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
81 entity_str + "<response protocol=\"3.0\">"
Alex Deymo8e18f932015-03-27 16:16:59 -070082 "<daystart elapsed_seconds=\"100\"/>"
Alex Deymo00d79ac2015-06-29 15:41:49 -070083 "<app appid=\"" + app_id + "\" " +
84 (include_cohorts ? "cohort=\"" + cohort + "\" cohorthint=\"" +
85 cohorthint + "\" cohortname=\"" + cohortname + "\" " : "") +
86 " status=\"ok\">"
87 "<ping status=\"ok\"/>"
88 "<updatecheck status=\"noupdate\"/></app></response>";
Alex Deymo8e18f932015-03-27 16:16:59 -070089 }
90
91 string GetUpdateResponse() const {
92 return
93 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response "
94 "protocol=\"3.0\">"
95 "<daystart elapsed_seconds=\"100\"" +
96 (elapsed_days.empty() ? "" : (" elapsed_days=\"" + elapsed_days + "\""))
97 + "/>"
98 "<app appid=\"" + app_id + "\" " +
99 (include_cohorts ? "cohort=\"" + cohort + "\" cohorthint=\"" +
100 cohorthint + "\" cohortname=\"" + cohortname + "\" " : "") +
101 " status=\"ok\">"
102 "<ping status=\"ok\"/><updatecheck status=\"ok\">"
103 "<urls><url codebase=\"" + codebase + "\"/></urls>"
104 "<manifest version=\"" + version + "\">"
105 "<packages><package hash=\"not-used\" name=\"" + filename + "\" "
106 "size=\"" + base::Int64ToString(size) + "\"/></packages>"
107 "<actions><action event=\"postinstall\" "
108 "ChromeOSVersion=\"" + version + "\" "
109 "MoreInfo=\"" + more_info_url + "\" Prompt=\"" + prompt + "\" "
110 "IsDelta=\"true\" "
111 "IsDeltaPayload=\"true\" "
112 "MaxDaysToScatter=\"" + max_days_to_scatter + "\" "
113 "sha256=\"" + hash + "\" "
114 "needsadmin=\"" + needsadmin + "\" " +
115 (deadline.empty() ? "" : ("deadline=\"" + deadline + "\" ")) +
116 (disable_p2p_for_downloading ?
117 "DisableP2PForDownloading=\"true\" " : "") +
118 (disable_p2p_for_sharing ? "DisableP2PForSharing=\"true\" " : "") +
119 "/></actions></manifest></updatecheck></app></response>";
120 }
121
122 // Return the payload URL, which is split in two fields in the XML response.
123 string GetPayloadUrl() {
124 return codebase + filename;
125 }
126
Alex Deymo85616652015-10-15 18:48:31 -0700127 string app_id = kTestAppId;
Alex Deymo8e18f932015-03-27 16:16:59 -0700128 string version = "1.2.3.4";
129 string more_info_url = "http://more/info";
130 string prompt = "true";
131 string codebase = "http://code/base/";
132 string filename = "file.signed";
133 string hash = "HASH1234=";
134 string needsadmin = "false";
135 int64_t size = 123;
136 string deadline = "";
137 string max_days_to_scatter = "7";
138 string elapsed_days = "42";
139
140 // P2P setting defaults to allowed.
141 bool disable_p2p_for_downloading = false;
142 bool disable_p2p_for_sharing = false;
143
144 // Omaha cohorts settings.
145 bool include_cohorts = false;
146 string cohort = "";
147 string cohorthint = "";
148 string cohortname = "";
149
150 // Whether to include the CrOS <!ENTITY> in the XML response.
151 bool include_entity = false;
152};
153
154} // namespace
155
Darin Petkov6a5b3222010-07-13 14:55:28 -0700156namespace chromeos_update_engine {
157
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700158class OmahaRequestActionTest : public ::testing::Test {
159 protected:
Alex Deymo610277e2014-11-11 21:18:11 -0800160 void SetUp() override {
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700161 fake_system_state_.set_request_params(&request_params_);
162 fake_system_state_.set_prefs(&fake_prefs_);
163 }
164
165 // Returns true iff an output response was obtained from the
Alex Deymo8427b4a2014-11-05 14:00:32 -0800166 // OmahaRequestAction. |prefs| may be null, in which case a local MockPrefs
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700167 // is used. |payload_state| may be null, in which case a local mock is used.
168 // |p2p_manager| may be null, in which case a local mock is used.
169 // |connection_manager| may be null, in which case a local mock is used.
170 // out_response may be null. If |fail_http_response_code| is non-negative,
171 // the transfer will fail with that code. |ping_only| is passed through to the
172 // OmahaRequestAction constructor. out_post_data may be null; if non-null, the
173 // post-data received by the mock HttpFetcher is returned.
174 //
175 // The |expected_check_result|, |expected_check_reaction| and
176 // |expected_error_code| parameters are for checking expectations
177 // about reporting UpdateEngine.Check.{Result,Reaction,DownloadError}
178 // UMA statistics. Use the appropriate ::kUnset value to specify that
179 // the given metric should not be reported.
180 bool TestUpdateCheck(OmahaRequestParams* request_params,
181 const string& http_response,
182 int fail_http_response_code,
183 bool ping_only,
184 ErrorCode expected_code,
185 metrics::CheckResult expected_check_result,
186 metrics::CheckReaction expected_check_reaction,
187 metrics::DownloadErrorCode expected_download_error_code,
188 OmahaResponse* out_response,
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700189 brillo::Blob* out_post_data);
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700190
Alex Vakulenkof68bbbc2015-02-09 12:53:18 -0800191 // Runs and checks a ping test. |ping_only| indicates whether it should send
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700192 // only a ping or also an updatecheck.
193 void PingTest(bool ping_only);
194
195 // InstallDate test helper function.
Alex Deymof329b932014-10-30 01:37:48 -0700196 bool InstallDateParseHelper(const string &elapsed_days,
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700197 OmahaResponse *response);
198
199 // P2P test helper function.
200 void P2PTest(
201 bool initial_allow_p2p_for_downloading,
202 bool initial_allow_p2p_for_sharing,
203 bool omaha_disable_p2p_for_downloading,
204 bool omaha_disable_p2p_for_sharing,
205 bool payload_state_allow_p2p_attempt,
206 bool expect_p2p_client_lookup,
207 const string& p2p_client_result_url,
208 bool expected_allow_p2p_for_downloading,
209 bool expected_allow_p2p_for_sharing,
210 const string& expected_p2p_url);
211
212 FakeSystemState fake_system_state_;
Alex Deymo8e18f932015-03-27 16:16:59 -0700213 FakeUpdateResponse fake_update_response_;
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700214
215 // By default, all tests use these objects unless they replace them in the
216 // fake_system_state_.
217 OmahaRequestParams request_params_ = OmahaRequestParams{
218 &fake_system_state_,
Alex Deymoac41a822015-09-15 20:52:53 -0700219 constants::kOmahaPlatformName,
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700220 OmahaRequestParams::kOsVersion,
221 "service_pack",
222 "x86-generic",
Alex Deymo85616652015-10-15 18:48:31 -0700223 kTestAppId,
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700224 "0.1.0.0",
225 "en-US",
226 "unittest",
227 "OEM MODEL 09235 7471",
228 "ChromeOSFirmware.1.0",
229 "0X0A1",
230 false, // delta okay
231 false, // interactive
232 "http://url",
Gilad Arnold74b5f552014-10-07 08:17:16 -0700233 ""}; // target_version_prefix
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700234
235 FakePrefs fake_prefs_;
236};
Darin Petkov6a5b3222010-07-13 14:55:28 -0700237
238namespace {
Darin Petkov6a5b3222010-07-13 14:55:28 -0700239class OmahaRequestActionTestProcessorDelegate : public ActionProcessorDelegate {
240 public:
241 OmahaRequestActionTestProcessorDelegate()
Alex Deymo60ca1a72015-06-18 18:19:15 -0700242 : expected_code_(ErrorCode::kSuccess) {}
Alex Deymo610277e2014-11-11 21:18:11 -0800243 ~OmahaRequestActionTestProcessorDelegate() override {
Darin Petkov6a5b3222010-07-13 14:55:28 -0700244 }
Yunlian Jiang35866ed2015-01-29 13:09:20 -0800245 void ProcessingDone(const ActionProcessor* processor,
246 ErrorCode code) override {
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700247 brillo::MessageLoop::current()->BreakLoop();
Darin Petkov6a5b3222010-07-13 14:55:28 -0700248 }
249
Yunlian Jiang35866ed2015-01-29 13:09:20 -0800250 void ActionCompleted(ActionProcessor* processor,
251 AbstractAction* action,
252 ErrorCode code) override {
Darin Petkov6a5b3222010-07-13 14:55:28 -0700253 // make sure actions always succeed
254 if (action->Type() == OmahaRequestAction::StaticType())
Darin Petkovc1a8b422010-07-19 11:34:49 -0700255 EXPECT_EQ(expected_code_, code);
Darin Petkov6a5b3222010-07-13 14:55:28 -0700256 else
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700257 EXPECT_EQ(ErrorCode::kSuccess, code);
Darin Petkov6a5b3222010-07-13 14:55:28 -0700258 }
David Zeuthena99981f2013-04-29 13:42:47 -0700259 ErrorCode expected_code_;
Darin Petkov6a5b3222010-07-13 14:55:28 -0700260};
Alex Vakulenkod2779df2014-06-16 13:19:00 -0700261} // namespace
Darin Petkov6a5b3222010-07-13 14:55:28 -0700262
263class OutputObjectCollectorAction;
264
265template<>
266class ActionTraits<OutputObjectCollectorAction> {
267 public:
268 // Does not take an object for input
269 typedef OmahaResponse InputObjectType;
270 // On success, puts the output path on output
271 typedef NoneType OutputObjectType;
272};
273
274class OutputObjectCollectorAction : public Action<OutputObjectCollectorAction> {
275 public:
276 OutputObjectCollectorAction() : has_input_object_(false) {}
277 void PerformAction() {
278 // copy input object
279 has_input_object_ = HasInputObject();
280 if (has_input_object_)
281 omaha_response_ = GetInputObject();
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700282 processor_->ActionComplete(this, ErrorCode::kSuccess);
Darin Petkov6a5b3222010-07-13 14:55:28 -0700283 }
284 // Should never be called
285 void TerminateProcessing() {
286 CHECK(false);
287 }
288 // Debugging/logging
Alex Deymof329b932014-10-30 01:37:48 -0700289 static string StaticType() {
Darin Petkov6a5b3222010-07-13 14:55:28 -0700290 return "OutputObjectCollectorAction";
291 }
Alex Deymof329b932014-10-30 01:37:48 -0700292 string Type() const { return StaticType(); }
Alex Vakulenko0057daa2016-01-23 16:22:50 -0800293 using InputObjectType =
294 ActionTraits<OutputObjectCollectorAction>::InputObjectType;
295 using OutputObjectType =
296 ActionTraits<OutputObjectCollectorAction>::OutputObjectType;
Darin Petkov6a5b3222010-07-13 14:55:28 -0700297 bool has_input_object_;
298 OmahaResponse omaha_response_;
299};
300
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700301bool OmahaRequestActionTest::TestUpdateCheck(
302 OmahaRequestParams* request_params,
303 const string& http_response,
304 int fail_http_response_code,
305 bool ping_only,
306 ErrorCode expected_code,
307 metrics::CheckResult expected_check_result,
308 metrics::CheckReaction expected_check_reaction,
309 metrics::DownloadErrorCode expected_download_error_code,
310 OmahaResponse* out_response,
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700311 brillo::Blob* out_post_data) {
312 brillo::FakeMessageLoop loop(nullptr);
Alex Deymo60ca1a72015-06-18 18:19:15 -0700313 loop.SetAsCurrent();
Darin Petkov0dc8e9a2010-07-14 14:51:57 -0700314 MockHttpFetcher* fetcher = new MockHttpFetcher(http_response.data(),
Andrew de los Reyes45168102010-11-22 11:13:50 -0800315 http_response.size(),
Alex Vakulenko88b591f2014-08-28 16:48:57 -0700316 nullptr);
Darin Petkovedc522e2010-11-05 09:35:17 -0700317 if (fail_http_response_code >= 0) {
318 fetcher->FailTransfer(fail_http_response_code);
319 }
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700320 if (request_params)
321 fake_system_state_.set_request_params(request_params);
322 OmahaRequestAction action(&fake_system_state_,
Alex Vakulenko88b591f2014-08-28 16:48:57 -0700323 nullptr,
Alex Deymoc1c17b42015-11-23 03:53:15 -0300324 brillo::make_unique_ptr(fetcher),
Darin Petkov265f2902011-05-09 15:17:40 -0700325 ping_only);
Darin Petkov6a5b3222010-07-13 14:55:28 -0700326 OmahaRequestActionTestProcessorDelegate delegate;
Darin Petkovc1a8b422010-07-19 11:34:49 -0700327 delegate.expected_code_ = expected_code;
Darin Petkova4a8a8c2010-07-15 22:21:12 -0700328
Darin Petkov6a5b3222010-07-13 14:55:28 -0700329 ActionProcessor processor;
Darin Petkov6a5b3222010-07-13 14:55:28 -0700330 processor.set_delegate(&delegate);
Darin Petkov6a5b3222010-07-13 14:55:28 -0700331 processor.EnqueueAction(&action);
332
333 OutputObjectCollectorAction collector_action;
Darin Petkov6a5b3222010-07-13 14:55:28 -0700334 BondActions(&action, &collector_action);
335 processor.EnqueueAction(&collector_action);
336
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700337 EXPECT_CALL(*fake_system_state_.mock_metrics_lib(), SendEnumToUMA(_, _, _))
David Zeuthen33bae492014-02-25 16:16:18 -0800338 .Times(AnyNumber());
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700339 EXPECT_CALL(*fake_system_state_.mock_metrics_lib(),
David Zeuthen33bae492014-02-25 16:16:18 -0800340 SendEnumToUMA(metrics::kMetricCheckResult,
341 static_cast<int>(expected_check_result),
342 static_cast<int>(metrics::CheckResult::kNumConstants) - 1))
343 .Times(expected_check_result == metrics::CheckResult::kUnset ? 0 : 1);
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700344 EXPECT_CALL(*fake_system_state_.mock_metrics_lib(),
David Zeuthen33bae492014-02-25 16:16:18 -0800345 SendEnumToUMA(metrics::kMetricCheckReaction,
346 static_cast<int>(expected_check_reaction),
347 static_cast<int>(metrics::CheckReaction::kNumConstants) - 1))
348 .Times(expected_check_reaction == metrics::CheckReaction::kUnset ? 0 : 1);
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700349 EXPECT_CALL(*fake_system_state_.mock_metrics_lib(),
David Zeuthenc0dd0212014-04-04 14:49:49 -0700350 SendSparseToUMA(metrics::kMetricCheckDownloadErrorCode,
351 static_cast<int>(expected_download_error_code)))
David Zeuthen33bae492014-02-25 16:16:18 -0800352 .Times(expected_download_error_code == metrics::DownloadErrorCode::kUnset
353 ? 0 : 1);
354
Alex Deymo60ca1a72015-06-18 18:19:15 -0700355 loop.PostTask(base::Bind([&processor] { processor.StartProcessing(); }));
Alex Deymo60ca1a72015-06-18 18:19:15 -0700356 loop.Run();
Alex Deymo60ca1a72015-06-18 18:19:15 -0700357 EXPECT_FALSE(loop.PendingTasks());
Darin Petkov6a5b3222010-07-13 14:55:28 -0700358 if (collector_action.has_input_object_ && out_response)
359 *out_response = collector_action.omaha_response_;
360 if (out_post_data)
361 *out_post_data = fetcher->post_data();
362 return collector_action.has_input_object_;
363}
364
Darin Petkov0dc8e9a2010-07-14 14:51:57 -0700365// Tests Event requests -- they should always succeed. |out_post_data|
366// may be null; if non-null, the post-data received by the mock
367// HttpFetcher is returned.
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700368void TestEvent(OmahaRequestParams params,
Darin Petkov0dc8e9a2010-07-14 14:51:57 -0700369 OmahaEvent* event,
370 const string& http_response,
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700371 brillo::Blob* out_post_data) {
372 brillo::FakeMessageLoop loop(nullptr);
Alex Deymo60ca1a72015-06-18 18:19:15 -0700373 loop.SetAsCurrent();
Darin Petkov0dc8e9a2010-07-14 14:51:57 -0700374 MockHttpFetcher* fetcher = new MockHttpFetcher(http_response.data(),
Andrew de los Reyes45168102010-11-22 11:13:50 -0800375 http_response.size(),
Alex Vakulenko88b591f2014-08-28 16:48:57 -0700376 nullptr);
Gilad Arnold5bb4c902014-04-10 12:32:13 -0700377 FakeSystemState fake_system_state;
378 fake_system_state.set_request_params(&params);
Alex Deymoc1c17b42015-11-23 03:53:15 -0300379 OmahaRequestAction action(&fake_system_state,
380 event,
381 brillo::make_unique_ptr(fetcher),
382 false);
Darin Petkov0dc8e9a2010-07-14 14:51:57 -0700383 OmahaRequestActionTestProcessorDelegate delegate;
Darin Petkov0dc8e9a2010-07-14 14:51:57 -0700384 ActionProcessor processor;
Darin Petkov0dc8e9a2010-07-14 14:51:57 -0700385 processor.set_delegate(&delegate);
Darin Petkov0dc8e9a2010-07-14 14:51:57 -0700386 processor.EnqueueAction(&action);
387
Alex Deymo60ca1a72015-06-18 18:19:15 -0700388 loop.PostTask(base::Bind([&processor] { processor.StartProcessing(); }));
389 loop.Run();
Alex Deymo72a25672016-03-23 15:44:39 -0700390 EXPECT_FALSE(loop.PendingTasks());
Alex Deymo60ca1a72015-06-18 18:19:15 -0700391
Darin Petkov0dc8e9a2010-07-14 14:51:57 -0700392 if (out_post_data)
393 *out_post_data = fetcher->post_data();
394}
395
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700396TEST_F(OmahaRequestActionTest, RejectEntities) {
David Zeuthenf3e28012014-08-26 18:23:52 -0400397 OmahaResponse response;
Alex Deymo8e18f932015-03-27 16:16:59 -0700398 fake_update_response_.include_entity = true;
David Zeuthenf3e28012014-08-26 18:23:52 -0400399 ASSERT_FALSE(
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700400 TestUpdateCheck(nullptr, // request_params
Alex Deymo8e18f932015-03-27 16:16:59 -0700401 fake_update_response_.GetNoUpdateResponse(),
David Zeuthenf3e28012014-08-26 18:23:52 -0400402 -1,
403 false, // ping_only
404 ErrorCode::kOmahaRequestXMLHasEntityDecl,
405 metrics::CheckResult::kParsingError,
406 metrics::CheckReaction::kUnset,
407 metrics::DownloadErrorCode::kUnset,
408 &response,
Alex Vakulenko88b591f2014-08-28 16:48:57 -0700409 nullptr));
David Zeuthenf3e28012014-08-26 18:23:52 -0400410 EXPECT_FALSE(response.update_exists);
411}
412
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700413TEST_F(OmahaRequestActionTest, NoUpdateTest) {
Darin Petkov6a5b3222010-07-13 14:55:28 -0700414 OmahaResponse response;
415 ASSERT_TRUE(
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700416 TestUpdateCheck(nullptr, // request_params
Alex Deymo8e18f932015-03-27 16:16:59 -0700417 fake_update_response_.GetNoUpdateResponse(),
Darin Petkovedc522e2010-11-05 09:35:17 -0700418 -1,
Darin Petkov265f2902011-05-09 15:17:40 -0700419 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700420 ErrorCode::kSuccess,
David Zeuthen33bae492014-02-25 16:16:18 -0800421 metrics::CheckResult::kNoUpdateAvailable,
422 metrics::CheckReaction::kUnset,
423 metrics::DownloadErrorCode::kUnset,
Darin Petkov0dc8e9a2010-07-14 14:51:57 -0700424 &response,
Alex Vakulenko88b591f2014-08-28 16:48:57 -0700425 nullptr));
Darin Petkov6a5b3222010-07-13 14:55:28 -0700426 EXPECT_FALSE(response.update_exists);
427}
428
Alex Deymo8e18f932015-03-27 16:16:59 -0700429// Test that all the values in the response are parsed in a normal update
430// response.
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700431TEST_F(OmahaRequestActionTest, ValidUpdateTest) {
Darin Petkov6a5b3222010-07-13 14:55:28 -0700432 OmahaResponse response;
Alex Deymo8e18f932015-03-27 16:16:59 -0700433 fake_update_response_.deadline = "20101020";
Darin Petkov6a5b3222010-07-13 14:55:28 -0700434 ASSERT_TRUE(
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700435 TestUpdateCheck(nullptr, // request_params
Alex Deymo8e18f932015-03-27 16:16:59 -0700436 fake_update_response_.GetUpdateResponse(),
Darin Petkovedc522e2010-11-05 09:35:17 -0700437 -1,
Darin Petkov265f2902011-05-09 15:17:40 -0700438 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700439 ErrorCode::kSuccess,
David Zeuthen33bae492014-02-25 16:16:18 -0800440 metrics::CheckResult::kUpdateAvailable,
441 metrics::CheckReaction::kUpdating,
442 metrics::DownloadErrorCode::kUnset,
Darin Petkov0dc8e9a2010-07-14 14:51:57 -0700443 &response,
Alex Vakulenko88b591f2014-08-28 16:48:57 -0700444 nullptr));
Darin Petkov6a5b3222010-07-13 14:55:28 -0700445 EXPECT_TRUE(response.update_exists);
Jay Srinivasan34b5d862012-07-23 11:43:22 -0700446 EXPECT_TRUE(response.update_exists);
Alex Deymo8e18f932015-03-27 16:16:59 -0700447 EXPECT_EQ(fake_update_response_.version, response.version);
448 EXPECT_EQ(fake_update_response_.GetPayloadUrl(), response.payload_urls[0]);
449 EXPECT_EQ(fake_update_response_.more_info_url, response.more_info_url);
450 EXPECT_EQ(fake_update_response_.hash, response.hash);
451 EXPECT_EQ(fake_update_response_.size, response.size);
452 EXPECT_EQ(fake_update_response_.prompt == "true", response.prompt);
453 EXPECT_EQ(fake_update_response_.deadline, response.deadline);
454 // Omaha cohort attribets are not set in the response, so they should not be
455 // persisted.
456 EXPECT_FALSE(fake_prefs_.Exists(kPrefsOmahaCohort));
457 EXPECT_FALSE(fake_prefs_.Exists(kPrefsOmahaCohortHint));
458 EXPECT_FALSE(fake_prefs_.Exists(kPrefsOmahaCohortName));
Darin Petkov6a5b3222010-07-13 14:55:28 -0700459}
460
Alex Deymo14ad88e2016-06-29 12:30:14 -0700461TEST_F(OmahaRequestActionTest, ExtraHeadersSentTest) {
462 const string http_response = "<?xml invalid response";
463 request_params_.set_interactive(true);
464
465 brillo::FakeMessageLoop loop(nullptr);
466 loop.SetAsCurrent();
467
468 MockHttpFetcher* fetcher =
469 new MockHttpFetcher(http_response.data(), http_response.size(), nullptr);
470 OmahaRequestAction action(
471 &fake_system_state_, nullptr, brillo::make_unique_ptr(fetcher), false);
472 ActionProcessor processor;
473 processor.EnqueueAction(&action);
474
475 loop.PostTask(base::Bind([&processor] { processor.StartProcessing(); }));
476 loop.Run();
477 EXPECT_FALSE(loop.PendingTasks());
478
479 // Check that the headers were set in the fetcher during the action. Note that
480 // we set this request as "interactive".
481 EXPECT_EQ("fg", fetcher->GetHeader("X-GoogleUpdate-Interactivity"));
482 EXPECT_EQ(kTestAppId, fetcher->GetHeader("X-GoogleUpdate-AppId"));
483 EXPECT_NE("", fetcher->GetHeader("X-GoogleUpdate-Updater"));
484}
485
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700486TEST_F(OmahaRequestActionTest, ValidUpdateBlockedByConnection) {
Chris Sosa77f79e82014-06-02 18:16:24 -0700487 OmahaResponse response;
488 // Set up a connection manager that doesn't allow a valid update over
489 // the current ethernet connection.
Alex Deymof6ee0162015-07-31 12:35:22 -0700490 MockConnectionManager mock_cm;
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700491 fake_system_state_.set_connection_manager(&mock_cm);
492
Alex Deymo30534502015-07-20 15:06:33 -0700493 EXPECT_CALL(mock_cm, GetConnectionProperties(_, _))
494 .WillRepeatedly(
Sen Jiang255e22b2016-05-20 16:15:29 -0700495 DoAll(SetArgumentPointee<0>(ConnectionType::kEthernet),
496 SetArgumentPointee<1>(ConnectionTethering::kUnknown),
Alex Deymo30534502015-07-20 15:06:33 -0700497 Return(true)));
Sen Jiang255e22b2016-05-20 16:15:29 -0700498 EXPECT_CALL(mock_cm, IsUpdateAllowedOver(ConnectionType::kEthernet, _))
499 .WillRepeatedly(Return(false));
Chris Sosa77f79e82014-06-02 18:16:24 -0700500
501 ASSERT_FALSE(
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700502 TestUpdateCheck(nullptr, // request_params
Alex Deymo8e18f932015-03-27 16:16:59 -0700503 fake_update_response_.GetUpdateResponse(),
Chris Sosa77f79e82014-06-02 18:16:24 -0700504 -1,
505 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700506 ErrorCode::kOmahaUpdateIgnoredPerPolicy,
Chris Sosa77f79e82014-06-02 18:16:24 -0700507 metrics::CheckResult::kUpdateAvailable,
508 metrics::CheckReaction::kIgnored,
509 metrics::DownloadErrorCode::kUnset,
510 &response,
Alex Vakulenko88b591f2014-08-28 16:48:57 -0700511 nullptr));
Chris Sosa77f79e82014-06-02 18:16:24 -0700512 EXPECT_FALSE(response.update_exists);
513}
514
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700515TEST_F(OmahaRequestActionTest, ValidUpdateBlockedByRollback) {
Chris Sosa77f79e82014-06-02 18:16:24 -0700516 string rollback_version = "1234.0.0";
517 OmahaResponse response;
518
519 MockPayloadState mock_payload_state;
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700520 fake_system_state_.set_payload_state(&mock_payload_state);
521
Chris Sosa77f79e82014-06-02 18:16:24 -0700522 EXPECT_CALL(mock_payload_state, GetRollbackVersion())
523 .WillRepeatedly(Return(rollback_version));
524
Alex Deymo8e18f932015-03-27 16:16:59 -0700525 fake_update_response_.version = rollback_version;
Chris Sosa77f79e82014-06-02 18:16:24 -0700526 ASSERT_FALSE(
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700527 TestUpdateCheck(nullptr, // request_params
Alex Deymo8e18f932015-03-27 16:16:59 -0700528 fake_update_response_.GetUpdateResponse(),
Chris Sosa77f79e82014-06-02 18:16:24 -0700529 -1,
530 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700531 ErrorCode::kOmahaUpdateIgnoredPerPolicy,
Chris Sosa77f79e82014-06-02 18:16:24 -0700532 metrics::CheckResult::kUpdateAvailable,
533 metrics::CheckReaction::kIgnored,
534 metrics::DownloadErrorCode::kUnset,
535 &response,
Alex Vakulenko88b591f2014-08-28 16:48:57 -0700536 nullptr));
Chris Sosa77f79e82014-06-02 18:16:24 -0700537 EXPECT_FALSE(response.update_exists);
538}
539
Kevin Cernekee2494e282016-03-29 18:03:53 -0700540// Verify that update checks called during OOBE will only try to download
541// an update if the response includes a non-empty deadline field.
542TEST_F(OmahaRequestActionTest, SkipNonCriticalUpdatesBeforeOOBE) {
543 OmahaResponse response;
544
545 fake_system_state_.fake_hardware()->UnsetIsOOBEComplete();
546 ASSERT_FALSE(
547 TestUpdateCheck(nullptr, // request_params
548 fake_update_response_.GetUpdateResponse(),
549 -1,
550 false, // ping_only
551 ErrorCode::kNonCriticalUpdateInOOBE,
552 metrics::CheckResult::kUnset,
553 metrics::CheckReaction::kUnset,
554 metrics::DownloadErrorCode::kUnset,
555 &response,
556 nullptr));
557 EXPECT_FALSE(response.update_exists);
558
Alex Deymo46a9aae2016-05-04 20:20:11 -0700559 // The IsOOBEComplete() value is ignored when the OOBE flow is not enabled.
560 fake_system_state_.fake_hardware()->SetIsOOBEEnabled(false);
561 ASSERT_TRUE(TestUpdateCheck(nullptr, // request_params
562 fake_update_response_.GetUpdateResponse(),
563 -1,
564 false, // ping_only
565 ErrorCode::kSuccess,
566 metrics::CheckResult::kUpdateAvailable,
567 metrics::CheckReaction::kUpdating,
568 metrics::DownloadErrorCode::kUnset,
569 &response,
570 nullptr));
571 EXPECT_TRUE(response.update_exists);
572 fake_system_state_.fake_hardware()->SetIsOOBEEnabled(true);
573
574 // The payload is applied when a deadline was set in the response.
Kevin Cernekee2494e282016-03-29 18:03:53 -0700575 fake_update_response_.deadline = "20101020";
576 ASSERT_TRUE(
577 TestUpdateCheck(nullptr, // request_params
578 fake_update_response_.GetUpdateResponse(),
579 -1,
580 false, // ping_only
581 ErrorCode::kSuccess,
582 metrics::CheckResult::kUpdateAvailable,
583 metrics::CheckReaction::kUpdating,
584 metrics::DownloadErrorCode::kUnset,
585 &response,
586 nullptr));
587 EXPECT_TRUE(response.update_exists);
588}
589
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700590TEST_F(OmahaRequestActionTest, WallClockBasedWaitAloneCausesScattering) {
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700591 OmahaResponse response;
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700592 OmahaRequestParams params = request_params_;
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700593 params.set_wall_clock_based_wait_enabled(true);
594 params.set_update_check_count_wait_enabled(false);
595 params.set_waiting_period(TimeDelta::FromDays(2));
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700596
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700597 ASSERT_FALSE(
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700598 TestUpdateCheck(&params,
Alex Deymo8e18f932015-03-27 16:16:59 -0700599 fake_update_response_.GetUpdateResponse(),
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700600 -1,
601 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700602 ErrorCode::kOmahaUpdateDeferredPerPolicy,
David Zeuthen33bae492014-02-25 16:16:18 -0800603 metrics::CheckResult::kUpdateAvailable,
604 metrics::CheckReaction::kDeferring,
605 metrics::DownloadErrorCode::kUnset,
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700606 &response,
Alex Vakulenko88b591f2014-08-28 16:48:57 -0700607 nullptr));
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700608 EXPECT_FALSE(response.update_exists);
Chris Sosa968d0572013-08-23 14:46:02 -0700609
610 // Verify if we are interactive check we don't defer.
611 params.set_interactive(true);
612 ASSERT_TRUE(
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700613 TestUpdateCheck(&params,
Alex Deymo8e18f932015-03-27 16:16:59 -0700614 fake_update_response_.GetUpdateResponse(),
Chris Sosa968d0572013-08-23 14:46:02 -0700615 -1,
616 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700617 ErrorCode::kSuccess,
David Zeuthen33bae492014-02-25 16:16:18 -0800618 metrics::CheckResult::kUpdateAvailable,
619 metrics::CheckReaction::kUpdating,
620 metrics::DownloadErrorCode::kUnset,
Chris Sosa968d0572013-08-23 14:46:02 -0700621 &response,
Alex Vakulenko88b591f2014-08-28 16:48:57 -0700622 nullptr));
Chris Sosa968d0572013-08-23 14:46:02 -0700623 EXPECT_TRUE(response.update_exists);
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700624}
625
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700626TEST_F(OmahaRequestActionTest, NoWallClockBasedWaitCausesNoScattering) {
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700627 OmahaResponse response;
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700628 OmahaRequestParams params = request_params_;
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700629 params.set_wall_clock_based_wait_enabled(false);
630 params.set_waiting_period(TimeDelta::FromDays(2));
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700631
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700632 params.set_update_check_count_wait_enabled(true);
633 params.set_min_update_checks_needed(1);
634 params.set_max_update_checks_allowed(8);
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700635
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700636 ASSERT_TRUE(
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700637 TestUpdateCheck(&params,
Alex Deymo8e18f932015-03-27 16:16:59 -0700638 fake_update_response_.GetUpdateResponse(),
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700639 -1,
640 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700641 ErrorCode::kSuccess,
David Zeuthen33bae492014-02-25 16:16:18 -0800642 metrics::CheckResult::kUpdateAvailable,
643 metrics::CheckReaction::kUpdating,
644 metrics::DownloadErrorCode::kUnset,
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700645 &response,
Alex Vakulenko88b591f2014-08-28 16:48:57 -0700646 nullptr));
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700647 EXPECT_TRUE(response.update_exists);
648}
649
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700650TEST_F(OmahaRequestActionTest, ZeroMaxDaysToScatterCausesNoScattering) {
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700651 OmahaResponse response;
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700652 OmahaRequestParams params = request_params_;
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700653 params.set_wall_clock_based_wait_enabled(true);
654 params.set_waiting_period(TimeDelta::FromDays(2));
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700655
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700656 params.set_update_check_count_wait_enabled(true);
657 params.set_min_update_checks_needed(1);
658 params.set_max_update_checks_allowed(8);
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700659
Alex Deymo8e18f932015-03-27 16:16:59 -0700660 fake_update_response_.max_days_to_scatter = "0";
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700661 ASSERT_TRUE(
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700662 TestUpdateCheck(&params,
Alex Deymo8e18f932015-03-27 16:16:59 -0700663 fake_update_response_.GetUpdateResponse(),
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700664 -1,
665 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700666 ErrorCode::kSuccess,
David Zeuthen33bae492014-02-25 16:16:18 -0800667 metrics::CheckResult::kUpdateAvailable,
668 metrics::CheckReaction::kUpdating,
669 metrics::DownloadErrorCode::kUnset,
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700670 &response,
Alex Vakulenko88b591f2014-08-28 16:48:57 -0700671 nullptr));
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700672 EXPECT_TRUE(response.update_exists);
673}
674
675
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700676TEST_F(OmahaRequestActionTest, ZeroUpdateCheckCountCausesNoScattering) {
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700677 OmahaResponse response;
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700678 OmahaRequestParams params = request_params_;
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700679 params.set_wall_clock_based_wait_enabled(true);
680 params.set_waiting_period(TimeDelta());
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700681
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700682 params.set_update_check_count_wait_enabled(true);
683 params.set_min_update_checks_needed(0);
684 params.set_max_update_checks_allowed(0);
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700685
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700686 ASSERT_TRUE(TestUpdateCheck(
Alex Vakulenkod2779df2014-06-16 13:19:00 -0700687 &params,
Alex Deymo8e18f932015-03-27 16:16:59 -0700688 fake_update_response_.GetUpdateResponse(),
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700689 -1,
690 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700691 ErrorCode::kSuccess,
David Zeuthen33bae492014-02-25 16:16:18 -0800692 metrics::CheckResult::kUpdateAvailable,
693 metrics::CheckReaction::kUpdating,
694 metrics::DownloadErrorCode::kUnset,
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700695 &response,
Alex Vakulenko88b591f2014-08-28 16:48:57 -0700696 nullptr));
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700697
Ben Chan9abb7632014-08-07 00:10:53 -0700698 int64_t count;
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700699 ASSERT_TRUE(fake_prefs_.GetInt64(kPrefsUpdateCheckCount, &count));
Alex Vakulenkod2779df2014-06-16 13:19:00 -0700700 ASSERT_EQ(count, 0);
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700701 EXPECT_TRUE(response.update_exists);
702}
703
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700704TEST_F(OmahaRequestActionTest, NonZeroUpdateCheckCountCausesScattering) {
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700705 OmahaResponse response;
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700706 OmahaRequestParams params = request_params_;
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700707 params.set_wall_clock_based_wait_enabled(true);
708 params.set_waiting_period(TimeDelta());
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700709
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700710 params.set_update_check_count_wait_enabled(true);
711 params.set_min_update_checks_needed(1);
712 params.set_max_update_checks_allowed(8);
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700713
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700714 ASSERT_FALSE(TestUpdateCheck(
Alex Vakulenkod2779df2014-06-16 13:19:00 -0700715 &params,
Alex Deymo8e18f932015-03-27 16:16:59 -0700716 fake_update_response_.GetUpdateResponse(),
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700717 -1,
718 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700719 ErrorCode::kOmahaUpdateDeferredPerPolicy,
David Zeuthen33bae492014-02-25 16:16:18 -0800720 metrics::CheckResult::kUpdateAvailable,
721 metrics::CheckReaction::kDeferring,
722 metrics::DownloadErrorCode::kUnset,
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700723 &response,
Alex Vakulenko88b591f2014-08-28 16:48:57 -0700724 nullptr));
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700725
Ben Chan9abb7632014-08-07 00:10:53 -0700726 int64_t count;
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700727 ASSERT_TRUE(fake_prefs_.GetInt64(kPrefsUpdateCheckCount, &count));
Alex Vakulenkod2779df2014-06-16 13:19:00 -0700728 ASSERT_GT(count, 0);
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700729 EXPECT_FALSE(response.update_exists);
Chris Sosa968d0572013-08-23 14:46:02 -0700730
731 // Verify if we are interactive check we don't defer.
732 params.set_interactive(true);
733 ASSERT_TRUE(
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700734 TestUpdateCheck(&params,
Alex Deymo8e18f932015-03-27 16:16:59 -0700735 fake_update_response_.GetUpdateResponse(),
Chris Sosa968d0572013-08-23 14:46:02 -0700736 -1,
737 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700738 ErrorCode::kSuccess,
David Zeuthen33bae492014-02-25 16:16:18 -0800739 metrics::CheckResult::kUpdateAvailable,
740 metrics::CheckReaction::kUpdating,
741 metrics::DownloadErrorCode::kUnset,
Chris Sosa968d0572013-08-23 14:46:02 -0700742 &response,
Alex Vakulenko88b591f2014-08-28 16:48:57 -0700743 nullptr));
Chris Sosa968d0572013-08-23 14:46:02 -0700744 EXPECT_TRUE(response.update_exists);
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700745}
746
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700747TEST_F(OmahaRequestActionTest, ExistingUpdateCheckCountCausesScattering) {
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700748 OmahaResponse response;
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700749 OmahaRequestParams params = request_params_;
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700750 params.set_wall_clock_based_wait_enabled(true);
751 params.set_waiting_period(TimeDelta());
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700752
Jay Srinivasanae4697c2013-03-18 17:08:08 -0700753 params.set_update_check_count_wait_enabled(true);
754 params.set_min_update_checks_needed(1);
755 params.set_max_update_checks_allowed(8);
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700756
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700757 ASSERT_TRUE(fake_prefs_.SetInt64(kPrefsUpdateCheckCount, 5));
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700758
759 ASSERT_FALSE(TestUpdateCheck(
Alex Vakulenkod2779df2014-06-16 13:19:00 -0700760 &params,
Alex Deymo8e18f932015-03-27 16:16:59 -0700761 fake_update_response_.GetUpdateResponse(),
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700762 -1,
763 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700764 ErrorCode::kOmahaUpdateDeferredPerPolicy,
David Zeuthen33bae492014-02-25 16:16:18 -0800765 metrics::CheckResult::kUpdateAvailable,
766 metrics::CheckReaction::kDeferring,
767 metrics::DownloadErrorCode::kUnset,
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700768 &response,
Alex Vakulenko88b591f2014-08-28 16:48:57 -0700769 nullptr));
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700770
Ben Chan9abb7632014-08-07 00:10:53 -0700771 int64_t count;
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700772 ASSERT_TRUE(fake_prefs_.GetInt64(kPrefsUpdateCheckCount, &count));
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700773 // count remains the same, as the decrementing happens in update_attempter
774 // which this test doesn't exercise.
Alex Vakulenkod2779df2014-06-16 13:19:00 -0700775 ASSERT_EQ(count, 5);
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700776 EXPECT_FALSE(response.update_exists);
Chris Sosa968d0572013-08-23 14:46:02 -0700777
778 // Verify if we are interactive check we don't defer.
779 params.set_interactive(true);
780 ASSERT_TRUE(
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700781 TestUpdateCheck(&params,
Alex Deymo8e18f932015-03-27 16:16:59 -0700782 fake_update_response_.GetUpdateResponse(),
Chris Sosa968d0572013-08-23 14:46:02 -0700783 -1,
784 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700785 ErrorCode::kSuccess,
David Zeuthen33bae492014-02-25 16:16:18 -0800786 metrics::CheckResult::kUpdateAvailable,
787 metrics::CheckReaction::kUpdating,
788 metrics::DownloadErrorCode::kUnset,
Chris Sosa968d0572013-08-23 14:46:02 -0700789 &response,
Alex Vakulenko88b591f2014-08-28 16:48:57 -0700790 nullptr));
Chris Sosa968d0572013-08-23 14:46:02 -0700791 EXPECT_TRUE(response.update_exists);
Jay Srinivasan480ddfa2012-06-01 19:15:26 -0700792}
Jay Srinivasan0a708742012-03-20 11:26:12 -0700793
Alex Deymo8e18f932015-03-27 16:16:59 -0700794TEST_F(OmahaRequestActionTest, CohortsArePersisted) {
795 OmahaResponse response;
796 OmahaRequestParams params = request_params_;
797 fake_update_response_.include_cohorts = true;
798 fake_update_response_.cohort = "s/154454/8479665";
799 fake_update_response_.cohorthint = "please-put-me-on-beta";
800 fake_update_response_.cohortname = "stable";
801
802 ASSERT_TRUE(TestUpdateCheck(&params,
803 fake_update_response_.GetUpdateResponse(),
804 -1,
805 false, // ping_only
806 ErrorCode::kSuccess,
807 metrics::CheckResult::kUpdateAvailable,
808 metrics::CheckReaction::kUpdating,
809 metrics::DownloadErrorCode::kUnset,
810 &response,
811 nullptr));
812
813 string value;
814 EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohort, &value));
815 EXPECT_EQ(fake_update_response_.cohort, value);
816
817 EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohortHint, &value));
818 EXPECT_EQ(fake_update_response_.cohorthint, value);
819
820 EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohortName, &value));
821 EXPECT_EQ(fake_update_response_.cohortname, value);
822}
823
824TEST_F(OmahaRequestActionTest, CohortsAreUpdated) {
825 OmahaResponse response;
826 OmahaRequestParams params = request_params_;
827 EXPECT_TRUE(fake_prefs_.SetString(kPrefsOmahaCohort, "old_value"));
828 EXPECT_TRUE(fake_prefs_.SetString(kPrefsOmahaCohortHint, "old_hint"));
829 EXPECT_TRUE(fake_prefs_.SetString(kPrefsOmahaCohortName, "old_name"));
830 fake_update_response_.include_cohorts = true;
831 fake_update_response_.cohort = "s/154454/8479665";
832 fake_update_response_.cohorthint = "please-put-me-on-beta";
833 fake_update_response_.cohortname = "";
834
835 ASSERT_TRUE(TestUpdateCheck(&params,
836 fake_update_response_.GetUpdateResponse(),
837 -1,
838 false, // ping_only
839 ErrorCode::kSuccess,
840 metrics::CheckResult::kUpdateAvailable,
841 metrics::CheckReaction::kUpdating,
842 metrics::DownloadErrorCode::kUnset,
843 &response,
844 nullptr));
845
846 string value;
847 EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohort, &value));
848 EXPECT_EQ(fake_update_response_.cohort, value);
849
850 EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohortHint, &value));
851 EXPECT_EQ(fake_update_response_.cohorthint, value);
852
853 EXPECT_FALSE(fake_prefs_.GetString(kPrefsOmahaCohortName, &value));
854}
855
856TEST_F(OmahaRequestActionTest, CohortsAreNotModifiedWhenMissing) {
857 OmahaResponse response;
858 OmahaRequestParams params = request_params_;
859 EXPECT_TRUE(fake_prefs_.SetString(kPrefsOmahaCohort, "old_value"));
860
861 ASSERT_TRUE(TestUpdateCheck(&params,
862 fake_update_response_.GetUpdateResponse(),
863 -1,
864 false, // ping_only
865 ErrorCode::kSuccess,
866 metrics::CheckResult::kUpdateAvailable,
867 metrics::CheckReaction::kUpdating,
868 metrics::DownloadErrorCode::kUnset,
869 &response,
870 nullptr));
871
872 string value;
873 EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohort, &value));
874 EXPECT_EQ("old_value", value);
875
876 EXPECT_FALSE(fake_prefs_.GetString(kPrefsOmahaCohortHint, &value));
877 EXPECT_FALSE(fake_prefs_.GetString(kPrefsOmahaCohortName, &value));
878}
879
Alex Deymo00d79ac2015-06-29 15:41:49 -0700880TEST_F(OmahaRequestActionTest, CohortsArePersistedWhenNoUpdate) {
881 OmahaResponse response;
882 OmahaRequestParams params = request_params_;
883 fake_update_response_.include_cohorts = true;
884 fake_update_response_.cohort = "s/154454/8479665";
885 fake_update_response_.cohorthint = "please-put-me-on-beta";
886 fake_update_response_.cohortname = "stable";
887
888 ASSERT_TRUE(TestUpdateCheck(&params,
889 fake_update_response_.GetNoUpdateResponse(),
890 -1,
891 false, // ping_only
892 ErrorCode::kSuccess,
893 metrics::CheckResult::kNoUpdateAvailable,
894 metrics::CheckReaction::kUnset,
895 metrics::DownloadErrorCode::kUnset,
896 &response,
897 nullptr));
898
899 string value;
900 EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohort, &value));
901 EXPECT_EQ(fake_update_response_.cohort, value);
902
903 EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohortHint, &value));
904 EXPECT_EQ(fake_update_response_.cohorthint, value);
905
906 EXPECT_TRUE(fake_prefs_.GetString(kPrefsOmahaCohortName, &value));
907 EXPECT_EQ(fake_update_response_.cohortname, value);
908}
909
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700910TEST_F(OmahaRequestActionTest, NoOutputPipeTest) {
Alex Deymo8e18f932015-03-27 16:16:59 -0700911 const string http_response(fake_update_response_.GetNoUpdateResponse());
Darin Petkov6a5b3222010-07-13 14:55:28 -0700912
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -0700913 brillo::FakeMessageLoop loop(nullptr);
Alex Deymo60ca1a72015-06-18 18:19:15 -0700914 loop.SetAsCurrent();
Darin Petkov6a5b3222010-07-13 14:55:28 -0700915
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700916 OmahaRequestParams params = request_params_;
917 fake_system_state_.set_request_params(&params);
918 OmahaRequestAction action(&fake_system_state_, nullptr,
Alex Deymoc1c17b42015-11-23 03:53:15 -0300919 brillo::make_unique_ptr(
920 new MockHttpFetcher(http_response.data(),
921 http_response.size(),
922 nullptr)),
Thieu Le116fda32011-04-19 11:01:54 -0700923 false);
Darin Petkov6a5b3222010-07-13 14:55:28 -0700924 OmahaRequestActionTestProcessorDelegate delegate;
Darin Petkov6a5b3222010-07-13 14:55:28 -0700925 ActionProcessor processor;
926 processor.set_delegate(&delegate);
Darin Petkov6a5b3222010-07-13 14:55:28 -0700927 processor.EnqueueAction(&action);
Darin Petkov6a5b3222010-07-13 14:55:28 -0700928
Alex Deymo60ca1a72015-06-18 18:19:15 -0700929 loop.PostTask(base::Bind([&processor] { processor.StartProcessing(); }));
930 loop.Run();
931 EXPECT_FALSE(loop.PendingTasks());
Darin Petkov6a5b3222010-07-13 14:55:28 -0700932 EXPECT_FALSE(processor.IsRunning());
933}
934
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700935TEST_F(OmahaRequestActionTest, InvalidXmlTest) {
Darin Petkov6a5b3222010-07-13 14:55:28 -0700936 OmahaResponse response;
937 ASSERT_FALSE(
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700938 TestUpdateCheck(nullptr, // request_params
Darin Petkov0dc8e9a2010-07-14 14:51:57 -0700939 "invalid xml>",
Darin Petkovedc522e2010-11-05 09:35:17 -0700940 -1,
Darin Petkov265f2902011-05-09 15:17:40 -0700941 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700942 ErrorCode::kOmahaRequestXMLParseError,
David Zeuthen33bae492014-02-25 16:16:18 -0800943 metrics::CheckResult::kParsingError,
944 metrics::CheckReaction::kUnset,
945 metrics::DownloadErrorCode::kUnset,
Darin Petkovedc522e2010-11-05 09:35:17 -0700946 &response,
Alex Vakulenko88b591f2014-08-28 16:48:57 -0700947 nullptr));
Darin Petkovedc522e2010-11-05 09:35:17 -0700948 EXPECT_FALSE(response.update_exists);
949}
950
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700951TEST_F(OmahaRequestActionTest, EmptyResponseTest) {
Darin Petkovedc522e2010-11-05 09:35:17 -0700952 OmahaResponse response;
953 ASSERT_FALSE(
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700954 TestUpdateCheck(nullptr, // request_params
Darin Petkovedc522e2010-11-05 09:35:17 -0700955 "",
956 -1,
Darin Petkov265f2902011-05-09 15:17:40 -0700957 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700958 ErrorCode::kOmahaRequestEmptyResponseError,
David Zeuthen33bae492014-02-25 16:16:18 -0800959 metrics::CheckResult::kParsingError,
960 metrics::CheckReaction::kUnset,
961 metrics::DownloadErrorCode::kUnset,
Darin Petkov0dc8e9a2010-07-14 14:51:57 -0700962 &response,
Alex Vakulenko88b591f2014-08-28 16:48:57 -0700963 nullptr));
Darin Petkov6a5b3222010-07-13 14:55:28 -0700964 EXPECT_FALSE(response.update_exists);
965}
966
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700967TEST_F(OmahaRequestActionTest, MissingStatusTest) {
Darin Petkov6a5b3222010-07-13 14:55:28 -0700968 OmahaResponse response;
Darin Petkov0dc8e9a2010-07-14 14:51:57 -0700969 ASSERT_FALSE(TestUpdateCheck(
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700970 nullptr, // request_params
Jay Srinivasan23b92a52012-10-27 02:00:21 -0700971 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response protocol=\"3.0\">"
972 "<daystart elapsed_seconds=\"100\"/>"
973 "<app appid=\"foo\" status=\"ok\">"
974 "<ping status=\"ok\"/>"
975 "<updatecheck/></app></response>",
Darin Petkovedc522e2010-11-05 09:35:17 -0700976 -1,
Darin Petkov265f2902011-05-09 15:17:40 -0700977 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700978 ErrorCode::kOmahaResponseInvalid,
David Zeuthen33bae492014-02-25 16:16:18 -0800979 metrics::CheckResult::kParsingError,
980 metrics::CheckReaction::kUnset,
981 metrics::DownloadErrorCode::kUnset,
Darin Petkov6a5b3222010-07-13 14:55:28 -0700982 &response,
Alex Vakulenko88b591f2014-08-28 16:48:57 -0700983 nullptr));
Darin Petkov6a5b3222010-07-13 14:55:28 -0700984 EXPECT_FALSE(response.update_exists);
985}
986
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700987TEST_F(OmahaRequestActionTest, InvalidStatusTest) {
Darin Petkov6a5b3222010-07-13 14:55:28 -0700988 OmahaResponse response;
Darin Petkov0dc8e9a2010-07-14 14:51:57 -0700989 ASSERT_FALSE(TestUpdateCheck(
Alex Deymoe1e3afe2014-10-30 13:02:49 -0700990 nullptr, // request_params
Jay Srinivasan23b92a52012-10-27 02:00:21 -0700991 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response protocol=\"3.0\">"
992 "<daystart elapsed_seconds=\"100\"/>"
993 "<app appid=\"foo\" status=\"ok\">"
994 "<ping status=\"ok\"/>"
995 "<updatecheck status=\"InvalidStatusTest\"/></app></response>",
Darin Petkovedc522e2010-11-05 09:35:17 -0700996 -1,
Darin Petkov265f2902011-05-09 15:17:40 -0700997 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -0700998 ErrorCode::kOmahaResponseInvalid,
David Zeuthen33bae492014-02-25 16:16:18 -0800999 metrics::CheckResult::kParsingError,
1000 metrics::CheckReaction::kUnset,
1001 metrics::DownloadErrorCode::kUnset,
Darin Petkov6a5b3222010-07-13 14:55:28 -07001002 &response,
Alex Vakulenko88b591f2014-08-28 16:48:57 -07001003 nullptr));
Darin Petkov6a5b3222010-07-13 14:55:28 -07001004 EXPECT_FALSE(response.update_exists);
1005}
1006
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001007TEST_F(OmahaRequestActionTest, MissingNodesetTest) {
Darin Petkov6a5b3222010-07-13 14:55:28 -07001008 OmahaResponse response;
Darin Petkov0dc8e9a2010-07-14 14:51:57 -07001009 ASSERT_FALSE(TestUpdateCheck(
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001010 nullptr, // request_params
Jay Srinivasan23b92a52012-10-27 02:00:21 -07001011 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response protocol=\"3.0\">"
1012 "<daystart elapsed_seconds=\"100\"/>"
1013 "<app appid=\"foo\" status=\"ok\">"
1014 "<ping status=\"ok\"/>"
1015 "</app></response>",
Darin Petkovedc522e2010-11-05 09:35:17 -07001016 -1,
Darin Petkov265f2902011-05-09 15:17:40 -07001017 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001018 ErrorCode::kOmahaResponseInvalid,
David Zeuthen33bae492014-02-25 16:16:18 -08001019 metrics::CheckResult::kParsingError,
1020 metrics::CheckReaction::kUnset,
1021 metrics::DownloadErrorCode::kUnset,
Darin Petkov6a5b3222010-07-13 14:55:28 -07001022 &response,
Alex Vakulenko88b591f2014-08-28 16:48:57 -07001023 nullptr));
Darin Petkov6a5b3222010-07-13 14:55:28 -07001024 EXPECT_FALSE(response.update_exists);
1025}
1026
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001027TEST_F(OmahaRequestActionTest, MissingFieldTest) {
Jay Srinivasan23b92a52012-10-27 02:00:21 -07001028 string input_response =
1029 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response protocol=\"3.0\">"
1030 "<daystart elapsed_seconds=\"100\"/>"
1031 "<app appid=\"xyz\" status=\"ok\">"
1032 "<updatecheck status=\"ok\">"
1033 "<urls><url codebase=\"http://missing/field/test/\"/></urls>"
Chris Sosa3b748432013-06-20 16:42:59 -07001034 "<manifest version=\"10.2.3.4\">"
Jay Srinivasan23b92a52012-10-27 02:00:21 -07001035 "<packages><package hash=\"not-used\" name=\"f\" "
1036 "size=\"587\"/></packages>"
1037 "<actions><action event=\"postinstall\" "
Jay Srinivasan23b92a52012-10-27 02:00:21 -07001038 "ChromeOSVersion=\"10.2.3.4\" "
1039 "Prompt=\"false\" "
1040 "IsDelta=\"true\" "
Jay Srinivasand671e972013-01-11 17:17:19 -08001041 "IsDeltaPayload=\"false\" "
Jay Srinivasan23b92a52012-10-27 02:00:21 -07001042 "sha256=\"lkq34j5345\" "
1043 "needsadmin=\"true\" "
1044 "/></actions></manifest></updatecheck></app></response>";
1045 LOG(INFO) << "Input Response = " << input_response;
1046
Darin Petkov6a5b3222010-07-13 14:55:28 -07001047 OmahaResponse response;
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001048 ASSERT_TRUE(TestUpdateCheck(nullptr, // request_params
Jay Srinivasan23b92a52012-10-27 02:00:21 -07001049 input_response,
Darin Petkovedc522e2010-11-05 09:35:17 -07001050 -1,
Darin Petkov265f2902011-05-09 15:17:40 -07001051 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001052 ErrorCode::kSuccess,
David Zeuthen33bae492014-02-25 16:16:18 -08001053 metrics::CheckResult::kUpdateAvailable,
1054 metrics::CheckReaction::kUpdating,
1055 metrics::DownloadErrorCode::kUnset,
Darin Petkov0dc8e9a2010-07-14 14:51:57 -07001056 &response,
Alex Vakulenko88b591f2014-08-28 16:48:57 -07001057 nullptr));
Darin Petkov6a5b3222010-07-13 14:55:28 -07001058 EXPECT_TRUE(response.update_exists);
Chris Sosa3b748432013-06-20 16:42:59 -07001059 EXPECT_EQ("10.2.3.4", response.version);
Jay Srinivasan6f6ea002012-12-14 11:26:28 -08001060 EXPECT_EQ("http://missing/field/test/f", response.payload_urls[0]);
Darin Petkov6a5b3222010-07-13 14:55:28 -07001061 EXPECT_EQ("", response.more_info_url);
Jay Srinivasan23b92a52012-10-27 02:00:21 -07001062 EXPECT_EQ("lkq34j5345", response.hash);
1063 EXPECT_EQ(587, response.size);
Darin Petkov6a5b3222010-07-13 14:55:28 -07001064 EXPECT_FALSE(response.prompt);
Darin Petkov6c118642010-10-21 12:06:30 -07001065 EXPECT_TRUE(response.deadline.empty());
Darin Petkov6a5b3222010-07-13 14:55:28 -07001066}
1067
1068namespace {
1069class TerminateEarlyTestProcessorDelegate : public ActionProcessorDelegate {
1070 public:
1071 void ProcessingStopped(const ActionProcessor* processor) {
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -07001072 brillo::MessageLoop::current()->BreakLoop();
Darin Petkov6a5b3222010-07-13 14:55:28 -07001073 }
Darin Petkov6a5b3222010-07-13 14:55:28 -07001074};
1075
Alex Deymo60ca1a72015-06-18 18:19:15 -07001076void TerminateTransferTestStarter(ActionProcessor* processor) {
Darin Petkov6a5b3222010-07-13 14:55:28 -07001077 processor->StartProcessing();
1078 CHECK(processor->IsRunning());
1079 processor->StopProcessing();
Darin Petkov6a5b3222010-07-13 14:55:28 -07001080}
Alex Vakulenkod2779df2014-06-16 13:19:00 -07001081} // namespace
Darin Petkov6a5b3222010-07-13 14:55:28 -07001082
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001083TEST_F(OmahaRequestActionTest, TerminateTransferTest) {
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -07001084 brillo::FakeMessageLoop loop(nullptr);
Alex Deymo60ca1a72015-06-18 18:19:15 -07001085 loop.SetAsCurrent();
Darin Petkov6a5b3222010-07-13 14:55:28 -07001086
Alex Deymo60ca1a72015-06-18 18:19:15 -07001087 string http_response("doesn't matter");
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001088 OmahaRequestAction action(&fake_system_state_, nullptr,
Alex Deymoc1c17b42015-11-23 03:53:15 -03001089 brillo::make_unique_ptr(
1090 new MockHttpFetcher(http_response.data(),
1091 http_response.size(),
1092 nullptr)),
Thieu Le116fda32011-04-19 11:01:54 -07001093 false);
Darin Petkov6a5b3222010-07-13 14:55:28 -07001094 TerminateEarlyTestProcessorDelegate delegate;
Darin Petkov6a5b3222010-07-13 14:55:28 -07001095 ActionProcessor processor;
1096 processor.set_delegate(&delegate);
Darin Petkov6a5b3222010-07-13 14:55:28 -07001097 processor.EnqueueAction(&action);
Darin Petkov6a5b3222010-07-13 14:55:28 -07001098
Alex Deymo60ca1a72015-06-18 18:19:15 -07001099 loop.PostTask(base::Bind(&TerminateTransferTestStarter, &processor));
1100 loop.Run();
1101 EXPECT_FALSE(loop.PendingTasks());
Darin Petkov6a5b3222010-07-13 14:55:28 -07001102}
1103
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001104TEST_F(OmahaRequestActionTest, XmlEncodeTest) {
Alex Deymob0d74eb2015-03-30 17:59:17 -07001105 string output;
1106 EXPECT_TRUE(XmlEncode("ab", &output));
1107 EXPECT_EQ("ab", output);
1108 EXPECT_TRUE(XmlEncode("a<b", &output));
1109 EXPECT_EQ("a&lt;b", output);
Alex Deymocc457852015-06-18 18:35:50 -07001110 EXPECT_TRUE(XmlEncode("<&>\"\'\\", &output));
1111 EXPECT_EQ("&lt;&amp;&gt;&quot;&apos;\\", output);
Alex Deymob0d74eb2015-03-30 17:59:17 -07001112 EXPECT_TRUE(XmlEncode("&lt;&amp;&gt;", &output));
1113 EXPECT_EQ("&amp;lt;&amp;amp;&amp;gt;", output);
Alex Deymocc457852015-06-18 18:35:50 -07001114 // Check that unterminated UTF-8 strings are handled properly.
Alex Deymob0d74eb2015-03-30 17:59:17 -07001115 EXPECT_FALSE(XmlEncode("\xc2", &output));
1116 // Fail with invalid ASCII-7 chars.
1117 EXPECT_FALSE(XmlEncode("This is an 'n' with a tilde: \xc3\xb1", &output));
1118}
Darin Petkov6a5b3222010-07-13 14:55:28 -07001119
Alex Deymob0d74eb2015-03-30 17:59:17 -07001120TEST_F(OmahaRequestActionTest, XmlEncodeWithDefaultTest) {
1121 EXPECT_EQ("&lt;&amp;&gt;", XmlEncodeWithDefault("<&>", "something else"));
1122 EXPECT_EQ("<not escaped>", XmlEncodeWithDefault("\xc2", "<not escaped>"));
1123}
1124
1125TEST_F(OmahaRequestActionTest, XmlEncodeIsUsedForParams) {
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -07001126 brillo::Blob post_data;
Darin Petkov6a5b3222010-07-13 14:55:28 -07001127
1128 // Make sure XML Encode is being called on the params
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001129 OmahaRequestParams params(&fake_system_state_,
Alex Deymoac41a822015-09-15 20:52:53 -07001130 constants::kOmahaPlatformName,
Darin Petkov6a5b3222010-07-13 14:55:28 -07001131 OmahaRequestParams::kOsVersion,
1132 "testtheservice_pack>",
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001133 "x86 generic<id",
Alex Deymo85616652015-10-15 18:48:31 -07001134 kTestAppId,
Darin Petkov6a5b3222010-07-13 14:55:28 -07001135 "0.1.0.0",
1136 "en-US",
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001137 "unittest_track&lt;",
Darin Petkovfbb40092010-07-29 17:05:50 -07001138 "<OEM MODEL>",
Chris Sosac1972482013-04-30 22:31:10 -07001139 "ChromeOSFirmware.1.0",
1140 "EC100",
Alex Vakulenkod2779df2014-06-16 13:19:00 -07001141 false, // delta okay
1142 false, // interactive
Jay Srinivasan0a708742012-03-20 11:26:12 -07001143 "http://url",
Gilad Arnold74b5f552014-10-07 08:17:16 -07001144 ""); // target_version_prefix
Alex Deymo8e18f932015-03-27 16:16:59 -07001145 fake_prefs_.SetString(kPrefsOmahaCohort, "evil\nstring");
1146 fake_prefs_.SetString(kPrefsOmahaCohortHint, "evil&string\\");
1147 fake_prefs_.SetString(kPrefsOmahaCohortName,
Alex Vakulenko0103c362016-01-20 07:56:15 -08001148 base::JoinString(
1149 vector<string>(100, "My spoon is too big."), " "));
Darin Petkov6a5b3222010-07-13 14:55:28 -07001150 OmahaResponse response;
1151 ASSERT_FALSE(
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001152 TestUpdateCheck(&params,
Darin Petkov0dc8e9a2010-07-14 14:51:57 -07001153 "invalid xml>",
Darin Petkovedc522e2010-11-05 09:35:17 -07001154 -1,
Darin Petkov265f2902011-05-09 15:17:40 -07001155 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001156 ErrorCode::kOmahaRequestXMLParseError,
David Zeuthen33bae492014-02-25 16:16:18 -08001157 metrics::CheckResult::kParsingError,
1158 metrics::CheckReaction::kUnset,
1159 metrics::DownloadErrorCode::kUnset,
Darin Petkov0dc8e9a2010-07-14 14:51:57 -07001160 &response,
1161 &post_data));
Darin Petkov6a5b3222010-07-13 14:55:28 -07001162 // convert post_data to string
Alex Vakulenkof68bbbc2015-02-09 12:53:18 -08001163 string post_str(post_data.begin(), post_data.end());
Alex Deymo8e18f932015-03-27 16:16:59 -07001164 EXPECT_NE(string::npos, post_str.find("testtheservice_pack&gt;"));
1165 EXPECT_EQ(string::npos, post_str.find("testtheservice_pack>"));
1166 EXPECT_NE(string::npos, post_str.find("x86 generic&lt;id"));
1167 EXPECT_EQ(string::npos, post_str.find("x86 generic<id"));
1168 EXPECT_NE(string::npos, post_str.find("unittest_track&amp;lt;"));
1169 EXPECT_EQ(string::npos, post_str.find("unittest_track&lt;"));
1170 EXPECT_NE(string::npos, post_str.find("&lt;OEM MODEL&gt;"));
1171 EXPECT_EQ(string::npos, post_str.find("<OEM MODEL>"));
1172 EXPECT_NE(string::npos, post_str.find("cohort=\"evil\nstring\""));
1173 EXPECT_EQ(string::npos, post_str.find("cohorthint=\"evil&string\\\""));
1174 EXPECT_NE(string::npos, post_str.find("cohorthint=\"evil&amp;string\\\""));
1175 // Values from Prefs that are too big are removed from the XML instead of
1176 // encoded.
1177 EXPECT_EQ(string::npos, post_str.find("cohortname="));
Darin Petkov6a5b3222010-07-13 14:55:28 -07001178}
1179
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001180TEST_F(OmahaRequestActionTest, XmlDecodeTest) {
Darin Petkov6a5b3222010-07-13 14:55:28 -07001181 OmahaResponse response;
Alex Deymo8e18f932015-03-27 16:16:59 -07001182 fake_update_response_.deadline = "&lt;20110101";
1183 fake_update_response_.more_info_url = "testthe&lt;url";
1184 fake_update_response_.codebase = "testthe&amp;codebase/";
Darin Petkov6a5b3222010-07-13 14:55:28 -07001185 ASSERT_TRUE(
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001186 TestUpdateCheck(nullptr, // request_params
Alex Deymo8e18f932015-03-27 16:16:59 -07001187 fake_update_response_.GetUpdateResponse(),
Darin Petkovedc522e2010-11-05 09:35:17 -07001188 -1,
Darin Petkov265f2902011-05-09 15:17:40 -07001189 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001190 ErrorCode::kSuccess,
David Zeuthen33bae492014-02-25 16:16:18 -08001191 metrics::CheckResult::kUpdateAvailable,
1192 metrics::CheckReaction::kUpdating,
1193 metrics::DownloadErrorCode::kUnset,
Darin Petkov0dc8e9a2010-07-14 14:51:57 -07001194 &response,
Alex Vakulenko88b591f2014-08-28 16:48:57 -07001195 nullptr));
Darin Petkov6a5b3222010-07-13 14:55:28 -07001196
1197 EXPECT_EQ(response.more_info_url, "testthe<url");
Jay Srinivasan6f6ea002012-12-14 11:26:28 -08001198 EXPECT_EQ(response.payload_urls[0], "testthe&codebase/file.signed");
Darin Petkov6c118642010-10-21 12:06:30 -07001199 EXPECT_EQ(response.deadline, "<20110101");
Darin Petkov6a5b3222010-07-13 14:55:28 -07001200}
1201
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001202TEST_F(OmahaRequestActionTest, ParseIntTest) {
Darin Petkov6a5b3222010-07-13 14:55:28 -07001203 OmahaResponse response;
Alex Deymo8e18f932015-03-27 16:16:59 -07001204 // overflows int32_t:
1205 fake_update_response_.size = 123123123123123ll;
Darin Petkov6a5b3222010-07-13 14:55:28 -07001206 ASSERT_TRUE(
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001207 TestUpdateCheck(nullptr, // request_params
Alex Deymo8e18f932015-03-27 16:16:59 -07001208 fake_update_response_.GetUpdateResponse(),
Darin Petkovedc522e2010-11-05 09:35:17 -07001209 -1,
Darin Petkov265f2902011-05-09 15:17:40 -07001210 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001211 ErrorCode::kSuccess,
David Zeuthen33bae492014-02-25 16:16:18 -08001212 metrics::CheckResult::kUpdateAvailable,
1213 metrics::CheckReaction::kUpdating,
1214 metrics::DownloadErrorCode::kUnset,
Darin Petkov0dc8e9a2010-07-14 14:51:57 -07001215 &response,
Alex Vakulenko88b591f2014-08-28 16:48:57 -07001216 nullptr));
Darin Petkov6a5b3222010-07-13 14:55:28 -07001217
1218 EXPECT_EQ(response.size, 123123123123123ll);
1219}
1220
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001221TEST_F(OmahaRequestActionTest, FormatUpdateCheckOutputTest) {
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -07001222 brillo::Blob post_data;
Alex Deymo8427b4a2014-11-05 14:00:32 -08001223 NiceMock<MockPrefs> prefs;
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001224 fake_system_state_.set_prefs(&prefs);
1225
Darin Petkov95508da2011-01-05 12:42:29 -08001226 EXPECT_CALL(prefs, GetString(kPrefsPreviousVersion, _))
1227 .WillOnce(DoAll(SetArgumentPointee<1>(string("")), Return(true)));
Alex Deymoefb9d832015-11-02 18:39:02 -08001228 // An existing but empty previous version means that we didn't reboot to a new
1229 // update, therefore, no need to update the previous version.
1230 EXPECT_CALL(prefs, SetString(kPrefsPreviousVersion, _)).Times(0);
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001231 ASSERT_FALSE(TestUpdateCheck(nullptr, // request_params
Darin Petkov0dc8e9a2010-07-14 14:51:57 -07001232 "invalid xml>",
Darin Petkovedc522e2010-11-05 09:35:17 -07001233 -1,
Darin Petkov265f2902011-05-09 15:17:40 -07001234 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001235 ErrorCode::kOmahaRequestXMLParseError,
David Zeuthen33bae492014-02-25 16:16:18 -08001236 metrics::CheckResult::kParsingError,
1237 metrics::CheckReaction::kUnset,
1238 metrics::DownloadErrorCode::kUnset,
Alex Vakulenko88b591f2014-08-28 16:48:57 -07001239 nullptr, // response
Darin Petkov0dc8e9a2010-07-14 14:51:57 -07001240 &post_data));
1241 // convert post_data to string
Alex Vakulenkof68bbbc2015-02-09 12:53:18 -08001242 string post_str(post_data.begin(), post_data.end());
Thieu Le116fda32011-04-19 11:01:54 -07001243 EXPECT_NE(post_str.find(
Jay Srinivasan23b92a52012-10-27 02:00:21 -07001244 " <ping active=\"1\" a=\"-1\" r=\"-1\"></ping>\n"
Jay Srinivasanae4697c2013-03-18 17:08:08 -07001245 " <updatecheck targetversionprefix=\"\"></updatecheck>\n"),
Jay Srinivasan0a708742012-03-20 11:26:12 -07001246 string::npos);
Darin Petkovfbb40092010-07-29 17:05:50 -07001247 EXPECT_NE(post_str.find("hardware_class=\"OEM MODEL 09235 7471\""),
1248 string::npos);
Chris Sosac1972482013-04-30 22:31:10 -07001249 EXPECT_NE(post_str.find("fw_version=\"ChromeOSFirmware.1.0\""),
1250 string::npos);
1251 EXPECT_NE(post_str.find("ec_version=\"0X0A1\""),
1252 string::npos);
Alex Deymoefb9d832015-11-02 18:39:02 -08001253 // No <event> tag should be sent if we didn't reboot to an update.
1254 EXPECT_EQ(post_str.find("<event"), string::npos);
Darin Petkov0dc8e9a2010-07-14 14:51:57 -07001255}
1256
Jay Srinivasan0a708742012-03-20 11:26:12 -07001257
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001258TEST_F(OmahaRequestActionTest, FormatSuccessEventOutputTest) {
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -07001259 brillo::Blob post_data;
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001260 TestEvent(request_params_,
Darin Petkove17f86b2010-07-20 09:12:01 -07001261 new OmahaEvent(OmahaEvent::kTypeUpdateDownloadStarted),
1262 "invalid xml>",
1263 &post_data);
1264 // convert post_data to string
Alex Vakulenkof68bbbc2015-02-09 12:53:18 -08001265 string post_str(post_data.begin(), post_data.end());
Alex Vakulenko75039d72014-03-25 12:36:28 -07001266 string expected_event = base::StringPrintf(
Jay Srinivasan23b92a52012-10-27 02:00:21 -07001267 " <event eventtype=\"%d\" eventresult=\"%d\"></event>\n",
Darin Petkove17f86b2010-07-20 09:12:01 -07001268 OmahaEvent::kTypeUpdateDownloadStarted,
1269 OmahaEvent::kResultSuccess);
1270 EXPECT_NE(post_str.find(expected_event), string::npos);
Jay Srinivasan23b92a52012-10-27 02:00:21 -07001271 EXPECT_EQ(post_str.find("ping"), string::npos);
1272 EXPECT_EQ(post_str.find("updatecheck"), string::npos);
Darin Petkove17f86b2010-07-20 09:12:01 -07001273}
1274
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001275TEST_F(OmahaRequestActionTest, FormatErrorEventOutputTest) {
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -07001276 brillo::Blob post_data;
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001277 TestEvent(request_params_,
Darin Petkove17f86b2010-07-20 09:12:01 -07001278 new OmahaEvent(OmahaEvent::kTypeDownloadComplete,
1279 OmahaEvent::kResultError,
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001280 ErrorCode::kError),
Darin Petkove17f86b2010-07-20 09:12:01 -07001281 "invalid xml>",
1282 &post_data);
1283 // convert post_data to string
Alex Vakulenkof68bbbc2015-02-09 12:53:18 -08001284 string post_str(post_data.begin(), post_data.end());
Alex Vakulenko75039d72014-03-25 12:36:28 -07001285 string expected_event = base::StringPrintf(
Jay Srinivasan23b92a52012-10-27 02:00:21 -07001286 " <event eventtype=\"%d\" eventresult=\"%d\" "
1287 "errorcode=\"%d\"></event>\n",
Darin Petkove17f86b2010-07-20 09:12:01 -07001288 OmahaEvent::kTypeDownloadComplete,
1289 OmahaEvent::kResultError,
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001290 static_cast<int>(ErrorCode::kError));
Darin Petkov0dc8e9a2010-07-14 14:51:57 -07001291 EXPECT_NE(post_str.find(expected_event), string::npos);
Jay Srinivasan23b92a52012-10-27 02:00:21 -07001292 EXPECT_EQ(post_str.find("updatecheck"), string::npos);
Darin Petkov0dc8e9a2010-07-14 14:51:57 -07001293}
1294
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001295TEST_F(OmahaRequestActionTest, IsEventTest) {
Darin Petkov0dc8e9a2010-07-14 14:51:57 -07001296 string http_response("doesn't matter");
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001297 // Create a copy of the OmahaRequestParams to reuse it later.
1298 OmahaRequestParams params = request_params_;
1299 fake_system_state_.set_request_params(&params);
Darin Petkov0dc8e9a2010-07-14 14:51:57 -07001300 OmahaRequestAction update_check_action(
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001301 &fake_system_state_,
Alex Vakulenko88b591f2014-08-28 16:48:57 -07001302 nullptr,
Alex Deymoc1c17b42015-11-23 03:53:15 -03001303 brillo::make_unique_ptr(
1304 new MockHttpFetcher(http_response.data(),
1305 http_response.size(),
1306 nullptr)),
Thieu Le116fda32011-04-19 11:01:54 -07001307 false);
Darin Petkov0dc8e9a2010-07-14 14:51:57 -07001308 EXPECT_FALSE(update_check_action.IsEvent());
1309
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001310 params = request_params_;
1311 fake_system_state_.set_request_params(&params);
Darin Petkov0dc8e9a2010-07-14 14:51:57 -07001312 OmahaRequestAction event_action(
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001313 &fake_system_state_,
Darin Petkove17f86b2010-07-20 09:12:01 -07001314 new OmahaEvent(OmahaEvent::kTypeUpdateComplete),
Alex Deymoc1c17b42015-11-23 03:53:15 -03001315 brillo::make_unique_ptr(
1316 new MockHttpFetcher(http_response.data(),
1317 http_response.size(),
1318 nullptr)),
Thieu Le116fda32011-04-19 11:01:54 -07001319 false);
Darin Petkov0dc8e9a2010-07-14 14:51:57 -07001320 EXPECT_TRUE(event_action.IsEvent());
1321}
1322
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001323TEST_F(OmahaRequestActionTest, FormatDeltaOkayOutputTest) {
Andrew de los Reyes3f0303a2010-07-15 22:35:35 -07001324 for (int i = 0; i < 2; i++) {
1325 bool delta_okay = i == 1;
1326 const char* delta_okay_str = delta_okay ? "true" : "false";
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -07001327 brillo::Blob post_data;
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001328 OmahaRequestParams params(&fake_system_state_,
Alex Deymoac41a822015-09-15 20:52:53 -07001329 constants::kOmahaPlatformName,
Andrew de los Reyes3f0303a2010-07-15 22:35:35 -07001330 OmahaRequestParams::kOsVersion,
1331 "service_pack",
1332 "x86-generic",
Alex Deymo85616652015-10-15 18:48:31 -07001333 kTestAppId,
Andrew de los Reyes3f0303a2010-07-15 22:35:35 -07001334 "0.1.0.0",
1335 "en-US",
1336 "unittest_track",
Darin Petkovfbb40092010-07-29 17:05:50 -07001337 "OEM MODEL REV 1234",
Chris Sosac1972482013-04-30 22:31:10 -07001338 "ChromeOSFirmware.1.0",
1339 "EC100",
Andrew de los Reyes3f0303a2010-07-15 22:35:35 -07001340 delta_okay,
Gilad Arnoldbbdd4902013-01-10 16:06:30 -08001341 false, // interactive
Jay Srinivasan0a708742012-03-20 11:26:12 -07001342 "http://url",
Gilad Arnold74b5f552014-10-07 08:17:16 -07001343 ""); // target_version_prefix
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001344 ASSERT_FALSE(TestUpdateCheck(&params,
Andrew de los Reyes3f0303a2010-07-15 22:35:35 -07001345 "invalid xml>",
Darin Petkovedc522e2010-11-05 09:35:17 -07001346 -1,
Darin Petkov265f2902011-05-09 15:17:40 -07001347 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001348 ErrorCode::kOmahaRequestXMLParseError,
David Zeuthen33bae492014-02-25 16:16:18 -08001349 metrics::CheckResult::kParsingError,
1350 metrics::CheckReaction::kUnset,
1351 metrics::DownloadErrorCode::kUnset,
Alex Vakulenko88b591f2014-08-28 16:48:57 -07001352 nullptr,
Andrew de los Reyes3f0303a2010-07-15 22:35:35 -07001353 &post_data));
1354 // convert post_data to string
Alex Vakulenkof68bbbc2015-02-09 12:53:18 -08001355 string post_str(post_data.begin(), post_data.end());
Alex Vakulenko75039d72014-03-25 12:36:28 -07001356 EXPECT_NE(post_str.find(base::StringPrintf(" delta_okay=\"%s\"",
1357 delta_okay_str)),
Andrew de los Reyes3f0303a2010-07-15 22:35:35 -07001358 string::npos)
1359 << "i = " << i;
1360 }
1361}
1362
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001363TEST_F(OmahaRequestActionTest, FormatInteractiveOutputTest) {
Gilad Arnoldbbdd4902013-01-10 16:06:30 -08001364 for (int i = 0; i < 2; i++) {
1365 bool interactive = i == 1;
Gilad Arnold8a659d82013-01-24 11:26:00 -08001366 const char* interactive_str = interactive ? "ondemandupdate" : "scheduler";
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -07001367 brillo::Blob post_data;
Gilad Arnold5bb4c902014-04-10 12:32:13 -07001368 FakeSystemState fake_system_state;
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001369 OmahaRequestParams params(&fake_system_state_,
Alex Deymoac41a822015-09-15 20:52:53 -07001370 constants::kOmahaPlatformName,
Gilad Arnoldbbdd4902013-01-10 16:06:30 -08001371 OmahaRequestParams::kOsVersion,
1372 "service_pack",
1373 "x86-generic",
Alex Deymo85616652015-10-15 18:48:31 -07001374 kTestAppId,
Gilad Arnoldbbdd4902013-01-10 16:06:30 -08001375 "0.1.0.0",
1376 "en-US",
1377 "unittest_track",
1378 "OEM MODEL REV 1234",
Chris Sosac1972482013-04-30 22:31:10 -07001379 "ChromeOSFirmware.1.0",
1380 "EC100",
David Zeuthen8f191b22013-08-06 12:27:50 -07001381 true, // delta_okay
Gilad Arnoldbbdd4902013-01-10 16:06:30 -08001382 interactive,
1383 "http://url",
Gilad Arnold74b5f552014-10-07 08:17:16 -07001384 ""); // target_version_prefix
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001385 ASSERT_FALSE(TestUpdateCheck(&params,
Gilad Arnoldbbdd4902013-01-10 16:06:30 -08001386 "invalid xml>",
1387 -1,
1388 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001389 ErrorCode::kOmahaRequestXMLParseError,
David Zeuthen33bae492014-02-25 16:16:18 -08001390 metrics::CheckResult::kParsingError,
1391 metrics::CheckReaction::kUnset,
1392 metrics::DownloadErrorCode::kUnset,
Alex Vakulenko88b591f2014-08-28 16:48:57 -07001393 nullptr,
Gilad Arnoldbbdd4902013-01-10 16:06:30 -08001394 &post_data));
1395 // convert post_data to string
Alex Vakulenkof68bbbc2015-02-09 12:53:18 -08001396 string post_str(post_data.begin(), post_data.end());
Alex Vakulenko75039d72014-03-25 12:36:28 -07001397 EXPECT_NE(post_str.find(base::StringPrintf("installsource=\"%s\"",
1398 interactive_str)),
Gilad Arnoldbbdd4902013-01-10 16:06:30 -08001399 string::npos)
1400 << "i = " << i;
1401 }
1402}
1403
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001404TEST_F(OmahaRequestActionTest, OmahaEventTest) {
Darin Petkove17f86b2010-07-20 09:12:01 -07001405 OmahaEvent default_event;
1406 EXPECT_EQ(OmahaEvent::kTypeUnknown, default_event.type);
1407 EXPECT_EQ(OmahaEvent::kResultError, default_event.result);
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001408 EXPECT_EQ(ErrorCode::kError, default_event.error_code);
Darin Petkove17f86b2010-07-20 09:12:01 -07001409
1410 OmahaEvent success_event(OmahaEvent::kTypeUpdateDownloadStarted);
1411 EXPECT_EQ(OmahaEvent::kTypeUpdateDownloadStarted, success_event.type);
1412 EXPECT_EQ(OmahaEvent::kResultSuccess, success_event.result);
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001413 EXPECT_EQ(ErrorCode::kSuccess, success_event.error_code);
Darin Petkove17f86b2010-07-20 09:12:01 -07001414
1415 OmahaEvent error_event(OmahaEvent::kTypeUpdateDownloadFinished,
1416 OmahaEvent::kResultError,
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001417 ErrorCode::kError);
Darin Petkove17f86b2010-07-20 09:12:01 -07001418 EXPECT_EQ(OmahaEvent::kTypeUpdateDownloadFinished, error_event.type);
1419 EXPECT_EQ(OmahaEvent::kResultError, error_event.result);
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001420 EXPECT_EQ(ErrorCode::kError, error_event.error_code);
Darin Petkove17f86b2010-07-20 09:12:01 -07001421}
1422
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001423void OmahaRequestActionTest::PingTest(bool ping_only) {
Alex Deymo8427b4a2014-11-05 14:00:32 -08001424 NiceMock<MockPrefs> prefs;
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001425 fake_system_state_.set_prefs(&prefs);
1426 EXPECT_CALL(prefs, GetInt64(kPrefsMetricsCheckLastReportingTime, _))
1427 .Times(AnyNumber());
1428 EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber());
1429 // Add a few hours to the day difference to test no rounding, etc.
1430 int64_t five_days_ago =
1431 (Time::Now() - TimeDelta::FromHours(5 * 24 + 13)).ToInternalValue();
1432 int64_t six_days_ago =
1433 (Time::Now() - TimeDelta::FromHours(6 * 24 + 11)).ToInternalValue();
1434 EXPECT_CALL(prefs, GetInt64(kPrefsInstallDateDays, _))
1435 .WillOnce(DoAll(SetArgumentPointee<1>(0), Return(true)));
1436 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _))
1437 .WillOnce(DoAll(SetArgumentPointee<1>(six_days_ago), Return(true)));
1438 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _))
1439 .WillOnce(DoAll(SetArgumentPointee<1>(five_days_ago), Return(true)));
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -07001440 brillo::Blob post_data;
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001441 ASSERT_TRUE(
1442 TestUpdateCheck(nullptr, // request_params
Alex Deymo8e18f932015-03-27 16:16:59 -07001443 fake_update_response_.GetNoUpdateResponse(),
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001444 -1,
1445 ping_only,
1446 ErrorCode::kSuccess,
1447 metrics::CheckResult::kUnset,
1448 metrics::CheckReaction::kUnset,
1449 metrics::DownloadErrorCode::kUnset,
1450 nullptr,
1451 &post_data));
Alex Vakulenkof68bbbc2015-02-09 12:53:18 -08001452 string post_str(post_data.begin(), post_data.end());
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001453 EXPECT_NE(post_str.find("<ping active=\"1\" a=\"6\" r=\"5\"></ping>"),
1454 string::npos);
1455 if (ping_only) {
1456 EXPECT_EQ(post_str.find("updatecheck"), string::npos);
1457 EXPECT_EQ(post_str.find("previousversion"), string::npos);
1458 } else {
1459 EXPECT_NE(post_str.find("updatecheck"), string::npos);
1460 EXPECT_NE(post_str.find("previousversion"), string::npos);
Darin Petkov265f2902011-05-09 15:17:40 -07001461 }
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001462}
1463
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001464TEST_F(OmahaRequestActionTest, PingTestSendOnlyAPing) {
1465 PingTest(true /* ping_only */);
1466}
1467
1468TEST_F(OmahaRequestActionTest, PingTestSendAlsoAnUpdateCheck) {
1469 PingTest(false /* ping_only */);
1470}
1471
1472TEST_F(OmahaRequestActionTest, ActivePingTest) {
Alex Deymo8427b4a2014-11-05 14:00:32 -08001473 NiceMock<MockPrefs> prefs;
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001474 fake_system_state_.set_prefs(&prefs);
David Zeuthen33bae492014-02-25 16:16:18 -08001475 EXPECT_CALL(prefs, GetInt64(kPrefsMetricsCheckLastReportingTime, _))
1476 .Times(AnyNumber());
1477 EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber());
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001478 int64_t three_days_ago =
1479 (Time::Now() - TimeDelta::FromHours(3 * 24 + 12)).ToInternalValue();
1480 int64_t now = Time::Now().ToInternalValue();
David Zeuthen639aa362014-02-03 16:23:44 -08001481 EXPECT_CALL(prefs, GetInt64(kPrefsInstallDateDays, _))
1482 .WillOnce(DoAll(SetArgumentPointee<1>(0), Return(true)));
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001483 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _))
1484 .WillOnce(DoAll(SetArgumentPointee<1>(three_days_ago), Return(true)));
1485 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _))
1486 .WillOnce(DoAll(SetArgumentPointee<1>(now), Return(true)));
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -07001487 brillo::Blob post_data;
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001488 ASSERT_TRUE(
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001489 TestUpdateCheck(nullptr, // request_params
Alex Deymo8e18f932015-03-27 16:16:59 -07001490 fake_update_response_.GetNoUpdateResponse(),
Darin Petkovedc522e2010-11-05 09:35:17 -07001491 -1,
Darin Petkov265f2902011-05-09 15:17:40 -07001492 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001493 ErrorCode::kSuccess,
David Zeuthen33bae492014-02-25 16:16:18 -08001494 metrics::CheckResult::kNoUpdateAvailable,
1495 metrics::CheckReaction::kUnset,
1496 metrics::DownloadErrorCode::kUnset,
Alex Vakulenko88b591f2014-08-28 16:48:57 -07001497 nullptr,
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001498 &post_data));
Alex Vakulenkof68bbbc2015-02-09 12:53:18 -08001499 string post_str(post_data.begin(), post_data.end());
Jay Srinivasan23b92a52012-10-27 02:00:21 -07001500 EXPECT_NE(post_str.find("<ping active=\"1\" a=\"3\"></ping>"),
Thieu Le116fda32011-04-19 11:01:54 -07001501 string::npos);
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001502}
1503
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001504TEST_F(OmahaRequestActionTest, RollCallPingTest) {
Alex Deymo8427b4a2014-11-05 14:00:32 -08001505 NiceMock<MockPrefs> prefs;
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001506 fake_system_state_.set_prefs(&prefs);
David Zeuthen33bae492014-02-25 16:16:18 -08001507 EXPECT_CALL(prefs, GetInt64(kPrefsMetricsCheckLastReportingTime, _))
1508 .Times(AnyNumber());
1509 EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber());
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001510 int64_t four_days_ago =
1511 (Time::Now() - TimeDelta::FromHours(4 * 24)).ToInternalValue();
1512 int64_t now = Time::Now().ToInternalValue();
David Zeuthen639aa362014-02-03 16:23:44 -08001513 EXPECT_CALL(prefs, GetInt64(kPrefsInstallDateDays, _))
1514 .WillOnce(DoAll(SetArgumentPointee<1>(0), Return(true)));
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001515 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _))
1516 .WillOnce(DoAll(SetArgumentPointee<1>(now), Return(true)));
1517 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _))
1518 .WillOnce(DoAll(SetArgumentPointee<1>(four_days_ago), Return(true)));
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -07001519 brillo::Blob post_data;
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001520 ASSERT_TRUE(
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001521 TestUpdateCheck(nullptr, // request_params
Alex Deymo8e18f932015-03-27 16:16:59 -07001522 fake_update_response_.GetNoUpdateResponse(),
Darin Petkovedc522e2010-11-05 09:35:17 -07001523 -1,
Darin Petkov265f2902011-05-09 15:17:40 -07001524 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001525 ErrorCode::kSuccess,
David Zeuthen33bae492014-02-25 16:16:18 -08001526 metrics::CheckResult::kNoUpdateAvailable,
1527 metrics::CheckReaction::kUnset,
1528 metrics::DownloadErrorCode::kUnset,
Alex Vakulenko88b591f2014-08-28 16:48:57 -07001529 nullptr,
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001530 &post_data));
Alex Vakulenkof68bbbc2015-02-09 12:53:18 -08001531 string post_str(post_data.begin(), post_data.end());
Jay Srinivasan23b92a52012-10-27 02:00:21 -07001532 EXPECT_NE(post_str.find("<ping active=\"1\" r=\"4\"></ping>\n"),
Thieu Le116fda32011-04-19 11:01:54 -07001533 string::npos);
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001534}
1535
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001536TEST_F(OmahaRequestActionTest, NoPingTest) {
Alex Deymo8427b4a2014-11-05 14:00:32 -08001537 NiceMock<MockPrefs> prefs;
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001538 fake_system_state_.set_prefs(&prefs);
David Zeuthen33bae492014-02-25 16:16:18 -08001539 EXPECT_CALL(prefs, GetInt64(kPrefsMetricsCheckLastReportingTime, _))
1540 .Times(AnyNumber());
1541 EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber());
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001542 int64_t one_hour_ago =
1543 (Time::Now() - TimeDelta::FromHours(1)).ToInternalValue();
David Zeuthen639aa362014-02-03 16:23:44 -08001544 EXPECT_CALL(prefs, GetInt64(kPrefsInstallDateDays, _))
1545 .WillOnce(DoAll(SetArgumentPointee<1>(0), Return(true)));
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001546 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _))
1547 .WillOnce(DoAll(SetArgumentPointee<1>(one_hour_ago), Return(true)));
1548 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _))
1549 .WillOnce(DoAll(SetArgumentPointee<1>(one_hour_ago), Return(true)));
Alex Deymoebbe7ef2014-10-30 13:02:49 -07001550 // LastActivePingDay and PrefsLastRollCallPingDay are set even if we didn't
1551 // send a ping.
1552 EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _))
1553 .WillOnce(Return(true));
1554 EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _))
1555 .WillOnce(Return(true));
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -07001556 brillo::Blob post_data;
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001557 ASSERT_TRUE(
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001558 TestUpdateCheck(nullptr, // request_params
Alex Deymo8e18f932015-03-27 16:16:59 -07001559 fake_update_response_.GetNoUpdateResponse(),
Darin Petkovedc522e2010-11-05 09:35:17 -07001560 -1,
Darin Petkov265f2902011-05-09 15:17:40 -07001561 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001562 ErrorCode::kSuccess,
David Zeuthen33bae492014-02-25 16:16:18 -08001563 metrics::CheckResult::kNoUpdateAvailable,
1564 metrics::CheckReaction::kUnset,
1565 metrics::DownloadErrorCode::kUnset,
Alex Vakulenko88b591f2014-08-28 16:48:57 -07001566 nullptr,
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001567 &post_data));
Alex Vakulenkof68bbbc2015-02-09 12:53:18 -08001568 string post_str(post_data.begin(), post_data.end());
Jay Srinivasan23b92a52012-10-27 02:00:21 -07001569 EXPECT_EQ(post_str.find("ping"), string::npos);
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001570}
1571
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001572TEST_F(OmahaRequestActionTest, IgnoreEmptyPingTest) {
Thieu Leb44e9e82011-06-06 14:34:04 -07001573 // This test ensures that we ignore empty ping only requests.
Alex Deymo8427b4a2014-11-05 14:00:32 -08001574 NiceMock<MockPrefs> prefs;
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001575 fake_system_state_.set_prefs(&prefs);
Thieu Leb44e9e82011-06-06 14:34:04 -07001576 int64_t now = Time::Now().ToInternalValue();
1577 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _))
1578 .WillOnce(DoAll(SetArgumentPointee<1>(now), Return(true)));
1579 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _))
1580 .WillOnce(DoAll(SetArgumentPointee<1>(now), Return(true)));
1581 EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)).Times(0);
1582 EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)).Times(0);
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -07001583 brillo::Blob post_data;
Thieu Leb44e9e82011-06-06 14:34:04 -07001584 EXPECT_TRUE(
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001585 TestUpdateCheck(nullptr, // request_params
Alex Deymo8e18f932015-03-27 16:16:59 -07001586 fake_update_response_.GetNoUpdateResponse(),
Thieu Leb44e9e82011-06-06 14:34:04 -07001587 -1,
1588 true, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001589 ErrorCode::kSuccess,
David Zeuthen33bae492014-02-25 16:16:18 -08001590 metrics::CheckResult::kUnset,
1591 metrics::CheckReaction::kUnset,
1592 metrics::DownloadErrorCode::kUnset,
Alex Vakulenko88b591f2014-08-28 16:48:57 -07001593 nullptr,
Thieu Leb44e9e82011-06-06 14:34:04 -07001594 &post_data));
Alex Deymo80f70ff2016-02-10 16:08:11 -08001595 EXPECT_EQ(0U, post_data.size());
Thieu Leb44e9e82011-06-06 14:34:04 -07001596}
1597
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001598TEST_F(OmahaRequestActionTest, BackInTimePingTest) {
Alex Deymo8427b4a2014-11-05 14:00:32 -08001599 NiceMock<MockPrefs> prefs;
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001600 fake_system_state_.set_prefs(&prefs);
David Zeuthen33bae492014-02-25 16:16:18 -08001601 EXPECT_CALL(prefs, GetInt64(kPrefsMetricsCheckLastReportingTime, _))
1602 .Times(AnyNumber());
1603 EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber());
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001604 int64_t future =
1605 (Time::Now() + TimeDelta::FromHours(3 * 24 + 4)).ToInternalValue();
David Zeuthen639aa362014-02-03 16:23:44 -08001606 EXPECT_CALL(prefs, GetInt64(kPrefsInstallDateDays, _))
1607 .WillOnce(DoAll(SetArgumentPointee<1>(0), Return(true)));
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001608 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _))
1609 .WillOnce(DoAll(SetArgumentPointee<1>(future), Return(true)));
1610 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _))
1611 .WillOnce(DoAll(SetArgumentPointee<1>(future), Return(true)));
1612 EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _))
1613 .WillOnce(Return(true));
1614 EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _))
1615 .WillOnce(Return(true));
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -07001616 brillo::Blob post_data;
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001617 ASSERT_TRUE(
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001618 TestUpdateCheck(nullptr, // request_params
Jay Srinivasan23b92a52012-10-27 02:00:21 -07001619 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response "
1620 "protocol=\"3.0\"><daystart elapsed_seconds=\"100\"/>"
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001621 "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>"
Jay Srinivasan23b92a52012-10-27 02:00:21 -07001622 "<updatecheck status=\"noupdate\"/></app></response>",
Darin Petkovedc522e2010-11-05 09:35:17 -07001623 -1,
Darin Petkov265f2902011-05-09 15:17:40 -07001624 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001625 ErrorCode::kSuccess,
David Zeuthen33bae492014-02-25 16:16:18 -08001626 metrics::CheckResult::kNoUpdateAvailable,
1627 metrics::CheckReaction::kUnset,
1628 metrics::DownloadErrorCode::kUnset,
Alex Vakulenko88b591f2014-08-28 16:48:57 -07001629 nullptr,
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001630 &post_data));
Alex Vakulenkof68bbbc2015-02-09 12:53:18 -08001631 string post_str(post_data.begin(), post_data.end());
Jay Srinivasan23b92a52012-10-27 02:00:21 -07001632 EXPECT_EQ(post_str.find("ping"), string::npos);
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001633}
1634
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001635TEST_F(OmahaRequestActionTest, LastPingDayUpdateTest) {
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001636 // This test checks that the action updates the last ping day to now
Darin Petkov84c763c2010-07-29 16:27:58 -07001637 // minus 200 seconds with a slack of 5 seconds. Therefore, the test
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001638 // may fail if it runs for longer than 5 seconds. It shouldn't run
1639 // that long though.
1640 int64_t midnight =
1641 (Time::Now() - TimeDelta::FromSeconds(200)).ToInternalValue();
1642 int64_t midnight_slack =
1643 (Time::Now() - TimeDelta::FromSeconds(195)).ToInternalValue();
Alex Deymo8427b4a2014-11-05 14:00:32 -08001644 NiceMock<MockPrefs> prefs;
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001645 fake_system_state_.set_prefs(&prefs);
David Zeuthen33bae492014-02-25 16:16:18 -08001646 EXPECT_CALL(prefs, GetInt64(_, _)).Times(AnyNumber());
1647 EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber());
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001648 EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay,
1649 AllOf(Ge(midnight), Le(midnight_slack))))
1650 .WillOnce(Return(true));
1651 EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay,
1652 AllOf(Ge(midnight), Le(midnight_slack))))
1653 .WillOnce(Return(true));
1654 ASSERT_TRUE(
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001655 TestUpdateCheck(nullptr, // request_params
Jay Srinivasan23b92a52012-10-27 02:00:21 -07001656 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response "
1657 "protocol=\"3.0\"><daystart elapsed_seconds=\"200\"/>"
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001658 "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>"
Jay Srinivasan23b92a52012-10-27 02:00:21 -07001659 "<updatecheck status=\"noupdate\"/></app></response>",
Darin Petkovedc522e2010-11-05 09:35:17 -07001660 -1,
Darin Petkov265f2902011-05-09 15:17:40 -07001661 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001662 ErrorCode::kSuccess,
David Zeuthen33bae492014-02-25 16:16:18 -08001663 metrics::CheckResult::kNoUpdateAvailable,
1664 metrics::CheckReaction::kUnset,
1665 metrics::DownloadErrorCode::kUnset,
Alex Vakulenko88b591f2014-08-28 16:48:57 -07001666 nullptr,
1667 nullptr));
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001668}
1669
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001670TEST_F(OmahaRequestActionTest, NoElapsedSecondsTest) {
Alex Deymo8427b4a2014-11-05 14:00:32 -08001671 NiceMock<MockPrefs> prefs;
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001672 fake_system_state_.set_prefs(&prefs);
David Zeuthen33bae492014-02-25 16:16:18 -08001673 EXPECT_CALL(prefs, GetInt64(_, _)).Times(AnyNumber());
1674 EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber());
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001675 EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)).Times(0);
1676 EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)).Times(0);
1677 ASSERT_TRUE(
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001678 TestUpdateCheck(nullptr, // request_params
Jay Srinivasan23b92a52012-10-27 02:00:21 -07001679 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response "
1680 "protocol=\"3.0\"><daystart blah=\"200\"/>"
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001681 "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>"
Jay Srinivasan23b92a52012-10-27 02:00:21 -07001682 "<updatecheck status=\"noupdate\"/></app></response>",
Darin Petkovedc522e2010-11-05 09:35:17 -07001683 -1,
Darin Petkov265f2902011-05-09 15:17:40 -07001684 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001685 ErrorCode::kSuccess,
David Zeuthen33bae492014-02-25 16:16:18 -08001686 metrics::CheckResult::kNoUpdateAvailable,
1687 metrics::CheckReaction::kUnset,
1688 metrics::DownloadErrorCode::kUnset,
Alex Vakulenko88b591f2014-08-28 16:48:57 -07001689 nullptr,
1690 nullptr));
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001691}
1692
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001693TEST_F(OmahaRequestActionTest, BadElapsedSecondsTest) {
Alex Deymo8427b4a2014-11-05 14:00:32 -08001694 NiceMock<MockPrefs> prefs;
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001695 fake_system_state_.set_prefs(&prefs);
David Zeuthen33bae492014-02-25 16:16:18 -08001696 EXPECT_CALL(prefs, GetInt64(_, _)).Times(AnyNumber());
1697 EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber());
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001698 EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)).Times(0);
1699 EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)).Times(0);
1700 ASSERT_TRUE(
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001701 TestUpdateCheck(nullptr, // request_params
Jay Srinivasan23b92a52012-10-27 02:00:21 -07001702 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response "
1703 "protocol=\"3.0\"><daystart elapsed_seconds=\"x\"/>"
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001704 "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>"
Jay Srinivasan23b92a52012-10-27 02:00:21 -07001705 "<updatecheck status=\"noupdate\"/></app></response>",
Darin Petkovedc522e2010-11-05 09:35:17 -07001706 -1,
Darin Petkov265f2902011-05-09 15:17:40 -07001707 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001708 ErrorCode::kSuccess,
David Zeuthen33bae492014-02-25 16:16:18 -08001709 metrics::CheckResult::kNoUpdateAvailable,
1710 metrics::CheckReaction::kUnset,
1711 metrics::DownloadErrorCode::kUnset,
Alex Vakulenko88b591f2014-08-28 16:48:57 -07001712 nullptr,
1713 nullptr));
Darin Petkov1cbd78f2010-07-29 12:38:34 -07001714}
1715
Alex Deymob3fa53b2016-04-18 19:57:58 -07001716TEST_F(OmahaRequestActionTest, ParseUpdateCheckAttributesTest) {
1717 // Test that the "eol" flags is only parsed from the "_eol" attribute and not
1718 // the "eol" attribute.
1719 ASSERT_TRUE(
1720 TestUpdateCheck(nullptr, // request_params
1721 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><response "
1722 "protocol=\"3.0\"><app appid=\"foo\" status=\"ok\">"
1723 "<ping status=\"ok\"/><updatecheck status=\"noupdate\" "
1724 "_eol=\"security-only\" eol=\"eol\" _foo=\"bar\"/>"
1725 "</app></response>",
1726 -1,
1727 false, // ping_only
1728 ErrorCode::kSuccess,
1729 metrics::CheckResult::kNoUpdateAvailable,
1730 metrics::CheckReaction::kUnset,
1731 metrics::DownloadErrorCode::kUnset,
1732 nullptr,
1733 nullptr));
1734 string eol_pref;
1735 EXPECT_TRUE(
1736 fake_system_state_.prefs()->GetString(kPrefsOmahaEolStatus, &eol_pref));
1737 // Note that the eol="eol" attribute should be ignored and the _eol should be
1738 // used instead.
1739 EXPECT_EQ("security-only", eol_pref);
1740}
1741
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001742TEST_F(OmahaRequestActionTest, NoUniqueIDTest) {
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -07001743 brillo::Blob post_data;
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001744 ASSERT_FALSE(TestUpdateCheck(nullptr, // request_params
Darin Petkov84c763c2010-07-29 16:27:58 -07001745 "invalid xml>",
Darin Petkovedc522e2010-11-05 09:35:17 -07001746 -1,
Darin Petkov265f2902011-05-09 15:17:40 -07001747 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001748 ErrorCode::kOmahaRequestXMLParseError,
David Zeuthen33bae492014-02-25 16:16:18 -08001749 metrics::CheckResult::kParsingError,
1750 metrics::CheckReaction::kUnset,
1751 metrics::DownloadErrorCode::kUnset,
Alex Vakulenko88b591f2014-08-28 16:48:57 -07001752 nullptr, // response
Darin Petkov84c763c2010-07-29 16:27:58 -07001753 &post_data));
1754 // convert post_data to string
Alex Vakulenkof68bbbc2015-02-09 12:53:18 -08001755 string post_str(post_data.begin(), post_data.end());
Darin Petkov84c763c2010-07-29 16:27:58 -07001756 EXPECT_EQ(post_str.find("machineid="), string::npos);
1757 EXPECT_EQ(post_str.find("userid="), string::npos);
1758}
1759
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001760TEST_F(OmahaRequestActionTest, NetworkFailureTest) {
Darin Petkovedc522e2010-11-05 09:35:17 -07001761 OmahaResponse response;
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001762 const int http_error_code =
1763 static_cast<int>(ErrorCode::kOmahaRequestHTTPResponseBase) + 501;
Darin Petkovedc522e2010-11-05 09:35:17 -07001764 ASSERT_FALSE(
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001765 TestUpdateCheck(nullptr, // request_params
Darin Petkovedc522e2010-11-05 09:35:17 -07001766 "",
1767 501,
Darin Petkov265f2902011-05-09 15:17:40 -07001768 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001769 static_cast<ErrorCode>(http_error_code),
David Zeuthen33bae492014-02-25 16:16:18 -08001770 metrics::CheckResult::kDownloadError,
1771 metrics::CheckReaction::kUnset,
1772 static_cast<metrics::DownloadErrorCode>(501),
Darin Petkovedc522e2010-11-05 09:35:17 -07001773 &response,
Alex Vakulenko88b591f2014-08-28 16:48:57 -07001774 nullptr));
Darin Petkovedc522e2010-11-05 09:35:17 -07001775 EXPECT_FALSE(response.update_exists);
1776}
1777
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001778TEST_F(OmahaRequestActionTest, NetworkFailureBadHTTPCodeTest) {
Darin Petkovedc522e2010-11-05 09:35:17 -07001779 OmahaResponse response;
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001780 const int http_error_code =
1781 static_cast<int>(ErrorCode::kOmahaRequestHTTPResponseBase) + 999;
Darin Petkovedc522e2010-11-05 09:35:17 -07001782 ASSERT_FALSE(
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001783 TestUpdateCheck(nullptr, // request_params
Darin Petkovedc522e2010-11-05 09:35:17 -07001784 "",
1785 1500,
Darin Petkov265f2902011-05-09 15:17:40 -07001786 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001787 static_cast<ErrorCode>(http_error_code),
David Zeuthen33bae492014-02-25 16:16:18 -08001788 metrics::CheckResult::kDownloadError,
1789 metrics::CheckReaction::kUnset,
1790 metrics::DownloadErrorCode::kHttpStatusOther,
Darin Petkovedc522e2010-11-05 09:35:17 -07001791 &response,
Alex Vakulenko88b591f2014-08-28 16:48:57 -07001792 nullptr));
Darin Petkovedc522e2010-11-05 09:35:17 -07001793 EXPECT_FALSE(response.update_exists);
1794}
1795
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001796TEST_F(OmahaRequestActionTest, TestUpdateFirstSeenAtGetsPersistedFirstTime) {
Jay Srinivasan34b5d862012-07-23 11:43:22 -07001797 OmahaResponse response;
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001798 OmahaRequestParams params = request_params_;
Jay Srinivasanae4697c2013-03-18 17:08:08 -07001799 params.set_wall_clock_based_wait_enabled(true);
1800 params.set_waiting_period(TimeDelta().FromDays(1));
1801 params.set_update_check_count_wait_enabled(false);
Jay Srinivasan34b5d862012-07-23 11:43:22 -07001802
Jay Srinivasan34b5d862012-07-23 11:43:22 -07001803 ASSERT_FALSE(TestUpdateCheck(
Alex Vakulenkod2779df2014-06-16 13:19:00 -07001804 &params,
Alex Deymo8e18f932015-03-27 16:16:59 -07001805 fake_update_response_.GetUpdateResponse(),
Jay Srinivasan34b5d862012-07-23 11:43:22 -07001806 -1,
1807 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001808 ErrorCode::kOmahaUpdateDeferredPerPolicy,
David Zeuthen33bae492014-02-25 16:16:18 -08001809 metrics::CheckResult::kUpdateAvailable,
1810 metrics::CheckReaction::kDeferring,
1811 metrics::DownloadErrorCode::kUnset,
Jay Srinivasan34b5d862012-07-23 11:43:22 -07001812 &response,
Alex Vakulenko88b591f2014-08-28 16:48:57 -07001813 nullptr));
Jay Srinivasan34b5d862012-07-23 11:43:22 -07001814
Ben Chan9abb7632014-08-07 00:10:53 -07001815 int64_t timestamp = 0;
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001816 ASSERT_TRUE(fake_prefs_.GetInt64(kPrefsUpdateFirstSeenAt, &timestamp));
Alex Vakulenkod2779df2014-06-16 13:19:00 -07001817 ASSERT_GT(timestamp, 0);
Jay Srinivasan34b5d862012-07-23 11:43:22 -07001818 EXPECT_FALSE(response.update_exists);
Chris Sosa968d0572013-08-23 14:46:02 -07001819
1820 // Verify if we are interactive check we don't defer.
1821 params.set_interactive(true);
1822 ASSERT_TRUE(
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001823 TestUpdateCheck(&params,
Alex Deymo8e18f932015-03-27 16:16:59 -07001824 fake_update_response_.GetUpdateResponse(),
Chris Sosa968d0572013-08-23 14:46:02 -07001825 -1,
1826 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001827 ErrorCode::kSuccess,
David Zeuthen33bae492014-02-25 16:16:18 -08001828 metrics::CheckResult::kUpdateAvailable,
1829 metrics::CheckReaction::kUpdating,
1830 metrics::DownloadErrorCode::kUnset,
Chris Sosa968d0572013-08-23 14:46:02 -07001831 &response,
Alex Vakulenko88b591f2014-08-28 16:48:57 -07001832 nullptr));
Chris Sosa968d0572013-08-23 14:46:02 -07001833 EXPECT_TRUE(response.update_exists);
Jay Srinivasan34b5d862012-07-23 11:43:22 -07001834}
1835
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001836TEST_F(OmahaRequestActionTest, TestUpdateFirstSeenAtGetsUsedIfAlreadyPresent) {
Jay Srinivasan34b5d862012-07-23 11:43:22 -07001837 OmahaResponse response;
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001838 OmahaRequestParams params = request_params_;
Jay Srinivasanae4697c2013-03-18 17:08:08 -07001839 params.set_wall_clock_based_wait_enabled(true);
1840 params.set_waiting_period(TimeDelta().FromDays(1));
1841 params.set_update_check_count_wait_enabled(false);
Jay Srinivasan34b5d862012-07-23 11:43:22 -07001842
Jay Srinivasan34b5d862012-07-23 11:43:22 -07001843 // Set the timestamp to a very old value such that it exceeds the
1844 // waiting period set above.
1845 Time t1;
1846 Time::FromString("1/1/2012", &t1);
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001847 ASSERT_TRUE(fake_prefs_.SetInt64(
1848 kPrefsUpdateFirstSeenAt, t1.ToInternalValue()));
Jay Srinivasan34b5d862012-07-23 11:43:22 -07001849 ASSERT_TRUE(TestUpdateCheck(
Alex Vakulenkod2779df2014-06-16 13:19:00 -07001850 &params,
Alex Deymo8e18f932015-03-27 16:16:59 -07001851 fake_update_response_.GetUpdateResponse(),
Jay Srinivasan34b5d862012-07-23 11:43:22 -07001852 -1,
1853 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001854 ErrorCode::kSuccess,
David Zeuthen33bae492014-02-25 16:16:18 -08001855 metrics::CheckResult::kUpdateAvailable,
1856 metrics::CheckReaction::kUpdating,
1857 metrics::DownloadErrorCode::kUnset,
Jay Srinivasan34b5d862012-07-23 11:43:22 -07001858 &response,
Alex Vakulenko88b591f2014-08-28 16:48:57 -07001859 nullptr));
Jay Srinivasan34b5d862012-07-23 11:43:22 -07001860
1861 EXPECT_TRUE(response.update_exists);
1862
1863 // Make sure the timestamp t1 is unchanged showing that it was reused.
Ben Chan9abb7632014-08-07 00:10:53 -07001864 int64_t timestamp = 0;
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001865 ASSERT_TRUE(fake_prefs_.GetInt64(kPrefsUpdateFirstSeenAt, &timestamp));
Jay Srinivasan34b5d862012-07-23 11:43:22 -07001866 ASSERT_TRUE(timestamp == t1.ToInternalValue());
1867}
1868
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001869TEST_F(OmahaRequestActionTest, TestChangingToMoreStableChannel) {
Gilad Arnoldeff87cc2013-07-22 18:32:09 -07001870 // Create a uniquely named test directory.
Sen Jiang297e5832016-03-17 14:45:51 -07001871 base::ScopedTempDir tempdir;
1872 ASSERT_TRUE(tempdir.CreateUniqueTempDir());
Gilad Arnoldeff87cc2013-07-22 18:32:09 -07001873
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -07001874 brillo::Blob post_data;
Sen Jiang297e5832016-03-17 14:45:51 -07001875 OmahaRequestParams params(&fake_system_state_);
1876 params.set_root(tempdir.path().value());
1877 params.set_app_id("{22222222-2222-2222-2222-222222222222}");
1878 params.set_app_version("1.2.3.4");
1879 params.set_current_channel("canary-channel");
1880 EXPECT_TRUE(params.SetTargetChannel("stable-channel", true, nullptr));
1881 params.UpdateDownloadChannel();
Jay Srinivasanae4697c2013-03-18 17:08:08 -07001882 EXPECT_TRUE(params.to_more_stable_channel());
1883 EXPECT_TRUE(params.is_powerwash_allowed());
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001884 ASSERT_FALSE(TestUpdateCheck(&params,
Jay Srinivasanae4697c2013-03-18 17:08:08 -07001885 "invalid xml>",
1886 -1,
1887 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001888 ErrorCode::kOmahaRequestXMLParseError,
David Zeuthen33bae492014-02-25 16:16:18 -08001889 metrics::CheckResult::kParsingError,
1890 metrics::CheckReaction::kUnset,
1891 metrics::DownloadErrorCode::kUnset,
Alex Vakulenko88b591f2014-08-28 16:48:57 -07001892 nullptr, // response
Jay Srinivasanae4697c2013-03-18 17:08:08 -07001893 &post_data));
1894 // convert post_data to string
Alex Vakulenkof68bbbc2015-02-09 12:53:18 -08001895 string post_str(post_data.begin(), post_data.end());
Jay Srinivasanae4697c2013-03-18 17:08:08 -07001896 EXPECT_NE(string::npos, post_str.find(
1897 "appid=\"{22222222-2222-2222-2222-222222222222}\" "
1898 "version=\"0.0.0.0\" from_version=\"1.2.3.4\" "
1899 "track=\"stable-channel\" from_track=\"canary-channel\" "));
1900}
1901
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001902TEST_F(OmahaRequestActionTest, TestChangingToLessStableChannel) {
Gilad Arnoldeff87cc2013-07-22 18:32:09 -07001903 // Create a uniquely named test directory.
Sen Jiang297e5832016-03-17 14:45:51 -07001904 base::ScopedTempDir tempdir;
1905 ASSERT_TRUE(tempdir.CreateUniqueTempDir());
Gilad Arnoldeff87cc2013-07-22 18:32:09 -07001906
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -07001907 brillo::Blob post_data;
Sen Jiang297e5832016-03-17 14:45:51 -07001908 OmahaRequestParams params(&fake_system_state_);
1909 params.set_root(tempdir.path().value());
1910 params.set_app_id("{11111111-1111-1111-1111-111111111111}");
1911 params.set_app_version("5.6.7.8");
1912 params.set_current_channel("stable-channel");
1913 EXPECT_TRUE(params.SetTargetChannel("canary-channel", false, nullptr));
1914 params.UpdateDownloadChannel();
Jay Srinivasanae4697c2013-03-18 17:08:08 -07001915 EXPECT_FALSE(params.to_more_stable_channel());
1916 EXPECT_FALSE(params.is_powerwash_allowed());
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001917 ASSERT_FALSE(TestUpdateCheck(&params,
Jay Srinivasanae4697c2013-03-18 17:08:08 -07001918 "invalid xml>",
1919 -1,
1920 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07001921 ErrorCode::kOmahaRequestXMLParseError,
David Zeuthen33bae492014-02-25 16:16:18 -08001922 metrics::CheckResult::kParsingError,
1923 metrics::CheckReaction::kUnset,
1924 metrics::DownloadErrorCode::kUnset,
Alex Vakulenko88b591f2014-08-28 16:48:57 -07001925 nullptr, // response
Jay Srinivasanae4697c2013-03-18 17:08:08 -07001926 &post_data));
1927 // convert post_data to string
Alex Vakulenkof68bbbc2015-02-09 12:53:18 -08001928 string post_str(post_data.begin(), post_data.end());
Jay Srinivasanae4697c2013-03-18 17:08:08 -07001929 EXPECT_NE(string::npos, post_str.find(
1930 "appid=\"{11111111-1111-1111-1111-111111111111}\" "
1931 "version=\"5.6.7.8\" "
1932 "track=\"canary-channel\" from_track=\"stable-channel\""));
Alex Vakulenkod2779df2014-06-16 13:19:00 -07001933 EXPECT_EQ(string::npos, post_str.find("from_version"));
Jay Srinivasanae4697c2013-03-18 17:08:08 -07001934}
1935
Alex Deymoebbe7ef2014-10-30 13:02:49 -07001936// Checks that the initial ping with a=-1 r=-1 is not send when the device
1937// was powerwashed.
1938TEST_F(OmahaRequestActionTest, PingWhenPowerwashed) {
1939 fake_prefs_.SetString(kPrefsPreviousVersion, "");
1940
1941 // Flag that the device was powerwashed in the past.
1942 fake_system_state_.fake_hardware()->SetPowerwashCount(1);
1943
Alex Vakulenko3f39d5c2015-10-13 09:27:13 -07001944 brillo::Blob post_data;
Alex Deymoebbe7ef2014-10-30 13:02:49 -07001945 ASSERT_TRUE(
1946 TestUpdateCheck(nullptr, // request_params
Alex Deymo8e18f932015-03-27 16:16:59 -07001947 fake_update_response_.GetNoUpdateResponse(),
Alex Deymoebbe7ef2014-10-30 13:02:49 -07001948 -1,
1949 false, // ping_only
1950 ErrorCode::kSuccess,
1951 metrics::CheckResult::kNoUpdateAvailable,
1952 metrics::CheckReaction::kUnset,
1953 metrics::DownloadErrorCode::kUnset,
1954 nullptr,
1955 &post_data));
1956 // We shouldn't send a ping in this case since powerwash > 0.
Alex Vakulenkof68bbbc2015-02-09 12:53:18 -08001957 string post_str(post_data.begin(), post_data.end());
Alex Deymoebbe7ef2014-10-30 13:02:49 -07001958 EXPECT_EQ(string::npos, post_str.find("<ping"));
1959}
1960
Alex Deymo9fded1e2015-11-05 12:31:19 -08001961// Checks that the event 54 is sent on a reboot to a new update.
1962TEST_F(OmahaRequestActionTest, RebootAfterUpdateEvent) {
1963 // Flag that the device was updated in a previous boot.
1964 fake_prefs_.SetString(kPrefsPreviousVersion, "1.2.3.4");
1965
1966 brillo::Blob post_data;
1967 ASSERT_TRUE(
1968 TestUpdateCheck(nullptr, // request_params
1969 fake_update_response_.GetNoUpdateResponse(),
1970 -1,
1971 false, // ping_only
1972 ErrorCode::kSuccess,
1973 metrics::CheckResult::kNoUpdateAvailable,
1974 metrics::CheckReaction::kUnset,
1975 metrics::DownloadErrorCode::kUnset,
1976 nullptr,
1977 &post_data));
1978 string post_str(post_data.begin(), post_data.end());
1979
1980 // An event 54 is included and has the right version.
1981 EXPECT_NE(string::npos,
1982 post_str.find(base::StringPrintf(
1983 "<event eventtype=\"%d\"",
1984 OmahaEvent::kTypeRebootedAfterUpdate)));
1985 EXPECT_NE(string::npos,
1986 post_str.find("previousversion=\"1.2.3.4\"></event>"));
1987
1988 // The previous version flag should have been removed.
1989 EXPECT_TRUE(fake_prefs_.Exists(kPrefsPreviousVersion));
1990 string prev_version;
1991 EXPECT_TRUE(fake_prefs_.GetString(kPrefsPreviousVersion, &prev_version));
1992 EXPECT_TRUE(prev_version.empty());
1993}
1994
Alex Deymoe1e3afe2014-10-30 13:02:49 -07001995void OmahaRequestActionTest::P2PTest(
1996 bool initial_allow_p2p_for_downloading,
1997 bool initial_allow_p2p_for_sharing,
1998 bool omaha_disable_p2p_for_downloading,
1999 bool omaha_disable_p2p_for_sharing,
2000 bool payload_state_allow_p2p_attempt,
2001 bool expect_p2p_client_lookup,
2002 const string& p2p_client_result_url,
2003 bool expected_allow_p2p_for_downloading,
2004 bool expected_allow_p2p_for_sharing,
2005 const string& expected_p2p_url) {
David Zeuthen8f191b22013-08-06 12:27:50 -07002006 OmahaResponse response;
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002007 OmahaRequestParams request_params = request_params_;
Gilad Arnold74b5f552014-10-07 08:17:16 -07002008 bool actual_allow_p2p_for_downloading = initial_allow_p2p_for_downloading;
2009 bool actual_allow_p2p_for_sharing = initial_allow_p2p_for_sharing;
2010 string actual_p2p_url;
David Zeuthen8f191b22013-08-06 12:27:50 -07002011
2012 MockPayloadState mock_payload_state;
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002013 fake_system_state_.set_payload_state(&mock_payload_state);
David Zeuthen8f191b22013-08-06 12:27:50 -07002014 EXPECT_CALL(mock_payload_state, P2PAttemptAllowed())
2015 .WillRepeatedly(Return(payload_state_allow_p2p_attempt));
Gilad Arnold74b5f552014-10-07 08:17:16 -07002016 EXPECT_CALL(mock_payload_state, GetUsingP2PForDownloading())
2017 .WillRepeatedly(ReturnPointee(&actual_allow_p2p_for_downloading));
2018 EXPECT_CALL(mock_payload_state, GetUsingP2PForSharing())
2019 .WillRepeatedly(ReturnPointee(&actual_allow_p2p_for_sharing));
2020 EXPECT_CALL(mock_payload_state, SetUsingP2PForDownloading(_))
2021 .WillRepeatedly(SaveArg<0>(&actual_allow_p2p_for_downloading));
2022 EXPECT_CALL(mock_payload_state, SetUsingP2PForSharing(_))
2023 .WillRepeatedly(SaveArg<0>(&actual_allow_p2p_for_sharing));
2024 EXPECT_CALL(mock_payload_state, SetP2PUrl(_))
2025 .WillRepeatedly(SaveArg<0>(&actual_p2p_url));
2026
David Zeuthen8f191b22013-08-06 12:27:50 -07002027 MockP2PManager mock_p2p_manager;
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002028 fake_system_state_.set_p2p_manager(&mock_p2p_manager);
David Zeuthen8f191b22013-08-06 12:27:50 -07002029 mock_p2p_manager.fake().SetLookupUrlForFileResult(p2p_client_result_url);
2030
David Zeuthen4cc5ed22014-01-15 12:35:03 -08002031 TimeDelta timeout = TimeDelta::FromSeconds(kMaxP2PNetworkWaitTimeSeconds);
2032 EXPECT_CALL(mock_p2p_manager, LookupUrlForFile(_, _, timeout, _))
David Zeuthen8f191b22013-08-06 12:27:50 -07002033 .Times(expect_p2p_client_lookup ? 1 : 0);
2034
Alex Deymo8e18f932015-03-27 16:16:59 -07002035 fake_update_response_.disable_p2p_for_downloading =
2036 omaha_disable_p2p_for_downloading;
2037 fake_update_response_.disable_p2p_for_sharing = omaha_disable_p2p_for_sharing;
David Zeuthen8f191b22013-08-06 12:27:50 -07002038 ASSERT_TRUE(
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002039 TestUpdateCheck(&request_params,
Alex Deymo8e18f932015-03-27 16:16:59 -07002040 fake_update_response_.GetUpdateResponse(),
David Zeuthen8f191b22013-08-06 12:27:50 -07002041 -1,
2042 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07002043 ErrorCode::kSuccess,
David Zeuthen33bae492014-02-25 16:16:18 -08002044 metrics::CheckResult::kUpdateAvailable,
2045 metrics::CheckReaction::kUpdating,
2046 metrics::DownloadErrorCode::kUnset,
David Zeuthen8f191b22013-08-06 12:27:50 -07002047 &response,
Alex Vakulenko88b591f2014-08-28 16:48:57 -07002048 nullptr));
David Zeuthen8f191b22013-08-06 12:27:50 -07002049 EXPECT_TRUE(response.update_exists);
2050
Gilad Arnold74b5f552014-10-07 08:17:16 -07002051 EXPECT_EQ(omaha_disable_p2p_for_downloading,
2052 response.disable_p2p_for_downloading);
2053 EXPECT_EQ(omaha_disable_p2p_for_sharing,
2054 response.disable_p2p_for_sharing);
David Zeuthen8f191b22013-08-06 12:27:50 -07002055
Gilad Arnold74b5f552014-10-07 08:17:16 -07002056 EXPECT_EQ(expected_allow_p2p_for_downloading,
2057 actual_allow_p2p_for_downloading);
2058 EXPECT_EQ(expected_allow_p2p_for_sharing, actual_allow_p2p_for_sharing);
2059 EXPECT_EQ(expected_p2p_url, actual_p2p_url);
David Zeuthen8f191b22013-08-06 12:27:50 -07002060}
2061
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002062TEST_F(OmahaRequestActionTest, P2PWithPeer) {
Alex Vakulenkod2779df2014-06-16 13:19:00 -07002063 P2PTest(true, // initial_allow_p2p_for_downloading
2064 true, // initial_allow_p2p_for_sharing
2065 false, // omaha_disable_p2p_for_downloading
2066 false, // omaha_disable_p2p_for_sharing
2067 true, // payload_state_allow_p2p_attempt
2068 true, // expect_p2p_client_lookup
2069 "http://1.3.5.7/p2p", // p2p_client_result_url
2070 true, // expected_allow_p2p_for_downloading
2071 true, // expected_allow_p2p_for_sharing
2072 "http://1.3.5.7/p2p"); // expected_p2p_url
David Zeuthen8f191b22013-08-06 12:27:50 -07002073}
2074
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002075TEST_F(OmahaRequestActionTest, P2PWithoutPeer) {
Alex Vakulenkod2779df2014-06-16 13:19:00 -07002076 P2PTest(true, // initial_allow_p2p_for_downloading
2077 true, // initial_allow_p2p_for_sharing
2078 false, // omaha_disable_p2p_for_downloading
2079 false, // omaha_disable_p2p_for_sharing
2080 true, // payload_state_allow_p2p_attempt
2081 true, // expect_p2p_client_lookup
2082 "", // p2p_client_result_url
2083 false, // expected_allow_p2p_for_downloading
2084 true, // expected_allow_p2p_for_sharing
2085 ""); // expected_p2p_url
David Zeuthen8f191b22013-08-06 12:27:50 -07002086}
2087
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002088TEST_F(OmahaRequestActionTest, P2PDownloadNotAllowed) {
Alex Vakulenkod2779df2014-06-16 13:19:00 -07002089 P2PTest(false, // initial_allow_p2p_for_downloading
2090 true, // initial_allow_p2p_for_sharing
2091 false, // omaha_disable_p2p_for_downloading
2092 false, // omaha_disable_p2p_for_sharing
2093 true, // payload_state_allow_p2p_attempt
2094 false, // expect_p2p_client_lookup
2095 "unset", // p2p_client_result_url
2096 false, // expected_allow_p2p_for_downloading
2097 true, // expected_allow_p2p_for_sharing
2098 ""); // expected_p2p_url
David Zeuthen8f191b22013-08-06 12:27:50 -07002099}
2100
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002101TEST_F(OmahaRequestActionTest, P2PWithPeerDownloadDisabledByOmaha) {
Alex Vakulenkod2779df2014-06-16 13:19:00 -07002102 P2PTest(true, // initial_allow_p2p_for_downloading
2103 true, // initial_allow_p2p_for_sharing
2104 true, // omaha_disable_p2p_for_downloading
2105 false, // omaha_disable_p2p_for_sharing
2106 true, // payload_state_allow_p2p_attempt
2107 false, // expect_p2p_client_lookup
2108 "unset", // p2p_client_result_url
2109 false, // expected_allow_p2p_for_downloading
2110 true, // expected_allow_p2p_for_sharing
2111 ""); // expected_p2p_url
David Zeuthen8f191b22013-08-06 12:27:50 -07002112}
2113
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002114TEST_F(OmahaRequestActionTest, P2PWithPeerSharingDisabledByOmaha) {
Alex Vakulenkod2779df2014-06-16 13:19:00 -07002115 P2PTest(true, // initial_allow_p2p_for_downloading
2116 true, // initial_allow_p2p_for_sharing
2117 false, // omaha_disable_p2p_for_downloading
2118 true, // omaha_disable_p2p_for_sharing
2119 true, // payload_state_allow_p2p_attempt
2120 true, // expect_p2p_client_lookup
2121 "http://1.3.5.7/p2p", // p2p_client_result_url
2122 true, // expected_allow_p2p_for_downloading
2123 false, // expected_allow_p2p_for_sharing
2124 "http://1.3.5.7/p2p"); // expected_p2p_url
David Zeuthen8f191b22013-08-06 12:27:50 -07002125}
2126
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002127TEST_F(OmahaRequestActionTest, P2PWithPeerBothDisabledByOmaha) {
Alex Vakulenkod2779df2014-06-16 13:19:00 -07002128 P2PTest(true, // initial_allow_p2p_for_downloading
2129 true, // initial_allow_p2p_for_sharing
2130 true, // omaha_disable_p2p_for_downloading
2131 true, // omaha_disable_p2p_for_sharing
2132 true, // payload_state_allow_p2p_attempt
2133 false, // expect_p2p_client_lookup
2134 "unset", // p2p_client_result_url
2135 false, // expected_allow_p2p_for_downloading
2136 false, // expected_allow_p2p_for_sharing
2137 ""); // expected_p2p_url
David Zeuthen8f191b22013-08-06 12:27:50 -07002138}
2139
Alex Deymof329b932014-10-30 01:37:48 -07002140bool OmahaRequestActionTest::InstallDateParseHelper(const string &elapsed_days,
2141 OmahaResponse *response) {
Alex Deymo8e18f932015-03-27 16:16:59 -07002142 fake_update_response_.elapsed_days = elapsed_days;
David Zeuthen639aa362014-02-03 16:23:44 -08002143 return
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002144 TestUpdateCheck(nullptr, // request_params
Alex Deymo8e18f932015-03-27 16:16:59 -07002145 fake_update_response_.GetUpdateResponse(),
David Zeuthen639aa362014-02-03 16:23:44 -08002146 -1,
2147 false, // ping_only
Gilad Arnoldd1c4d2d2014-06-05 14:07:53 -07002148 ErrorCode::kSuccess,
David Zeuthen33bae492014-02-25 16:16:18 -08002149 metrics::CheckResult::kUpdateAvailable,
2150 metrics::CheckReaction::kUpdating,
2151 metrics::DownloadErrorCode::kUnset,
David Zeuthen639aa362014-02-03 16:23:44 -08002152 response,
Alex Vakulenko88b591f2014-08-28 16:48:57 -07002153 nullptr);
David Zeuthen639aa362014-02-03 16:23:44 -08002154}
2155
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002156TEST_F(OmahaRequestActionTest, ParseInstallDateFromResponse) {
David Zeuthen639aa362014-02-03 16:23:44 -08002157 OmahaResponse response;
David Zeuthen639aa362014-02-03 16:23:44 -08002158
Kevin Cernekee2494e282016-03-29 18:03:53 -07002159 // Simulate a successful update check that happens during OOBE. The
2160 // deadline in the response is needed to force the update attempt to
2161 // occur; responses without a deadline seen during OOBE will normally
2162 // return ErrorCode::kNonCriticalUpdateInOOBE.
2163 fake_system_state_.fake_hardware()->UnsetIsOOBEComplete();
2164 fake_update_response_.deadline = "20101020";
2165
David Zeuthen639aa362014-02-03 16:23:44 -08002166 // Check that we parse elapsed_days in the Omaha Response correctly.
2167 // and that the kPrefsInstallDateDays value is written to.
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002168 EXPECT_FALSE(fake_prefs_.Exists(kPrefsInstallDateDays));
2169 EXPECT_TRUE(InstallDateParseHelper("42", &response));
David Zeuthen639aa362014-02-03 16:23:44 -08002170 EXPECT_TRUE(response.update_exists);
2171 EXPECT_EQ(42, response.install_date_days);
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002172 EXPECT_TRUE(fake_prefs_.Exists(kPrefsInstallDateDays));
David Zeuthen639aa362014-02-03 16:23:44 -08002173 int64_t prefs_days;
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002174 EXPECT_TRUE(fake_prefs_.GetInt64(kPrefsInstallDateDays, &prefs_days));
David Zeuthen639aa362014-02-03 16:23:44 -08002175 EXPECT_EQ(prefs_days, 42);
2176
2177 // If there already is a value set, we shouldn't do anything.
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002178 EXPECT_TRUE(InstallDateParseHelper("7", &response));
David Zeuthen639aa362014-02-03 16:23:44 -08002179 EXPECT_TRUE(response.update_exists);
2180 EXPECT_EQ(7, response.install_date_days);
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002181 EXPECT_TRUE(fake_prefs_.GetInt64(kPrefsInstallDateDays, &prefs_days));
David Zeuthen639aa362014-02-03 16:23:44 -08002182 EXPECT_EQ(prefs_days, 42);
2183
2184 // Note that elapsed_days is not necessarily divisible by 7 so check
2185 // that we round down correctly when populating kPrefsInstallDateDays.
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002186 EXPECT_TRUE(fake_prefs_.Delete(kPrefsInstallDateDays));
2187 EXPECT_TRUE(InstallDateParseHelper("23", &response));
David Zeuthen639aa362014-02-03 16:23:44 -08002188 EXPECT_TRUE(response.update_exists);
2189 EXPECT_EQ(23, response.install_date_days);
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002190 EXPECT_TRUE(fake_prefs_.GetInt64(kPrefsInstallDateDays, &prefs_days));
David Zeuthen639aa362014-02-03 16:23:44 -08002191 EXPECT_EQ(prefs_days, 21);
2192
2193 // Check that we correctly handle elapsed_days not being included in
2194 // the Omaha Response.
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002195 EXPECT_TRUE(InstallDateParseHelper("", &response));
David Zeuthen639aa362014-02-03 16:23:44 -08002196 EXPECT_TRUE(response.update_exists);
2197 EXPECT_EQ(-1, response.install_date_days);
David Zeuthen639aa362014-02-03 16:23:44 -08002198}
2199
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002200// If there is no prefs and OOBE is not complete, we should not
2201// report anything to Omaha.
2202TEST_F(OmahaRequestActionTest, GetInstallDateWhenNoPrefsNorOOBE) {
Kevin Cernekee2494e282016-03-29 18:03:53 -07002203 fake_system_state_.fake_hardware()->UnsetIsOOBEComplete();
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002204 EXPECT_EQ(OmahaRequestAction::GetInstallDate(&fake_system_state_), -1);
2205 EXPECT_FALSE(fake_prefs_.Exists(kPrefsInstallDateDays));
2206}
David Zeuthen639aa362014-02-03 16:23:44 -08002207
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002208// If OOBE is complete and happened on a valid date (e.g. after Jan
2209// 1 2007 0:00 PST), that date should be used and written to
2210// prefs. However, first try with an invalid date and check we do
2211// nothing.
2212TEST_F(OmahaRequestActionTest, GetInstallDateWhenOOBECompletedWithInvalidDate) {
2213 Time oobe_date = Time::FromTimeT(42); // Dec 31, 1969 16:00:42 PST.
2214 fake_system_state_.fake_hardware()->SetIsOOBEComplete(oobe_date);
2215 EXPECT_EQ(OmahaRequestAction::GetInstallDate(&fake_system_state_), -1);
2216 EXPECT_FALSE(fake_prefs_.Exists(kPrefsInstallDateDays));
2217}
David Zeuthen639aa362014-02-03 16:23:44 -08002218
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002219// Then check with a valid date. The date Jan 20, 2007 0:00 PST
2220// should yield an InstallDate of 14.
2221TEST_F(OmahaRequestActionTest, GetInstallDateWhenOOBECompletedWithValidDate) {
2222 Time oobe_date = Time::FromTimeT(1169280000); // Jan 20, 2007 0:00 PST.
2223 fake_system_state_.fake_hardware()->SetIsOOBEComplete(oobe_date);
2224 EXPECT_EQ(OmahaRequestAction::GetInstallDate(&fake_system_state_), 14);
2225 EXPECT_TRUE(fake_prefs_.Exists(kPrefsInstallDateDays));
David Zeuthen639aa362014-02-03 16:23:44 -08002226
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002227 int64_t prefs_days;
2228 EXPECT_TRUE(fake_prefs_.GetInt64(kPrefsInstallDateDays, &prefs_days));
2229 EXPECT_EQ(prefs_days, 14);
2230}
David Zeuthen639aa362014-02-03 16:23:44 -08002231
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002232// Now that we have a valid date in prefs, check that we keep using
2233// that even if OOBE date reports something else. The date Jan 30,
2234// 2007 0:00 PST should yield an InstallDate of 28... but since
2235// there's a prefs file, we should still get 14.
2236TEST_F(OmahaRequestActionTest, GetInstallDateWhenOOBECompletedDateChanges) {
2237 // Set a valid date in the prefs first.
2238 EXPECT_TRUE(fake_prefs_.SetInt64(kPrefsInstallDateDays, 14));
David Zeuthen639aa362014-02-03 16:23:44 -08002239
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002240 Time oobe_date = Time::FromTimeT(1170144000); // Jan 30, 2007 0:00 PST.
2241 fake_system_state_.fake_hardware()->SetIsOOBEComplete(oobe_date);
2242 EXPECT_EQ(OmahaRequestAction::GetInstallDate(&fake_system_state_), 14);
David Zeuthen639aa362014-02-03 16:23:44 -08002243
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002244 int64_t prefs_days;
2245 EXPECT_TRUE(fake_prefs_.GetInt64(kPrefsInstallDateDays, &prefs_days));
2246 EXPECT_EQ(prefs_days, 14);
David Zeuthen639aa362014-02-03 16:23:44 -08002247
Alex Deymoe1e3afe2014-10-30 13:02:49 -07002248 // If we delete the prefs file, we should get 28 days.
2249 EXPECT_TRUE(fake_prefs_.Delete(kPrefsInstallDateDays));
2250 EXPECT_EQ(OmahaRequestAction::GetInstallDate(&fake_system_state_), 28);
2251 EXPECT_TRUE(fake_prefs_.GetInt64(kPrefsInstallDateDays, &prefs_days));
2252 EXPECT_EQ(prefs_days, 28);
David Zeuthen639aa362014-02-03 16:23:44 -08002253}
2254
Darin Petkov6a5b3222010-07-13 14:55:28 -07002255} // namespace chromeos_update_engine