[email protected] | 1771610d | 2014-02-27 06:08:24 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 1771610d | 2014-02-27 06:08:24 | [diff] [blame] | 5 | #include "gin/shell_runner.h" |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 6 | |
| 7 | #include "base/compiler_specific.h" |
fdoray | 09a43ef | 2017-05-08 16:26:57 | [diff] [blame] | 8 | #include "base/test/scoped_task_environment.h" |
altimin | 124814c | 2017-01-03 14:06:54 | [diff] [blame] | 9 | #include "base/threading/thread_task_runner_handle.h" |
jochen | 2f43f2c9 | 2014-09-10 23:47:31 | [diff] [blame] | 10 | #include "gin/array_buffer.h" |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 11 | #include "gin/converter.h" |
[email protected] | f04b0e9 | 2013-11-22 14:20:55 | [diff] [blame] | 12 | #include "gin/public/isolate_holder.h" |
oth | 05c26fde | 2015-04-05 14:30:57 | [diff] [blame] | 13 | #include "gin/v8_initializer.h" |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 14 | #include "testing/gtest/include/gtest/gtest.h" |
| 15 | |
baixo | 3a3c88a | 2014-10-28 11:52:21 | [diff] [blame] | 16 | #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
| 17 | #include "gin/public/isolate_holder.h" |
| 18 | #endif |
| 19 | |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 20 | using v8::Isolate; |
| 21 | using v8::Object; |
| 22 | using v8::Script; |
| 23 | using v8::String; |
| 24 | |
| 25 | namespace gin { |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 26 | |
Yuzhu Shen | a9b25af | 2017-12-11 22:30:26 | [diff] [blame] | 27 | TEST(RunnerTest, Run) { |
Gabriel Charette | 694c3c33 | 2019-08-19 14:53:05 | [diff] [blame^] | 28 | base::test::TaskEnvironment task_environment; |
[email protected] | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 29 | std::string source = "this.result = 'PASS';\n"; |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 30 | |
baixo | 3a3c88a | 2014-10-28 11:52:21 | [diff] [blame] | 31 | #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
oth | 05c26fde | 2015-04-05 14:30:57 | [diff] [blame] | 32 | gin::V8Initializer::LoadV8Snapshot(); |
erikcorry | c94eff1 | 2015-06-08 11:29:16 | [diff] [blame] | 33 | gin::V8Initializer::LoadV8Natives(); |
baixo | 3a3c88a | 2014-10-28 11:52:21 | [diff] [blame] | 34 | #endif |
| 35 | |
jochen | 2f43f2c9 | 2014-09-10 23:47:31 | [diff] [blame] | 36 | gin::IsolateHolder::Initialize(gin::IsolateHolder::kStrictMode, |
| 37 | gin::ArrayBufferAllocator::SharedInstance()); |
Ulan Degenbaev | 51945ab | 2018-08-23 14:12:58 | [diff] [blame] | 38 | gin::IsolateHolder instance(base::ThreadTaskRunnerHandle::Get(), |
| 39 | gin::IsolateHolder::IsolateType::kTest); |
[email protected] | 1b93c23 | 2013-11-19 19:25:12 | [diff] [blame] | 40 | |
[email protected] | 1771610d | 2014-02-27 06:08:24 | [diff] [blame] | 41 | ShellRunnerDelegate delegate; |
[email protected] | 1b93c23 | 2013-11-19 19:25:12 | [diff] [blame] | 42 | Isolate* isolate = instance.isolate(); |
[email protected] | 1771610d | 2014-02-27 06:08:24 | [diff] [blame] | 43 | ShellRunner runner(&delegate, isolate); |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 44 | Runner::Scope scope(&runner); |
[email protected] | 2f70342 | 2013-11-25 21:26:15 | [diff] [blame] | 45 | runner.Run(source, "test_data.js"); |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 46 | |
| 47 | std::string result; |
Dan Elphick | d7eeb4a | 2019-02-01 17:55:56 | [diff] [blame] | 48 | EXPECT_TRUE(Converter<std::string>::FromV8( |
| 49 | isolate, |
| 50 | runner.global() |
| 51 | ->Get(isolate->GetCurrentContext(), StringToV8(isolate, "result")) |
| 52 | .ToLocalChecked(), |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 53 | &result)); |
| 54 | EXPECT_EQ("PASS", result); |
| 55 | } |
| 56 | |
| 57 | } // namespace gin |