[email protected] | 6d2d55b | 2012-05-05 21:33:43 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 637bf32 | 2011-10-01 20:46:32 | [diff] [blame] | 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 CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_TEST_UTILS_H_ |
| 6 | #define CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_TEST_UTILS_H_ |
[email protected] | 637bf32 | 2011-10-01 20:46:32 | [diff] [blame] | 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | #include "base/memory/ref_counted.h" |
Devlin Cronin | 35252c2b | 2018-02-14 00:03:53 | [diff] [blame] | 11 | #include "extensions/browser/api_test_utils.h" |
[email protected] | d42c111 | 2013-08-22 19:36:32 | [diff] [blame] | 12 | #include "extensions/common/manifest.h" |
[email protected] | 4e3ce3b | 2011-10-14 23:25:17 | [diff] [blame] | 13 | |
| 14 | class Browser; |
Clark DuVall | fd4db3d | 2019-07-30 19:10:43 | [diff] [blame] | 15 | class ExtensionFunction; |
[email protected] | 637bf32 | 2011-10-01 20:46:32 | [diff] [blame] | 16 | |
| 17 | namespace base { |
| 18 | class Value; |
| 19 | class DictionaryValue; |
| 20 | class ListValue; |
| 21 | } |
| 22 | |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 23 | // TODO(ckehoe): Accept args as std::unique_ptr<base::Value>, |
[email protected] | fc672e1 | 2014-08-16 08:16:15 | [diff] [blame] | 24 | // and migrate existing users to the new API. |
yoz | b6272ef | 2014-08-28 02:23:05 | [diff] [blame] | 25 | // This file is DEPRECATED. New tests should use the versions in |
| 26 | // extensions/browser/api_test_utils.h. |
[email protected] | 637bf32 | 2011-10-01 20:46:32 | [diff] [blame] | 27 | namespace extension_function_test_utils { |
| 28 | |
Devlin Cronin | 2e6f4f87 | 2017-10-03 00:07:24 | [diff] [blame] | 29 | // Parse JSON and return as a ListValue, or null if invalid. |
[email protected] | 637bf32 | 2011-10-01 20:46:32 | [diff] [blame] | 30 | base::ListValue* ParseList(const std::string& data); |
[email protected] | 637bf32 | 2011-10-01 20:46:32 | [diff] [blame] | 31 | |
| 32 | // If |val| is a dictionary, return it as one, otherwise NULL. |
| 33 | base::DictionaryValue* ToDictionary(base::Value* val); |
| 34 | |
[email protected] | 008ff7fb | 2011-12-19 08:51:17 | [diff] [blame] | 35 | // If |val| is a list, return it as one, otherwise NULL. |
| 36 | base::ListValue* ToList(base::Value* val); |
| 37 | |
Tim Judkins | 92389f75 | 2019-09-20 21:04:14 | [diff] [blame] | 38 | // Returns true if |val| contains any privacy information, e.g. url, |
| 39 | // pendingUrl, title or faviconUrl. |
| 40 | bool HasAnyPrivacySensitiveFields(base::DictionaryValue* val); |
[email protected] | 37bb582 | 2012-09-10 15:09:57 | [diff] [blame] | 41 | |
[email protected] | 637bf32 | 2011-10-01 20:46:32 | [diff] [blame] | 42 | // Run |function| with |args| and return the resulting error. Adds an error to |
[email protected] | 4f9c79ec | 2013-03-21 04:41:37 | [diff] [blame] | 43 | // the current test if |function| returns a result. Takes ownership of |
| 44 | // |function|. |
Devlin Cronin | 35252c2b | 2018-02-14 00:03:53 | [diff] [blame] | 45 | std::string RunFunctionAndReturnError( |
Clark DuVall | fd4db3d | 2019-07-30 19:10:43 | [diff] [blame] | 46 | ExtensionFunction* function, |
Devlin Cronin | 35252c2b | 2018-02-14 00:03:53 | [diff] [blame] | 47 | const std::string& args, |
| 48 | Browser* browser, |
| 49 | extensions::api_test_utils::RunFunctionFlags flags); |
Clark DuVall | fd4db3d | 2019-07-30 19:10:43 | [diff] [blame] | 50 | std::string RunFunctionAndReturnError(ExtensionFunction* function, |
[email protected] | 637bf32 | 2011-10-01 20:46:32 | [diff] [blame] | 51 | const std::string& args, |
| 52 | Browser* browser); |
| 53 | |
| 54 | // Run |function| with |args| and return the result. Adds an error to the |
[email protected] | 4f9c79ec | 2013-03-21 04:41:37 | [diff] [blame] | 55 | // current test if |function| returns an error. Takes ownership of |
| 56 | // |function|. The caller takes ownership of the result. |
[email protected] | 07ff5fd | 2012-07-12 22:39:09 | [diff] [blame] | 57 | base::Value* RunFunctionAndReturnSingleResult( |
Clark DuVall | fd4db3d | 2019-07-30 19:10:43 | [diff] [blame] | 58 | ExtensionFunction* function, |
[email protected] | 07ff5fd | 2012-07-12 22:39:09 | [diff] [blame] | 59 | const std::string& args, |
| 60 | Browser* browser, |
Devlin Cronin | 35252c2b | 2018-02-14 00:03:53 | [diff] [blame] | 61 | extensions::api_test_utils::RunFunctionFlags flags); |
Clark DuVall | fd4db3d | 2019-07-30 19:10:43 | [diff] [blame] | 62 | base::Value* RunFunctionAndReturnSingleResult(ExtensionFunction* function, |
| 63 | const std::string& args, |
| 64 | Browser* browser); |
[email protected] | 637bf32 | 2011-10-01 20:46:32 | [diff] [blame] | 65 | |
[email protected] | bdfc03e | 2011-11-22 00:20:33 | [diff] [blame] | 66 | // Create and run |function| with |args|. Works with both synchronous and async |
[email protected] | 4f9c79ec | 2013-03-21 04:41:37 | [diff] [blame] | 67 | // functions. Ownership of |function| remains with the caller. |
[email protected] | 637bf32 | 2011-10-01 20:46:32 | [diff] [blame] | 68 | // |
| 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] | bdfc03e | 2011-11-22 00:20:33 | [diff] [blame] | 74 | // 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 DuVall | fd4db3d | 2019-07-30 19:10:43 | [diff] [blame] | 76 | bool RunFunction(ExtensionFunction* function, |
[email protected] | 637bf32 | 2011-10-01 20:46:32 | [diff] [blame] | 77 | const std::string& args, |
| 78 | Browser* browser, |
Devlin Cronin | 35252c2b | 2018-02-14 00:03:53 | [diff] [blame] | 79 | extensions::api_test_utils::RunFunctionFlags flags); |
Clark DuVall | fd4db3d | 2019-07-30 19:10:43 | [diff] [blame] | 80 | bool RunFunction(ExtensionFunction* function, |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 81 | std::unique_ptr<base::ListValue> args, |
[email protected] | fc672e1 | 2014-08-16 08:16:15 | [diff] [blame] | 82 | Browser* browser, |
Devlin Cronin | 35252c2b | 2018-02-14 00:03:53 | [diff] [blame] | 83 | extensions::api_test_utils::RunFunctionFlags flags); |
[email protected] | 637bf32 | 2011-10-01 20:46:32 | [diff] [blame] | 84 | |
[email protected] | 637bf32 | 2011-10-01 20:46:32 | [diff] [blame] | 85 | } // namespace extension_function_test_utils |
| 86 | |
| 87 | #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_TEST_UTILS_H_ |