[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 | |
27 | TEST(RunnerTest, Run) { | ||||
fdoray | 09a43ef | 2017-05-08 16:26:57 | [diff] [blame] | 28 | base::test::ScopedTaskEnvironment scoped_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, |
yhirano | 9315024 | 2015-12-07 12:28:33 | [diff] [blame] | 37 | gin::IsolateHolder::kStableV8Extras, |
jochen | 2f43f2c9 | 2014-09-10 23:47:31 | [diff] [blame] | 38 | gin::ArrayBufferAllocator::SharedInstance()); |
altimin | 124814c | 2017-01-03 14:06:54 | [diff] [blame] | 39 | gin::IsolateHolder instance(base::ThreadTaskRunnerHandle::Get()); |
[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; | ||||
[email protected] | 7618ebbb | 2013-11-27 03:38:26 | [diff] [blame] | 48 | EXPECT_TRUE(Converter<std::string>::FromV8(isolate, |
[email protected] | a22998a | 2013-11-10 05:00:50 | [diff] [blame] | 49 | runner.global()->Get(StringToV8(isolate, "result")), |
50 | &result)); | ||||
51 | EXPECT_EQ("PASS", result); | ||||
52 | } | ||||
53 | |||||
54 | } // namespace gin |