| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/renderer/manifest/manifest_parser.h" | 5 #include "content/renderer/manifest/manifest_parser.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 } | 22 } |
| 23 | 23 |
| 24 } // anonymous namespace | 24 } // anonymous namespace |
| 25 | 25 |
| 26 class ManifestParserTest : public testing::Test { | 26 class ManifestParserTest : public testing::Test { |
| 27 protected: | 27 protected: |
| 28 ManifestParserTest() {} | 28 ManifestParserTest() {} |
| 29 ~ManifestParserTest() override {} | 29 ~ManifestParserTest() override {} |
| 30 | 30 |
| 31 Manifest ParseManifestWithURLs(const base::StringPiece& data, | 31 Manifest ParseManifestWithURLs(const base::StringPiece& data, |
| 32 const GURL& document_url, | 32 const GURL& manifest_url, |
| 33 const GURL& manifest_url) { | 33 const GURL& document_url) { |
| 34 ManifestParser parser(data, document_url, manifest_url); | 34 ManifestParser parser(data, manifest_url, document_url); |
| 35 parser.Parse(); | 35 parser.Parse(); |
| 36 std::vector<ManifestDebugInfo::Error> errors; | 36 std::vector<ManifestDebugInfo::Error> errors; |
| 37 parser.TakeErrors(&errors); | 37 parser.TakeErrors(&errors); |
| 38 | 38 |
| 39 errors_.clear(); | 39 errors_.clear(); |
| 40 for (const auto& error : errors) | 40 for (const auto& error : errors) |
| 41 errors_.push_back(error.message); | 41 errors_.push_back(error.message); |
| 42 return parser.manifest(); | 42 return parser.manifest(); |
| 43 } | 43 } |
| 44 | 44 |
| 45 Manifest ParseManifest(const base::StringPiece& data) { | 45 Manifest ParseManifest(const base::StringPiece& data) { |
| 46 return ParseManifestWithURLs( | 46 return ParseManifestWithURLs( |
| 47 data, default_document_url, default_manifest_url); | 47 data, default_manifest_url, default_document_url); |
| 48 } | 48 } |
| 49 | 49 |
| 50 const std::vector<std::string>& errors() const { | 50 const std::vector<std::string>& errors() const { |
| 51 return errors_; | 51 return errors_; |
| 52 } | 52 } |
| 53 | 53 |
| 54 unsigned int GetErrorCount() const { | 54 unsigned int GetErrorCount() const { |
| 55 return errors_.size(); | 55 return errors_.size(); |
| 56 } | 56 } |
| 57 | 57 |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 Manifest manifest = ParseManifest("{ \"icons\": [ { \"icons\": [] } ] }"); | 505 Manifest manifest = ParseManifest("{ \"icons\": [ { \"icons\": [] } ] }"); |
| 506 EXPECT_EQ(manifest.icons.size(), 0u); | 506 EXPECT_EQ(manifest.icons.size(), 0u); |
| 507 EXPECT_TRUE(manifest.IsEmpty()); | 507 EXPECT_TRUE(manifest.IsEmpty()); |
| 508 EXPECT_EQ(0u, GetErrorCount()); | 508 EXPECT_EQ(0u, GetErrorCount()); |
| 509 } | 509 } |
| 510 | 510 |
| 511 // Smoke test: if icon with empty src, it will be present in the list. | 511 // Smoke test: if icon with empty src, it will be present in the list. |
| 512 { | 512 { |
| 513 Manifest manifest = ParseManifest("{ \"icons\": [ { \"src\": \"\" } ] }"); | 513 Manifest manifest = ParseManifest("{ \"icons\": [ { \"src\": \"\" } ] }"); |
| 514 EXPECT_EQ(manifest.icons.size(), 1u); | 514 EXPECT_EQ(manifest.icons.size(), 1u); |
| 515 EXPECT_EQ(manifest.icons[0].src.spec(), "http://foo.com/index.html"); | 515 EXPECT_EQ(manifest.icons[0].src.spec(), "http://foo.com/manifest.json"); |
| 516 EXPECT_FALSE(manifest.IsEmpty()); | 516 EXPECT_FALSE(manifest.IsEmpty()); |
| 517 EXPECT_EQ(0u, GetErrorCount()); | 517 EXPECT_EQ(0u, GetErrorCount()); |
| 518 } | 518 } |
| 519 | 519 |
| 520 // Smoke test: if one icons with valid src, it will be present in the list. | 520 // Smoke test: if one icons with valid src, it will be present in the list. |
| 521 { | 521 { |
| 522 Manifest manifest = | 522 Manifest manifest = |
| 523 ParseManifest("{ \"icons\": [{ \"src\": \"foo.jpg\" }] }"); | 523 ParseManifest("{ \"icons\": [{ \"src\": \"foo.jpg\" }] }"); |
| 524 EXPECT_EQ(manifest.icons.size(), 1u); | 524 EXPECT_EQ(manifest.icons.size(), 1u); |
| 525 EXPECT_EQ(manifest.icons[0].src.spec(), "http://foo.com/foo.jpg"); | 525 EXPECT_EQ(manifest.icons[0].src.spec(), "http://foo.com/foo.jpg"); |
| (...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1260 { | 1260 { |
| 1261 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": 42 }"); | 1261 Manifest manifest = ParseManifest("{ \"gcm_sender_id\": 42 }"); |
| 1262 EXPECT_TRUE(manifest.gcm_sender_id.is_null()); | 1262 EXPECT_TRUE(manifest.gcm_sender_id.is_null()); |
| 1263 EXPECT_EQ(1u, GetErrorCount()); | 1263 EXPECT_EQ(1u, GetErrorCount()); |
| 1264 EXPECT_EQ("property 'gcm_sender_id' ignored, type string expected.", | 1264 EXPECT_EQ("property 'gcm_sender_id' ignored, type string expected.", |
| 1265 errors()[0]); | 1265 errors()[0]); |
| 1266 } | 1266 } |
| 1267 } | 1267 } |
| 1268 | 1268 |
| 1269 } // namespace content | 1269 } // namespace content |
| OLD | NEW |