Landing Recent QUIC Changes.
[chromium-blink-merge.git] / gin / test / file_runner.cc
blob82b55ade05c3a1ad42f2670395ccd98335a9804c
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/file.h"
16 #include "gin/test/gc.h"
17 #include "gin/test/gtest.h"
18 #include "gin/try_catch.h"
19 #include "testing/gtest/include/gtest/gtest.h"
21 namespace gin {
23 namespace {
25 std::vector<base::FilePath> GetModuleSearchPaths() {
26 std::vector<base::FilePath> search_paths(2);
27 PathService::Get(base::DIR_SOURCE_ROOT, &search_paths[0]);
28 PathService::Get(base::DIR_EXE, &search_paths[1]);
29 search_paths[1] = search_paths[1].AppendASCII("gen");
30 return search_paths;
33 } // namespace
35 FileRunnerDelegate::FileRunnerDelegate()
36 : ModuleRunnerDelegate(GetModuleSearchPaths()) {
37 AddBuiltinModule(Console::kModuleName, Console::GetModule);
38 AddBuiltinModule(GTest::kModuleName, GTest::GetModule);
39 AddBuiltinModule(GC::kModuleName, GC::GetModule);
40 AddBuiltinModule(File::kModuleName, File::GetModule);
43 FileRunnerDelegate::~FileRunnerDelegate() {
46 void FileRunnerDelegate::UnhandledException(ShellRunner* runner,
47 TryCatch& try_catch) {
48 ModuleRunnerDelegate::UnhandledException(runner, try_catch);
49 FAIL() << try_catch.GetStackTrace();
52 void RunTestFromFile(const base::FilePath& path, FileRunnerDelegate* delegate,
53 bool run_until_idle) {
54 ASSERT_TRUE(base::PathExists(path)) << path.LossyDisplayName();
55 std::string source;
56 ASSERT_TRUE(ReadFileToString(path, &source));
58 base::MessageLoop message_loop;
60 gin::IsolateHolder instance(gin::IsolateHolder::kStrictMode);
61 gin::ShellRunner runner(delegate, instance.isolate());
63 gin::Runner::Scope scope(&runner);
64 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true);
65 runner.Run(source, path.AsUTF8Unsafe());
67 if (run_until_idle) {
68 message_loop.RunUntilIdle();
69 } else {
70 message_loop.Run();
73 v8::Handle<v8::Value> result = runner.global()->Get(
74 StringToSymbol(runner.GetContextHolder()->isolate(), "result"));
75 EXPECT_EQ("PASS", V8ToString(result));
79 } // namespace gin