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/file_util.h" | 7 #include "base/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/converter.h" | 10 #include "gin/converter.h" |
11 #include "gin/modules/console.h" | 11 #include "gin/modules/console.h" |
12 #include "gin/modules/module_registry.h" | 12 #include "gin/modules/module_registry.h" |
| 13 #include "gin/public/context_holder.h" |
13 #include "gin/public/isolate_holder.h" | 14 #include "gin/public/isolate_holder.h" |
14 #include "gin/test/gtest.h" | 15 #include "gin/test/gtest.h" |
15 #include "gin/try_catch.h" | 16 #include "gin/try_catch.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 | 18 |
18 namespace gin { | 19 namespace gin { |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 std::vector<base::FilePath> GetModuleSearchPaths() { | 23 std::vector<base::FilePath> GetModuleSearchPaths() { |
23 std::vector<base::FilePath> search_paths(2); | 24 std::vector<base::FilePath> search_paths(2); |
24 PathService::Get(base::DIR_SOURCE_ROOT, &search_paths[0]); | 25 PathService::Get(base::DIR_SOURCE_ROOT, &search_paths[0]); |
25 PathService::Get(base::DIR_EXE, &search_paths[1]); | 26 PathService::Get(base::DIR_EXE, &search_paths[1]); |
26 search_paths[1] = search_paths[1].AppendASCII("gen"); | 27 search_paths[1] = search_paths[1].AppendASCII("gen"); |
27 return search_paths; | 28 return search_paths; |
28 } | 29 } |
29 | 30 |
30 } // namespace | 31 } // namespace |
31 | 32 |
32 FileRunnerDelegate::FileRunnerDelegate() | 33 FileRunnerDelegate::FileRunnerDelegate() |
33 : ModuleRunnerDelegate(GetModuleSearchPaths()) { | 34 : ModuleRunnerDelegate(GetModuleSearchPaths()) { |
34 AddBuiltinModule(Console::kModuleName, Console::GetModule); | 35 AddBuiltinModule(Console::kModuleName, Console::GetModule); |
35 AddBuiltinModule(GTest::kModuleName, GTest::GetModule); | 36 AddBuiltinModule(GTest::kModuleName, GTest::GetModule); |
36 } | 37 } |
37 | 38 |
38 FileRunnerDelegate::~FileRunnerDelegate() { | 39 FileRunnerDelegate::~FileRunnerDelegate() { |
39 } | 40 } |
40 | 41 |
41 void FileRunnerDelegate::UnhandledException(Runner* runner, | 42 void FileRunnerDelegate::UnhandledException(ShellRunner* runner, |
42 TryCatch& try_catch) { | 43 TryCatch& try_catch) { |
43 ModuleRunnerDelegate::UnhandledException(runner, try_catch); | 44 ModuleRunnerDelegate::UnhandledException(runner, try_catch); |
44 FAIL() << try_catch.GetStackTrace(); | 45 FAIL() << try_catch.GetStackTrace(); |
45 } | 46 } |
46 | 47 |
47 void RunTestFromFile(const base::FilePath& path, FileRunnerDelegate* delegate, | 48 void RunTestFromFile(const base::FilePath& path, FileRunnerDelegate* delegate, |
48 bool run_until_idle) { | 49 bool run_until_idle) { |
49 ASSERT_TRUE(base::PathExists(path)) << path.LossyDisplayName(); | 50 ASSERT_TRUE(base::PathExists(path)) << path.LossyDisplayName(); |
50 std::string source; | 51 std::string source; |
51 ASSERT_TRUE(ReadFileToString(path, &source)); | 52 ASSERT_TRUE(ReadFileToString(path, &source)); |
52 | 53 |
53 base::MessageLoop message_loop; | 54 base::MessageLoop message_loop; |
54 | 55 |
55 gin::IsolateHolder instance; | 56 gin::IsolateHolder instance; |
56 gin::Runner runner(delegate, instance.isolate()); | 57 gin::ShellRunner runner(delegate, instance.isolate()); |
57 { | 58 { |
58 gin::Runner::Scope scope(&runner); | 59 gin::Runner::Scope scope(&runner); |
59 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); | 60 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true); |
60 runner.Run(source, path.AsUTF8Unsafe()); | 61 runner.Run(source, path.AsUTF8Unsafe()); |
61 | 62 |
62 if (run_until_idle) { | 63 if (run_until_idle) { |
63 message_loop.RunUntilIdle(); | 64 message_loop.RunUntilIdle(); |
64 } else { | 65 } else { |
65 message_loop.Run(); | 66 message_loop.Run(); |
66 } | 67 } |
67 | 68 |
68 v8::Handle<v8::Value> result = runner.context()->Global()->Get( | 69 v8::Handle<v8::Value> result = runner.global()->Get( |
69 StringToSymbol(runner.isolate(), "result")); | 70 StringToSymbol(runner.GetContextHolder()->isolate(), "result")); |
70 EXPECT_EQ("PASS", V8ToString(result)); | 71 EXPECT_EQ("PASS", V8ToString(result)); |
71 } | 72 } |
72 } | 73 } |
73 | 74 |
74 } // namespace gin | 75 } // namespace gin |
OLD | NEW |