Apply _RELATIVE relocations ahead of others.
[chromium-blink-merge.git] / gin / test / file_runner.cc
blobb639d0640630e8821cb01ccd330b15e1eed8396f
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/files/file_util.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/path_service.h"
10 #include "gin/array_buffer.h"
11 #include "gin/converter.h"
12 #include "gin/modules/console.h"
13 #include "gin/modules/module_registry.h"
14 #include "gin/public/context_holder.h"
15 #include "gin/public/isolate_holder.h"
16 #include "gin/test/file.h"
17 #include "gin/test/gc.h"
18 #include "gin/test/gtest.h"
19 #include "gin/try_catch.h"
20 #include "testing/gtest/include/gtest/gtest.h"
22 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
23 #include "gin/public/isolate_holder.h"
24 #endif
26 namespace gin {
28 namespace {
30 std::vector<base::FilePath> GetModuleSearchPaths() {
31 std::vector<base::FilePath> search_paths(2);
32 PathService::Get(base::DIR_SOURCE_ROOT, &search_paths[0]);
33 PathService::Get(base::DIR_EXE, &search_paths[1]);
34 search_paths[1] = search_paths[1].AppendASCII("gen");
35 return search_paths;
38 } // namespace
40 FileRunnerDelegate::FileRunnerDelegate()
41 : ModuleRunnerDelegate(GetModuleSearchPaths()) {
42 AddBuiltinModule(Console::kModuleName, Console::GetModule);
43 AddBuiltinModule(GTest::kModuleName, GTest::GetModule);
44 AddBuiltinModule(GC::kModuleName, GC::GetModule);
45 AddBuiltinModule(File::kModuleName, File::GetModule);
48 FileRunnerDelegate::~FileRunnerDelegate() {
51 void FileRunnerDelegate::UnhandledException(ShellRunner* runner,
52 TryCatch& try_catch) {
53 ModuleRunnerDelegate::UnhandledException(runner, try_catch);
54 FAIL() << try_catch.GetStackTrace();
57 void RunTestFromFile(const base::FilePath& path, FileRunnerDelegate* delegate,
58 bool run_until_idle) {
59 ASSERT_TRUE(base::PathExists(path)) << path.LossyDisplayName();
60 std::string source;
61 ASSERT_TRUE(ReadFileToString(path, &source));
63 base::MessageLoop message_loop;
65 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
66 gin::IsolateHolder::LoadV8Snapshot();
67 #endif
69 gin::IsolateHolder::Initialize(gin::IsolateHolder::kStrictMode,
70 gin::ArrayBufferAllocator::SharedInstance());
71 gin::IsolateHolder instance;
72 gin::ShellRunner runner(delegate, instance.isolate());
74 gin::Runner::Scope scope(&runner);
75 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true);
76 runner.Run(source, path.AsUTF8Unsafe());
78 if (run_until_idle) {
79 message_loop.RunUntilIdle();
80 } else {
81 message_loop.Run();
84 v8::Handle<v8::Value> result = runner.global()->Get(
85 StringToSymbol(runner.GetContextHolder()->isolate(), "result"));
86 EXPECT_EQ("PASS", V8ToString(result));
90 } // namespace gin