| OLD | NEW |
| 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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 class ActionTraits<OutputObjectCollectorAction> { | 86 class ActionTraits<OutputObjectCollectorAction> { |
| 87 public: | 87 public: |
| 88 // Does not take an object for input | 88 // Does not take an object for input |
| 89 typedef UpdateCheckResponse InputObjectType; | 89 typedef UpdateCheckResponse InputObjectType; |
| 90 // On success, puts the output path on output | 90 // On success, puts the output path on output |
| 91 typedef NoneType OutputObjectType; | 91 typedef NoneType OutputObjectType; |
| 92 }; | 92 }; |
| 93 | 93 |
| 94 class OutputObjectCollectorAction : public Action<OutputObjectCollectorAction> { | 94 class OutputObjectCollectorAction : public Action<OutputObjectCollectorAction> { |
| 95 public: | 95 public: |
| 96 OutputObjectCollectorAction() : has_input_object_(false) {} |
| 96 void PerformAction() { | 97 void PerformAction() { |
| 97 // copy input object | 98 // copy input object |
| 98 has_input_object_ = HasInputObject(); | 99 has_input_object_ = HasInputObject(); |
| 99 if (has_input_object_) | 100 if (has_input_object_) |
| 100 update_check_response_ = GetInputObject(); | 101 update_check_response_ = GetInputObject(); |
| 101 processor_->ActionComplete(this, true); | 102 processor_->ActionComplete(this, true); |
| 102 } | 103 } |
| 103 // Should never be called | 104 // Should never be called |
| 104 void TerminateProcessing() { | 105 void TerminateProcessing() { |
| 105 CHECK(false); | 106 CHECK(false); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 UpdateCheckParams params("machine_id", | 243 UpdateCheckParams params("machine_id", |
| 243 "user_id", | 244 "user_id", |
| 244 UpdateCheckParams::kOsPlatform, | 245 UpdateCheckParams::kOsPlatform, |
| 245 UpdateCheckParams::kOsVersion, | 246 UpdateCheckParams::kOsVersion, |
| 246 "service_pack", | 247 "service_pack", |
| 247 UpdateCheckParams::kAppId, | 248 UpdateCheckParams::kAppId, |
| 248 "0.1.0.0", | 249 "0.1.0.0", |
| 249 "en-US", | 250 "en-US", |
| 250 "unittest_track"); | 251 "unittest_track"); |
| 251 UpdateCheckResponse response; | 252 UpdateCheckResponse response; |
| 252 ASSERT_TRUE( | 253 ASSERT_FALSE( |
| 253 TestUpdateCheckAction(params, | 254 TestUpdateCheckAction(params, |
| 254 "invalid xml>", | 255 "invalid xml>", |
| 255 false, | 256 false, |
| 256 &response, | 257 &response, |
| 257 NULL)); | 258 NULL)); |
| 258 EXPECT_FALSE(response.update_exists); | 259 EXPECT_FALSE(response.update_exists); |
| 259 } | 260 } |
| 260 | 261 |
| 261 TEST(UpdateCheckActionTest, MissingStatusTest) { | 262 TEST(UpdateCheckActionTest, MissingStatusTest) { |
| 262 UpdateCheckParams params("machine_id", | 263 UpdateCheckParams params("machine_id", |
| 263 "user_id", | 264 "user_id", |
| 264 UpdateCheckParams::kOsPlatform, | 265 UpdateCheckParams::kOsPlatform, |
| 265 UpdateCheckParams::kOsVersion, | 266 UpdateCheckParams::kOsVersion, |
| 266 "service_pack", | 267 "service_pack", |
| 267 UpdateCheckParams::kAppId, | 268 UpdateCheckParams::kAppId, |
| 268 "0.1.0.0", | 269 "0.1.0.0", |
| 269 "en-US", | 270 "en-US", |
| 270 "unittest_track"); | 271 "unittest_track"); |
| 271 UpdateCheckResponse response; | 272 UpdateCheckResponse response; |
| 272 ASSERT_TRUE(TestUpdateCheckAction( | 273 ASSERT_FALSE(TestUpdateCheckAction( |
| 273 params, | 274 params, |
| 274 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " | 275 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " |
| 275 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " | 276 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " |
| 276 "appid=\"foo\" status=\"ok\"><ping " | 277 "appid=\"foo\" status=\"ok\"><ping " |
| 277 "status=\"ok\"/><updatecheck/></app></gupdate>", | 278 "status=\"ok\"/><updatecheck/></app></gupdate>", |
| 278 false, | 279 false, |
| 279 &response, | 280 &response, |
| 280 NULL)); | 281 NULL)); |
| 281 EXPECT_FALSE(response.update_exists); | 282 EXPECT_FALSE(response.update_exists); |
| 282 } | 283 } |
| 283 | 284 |
| 284 TEST(UpdateCheckActionTest, InvalidStatusTest) { | 285 TEST(UpdateCheckActionTest, InvalidStatusTest) { |
| 285 UpdateCheckParams params("machine_id", | 286 UpdateCheckParams params("machine_id", |
| 286 "user_id", | 287 "user_id", |
| 287 UpdateCheckParams::kOsPlatform, | 288 UpdateCheckParams::kOsPlatform, |
| 288 UpdateCheckParams::kOsVersion, | 289 UpdateCheckParams::kOsVersion, |
| 289 "service_pack", | 290 "service_pack", |
| 290 UpdateCheckParams::kAppId, | 291 UpdateCheckParams::kAppId, |
| 291 "0.1.0.0", | 292 "0.1.0.0", |
| 292 "en-US", | 293 "en-US", |
| 293 "unittest_track"); | 294 "unittest_track"); |
| 294 UpdateCheckResponse response; | 295 UpdateCheckResponse response; |
| 295 ASSERT_TRUE(TestUpdateCheckAction( | 296 ASSERT_FALSE(TestUpdateCheckAction( |
| 296 params, | 297 params, |
| 297 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " | 298 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " |
| 298 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " | 299 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " |
| 299 "appid=\"foo\" status=\"ok\"><ping " | 300 "appid=\"foo\" status=\"ok\"><ping " |
| 300 "status=\"ok\"/><updatecheck status=\"foo\"/></app></gupdate>", | 301 "status=\"ok\"/><updatecheck status=\"foo\"/></app></gupdate>", |
| 301 false, | 302 false, |
| 302 &response, | 303 &response, |
| 303 NULL)); | 304 NULL)); |
| 304 EXPECT_FALSE(response.update_exists); | 305 EXPECT_FALSE(response.update_exists); |
| 305 } | 306 } |
| 306 | 307 |
| 307 TEST(UpdateCheckActionTest, MissingNodesetTest) { | 308 TEST(UpdateCheckActionTest, MissingNodesetTest) { |
| 308 UpdateCheckParams params("machine_id", | 309 UpdateCheckParams params("machine_id", |
| 309 "user_id", | 310 "user_id", |
| 310 UpdateCheckParams::kOsPlatform, | 311 UpdateCheckParams::kOsPlatform, |
| 311 UpdateCheckParams::kOsVersion, | 312 UpdateCheckParams::kOsVersion, |
| 312 "service_pack", | 313 "service_pack", |
| 313 UpdateCheckParams::kAppId, | 314 UpdateCheckParams::kAppId, |
| 314 "0.1.0.0", | 315 "0.1.0.0", |
| 315 "en-US", | 316 "en-US", |
| 316 "unittest_track"); | 317 "unittest_track"); |
| 317 UpdateCheckResponse response; | 318 UpdateCheckResponse response; |
| 318 ASSERT_TRUE(TestUpdateCheckAction( | 319 ASSERT_FALSE(TestUpdateCheckAction( |
| 319 params, | 320 params, |
| 320 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " | 321 "<?xml version=\"1.0\" encoding=\"UTF-8\"?><gupdate " |
| 321 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " | 322 "xmlns=\"http://www.google.com/update2/response\" protocol=\"2.0\"><app " |
| 322 "appid=\"foo\" status=\"ok\"><ping " | 323 "appid=\"foo\" status=\"ok\"><ping " |
| 323 "status=\"ok\"/></app></gupdate>", | 324 "status=\"ok\"/></app></gupdate>", |
| 324 false, | 325 false, |
| 325 &response, | 326 &response, |
| 326 NULL)); | 327 NULL)); |
| 327 EXPECT_FALSE(response.update_exists); | 328 EXPECT_FALSE(response.update_exists); |
| 328 } | 329 } |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 UpdateCheckParams params("testthemachine<id", | 429 UpdateCheckParams params("testthemachine<id", |
| 429 "testtheuser_id<", | 430 "testtheuser_id<", |
| 430 UpdateCheckParams::kOsPlatform, | 431 UpdateCheckParams::kOsPlatform, |
| 431 UpdateCheckParams::kOsVersion, | 432 UpdateCheckParams::kOsVersion, |
| 432 "testtheservice_pack>", | 433 "testtheservice_pack>", |
| 433 UpdateCheckParams::kAppId, | 434 UpdateCheckParams::kAppId, |
| 434 "0.1.0.0", | 435 "0.1.0.0", |
| 435 "en-US", | 436 "en-US", |
| 436 "unittest_track"); | 437 "unittest_track"); |
| 437 UpdateCheckResponse response; | 438 UpdateCheckResponse response; |
| 438 ASSERT_TRUE( | 439 ASSERT_FALSE( |
| 439 TestUpdateCheckAction(params, | 440 TestUpdateCheckAction(params, |
| 440 "invalid xml>", | 441 "invalid xml>", |
| 441 false, | 442 false, |
| 442 &response, | 443 &response, |
| 443 &post_data)); | 444 &post_data)); |
| 444 // convert post_data to string | 445 // convert post_data to string |
| 445 string post_str(&post_data[0], post_data.size()); | 446 string post_str(&post_data[0], post_data.size()); |
| 446 EXPECT_NE(post_str.find("testthemachine<id"), string::npos); | 447 EXPECT_NE(post_str.find("testthemachine<id"), string::npos); |
| 447 EXPECT_EQ(post_str.find("testthemachine<id"), string::npos); | 448 EXPECT_EQ(post_str.find("testthemachine<id"), string::npos); |
| 448 EXPECT_NE(post_str.find("testtheuser_id&lt;"), string::npos); | 449 EXPECT_NE(post_str.find("testtheuser_id&lt;"), string::npos); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 // overflows int32: | 504 // overflows int32: |
| 504 "123123123123123"), // size | 505 "123123123123123"), // size |
| 505 true, | 506 true, |
| 506 &response, | 507 &response, |
| 507 NULL)); | 508 NULL)); |
| 508 | 509 |
| 509 EXPECT_EQ(response.size, 123123123123123ll); | 510 EXPECT_EQ(response.size, 123123123123123ll); |
| 510 } | 511 } |
| 511 | 512 |
| 512 } // namespace chromeos_update_engine | 513 } // namespace chromeos_update_engine |
| OLD | NEW |