| 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.h" | 5 #include "chrome/common/extensions/manifest.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 // Only supported in manifest_version=1. | 61 // Only supported in manifest_version=1. |
| 62 manifest_value->SetString(keys::kBackgroundPageLegacy, "bg.html"); | 62 manifest_value->SetString(keys::kBackgroundPageLegacy, "bg.html"); |
| 63 manifest_value->SetString("unknown_key", "foo"); | 63 manifest_value->SetString("unknown_key", "foo"); |
| 64 | 64 |
| 65 scoped_ptr<Manifest> manifest( | 65 scoped_ptr<Manifest> manifest( |
| 66 new Manifest(Extension::INTERNAL, manifest_value.Pass())); | 66 new Manifest(Extension::INTERNAL, manifest_value.Pass())); |
| 67 std::string error; | 67 std::string error; |
| 68 std::vector<std::string> warnings; | 68 std::vector<std::string> warnings; |
| 69 manifest->ValidateManifest(&error, &warnings); | 69 manifest->ValidateManifest(&error, &warnings); |
| 70 EXPECT_TRUE(error.empty()); | 70 EXPECT_TRUE(error.empty()); |
| 71 EXPECT_TRUE(warnings.empty()); | 71 ASSERT_EQ(1u, warnings.size()); |
| 72 AssertType(manifest.get(), Extension::TYPE_EXTENSION); | 72 AssertType(manifest.get(), Extension::TYPE_EXTENSION); |
| 73 | 73 |
| 74 // The known key 'background_page' should be accessible. | 74 // The known key 'background_page' should be accessible. |
| 75 std::string value; | 75 std::string value; |
| 76 EXPECT_TRUE(manifest->GetString(keys::kBackgroundPageLegacy, &value)); | 76 EXPECT_TRUE(manifest->GetString(keys::kBackgroundPageLegacy, &value)); |
| 77 EXPECT_EQ("bg.html", value); | 77 EXPECT_EQ("bg.html", value); |
| 78 | 78 |
| 79 // The unknown key 'unknown_key' should be accesible. | 79 // The unknown key 'unknown_key' should be accesible. |
| 80 value.clear(); | 80 value.clear(); |
| 81 EXPECT_TRUE(manifest->GetString("unknown_key", &value)); | 81 EXPECT_TRUE(manifest->GetString("unknown_key", &value)); |
| 82 EXPECT_EQ("foo", value); | 82 EXPECT_EQ("foo", value); |
| 83 | 83 |
| 84 // Set the manifest_version to 2; background_page should stop working. | 84 // Set the manifest_version to 2; background_page should stop working. |
| 85 value.clear(); | 85 value.clear(); |
| 86 MutateManifest( | 86 MutateManifest( |
| 87 &manifest, keys::kManifestVersion, Value::CreateIntegerValue(2)); | 87 &manifest, keys::kManifestVersion, Value::CreateIntegerValue(2)); |
| 88 EXPECT_FALSE(manifest->GetString("background_page", &value)); | 88 EXPECT_FALSE(manifest->GetString("background_page", &value)); |
| 89 EXPECT_EQ("", value); | 89 EXPECT_EQ("", value); |
| 90 | 90 |
| 91 // Validate should also give a warning. | 91 // Validate should also give a warning. |
| 92 warnings.clear(); | 92 warnings.clear(); |
| 93 manifest->ValidateManifest(&error, &warnings); | 93 manifest->ValidateManifest(&error, &warnings); |
| 94 EXPECT_TRUE(error.empty()); | 94 EXPECT_TRUE(error.empty()); |
| 95 ASSERT_EQ(1u, warnings.size()); | 95 ASSERT_EQ(2u, warnings.size()); |
| 96 { | 96 { |
| 97 Feature feature; | 97 Feature feature; |
| 98 feature.set_name("background_page"); | 98 feature.set_name("background_page"); |
| 99 feature.set_max_manifest_version(1); | 99 feature.set_max_manifest_version(1); |
| 100 EXPECT_EQ(feature.GetErrorMessage(Feature::INVALID_MAX_MANIFEST_VERSION), | 100 EXPECT_EQ(feature.GetErrorMessage(Feature::INVALID_MAX_MANIFEST_VERSION), |
| 101 warnings[0]); | 101 warnings[0]); |
| 102 } | 102 } |
| 103 | 103 |
| 104 // Test DeepCopy and Equals. | 104 // Test DeepCopy and Equals. |
| 105 scoped_ptr<Manifest> manifest2(manifest->DeepCopy()); | 105 scoped_ptr<Manifest> manifest2(manifest->DeepCopy()); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 EXPECT_FALSE(manifest->HasKey(keys::kCommands)); | 201 EXPECT_FALSE(manifest->HasKey(keys::kCommands)); |
| 202 EXPECT_FALSE(manifest->Get(keys::kCommands, &output)); | 202 EXPECT_FALSE(manifest->Get(keys::kCommands, &output)); |
| 203 | 203 |
| 204 MutateManifest( | 204 MutateManifest( |
| 205 &manifest, keys::kManifestVersion, Value::CreateIntegerValue(2)); | 205 &manifest, keys::kManifestVersion, Value::CreateIntegerValue(2)); |
| 206 EXPECT_TRUE(manifest->HasKey(keys::kCommands)); | 206 EXPECT_TRUE(manifest->HasKey(keys::kCommands)); |
| 207 EXPECT_TRUE(manifest->Get(keys::kCommands, &output)); | 207 EXPECT_TRUE(manifest->Get(keys::kCommands, &output)); |
| 208 }; | 208 }; |
| 209 | 209 |
| 210 } // namespace extensions | 210 } // namespace extensions |
| OLD | NEW |