| 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 <memory> |
| 8 #include <string> | 9 #include <string> |
| 9 | 10 |
| 10 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "extensions/common/manifest.h" | 12 #include "extensions/common/manifest.h" |
| 13 | 13 |
| 14 class UIThreadExtensionFunction; | 14 class UIThreadExtensionFunction; |
| 15 | 15 |
| 16 namespace base { | 16 namespace base { |
| 17 class DictionaryValue; | 17 class DictionaryValue; |
| 18 class ListValue; | 18 class ListValue; |
| 19 class Value; | 19 class Value; |
| 20 } | 20 } |
| 21 | 21 |
| 22 namespace content { | 22 namespace content { |
| 23 class BrowserContext; | 23 class BrowserContext; |
| 24 } | 24 } |
| 25 | 25 |
| 26 namespace extensions { | 26 namespace extensions { |
| 27 class Extension; | 27 class Extension; |
| 28 class ExtensionFunctionDispatcher; | 28 class ExtensionFunctionDispatcher; |
| 29 | 29 |
| 30 // TODO(yoz): crbug.com/394840: Remove duplicate functionality in | 30 // TODO(yoz): crbug.com/394840: Remove duplicate functionality in |
| 31 // chrome/browser/extensions/extension_function_test_utils.h. | 31 // chrome/browser/extensions/extension_function_test_utils.h. |
| 32 // | 32 // |
| 33 // TODO(ckehoe): Accept args as scoped_ptr<base::Value>, | 33 // TODO(ckehoe): Accept args as std::unique_ptr<base::Value>, |
| 34 // and migrate existing users to the new API. | 34 // and migrate existing users to the new API. |
| 35 namespace api_test_utils { | 35 namespace api_test_utils { |
| 36 | 36 |
| 37 enum RunFunctionFlags { NONE = 0, INCLUDE_INCOGNITO = 1 << 0 }; | 37 enum RunFunctionFlags { NONE = 0, INCLUDE_INCOGNITO = 1 << 0 }; |
| 38 | 38 |
| 39 // Parse JSON and return as the specified type, or NULL if the JSON is invalid | 39 // Parse JSON and return as the specified type, or NULL if the JSON is invalid |
| 40 // or not the specified type. | 40 // or not the specified type. |
| 41 scoped_ptr<base::DictionaryValue> ParseDictionary(const std::string& data); | 41 std::unique_ptr<base::DictionaryValue> ParseDictionary(const std::string& data); |
| 42 | 42 |
| 43 // Get |key| from |val| as the specified type. If |key| does not exist, or is | 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 | 44 // not of the specified type, adds a failure to the current test and returns |
| 45 // false, 0, empty string, etc. | 45 // false, 0, empty string, etc. |
| 46 bool GetBoolean(const base::DictionaryValue* val, const std::string& key); | 46 bool GetBoolean(const base::DictionaryValue* val, const std::string& key); |
| 47 int GetInteger(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); | 48 std::string GetString(const base::DictionaryValue* val, const std::string& key); |
| 49 | 49 |
| 50 // Creates an extension instance with a specified extension value that can be | 50 // Creates an extension instance with a specified extension value that can be |
| 51 // attached to an ExtensionFunction before running. | 51 // attached to an ExtensionFunction before running. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 62 scoped_refptr<extensions::Extension> CreateEmptyExtensionWithLocation( | 62 scoped_refptr<extensions::Extension> CreateEmptyExtensionWithLocation( |
| 63 extensions::Manifest::Location location); | 63 extensions::Manifest::Location location); |
| 64 | 64 |
| 65 // Run |function| with |args| and return the result. Adds an error to the | 65 // Run |function| with |args| and return the result. Adds an error to the |
| 66 // current test if |function| returns an error. Takes ownership of | 66 // current test if |function| returns an error. Takes ownership of |
| 67 // |function|. The caller takes ownership of the result. | 67 // |function|. The caller takes ownership of the result. |
| 68 base::Value* RunFunctionWithDelegateAndReturnSingleResult( | 68 base::Value* RunFunctionWithDelegateAndReturnSingleResult( |
| 69 UIThreadExtensionFunction* function, | 69 UIThreadExtensionFunction* function, |
| 70 const std::string& args, | 70 const std::string& args, |
| 71 content::BrowserContext* context, | 71 content::BrowserContext* context, |
| 72 scoped_ptr<ExtensionFunctionDispatcher> dispatcher); | 72 std::unique_ptr<ExtensionFunctionDispatcher> dispatcher); |
| 73 base::Value* RunFunctionWithDelegateAndReturnSingleResult( | 73 base::Value* RunFunctionWithDelegateAndReturnSingleResult( |
| 74 UIThreadExtensionFunction* function, | 74 UIThreadExtensionFunction* function, |
| 75 const std::string& args, | 75 const std::string& args, |
| 76 content::BrowserContext* context, | 76 content::BrowserContext* context, |
| 77 scoped_ptr<ExtensionFunctionDispatcher> dispatcher, | 77 std::unique_ptr<ExtensionFunctionDispatcher> dispatcher, |
| 78 RunFunctionFlags flags); | 78 RunFunctionFlags flags); |
| 79 | 79 |
| 80 // RunFunctionWithDelegateAndReturnSingleResult, except with a NULL | 80 // RunFunctionWithDelegateAndReturnSingleResult, except with a NULL |
| 81 // implementation of the Delegate. | 81 // implementation of the Delegate. |
| 82 base::Value* RunFunctionAndReturnSingleResult( | 82 base::Value* RunFunctionAndReturnSingleResult( |
| 83 UIThreadExtensionFunction* function, | 83 UIThreadExtensionFunction* function, |
| 84 const std::string& args, | 84 const std::string& args, |
| 85 content::BrowserContext* context); | 85 content::BrowserContext* context); |
| 86 base::Value* RunFunctionAndReturnSingleResult( | 86 base::Value* RunFunctionAndReturnSingleResult( |
| 87 UIThreadExtensionFunction* function, | 87 UIThreadExtensionFunction* function, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 109 // | 109 // |
| 110 // TODO(aa): I'm concerned that this style won't scale to all the bits and bobs | 110 // TODO(aa): I'm concerned that this style won't scale to all the bits and bobs |
| 111 // we're going to need to frob for all the different extension functions. But | 111 // we're going to need to frob for all the different extension functions. But |
| 112 // we can refactor when we see what is needed. | 112 // we can refactor when we see what is needed. |
| 113 bool RunFunction(UIThreadExtensionFunction* function, | 113 bool RunFunction(UIThreadExtensionFunction* function, |
| 114 const std::string& args, | 114 const std::string& args, |
| 115 content::BrowserContext* context); | 115 content::BrowserContext* context); |
| 116 bool RunFunction(UIThreadExtensionFunction* function, | 116 bool RunFunction(UIThreadExtensionFunction* function, |
| 117 const std::string& args, | 117 const std::string& args, |
| 118 content::BrowserContext* context, | 118 content::BrowserContext* context, |
| 119 scoped_ptr<ExtensionFunctionDispatcher> dispatcher, | 119 std::unique_ptr<ExtensionFunctionDispatcher> dispatcher, |
| 120 RunFunctionFlags flags); | 120 RunFunctionFlags flags); |
| 121 bool RunFunction(UIThreadExtensionFunction* function, | 121 bool RunFunction(UIThreadExtensionFunction* function, |
| 122 scoped_ptr<base::ListValue> args, | 122 std::unique_ptr<base::ListValue> args, |
| 123 content::BrowserContext* context, | 123 content::BrowserContext* context, |
| 124 scoped_ptr<ExtensionFunctionDispatcher> dispatcher, | 124 std::unique_ptr<ExtensionFunctionDispatcher> dispatcher, |
| 125 RunFunctionFlags flags); | 125 RunFunctionFlags flags); |
| 126 | 126 |
| 127 } // namespace api_test_utils | 127 } // namespace api_test_utils |
| 128 } // namespace extensions | 128 } // namespace extensions |
| 129 | 129 |
| 130 #endif // EXTENSIONS_BROWSER_API_TEST_UTILS_H_ | 130 #endif // EXTENSIONS_BROWSER_API_TEST_UTILS_H_ |
| OLD | NEW |