Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / common / extensions / manifest_tests / extension_manifest_test.h
blobd7169437cb4fb525a8747fef933662ee83ea04d7
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
3 // found in the LICENSE file.
5 #ifndef CHROME_COMMON_EXTENSIONS_MANIFEST_TESTS_EXTENSION_MANIFEST_TEST_H_
6 #define CHROME_COMMON_EXTENSIONS_MANIFEST_TESTS_EXTENSION_MANIFEST_TEST_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/values.h"
11 #include "chrome/common/extensions/features/feature_channel.h"
12 #include "extensions/common/extension.h"
13 #include "extensions/common/manifest.h"
14 #include "testing/gtest/include/gtest/gtest.h"
16 class ExtensionManifestTest : public testing::Test {
17 public:
18 ExtensionManifestTest();
20 protected:
21 // Helper class that simplifies creating methods that take either a filename
22 // to a manifest or the manifest itself.
23 class Manifest {
24 public:
25 explicit Manifest(const char* name);
26 Manifest(base::DictionaryValue* manifest, const char* name);
27 // 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 // contains a scoped_ptr, its implicit copy constructor is declared
30 // Manifest(Manifest&) according to spec 12.8.5. This breaks the first
31 // requirement and thus you cannot use it with LoadAndExpectError() or
32 // LoadAndExpectSuccess() easily.
34 // To get around this spec pedantry, we declare the copy constructor
35 // explicitly. It will never get invoked.
36 Manifest(const Manifest& m);
38 ~Manifest();
40 const std::string& name() const { return name_; };
42 base::DictionaryValue* GetManifest(char const* test_data_dir,
43 std::string* error) const;
45 private:
46 const std::string name_;
47 mutable base::DictionaryValue* manifest_;
48 mutable scoped_ptr<base::DictionaryValue> manifest_holder_;
51 // The subdirectory in which to find test data files.
52 virtual char const* test_data_dir();
54 scoped_ptr<base::DictionaryValue> LoadManifest(
55 char const* manifest_name,
56 std::string* error);
58 scoped_refptr<extensions::Extension> LoadExtension(
59 const Manifest& manifest,
60 std::string* error,
61 extensions::Manifest::Location location =
62 extensions::Manifest::INTERNAL,
63 int flags = extensions::Extension::NO_FLAGS);
65 scoped_refptr<extensions::Extension> LoadAndExpectSuccess(
66 const Manifest& manifest,
67 extensions::Manifest::Location location =
68 extensions::Manifest::INTERNAL,
69 int flags = extensions::Extension::NO_FLAGS);
71 scoped_refptr<extensions::Extension> LoadAndExpectSuccess(
72 char const* manifest_name,
73 extensions::Manifest::Location location =
74 extensions::Manifest::INTERNAL,
75 int flags = extensions::Extension::NO_FLAGS);
77 scoped_refptr<extensions::Extension> LoadAndExpectWarning(
78 const Manifest& manifest,
79 const std::string& expected_error,
80 extensions::Manifest::Location location =
81 extensions::Manifest::INTERNAL,
82 int flags = extensions::Extension::NO_FLAGS);
84 scoped_refptr<extensions::Extension> LoadAndExpectWarning(
85 char const* manifest_name,
86 const std::string& expected_error,
87 extensions::Manifest::Location location =
88 extensions::Manifest::INTERNAL,
89 int flags = extensions::Extension::NO_FLAGS);
91 void VerifyExpectedError(extensions::Extension* extension,
92 const std::string& name,
93 const std::string& error,
94 const std::string& expected_error);
96 void LoadAndExpectError(char const* manifest_name,
97 const std::string& expected_error,
98 extensions::Manifest::Location location =
99 extensions::Manifest::INTERNAL,
100 int flags = extensions::Extension::NO_FLAGS);
102 void LoadAndExpectError(const Manifest& manifest,
103 const std::string& expected_error,
104 extensions::Manifest::Location location =
105 extensions::Manifest::INTERNAL,
106 int flags = extensions::Extension::NO_FLAGS);
108 void AddPattern(extensions::URLPatternSet* extent,
109 const std::string& pattern);
111 // used to differentiate between calls to LoadAndExpectError,
112 // LoadAndExpectWarning and LoadAndExpectSuccess via function RunTestcases.
113 enum ExpectType {
114 EXPECT_TYPE_ERROR,
115 EXPECT_TYPE_WARNING,
116 EXPECT_TYPE_SUCCESS
119 struct Testcase {
120 std::string manifest_filename_;
121 std::string expected_error_; // only used for ExpectedError tests
122 extensions::Manifest::Location location_;
123 int flags_;
125 Testcase(std::string manifest_filename, std::string expected_error,
126 extensions::Manifest::Location location, int flags);
128 Testcase(std::string manifest_filename, std::string expected_error);
130 explicit Testcase(std::string manifest_filename);
132 Testcase(std::string manifest_filename,
133 extensions::Manifest::Location location,
134 int flags);
137 void RunTestcases(const Testcase* testcases,
138 size_t num_testcases,
139 ExpectType type);
141 void RunTestcase(const Testcase& testcase, ExpectType type);
143 bool enable_apps_;
145 // 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
147 // stable/beta.
149 // These objects nest, so if a test wants to explicitly test the behaviour
150 // on stable or beta, declare it inside that test.
151 extensions::ScopedCurrentChannel current_channel_;
154 #endif // CHROME_COMMON_EXTENSIONS_MANIFEST_TESTS_EXTENSION_MANIFEST_TEST_H_