OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_TEST_UTILS_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_TEST_UTILS_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_TEST_UTILS_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_TEST_UTILS_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 // Creates an extension instance that can be attached to an ExtensionFunction | 42 // Creates an extension instance that can be attached to an ExtensionFunction |
43 // before running it. | 43 // before running it. |
44 scoped_refptr<Extension> CreateEmptyExtension(); | 44 scoped_refptr<Extension> CreateEmptyExtension(); |
45 | 45 |
46 enum RunFunctionFlags { | 46 enum RunFunctionFlags { |
47 NONE = 0, | 47 NONE = 0, |
48 INCLUDE_INCOGNITO = 1 << 0 | 48 INCLUDE_INCOGNITO = 1 << 0 |
49 }; | 49 }; |
50 | 50 |
51 // Run |function| with |args| and return the resulting error. Adds an error to | 51 // Run |function| with |args| and return the resulting error. Adds an error to |
52 // the current test if |function| returns a result. The caller releases | 52 // the current test if |function| returns a result. |
53 // ownership of |function|. | |
54 std::string RunFunctionAndReturnError(UIThreadExtensionFunction* function, | 53 std::string RunFunctionAndReturnError(UIThreadExtensionFunction* function, |
55 const std::string& args, | 54 const std::string& args, |
56 Browser* browser, | 55 Browser* browser, |
57 RunFunctionFlags flags); | 56 RunFunctionFlags flags); |
58 std::string RunFunctionAndReturnError(UIThreadExtensionFunction* function, | 57 std::string RunFunctionAndReturnError(UIThreadExtensionFunction* function, |
59 const std::string& args, | 58 const std::string& args, |
60 Browser* browser); | 59 Browser* browser); |
61 | 60 |
62 // Run |function| with |args| and return the result. Adds an error to the | 61 // Run |function| with |args| and return the result. Adds an error to the |
63 // current test if |function| returns an error. The caller releases ownership of | 62 // current test if |function| returns an error. The caller takes ownership of |
64 // |function|. the caller takes ownership of the result. | 63 // the result. |
65 base::Value* RunFunctionAndReturnResult(UIThreadExtensionFunction* function, | 64 base::Value* RunFunctionAndReturnResult(UIThreadExtensionFunction* function, |
66 const std::string& args, | 65 const std::string& args, |
67 Browser* browser, | 66 Browser* browser, |
68 RunFunctionFlags flags); | 67 RunFunctionFlags flags); |
69 base::Value* RunFunctionAndReturnResult(UIThreadExtensionFunction* function, | 68 base::Value* RunFunctionAndReturnResult(UIThreadExtensionFunction* function, |
70 const std::string& args, | 69 const std::string& args, |
71 Browser* browser); | 70 Browser* browser); |
72 | 71 |
73 // Create and run |function| with |args|. The caller retains ownership of | 72 // Create and run |function| with |args|. Works with both synchronous and async |
74 // |function|. | 73 // functions. |
75 // | 74 // |
76 // TODO(aa): It would be nice if |args| could be validated against the schema | 75 // TODO(aa): It would be nice if |args| could be validated against the schema |
77 // that |function| expects. That way, we know that we are testing something | 76 // that |function| expects. That way, we know that we are testing something |
78 // close to what the bindings would actually send. | 77 // close to what the bindings would actually send. |
79 // | 78 // |
80 // TODO(aa): I'm concerned that this style won't scale to all the bits and bobs | 79 // TODO(aa): I'm concerned that this style won't scale to all the bits and bobs |
81 // we're going to need to frob for all the different extension functions. But we | 80 // we're going to need to frob for all the different extension functions. But |
82 // can refactor when we see what is needed. | 81 // we can refactor when we see what is needed. |
83 void RunFunction(UIThreadExtensionFunction* function, | 82 bool RunFunction(UIThreadExtensionFunction* function, |
84 const std::string& args, | 83 const std::string& args, |
85 Browser* browser, | 84 Browser* browser, |
86 RunFunctionFlags flags); | 85 RunFunctionFlags flags); |
87 | 86 |
88 // Similar to RunFunction, but doesn't return until |function| calls | |
89 // SendResponse. Returns the value |function| passed to SendResponse. | |
90 bool RunAsyncFunction(AsyncExtensionFunction* function, | |
91 const std::string& args, | |
92 Browser* browser, | |
93 RunFunctionFlags flags); | |
94 | |
95 } // namespace extension_function_test_utils | 87 } // namespace extension_function_test_utils |
96 | 88 |
97 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_TEST_UTILS_H_ | 89 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_TEST_UTILS_H_ |
OLD | NEW |