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

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

Issue 2556153002: [Extensions] Convert more callers of CallModuleMethod (Closed)
Patch Set: revert doc change Created 4 years 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 | « no previous file | extensions/renderer/module_system.h » ('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/location.h"
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 base::ThreadTaskRunnerHandle::Get()->PostTask( 197 base::ThreadTaskRunnerHandle::Get()->PostTask(
198 FROM_HERE, base::Bind(&ApiTestEnvironment::RunPromisesAgain, 198 FROM_HERE, base::Bind(&ApiTestEnvironment::RunPromisesAgain,
199 base::Unretained(this))); 199 base::Unretained(this)));
200 run_loop.Run(); 200 run_loop.Run();
201 } 201 }
202 202
203 void ApiTestEnvironment::RunTestInner(const std::string& test_name, 203 void ApiTestEnvironment::RunTestInner(const std::string& test_name,
204 const base::Closure& quit_closure) { 204 const base::Closure& quit_closure) {
205 v8::HandleScope scope(env()->isolate()); 205 v8::HandleScope scope(env()->isolate());
206 ModuleSystem::NativesEnabledScope natives_enabled(env()->module_system()); 206 ModuleSystem::NativesEnabledScope natives_enabled(env()->module_system());
207 v8::Local<v8::Value> result = 207 v8::Local<v8::Value> result;
208 env()->module_system()->CallModuleMethod("testBody", test_name); 208 bool did_run = false;
209 if (!result->IsTrue()) { 209 auto callback = [](bool* did_run, const base::Closure& quit_closure,
210 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, quit_closure); 210 const std::string& test_name,
211 FAIL() << "Failed to run test \"" << test_name << "\""; 211 const std::vector<v8::Local<v8::Value>>& result) {
212 } 212 *did_run = true;
213 if (result.empty() || result[0].IsEmpty() || !result[0]->IsTrue()) {
214 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, quit_closure);
215 FAIL() << "Failed to run test \"" << test_name << "\"";
216 }
217 };
218 env()->module_system()->CallModuleMethodSafe(
219 "testBody", test_name, 0, nullptr,
220 base::Bind(callback, &did_run, quit_closure, test_name));
221 ASSERT_TRUE(did_run);
213 } 222 }
214 223
215 void ApiTestEnvironment::RunPromisesAgain() { 224 void ApiTestEnvironment::RunPromisesAgain() {
216 v8::MicrotasksScope::PerformCheckpoint(env()->isolate()); 225 v8::MicrotasksScope::PerformCheckpoint(env()->isolate());
217 base::ThreadTaskRunnerHandle::Get()->PostTask( 226 base::ThreadTaskRunnerHandle::Get()->PostTask(
218 FROM_HERE, base::Bind(&ApiTestEnvironment::RunPromisesAgain, 227 FROM_HERE, base::Bind(&ApiTestEnvironment::RunPromisesAgain,
219 base::Unretained(this))); 228 base::Unretained(this)));
220 } 229 }
221 230
222 ApiTestBase::ApiTestBase() { 231 ApiTestBase::ApiTestBase() {
223 } 232 }
224 233
225 ApiTestBase::~ApiTestBase() { 234 ApiTestBase::~ApiTestBase() {
226 } 235 }
227 236
228 void ApiTestBase::SetUp() { 237 void ApiTestBase::SetUp() {
229 ModuleSystemTest::SetUp(); 238 ModuleSystemTest::SetUp();
230 test_env_.reset(new ApiTestEnvironment(env())); 239 test_env_.reset(new ApiTestEnvironment(env()));
231 } 240 }
232 241
233 void ApiTestBase::RunTest(const std::string& file_name, 242 void ApiTestBase::RunTest(const std::string& file_name,
234 const std::string& test_name) { 243 const std::string& test_name) {
235 ExpectNoAssertionsMade(); 244 ExpectNoAssertionsMade();
236 test_env_->RunTest(file_name, test_name); 245 test_env_->RunTest(file_name, test_name);
237 } 246 }
238 247
239 } // namespace extensions 248 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | extensions/renderer/module_system.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698