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

Side by Side Diff: src/platform/update_engine/update_check_action_unittest.cc

Issue 1881001: AU: Many minor cleanup changes (Closed) Base URL: ssh://git@chromiumos-git/chromeos
Patch Set: fixes for review Created 10 years, 7 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
« no previous file with comments | « src/platform/update_engine/update_check_action.cc ('k') | src/platform/update_engine/utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2009 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 #include <glib.h> 7 #include <glib.h>
8 #include <gtest/gtest.h> 8 #include <gtest/gtest.h>
9 #include "update_engine/action_pipe.h" 9 #include "update_engine/action_pipe.h"
10 #include "update_engine/update_check_action.h" 10 #include "update_engine/update_check_action.h"
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 155
156 TEST(UpdateCheckActionTest, NoUpdateTest) { 156 TEST(UpdateCheckActionTest, NoUpdateTest) {
157 UpdateCheckParams params("", // machine_id 157 UpdateCheckParams params("", // machine_id
158 "", // user_id 158 "", // user_id
159 UpdateCheckParams::kOsPlatform, 159 UpdateCheckParams::kOsPlatform,
160 UpdateCheckParams::kOsVersion, 160 UpdateCheckParams::kOsVersion,
161 "", // os_sp 161 "", // os_sp
162 UpdateCheckParams::kAppId, 162 UpdateCheckParams::kAppId,
163 "0.1.0.0", 163 "0.1.0.0",
164 "en-US", 164 "en-US",
165 "unittest"); 165 "unittest",
166 ""); // url
166 UpdateCheckResponse response; 167 UpdateCheckResponse response;
167 ASSERT_TRUE( 168 ASSERT_TRUE(
168 TestUpdateCheckAction(params, 169 TestUpdateCheckAction(params,
169 GetNoUpdateResponse(UpdateCheckParams::kAppId), 170 GetNoUpdateResponse(UpdateCheckParams::kAppId),
170 true, 171 true,
171 &response, 172 &response,
172 NULL)); 173 NULL));
173 EXPECT_FALSE(response.update_exists); 174 EXPECT_FALSE(response.update_exists);
174 } 175 }
175 176
176 TEST(UpdateCheckActionTest, ValidUpdateTest) { 177 TEST(UpdateCheckActionTest, ValidUpdateTest) {
177 UpdateCheckParams params("machine_id", 178 UpdateCheckParams params("machine_id",
178 "user_id", 179 "user_id",
179 UpdateCheckParams::kOsPlatform, 180 UpdateCheckParams::kOsPlatform,
180 UpdateCheckParams::kOsVersion, 181 UpdateCheckParams::kOsVersion,
181 "service_pack", 182 "service_pack",
182 UpdateCheckParams::kAppId, 183 UpdateCheckParams::kAppId,
183 "0.1.0.0", 184 "0.1.0.0",
184 "en-US", 185 "en-US",
185 "unittest_track"); 186 "unittest_track",
187 ""); // url
186 UpdateCheckResponse response; 188 UpdateCheckResponse response;
187 ASSERT_TRUE( 189 ASSERT_TRUE(
188 TestUpdateCheckAction(params, 190 TestUpdateCheckAction(params,
189 GetUpdateResponse(UpdateCheckParams::kAppId, 191 GetUpdateResponse(UpdateCheckParams::kAppId,
190 "1.2.3.4", // version 192 "1.2.3.4", // version
191 "http://more/info", 193 "http://more/info",
192 "true", // prompt 194 "true", // prompt
193 "http://code/base", // dl url 195 "http://code/base", // dl url
194 "HASH1234=", // checksum 196 "HASH1234=", // checksum
195 "false", // needs admin 197 "false", // needs admin
(...skipping 13 matching lines...) Expand all
209 211
210 TEST(UpdateCheckActionTest, NoOutputPipeTest) { 212 TEST(UpdateCheckActionTest, NoOutputPipeTest) {
211 UpdateCheckParams params("", // machine_id 213 UpdateCheckParams params("", // machine_id
212 "", // usr_id 214 "", // usr_id
213 UpdateCheckParams::kOsPlatform, 215 UpdateCheckParams::kOsPlatform,
214 UpdateCheckParams::kOsVersion, 216 UpdateCheckParams::kOsVersion,
215 "", // os_sp 217 "", // os_sp
216 UpdateCheckParams::kAppId, 218 UpdateCheckParams::kAppId,
217 "0.1.0.0", 219 "0.1.0.0",
218 "en-US", 220 "en-US",
219 "unittest"); 221 "unittest",
222 ""); // url
220 const string http_response(GetNoUpdateResponse(UpdateCheckParams::kAppId)); 223 const string http_response(GetNoUpdateResponse(UpdateCheckParams::kAppId));
221 224
222 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); 225 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE);
223 226
224 ObjectFeederAction<UpdateCheckParams> feeder_action; 227 ObjectFeederAction<UpdateCheckParams> feeder_action;
225 feeder_action.set_obj(params); 228 feeder_action.set_obj(params);
226 UpdateCheckAction action(new MockHttpFetcher(http_response.data(), 229 UpdateCheckAction action(new MockHttpFetcher(http_response.data(),
227 http_response.size())); 230 http_response.size()));
228 UpdateCheckActionTestProcessorDelegate delegate; 231 UpdateCheckActionTestProcessorDelegate delegate;
229 delegate.loop_ = loop; 232 delegate.loop_ = loop;
(...skipping 11 matching lines...) Expand all
241 244
242 TEST(UpdateCheckActionTest, InvalidXmlTest) { 245 TEST(UpdateCheckActionTest, InvalidXmlTest) {
243 UpdateCheckParams params("machine_id", 246 UpdateCheckParams params("machine_id",
244 "user_id", 247 "user_id",
245 UpdateCheckParams::kOsPlatform, 248 UpdateCheckParams::kOsPlatform,
246 UpdateCheckParams::kOsVersion, 249 UpdateCheckParams::kOsVersion,
247 "service_pack", 250 "service_pack",
248 UpdateCheckParams::kAppId, 251 UpdateCheckParams::kAppId,
249 "0.1.0.0", 252 "0.1.0.0",
250 "en-US", 253 "en-US",
251 "unittest_track"); 254 "unittest_track",
255 "http://url");
252 UpdateCheckResponse response; 256 UpdateCheckResponse response;
253 ASSERT_FALSE( 257 ASSERT_FALSE(
254 TestUpdateCheckAction(params, 258 TestUpdateCheckAction(params,
255 "invalid xml>", 259 "invalid xml>",
256 false, 260 false,
257 &response, 261 &response,
258 NULL)); 262 NULL));
259 EXPECT_FALSE(response.update_exists); 263 EXPECT_FALSE(response.update_exists);
260 } 264 }
261 265
262 TEST(UpdateCheckActionTest, MissingStatusTest) { 266 TEST(UpdateCheckActionTest, MissingStatusTest) {
263 UpdateCheckParams params("machine_id", 267 UpdateCheckParams params("machine_id",
264 "user_id", 268 "user_id",
265 UpdateCheckParams::kOsPlatform, 269 UpdateCheckParams::kOsPlatform,
266 UpdateCheckParams::kOsVersion, 270 UpdateCheckParams::kOsVersion,
267 "service_pack", 271 "service_pack",
268 UpdateCheckParams::kAppId, 272 UpdateCheckParams::kAppId,
269 "0.1.0.0", 273 "0.1.0.0",
270 "en-US", 274 "en-US",
271 "unittest_track"); 275 "unittest_track",
276 "http://url");
272 UpdateCheckResponse response; 277 UpdateCheckResponse response;
273 ASSERT_FALSE(TestUpdateCheckAction( 278 ASSERT_FALSE(TestUpdateCheckAction(
274 params, 279 params,
275 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " 280 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate "
276 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " 281 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app "
277 "appid=\"foo\" status=\"ok\"><ping " 282 "appid=\"foo\" status=\"ok\"><ping "
278 "status=\"ok\"/><updatecheck/></app></gupdate>", 283 "status=\"ok\"/><updatecheck/></app></gupdate>",
279 false, 284 false,
280 &response, 285 &response,
281 NULL)); 286 NULL));
282 EXPECT_FALSE(response.update_exists); 287 EXPECT_FALSE(response.update_exists);
283 } 288 }
284 289
285 TEST(UpdateCheckActionTest, InvalidStatusTest) { 290 TEST(UpdateCheckActionTest, InvalidStatusTest) {
286 UpdateCheckParams params("machine_id", 291 UpdateCheckParams params("machine_id",
287 "user_id", 292 "user_id",
288 UpdateCheckParams::kOsPlatform, 293 UpdateCheckParams::kOsPlatform,
289 UpdateCheckParams::kOsVersion, 294 UpdateCheckParams::kOsVersion,
290 "service_pack", 295 "service_pack",
291 UpdateCheckParams::kAppId, 296 UpdateCheckParams::kAppId,
292 "0.1.0.0", 297 "0.1.0.0",
293 "en-US", 298 "en-US",
294 "unittest_track"); 299 "unittest_track",
300 "http://url");
295 UpdateCheckResponse response; 301 UpdateCheckResponse response;
296 ASSERT_FALSE(TestUpdateCheckAction( 302 ASSERT_FALSE(TestUpdateCheckAction(
297 params, 303 params,
298 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " 304 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate "
299 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " 305 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app "
300 "appid=\"foo\" status=\"ok\"><ping " 306 "appid=\"foo\" status=\"ok\"><ping "
301 "status=\"ok\"/><updatecheck status=\"foo\"/></app></gupdate>", 307 "status=\"ok\"/><updatecheck status=\"foo\"/></app></gupdate>",
302 false, 308 false,
303 &response, 309 &response,
304 NULL)); 310 NULL));
305 EXPECT_FALSE(response.update_exists); 311 EXPECT_FALSE(response.update_exists);
306 } 312 }
307 313
308 TEST(UpdateCheckActionTest, MissingNodesetTest) { 314 TEST(UpdateCheckActionTest, MissingNodesetTest) {
309 UpdateCheckParams params("machine_id", 315 UpdateCheckParams params("machine_id",
310 "user_id", 316 "user_id",
311 UpdateCheckParams::kOsPlatform, 317 UpdateCheckParams::kOsPlatform,
312 UpdateCheckParams::kOsVersion, 318 UpdateCheckParams::kOsVersion,
313 "service_pack", 319 "service_pack",
314 UpdateCheckParams::kAppId, 320 UpdateCheckParams::kAppId,
315 "0.1.0.0", 321 "0.1.0.0",
316 "en-US", 322 "en-US",
317 "unittest_track"); 323 "unittest_track",
324 "http://url");
318 UpdateCheckResponse response; 325 UpdateCheckResponse response;
319 ASSERT_FALSE(TestUpdateCheckAction( 326 ASSERT_FALSE(TestUpdateCheckAction(
320 params, 327 params,
321 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " 328 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate "
322 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " 329 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app "
323 "appid=\"foo\" status=\"ok\"><ping " 330 "appid=\"foo\" status=\"ok\"><ping "
324 "status=\"ok\"/></app></gupdate>", 331 "status=\"ok\"/></app></gupdate>",
325 false, 332 false,
326 &response, 333 &response,
327 NULL)); 334 NULL));
328 EXPECT_FALSE(response.update_exists); 335 EXPECT_FALSE(response.update_exists);
329 } 336 }
330 337
331 TEST(UpdateCheckActionTest, MissingFieldTest) { 338 TEST(UpdateCheckActionTest, MissingFieldTest) {
332 UpdateCheckParams params("machine_id", 339 UpdateCheckParams params("machine_id",
333 "user_id", 340 "user_id",
334 UpdateCheckParams::kOsPlatform, 341 UpdateCheckParams::kOsPlatform,
335 UpdateCheckParams::kOsVersion, 342 UpdateCheckParams::kOsVersion,
336 "service_pack", 343 "service_pack",
337 UpdateCheckParams::kAppId, 344 UpdateCheckParams::kAppId,
338 "0.1.0.0", 345 "0.1.0.0",
339 "en-US", 346 "en-US",
340 "unittest_track"); 347 "unittest_track",
348 "http://url");
341 UpdateCheckResponse response; 349 UpdateCheckResponse response;
342 ASSERT_TRUE(TestUpdateCheckAction(params, 350 ASSERT_TRUE(TestUpdateCheckAction(params,
343 string("<?xml version=\"1.0\" " 351 string("<?xml version=\"1.0\" "
344 "encoding=\"UTF-8\"?><gupdate " 352 "encoding=\"UTF-8\"?><gupdate "
345 "xmlns=\"http://www.google.com/" 353 "xmlns=\"http://www.google.com/"
346 "update2/response\" " 354 "update2/response\" "
347 "protocol=\"2.0\"><app appid=\"") + 355 "protocol=\"2.0\"><app appid=\"") +
348 UpdateCheckParams::kAppId 356 UpdateCheckParams::kAppId
349 + "\" status=\"ok\"><ping " 357 + "\" status=\"ok\"><ping "
350 "status=\"ok\"/><updatecheck " 358 "status=\"ok\"/><updatecheck "
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 396
389 TEST(UpdateCheckActionTest, TerminateTransferTest) { 397 TEST(UpdateCheckActionTest, TerminateTransferTest) {
390 UpdateCheckParams params("", // machine_id 398 UpdateCheckParams params("", // machine_id
391 "", // usr_id 399 "", // usr_id
392 UpdateCheckParams::kOsPlatform, 400 UpdateCheckParams::kOsPlatform,
393 UpdateCheckParams::kOsVersion, 401 UpdateCheckParams::kOsVersion,
394 "", // os_sp 402 "", // os_sp
395 UpdateCheckParams::kAppId, 403 UpdateCheckParams::kAppId,
396 "0.1.0.0", 404 "0.1.0.0",
397 "en-US", 405 "en-US",
398 "unittest"); 406 "unittest",
407 "http://url");
399 string http_response("doesn't matter"); 408 string http_response("doesn't matter");
400 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); 409 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE);
401 410
402 ObjectFeederAction<UpdateCheckParams> feeder_action; 411 ObjectFeederAction<UpdateCheckParams> feeder_action;
403 feeder_action.set_obj(params); 412 feeder_action.set_obj(params);
404 UpdateCheckAction action(new MockHttpFetcher(http_response.data(), 413 UpdateCheckAction action(new MockHttpFetcher(http_response.data(),
405 http_response.size())); 414 http_response.size()));
406 TerminateEarlyTestProcessorDelegate delegate; 415 TerminateEarlyTestProcessorDelegate delegate;
407 delegate.loop_ = loop; 416 delegate.loop_ = loop;
408 ActionProcessor processor; 417 ActionProcessor processor;
(...skipping 18 matching lines...) Expand all
427 436
428 // Make sure XML Encode is being called on the params 437 // Make sure XML Encode is being called on the params
429 UpdateCheckParams params("testthemachine<id", 438 UpdateCheckParams params("testthemachine<id",
430 "testtheuser_id&lt;", 439 "testtheuser_id&lt;",
431 UpdateCheckParams::kOsPlatform, 440 UpdateCheckParams::kOsPlatform,
432 UpdateCheckParams::kOsVersion, 441 UpdateCheckParams::kOsVersion,
433 "testtheservice_pack>", 442 "testtheservice_pack>",
434 UpdateCheckParams::kAppId, 443 UpdateCheckParams::kAppId,
435 "0.1.0.0", 444 "0.1.0.0",
436 "en-US", 445 "en-US",
437 "unittest_track"); 446 "unittest_track",
447 "http://url");
438 UpdateCheckResponse response; 448 UpdateCheckResponse response;
439 ASSERT_FALSE( 449 ASSERT_FALSE(
440 TestUpdateCheckAction(params, 450 TestUpdateCheckAction(params,
441 "invalid xml>", 451 "invalid xml>",
442 false, 452 false,
443 &response, 453 &response,
444 &post_data)); 454 &post_data));
445 // convert post_data to string 455 // convert post_data to string
446 string post_str(&post_data[0], post_data.size()); 456 string post_str(&post_data[0], post_data.size());
447 EXPECT_NE(post_str.find("testthemachine&lt;id"), string::npos); 457 EXPECT_NE(post_str.find("testthemachine&lt;id"), string::npos);
448 EXPECT_EQ(post_str.find("testthemachine<id"), string::npos); 458 EXPECT_EQ(post_str.find("testthemachine<id"), string::npos);
449 EXPECT_NE(post_str.find("testtheuser_id&amp;lt;"), string::npos); 459 EXPECT_NE(post_str.find("testtheuser_id&amp;lt;"), string::npos);
450 EXPECT_EQ(post_str.find("testtheuser_id&lt;"), string::npos); 460 EXPECT_EQ(post_str.find("testtheuser_id&lt;"), string::npos);
451 EXPECT_NE(post_str.find("testtheservice_pack&gt;"), string::npos); 461 EXPECT_NE(post_str.find("testtheservice_pack&gt;"), string::npos);
452 EXPECT_EQ(post_str.find("testtheservice_pack>"), string::npos); 462 EXPECT_EQ(post_str.find("testtheservice_pack>"), string::npos);
453 } 463 }
454 464
455 TEST(UpdateCheckActionTest, XmlDecodeTest) { 465 TEST(UpdateCheckActionTest, XmlDecodeTest) {
456 UpdateCheckParams params("machine_id", 466 UpdateCheckParams params("machine_id",
457 "user_id", 467 "user_id",
458 UpdateCheckParams::kOsPlatform, 468 UpdateCheckParams::kOsPlatform,
459 UpdateCheckParams::kOsVersion, 469 UpdateCheckParams::kOsVersion,
460 "service_pack", 470 "service_pack",
461 UpdateCheckParams::kAppId, 471 UpdateCheckParams::kAppId,
462 "0.1.0.0", 472 "0.1.0.0",
463 "en-US", 473 "en-US",
464 "unittest_track"); 474 "unittest_track",
475 "http://url");
465 UpdateCheckResponse response; 476 UpdateCheckResponse response;
466 ASSERT_TRUE( 477 ASSERT_TRUE(
467 TestUpdateCheckAction(params, 478 TestUpdateCheckAction(params,
468 GetUpdateResponse(UpdateCheckParams::kAppId, 479 GetUpdateResponse(UpdateCheckParams::kAppId,
469 "1.2.3.4", // version 480 "1.2.3.4", // version
470 "testthe&lt;url", // more info 481 "testthe&lt;url", // more info
471 "true", // prompt 482 "true", // prompt
472 "testthe&amp;codebase", // dl url 483 "testthe&amp;codebase", // dl url
473 "HASH1234=", // checksum 484 "HASH1234=", // checksum
474 "false", // needs admin 485 "false", // needs admin
475 "123"), // size 486 "123"), // size
476 true, 487 true,
477 &response, 488 &response,
478 NULL)); 489 NULL));
479 490
480 EXPECT_EQ(response.more_info_url, "testthe<url"); 491 EXPECT_EQ(response.more_info_url, "testthe<url");
481 EXPECT_EQ(response.codebase, "testthe&codebase"); 492 EXPECT_EQ(response.codebase, "testthe&codebase");
482 } 493 }
483 494
484 TEST(UpdateCheckActionTest, ParseIntTest) { 495 TEST(UpdateCheckActionTest, ParseIntTest) {
485 UpdateCheckParams params("machine_id", 496 UpdateCheckParams params("machine_id",
486 "user_id", 497 "user_id",
487 UpdateCheckParams::kOsPlatform, 498 UpdateCheckParams::kOsPlatform,
488 UpdateCheckParams::kOsVersion, 499 UpdateCheckParams::kOsVersion,
489 "service_pack", 500 "service_pack",
490 UpdateCheckParams::kAppId, 501 UpdateCheckParams::kAppId,
491 "0.1.0.0", 502 "0.1.0.0",
492 "en-US", 503 "en-US",
493 "unittest_track"); 504 "unittest_track",
505 "http://url");
494 UpdateCheckResponse response; 506 UpdateCheckResponse response;
495 ASSERT_TRUE( 507 ASSERT_TRUE(
496 TestUpdateCheckAction(params, 508 TestUpdateCheckAction(params,
497 GetUpdateResponse(UpdateCheckParams::kAppId, 509 GetUpdateResponse(UpdateCheckParams::kAppId,
498 "1.2.3.4", // version 510 "1.2.3.4", // version
499 "theurl", // more info 511 "theurl", // more info
500 "true", // prompt 512 "true", // prompt
501 "thecodebase", // dl url 513 "thecodebase", // dl url
502 "HASH1234=", // checksum 514 "HASH1234=", // checksum
503 "false", // needs admin 515 "false", // needs admin
504 // overflows int32: 516 // overflows int32:
505 "123123123123123"), // size 517 "123123123123123"), // size
506 true, 518 true,
507 &response, 519 &response,
508 NULL)); 520 NULL));
509 521
510 EXPECT_EQ(response.size, 123123123123123ll); 522 EXPECT_EQ(response.size, 123123123123123ll);
511 } 523 }
512 524
513 } // namespace chromeos_update_engine 525 } // namespace chromeos_update_engine
OLDNEW
« no previous file with comments | « src/platform/update_engine/update_check_action.cc ('k') | src/platform/update_engine/utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698