OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium 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 "components/update_client/update_response.h" | 5 #include "components/update_client/update_response.h" |
6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
7 | 7 |
8 namespace update_client { | 8 namespace update_client { |
9 | 9 |
10 const char* kValidXml = | 10 const char* kValidXml = |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 " </urls>" | 234 " </urls>" |
235 " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>" | 235 " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>" |
236 " <packages>" | 236 " <packages>" |
237 " <package name='extension_1_2_3_4.crx'/>" | 237 " <package name='extension_1_2_3_4.crx'/>" |
238 " </packages>" | 238 " </packages>" |
239 " </manifest>" | 239 " </manifest>" |
240 " </updatecheck>" | 240 " </updatecheck>" |
241 " </app>" | 241 " </app>" |
242 "</response>"; | 242 "</response>"; |
243 | 243 |
| 244 // Includes a run action for an update check with status='ok'. |
| 245 const char* kUpdateCheckStatusOkWithRunAction = |
| 246 "<?xml version='1.0' encoding='UTF-8'?>" |
| 247 "<response protocol='3.0'>" |
| 248 " <app appid='12345'>" |
| 249 " <updatecheck status='ok'>" |
| 250 " <urls>" |
| 251 " <url codebase='http://example.com/'/>" |
| 252 " <url codebasediff='http://diff.example.com/'/>" |
| 253 " </urls>" |
| 254 " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>" |
| 255 " <packages>" |
| 256 " <package name='extension_1_2_3_4.crx'/>" |
| 257 " </packages>" |
| 258 " </manifest>" |
| 259 " <actions>" |
| 260 " <action run='this'/>" |
| 261 " </actions>" |
| 262 " </updatecheck>" |
| 263 " </app>" |
| 264 "</response>"; |
| 265 |
| 266 // Includes a run action for an update check with status='noupdate'. |
| 267 const char* kUpdateCheckStatusNoUpdateWithRunAction = |
| 268 "<?xml version='1.0' encoding='UTF-8'?>" |
| 269 "<response protocol='3.0'>" |
| 270 " <app appid='12345'>" |
| 271 " <updatecheck status='noupdate'>" |
| 272 " <actions>" |
| 273 " <action run='this'/>" |
| 274 " </actions>" |
| 275 " </updatecheck>" |
| 276 " </app>" |
| 277 "</response>"; |
| 278 |
| 279 // Includes a run action for an update check with status='error'. |
| 280 const char* kUpdateCheckStatusErrorWithRunAction = |
| 281 "<?xml version='1.0' encoding='UTF-8'?>" |
| 282 "<response protocol='3.0'>" |
| 283 " <app appid='12345' status='ok'>" |
| 284 " <updatecheck status='error-osnotsupported'>" |
| 285 " <actions>" |
| 286 " <action run='this'/>" |
| 287 " </actions>" |
| 288 " </updatecheck>" |
| 289 " </app>" |
| 290 "</response>"; |
| 291 |
244 TEST(ComponentUpdaterUpdateResponseTest, TestParser) { | 292 TEST(ComponentUpdaterUpdateResponseTest, TestParser) { |
245 UpdateResponse parser; | 293 UpdateResponse parser; |
246 | 294 |
247 // Test parsing of a number of invalid xml cases | 295 // Test parsing of a number of invalid xml cases |
248 EXPECT_FALSE(parser.Parse(std::string())); | 296 EXPECT_FALSE(parser.Parse(std::string())); |
249 EXPECT_FALSE(parser.errors().empty()); | 297 EXPECT_FALSE(parser.errors().empty()); |
250 | 298 |
251 EXPECT_TRUE(parser.Parse(kMissingAppId)); | 299 EXPECT_TRUE(parser.Parse(kMissingAppId)); |
252 EXPECT_TRUE(parser.results().list.empty()); | 300 EXPECT_TRUE(parser.results().list.empty()); |
253 EXPECT_FALSE(parser.errors().empty()); | 301 EXPECT_FALSE(parser.errors().empty()); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 const UpdateResponse::Result* secondResult = &parser.results().list[1]; | 402 const UpdateResponse::Result* secondResult = &parser.results().list[1]; |
355 EXPECT_EQ(secondResult->extension_id, "bbbbbbbb"); | 403 EXPECT_EQ(secondResult->extension_id, "bbbbbbbb"); |
356 EXPECT_NE(secondResult->cohort_attrs.find("cohort"), | 404 EXPECT_NE(secondResult->cohort_attrs.find("cohort"), |
357 secondResult->cohort_attrs.end()); | 405 secondResult->cohort_attrs.end()); |
358 EXPECT_EQ(secondResult->cohort_attrs.find("cohort")->second, "1:33z@0.33"); | 406 EXPECT_EQ(secondResult->cohort_attrs.find("cohort")->second, "1:33z@0.33"); |
359 EXPECT_NE(secondResult->cohort_attrs.find("cohortname"), | 407 EXPECT_NE(secondResult->cohort_attrs.find("cohortname"), |
360 secondResult->cohort_attrs.end()); | 408 secondResult->cohort_attrs.end()); |
361 EXPECT_EQ(secondResult->cohort_attrs.find("cohortname")->second, "cname"); | 409 EXPECT_EQ(secondResult->cohort_attrs.find("cohortname")->second, "cname"); |
362 EXPECT_EQ(secondResult->cohort_attrs.find("cohorthint"), | 410 EXPECT_EQ(secondResult->cohort_attrs.find("cohorthint"), |
363 secondResult->cohort_attrs.end()); | 411 secondResult->cohort_attrs.end()); |
| 412 |
| 413 EXPECT_TRUE(parser.Parse(kUpdateCheckStatusOkWithRunAction)); |
| 414 EXPECT_TRUE(parser.errors().empty()); |
| 415 EXPECT_FALSE(parser.results().list.empty()); |
| 416 firstResult = &parser.results().list[0]; |
| 417 EXPECT_STREQ("ok", firstResult->status.c_str()); |
| 418 EXPECT_EQ(firstResult->extension_id, "12345"); |
| 419 EXPECT_STREQ("this", firstResult->action_run.c_str()); |
| 420 |
| 421 EXPECT_TRUE(parser.Parse(kUpdateCheckStatusNoUpdateWithRunAction)); |
| 422 EXPECT_TRUE(parser.errors().empty()); |
| 423 EXPECT_FALSE(parser.results().list.empty()); |
| 424 firstResult = &parser.results().list[0]; |
| 425 EXPECT_STREQ("noupdate", firstResult->status.c_str()); |
| 426 EXPECT_EQ(firstResult->extension_id, "12345"); |
| 427 EXPECT_STREQ("this", firstResult->action_run.c_str()); |
| 428 |
| 429 EXPECT_TRUE(parser.Parse(kUpdateCheckStatusErrorWithRunAction)); |
| 430 EXPECT_FALSE(parser.errors().empty()); |
| 431 EXPECT_TRUE(parser.results().list.empty()); |
364 } | 432 } |
365 | 433 |
366 } // namespace update_client | 434 } // namespace update_client |
OLD | NEW |