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