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

Side by Side Diff: update_check_action_unittest.cc

Issue 2827032: AU: Send board (e.g. x86-generic) to update server in query. (Closed) Base URL: ssh://git@chromiumos-git/update_engine.git
Patch Set: Created 10 years, 5 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 | « update_check_action.cc ('k') | no next file » | 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 *out_post_data = fetcher->post_data(); 152 *out_post_data = fetcher->post_data();
153 return collector_action.has_input_object_; 153 return collector_action.has_input_object_;
154 } 154 }
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 "x86-generic",
162 UpdateCheckParams::kAppId, 163 UpdateCheckParams::kAppId,
163 "0.1.0.0", 164 "0.1.0.0",
164 "en-US", 165 "en-US",
165 "unittest", 166 "unittest",
166 ""); // url 167 ""); // url
167 UpdateCheckResponse response; 168 UpdateCheckResponse response;
168 ASSERT_TRUE( 169 ASSERT_TRUE(
169 TestUpdateCheckAction(params, 170 TestUpdateCheckAction(params,
170 GetNoUpdateResponse(UpdateCheckParams::kAppId), 171 GetNoUpdateResponse(UpdateCheckParams::kAppId),
171 true, 172 true,
172 &response, 173 &response,
173 NULL)); 174 NULL));
174 EXPECT_FALSE(response.update_exists); 175 EXPECT_FALSE(response.update_exists);
175 } 176 }
176 177
177 TEST(UpdateCheckActionTest, ValidUpdateTest) { 178 TEST(UpdateCheckActionTest, ValidUpdateTest) {
178 UpdateCheckParams params("machine_id", 179 UpdateCheckParams params("machine_id",
179 "user_id", 180 "user_id",
180 UpdateCheckParams::kOsPlatform, 181 UpdateCheckParams::kOsPlatform,
181 UpdateCheckParams::kOsVersion, 182 UpdateCheckParams::kOsVersion,
182 "service_pack", 183 "service_pack",
184 "arm-generic",
183 UpdateCheckParams::kAppId, 185 UpdateCheckParams::kAppId,
184 "0.1.0.0", 186 "0.1.0.0",
185 "en-US", 187 "en-US",
186 "unittest_track", 188 "unittest_track",
187 ""); // url 189 ""); // url
188 UpdateCheckResponse response; 190 UpdateCheckResponse response;
189 ASSERT_TRUE( 191 ASSERT_TRUE(
190 TestUpdateCheckAction(params, 192 TestUpdateCheckAction(params,
191 GetUpdateResponse(UpdateCheckParams::kAppId, 193 GetUpdateResponse(UpdateCheckParams::kAppId,
192 "1.2.3.4", // version 194 "1.2.3.4", // version
(...skipping 15 matching lines...) Expand all
208 EXPECT_FALSE(response.needs_admin); 210 EXPECT_FALSE(response.needs_admin);
209 EXPECT_TRUE(response.prompt); 211 EXPECT_TRUE(response.prompt);
210 } 212 }
211 213
212 TEST(UpdateCheckActionTest, NoOutputPipeTest) { 214 TEST(UpdateCheckActionTest, NoOutputPipeTest) {
213 UpdateCheckParams params("", // machine_id 215 UpdateCheckParams params("", // machine_id
214 "", // usr_id 216 "", // usr_id
215 UpdateCheckParams::kOsPlatform, 217 UpdateCheckParams::kOsPlatform,
216 UpdateCheckParams::kOsVersion, 218 UpdateCheckParams::kOsVersion,
217 "", // os_sp 219 "", // os_sp
220 "", // os_board
218 UpdateCheckParams::kAppId, 221 UpdateCheckParams::kAppId,
219 "0.1.0.0", 222 "0.1.0.0",
220 "en-US", 223 "en-US",
221 "unittest", 224 "unittest",
222 ""); // url 225 ""); // url
223 const string http_response(GetNoUpdateResponse(UpdateCheckParams::kAppId)); 226 const string http_response(GetNoUpdateResponse(UpdateCheckParams::kAppId));
224 227
225 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); 228 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE);
226 229
227 ObjectFeederAction<UpdateCheckParams> feeder_action; 230 ObjectFeederAction<UpdateCheckParams> feeder_action;
(...skipping 13 matching lines...) Expand all
241 g_main_loop_unref(loop); 244 g_main_loop_unref(loop);
242 EXPECT_FALSE(processor.IsRunning()); 245 EXPECT_FALSE(processor.IsRunning());
243 } 246 }
244 247
245 TEST(UpdateCheckActionTest, InvalidXmlTest) { 248 TEST(UpdateCheckActionTest, InvalidXmlTest) {
246 UpdateCheckParams params("machine_id", 249 UpdateCheckParams params("machine_id",
247 "user_id", 250 "user_id",
248 UpdateCheckParams::kOsPlatform, 251 UpdateCheckParams::kOsPlatform,
249 UpdateCheckParams::kOsVersion, 252 UpdateCheckParams::kOsVersion,
250 "service_pack", 253 "service_pack",
254 "x86-generic",
251 UpdateCheckParams::kAppId, 255 UpdateCheckParams::kAppId,
252 "0.1.0.0", 256 "0.1.0.0",
253 "en-US", 257 "en-US",
254 "unittest_track", 258 "unittest_track",
255 "http://url"); 259 "http://url");
256 UpdateCheckResponse response; 260 UpdateCheckResponse response;
257 ASSERT_FALSE( 261 ASSERT_FALSE(
258 TestUpdateCheckAction(params, 262 TestUpdateCheckAction(params,
259 "invalid xml>", 263 "invalid xml>",
260 false, 264 false,
261 &response, 265 &response,
262 NULL)); 266 NULL));
263 EXPECT_FALSE(response.update_exists); 267 EXPECT_FALSE(response.update_exists);
264 } 268 }
265 269
266 TEST(UpdateCheckActionTest, MissingStatusTest) { 270 TEST(UpdateCheckActionTest, MissingStatusTest) {
267 UpdateCheckParams params("machine_id", 271 UpdateCheckParams params("machine_id",
268 "user_id", 272 "user_id",
269 UpdateCheckParams::kOsPlatform, 273 UpdateCheckParams::kOsPlatform,
270 UpdateCheckParams::kOsVersion, 274 UpdateCheckParams::kOsVersion,
271 "service_pack", 275 "service_pack",
276 "x86-generic",
272 UpdateCheckParams::kAppId, 277 UpdateCheckParams::kAppId,
273 "0.1.0.0", 278 "0.1.0.0",
274 "en-US", 279 "en-US",
275 "unittest_track", 280 "unittest_track",
276 "http://url"); 281 "http://url");
277 UpdateCheckResponse response; 282 UpdateCheckResponse response;
278 ASSERT_FALSE(TestUpdateCheckAction( 283 ASSERT_FALSE(TestUpdateCheckAction(
279 params, 284 params,
280 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " 285 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate "
281 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " 286 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app "
282 "appid=\"foo\" status=\"ok\"><ping " 287 "appid=\"foo\" status=\"ok\"><ping "
283 "status=\"ok\"/><updatecheck/></app></gupdate>", 288 "status=\"ok\"/><updatecheck/></app></gupdate>",
284 false, 289 false,
285 &response, 290 &response,
286 NULL)); 291 NULL));
287 EXPECT_FALSE(response.update_exists); 292 EXPECT_FALSE(response.update_exists);
288 } 293 }
289 294
290 TEST(UpdateCheckActionTest, InvalidStatusTest) { 295 TEST(UpdateCheckActionTest, InvalidStatusTest) {
291 UpdateCheckParams params("machine_id", 296 UpdateCheckParams params("machine_id",
292 "user_id", 297 "user_id",
293 UpdateCheckParams::kOsPlatform, 298 UpdateCheckParams::kOsPlatform,
294 UpdateCheckParams::kOsVersion, 299 UpdateCheckParams::kOsVersion,
295 "service_pack", 300 "service_pack",
301 "x86-generic",
296 UpdateCheckParams::kAppId, 302 UpdateCheckParams::kAppId,
297 "0.1.0.0", 303 "0.1.0.0",
298 "en-US", 304 "en-US",
299 "unittest_track", 305 "unittest_track",
300 "http://url"); 306 "http://url");
301 UpdateCheckResponse response; 307 UpdateCheckResponse response;
302 ASSERT_FALSE(TestUpdateCheckAction( 308 ASSERT_FALSE(TestUpdateCheckAction(
303 params, 309 params,
304 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " 310 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate "
305 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " 311 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app "
306 "appid=\"foo\" status=\"ok\"><ping " 312 "appid=\"foo\" status=\"ok\"><ping "
307 "status=\"ok\"/><updatecheck status=\"foo\"/></app></gupdate>", 313 "status=\"ok\"/><updatecheck status=\"foo\"/></app></gupdate>",
308 false, 314 false,
309 &response, 315 &response,
310 NULL)); 316 NULL));
311 EXPECT_FALSE(response.update_exists); 317 EXPECT_FALSE(response.update_exists);
312 } 318 }
313 319
314 TEST(UpdateCheckActionTest, MissingNodesetTest) { 320 TEST(UpdateCheckActionTest, MissingNodesetTest) {
315 UpdateCheckParams params("machine_id", 321 UpdateCheckParams params("machine_id",
316 "user_id", 322 "user_id",
317 UpdateCheckParams::kOsPlatform, 323 UpdateCheckParams::kOsPlatform,
318 UpdateCheckParams::kOsVersion, 324 UpdateCheckParams::kOsVersion,
319 "service_pack", 325 "service_pack",
326 "x86-generic",
320 UpdateCheckParams::kAppId, 327 UpdateCheckParams::kAppId,
321 "0.1.0.0", 328 "0.1.0.0",
322 "en-US", 329 "en-US",
323 "unittest_track", 330 "unittest_track",
324 "http://url"); 331 "http://url");
325 UpdateCheckResponse response; 332 UpdateCheckResponse response;
326 ASSERT_FALSE(TestUpdateCheckAction( 333 ASSERT_FALSE(TestUpdateCheckAction(
327 params, 334 params,
328 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " 335 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate "
329 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " 336 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app "
330 "appid=\"foo\" status=\"ok\"><ping " 337 "appid=\"foo\" status=\"ok\"><ping "
331 "status=\"ok\"/></app></gupdate>", 338 "status=\"ok\"/></app></gupdate>",
332 false, 339 false,
333 &response, 340 &response,
334 NULL)); 341 NULL));
335 EXPECT_FALSE(response.update_exists); 342 EXPECT_FALSE(response.update_exists);
336 } 343 }
337 344
338 TEST(UpdateCheckActionTest, MissingFieldTest) { 345 TEST(UpdateCheckActionTest, MissingFieldTest) {
339 UpdateCheckParams params("machine_id", 346 UpdateCheckParams params("machine_id",
340 "user_id", 347 "user_id",
341 UpdateCheckParams::kOsPlatform, 348 UpdateCheckParams::kOsPlatform,
342 UpdateCheckParams::kOsVersion, 349 UpdateCheckParams::kOsVersion,
343 "service_pack", 350 "service_pack",
351 "x86-generic",
344 UpdateCheckParams::kAppId, 352 UpdateCheckParams::kAppId,
345 "0.1.0.0", 353 "0.1.0.0",
346 "en-US", 354 "en-US",
347 "unittest_track", 355 "unittest_track",
348 "http://url"); 356 "http://url");
349 UpdateCheckResponse response; 357 UpdateCheckResponse response;
350 ASSERT_TRUE(TestUpdateCheckAction(params, 358 ASSERT_TRUE(TestUpdateCheckAction(params,
351 string("<?xml version=\"1.0\" " 359 string("<?xml version=\"1.0\" "
352 "encoding=\"UTF-8\"?><gupdate " 360 "encoding=\"UTF-8\"?><gupdate "
353 "xmlns=\"http://www.google.com/" 361 "xmlns=\"http://www.google.com/"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 return FALSE; 401 return FALSE;
394 } 402 }
395 } // namespace {} 403 } // namespace {}
396 404
397 TEST(UpdateCheckActionTest, TerminateTransferTest) { 405 TEST(UpdateCheckActionTest, TerminateTransferTest) {
398 UpdateCheckParams params("", // machine_id 406 UpdateCheckParams params("", // machine_id
399 "", // usr_id 407 "", // usr_id
400 UpdateCheckParams::kOsPlatform, 408 UpdateCheckParams::kOsPlatform,
401 UpdateCheckParams::kOsVersion, 409 UpdateCheckParams::kOsVersion,
402 "", // os_sp 410 "", // os_sp
411 "", // os_board
403 UpdateCheckParams::kAppId, 412 UpdateCheckParams::kAppId,
404 "0.1.0.0", 413 "0.1.0.0",
405 "en-US", 414 "en-US",
406 "unittest", 415 "unittest",
407 "http://url"); 416 "http://url");
408 string http_response("doesn't matter"); 417 string http_response("doesn't matter");
409 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE); 418 GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE);
410 419
411 ObjectFeederAction<UpdateCheckParams> feeder_action; 420 ObjectFeederAction<UpdateCheckParams> feeder_action;
412 feeder_action.set_obj(params); 421 feeder_action.set_obj(params);
(...skipping 20 matching lines...) Expand all
433 EXPECT_EQ("&amp;lt;&amp;amp;&amp;gt;", XmlEncode("&lt;&amp;&gt;")); 442 EXPECT_EQ("&amp;lt;&amp;amp;&amp;gt;", XmlEncode("&lt;&amp;&gt;"));
434 443
435 vector<char> post_data; 444 vector<char> post_data;
436 445
437 // Make sure XML Encode is being called on the params 446 // Make sure XML Encode is being called on the params
438 UpdateCheckParams params("testthemachine<id", 447 UpdateCheckParams params("testthemachine<id",
439 "testtheuser_id&lt;", 448 "testtheuser_id&lt;",
440 UpdateCheckParams::kOsPlatform, 449 UpdateCheckParams::kOsPlatform,
441 UpdateCheckParams::kOsVersion, 450 UpdateCheckParams::kOsVersion,
442 "testtheservice_pack>", 451 "testtheservice_pack>",
452 "x86 generic",
443 UpdateCheckParams::kAppId, 453 UpdateCheckParams::kAppId,
444 "0.1.0.0", 454 "0.1.0.0",
445 "en-US", 455 "en-US",
446 "unittest_track", 456 "unittest_track",
447 "http://url"); 457 "http://url");
448 UpdateCheckResponse response; 458 UpdateCheckResponse response;
449 ASSERT_FALSE( 459 ASSERT_FALSE(
450 TestUpdateCheckAction(params, 460 TestUpdateCheckAction(params,
451 "invalid xml>", 461 "invalid xml>",
452 false, 462 false,
453 &response, 463 &response,
454 &post_data)); 464 &post_data));
455 // convert post_data to string 465 // convert post_data to string
456 string post_str(&post_data[0], post_data.size()); 466 string post_str(&post_data[0], post_data.size());
457 EXPECT_NE(post_str.find("testthemachine&lt;id"), string::npos); 467 EXPECT_NE(post_str.find("testthemachine&lt;id"), string::npos);
458 EXPECT_EQ(post_str.find("testthemachine<id"), string::npos); 468 EXPECT_EQ(post_str.find("testthemachine<id"), string::npos);
459 EXPECT_NE(post_str.find("testtheuser_id&amp;lt;"), string::npos); 469 EXPECT_NE(post_str.find("testtheuser_id&amp;lt;"), string::npos);
460 EXPECT_EQ(post_str.find("testtheuser_id&lt;"), string::npos); 470 EXPECT_EQ(post_str.find("testtheuser_id&lt;"), string::npos);
461 EXPECT_NE(post_str.find("testtheservice_pack&gt;"), string::npos); 471 EXPECT_NE(post_str.find("testtheservice_pack&gt;"), string::npos);
462 EXPECT_EQ(post_str.find("testtheservice_pack>"), string::npos); 472 EXPECT_EQ(post_str.find("testtheservice_pack>"), string::npos);
473 EXPECT_NE(post_str.find("x86 generic"), string::npos);
463 } 474 }
464 475
465 TEST(UpdateCheckActionTest, XmlDecodeTest) { 476 TEST(UpdateCheckActionTest, XmlDecodeTest) {
466 UpdateCheckParams params("machine_id", 477 UpdateCheckParams params("machine_id",
467 "user_id", 478 "user_id",
468 UpdateCheckParams::kOsPlatform, 479 UpdateCheckParams::kOsPlatform,
469 UpdateCheckParams::kOsVersion, 480 UpdateCheckParams::kOsVersion,
470 "service_pack", 481 "service_pack",
482 "x86-generic",
471 UpdateCheckParams::kAppId, 483 UpdateCheckParams::kAppId,
472 "0.1.0.0", 484 "0.1.0.0",
473 "en-US", 485 "en-US",
474 "unittest_track", 486 "unittest_track",
475 "http://url"); 487 "http://url");
476 UpdateCheckResponse response; 488 UpdateCheckResponse response;
477 ASSERT_TRUE( 489 ASSERT_TRUE(
478 TestUpdateCheckAction(params, 490 TestUpdateCheckAction(params,
479 GetUpdateResponse(UpdateCheckParams::kAppId, 491 GetUpdateResponse(UpdateCheckParams::kAppId,
480 "1.2.3.4", // version 492 "1.2.3.4", // version
(...skipping 10 matching lines...) Expand all
491 EXPECT_EQ(response.more_info_url, "testthe<url"); 503 EXPECT_EQ(response.more_info_url, "testthe<url");
492 EXPECT_EQ(response.codebase, "testthe&codebase"); 504 EXPECT_EQ(response.codebase, "testthe&codebase");
493 } 505 }
494 506
495 TEST(UpdateCheckActionTest, ParseIntTest) { 507 TEST(UpdateCheckActionTest, ParseIntTest) {
496 UpdateCheckParams params("machine_id", 508 UpdateCheckParams params("machine_id",
497 "user_id", 509 "user_id",
498 UpdateCheckParams::kOsPlatform, 510 UpdateCheckParams::kOsPlatform,
499 UpdateCheckParams::kOsVersion, 511 UpdateCheckParams::kOsVersion,
500 "service_pack", 512 "service_pack",
513 "the_board",
501 UpdateCheckParams::kAppId, 514 UpdateCheckParams::kAppId,
502 "0.1.0.0", 515 "0.1.0.0",
503 "en-US", 516 "en-US",
504 "unittest_track", 517 "unittest_track",
505 "http://url"); 518 "http://url");
506 UpdateCheckResponse response; 519 UpdateCheckResponse response;
507 ASSERT_TRUE( 520 ASSERT_TRUE(
508 TestUpdateCheckAction(params, 521 TestUpdateCheckAction(params,
509 GetUpdateResponse(UpdateCheckParams::kAppId, 522 GetUpdateResponse(UpdateCheckParams::kAppId,
510 "1.2.3.4", // version 523 "1.2.3.4", // version
511 "theurl", // more info 524 "theurl", // more info
512 "true", // prompt 525 "true", // prompt
513 "thecodebase", // dl url 526 "thecodebase", // dl url
514 "HASH1234=", // checksum 527 "HASH1234=", // checksum
515 "false", // needs admin 528 "false", // needs admin
516 // overflows int32: 529 // overflows int32:
517 "123123123123123"), // size 530 "123123123123123"), // size
518 true, 531 true,
519 &response, 532 &response,
520 NULL)); 533 NULL));
521 534
522 EXPECT_EQ(response.size, 123123123123123ll); 535 EXPECT_EQ(response.size, 123123123123123ll);
523 } 536 }
524 537
525 } // namespace chromeos_update_engine 538 } // namespace chromeos_update_engine
OLDNEW
« no previous file with comments | « update_check_action.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698