Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / extensions / common / manifest_test.h
blobcf416ce6160d27d1a90dc146020249d6b50d9ffe
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 EXTENSIONS_COMMON_MANIFEST_TEST_H_
6 #define EXTENSIONS_COMMON_MANIFEST_TEST_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/values.h"
11 #include "extensions/common/extension.h"
12 #include "extensions/common/manifest.h"
13 #include "testing/gtest/include/gtest/gtest.h"
15 namespace base {
16 class FilePath;
19 namespace extensions {
21 // Base class for tests that parse a manifest file.
22 class ManifestTest : public testing::Test {
23 public:
24 ManifestTest();
25 ~ManifestTest() override;
27 protected:
28 // Helper class that simplifies creating methods that take either a filename
29 // to a manifest or the manifest itself.
30 class ManifestData {
31 public:
32 explicit ManifestData(const char* name);
33 ManifestData(base::DictionaryValue* manifest, const char* name);
34 explicit ManifestData(scoped_ptr<base::DictionaryValue> manifest);
35 // C++98 requires the copy constructor for a type to be visible if you
36 // take a const-ref of a temporary for that type. Since Manifest
37 // contains a scoped_ptr, its implicit copy constructor is declared
38 // Manifest(Manifest&) according to spec 12.8.5. This breaks the first
39 // requirement and thus you cannot use it with LoadAndExpectError() or
40 // LoadAndExpectSuccess() easily.
42 // To get around this spec pedantry, we declare the copy constructor
43 // explicitly. It will never get invoked.
44 ManifestData(const ManifestData& m);
46 ~ManifestData();
48 const std::string& name() const { return name_; };
50 base::DictionaryValue* GetManifest(base::FilePath manifest_path,
51 std::string* error) const;
53 private:
54 const std::string name_;
55 mutable base::DictionaryValue* manifest_;
56 mutable scoped_ptr<base::DictionaryValue> manifest_holder_;
59 // Allows the test implementation to override a loaded test manifest's
60 // extension ID. Useful for testing features behind a whitelist.
61 virtual std::string GetTestExtensionID() const;
63 // Returns the path in which to find test manifest data files, for example
64 // extensions/test/data/manifest_tests.
65 virtual base::FilePath GetTestDataDir();
67 scoped_ptr<base::DictionaryValue> LoadManifest(
68 char const* manifest_name,
69 std::string* error);
71 scoped_refptr<extensions::Extension> LoadExtension(
72 const ManifestData& manifest,
73 std::string* error,
74 extensions::Manifest::Location location =
75 extensions::Manifest::INTERNAL,
76 int flags = extensions::Extension::NO_FLAGS);
78 scoped_refptr<extensions::Extension> LoadAndExpectSuccess(
79 const ManifestData& manifest,
80 extensions::Manifest::Location location =
81 extensions::Manifest::INTERNAL,
82 int flags = extensions::Extension::NO_FLAGS);
84 scoped_refptr<extensions::Extension> LoadAndExpectSuccess(
85 char const* manifest_name,
86 extensions::Manifest::Location location =
87 extensions::Manifest::INTERNAL,
88 int flags = extensions::Extension::NO_FLAGS);
90 scoped_refptr<extensions::Extension> LoadAndExpectWarning(
91 const ManifestData& manifest,
92 const std::string& expected_error,
93 extensions::Manifest::Location location =
94 extensions::Manifest::INTERNAL,
95 int flags = extensions::Extension::NO_FLAGS);
97 scoped_refptr<extensions::Extension> LoadAndExpectWarning(
98 char const* manifest_name,
99 const std::string& expected_error,
100 extensions::Manifest::Location location =
101 extensions::Manifest::INTERNAL,
102 int flags = extensions::Extension::NO_FLAGS);
104 void VerifyExpectedError(extensions::Extension* extension,
105 const std::string& name,
106 const std::string& error,
107 const std::string& expected_error);
109 void LoadAndExpectError(char const* manifest_name,
110 const std::string& expected_error,
111 extensions::Manifest::Location location =
112 extensions::Manifest::INTERNAL,
113 int flags = extensions::Extension::NO_FLAGS);
115 void LoadAndExpectError(const ManifestData& manifest,
116 const std::string& expected_error,
117 extensions::Manifest::Location location =
118 extensions::Manifest::INTERNAL,
119 int flags = extensions::Extension::NO_FLAGS);
121 void AddPattern(extensions::URLPatternSet* extent,
122 const std::string& pattern);
124 // used to differentiate between calls to LoadAndExpectError,
125 // LoadAndExpectWarning and LoadAndExpectSuccess via function RunTestcases.
126 enum ExpectType {
127 EXPECT_TYPE_ERROR,
128 EXPECT_TYPE_WARNING,
129 EXPECT_TYPE_SUCCESS
132 struct Testcase {
133 std::string manifest_filename_;
134 std::string expected_error_; // only used for ExpectedError tests
135 extensions::Manifest::Location location_;
136 int flags_;
138 Testcase(std::string manifest_filename, std::string expected_error,
139 extensions::Manifest::Location location, int flags);
141 Testcase(std::string manifest_filename, std::string expected_error);
143 explicit Testcase(std::string manifest_filename);
145 Testcase(std::string manifest_filename,
146 extensions::Manifest::Location location,
147 int flags);
150 void RunTestcases(const Testcase* testcases,
151 size_t num_testcases,
152 ExpectType type);
154 void RunTestcase(const Testcase& testcase, ExpectType type);
156 bool enable_apps_;
158 private:
159 DISALLOW_COPY_AND_ASSIGN(ManifestTest);
162 } // namespace extensions
164 #endif // EXTENSIONS_COMMON_MANIFEST_TEST_H_