OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef EXTENSIONS_BROWSER_API_TEST_UTILS_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_TEST_UTILS_H_ |
6 #define EXTENSIONS_BROWSER_API_TEST_UTILS_H_ | 6 #define EXTENSIONS_BROWSER_API_TEST_UTILS_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
| 10 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "extensions/common/manifest.h" |
11 | 13 |
12 class UIThreadExtensionFunction; | 14 class UIThreadExtensionFunction; |
13 | 15 |
14 namespace base { | 16 namespace base { |
| 17 class DictionaryValue; |
15 class ListValue; | 18 class ListValue; |
16 class Value; | 19 class Value; |
17 } | 20 } |
18 | 21 |
19 namespace content { | 22 namespace content { |
20 class BrowserContext; | 23 class BrowserContext; |
21 } | 24 } |
22 | 25 |
23 namespace extensions { | 26 namespace extensions { |
| 27 class Extension; |
24 class ExtensionFunctionDispatcher; | 28 class ExtensionFunctionDispatcher; |
25 | 29 |
26 // TODO(yoz): crbug.com/394840: Remove duplicate functionality in | 30 // TODO(yoz): crbug.com/394840: Remove duplicate functionality in |
27 // chrome/browser/extensions/extension_function_test_utils.h. | 31 // chrome/browser/extensions/extension_function_test_utils.h. |
28 // | 32 // |
29 // TODO(ckehoe): Accept args as scoped_ptr<base::Value>, | 33 // TODO(ckehoe): Accept args as scoped_ptr<base::Value>, |
30 // and migrate existing users to the new API. | 34 // and migrate existing users to the new API. |
31 namespace api_test_utils { | 35 namespace api_test_utils { |
32 | 36 |
33 enum RunFunctionFlags { NONE = 0, INCLUDE_INCOGNITO = 1 << 0 }; | 37 enum RunFunctionFlags { NONE = 0, INCLUDE_INCOGNITO = 1 << 0 }; |
34 | 38 |
| 39 // Parse JSON and return as the specified type, or NULL if the JSON is invalid |
| 40 // or not the specified type. |
| 41 base::DictionaryValue* ParseDictionary(const std::string& data); |
| 42 |
| 43 // Get |key| from |val| as the specified type. If |key| does not exist, or is |
| 44 // not of the specified type, adds a failure to the current test and returns |
| 45 // false, 0, empty string, etc. |
| 46 bool GetBoolean(const base::DictionaryValue* val, const std::string& key); |
| 47 int GetInteger(const base::DictionaryValue* val, const std::string& key); |
| 48 std::string GetString(const base::DictionaryValue* val, const std::string& key); |
| 49 |
| 50 // Creates an extension instance with a specified extension value that can be |
| 51 // attached to an ExtensionFunction before running. |
| 52 scoped_refptr<extensions::Extension> CreateExtension( |
| 53 base::DictionaryValue* test_extension_value); |
| 54 |
| 55 scoped_refptr<extensions::Extension> CreateExtension( |
| 56 extensions::Manifest::Location location, |
| 57 base::DictionaryValue* test_extension_value, |
| 58 const std::string& id_input); |
| 59 |
35 // Run |function| with |args| and return the result. Adds an error to the | 60 // Run |function| with |args| and return the result. Adds an error to the |
36 // current test if |function| returns an error. Takes ownership of | 61 // current test if |function| returns an error. Takes ownership of |
37 // |function|. The caller takes ownership of the result. | 62 // |function|. The caller takes ownership of the result. |
38 base::Value* RunFunctionWithDelegateAndReturnSingleResult( | 63 base::Value* RunFunctionWithDelegateAndReturnSingleResult( |
39 UIThreadExtensionFunction* function, | 64 UIThreadExtensionFunction* function, |
40 const std::string& args, | 65 const std::string& args, |
41 content::BrowserContext* context, | 66 content::BrowserContext* context, |
42 scoped_ptr<ExtensionFunctionDispatcher> dispatcher); | 67 scoped_ptr<ExtensionFunctionDispatcher> dispatcher); |
43 base::Value* RunFunctionWithDelegateAndReturnSingleResult( | 68 base::Value* RunFunctionWithDelegateAndReturnSingleResult( |
44 UIThreadExtensionFunction* function, | 69 UIThreadExtensionFunction* function, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 const std::string& args, | 112 const std::string& args, |
88 content::BrowserContext* context, | 113 content::BrowserContext* context, |
89 scoped_ptr<ExtensionFunctionDispatcher> dispatcher, | 114 scoped_ptr<ExtensionFunctionDispatcher> dispatcher, |
90 RunFunctionFlags flags); | 115 RunFunctionFlags flags); |
91 bool RunFunction(UIThreadExtensionFunction* function, | 116 bool RunFunction(UIThreadExtensionFunction* function, |
92 scoped_ptr<base::ListValue> args, | 117 scoped_ptr<base::ListValue> args, |
93 content::BrowserContext* context, | 118 content::BrowserContext* context, |
94 scoped_ptr<ExtensionFunctionDispatcher> dispatcher, | 119 scoped_ptr<ExtensionFunctionDispatcher> dispatcher, |
95 RunFunctionFlags flags); | 120 RunFunctionFlags flags); |
96 | 121 |
97 } // namespace function_test_utils | 122 } // namespace api_test_utils |
98 } // namespace extensions | 123 } // namespace extensions |
99 | 124 |
100 #endif // EXTENSIONS_BROWSER_API_TEST_UTILS_H_ | 125 #endif // EXTENSIONS_BROWSER_API_TEST_UTILS_H_ |
OLD | NEW |