| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/test/file_runner.h" | 5 #include "gin/test/file_runner.h" |
| 6 | 6 |
| 7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.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/modules/console.h" | 12 #include "gin/modules/console.h" |
| 13 #include "gin/modules/module_registry.h" | 13 #include "gin/modules/module_registry.h" |
| 14 #include "gin/public/context_holder.h" | 14 #include "gin/public/context_holder.h" |
| 15 #include "gin/public/isolate_holder.h" | 15 #include "gin/public/isolate_holder.h" |
| 16 #include "gin/test/file.h" | 16 #include "gin/test/file.h" |
| 17 #include "gin/test/gc.h" | 17 #include "gin/test/gc.h" |
| 18 #include "gin/test/gtest.h" | 18 #include "gin/test/gtest.h" |
| 19 #include "gin/try_catch.h" | 19 #include "gin/try_catch.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 21 |
| 22 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
| 23 #include "gin/public/isolate_holder.h" |
| 24 #endif |
| 25 |
| 22 namespace gin { | 26 namespace gin { |
| 23 | 27 |
| 24 namespace { | 28 namespace { |
| 25 | 29 |
| 26 std::vector<base::FilePath> GetModuleSearchPaths() { | 30 std::vector<base::FilePath> GetModuleSearchPaths() { |
| 27 std::vector<base::FilePath> search_paths(2); | 31 std::vector<base::FilePath> search_paths(2); |
| 28 PathService::Get(base::DIR_SOURCE_ROOT, &search_paths[0]); | 32 PathService::Get(base::DIR_SOURCE_ROOT, &search_paths[0]); |
| 29 PathService::Get(base::DIR_EXE, &search_paths[1]); | 33 PathService::Get(base::DIR_EXE, &search_paths[1]); |
| 30 search_paths[1] = search_paths[1].AppendASCII("gen"); | 34 search_paths[1] = search_paths[1].AppendASCII("gen"); |
| 31 return search_paths; | 35 return search_paths; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 51 } | 55 } |
| 52 | 56 |
| 53 void RunTestFromFile(const base::FilePath& path, FileRunnerDelegate* delegate, | 57 void RunTestFromFile(const base::FilePath& path, FileRunnerDelegate* delegate, |
| 54 bool run_until_idle) { | 58 bool run_until_idle) { |
| 55 ASSERT_TRUE(base::PathExists(path)) << path.LossyDisplayName(); | 59 ASSERT_TRUE(base::PathExists(path)) << path.LossyDisplayName(); |
| 56 std::string source; | 60 std::string source; |
| 57 ASSERT_TRUE(ReadFileToString(path, &source)); | 61 ASSERT_TRUE(ReadFileToString(path, &source)); |
| 58 | 62 |
| 59 base::MessageLoop message_loop; | 63 base::MessageLoop message_loop; |
| 60 | 64 |
| 65 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
| 66 gin::IsolateHolder::LoadV8Snapshot(); |
| 67 #endif |
| 68 |
| 61 gin::IsolateHolder::Initialize(gin::IsolateHolder::kStrictMode, | 69 gin::IsolateHolder::Initialize(gin::IsolateHolder::kStrictMode, |
| 62 gin::ArrayBufferAllocator::SharedInstance()); | 70 gin::ArrayBufferAllocator::SharedInstance()); |
| 63 gin::IsolateHolder instance; | 71 gin::IsolateHolder instance; |
| 64 gin::ShellRunner runner(delegate, instance.isolate()); | 72 gin::ShellRunner runner(delegate, instance.isolate()); |
| 65 { | 73 { |
| 66 gin::Runner::Scope scope(&runner); | 74 gin::Runner::Scope scope(&runner); |
| 67 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); | 75 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); |
| 68 runner.Run(source, path.AsUTF8Unsafe()); | 76 runner.Run(source, path.AsUTF8Unsafe()); |
| 69 | 77 |
| 70 if (run_until_idle) { | 78 if (run_until_idle) { |
| 71 message_loop.RunUntilIdle(); | 79 message_loop.RunUntilIdle(); |
| 72 } else { | 80 } else { |
| 73 message_loop.Run(); | 81 message_loop.Run(); |
| 74 } | 82 } |
| 75 | 83 |
| 76 v8::Handle<v8::Value> result = runner.global()->Get( | 84 v8::Handle<v8::Value> result = runner.global()->Get( |
| 77 StringToSymbol(runner.GetContextHolder()->isolate(), "result")); | 85 StringToSymbol(runner.GetContextHolder()->isolate(), "result")); |
| 78 EXPECT_EQ("PASS", V8ToString(result)); | 86 EXPECT_EQ("PASS", V8ToString(result)); |
| 79 } | 87 } |
| 80 } | 88 } |
| 81 | 89 |
| 82 } // namespace gin | 90 } // namespace gin |
| OLD | NEW |