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 #ifndef CHROME_COMMON_EXTENSIONS_MANIFEST_TESTS_EXTENSION_MANIFEST_TEST_H_ | 5 #ifndef CHROME_COMMON_EXTENSIONS_MANIFEST_TESTS_EXTENSION_MANIFEST_TEST_H_ |
6 #define CHROME_COMMON_EXTENSIONS_MANIFEST_TESTS_EXTENSION_MANIFEST_TEST_H_ | 6 #define CHROME_COMMON_EXTENSIONS_MANIFEST_TESTS_EXTENSION_MANIFEST_TEST_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/common/extensions/features/feature_channel.h" | 11 #include "chrome/common/extensions/features/feature_channel.h" |
12 #include "extensions/common/extension.h" | 12 #include "extensions/common/extension.h" |
13 #include "extensions/common/manifest.h" | 13 #include "extensions/common/manifest.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 | 15 |
16 class ExtensionManifestTest : public testing::Test { | 16 class ExtensionManifestTest : public testing::Test { |
17 public: | 17 public: |
18 ExtensionManifestTest(); | 18 ExtensionManifestTest(); |
19 | 19 |
20 protected: | 20 protected: |
21 // Helper class that simplifies creating methods that take either a filename | 21 // Helper class that simplifies creating methods that take either a filename |
22 // to a manifest or the manifest itself. | 22 // to a manifest or the manifest itself. |
23 class Manifest { | 23 class Manifest { |
24 public: | 24 public: |
25 explicit Manifest(const char* name); | 25 explicit Manifest(const char* name); |
26 Manifest(base::DictionaryValue* manifest, const char* name); | 26 Manifest(base::DictionaryValue* manifest, const char* name); |
| 27 explicit Manifest(scoped_ptr<base::DictionaryValue> manifest); |
27 // C++98 requires the copy constructor for a type to be visible if you | 28 // C++98 requires the copy constructor for a type to be visible if you |
28 // take a const-ref of a temporary for that type. Since Manifest | 29 // take a const-ref of a temporary for that type. Since Manifest |
29 // contains a scoped_ptr, its implicit copy constructor is declared | 30 // contains a scoped_ptr, its implicit copy constructor is declared |
30 // Manifest(Manifest&) according to spec 12.8.5. This breaks the first | 31 // Manifest(Manifest&) according to spec 12.8.5. This breaks the first |
31 // requirement and thus you cannot use it with LoadAndExpectError() or | 32 // requirement and thus you cannot use it with LoadAndExpectError() or |
32 // LoadAndExpectSuccess() easily. | 33 // LoadAndExpectSuccess() easily. |
33 // | 34 // |
34 // To get around this spec pedantry, we declare the copy constructor | 35 // To get around this spec pedantry, we declare the copy constructor |
35 // explicitly. It will never get invoked. | 36 // explicitly. It will never get invoked. |
36 Manifest(const Manifest& m); | 37 Manifest(const Manifest& m); |
(...skipping 30 matching lines...) Expand all Loading... |
67 extensions::Manifest::Location location = | 68 extensions::Manifest::Location location = |
68 extensions::Manifest::INTERNAL, | 69 extensions::Manifest::INTERNAL, |
69 int flags = extensions::Extension::NO_FLAGS); | 70 int flags = extensions::Extension::NO_FLAGS); |
70 | 71 |
71 scoped_refptr<extensions::Extension> LoadAndExpectSuccess( | 72 scoped_refptr<extensions::Extension> LoadAndExpectSuccess( |
72 char const* manifest_name, | 73 char const* manifest_name, |
73 extensions::Manifest::Location location = | 74 extensions::Manifest::Location location = |
74 extensions::Manifest::INTERNAL, | 75 extensions::Manifest::INTERNAL, |
75 int flags = extensions::Extension::NO_FLAGS); | 76 int flags = extensions::Extension::NO_FLAGS); |
76 | 77 |
| 78 // Load and expect success from a manifest provided as a json string. Single |
| 79 // quotes will be replaced with double quotes for test readability. |
| 80 scoped_refptr<extensions::Extension> LoadFromStringAndExpectSuccess( |
| 81 char const* manifest_json); |
| 82 |
77 scoped_refptr<extensions::Extension> LoadAndExpectWarning( | 83 scoped_refptr<extensions::Extension> LoadAndExpectWarning( |
78 const Manifest& manifest, | 84 const Manifest& manifest, |
79 const std::string& expected_error, | 85 const std::string& expected_error, |
80 extensions::Manifest::Location location = | 86 extensions::Manifest::Location location = |
81 extensions::Manifest::INTERNAL, | 87 extensions::Manifest::INTERNAL, |
82 int flags = extensions::Extension::NO_FLAGS); | 88 int flags = extensions::Extension::NO_FLAGS); |
83 | 89 |
84 scoped_refptr<extensions::Extension> LoadAndExpectWarning( | 90 scoped_refptr<extensions::Extension> LoadAndExpectWarning( |
85 char const* manifest_name, | 91 char const* manifest_name, |
86 const std::string& expected_error, | 92 const std::string& expected_error, |
(...skipping 11 matching lines...) Expand all Loading... |
98 extensions::Manifest::Location location = | 104 extensions::Manifest::Location location = |
99 extensions::Manifest::INTERNAL, | 105 extensions::Manifest::INTERNAL, |
100 int flags = extensions::Extension::NO_FLAGS); | 106 int flags = extensions::Extension::NO_FLAGS); |
101 | 107 |
102 void LoadAndExpectError(const Manifest& manifest, | 108 void LoadAndExpectError(const Manifest& manifest, |
103 const std::string& expected_error, | 109 const std::string& expected_error, |
104 extensions::Manifest::Location location = | 110 extensions::Manifest::Location location = |
105 extensions::Manifest::INTERNAL, | 111 extensions::Manifest::INTERNAL, |
106 int flags = extensions::Extension::NO_FLAGS); | 112 int flags = extensions::Extension::NO_FLAGS); |
107 | 113 |
| 114 // Load and expect an error from a manifest provided as a json string. Single |
| 115 // quotes will be replaced with double quotes for test readability. |
| 116 void LoadFromStringAndExpectError(char const* manifest_json, |
| 117 const std::string& expected_error); |
| 118 |
108 void AddPattern(extensions::URLPatternSet* extent, | 119 void AddPattern(extensions::URLPatternSet* extent, |
109 const std::string& pattern); | 120 const std::string& pattern); |
110 | 121 |
111 // used to differentiate between calls to LoadAndExpectError, | 122 // used to differentiate between calls to LoadAndExpectError, |
112 // LoadAndExpectWarning and LoadAndExpectSuccess via function RunTestcases. | 123 // LoadAndExpectWarning and LoadAndExpectSuccess via function RunTestcases. |
113 enum ExpectType { | 124 enum ExpectType { |
114 EXPECT_TYPE_ERROR, | 125 EXPECT_TYPE_ERROR, |
115 EXPECT_TYPE_WARNING, | 126 EXPECT_TYPE_WARNING, |
116 EXPECT_TYPE_SUCCESS | 127 EXPECT_TYPE_SUCCESS |
117 }; | 128 }; |
(...skipping 27 matching lines...) Expand all Loading... |
145 // Force the manifest tests to run as though they are on trunk, since several | 156 // Force the manifest tests to run as though they are on trunk, since several |
146 // tests rely on manifest features being available that aren't on | 157 // tests rely on manifest features being available that aren't on |
147 // stable/beta. | 158 // stable/beta. |
148 // | 159 // |
149 // These objects nest, so if a test wants to explicitly test the behaviour | 160 // These objects nest, so if a test wants to explicitly test the behaviour |
150 // on stable or beta, declare it inside that test. | 161 // on stable or beta, declare it inside that test. |
151 extensions::ScopedCurrentChannel current_channel_; | 162 extensions::ScopedCurrentChannel current_channel_; |
152 }; | 163 }; |
153 | 164 |
154 #endif // CHROME_COMMON_EXTENSIONS_MANIFEST_TESTS_EXTENSION_MANIFEST_TEST_H_ | 165 #endif // CHROME_COMMON_EXTENSIONS_MANIFEST_TESTS_EXTENSION_MANIFEST_TEST_H_ |
OLD | NEW |