blob: b1c76c47c3a46d49d79374daf6a708bb13828cbc [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"
Devlin Cronin35252c2b2018-02-14 00:03:5311#include "extensions/browser/api_test_utils.h"
[email protected]d42c1112013-08-22 19:36:3212#include "extensions/common/manifest.h"
[email protected]4e3ce3b2011-10-14 23:25:1713
14class Browser;
Clark DuVallfd4db3d2019-07-30 19:10:4315class ExtensionFunction;
[email protected]637bf322011-10-01 20:46:3216
17namespace base {
18class Value;
19class DictionaryValue;
20class ListValue;
21}
22
dchengc963c7142016-04-08 03:55:2223// TODO(ckehoe): Accept args as std::unique_ptr<base::Value>,
[email protected]fc672e12014-08-16 08:16:1524// and migrate existing users to the new API.
yozb6272ef2014-08-28 02:23:0525// This file is DEPRECATED. New tests should use the versions in
26// extensions/browser/api_test_utils.h.
[email protected]637bf322011-10-01 20:46:3227namespace extension_function_test_utils {
28
Devlin Cronin2e6f4f872017-10-03 00:07:2429// Parse JSON and return as a ListValue, or null if invalid.
[email protected]637bf322011-10-01 20:46:3230base::ListValue* ParseList(const std::string& data);
[email protected]637bf322011-10-01 20:46:3231
32// If |val| is a dictionary, return it as one, otherwise NULL.
33base::DictionaryValue* ToDictionary(base::Value* val);
34
[email protected]008ff7fb2011-12-19 08:51:1735// If |val| is a list, return it as one, otherwise NULL.
36base::ListValue* ToList(base::Value* val);
37
Tim Judkins92389f752019-09-20 21:04:1438// Returns true if |val| contains any privacy information, e.g. url,
39// pendingUrl, title or faviconUrl.
40bool HasAnyPrivacySensitiveFields(base::DictionaryValue* val);
[email protected]37bb5822012-09-10 15:09:5741
[email protected]637bf322011-10-01 20:46:3242// Run |function| with |args| and return the resulting error. Adds an error to
[email protected]4f9c79ec2013-03-21 04:41:3743// the current test if |function| returns a result. Takes ownership of
44// |function|.
Devlin Cronin35252c2b2018-02-14 00:03:5345std::string RunFunctionAndReturnError(
Clark DuVallfd4db3d2019-07-30 19:10:4346 ExtensionFunction* function,
Devlin Cronin35252c2b2018-02-14 00:03:5347 const std::string& args,
48 Browser* browser,
49 extensions::api_test_utils::RunFunctionFlags flags);
Clark DuVallfd4db3d2019-07-30 19:10:4350std::string RunFunctionAndReturnError(ExtensionFunction* function,
[email protected]637bf322011-10-01 20:46:3251 const std::string& args,
52 Browser* browser);
53
54// Run |function| with |args| and return the result. Adds an error to the
[email protected]4f9c79ec2013-03-21 04:41:3755// current test if |function| returns an error. Takes ownership of
56// |function|. The caller takes ownership of the result.
[email protected]07ff5fd2012-07-12 22:39:0957base::Value* RunFunctionAndReturnSingleResult(
Clark DuVallfd4db3d2019-07-30 19:10:4358 ExtensionFunction* function,
[email protected]07ff5fd2012-07-12 22:39:0959 const std::string& args,
60 Browser* browser,
Devlin Cronin35252c2b2018-02-14 00:03:5361 extensions::api_test_utils::RunFunctionFlags flags);
Clark DuVallfd4db3d2019-07-30 19:10:4362base::Value* RunFunctionAndReturnSingleResult(ExtensionFunction* function,
63 const std::string& args,
64 Browser* browser);
[email protected]637bf322011-10-01 20:46:3265
[email protected]bdfc03e2011-11-22 00:20:3366// Create and run |function| with |args|. Works with both synchronous and async
[email protected]4f9c79ec2013-03-21 04:41:3767// functions. Ownership of |function| remains with the caller.
[email protected]637bf322011-10-01 20:46:3268//
69// TODO(aa): It would be nice if |args| could be validated against the schema
70// that |function| expects. That way, we know that we are testing something
71// close to what the bindings would actually send.
72//
73// TODO(aa): I'm concerned that this style won't scale to all the bits and bobs
[email protected]bdfc03e2011-11-22 00:20:3374// we're going to need to frob for all the different extension functions. But
75// we can refactor when we see what is needed.
Clark DuVallfd4db3d2019-07-30 19:10:4376bool RunFunction(ExtensionFunction* function,
[email protected]637bf322011-10-01 20:46:3277 const std::string& args,
78 Browser* browser,
Devlin Cronin35252c2b2018-02-14 00:03:5379 extensions::api_test_utils::RunFunctionFlags flags);
Clark DuVallfd4db3d2019-07-30 19:10:4380bool RunFunction(ExtensionFunction* function,
dchengc963c7142016-04-08 03:55:2281 std::unique_ptr<base::ListValue> args,
[email protected]fc672e12014-08-16 08:16:1582 Browser* browser,
Devlin Cronin35252c2b2018-02-14 00:03:5383 extensions::api_test_utils::RunFunctionFlags flags);
[email protected]637bf322011-10-01 20:46:3284
[email protected]637bf322011-10-01 20:46:3285} // namespace extension_function_test_utils
86
87#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_TEST_UTILS_H_