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

Side by Side Diff: omaha_request_action_unittest.cc

Issue 2856070: Don't send machine and user ID to Omaha anymore. Send a/r pings instead. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git
Patch Set: Address review comments. Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include <glib.h> 8 #include <glib.h>
9 9
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/time.h"
11 #include "gtest/gtest.h" 12 #include "gtest/gtest.h"
12 #include "update_engine/action_pipe.h" 13 #include "update_engine/action_pipe.h"
13 #include "update_engine/mock_http_fetcher.h" 14 #include "update_engine/mock_http_fetcher.h"
14 #include "update_engine/omaha_hash_calculator.h" 15 #include "update_engine/omaha_hash_calculator.h"
15 #include "update_engine/omaha_request_action.h" 16 #include "update_engine/omaha_request_action.h"
16 #include "update_engine/omaha_request_params.h" 17 #include "update_engine/omaha_request_params.h"
18 #include "update_engine/prefs_mock.h"
17 #include "update_engine/test_utils.h" 19 #include "update_engine/test_utils.h"
18 20
21 using base::Time;
22 using base::TimeDelta;
19 using std::string; 23 using std::string;
20 using std::vector; 24 using std::vector;
25 using testing::_;
26 using testing::AllOf;
27 using testing::Ge;
28 using testing::Le;
29 using testing::Return;
30 using testing::SetArgumentPointee;
21 31
22 namespace chromeos_update_engine { 32 namespace chromeos_update_engine {
23 33
24 class OmahaRequestActionTest : public ::testing::Test { }; 34 class OmahaRequestActionTest : public ::testing::Test { };
25 35
26 namespace { 36 namespace {
37 const OmahaRequestParams kDefaultTestParams(
38 "machine_id",
39 "user_id",
40 OmahaRequestParams::kOsPlatform,
41 OmahaRequestParams::kOsVersion,
42 "service_pack",
43 "x86-generic",
44 OmahaRequestParams::kAppId,
45 "0.1.0.0",
46 "en-US",
47 "unittest",
48 false, // delta okay
49 "http://url");
50
27 string GetNoUpdateResponse(const string& app_id) { 51 string GetNoUpdateResponse(const string& app_id) {
28 return string( 52 return string(
29 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " 53 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate "
30 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " 54 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app "
31 "appid=\"") + app_id + "\" status=\"ok\"><ping " 55 "appid=\"") + app_id + "\" status=\"ok\"><ping "
32 "status=\"ok\"/><updatecheck status=\"noupdate\"/></app></gupdate>"; 56 "status=\"ok\"/><updatecheck status=\"noupdate\"/></app></gupdate>";
33 } 57 }
34 58
35 string GetUpdateResponse(const string& app_id, 59 string GetUpdateResponse(const string& app_id,
36 const string& display_version, 60 const string& display_version,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 } 100 }
77 GMainLoop *loop_; 101 GMainLoop *loop_;
78 ActionExitCode expected_code_; 102 ActionExitCode expected_code_;
79 }; 103 };
80 104
81 gboolean StartProcessorInRunLoop(gpointer data) { 105 gboolean StartProcessorInRunLoop(gpointer data) {
82 ActionProcessor *processor = reinterpret_cast<ActionProcessor*>(data); 106 ActionProcessor *processor = reinterpret_cast<ActionProcessor*>(data);
83 processor->StartProcessing(); 107 processor->StartProcessing();
84 return FALSE; 108 return FALSE;
85 } 109 }
86
87 } // namespace {} 110 } // namespace {}
88 111
89 class OutputObjectCollectorAction; 112 class OutputObjectCollectorAction;
90 113
91 template<> 114 template<>
92 class ActionTraits<OutputObjectCollectorAction> { 115 class ActionTraits<OutputObjectCollectorAction> {
93 public: 116 public:
94 // Does not take an object for input 117 // Does not take an object for input
95 typedef OmahaResponse InputObjectType; 118 typedef OmahaResponse InputObjectType;
96 // On success, puts the output path on output 119 // On success, puts the output path on output
(...skipping 16 matching lines...) Expand all
113 } 136 }
114 // Debugging/logging 137 // Debugging/logging
115 static std::string StaticType() { 138 static std::string StaticType() {
116 return "OutputObjectCollectorAction"; 139 return "OutputObjectCollectorAction";
117 } 140 }
118 std::string Type() const { return StaticType(); } 141 std::string Type() const { return StaticType(); }
119 bool has_input_object_; 142 bool has_input_object_;
120 OmahaResponse omaha_response_; 143 OmahaResponse omaha_response_;
121 }; 144 };
122 145
123 // returns true iff an output response was obtained from the 146 // Returns true iff an output response was obtained from the
124 // OmahaRequestAction. out_response may be NULL. 147 // OmahaRequestAction. |prefs| may be NULL, in which case a local
125 // out_post_data may be null; if non-null, the post-data received by the 148 // PrefsMock is used. out_response may be NULL. out_post_data may be
126 // mock HttpFetcher is returned. 149 // null; if non-null, the post-data received by the mock HttpFetcher
127 bool TestUpdateCheck(const OmahaRequestParams& params, 150 // is returned.
151 bool TestUpdateCheck(PrefsInterface* prefs,
152 const OmahaRequestParams& params,
128 const string& http_response, 153 const string& http_response,
129 ActionExitCode expected_code, 154 ActionExitCode expected_code,
130 OmahaResponse* out_response, 155 OmahaResponse* out_response,
131 vector<char>* out_post_data) { 156 vector<char>* out_post_data) {
132 GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE); 157 GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE);
133 MockHttpFetcher* fetcher = new MockHttpFetcher(http_response.data(), 158 MockHttpFetcher* fetcher = new MockHttpFetcher(http_response.data(),
134 http_response.size()); 159 http_response.size());
135 OmahaRequestAction action(params, NULL, fetcher); 160 PrefsMock local_prefs;
161 OmahaRequestAction action(prefs ? prefs : &local_prefs,
162 params,
163 NULL,
164 fetcher);
136 OmahaRequestActionTestProcessorDelegate delegate; 165 OmahaRequestActionTestProcessorDelegate delegate;
137 delegate.loop_ = loop; 166 delegate.loop_ = loop;
138 delegate.expected_code_ = expected_code; 167 delegate.expected_code_ = expected_code;
139 168
140 ActionProcessor processor; 169 ActionProcessor processor;
141 processor.set_delegate(&delegate); 170 processor.set_delegate(&delegate);
142 processor.EnqueueAction(&action); 171 processor.EnqueueAction(&action);
143 172
144 OutputObjectCollectorAction collector_action; 173 OutputObjectCollectorAction collector_action;
145 BondActions(&action, &collector_action); 174 BondActions(&action, &collector_action);
(...skipping 12 matching lines...) Expand all
158 // Tests Event requests -- they should always succeed. |out_post_data| 187 // Tests Event requests -- they should always succeed. |out_post_data|
159 // may be null; if non-null, the post-data received by the mock 188 // may be null; if non-null, the post-data received by the mock
160 // HttpFetcher is returned. 189 // HttpFetcher is returned.
161 void TestEvent(const OmahaRequestParams& params, 190 void TestEvent(const OmahaRequestParams& params,
162 OmahaEvent* event, 191 OmahaEvent* event,
163 const string& http_response, 192 const string& http_response,
164 vector<char>* out_post_data) { 193 vector<char>* out_post_data) {
165 GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE); 194 GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE);
166 MockHttpFetcher* fetcher = new MockHttpFetcher(http_response.data(), 195 MockHttpFetcher* fetcher = new MockHttpFetcher(http_response.data(),
167 http_response.size()); 196 http_response.size());
168 OmahaRequestAction action(params, event, fetcher); 197 PrefsMock prefs;
198 OmahaRequestAction action(&prefs, params, event, fetcher);
169 OmahaRequestActionTestProcessorDelegate delegate; 199 OmahaRequestActionTestProcessorDelegate delegate;
170 delegate.loop_ = loop; 200 delegate.loop_ = loop;
171 ActionProcessor processor; 201 ActionProcessor processor;
172 processor.set_delegate(&delegate); 202 processor.set_delegate(&delegate);
173 processor.EnqueueAction(&action); 203 processor.EnqueueAction(&action);
174 204
175 g_timeout_add(0, &StartProcessorInRunLoop, &processor); 205 g_timeout_add(0, &StartProcessorInRunLoop, &processor);
176 g_main_loop_run(loop); 206 g_main_loop_run(loop);
177 g_main_loop_unref(loop); 207 g_main_loop_unref(loop);
178 if (out_post_data) 208 if (out_post_data)
179 *out_post_data = fetcher->post_data(); 209 *out_post_data = fetcher->post_data();
180 } 210 }
181 211
182 TEST(OmahaRequestActionTest, NoUpdateTest) { 212 TEST(OmahaRequestActionTest, NoUpdateTest) {
183 OmahaRequestParams params("", // machine_id
184 "", // user_id
185 OmahaRequestParams::kOsPlatform,
186 OmahaRequestParams::kOsVersion,
187 "", // os_sp
188 "x86-generic",
189 OmahaRequestParams::kAppId,
190 "0.1.0.0",
191 "en-US",
192 "unittest",
193 false, // delta okay
194 ""); // url
195 OmahaResponse response; 213 OmahaResponse response;
196 ASSERT_TRUE( 214 ASSERT_TRUE(
197 TestUpdateCheck(params, 215 TestUpdateCheck(NULL, // prefs
216 kDefaultTestParams,
198 GetNoUpdateResponse(OmahaRequestParams::kAppId), 217 GetNoUpdateResponse(OmahaRequestParams::kAppId),
199 kActionCodeSuccess, 218 kActionCodeSuccess,
200 &response, 219 &response,
201 NULL)); 220 NULL));
202 EXPECT_FALSE(response.update_exists); 221 EXPECT_FALSE(response.update_exists);
203 } 222 }
204 223
205 TEST(OmahaRequestActionTest, ValidUpdateTest) { 224 TEST(OmahaRequestActionTest, ValidUpdateTest) {
206 OmahaRequestParams params("machine_id",
207 "user_id",
208 OmahaRequestParams::kOsPlatform,
209 OmahaRequestParams::kOsVersion,
210 "service_pack",
211 "arm-generic",
212 OmahaRequestParams::kAppId,
213 "0.1.0.0",
214 "en-US",
215 "unittest_track",
216 false, // delta okay
217 ""); // url
218 OmahaResponse response; 225 OmahaResponse response;
219 ASSERT_TRUE( 226 ASSERT_TRUE(
220 TestUpdateCheck(params, 227 TestUpdateCheck(NULL, // prefs
228 kDefaultTestParams,
221 GetUpdateResponse(OmahaRequestParams::kAppId, 229 GetUpdateResponse(OmahaRequestParams::kAppId,
222 "1.2.3.4", // version 230 "1.2.3.4", // version
223 "http://more/info", 231 "http://more/info",
224 "true", // prompt 232 "true", // prompt
225 "http://code/base", // dl url 233 "http://code/base", // dl url
226 "HASH1234=", // checksum 234 "HASH1234=", // checksum
227 "false", // needs admin 235 "false", // needs admin
228 "123"), // size 236 "123"), // size
229 kActionCodeSuccess, 237 kActionCodeSuccess,
230 &response, 238 &response,
231 NULL)); 239 NULL));
232 EXPECT_TRUE(response.update_exists); 240 EXPECT_TRUE(response.update_exists);
233 EXPECT_EQ("1.2.3.4", response.display_version); 241 EXPECT_EQ("1.2.3.4", response.display_version);
234 EXPECT_EQ("http://code/base", response.codebase); 242 EXPECT_EQ("http://code/base", response.codebase);
235 EXPECT_EQ("http://more/info", response.more_info_url); 243 EXPECT_EQ("http://more/info", response.more_info_url);
236 EXPECT_TRUE(response.is_delta); 244 EXPECT_TRUE(response.is_delta);
237 EXPECT_EQ("HASH1234=", response.hash); 245 EXPECT_EQ("HASH1234=", response.hash);
238 EXPECT_EQ(123, response.size); 246 EXPECT_EQ(123, response.size);
239 EXPECT_FALSE(response.needs_admin); 247 EXPECT_FALSE(response.needs_admin);
240 EXPECT_TRUE(response.prompt); 248 EXPECT_TRUE(response.prompt);
241 } 249 }
242 250
243 TEST(OmahaRequestActionTest, NoOutputPipeTest) { 251 TEST(OmahaRequestActionTest, NoOutputPipeTest) {
244 OmahaRequestParams params("", // machine_id
245 "", // usr_id
246 OmahaRequestParams::kOsPlatform,
247 OmahaRequestParams::kOsVersion,
248 "", // os_sp
249 "", // os_board
250 OmahaRequestParams::kAppId,
251 "0.1.0.0",
252 "en-US",
253 "unittest",
254 false, // delta okay
255 ""); // url
256 const string http_response(GetNoUpdateResponse(OmahaRequestParams::kAppId)); 252 const string http_response(GetNoUpdateResponse(OmahaRequestParams::kAppId));
257 253
258 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); 254 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE);
259 255
260 OmahaRequestAction action(params, NULL, 256 PrefsMock prefs;
257 OmahaRequestAction action(&prefs, kDefaultTestParams, NULL,
261 new MockHttpFetcher(http_response.data(), 258 new MockHttpFetcher(http_response.data(),
262 http_response.size())); 259 http_response.size()));
263 OmahaRequestActionTestProcessorDelegate delegate; 260 OmahaRequestActionTestProcessorDelegate delegate;
264 delegate.loop_ = loop; 261 delegate.loop_ = loop;
265 ActionProcessor processor; 262 ActionProcessor processor;
266 processor.set_delegate(&delegate); 263 processor.set_delegate(&delegate);
267 processor.EnqueueAction(&action); 264 processor.EnqueueAction(&action);
268 265
269 g_timeout_add(0, &StartProcessorInRunLoop, &processor); 266 g_timeout_add(0, &StartProcessorInRunLoop, &processor);
270 g_main_loop_run(loop); 267 g_main_loop_run(loop);
271 g_main_loop_unref(loop); 268 g_main_loop_unref(loop);
272 EXPECT_FALSE(processor.IsRunning()); 269 EXPECT_FALSE(processor.IsRunning());
273 } 270 }
274 271
275 TEST(OmahaRequestActionTest, InvalidXmlTest) { 272 TEST(OmahaRequestActionTest, InvalidXmlTest) {
276 OmahaRequestParams params("machine_id",
277 "user_id",
278 OmahaRequestParams::kOsPlatform,
279 OmahaRequestParams::kOsVersion,
280 "service_pack",
281 "x86-generic",
282 OmahaRequestParams::kAppId,
283 "0.1.0.0",
284 "en-US",
285 "unittest_track",
286 false, // delta okay
287 "http://url");
288 OmahaResponse response; 273 OmahaResponse response;
289 ASSERT_FALSE( 274 ASSERT_FALSE(
290 TestUpdateCheck(params, 275 TestUpdateCheck(NULL, // prefs
276 kDefaultTestParams,
291 "invalid xml>", 277 "invalid xml>",
292 kActionCodeError, 278 kActionCodeError,
293 &response, 279 &response,
294 NULL)); 280 NULL));
295 EXPECT_FALSE(response.update_exists); 281 EXPECT_FALSE(response.update_exists);
296 } 282 }
297 283
298 TEST(OmahaRequestActionTest, MissingStatusTest) { 284 TEST(OmahaRequestActionTest, MissingStatusTest) {
299 OmahaRequestParams params("machine_id",
300 "user_id",
301 OmahaRequestParams::kOsPlatform,
302 OmahaRequestParams::kOsVersion,
303 "service_pack",
304 "x86-generic",
305 OmahaRequestParams::kAppId,
306 "0.1.0.0",
307 "en-US",
308 "unittest_track",
309 false, // delta okay
310 "http://url");
311 OmahaResponse response; 285 OmahaResponse response;
312 ASSERT_FALSE(TestUpdateCheck( 286 ASSERT_FALSE(TestUpdateCheck(
313 params, 287 NULL, // prefs
288 kDefaultTestParams,
314 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " 289 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate "
315 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " 290 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app "
316 "appid=\"foo\" status=\"ok\"><ping " 291 "appid=\"foo\" status=\"ok\"><ping "
317 "status=\"ok\"/><updatecheck/></app></gupdate>", 292 "status=\"ok\"/><updatecheck/></app></gupdate>",
318 kActionCodeError, 293 kActionCodeError,
319 &response, 294 &response,
320 NULL)); 295 NULL));
321 EXPECT_FALSE(response.update_exists); 296 EXPECT_FALSE(response.update_exists);
322 } 297 }
323 298
324 TEST(OmahaRequestActionTest, InvalidStatusTest) { 299 TEST(OmahaRequestActionTest, InvalidStatusTest) {
325 OmahaRequestParams params("machine_id",
326 "user_id",
327 OmahaRequestParams::kOsPlatform,
328 OmahaRequestParams::kOsVersion,
329 "service_pack",
330 "x86-generic",
331 OmahaRequestParams::kAppId,
332 "0.1.0.0",
333 "en-US",
334 "unittest_track",
335 false, // delta okay
336 "http://url");
337 OmahaResponse response; 300 OmahaResponse response;
338 ASSERT_FALSE(TestUpdateCheck( 301 ASSERT_FALSE(TestUpdateCheck(
339 params, 302 NULL, // prefs
303 kDefaultTestParams,
340 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " 304 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate "
341 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " 305 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app "
342 "appid=\"foo\" status=\"ok\"><ping " 306 "appid=\"foo\" status=\"ok\"><ping "
343 "status=\"ok\"/><updatecheck status=\"foo\"/></app></gupdate>", 307 "status=\"ok\"/><updatecheck status=\"foo\"/></app></gupdate>",
344 kActionCodeError, 308 kActionCodeError,
345 &response, 309 &response,
346 NULL)); 310 NULL));
347 EXPECT_FALSE(response.update_exists); 311 EXPECT_FALSE(response.update_exists);
348 } 312 }
349 313
350 TEST(OmahaRequestActionTest, MissingNodesetTest) { 314 TEST(OmahaRequestActionTest, MissingNodesetTest) {
351 OmahaRequestParams params("machine_id",
352 "user_id",
353 OmahaRequestParams::kOsPlatform,
354 OmahaRequestParams::kOsVersion,
355 "service_pack",
356 "x86-generic",
357 OmahaRequestParams::kAppId,
358 "0.1.0.0",
359 "en-US",
360 "unittest_track",
361 false, // delta okay
362 "http://url");
363 OmahaResponse response; 315 OmahaResponse response;
364 ASSERT_FALSE(TestUpdateCheck( 316 ASSERT_FALSE(TestUpdateCheck(
365 params, 317 NULL, // prefs
318 kDefaultTestParams,
366 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " 319 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate "
367 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " 320 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app "
368 "appid=\"foo\" status=\"ok\"><ping " 321 "appid=\"foo\" status=\"ok\"><ping "
369 "status=\"ok\"/></app></gupdate>", 322 "status=\"ok\"/></app></gupdate>",
370 kActionCodeError, 323 kActionCodeError,
371 &response, 324 &response,
372 NULL)); 325 NULL));
373 EXPECT_FALSE(response.update_exists); 326 EXPECT_FALSE(response.update_exists);
374 } 327 }
375 328
376 TEST(OmahaRequestActionTest, MissingFieldTest) { 329 TEST(OmahaRequestActionTest, MissingFieldTest) {
377 OmahaRequestParams params("machine_id",
378 "user_id",
379 OmahaRequestParams::kOsPlatform,
380 OmahaRequestParams::kOsVersion,
381 "service_pack",
382 "x86-generic",
383 OmahaRequestParams::kAppId,
384 "0.1.0.0",
385 "en-US",
386 "unittest_track",
387 false, // delta okay
388 "http://url");
389 OmahaResponse response; 330 OmahaResponse response;
390 ASSERT_TRUE(TestUpdateCheck(params, 331 ASSERT_TRUE(TestUpdateCheck(NULL, // prefs
332 kDefaultTestParams,
391 string("<?xml version=\"1.0\" " 333 string("<?xml version=\"1.0\" "
392 "encoding=\"UTF-8\"?><gupdate " 334 "encoding=\"UTF-8\"?><gupdate "
393 "xmlns=\"http://www.google.com/" 335 "xmlns=\"http://www.google.com/"
394 "update2/response\" " 336 "update2/response\" "
395 "protocol=\"2.0\"><app appid=\"") + 337 "protocol=\"2.0\"><app appid=\"") +
396 OmahaRequestParams::kAppId 338 OmahaRequestParams::kAppId
397 + "\" status=\"ok\"><ping " 339 + "\" status=\"ok\"><ping "
398 "status=\"ok\"/><updatecheck " 340 "status=\"ok\"/><updatecheck "
399 "DisplayVersion=\"1.2.3.4\" " 341 "DisplayVersion=\"1.2.3.4\" "
400 "Prompt=\"false\" " 342 "Prompt=\"false\" "
(...skipping 28 matching lines...) Expand all
429 gboolean TerminateTransferTestStarter(gpointer data) { 371 gboolean TerminateTransferTestStarter(gpointer data) {
430 ActionProcessor *processor = reinterpret_cast<ActionProcessor*>(data); 372 ActionProcessor *processor = reinterpret_cast<ActionProcessor*>(data);
431 processor->StartProcessing(); 373 processor->StartProcessing();
432 CHECK(processor->IsRunning()); 374 CHECK(processor->IsRunning());
433 processor->StopProcessing(); 375 processor->StopProcessing();
434 return FALSE; 376 return FALSE;
435 } 377 }
436 } // namespace {} 378 } // namespace {}
437 379
438 TEST(OmahaRequestActionTest, TerminateTransferTest) { 380 TEST(OmahaRequestActionTest, TerminateTransferTest) {
439 OmahaRequestParams params("", // machine_id
440 "", // usr_id
441 OmahaRequestParams::kOsPlatform,
442 OmahaRequestParams::kOsVersion,
443 "", // os_sp
444 "", // os_board
445 OmahaRequestParams::kAppId,
446 "0.1.0.0",
447 "en-US",
448 "unittest",
449 false, // delta okay
450 "http://url");
451 string http_response("doesn't matter"); 381 string http_response("doesn't matter");
452 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); 382 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE);
453 383
454 OmahaRequestAction action(params, NULL, 384 PrefsMock prefs;
385 OmahaRequestAction action(&prefs, kDefaultTestParams, NULL,
455 new MockHttpFetcher(http_response.data(), 386 new MockHttpFetcher(http_response.data(),
456 http_response.size())); 387 http_response.size()));
457 TerminateEarlyTestProcessorDelegate delegate; 388 TerminateEarlyTestProcessorDelegate delegate;
458 delegate.loop_ = loop; 389 delegate.loop_ = loop;
459 ActionProcessor processor; 390 ActionProcessor processor;
460 processor.set_delegate(&delegate); 391 processor.set_delegate(&delegate);
461 processor.EnqueueAction(&action); 392 processor.EnqueueAction(&action);
462 393
463 g_timeout_add(0, &TerminateTransferTestStarter, &processor); 394 g_timeout_add(0, &TerminateTransferTestStarter, &processor);
464 g_main_loop_run(loop); 395 g_main_loop_run(loop);
465 g_main_loop_unref(loop); 396 g_main_loop_unref(loop);
466 } 397 }
467 398
468 TEST(OmahaRequestActionTest, XmlEncodeTest) { 399 TEST(OmahaRequestActionTest, XmlEncodeTest) {
469 EXPECT_EQ("ab", XmlEncode("ab")); 400 EXPECT_EQ("ab", XmlEncode("ab"));
470 EXPECT_EQ("a&lt;b", XmlEncode("a<b")); 401 EXPECT_EQ("a&lt;b", XmlEncode("a<b"));
471 EXPECT_EQ("foo-&#x3A9;", XmlEncode("foo-\xce\xa9")); 402 EXPECT_EQ("foo-&#x3A9;", XmlEncode("foo-\xce\xa9"));
472 EXPECT_EQ("&lt;&amp;&gt;", XmlEncode("<&>")); 403 EXPECT_EQ("&lt;&amp;&gt;", XmlEncode("<&>"));
473 EXPECT_EQ("&amp;lt;&amp;amp;&amp;gt;", XmlEncode("&lt;&amp;&gt;")); 404 EXPECT_EQ("&amp;lt;&amp;amp;&amp;gt;", XmlEncode("&lt;&amp;&gt;"));
474 405
475 vector<char> post_data; 406 vector<char> post_data;
476 407
477 // Make sure XML Encode is being called on the params 408 // Make sure XML Encode is being called on the params
478 OmahaRequestParams params("testthemachine<id", 409 OmahaRequestParams params("testthemachine<id",
479 "testtheuser_id&lt;", 410 "testtheuser_id&lt;",
480 OmahaRequestParams::kOsPlatform, 411 OmahaRequestParams::kOsPlatform,
481 OmahaRequestParams::kOsVersion, 412 OmahaRequestParams::kOsVersion,
482 "testtheservice_pack>", 413 "testtheservice_pack>",
483 "x86 generic", 414 "x86 generic<id",
484 OmahaRequestParams::kAppId, 415 OmahaRequestParams::kAppId,
485 "0.1.0.0", 416 "0.1.0.0",
486 "en-US", 417 "en-US",
487 "unittest_track", 418 "unittest_track&lt;",
488 false, // delta okay 419 false, // delta okay
489 "http://url"); 420 "http://url");
490 OmahaResponse response; 421 OmahaResponse response;
491 ASSERT_FALSE( 422 ASSERT_FALSE(
492 TestUpdateCheck(params, 423 TestUpdateCheck(NULL, // prefs
424 params,
493 "invalid xml>", 425 "invalid xml>",
494 kActionCodeError, 426 kActionCodeError,
495 &response, 427 &response,
496 &post_data)); 428 &post_data));
497 // convert post_data to string 429 // convert post_data to string
498 string post_str(&post_data[0], post_data.size()); 430 string post_str(&post_data[0], post_data.size());
499 EXPECT_NE(post_str.find("testthemachine&lt;id"), string::npos);
500 EXPECT_EQ(post_str.find("testthemachine<id"), string::npos);
501 EXPECT_NE(post_str.find("testtheuser_id&amp;lt;"), string::npos);
502 EXPECT_EQ(post_str.find("testtheuser_id&lt;"), string::npos);
503 EXPECT_NE(post_str.find("testtheservice_pack&gt;"), string::npos); 431 EXPECT_NE(post_str.find("testtheservice_pack&gt;"), string::npos);
504 EXPECT_EQ(post_str.find("testtheservice_pack>"), string::npos); 432 EXPECT_EQ(post_str.find("testtheservice_pack>"), string::npos);
505 EXPECT_NE(post_str.find("x86 generic"), string::npos); 433 EXPECT_NE(post_str.find("x86 generic&lt;id"), string::npos);
434 EXPECT_EQ(post_str.find("x86 generic<id"), string::npos);
435 EXPECT_NE(post_str.find("unittest_track&amp;lt;"), string::npos);
436 EXPECT_EQ(post_str.find("unittest_track&lt;"), string::npos);
506 } 437 }
507 438
508 TEST(OmahaRequestActionTest, XmlDecodeTest) { 439 TEST(OmahaRequestActionTest, XmlDecodeTest) {
509 OmahaRequestParams params("machine_id",
510 "user_id",
511 OmahaRequestParams::kOsPlatform,
512 OmahaRequestParams::kOsVersion,
513 "service_pack",
514 "x86-generic",
515 OmahaRequestParams::kAppId,
516 "0.1.0.0",
517 "en-US",
518 "unittest_track",
519 false, // delta okay
520 "http://url");
521 OmahaResponse response; 440 OmahaResponse response;
522 ASSERT_TRUE( 441 ASSERT_TRUE(
523 TestUpdateCheck(params, 442 TestUpdateCheck(NULL, // prefs
443 kDefaultTestParams,
524 GetUpdateResponse(OmahaRequestParams::kAppId, 444 GetUpdateResponse(OmahaRequestParams::kAppId,
525 "1.2.3.4", // version 445 "1.2.3.4", // version
526 "testthe&lt;url", // more info 446 "testthe&lt;url", // more info
527 "true", // prompt 447 "true", // prompt
528 "testthe&amp;codebase", // dl url 448 "testthe&amp;codebase", // dl url
529 "HASH1234=", // checksum 449 "HASH1234=", // checksum
530 "false", // needs admin 450 "false", // needs admin
531 "123"), // size 451 "123"), // size
532 kActionCodeSuccess, 452 kActionCodeSuccess,
533 &response, 453 &response,
534 NULL)); 454 NULL));
535 455
536 EXPECT_EQ(response.more_info_url, "testthe<url"); 456 EXPECT_EQ(response.more_info_url, "testthe<url");
537 EXPECT_EQ(response.codebase, "testthe&codebase"); 457 EXPECT_EQ(response.codebase, "testthe&codebase");
538 } 458 }
539 459
540 TEST(OmahaRequestActionTest, ParseIntTest) { 460 TEST(OmahaRequestActionTest, ParseIntTest) {
541 OmahaRequestParams params("machine_id",
542 "user_id",
543 OmahaRequestParams::kOsPlatform,
544 OmahaRequestParams::kOsVersion,
545 "service_pack",
546 "the_board",
547 OmahaRequestParams::kAppId,
548 "0.1.0.0",
549 "en-US",
550 "unittest_track",
551 false, // delta okay
552 "http://url");
553 OmahaResponse response; 461 OmahaResponse response;
554 ASSERT_TRUE( 462 ASSERT_TRUE(
555 TestUpdateCheck(params, 463 TestUpdateCheck(NULL, // prefs
464 kDefaultTestParams,
556 GetUpdateResponse(OmahaRequestParams::kAppId, 465 GetUpdateResponse(OmahaRequestParams::kAppId,
557 "1.2.3.4", // version 466 "1.2.3.4", // version
558 "theurl", // more info 467 "theurl", // more info
559 "true", // prompt 468 "true", // prompt
560 "thecodebase", // dl url 469 "thecodebase", // dl url
561 "HASH1234=", // checksum 470 "HASH1234=", // checksum
562 "false", // needs admin 471 "false", // needs admin
563 // overflows int32: 472 // overflows int32:
564 "123123123123123"), // size 473 "123123123123123"), // size
565 kActionCodeSuccess, 474 kActionCodeSuccess,
566 &response, 475 &response,
567 NULL)); 476 NULL));
568 477
569 EXPECT_EQ(response.size, 123123123123123ll); 478 EXPECT_EQ(response.size, 123123123123123ll);
570 } 479 }
571 480
572 TEST(OmahaRequestActionTest, FormatUpdateCheckOutputTest) { 481 TEST(OmahaRequestActionTest, FormatUpdateCheckOutputTest) {
573 vector<char> post_data; 482 vector<char> post_data;
574 OmahaRequestParams params("machine_id", 483 ASSERT_FALSE(TestUpdateCheck(NULL, // prefs
575 "user_id", 484 kDefaultTestParams,
576 OmahaRequestParams::kOsPlatform,
577 OmahaRequestParams::kOsVersion,
578 "service_pack",
579 "x86-generic",
580 OmahaRequestParams::kAppId,
581 "0.1.0.0",
582 "en-US",
583 "unittest_track",
584 false, // delta okay
585 "http://url");
586 OmahaResponse response;
587 ASSERT_FALSE(TestUpdateCheck(params,
588 "invalid xml>", 485 "invalid xml>",
589 kActionCodeError, 486 kActionCodeError,
590 &response, 487 NULL, // response
591 &post_data)); 488 &post_data));
592 // convert post_data to string 489 // convert post_data to string
593 string post_str(&post_data[0], post_data.size()); 490 string post_str(&post_data[0], post_data.size());
594 EXPECT_NE(post_str.find(" <o:ping active=\"0\"></o:ping>\n" 491 EXPECT_NE(post_str.find(" <o:ping a=\"-1\" r=\"-1\"></o:ping>\n"
595 " <o:updatecheck></o:updatecheck>\n"), 492 " <o:updatecheck></o:updatecheck>\n"),
596 string::npos); 493 string::npos);
597 EXPECT_EQ(post_str.find("o:event"), string::npos); 494 EXPECT_EQ(post_str.find("o:event"), string::npos);
598 } 495 }
599 496
600 TEST(OmahaRequestActionTest, FormatSuccessEventOutputTest) { 497 TEST(OmahaRequestActionTest, FormatSuccessEventOutputTest) {
601 vector<char> post_data; 498 vector<char> post_data;
602 OmahaRequestParams params("machine_id", 499 TestEvent(kDefaultTestParams,
603 "user_id",
604 OmahaRequestParams::kOsPlatform,
605 OmahaRequestParams::kOsVersion,
606 "service_pack",
607 "x86-generic",
608 OmahaRequestParams::kAppId,
609 "0.1.0.0",
610 "en-US",
611 "unittest_track",
612 false, // delta okay
613 "http://url");
614 TestEvent(params,
615 new OmahaEvent(OmahaEvent::kTypeUpdateDownloadStarted), 500 new OmahaEvent(OmahaEvent::kTypeUpdateDownloadStarted),
616 "invalid xml>", 501 "invalid xml>",
617 &post_data); 502 &post_data);
618 // convert post_data to string 503 // convert post_data to string
619 string post_str(&post_data[0], post_data.size()); 504 string post_str(&post_data[0], post_data.size());
620 string expected_event = StringPrintf( 505 string expected_event = StringPrintf(
621 " <o:event eventtype=\"%d\" eventresult=\"%d\"></o:event>\n", 506 " <o:event eventtype=\"%d\" eventresult=\"%d\"></o:event>\n",
622 OmahaEvent::kTypeUpdateDownloadStarted, 507 OmahaEvent::kTypeUpdateDownloadStarted,
623 OmahaEvent::kResultSuccess); 508 OmahaEvent::kResultSuccess);
624 EXPECT_NE(post_str.find(expected_event), string::npos); 509 EXPECT_NE(post_str.find(expected_event), string::npos);
510 EXPECT_EQ(post_str.find("o:ping"), string::npos);
625 EXPECT_EQ(post_str.find("o:updatecheck"), string::npos); 511 EXPECT_EQ(post_str.find("o:updatecheck"), string::npos);
626 } 512 }
627 513
628 TEST(OmahaRequestActionTest, FormatErrorEventOutputTest) { 514 TEST(OmahaRequestActionTest, FormatErrorEventOutputTest) {
629 vector<char> post_data; 515 vector<char> post_data;
630 OmahaRequestParams params("machine_id", 516 TestEvent(kDefaultTestParams,
631 "user_id",
632 OmahaRequestParams::kOsPlatform,
633 OmahaRequestParams::kOsVersion,
634 "service_pack",
635 "x86-generic",
636 OmahaRequestParams::kAppId,
637 "0.1.0.0",
638 "en-US",
639 "unittest_track",
640 false, // delta okay
641 "http://url");
642 TestEvent(params,
643 new OmahaEvent(OmahaEvent::kTypeDownloadComplete, 517 new OmahaEvent(OmahaEvent::kTypeDownloadComplete,
644 OmahaEvent::kResultError, 518 OmahaEvent::kResultError,
645 kActionCodeError), 519 kActionCodeError),
646 "invalid xml>", 520 "invalid xml>",
647 &post_data); 521 &post_data);
648 // convert post_data to string 522 // convert post_data to string
649 string post_str(&post_data[0], post_data.size()); 523 string post_str(&post_data[0], post_data.size());
650 string expected_event = StringPrintf( 524 string expected_event = StringPrintf(
651 " <o:event eventtype=\"%d\" eventresult=\"%d\" " 525 " <o:event eventtype=\"%d\" eventresult=\"%d\" "
652 "errorcode=\"%d\"></o:event>\n", 526 "errorcode=\"%d\"></o:event>\n",
653 OmahaEvent::kTypeDownloadComplete, 527 OmahaEvent::kTypeDownloadComplete,
654 OmahaEvent::kResultError, 528 OmahaEvent::kResultError,
655 kActionCodeError); 529 kActionCodeError);
656 EXPECT_NE(post_str.find(expected_event), string::npos); 530 EXPECT_NE(post_str.find(expected_event), string::npos);
657 EXPECT_EQ(post_str.find("o:updatecheck"), string::npos); 531 EXPECT_EQ(post_str.find("o:updatecheck"), string::npos);
658 } 532 }
659 533
660 TEST(OmahaRequestActionTest, FormatEventOutputTest) { 534 TEST(OmahaRequestActionTest, FormatEventOutputTest) {
661 vector<char> post_data; 535 vector<char> post_data;
662 OmahaRequestParams params("machine_id", 536 TestEvent(kDefaultTestParams,
663 "user_id",
664 OmahaRequestParams::kOsPlatform,
665 OmahaRequestParams::kOsVersion,
666 "service_pack",
667 "x86-generic",
668 OmahaRequestParams::kAppId,
669 "0.1.0.0",
670 "en-US",
671 "unittest_track",
672 false, // delta okay
673 "http://url");
674 TestEvent(params,
675 new OmahaEvent(OmahaEvent::kTypeDownloadComplete, 537 new OmahaEvent(OmahaEvent::kTypeDownloadComplete,
676 OmahaEvent::kResultError, 538 OmahaEvent::kResultError,
677 kActionCodeError), 539 kActionCodeError),
678 "invalid xml>", 540 "invalid xml>",
679 &post_data); 541 &post_data);
680 // convert post_data to string 542 // convert post_data to string
681 string post_str(&post_data[0], post_data.size()); 543 string post_str(&post_data[0], post_data.size());
682 string expected_event = StringPrintf( 544 string expected_event = StringPrintf(
683 " <o:event eventtype=\"%d\" eventresult=\"%d\" " 545 " <o:event eventtype=\"%d\" eventresult=\"%d\" "
684 "errorcode=\"%d\"></o:event>\n", 546 "errorcode=\"%d\"></o:event>\n",
685 OmahaEvent::kTypeDownloadComplete, 547 OmahaEvent::kTypeDownloadComplete,
686 OmahaEvent::kResultError, 548 OmahaEvent::kResultError,
687 kActionCodeError); 549 kActionCodeError);
688 EXPECT_NE(post_str.find(expected_event), string::npos); 550 EXPECT_NE(post_str.find(expected_event), string::npos);
689 EXPECT_EQ(post_str.find("o:updatecheck"), string::npos); 551 EXPECT_EQ(post_str.find("o:updatecheck"), string::npos);
690 } 552 }
691 553
692 TEST(OmahaRequestActionTest, IsEventTest) { 554 TEST(OmahaRequestActionTest, IsEventTest) {
693 string http_response("doesn't matter"); 555 string http_response("doesn't matter");
694 OmahaRequestParams params("machine_id", 556 PrefsMock prefs;
695 "user_id",
696 OmahaRequestParams::kOsPlatform,
697 OmahaRequestParams::kOsVersion,
698 "service_pack",
699 "x86-generic",
700 OmahaRequestParams::kAppId,
701 "0.1.0.0",
702 "en-US",
703 "unittest_track",
704 false, // delta okay
705 "http://url");
706
707 OmahaRequestAction update_check_action( 557 OmahaRequestAction update_check_action(
708 params, 558 &prefs,
559 kDefaultTestParams,
709 NULL, 560 NULL,
710 new MockHttpFetcher(http_response.data(), 561 new MockHttpFetcher(http_response.data(),
711 http_response.size())); 562 http_response.size()));
712 EXPECT_FALSE(update_check_action.IsEvent()); 563 EXPECT_FALSE(update_check_action.IsEvent());
713 564
714 OmahaRequestAction event_action( 565 OmahaRequestAction event_action(
715 params, 566 &prefs,
567 kDefaultTestParams,
716 new OmahaEvent(OmahaEvent::kTypeUpdateComplete), 568 new OmahaEvent(OmahaEvent::kTypeUpdateComplete),
717 new MockHttpFetcher(http_response.data(), 569 new MockHttpFetcher(http_response.data(),
718 http_response.size())); 570 http_response.size()));
719 EXPECT_TRUE(event_action.IsEvent()); 571 EXPECT_TRUE(event_action.IsEvent());
720 } 572 }
721 573
722 TEST(OmahaRequestActionTest, FormatDeltaOkayOutputTest) { 574 TEST(OmahaRequestActionTest, FormatDeltaOkayOutputTest) {
723 for (int i = 0; i < 2; i++) { 575 for (int i = 0; i < 2; i++) {
724 bool delta_okay = i == 1; 576 bool delta_okay = i == 1;
725 const char* delta_okay_str = delta_okay ? "true" : "false"; 577 const char* delta_okay_str = delta_okay ? "true" : "false";
726 vector<char> post_data; 578 vector<char> post_data;
727 OmahaRequestParams params("machine_id", 579 OmahaRequestParams params("machine_id",
728 "user_id", 580 "user_id",
729 OmahaRequestParams::kOsPlatform, 581 OmahaRequestParams::kOsPlatform,
730 OmahaRequestParams::kOsVersion, 582 OmahaRequestParams::kOsVersion,
731 "service_pack", 583 "service_pack",
732 "x86-generic", 584 "x86-generic",
733 OmahaRequestParams::kAppId, 585 OmahaRequestParams::kAppId,
734 "0.1.0.0", 586 "0.1.0.0",
735 "en-US", 587 "en-US",
736 "unittest_track", 588 "unittest_track",
737 delta_okay, 589 delta_okay,
738 "http://url"); 590 "http://url");
739 ASSERT_FALSE(TestUpdateCheck(params, 591 ASSERT_FALSE(TestUpdateCheck(NULL, // prefs
592 params,
740 "invalid xml>", 593 "invalid xml>",
741 kActionCodeError, 594 kActionCodeError,
742 NULL, 595 NULL,
743 &post_data)); 596 &post_data));
744 // convert post_data to string 597 // convert post_data to string
745 string post_str(&post_data[0], post_data.size()); 598 string post_str(&post_data[0], post_data.size());
746 EXPECT_NE(post_str.find(StringPrintf(" delta_okay=\"%s\"", delta_okay_str)), 599 EXPECT_NE(post_str.find(StringPrintf(" delta_okay=\"%s\"", delta_okay_str)),
747 string::npos) 600 string::npos)
748 << "i = " << i; 601 << "i = " << i;
749 } 602 }
(...skipping 11 matching lines...) Expand all
761 EXPECT_EQ(kActionCodeSuccess, success_event.error_code); 614 EXPECT_EQ(kActionCodeSuccess, success_event.error_code);
762 615
763 OmahaEvent error_event(OmahaEvent::kTypeUpdateDownloadFinished, 616 OmahaEvent error_event(OmahaEvent::kTypeUpdateDownloadFinished,
764 OmahaEvent::kResultError, 617 OmahaEvent::kResultError,
765 kActionCodeError); 618 kActionCodeError);
766 EXPECT_EQ(OmahaEvent::kTypeUpdateDownloadFinished, error_event.type); 619 EXPECT_EQ(OmahaEvent::kTypeUpdateDownloadFinished, error_event.type);
767 EXPECT_EQ(OmahaEvent::kResultError, error_event.result); 620 EXPECT_EQ(OmahaEvent::kResultError, error_event.result);
768 EXPECT_EQ(kActionCodeError, error_event.error_code); 621 EXPECT_EQ(kActionCodeError, error_event.error_code);
769 } 622 }
770 623
624 TEST(OmahaRequestActionTest, PingTest) {
625 PrefsMock prefs;
626 // Add a few hours to the day difference to test no rounding, etc.
627 int64_t five_days_ago =
628 (Time::Now() - TimeDelta::FromHours(5 * 24 + 13)).ToInternalValue();
629 int64_t six_days_ago =
630 (Time::Now() - TimeDelta::FromHours(6 * 24 + 11)).ToInternalValue();
631 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _))
632 .WillOnce(DoAll(SetArgumentPointee<1>(six_days_ago), Return(true)));
633 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _))
634 .WillOnce(DoAll(SetArgumentPointee<1>(five_days_ago), Return(true)));
635 vector<char> post_data;
636 ASSERT_TRUE(
637 TestUpdateCheck(&prefs,
638 kDefaultTestParams,
639 GetNoUpdateResponse(OmahaRequestParams::kAppId),
640 kActionCodeSuccess,
641 NULL,
642 &post_data));
643 string post_str(&post_data[0], post_data.size());
644 EXPECT_NE(post_str.find("<o:ping a=\"6\" r=\"5\"></o:ping>"), string::npos);
645 }
646
647 TEST(OmahaRequestActionTest, ActivePingTest) {
648 PrefsMock prefs;
649 int64_t three_days_ago =
650 (Time::Now() - TimeDelta::FromHours(3 * 24 + 12)).ToInternalValue();
651 int64_t now = Time::Now().ToInternalValue();
652 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _))
653 .WillOnce(DoAll(SetArgumentPointee<1>(three_days_ago), Return(true)));
654 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _))
655 .WillOnce(DoAll(SetArgumentPointee<1>(now), Return(true)));
656 vector<char> post_data;
657 ASSERT_TRUE(
658 TestUpdateCheck(&prefs,
659 kDefaultTestParams,
660 GetNoUpdateResponse(OmahaRequestParams::kAppId),
661 kActionCodeSuccess,
662 NULL,
663 &post_data));
664 string post_str(&post_data[0], post_data.size());
665 EXPECT_NE(post_str.find("<o:ping a=\"3\"></o:ping>"), string::npos);
666 }
667
668 TEST(OmahaRequestActionTest, RollCallPingTest) {
669 PrefsMock prefs;
670 int64_t four_days_ago =
671 (Time::Now() - TimeDelta::FromHours(4 * 24)).ToInternalValue();
672 int64_t now = Time::Now().ToInternalValue();
673 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _))
674 .WillOnce(DoAll(SetArgumentPointee<1>(now), Return(true)));
675 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _))
676 .WillOnce(DoAll(SetArgumentPointee<1>(four_days_ago), Return(true)));
677 vector<char> post_data;
678 ASSERT_TRUE(
679 TestUpdateCheck(&prefs,
680 kDefaultTestParams,
681 GetNoUpdateResponse(OmahaRequestParams::kAppId),
682 kActionCodeSuccess,
683 NULL,
684 &post_data));
685 string post_str(&post_data[0], post_data.size());
686 EXPECT_NE(post_str.find("<o:ping r=\"4\"></o:ping>\n"), string::npos);
687 }
688
689 TEST(OmahaRequestActionTest, NoPingTest) {
690 PrefsMock prefs;
691 int64_t one_hour_ago =
692 (Time::Now() - TimeDelta::FromHours(1)).ToInternalValue();
693 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _))
694 .WillOnce(DoAll(SetArgumentPointee<1>(one_hour_ago), Return(true)));
695 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _))
696 .WillOnce(DoAll(SetArgumentPointee<1>(one_hour_ago), Return(true)));
697 EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)).Times(0);
698 EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)).Times(0);
699 vector<char> post_data;
700 ASSERT_TRUE(
701 TestUpdateCheck(&prefs,
702 kDefaultTestParams,
703 GetNoUpdateResponse(OmahaRequestParams::kAppId),
704 kActionCodeSuccess,
705 NULL,
706 &post_data));
707 string post_str(&post_data[0], post_data.size());
708 EXPECT_EQ(post_str.find("o:ping"), string::npos);
709 }
710
711 TEST(OmahaRequestActionTest, BackInTimePingTest) {
712 PrefsMock prefs;
713 int64_t future =
714 (Time::Now() + TimeDelta::FromHours(3 * 24 + 4)).ToInternalValue();
715 EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _))
716 .WillOnce(DoAll(SetArgumentPointee<1>(future), Return(true)));
717 EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _))
718 .WillOnce(DoAll(SetArgumentPointee<1>(future), Return(true)));
719 EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _))
720 .WillOnce(Return(true));
721 EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _))
722 .WillOnce(Return(true));
723 vector<char> post_data;
724 ASSERT_TRUE(
725 TestUpdateCheck(&prefs,
726 kDefaultTestParams,
727 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate "
728 "xmlns=\"http://www.google.com/update2/response\" "
729 "protocol=\"2.0\"><daystart elapsed_seconds=\"100\"/>"
730 "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>"
731 "<updatecheck status=\"noupdate\"/></app></gupdate>",
732 kActionCodeSuccess,
733 NULL,
734 &post_data));
735 string post_str(&post_data[0], post_data.size());
736 EXPECT_EQ(post_str.find("o:ping"), string::npos);
737 }
738
739 TEST(OmahaRequestActionTest, LastPingDayUpdateTest) {
740 // This test checks that the action updates the last ping day to now
741 // minus 200 seconds with a slack for 5 seconds. Therefore, the test
742 // may fail if it runs for longer than 5 seconds. It shouldn't run
743 // that long though.
744 int64_t midnight =
745 (Time::Now() - TimeDelta::FromSeconds(200)).ToInternalValue();
746 int64_t midnight_slack =
747 (Time::Now() - TimeDelta::FromSeconds(195)).ToInternalValue();
748 PrefsMock prefs;
749 EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay,
750 AllOf(Ge(midnight), Le(midnight_slack))))
751 .WillOnce(Return(true));
752 EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay,
753 AllOf(Ge(midnight), Le(midnight_slack))))
754 .WillOnce(Return(true));
755 ASSERT_TRUE(
756 TestUpdateCheck(&prefs,
757 kDefaultTestParams,
758 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate "
759 "xmlns=\"http://www.google.com/update2/response\" "
760 "protocol=\"2.0\"><daystart elapsed_seconds=\"200\"/>"
761 "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>"
762 "<updatecheck status=\"noupdate\"/></app></gupdate>",
763 kActionCodeSuccess,
764 NULL,
765 NULL));
766 }
767
768 TEST(OmahaRequestActionTest, NoElapsedSecondsTest) {
769 PrefsMock prefs;
770 EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)).Times(0);
771 EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)).Times(0);
772 ASSERT_TRUE(
773 TestUpdateCheck(&prefs,
774 kDefaultTestParams,
775 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate "
776 "xmlns=\"http://www.google.com/update2/response\" "
777 "protocol=\"2.0\"><daystart blah=\"200\"/>"
778 "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>"
779 "<updatecheck status=\"noupdate\"/></app></gupdate>",
780 kActionCodeSuccess,
781 NULL,
782 NULL));
783 }
784
785 TEST(OmahaRequestActionTest, BadElapsedSecondsTest) {
786 PrefsMock prefs;
787 EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)).Times(0);
788 EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)).Times(0);
789 ASSERT_TRUE(
790 TestUpdateCheck(&prefs,
791 kDefaultTestParams,
792 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate "
793 "xmlns=\"http://www.google.com/update2/response\" "
794 "protocol=\"2.0\"><daystart elapsed_seconds=\"x\"/>"
795 "<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>"
796 "<updatecheck status=\"noupdate\"/></app></gupdate>",
797 kActionCodeSuccess,
798 NULL,
799 NULL));
800 }
801
771 } // namespace chromeos_update_engine 802 } // namespace chromeos_update_engine
OLDNEW
« omaha_request_action.h ('K') | « omaha_request_action.cc ('k') | prefs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698