[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" |
[email protected] | d42c111 | 2013-08-22 19:36:32 | [diff] [blame] | 11 | #include "extensions/common/manifest.h" |
[email protected] | 4e3ce3b | 2011-10-14 23:25:17 | [diff] [blame] | 12 | |
| 13 | class Browser; |
[email protected] | 4e3ce3b | 2011-10-14 23:25:17 | [diff] [blame] | 14 | class UIThreadExtensionFunction; |
[email protected] | 637bf32 | 2011-10-01 20:46:32 | [diff] [blame] | 15 | |
| 16 | namespace base { |
| 17 | class Value; |
| 18 | class DictionaryValue; |
| 19 | class ListValue; |
| 20 | } |
| 21 | |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 22 | // TODO(ckehoe): Accept args as std::unique_ptr<base::Value>, |
[email protected] | fc672e1 | 2014-08-16 08:16:15 | [diff] [blame] | 23 | // and migrate existing users to the new API. |
yoz | b6272ef | 2014-08-28 02:23:05 | [diff] [blame] | 24 | // This file is DEPRECATED. New tests should use the versions in |
| 25 | // extensions/browser/api_test_utils.h. |
[email protected] | 637bf32 | 2011-10-01 20:46:32 | [diff] [blame] | 26 | namespace extension_function_test_utils { |
| 27 | |
Devlin Cronin | 2e6f4f87 | 2017-10-03 00:07:24 | [diff] [blame^] | 28 | // Parse JSON and return as a ListValue, or null if invalid. |
[email protected] | 637bf32 | 2011-10-01 20:46:32 | [diff] [blame] | 29 | base::ListValue* ParseList(const std::string& data); |
[email protected] | 637bf32 | 2011-10-01 20:46:32 | [diff] [blame] | 30 | |
| 31 | // If |val| is a dictionary, return it as one, otherwise NULL. |
| 32 | base::DictionaryValue* ToDictionary(base::Value* val); |
| 33 | |
[email protected] | 008ff7fb | 2011-12-19 08:51:17 | [diff] [blame] | 34 | // If |val| is a list, return it as one, otherwise NULL. |
| 35 | base::ListValue* ToList(base::Value* val); |
| 36 | |
[email protected] | 37bb582 | 2012-09-10 15:09:57 | [diff] [blame] | 37 | // Returns true if |val| contains privacy information, e.g. url, |
| 38 | // title, and faviconUrl. |
| 39 | bool HasPrivacySensitiveFields(base::DictionaryValue* val); |
| 40 | |
[email protected] | 637bf32 | 2011-10-01 20:46:32 | [diff] [blame] | 41 | enum RunFunctionFlags { |
| 42 | NONE = 0, |
| 43 | INCLUDE_INCOGNITO = 1 << 0 |
| 44 | }; |
| 45 | |
| 46 | // Run |function| with |args| and return the resulting error. Adds an error to |
[email protected] | 4f9c79ec | 2013-03-21 04:41:37 | [diff] [blame] | 47 | // the current test if |function| returns a result. Takes ownership of |
| 48 | // |function|. |
[email protected] | 637bf32 | 2011-10-01 20:46:32 | [diff] [blame] | 49 | std::string RunFunctionAndReturnError(UIThreadExtensionFunction* function, |
| 50 | const std::string& args, |
| 51 | Browser* browser, |
| 52 | RunFunctionFlags flags); |
| 53 | std::string RunFunctionAndReturnError(UIThreadExtensionFunction* function, |
| 54 | const std::string& args, |
| 55 | Browser* browser); |
| 56 | |
| 57 | // Run |function| with |args| and return the result. Adds an error to the |
[email protected] | 4f9c79ec | 2013-03-21 04:41:37 | [diff] [blame] | 58 | // current test if |function| returns an error. Takes ownership of |
| 59 | // |function|. The caller takes ownership of the result. |
[email protected] | 07ff5fd | 2012-07-12 22:39:09 | [diff] [blame] | 60 | base::Value* RunFunctionAndReturnSingleResult( |
| 61 | UIThreadExtensionFunction* function, |
| 62 | const std::string& args, |
| 63 | Browser* browser, |
| 64 | RunFunctionFlags flags); |
| 65 | base::Value* RunFunctionAndReturnSingleResult( |
| 66 | UIThreadExtensionFunction* function, |
| 67 | const std::string& args, |
| 68 | Browser* browser); |
[email protected] | 637bf32 | 2011-10-01 20:46:32 | [diff] [blame] | 69 | |
[email protected] | bdfc03e | 2011-11-22 00:20:33 | [diff] [blame] | 70 | // Create and run |function| with |args|. Works with both synchronous and async |
[email protected] | 4f9c79ec | 2013-03-21 04:41:37 | [diff] [blame] | 71 | // functions. Ownership of |function| remains with the caller. |
[email protected] | 637bf32 | 2011-10-01 20:46:32 | [diff] [blame] | 72 | // |
| 73 | // TODO(aa): It would be nice if |args| could be validated against the schema |
| 74 | // that |function| expects. That way, we know that we are testing something |
| 75 | // close to what the bindings would actually send. |
| 76 | // |
| 77 | // 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] | 78 | // we're going to need to frob for all the different extension functions. But |
| 79 | // we can refactor when we see what is needed. |
| 80 | bool RunFunction(UIThreadExtensionFunction* function, |
[email protected] | 637bf32 | 2011-10-01 20:46:32 | [diff] [blame] | 81 | const std::string& args, |
| 82 | Browser* browser, |
| 83 | RunFunctionFlags flags); |
[email protected] | fc672e1 | 2014-08-16 08:16:15 | [diff] [blame] | 84 | bool RunFunction(UIThreadExtensionFunction* function, |
dcheng | c963c714 | 2016-04-08 03:55:22 | [diff] [blame] | 85 | std::unique_ptr<base::ListValue> args, |
[email protected] | fc672e1 | 2014-08-16 08:16:15 | [diff] [blame] | 86 | Browser* browser, |
| 87 | RunFunctionFlags flags); |
[email protected] | 637bf32 | 2011-10-01 20:46:32 | [diff] [blame] | 88 | |
[email protected] | 637bf32 | 2011-10-01 20:46:32 | [diff] [blame] | 89 | } // namespace extension_function_test_utils |
| 90 | |
| 91 | #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_TEST_UTILS_H_ |