| 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 "gin/shell_runner.h" | 5 #include "gin/shell_runner.h" | 
| 6 | 6 | 
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" | 
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/test/scoped_task_environment.h" | 
| 9 #include "base/threading/thread_task_runner_handle.h" | 9 #include "base/threading/thread_task_runner_handle.h" | 
| 10 #include "gin/array_buffer.h" | 10 #include "gin/array_buffer.h" | 
| 11 #include "gin/converter.h" | 11 #include "gin/converter.h" | 
| 12 #include "gin/public/isolate_holder.h" | 12 #include "gin/public/isolate_holder.h" | 
| 13 #include "gin/v8_initializer.h" | 13 #include "gin/v8_initializer.h" | 
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" | 
| 15 | 15 | 
| 16 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 16 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 
| 17 #include "gin/public/isolate_holder.h" | 17 #include "gin/public/isolate_holder.h" | 
| 18 #endif | 18 #endif | 
| 19 | 19 | 
| 20 using v8::Isolate; | 20 using v8::Isolate; | 
| 21 using v8::Object; | 21 using v8::Object; | 
| 22 using v8::Script; | 22 using v8::Script; | 
| 23 using v8::String; | 23 using v8::String; | 
| 24 | 24 | 
| 25 namespace gin { | 25 namespace gin { | 
| 26 | 26 | 
| 27 TEST(RunnerTest, Run) { | 27 TEST(RunnerTest, Run) { | 
| 28   base::MessageLoop message_loop; | 28   base::test::ScopedTaskEnvironment scoped_task_environment; | 
| 29   std::string source = "this.result = 'PASS';\n"; | 29   std::string source = "this.result = 'PASS';\n"; | 
| 30 | 30 | 
| 31 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 31 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 
| 32   gin::V8Initializer::LoadV8Snapshot(); | 32   gin::V8Initializer::LoadV8Snapshot(); | 
| 33   gin::V8Initializer::LoadV8Natives(); | 33   gin::V8Initializer::LoadV8Natives(); | 
| 34 #endif | 34 #endif | 
| 35 | 35 | 
| 36   gin::IsolateHolder::Initialize(gin::IsolateHolder::kStrictMode, | 36   gin::IsolateHolder::Initialize(gin::IsolateHolder::kStrictMode, | 
| 37                                  gin::IsolateHolder::kStableV8Extras, | 37                                  gin::IsolateHolder::kStableV8Extras, | 
| 38                                  gin::ArrayBufferAllocator::SharedInstance()); | 38                                  gin::ArrayBufferAllocator::SharedInstance()); | 
| 39   gin::IsolateHolder instance(base::ThreadTaskRunnerHandle::Get()); | 39   gin::IsolateHolder instance(base::ThreadTaskRunnerHandle::Get()); | 
| 40 | 40 | 
| 41   ShellRunnerDelegate delegate; | 41   ShellRunnerDelegate delegate; | 
| 42   Isolate* isolate = instance.isolate(); | 42   Isolate* isolate = instance.isolate(); | 
| 43   ShellRunner runner(&delegate, isolate); | 43   ShellRunner runner(&delegate, isolate); | 
| 44   Runner::Scope scope(&runner); | 44   Runner::Scope scope(&runner); | 
| 45   runner.Run(source, "test_data.js"); | 45   runner.Run(source, "test_data.js"); | 
| 46 | 46 | 
| 47   std::string result; | 47   std::string result; | 
| 48   EXPECT_TRUE(Converter<std::string>::FromV8(isolate, | 48   EXPECT_TRUE(Converter<std::string>::FromV8(isolate, | 
| 49       runner.global()->Get(StringToV8(isolate, "result")), | 49       runner.global()->Get(StringToV8(isolate, "result")), | 
| 50       &result)); | 50       &result)); | 
| 51   EXPECT_EQ("PASS", result); | 51   EXPECT_EQ("PASS", result); | 
| 52 } | 52 } | 
| 53 | 53 | 
| 54 }  // namespace gin | 54 }  // namespace gin | 
| OLD | NEW | 
|---|