OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/files/file_path.h" | 5 #include "base/files/file_path.h" |
6 #include "base/macros.h" | 6 #include "base/macros.h" |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "chrome/browser/extensions/extension_browsertest.h" | 8 #include "chrome/browser/extensions/extension_browsertest.h" |
9 #include "chrome/browser/extensions/test_extension_dir.h" | 9 #include "chrome/browser/extensions/test_extension_dir.h" |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 // have been cleared from the task queue. | 100 // have been cleared from the task queue. |
101 testing::AssertionResult RunTest(PermissionOrMatcherType manifest_permission, | 101 testing::AssertionResult RunTest(PermissionOrMatcherType manifest_permission, |
102 PermissionOrMatcherType script_matcher, | 102 PermissionOrMatcherType script_matcher, |
103 bool should_inject); | 103 bool should_inject); |
104 | 104 |
105 private: | 105 private: |
106 testing::AssertionResult CreateAndLoadExtension( | 106 testing::AssertionResult CreateAndLoadExtension( |
107 PermissionOrMatcherType manifest_permission, | 107 PermissionOrMatcherType manifest_permission, |
108 PermissionOrMatcherType script_matcher); | 108 PermissionOrMatcherType script_matcher); |
109 | 109 |
110 scoped_ptr<TestExtensionDir> test_extension_dir_; | 110 std::unique_ptr<TestExtensionDir> test_extension_dir_; |
111 const Extension* extension_; | 111 const Extension* extension_; |
112 }; | 112 }; |
113 | 113 |
114 RequestContentScriptAPITest::RequestContentScriptAPITest() | 114 RequestContentScriptAPITest::RequestContentScriptAPITest() |
115 : extension_(NULL) {} | 115 : extension_(NULL) {} |
116 | 116 |
117 testing::AssertionResult RequestContentScriptAPITest::RunTest( | 117 testing::AssertionResult RequestContentScriptAPITest::RunTest( |
118 PermissionOrMatcherType manifest_permission, | 118 PermissionOrMatcherType manifest_permission, |
119 PermissionOrMatcherType script_matcher, | 119 PermissionOrMatcherType script_matcher, |
120 bool should_inject) { | 120 bool should_inject) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 ExtensionTestMessageListener injection_setup_listener( | 164 ExtensionTestMessageListener injection_setup_listener( |
165 kInjectionSetup, | 165 kInjectionSetup, |
166 false /* won't reply */); | 166 false /* won't reply */); |
167 | 167 |
168 std::string manifest = base::StringPrintf(kManifest, | 168 std::string manifest = base::StringPrintf(kManifest, |
169 kPermissions[manifest_permission]); | 169 kPermissions[manifest_permission]); |
170 std::string background_src = base::StringPrintf( | 170 std::string background_src = base::StringPrintf( |
171 kBackgroundScriptSource, | 171 kBackgroundScriptSource, |
172 kScriptMatchers[script_matcher]); | 172 kScriptMatchers[script_matcher]); |
173 | 173 |
174 scoped_ptr<TestExtensionDir> dir(new TestExtensionDir); | 174 std::unique_ptr<TestExtensionDir> dir(new TestExtensionDir); |
175 dir->WriteManifest(manifest); | 175 dir->WriteManifest(manifest); |
176 dir->WriteFile(FILE_PATH_LITERAL("background.js"), background_src); | 176 dir->WriteFile(FILE_PATH_LITERAL("background.js"), background_src); |
177 dir->WriteFile(FILE_PATH_LITERAL("script.js"), | 177 dir->WriteFile(FILE_PATH_LITERAL("script.js"), |
178 kContentScriptSource); | 178 kContentScriptSource); |
179 | 179 |
180 const Extension* extension = LoadExtension(dir->unpacked_path()); | 180 const Extension* extension = LoadExtension(dir->unpacked_path()); |
181 if (!extension) | 181 if (!extension) |
182 return testing::AssertionFailure() << "Failed to load extension."; | 182 return testing::AssertionFailure() << "Failed to load extension."; |
183 | 183 |
184 test_extension_dir_.reset(dir.release()); | 184 test_extension_dir_.reset(dir.release()); |
(...skipping 30 matching lines...) Expand all Loading... |
215 EXPECT_TRUE(RunTest(PARTICULAR, NOWHERE, false)); | 215 EXPECT_TRUE(RunTest(PARTICULAR, NOWHERE, false)); |
216 | 216 |
217 // TODO(markdittmer): Add more tests: | 217 // TODO(markdittmer): Add more tests: |
218 // - Inject script with multiple files | 218 // - Inject script with multiple files |
219 // - Inject multiple scripts | 219 // - Inject multiple scripts |
220 // - Match on CSS selector conditions | 220 // - Match on CSS selector conditions |
221 // - Match all frames in document containing frames | 221 // - Match all frames in document containing frames |
222 } | 222 } |
223 | 223 |
224 } // namespace extensions | 224 } // namespace extensions |
OLD | NEW |