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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 bool RunFunction(UIThreadExtensionFunction* function, | 135 bool RunFunction(UIThreadExtensionFunction* function, |
136 const std::string& args, | 136 const std::string& args, |
137 content::BrowserContext* context, | 137 content::BrowserContext* context, |
138 scoped_ptr<extensions::ExtensionFunctionDispatcher> dispatcher, | 138 scoped_ptr<extensions::ExtensionFunctionDispatcher> dispatcher, |
139 RunFunctionFlags flags) { | 139 RunFunctionFlags flags) { |
| 140 scoped_ptr<base::ListValue> parsed_args(ParseList(args)); |
| 141 EXPECT_TRUE(parsed_args.get()) |
| 142 << "Could not parse extension function arguments: " << args; |
| 143 return RunFunction( |
| 144 function, parsed_args.Pass(), context, dispatcher.Pass(), flags); |
| 145 } |
| 146 |
| 147 bool RunFunction(UIThreadExtensionFunction* function, |
| 148 scoped_ptr<base::ListValue> args, |
| 149 content::BrowserContext* context, |
| 150 scoped_ptr<extensions::ExtensionFunctionDispatcher> dispatcher, |
| 151 RunFunctionFlags flags) { |
140 SendResponseDelegate response_delegate; | 152 SendResponseDelegate response_delegate; |
141 function->set_test_delegate(&response_delegate); | 153 function->set_test_delegate(&response_delegate); |
142 scoped_ptr<base::ListValue> parsed_args(ParseList(args)); | 154 function->SetArgs(args.get()); |
143 EXPECT_TRUE(parsed_args.get()) | |
144 << "Could not parse extension function arguments: " << args; | |
145 function->SetArgs(parsed_args.get()); | |
146 | 155 |
147 CHECK(dispatcher); | 156 CHECK(dispatcher); |
148 function->set_dispatcher(dispatcher->AsWeakPtr()); | 157 function->set_dispatcher(dispatcher->AsWeakPtr()); |
149 | 158 |
150 function->set_browser_context(context); | 159 function->set_browser_context(context); |
151 function->set_include_incognito(flags & INCLUDE_INCOGNITO); | 160 function->set_include_incognito(flags & INCLUDE_INCOGNITO); |
152 function->Run()->Execute(); | 161 function->Run()->Execute(); |
153 | 162 |
154 // If the RunAsync of |function| didn't already call SendResponse, run the | 163 // If the RunAsync of |function| didn't already call SendResponse, run the |
155 // message loop until they do. | 164 // message loop until they do. |
156 if (!response_delegate.HasResponse()) { | 165 if (!response_delegate.HasResponse()) { |
157 response_delegate.set_should_post_quit(true); | 166 response_delegate.set_should_post_quit(true); |
158 content::RunMessageLoop(); | 167 content::RunMessageLoop(); |
159 } | 168 } |
160 | 169 |
161 EXPECT_TRUE(response_delegate.HasResponse()); | 170 EXPECT_TRUE(response_delegate.HasResponse()); |
162 return response_delegate.GetResponse(); | 171 return response_delegate.GetResponse(); |
163 } | 172 } |
164 | 173 |
165 } // namespace api_test_utils | 174 } // namespace api_test_utils |
166 } // namespace extensions | 175 } // namespace extensions |
OLD | NEW |