Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(843)

Side by Side Diff: extensions/browser/api_test_utils.cc

Issue 461273003: Rework ExtensionApiUnittest to run in extensions_unittests, removing its Chrome dependencies. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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,
James Cook 2014/08/13 16:11:36 What's the plan for the copy of this code in chrom
Yoyo Zhou 2014/08/13 22:53:43 I'd rather not spend time on refactoring it when t
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698