| 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 #include "extensions/browser/api_test_utils.h" | 5 #include "extensions/browser/api_test_utils.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 return RunFunctionWithDelegateAndReturnSingleResult( | 138 return RunFunctionWithDelegateAndReturnSingleResult( |
| 139 function, args, context, std::move(dispatcher), NONE); | 139 function, args, context, std::move(dispatcher), NONE); |
| 140 } | 140 } |
| 141 | 141 |
| 142 base::Value* RunFunctionWithDelegateAndReturnSingleResult( | 142 base::Value* RunFunctionWithDelegateAndReturnSingleResult( |
| 143 UIThreadExtensionFunction* function, | 143 UIThreadExtensionFunction* function, |
| 144 const std::string& args, | 144 const std::string& args, |
| 145 content::BrowserContext* context, | 145 content::BrowserContext* context, |
| 146 std::unique_ptr<extensions::ExtensionFunctionDispatcher> dispatcher, | 146 std::unique_ptr<extensions::ExtensionFunctionDispatcher> dispatcher, |
| 147 RunFunctionFlags flags) { | 147 RunFunctionFlags flags) { |
| 148 std::unique_ptr<base::ListValue> parsed_args = ParseList(args); |
| 149 EXPECT_TRUE(parsed_args.get()) |
| 150 << "Could not parse extension function arguments: " << args; |
| 151 |
| 152 return RunFunctionWithDelegateAndReturnSingleResult( |
| 153 function, std::move(parsed_args), context, std::move(dispatcher), flags); |
| 154 } |
| 155 |
| 156 base::Value* RunFunctionWithDelegateAndReturnSingleResult( |
| 157 UIThreadExtensionFunction* function, |
| 158 std::unique_ptr<base::ListValue> args, |
| 159 content::BrowserContext* context, |
| 160 std::unique_ptr<extensions::ExtensionFunctionDispatcher> dispatcher, |
| 161 RunFunctionFlags flags) { |
| 148 scoped_refptr<ExtensionFunction> function_owner(function); | 162 scoped_refptr<ExtensionFunction> function_owner(function); |
| 149 // Without a callback the function will not generate a result. | 163 // Without a callback the function will not generate a result. |
| 150 function->set_has_callback(true); | 164 function->set_has_callback(true); |
| 151 RunFunction(function, args, context, std::move(dispatcher), flags); | 165 RunFunction(function, std::move(args), context, std::move(dispatcher), flags); |
| 152 EXPECT_TRUE(function->GetError().empty()) | 166 EXPECT_TRUE(function->GetError().empty()) << "Unexpected error: " |
| 153 << "Unexpected error: " << function->GetError(); | 167 << function->GetError(); |
| 154 const base::Value* single_result = NULL; | 168 const base::Value* single_result = NULL; |
| 155 if (function->GetResultList() != NULL && | 169 if (function->GetResultList() != NULL && |
| 156 function->GetResultList()->Get(0, &single_result)) { | 170 function->GetResultList()->Get(0, &single_result)) { |
| 157 return single_result->DeepCopy(); | 171 return single_result->DeepCopy(); |
| 158 } | 172 } |
| 159 return NULL; | 173 return NULL; |
| 160 } | 174 } |
| 161 | 175 |
| 162 base::Value* RunFunctionAndReturnSingleResult( | 176 base::Value* RunFunctionAndReturnSingleResult( |
| 163 UIThreadExtensionFunction* function, | 177 UIThreadExtensionFunction* function, |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 function->set_include_incognito(flags & INCLUDE_INCOGNITO); | 250 function->set_include_incognito(flags & INCLUDE_INCOGNITO); |
| 237 function->RunWithValidation()->Execute(); | 251 function->RunWithValidation()->Execute(); |
| 238 response_delegate.WaitForResponse(); | 252 response_delegate.WaitForResponse(); |
| 239 | 253 |
| 240 EXPECT_TRUE(response_delegate.HasResponse()); | 254 EXPECT_TRUE(response_delegate.HasResponse()); |
| 241 return response_delegate.GetResponse(); | 255 return response_delegate.GetResponse(); |
| 242 } | 256 } |
| 243 | 257 |
| 244 } // namespace api_test_utils | 258 } // namespace api_test_utils |
| 245 } // namespace extensions | 259 } // namespace extensions |
| OLD | NEW |