| 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 "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "content/public/browser/browser_context.h" | 10 #include "content/public/browser/browser_context.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 content::BrowserContext* context, | 125 content::BrowserContext* context, |
| 126 RunFunctionFlags flags) { | 126 RunFunctionFlags flags) { |
| 127 TestFunctionDispatcherDelegate delegate; | 127 TestFunctionDispatcherDelegate delegate; |
| 128 scoped_ptr<ExtensionFunctionDispatcher> dispatcher( | 128 scoped_ptr<ExtensionFunctionDispatcher> dispatcher( |
| 129 new ExtensionFunctionDispatcher(context, &delegate)); | 129 new ExtensionFunctionDispatcher(context, &delegate)); |
| 130 | 130 |
| 131 return RunFunctionWithDelegateAndReturnSingleResult( | 131 return RunFunctionWithDelegateAndReturnSingleResult( |
| 132 function, args, context, dispatcher.Pass(), flags); | 132 function, args, context, dispatcher.Pass(), flags); |
| 133 } | 133 } |
| 134 | 134 |
| 135 std::string RunFunctionAndReturnError(UIThreadExtensionFunction* function, |
| 136 const std::string& args, |
| 137 content::BrowserContext* context) { |
| 138 return RunFunctionAndReturnError(function, args, context, NONE); |
| 139 } |
| 140 |
| 141 std::string RunFunctionAndReturnError(UIThreadExtensionFunction* function, |
| 142 const std::string& args, |
| 143 content::BrowserContext* context, |
| 144 RunFunctionFlags flags) { |
| 145 TestFunctionDispatcherDelegate delegate; |
| 146 scoped_ptr<ExtensionFunctionDispatcher> dispatcher( |
| 147 new ExtensionFunctionDispatcher(context, &delegate)); |
| 148 scoped_refptr<ExtensionFunction> function_owner(function); |
| 149 // Without a callback the function will not generate a result. |
| 150 function->set_has_callback(true); |
| 151 RunFunction(function, args, context, dispatcher.Pass(), flags); |
| 152 EXPECT_FALSE(function->GetResultList()) << "Did not expect a result"; |
| 153 return function->GetError(); |
| 154 } |
| 155 |
| 135 bool RunFunction(UIThreadExtensionFunction* function, | 156 bool RunFunction(UIThreadExtensionFunction* function, |
| 136 const std::string& args, | 157 const std::string& args, |
| 137 content::BrowserContext* context, | 158 content::BrowserContext* context, |
| 138 scoped_ptr<extensions::ExtensionFunctionDispatcher> dispatcher, | 159 scoped_ptr<extensions::ExtensionFunctionDispatcher> dispatcher, |
| 139 RunFunctionFlags flags) { | 160 RunFunctionFlags flags) { |
| 140 scoped_ptr<base::ListValue> parsed_args(ParseList(args)); | 161 scoped_ptr<base::ListValue> parsed_args(ParseList(args)); |
| 141 EXPECT_TRUE(parsed_args.get()) | 162 EXPECT_TRUE(parsed_args.get()) |
| 142 << "Could not parse extension function arguments: " << args; | 163 << "Could not parse extension function arguments: " << args; |
| 143 return RunFunction( | 164 return RunFunction( |
| 144 function, parsed_args.Pass(), context, dispatcher.Pass(), flags); | 165 function, parsed_args.Pass(), context, dispatcher.Pass(), flags); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 166 response_delegate.set_should_post_quit(true); | 187 response_delegate.set_should_post_quit(true); |
| 167 content::RunMessageLoop(); | 188 content::RunMessageLoop(); |
| 168 } | 189 } |
| 169 | 190 |
| 170 EXPECT_TRUE(response_delegate.HasResponse()); | 191 EXPECT_TRUE(response_delegate.HasResponse()); |
| 171 return response_delegate.GetResponse(); | 192 return response_delegate.GetResponse(); |
| 172 } | 193 } |
| 173 | 194 |
| 174 } // namespace api_test_utils | 195 } // namespace api_test_utils |
| 175 } // namespace extensions | 196 } // namespace extensions |
| OLD | NEW |