api_test_utils.h revision 5f1c94371a64b3196d4be9466099bb892df9b88e
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.
4
5#ifndef EXTENSIONS_BROWSER_API_TEST_UTILS_H_
6#define EXTENSIONS_BROWSER_API_TEST_UTILS_H_
7
8#include <string>
9
10#include "base/memory/scoped_ptr.h"
11
12class UIThreadExtensionFunction;
13
14namespace base {
15class Value;
16}
17
18namespace content {
19class BrowserContext;
20}
21
22namespace extensions {
23class ExtensionFunctionDispatcher;
24
25// TODO(yoz): crbug.com/394840: Remove duplicate functionality in
26// chrome/browser/extensions/extension_function_test_utils.h.
27namespace api_test_utils {
28
29enum RunFunctionFlags { NONE = 0, INCLUDE_INCOGNITO = 1 << 0 };
30
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
33// |function|. The caller takes ownership of the result.
34base::Value* RunFunctionAndReturnSingleResult(
35    UIThreadExtensionFunction* function,
36    const std::string& args,
37    content::BrowserContext* context,
38    scoped_ptr<ExtensionFunctionDispatcher> dispatcher);
39base::Value* RunFunctionAndReturnSingleResult(
40    UIThreadExtensionFunction* function,
41    const std::string& args,
42    content::BrowserContext* context,
43    scoped_ptr<ExtensionFunctionDispatcher> dispatcher,
44    RunFunctionFlags flags);
45
46// Create and run |function| with |args|. Works with both synchronous and async
47// functions. Ownership of |function| remains with the caller.
48//
49// 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
51// close to what the bindings would actually send.
52//
53// 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
55// we can refactor when we see what is needed.
56bool RunFunction(UIThreadExtensionFunction* function,
57                 const std::string& args,
58                 content::BrowserContext* context,
59                 scoped_ptr<ExtensionFunctionDispatcher> dispatcher,
60                 RunFunctionFlags flags);
61
62}  // namespace function_test_utils
63}  // namespace extensions
64
65#endif  // EXTENSIONS_BROWSER_API_TEST_UTILS_H_
66