| 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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 " </urls>" | 213 " </urls>" |
| 214 " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>" | 214 " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>" |
| 215 " <packages>" | 215 " <packages>" |
| 216 " <package name='extension_1_2_3_4.crx'/>" | 216 " <package name='extension_1_2_3_4.crx'/>" |
| 217 " </packages>" | 217 " </packages>" |
| 218 " </manifest>" | 218 " </manifest>" |
| 219 " </updatecheck>" | 219 " </updatecheck>" |
| 220 " </app>" | 220 " </app>" |
| 221 "</response>"; | 221 "</response>"; |
| 222 | 222 |
| 223 // Includes two <app> tags, both of which set the cohort. |
| 224 const char* kTwoAppsSetCohort = |
| 225 "<?xml version='1.0' encoding='UTF-8'?>" |
| 226 "<response protocol='3.0'>" |
| 227 " <app appid='aaaaaaaa' cohort='1:2q3/'>" |
| 228 " <updatecheck status='noupdate'/>" |
| 229 " </app>" |
| 230 " <app appid='bbbbbbbb' cohort='1:33z@0.33' cohortname='cname'>" |
| 231 " <updatecheck status='ok'>" |
| 232 " <urls>" |
| 233 " <url codebase='http://example.com/'/>" |
| 234 " </urls>" |
| 235 " <manifest version='1.2.3.4' prodversionmin='2.0.143.0'>" |
| 236 " <packages>" |
| 237 " <package name='extension_1_2_3_4.crx'/>" |
| 238 " </packages>" |
| 239 " </manifest>" |
| 240 " </updatecheck>" |
| 241 " </app>" |
| 242 "</response>"; |
| 243 |
| 223 TEST(ComponentUpdaterUpdateResponseTest, TestParser) { | 244 TEST(ComponentUpdaterUpdateResponseTest, TestParser) { |
| 224 UpdateResponse parser; | 245 UpdateResponse parser; |
| 225 | 246 |
| 226 // Test parsing of a number of invalid xml cases | 247 // Test parsing of a number of invalid xml cases |
| 227 EXPECT_FALSE(parser.Parse(std::string())); | 248 EXPECT_FALSE(parser.Parse(std::string())); |
| 228 EXPECT_FALSE(parser.errors().empty()); | 249 EXPECT_FALSE(parser.errors().empty()); |
| 229 | 250 |
| 230 EXPECT_TRUE(parser.Parse(kMissingAppId)); | 251 EXPECT_TRUE(parser.Parse(kMissingAppId)); |
| 231 EXPECT_TRUE(parser.results().list.empty()); | 252 EXPECT_TRUE(parser.results().list.empty()); |
| 232 EXPECT_FALSE(parser.errors().empty()); | 253 EXPECT_FALSE(parser.errors().empty()); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 firstResult = &parser.results().list[0]; | 326 firstResult = &parser.results().list[0]; |
| 306 EXPECT_EQ(firstResult->extension_id, "12345"); | 327 EXPECT_EQ(firstResult->extension_id, "12345"); |
| 307 EXPECT_EQ(firstResult->manifest.version, ""); | 328 EXPECT_EQ(firstResult->manifest.version, ""); |
| 308 | 329 |
| 309 // Parse xml with one error and one success <app> tag. | 330 // Parse xml with one error and one success <app> tag. |
| 310 EXPECT_TRUE(parser.Parse(kTwoAppsOneError)); | 331 EXPECT_TRUE(parser.Parse(kTwoAppsOneError)); |
| 311 EXPECT_FALSE(parser.errors().empty()); | 332 EXPECT_FALSE(parser.errors().empty()); |
| 312 EXPECT_EQ(1u, parser.results().list.size()); | 333 EXPECT_EQ(1u, parser.results().list.size()); |
| 313 firstResult = &parser.results().list[0]; | 334 firstResult = &parser.results().list[0]; |
| 314 EXPECT_EQ(firstResult->extension_id, "bbbbbbbb"); | 335 EXPECT_EQ(firstResult->extension_id, "bbbbbbbb"); |
| 336 |
| 337 // Parse xml with two apps setting the cohort info. |
| 338 EXPECT_TRUE(parser.Parse(kTwoAppsSetCohort)); |
| 339 EXPECT_TRUE(parser.errors().empty()); |
| 340 EXPECT_EQ(2u, parser.results().list.size()); |
| 341 firstResult = &parser.results().list[0]; |
| 342 EXPECT_EQ(firstResult->extension_id, "aaaaaaaa"); |
| 343 EXPECT_NE(firstResult->cohort_attrs.find("cohort"), |
| 344 firstResult->cohort_attrs.end()); |
| 345 EXPECT_EQ(firstResult->cohort_attrs.find("cohort")->second, "1:2q3/"); |
| 346 EXPECT_EQ(firstResult->cohort_attrs.find("cohortname"), |
| 347 firstResult->cohort_attrs.end()); |
| 348 EXPECT_EQ(firstResult->cohort_attrs.find("cohorthint"), |
| 349 firstResult->cohort_attrs.end()); |
| 350 const UpdateResponse::Result* secondResult = &parser.results().list[1]; |
| 351 EXPECT_EQ(secondResult->extension_id, "bbbbbbbb"); |
| 352 EXPECT_NE(secondResult->cohort_attrs.find("cohort"), |
| 353 secondResult->cohort_attrs.end()); |
| 354 EXPECT_EQ(secondResult->cohort_attrs.find("cohort")->second, "1:33z@0.33"); |
| 355 EXPECT_NE(secondResult->cohort_attrs.find("cohortname"), |
| 356 secondResult->cohort_attrs.end()); |
| 357 EXPECT_EQ(secondResult->cohort_attrs.find("cohortname")->second, "cname"); |
| 358 EXPECT_EQ(secondResult->cohort_attrs.find("cohorthint"), |
| 359 secondResult->cohort_attrs.end()); |
| 315 } | 360 } |
| 316 | 361 |
| 317 } // namespace update_client | 362 } // namespace update_client |
| OLD | NEW |