| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/common/extensions/manifest_tests/extension_manifest_test.h" | 5 #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h" |
| 6 | 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "testing/gmock/include/gmock/gmock.h" | 8 #include "testing/gmock/include/gmock/gmock.h" |
| 9 | 9 |
| 10 using extensions::Extension; | 10 using extensions::Extension; |
| 11 | 11 |
| 12 namespace errors = extension_manifest_errors; | 12 namespace errors = extension_manifest_errors; |
| 13 | 13 |
| 14 TEST_F(ExtensionManifestTest, ManifestVersionWarning) { | 14 TEST_F(ExtensionManifestTest, ManifestVersionError) { |
| 15 scoped_ptr<DictionaryValue> manifest1(new DictionaryValue()); | 15 scoped_ptr<DictionaryValue> manifest1(new DictionaryValue()); |
| 16 manifest1->SetString("name", "Miles"); | 16 manifest1->SetString("name", "Miles"); |
| 17 manifest1->SetString("version", "0.55"); | 17 manifest1->SetString("version", "0.55"); |
| 18 | 18 |
| 19 scoped_ptr<DictionaryValue> manifest2(manifest1->DeepCopy()); | 19 scoped_ptr<DictionaryValue> manifest2(manifest1->DeepCopy()); |
| 20 manifest2->SetInteger("manifest_version", 1); | 20 manifest2->SetInteger("manifest_version", 1); |
| 21 | 21 |
| 22 scoped_ptr<DictionaryValue> manifest3(manifest1->DeepCopy()); | 22 scoped_ptr<DictionaryValue> manifest3(manifest1->DeepCopy()); |
| 23 manifest3->SetInteger("manifest_version", 2); | 23 manifest3->SetInteger("manifest_version", 2); |
| 24 | 24 |
| 25 struct { | 25 struct { |
| 26 const char* test_name; | 26 const char* test_name; |
| 27 bool require_modern_manifest_version; |
| 27 DictionaryValue* manifest; | 28 DictionaryValue* manifest; |
| 28 bool expect_warning; | 29 bool expect_error; |
| 29 } test_data[] = { | 30 } test_data[] = { |
| 30 { "default_manifest_version", manifest1.get(), true }, | 31 { "require_modern_with_default", true, manifest1.get(), true }, |
| 31 { "manifest_version_1", manifest2.get(), true }, | 32 { "require_modern_with_v1", true, manifest2.get(), true }, |
| 32 { "manifest_version_2", manifest3.get(), false } | 33 { "require_modern_with_v2", true, manifest3.get(), false }, |
| 34 { "dont_require_modern_with_default", false, manifest1.get(), false }, |
| 35 { "dont_require_modern_with_v1", false, manifest2.get(), false }, |
| 36 { "dont_require_modern_with_v2", false, manifest3.get(), false }, |
| 33 }; | 37 }; |
| 34 | 38 |
| 35 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { | 39 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { |
| 36 scoped_refptr<Extension> extension( | 40 int create_flags = Extension::NO_FLAGS; |
| 37 LoadAndExpectSuccess(Manifest(test_data[i].manifest, | 41 if (test_data[i].require_modern_manifest_version) |
| 38 test_data[i].test_name), | 42 create_flags |= Extension::REQUIRE_MODERN_MANIFEST_VERSION; |
| 39 Extension::LOAD)); | 43 if (test_data[i].expect_error) { |
| 40 if (test_data[i].expect_warning) { | 44 LoadAndExpectError( |
| 41 EXPECT_THAT( | 45 Manifest(test_data[i].manifest, |
| 42 extension->install_warnings(), | 46 test_data[i].test_name), |
| 43 testing::Contains( | 47 errors::kInvalidManifestVersionOld, |
| 44 testing::Field( | 48 Extension::LOAD, |
| 45 &Extension::InstallWarning::message, | 49 create_flags); |
| 46 testing::HasSubstr( | |
| 47 "Support for manifest version 1 is being phased out.")))) | |
| 48 << test_data[i].test_name; | |
| 49 } else { | 50 } else { |
| 50 EXPECT_THAT( | 51 LoadAndExpectSuccess(Manifest(test_data[i].manifest, |
| 51 extension->install_warnings(), | 52 test_data[i].test_name), |
| 52 testing::Not( | 53 Extension::LOAD, |
| 53 testing::Contains( | 54 create_flags); |
| 54 testing::Field( | |
| 55 &Extension::InstallWarning::message, | |
| 56 testing::HasSubstr( | |
| 57 "Support for manifest version 1 is being phased " | |
| 58 "out."))))) | |
| 59 << test_data[i].test_name; | |
| 60 } | 55 } |
| 61 } | 56 } |
| 62 } | 57 } |
| OLD | NEW |