blob: f19d506fabd5b9e2eabfe78e03a5af113fd1e4a8 [file] [log] [blame]
[email protected]6d2d55b2012-05-05 21:33:431// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]637bf322011-10-01 20:46:322// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_TEST_UTILS_H_
6#define CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_TEST_UTILS_H_
[email protected]637bf322011-10-01 20:46:327
8#include <string>
9
10#include "base/memory/ref_counted.h"
[email protected]d42c1112013-08-22 19:36:3211#include "extensions/common/manifest.h"
[email protected]4e3ce3b2011-10-14 23:25:1712
13class Browser;
[email protected]4e3ce3b2011-10-14 23:25:1714class UIThreadExtensionFunction;
[email protected]637bf322011-10-01 20:46:3215
16namespace base {
17class Value;
18class DictionaryValue;
19class ListValue;
20}
21
[email protected]1c321ee2012-05-21 03:02:3422namespace extensions {
23class Extension;
24}
25
[email protected]fc672e12014-08-16 08:16:1526// TODO(ckehoe): Accept args as scoped_ptr<base::Value>,
27// and migrate existing users to the new API.
yozb6272ef2014-08-28 02:23:0528// This file is DEPRECATED. New tests should use the versions in
29// extensions/browser/api_test_utils.h.
[email protected]637bf322011-10-01 20:46:3230namespace extension_function_test_utils {
31
32// Parse JSON and return as the specified type, or NULL if the JSON is invalid
33// or not the specified type.
34base::Value* ParseJSON(const std::string& data);
35base::ListValue* ParseList(const std::string& data);
[email protected]637bf322011-10-01 20:46:3236
37// If |val| is a dictionary, return it as one, otherwise NULL.
38base::DictionaryValue* ToDictionary(base::Value* val);
39
[email protected]008ff7fb2011-12-19 08:51:1740// If |val| is a list, return it as one, otherwise NULL.
41base::ListValue* ToList(base::Value* val);
42
[email protected]37bb5822012-09-10 15:09:5743// Returns true if |val| contains privacy information, e.g. url,
44// title, and faviconUrl.
45bool HasPrivacySensitiveFields(base::DictionaryValue* val);
46
[email protected]637bf322011-10-01 20:46:3247enum RunFunctionFlags {
48 NONE = 0,
49 INCLUDE_INCOGNITO = 1 << 0
50};
51
52// Run |function| with |args| and return the resulting error. Adds an error to
[email protected]4f9c79ec2013-03-21 04:41:3753// the current test if |function| returns a result. Takes ownership of
54// |function|.
[email protected]637bf322011-10-01 20:46:3255std::string RunFunctionAndReturnError(UIThreadExtensionFunction* function,
56 const std::string& args,
57 Browser* browser,
58 RunFunctionFlags flags);
59std::string RunFunctionAndReturnError(UIThreadExtensionFunction* function,
60 const std::string& args,
61 Browser* browser);
62
63// Run |function| with |args| and return the result. Adds an error to the
[email protected]4f9c79ec2013-03-21 04:41:3764// current test if |function| returns an error. Takes ownership of
65// |function|. The caller takes ownership of the result.
[email protected]07ff5fd2012-07-12 22:39:0966base::Value* RunFunctionAndReturnSingleResult(
67 UIThreadExtensionFunction* function,
68 const std::string& args,
69 Browser* browser,
70 RunFunctionFlags flags);
71base::Value* RunFunctionAndReturnSingleResult(
72 UIThreadExtensionFunction* function,
73 const std::string& args,
74 Browser* browser);
[email protected]637bf322011-10-01 20:46:3275
[email protected]bdfc03e2011-11-22 00:20:3376// Create and run |function| with |args|. Works with both synchronous and async
[email protected]4f9c79ec2013-03-21 04:41:3777// functions. Ownership of |function| remains with the caller.
[email protected]637bf322011-10-01 20:46:3278//
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.
82//
83// TODO(aa): I'm concerned that this style won't scale to all the bits and bobs
[email protected]bdfc03e2011-11-22 00:20:3384// we're going to need to frob for all the different extension functions. But
85// we can refactor when we see what is needed.
86bool RunFunction(UIThreadExtensionFunction* function,
[email protected]637bf322011-10-01 20:46:3287 const std::string& args,
88 Browser* browser,
89 RunFunctionFlags flags);
[email protected]fc672e12014-08-16 08:16:1590bool RunFunction(UIThreadExtensionFunction* function,
91 scoped_ptr<base::ListValue> args,
92 Browser* browser,
93 RunFunctionFlags flags);
[email protected]637bf322011-10-01 20:46:3294
[email protected]637bf322011-10-01 20:46:3295} // namespace extension_function_test_utils
96
97#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_TEST_UTILS_H_