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/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 Loading... |
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 |
OLD | NEW |