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
3 // found in the LICENSE file.
5 #include "gin/test/file_runner.h"
7 #include "base/file_util.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/path_service.h"
10 #include "gin/converter.h"
11 #include "gin/modules/console.h"
12 #include "gin/modules/module_registry.h"
13 #include "gin/public/context_holder.h"
14 #include "gin/public/isolate_holder.h"
15 #include "gin/test/gc.h"
16 #include "gin/test/gtest.h"
17 #include "gin/try_catch.h"
18 #include "testing/gtest/include/gtest/gtest.h"
24 std::vector
<base::FilePath
> GetModuleSearchPaths() {
25 std::vector
<base::FilePath
> search_paths(2);
26 PathService::Get(base::DIR_SOURCE_ROOT
, &search_paths
[0]);
27 PathService::Get(base::DIR_EXE
, &search_paths
[1]);
28 search_paths
[1] = search_paths
[1].AppendASCII("gen");
34 FileRunnerDelegate::FileRunnerDelegate()
35 : ModuleRunnerDelegate(GetModuleSearchPaths()) {
36 AddBuiltinModule(Console::kModuleName
, Console::GetModule
);
37 AddBuiltinModule(GTest::kModuleName
, GTest::GetModule
);
38 AddBuiltinModule(GC::kModuleName
, GC::GetModule
);
41 FileRunnerDelegate::~FileRunnerDelegate() {
44 void FileRunnerDelegate::UnhandledException(ShellRunner
* runner
,
45 TryCatch
& try_catch
) {
46 ModuleRunnerDelegate::UnhandledException(runner
, try_catch
);
47 FAIL() << try_catch
.GetStackTrace();
50 void RunTestFromFile(const base::FilePath
& path
, FileRunnerDelegate
* delegate
,
51 bool run_until_idle
) {
52 ASSERT_TRUE(base::PathExists(path
)) << path
.LossyDisplayName();
54 ASSERT_TRUE(ReadFileToString(path
, &source
));
56 base::MessageLoop message_loop
;
58 gin::IsolateHolder
instance(gin::IsolateHolder::kStrictMode
);
59 gin::ShellRunner
runner(delegate
, instance
.isolate());
61 gin::Runner::Scope
scope(&runner
);
62 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true);
63 runner
.Run(source
, path
.AsUTF8Unsafe());
66 message_loop
.RunUntilIdle();
71 v8::Handle
<v8::Value
> result
= runner
.global()->Get(
72 StringToSymbol(runner
.GetContextHolder()->isolate(), "result"));
73 EXPECT_EQ("PASS", V8ToString(result
));