James Robinson | a976313 | 2014-10-06 11:18:13 -0700 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "gin/shell_runner.h" |
| 6 | |
| 7 | #include "base/compiler_specific.h" |
| 8 | #include "gin/array_buffer.h" |
| 9 | #include "gin/converter.h" |
| 10 | #include "gin/public/isolate_holder.h" |
| 11 | #include "testing/gtest/include/gtest/gtest.h" |
| 12 | |
James Robinson | 53b7758 | 2014-10-28 17:00:48 -0700 | [diff] [blame] | 13 | #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
| 14 | #include "gin/public/isolate_holder.h" |
| 15 | #endif |
| 16 | |
James Robinson | a976313 | 2014-10-06 11:18:13 -0700 | [diff] [blame] | 17 | using v8::Isolate; |
| 18 | using v8::Object; |
| 19 | using v8::Script; |
| 20 | using v8::String; |
| 21 | |
| 22 | namespace gin { |
| 23 | |
| 24 | TEST(RunnerTest, Run) { |
| 25 | std::string source = "this.result = 'PASS';\n"; |
| 26 | |
James Robinson | 53b7758 | 2014-10-28 17:00:48 -0700 | [diff] [blame] | 27 | #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
| 28 | gin::IsolateHolder::LoadV8Snapshot(); |
| 29 | #endif |
| 30 | |
James Robinson | a976313 | 2014-10-06 11:18:13 -0700 | [diff] [blame] | 31 | gin::IsolateHolder::Initialize(gin::IsolateHolder::kStrictMode, |
| 32 | gin::ArrayBufferAllocator::SharedInstance()); |
| 33 | gin::IsolateHolder instance; |
| 34 | |
| 35 | ShellRunnerDelegate delegate; |
| 36 | Isolate* isolate = instance.isolate(); |
| 37 | ShellRunner runner(&delegate, isolate); |
| 38 | Runner::Scope scope(&runner); |
| 39 | runner.Run(source, "test_data.js"); |
| 40 | |
| 41 | std::string result; |
| 42 | EXPECT_TRUE(Converter<std::string>::FromV8(isolate, |
| 43 | runner.global()->Get(StringToV8(isolate, "result")), |
| 44 | &result)); |
| 45 | EXPECT_EQ("PASS", result); |
| 46 | } |
| 47 | |
| 48 | } // namespace gin |