1 // Copyright (c) 2012 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 CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_TEST_UTILS_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_TEST_UTILS_H_
10 #include "base/memory/ref_counted.h"
11 #include "extensions/common/manifest.h"
14 class UIThreadExtensionFunction
;
18 class DictionaryValue
;
22 namespace extensions
{
26 // TODO(ckehoe): Accept args as scoped_ptr<base::Value>,
27 // and migrate existing users to the new API.
28 // This file is DEPRECATED. New tests should use the versions in
29 // extensions/browser/api_test_utils.h.
30 namespace extension_function_test_utils
{
32 // Parse JSON and return as the specified type, or NULL if the JSON is invalid
33 // or not the specified type.
34 base::Value
* ParseJSON(const std::string
& data
);
35 base::ListValue
* ParseList(const std::string
& data
);
37 // If |val| is a dictionary, return it as one, otherwise NULL.
38 base::DictionaryValue
* ToDictionary(base::Value
* val
);
40 // If |val| is a list, return it as one, otherwise NULL.
41 base::ListValue
* ToList(base::Value
* val
);
43 // Returns true if |val| contains privacy information, e.g. url,
44 // title, and faviconUrl.
45 bool HasPrivacySensitiveFields(base::DictionaryValue
* val
);
47 enum RunFunctionFlags
{
49 INCLUDE_INCOGNITO
= 1 << 0
52 // Run |function| with |args| and return the resulting error. Adds an error to
53 // the current test if |function| returns a result. Takes ownership of
55 std::string
RunFunctionAndReturnError(UIThreadExtensionFunction
* function
,
56 const std::string
& args
,
58 RunFunctionFlags flags
);
59 std::string
RunFunctionAndReturnError(UIThreadExtensionFunction
* function
,
60 const std::string
& args
,
63 // Run |function| with |args| and return the result. Adds an error to the
64 // current test if |function| returns an error. Takes ownership of
65 // |function|. The caller takes ownership of the result.
66 base::Value
* RunFunctionAndReturnSingleResult(
67 UIThreadExtensionFunction
* function
,
68 const std::string
& args
,
70 RunFunctionFlags flags
);
71 base::Value
* RunFunctionAndReturnSingleResult(
72 UIThreadExtensionFunction
* function
,
73 const std::string
& args
,
76 // Create and run |function| with |args|. Works with both synchronous and async
77 // functions. Ownership of |function| remains with the caller.
79 // TODO(aa): It would be nice if |args| could be validated against the schema
80 // that |function| expects. That way, we know that we are testing something
81 // close to what the bindings would actually send.
83 // TODO(aa): I'm concerned that this style won't scale to all the bits and bobs
84 // we're going to need to frob for all the different extension functions. But
85 // we can refactor when we see what is needed.
86 bool RunFunction(UIThreadExtensionFunction
* function
,
87 const std::string
& args
,
89 RunFunctionFlags flags
);
90 bool RunFunction(UIThreadExtensionFunction
* function
,
91 scoped_ptr
<base::ListValue
> args
,
93 RunFunctionFlags flags
);
95 } // namespace extension_function_test_utils
97 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_TEST_UTILS_H_