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
3 // found in the LICENSE file.
5 #ifndef EXTENSIONS_BROWSER_API_TEST_UTILS_H_
6 #define EXTENSIONS_BROWSER_API_TEST_UTILS_H_
10 #include "base/memory/scoped_ptr.h"
12 class UIThreadExtensionFunction
;
23 namespace extensions
{
24 class ExtensionFunctionDispatcher
;
26 // TODO(yoz): crbug.com/394840: Remove duplicate functionality in
27 // chrome/browser/extensions/extension_function_test_utils.h.
29 // TODO(ckehoe): Accept args as scoped_ptr<base::Value>,
30 // and migrate existing users to the new API.
31 namespace api_test_utils
{
33 enum RunFunctionFlags
{ NONE
= 0, INCLUDE_INCOGNITO
= 1 << 0 };
35 // Run |function| with |args| and return the result. Adds an error to the
36 // current test if |function| returns an error. Takes ownership of
37 // |function|. The caller takes ownership of the result.
38 base::Value
* RunFunctionWithDelegateAndReturnSingleResult(
39 UIThreadExtensionFunction
* function
,
40 const std::string
& args
,
41 content::BrowserContext
* context
,
42 scoped_ptr
<ExtensionFunctionDispatcher
> dispatcher
);
43 base::Value
* RunFunctionWithDelegateAndReturnSingleResult(
44 UIThreadExtensionFunction
* function
,
45 const std::string
& args
,
46 content::BrowserContext
* context
,
47 scoped_ptr
<ExtensionFunctionDispatcher
> dispatcher
,
48 RunFunctionFlags flags
);
50 // RunFunctionWithDelegateAndReturnSingleResult, except with a NULL
51 // implementation of the Delegate.
52 base::Value
* RunFunctionAndReturnSingleResult(
53 UIThreadExtensionFunction
* function
,
54 const std::string
& args
,
55 content::BrowserContext
* context
);
56 base::Value
* RunFunctionAndReturnSingleResult(
57 UIThreadExtensionFunction
* function
,
58 const std::string
& args
,
59 content::BrowserContext
* context
,
60 RunFunctionFlags flags
);
62 // Run |function| with |args| and return the resulting error. Adds an error to
63 // the current test if |function| returns a result. Takes ownership of
65 std::string
RunFunctionAndReturnError(UIThreadExtensionFunction
* function
,
66 const std::string
& args
,
67 content::BrowserContext
* context
,
68 RunFunctionFlags flags
);
69 std::string
RunFunctionAndReturnError(UIThreadExtensionFunction
* function
,
70 const std::string
& args
,
71 content::BrowserContext
* context
);
73 // Create and run |function| with |args|. Works with both synchronous and async
74 // functions. Ownership of |function| remains with the caller.
76 // 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
78 // close to what the bindings would actually send.
80 // 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
82 // we can refactor when we see what is needed.
83 bool RunFunction(UIThreadExtensionFunction
* function
,
84 const std::string
& args
,
85 content::BrowserContext
* context
,
86 scoped_ptr
<ExtensionFunctionDispatcher
> dispatcher
,
87 RunFunctionFlags flags
);
88 bool RunFunction(UIThreadExtensionFunction
* function
,
89 scoped_ptr
<base::ListValue
> args
,
90 content::BrowserContext
* context
,
91 scoped_ptr
<ExtensionFunctionDispatcher
> dispatcher
,
92 RunFunctionFlags flags
);
94 } // namespace function_test_utils
95 } // namespace extensions
97 #endif // EXTENSIONS_BROWSER_API_TEST_UTILS_H_