| 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 SendResponseDelegate response_delegate; | 161 SendResponseDelegate response_delegate; |
| 141 function->set_test_delegate(&response_delegate); | 162 function->set_test_delegate(&response_delegate); |
| 142 scoped_ptr<base::ListValue> parsed_args(ParseList(args)); | 163 scoped_ptr<base::ListValue> parsed_args(ParseList(args)); |
| 143 EXPECT_TRUE(parsed_args.get()) | 164 EXPECT_TRUE(parsed_args.get()) |
| 144 << "Could not parse extension function arguments: " << args; | 165 << "Could not parse extension function arguments: " << args; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 157 response_delegate.set_should_post_quit(true); | 178 response_delegate.set_should_post_quit(true); |
| 158 content::RunMessageLoop(); | 179 content::RunMessageLoop(); |
| 159 } | 180 } |
| 160 | 181 |
| 161 EXPECT_TRUE(response_delegate.HasResponse()); | 182 EXPECT_TRUE(response_delegate.HasResponse()); |
| 162 return response_delegate.GetResponse(); | 183 return response_delegate.GetResponse(); |
| 163 } | 184 } |
| 164 | 185 |
| 165 } // namespace api_test_utils | 186 } // namespace api_test_utils |
| 166 } // namespace extensions | 187 } // namespace extensions |
| OLD | NEW |