| 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" |
| 9 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/values.h" | 10 #include "base/values.h" |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "chrome/common/extensions/extension.h" | 11 #include "chrome/common/extensions/extension.h" |
| 11 #include "chrome/common/extensions/extension_manifest_constants.h" | 12 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 12 #include "chrome/common/extensions/features/feature.h" | 13 #include "chrome/common/extensions/features/feature.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 15 |
| 15 namespace errors = extension_manifest_errors; | 16 namespace errors = extension_manifest_errors; |
| 16 namespace keys = extension_manifest_keys; | 17 namespace keys = extension_manifest_keys; |
| 17 | 18 |
| 18 class ExtensionManifestTest : public testing::Test { | 19 class ExtensionManifestTest : public testing::Test { |
| 19 public: | 20 public: |
| 20 ExtensionManifestTest(); | 21 ExtensionManifestTest(); |
| 21 | 22 |
| 22 protected: | 23 protected: |
| 23 // If filename is a relative path, LoadManifestFile will treat it relative to | |
| 24 // the appropriate test directory. | |
| 25 static DictionaryValue* LoadManifestFile(const std::string& filename, | |
| 26 std::string* error); | |
| 27 | |
| 28 // Helper class that simplifies creating methods that take either a filename | 24 // Helper class that simplifies creating methods that take either a filename |
| 29 // to a manifest or the manifest itself. | 25 // to a manifest or the manifest itself. |
| 30 class Manifest { | 26 class Manifest { |
| 31 public: | 27 public: |
| 32 explicit Manifest(const char* name); | 28 explicit Manifest(const char* name); |
| 33 Manifest(DictionaryValue* manifest, const char* name); | 29 Manifest(DictionaryValue* manifest, const char* name); |
| 34 // C++98 requires the copy constructor for a type to be visible if you | 30 // C++98 requires the copy constructor for a type to be visible if you |
| 35 // take a const-ref of a temporary for that type. Since Manifest | 31 // take a const-ref of a temporary for that type. Since Manifest |
| 36 // contains a scoped_ptr, its implicit copy constructor is declared | 32 // contains a scoped_ptr, its implicit copy constructor is declared |
| 37 // Manifest(Manifest&) according to spec 12.8.5. This breaks the first | 33 // Manifest(Manifest&) according to spec 12.8.5. This breaks the first |
| 38 // requirement and thus you cannot use it with LoadAndExpectError() or | 34 // requirement and thus you cannot use it with LoadAndExpectError() or |
| 39 // LoadAndExpectSuccess() easily. | 35 // LoadAndExpectSuccess() easily. |
| 40 // | 36 // |
| 41 // To get around this spec pedantry, we declare the copy constructor | 37 // To get around this spec pedantry, we declare the copy constructor |
| 42 // explicitly. It will never get invoked. | 38 // explicitly. It will never get invoked. |
| 43 Manifest(const Manifest& m); | 39 Manifest(const Manifest& m); |
| 44 | 40 |
| 45 ~Manifest(); | 41 ~Manifest(); |
| 46 | 42 |
| 47 const std::string& name() const { return name_; }; | 43 const std::string& name() const { return name_; }; |
| 48 | 44 |
| 49 DictionaryValue* GetManifest(std::string* error) const; | 45 DictionaryValue* GetManifest(char const* test_data_dir, |
| 46 std::string* error) const; |
| 50 | 47 |
| 51 private: | 48 private: |
| 52 const std::string name_; | 49 const std::string name_; |
| 53 mutable DictionaryValue* manifest_; | 50 mutable DictionaryValue* manifest_; |
| 54 mutable scoped_ptr<DictionaryValue> manifest_holder_; | 51 mutable scoped_ptr<DictionaryValue> manifest_holder_; |
| 55 }; | 52 }; |
| 56 | 53 |
| 54 // The subdirectory in which to find test data files. |
| 55 virtual char const* test_data_dir() { |
| 56 return "manifest_tests"; |
| 57 } |
| 58 |
| 59 scoped_ptr<DictionaryValue> LoadManifest( |
| 60 char const* manifest_name, |
| 61 std::string* error); |
| 62 |
| 57 scoped_refptr<extensions::Extension> LoadExtension( | 63 scoped_refptr<extensions::Extension> LoadExtension( |
| 58 const Manifest& manifest, | 64 const Manifest& manifest, |
| 59 std::string* error, | 65 std::string* error, |
| 60 extensions::Extension::Location location = | 66 extensions::Extension::Location location = |
| 61 extensions::Extension::INTERNAL, | 67 extensions::Extension::INTERNAL, |
| 62 int flags = extensions::Extension::NO_FLAGS); | 68 int flags = extensions::Extension::NO_FLAGS); |
| 63 | 69 |
| 64 scoped_refptr<extensions::Extension> LoadAndExpectSuccess( | 70 scoped_refptr<extensions::Extension> LoadAndExpectSuccess( |
| 65 const Manifest& manifest, | 71 const Manifest& manifest, |
| 66 extensions::Extension::Location location = | 72 extensions::Extension::Location location = |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 // Force the manifest tests to run as though they are on trunk, since several | 147 // Force the manifest tests to run as though they are on trunk, since several |
| 142 // tests rely on manifest features being available that aren't on | 148 // tests rely on manifest features being available that aren't on |
| 143 // stable/beta. | 149 // stable/beta. |
| 144 // | 150 // |
| 145 // These objects nest, so if a test wants to explicitly test the behaviour | 151 // These objects nest, so if a test wants to explicitly test the behaviour |
| 146 // on stable or beta, declare it inside that test. | 152 // on stable or beta, declare it inside that test. |
| 147 extensions::Feature::ScopedCurrentChannel current_channel_; | 153 extensions::Feature::ScopedCurrentChannel current_channel_; |
| 148 }; | 154 }; |
| 149 | 155 |
| 150 #endif // CHROME_COMMON_EXTENSIONS_MANIFEST_TESTS_EXTENSION_MANIFEST_TEST_H_ | 156 #endif // CHROME_COMMON_EXTENSIONS_MANIFEST_TESTS_EXTENSION_MANIFEST_TEST_H_ |
| OLD | NEW |