| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "base/test/values_test_util.h" | 5 #include "base/test/values_test_util.h" |
| 6 #include "extensions/common/manifest_handlers/icons_handler.h" | 6 #include "extensions/common/manifest_handlers/icons_handler.h" |
| 7 #include "extensions/common/manifest_test.h" | 7 #include "extensions/common/manifest_test.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 namespace extensions { | 10 namespace extensions { |
| 11 | 11 |
| 12 class ProductIconManifestTest : public ManifestTest { | 12 class ProductIconManifestTest : public ManifestTest { |
| 13 public: | 13 public: |
| 14 ProductIconManifestTest() {} | 14 ProductIconManifestTest() {} |
| 15 | 15 |
| 16 protected: | 16 protected: |
| 17 scoped_ptr<base::DictionaryValue> CreateManifest( | 17 std::unique_ptr<base::DictionaryValue> CreateManifest( |
| 18 const std::string& extra_icons) { | 18 const std::string& extra_icons) { |
| 19 scoped_ptr<base::DictionaryValue> manifest = base::DictionaryValue::From( | 19 std::unique_ptr<base::DictionaryValue> manifest = |
| 20 base::test::ParseJson("{ \n" | 20 base::DictionaryValue::From( |
| 21 " \"name\": \"test\", \n" | 21 base::test::ParseJson("{ \n" |
| 22 " \"version\": \"0.1\", \n" | 22 " \"name\": \"test\", \n" |
| 23 " \"manifest_version\": 2, \n" | 23 " \"version\": \"0.1\", \n" |
| 24 " \"icons\": { \n" + | 24 " \"manifest_version\": 2, \n" |
| 25 extra_icons + " \"16\": \"icon1.png\", \n" | 25 " \"icons\": { \n" + |
| 26 " \"32\": \"icon2.png\" \n" | 26 extra_icons + " \"16\": \"icon1.png\", \n" |
| 27 " } \n" | 27 " \"32\": \"icon2.png\" \n" |
| 28 "} \n")); | 28 " } \n" |
| 29 "} \n")); |
| 29 EXPECT_TRUE(manifest); | 30 EXPECT_TRUE(manifest); |
| 30 return manifest; | 31 return manifest; |
| 31 } | 32 } |
| 32 | 33 |
| 33 private: | 34 private: |
| 34 DISALLOW_COPY_AND_ASSIGN(ProductIconManifestTest); | 35 DISALLOW_COPY_AND_ASSIGN(ProductIconManifestTest); |
| 35 }; | 36 }; |
| 36 | 37 |
| 37 TEST_F(ProductIconManifestTest, Sizes) { | 38 TEST_F(ProductIconManifestTest, Sizes) { |
| 38 // Too big. | 39 // Too big. |
| 39 { | 40 { |
| 40 scoped_ptr<base::DictionaryValue> ext_manifest = | 41 std::unique_ptr<base::DictionaryValue> ext_manifest = |
| 41 CreateManifest("\"100000\": \"icon3.png\", \n"); | 42 CreateManifest("\"100000\": \"icon3.png\", \n"); |
| 42 ManifestData manifest(std::move(ext_manifest), "test"); | 43 ManifestData manifest(std::move(ext_manifest), "test"); |
| 43 LoadAndExpectError(manifest, "Invalid key in icons: \"100000\"."); | 44 LoadAndExpectError(manifest, "Invalid key in icons: \"100000\"."); |
| 44 } | 45 } |
| 45 // Too small. | 46 // Too small. |
| 46 { | 47 { |
| 47 scoped_ptr<base::DictionaryValue> ext_manifest = | 48 std::unique_ptr<base::DictionaryValue> ext_manifest = |
| 48 CreateManifest("\"0\": \"icon3.png\", \n"); | 49 CreateManifest("\"0\": \"icon3.png\", \n"); |
| 49 ManifestData manifest(std::move(ext_manifest), "test"); | 50 ManifestData manifest(std::move(ext_manifest), "test"); |
| 50 LoadAndExpectError(manifest, "Invalid key in icons: \"0\"."); | 51 LoadAndExpectError(manifest, "Invalid key in icons: \"0\"."); |
| 51 } | 52 } |
| 52 // NaN. | 53 // NaN. |
| 53 { | 54 { |
| 54 scoped_ptr<base::DictionaryValue> ext_manifest = | 55 std::unique_ptr<base::DictionaryValue> ext_manifest = |
| 55 CreateManifest("\"sixteen\": \"icon3.png\", \n"); | 56 CreateManifest("\"sixteen\": \"icon3.png\", \n"); |
| 56 ManifestData manifest(std::move(ext_manifest), "test"); | 57 ManifestData manifest(std::move(ext_manifest), "test"); |
| 57 LoadAndExpectError(manifest, "Invalid key in icons: \"sixteen\"."); | 58 LoadAndExpectError(manifest, "Invalid key in icons: \"sixteen\"."); |
| 58 } | 59 } |
| 59 // Just right. | 60 // Just right. |
| 60 { | 61 { |
| 61 scoped_ptr<base::DictionaryValue> ext_manifest = | 62 std::unique_ptr<base::DictionaryValue> ext_manifest = |
| 62 CreateManifest("\"512\": \"icon3.png\", \n"); | 63 CreateManifest("\"512\": \"icon3.png\", \n"); |
| 63 ManifestData manifest(std::move(ext_manifest), "test"); | 64 ManifestData manifest(std::move(ext_manifest), "test"); |
| 64 scoped_refptr<extensions::Extension> extension = | 65 scoped_refptr<extensions::Extension> extension = |
| 65 LoadAndExpectSuccess(manifest); | 66 LoadAndExpectSuccess(manifest); |
| 66 } | 67 } |
| 67 } | 68 } |
| 68 | 69 |
| 69 } // namespace extensions | 70 } // namespace extensions |
| OLD | NEW |