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 #ifndef EXTENSIONS_BROWSER_API_TEST_UTILS_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_TEST_UTILS_H_ |
6 #define EXTENSIONS_BROWSER_API_TEST_UTILS_H_ | 6 #define EXTENSIONS_BROWSER_API_TEST_UTILS_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
| 10 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "extensions/common/extension.h" |
11 | 13 |
12 class UIThreadExtensionFunction; | 14 class UIThreadExtensionFunction; |
13 | 15 |
14 namespace base { | 16 namespace base { |
15 class Value; | 17 class Value; |
16 } | 18 } |
17 | 19 |
18 namespace content { | 20 namespace content { |
19 class BrowserContext; | 21 class BrowserContext; |
20 } | 22 } |
21 | 23 |
22 namespace extensions { | 24 namespace extensions { |
23 class ExtensionFunctionDispatcher; | 25 class ExtensionFunctionDispatcher; |
24 | 26 |
25 // TODO(yoz): crbug.com/394840: Remove duplicate functionality in | 27 // TODO(yoz): crbug.com/394840: Remove duplicate functionality in |
26 // chrome/browser/extensions/extension_function_test_utils.h. | 28 // chrome/browser/extensions/extension_function_test_utils.h. |
27 namespace api_test_utils { | 29 namespace api_test_utils { |
28 | 30 |
29 enum RunFunctionFlags { NONE = 0, INCLUDE_INCOGNITO = 1 << 0 }; | 31 enum RunFunctionFlags { NONE = 0, INCLUDE_INCOGNITO = 1 << 0 }; |
30 | 32 |
| 33 // Creates an extension instance that can be attached to an ExtensionFunction |
| 34 // before running it. |
| 35 scoped_refptr<Extension> CreateEmptyExtension(); |
| 36 |
31 // Run |function| with |args| and return the result. Adds an error to the | 37 // Run |function| with |args| and return the result. Adds an error to the |
32 // current test if |function| returns an error. Takes ownership of | 38 // current test if |function| returns an error. Takes ownership of |
33 // |function|. The caller takes ownership of the result. | 39 // |function|. The caller takes ownership of the result. |
34 base::Value* RunFunctionAndReturnSingleResult( | 40 base::Value* RunFunctionAndReturnSingleResult( |
35 UIThreadExtensionFunction* function, | 41 UIThreadExtensionFunction* function, |
36 const std::string& args, | 42 const std::string& args, |
37 content::BrowserContext* context, | 43 content::BrowserContext* context, |
38 scoped_ptr<ExtensionFunctionDispatcher> dispatcher); | 44 scoped_ptr<ExtensionFunctionDispatcher> dispatcher); |
39 base::Value* RunFunctionAndReturnSingleResult( | 45 base::Value* RunFunctionAndReturnSingleResult( |
40 UIThreadExtensionFunction* function, | 46 UIThreadExtensionFunction* function, |
41 const std::string& args, | 47 const std::string& args, |
42 content::BrowserContext* context, | 48 content::BrowserContext* context, |
43 scoped_ptr<ExtensionFunctionDispatcher> dispatcher, | 49 scoped_ptr<ExtensionFunctionDispatcher> dispatcher, |
44 RunFunctionFlags flags); | 50 RunFunctionFlags flags); |
45 | 51 |
| 52 // RunFunctionAndReturnSingleResult, except with a NULL implementation of the |
| 53 // Delegate. |
| 54 base::Value* RunDelegatelessFunctionAndReturnSingleResult( |
| 55 UIThreadExtensionFunction* function, |
| 56 const std::string& args, |
| 57 content::BrowserContext* context); |
| 58 base::Value* RunDelegatelessFunctionAndReturnSingleResult( |
| 59 UIThreadExtensionFunction* function, |
| 60 const std::string& args, |
| 61 content::BrowserContext* context, |
| 62 RunFunctionFlags flags); |
| 63 |
46 // Create and run |function| with |args|. Works with both synchronous and async | 64 // Create and run |function| with |args|. Works with both synchronous and async |
47 // functions. Ownership of |function| remains with the caller. | 65 // functions. Ownership of |function| remains with the caller. |
48 // | 66 // |
49 // TODO(aa): It would be nice if |args| could be validated against the schema | 67 // TODO(aa): It would be nice if |args| could be validated against the schema |
50 // that |function| expects. That way, we know that we are testing something | 68 // that |function| expects. That way, we know that we are testing something |
51 // close to what the bindings would actually send. | 69 // close to what the bindings would actually send. |
52 // | 70 // |
53 // TODO(aa): I'm concerned that this style won't scale to all the bits and bobs | 71 // TODO(aa): I'm concerned that this style won't scale to all the bits and bobs |
54 // we're going to need to frob for all the different extension functions. But | 72 // we're going to need to frob for all the different extension functions. But |
55 // we can refactor when we see what is needed. | 73 // we can refactor when we see what is needed. |
56 bool RunFunction(UIThreadExtensionFunction* function, | 74 bool RunFunction(UIThreadExtensionFunction* function, |
57 const std::string& args, | 75 const std::string& args, |
58 content::BrowserContext* context, | 76 content::BrowserContext* context, |
59 scoped_ptr<ExtensionFunctionDispatcher> dispatcher, | 77 scoped_ptr<ExtensionFunctionDispatcher> dispatcher, |
60 RunFunctionFlags flags); | 78 RunFunctionFlags flags); |
61 | 79 |
62 } // namespace function_test_utils | 80 } // namespace function_test_utils |
63 } // namespace extensions | 81 } // namespace extensions |
64 | 82 |
65 #endif // EXTENSIONS_BROWSER_API_TEST_UTILS_H_ | 83 #endif // EXTENSIONS_BROWSER_API_TEST_UTILS_H_ |
OLD | NEW |