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

Side by Side Diff: extensions/renderer/api_test_base.cc

Issue 2036863002: Remove use of deprecated MessageLoop methods in extensions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « extensions/browser/state_store.cc ('k') | extensions/renderer/gc_callback.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/renderer/api_test_base.h" 5 #include "extensions/renderer/api_test_base.h"
6 6
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/location.h"
10 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "base/single_thread_task_runner.h"
13 #include "base/threading/thread_task_runner_handle.h"
11 #include "extensions/common/extension_urls.h" 14 #include "extensions/common/extension_urls.h"
12 #include "extensions/renderer/dispatcher.h" 15 #include "extensions/renderer/dispatcher.h"
13 #include "extensions/renderer/process_info_native_handler.h" 16 #include "extensions/renderer/process_info_native_handler.h"
14 #include "gin/converter.h" 17 #include "gin/converter.h"
15 #include "gin/dictionary.h" 18 #include "gin/dictionary.h"
16 #include "mojo/edk/js/core.h" 19 #include "mojo/edk/js/core.h"
17 #include "mojo/edk/js/handle.h" 20 #include "mojo/edk/js/handle.h"
18 #include "mojo/edk/js/support.h" 21 #include "mojo/edk/js/support.h"
19 #include "mojo/public/cpp/bindings/interface_request.h" 22 #include "mojo/public/cpp/bindings/interface_request.h"
20 #include "mojo/public/cpp/system/core.h" 23 #include "mojo/public/cpp/system/core.h"
(...skipping 20 matching lines...) Expand all
41 44
42 void Log(const std::string& value) { logs_ += value + "\n"; } 45 void Log(const std::string& value) { logs_ += value + "\n"; }
43 void NotifyPass() { FinishTesting(); } 46 void NotifyPass() { FinishTesting(); }
44 47
45 void NotifyFail(const std::string& message) { 48 void NotifyFail(const std::string& message) {
46 FinishTesting(); 49 FinishTesting();
47 FAIL() << logs_ << message; 50 FAIL() << logs_ << message;
48 } 51 }
49 52
50 void FinishTesting() { 53 void FinishTesting() {
51 base::MessageLoop::current()->PostTask(FROM_HERE, quit_closure_); 54 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, quit_closure_);
52 } 55 }
53 56
54 static gin::WrapperInfo kWrapperInfo; 57 static gin::WrapperInfo kWrapperInfo;
55 58
56 private: 59 private:
57 explicit TestNatives(const base::Closure& quit_closure) 60 explicit TestNatives(const base::Closure& quit_closure)
58 : quit_closure_(quit_closure) {} 61 : quit_closure_(quit_closure) {}
59 62
60 const base::Closure quit_closure_; 63 const base::Closure quit_closure_;
61 std::string logs_; 64 std::string logs_;
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 } 182 }
180 183
181 void ApiTestEnvironment::RunTest(const std::string& file_name, 184 void ApiTestEnvironment::RunTest(const std::string& file_name,
182 const std::string& test_name) { 185 const std::string& test_name) {
183 env()->RegisterTestFile("testBody", file_name); 186 env()->RegisterTestFile("testBody", file_name);
184 base::RunLoop run_loop; 187 base::RunLoop run_loop;
185 gin::ModuleRegistry::From(env()->context()->v8_context())->AddBuiltinModule( 188 gin::ModuleRegistry::From(env()->context()->v8_context())->AddBuiltinModule(
186 env()->isolate(), 189 env()->isolate(),
187 "testNatives", 190 "testNatives",
188 TestNatives::Create(env()->isolate(), run_loop.QuitClosure()).ToV8()); 191 TestNatives::Create(env()->isolate(), run_loop.QuitClosure()).ToV8());
189 base::MessageLoop::current()->PostTask( 192 base::ThreadTaskRunnerHandle::Get()->PostTask(
190 FROM_HERE, 193 FROM_HERE,
191 base::Bind(&ApiTestEnvironment::RunTestInner, base::Unretained(this), 194 base::Bind(&ApiTestEnvironment::RunTestInner, base::Unretained(this),
192 test_name, run_loop.QuitClosure())); 195 test_name, run_loop.QuitClosure()));
193 base::MessageLoop::current()->PostTask( 196 base::ThreadTaskRunnerHandle::Get()->PostTask(
194 FROM_HERE, base::Bind(&ApiTestEnvironment::RunPromisesAgain, 197 FROM_HERE, base::Bind(&ApiTestEnvironment::RunPromisesAgain,
195 base::Unretained(this))); 198 base::Unretained(this)));
196 run_loop.Run(); 199 run_loop.Run();
197 } 200 }
198 201
199 void ApiTestEnvironment::RunTestInner(const std::string& test_name, 202 void ApiTestEnvironment::RunTestInner(const std::string& test_name,
200 const base::Closure& quit_closure) { 203 const base::Closure& quit_closure) {
201 v8::HandleScope scope(env()->isolate()); 204 v8::HandleScope scope(env()->isolate());
202 ModuleSystem::NativesEnabledScope natives_enabled(env()->module_system()); 205 ModuleSystem::NativesEnabledScope natives_enabled(env()->module_system());
203 v8::Local<v8::Value> result = 206 v8::Local<v8::Value> result =
204 env()->module_system()->CallModuleMethod("testBody", test_name); 207 env()->module_system()->CallModuleMethod("testBody", test_name);
205 if (!result->IsTrue()) { 208 if (!result->IsTrue()) {
206 base::MessageLoop::current()->PostTask(FROM_HERE, quit_closure); 209 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, quit_closure);
207 FAIL() << "Failed to run test \"" << test_name << "\""; 210 FAIL() << "Failed to run test \"" << test_name << "\"";
208 } 211 }
209 } 212 }
210 213
211 void ApiTestEnvironment::RunPromisesAgain() { 214 void ApiTestEnvironment::RunPromisesAgain() {
212 v8::MicrotasksScope::PerformCheckpoint(env()->isolate()); 215 v8::MicrotasksScope::PerformCheckpoint(env()->isolate());
213 base::MessageLoop::current()->PostTask( 216 base::ThreadTaskRunnerHandle::Get()->PostTask(
214 FROM_HERE, base::Bind(&ApiTestEnvironment::RunPromisesAgain, 217 FROM_HERE, base::Bind(&ApiTestEnvironment::RunPromisesAgain,
215 base::Unretained(this))); 218 base::Unretained(this)));
216 } 219 }
217 220
218 ApiTestBase::ApiTestBase() { 221 ApiTestBase::ApiTestBase() {
219 } 222 }
220 223
221 ApiTestBase::~ApiTestBase() { 224 ApiTestBase::~ApiTestBase() {
222 } 225 }
223 226
224 void ApiTestBase::SetUp() { 227 void ApiTestBase::SetUp() {
225 ModuleSystemTest::SetUp(); 228 ModuleSystemTest::SetUp();
226 test_env_.reset(new ApiTestEnvironment(env())); 229 test_env_.reset(new ApiTestEnvironment(env()));
227 } 230 }
228 231
229 void ApiTestBase::RunTest(const std::string& file_name, 232 void ApiTestBase::RunTest(const std::string& file_name,
230 const std::string& test_name) { 233 const std::string& test_name) {
231 ExpectNoAssertionsMade(); 234 ExpectNoAssertionsMade();
232 test_env_->RunTest(file_name, test_name); 235 test_env_->RunTest(file_name, test_name);
233 } 236 }
234 237
235 } // namespace extensions 238 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/state_store.cc ('k') | extensions/renderer/gc_callback.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698