rAc: fix some compile warnings in libaddressinput's tests.
[chromium-blink-merge.git] / gin / test / file_runner.cc
blob7b9127368d6591675eb5de8a195b4d6cb6dc38bd
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/isolate_holder.h"
14 #include "gin/test/gtest.h"
15 #include "gin/try_catch.h"
16 #include "testing/gtest/include/gtest/gtest.h"
18 namespace gin {
20 namespace {
22 std::vector<base::FilePath> GetModuleSearchPaths() {
23 std::vector<base::FilePath> search_paths(2);
24 PathService::Get(base::DIR_SOURCE_ROOT, &search_paths[0]);
25 PathService::Get(base::DIR_EXE, &search_paths[1]);
26 search_paths[1] = search_paths[1].AppendASCII("gen");
27 return search_paths;
30 } // namespace
32 FileRunnerDelegate::FileRunnerDelegate()
33 : ModuleRunnerDelegate(GetModuleSearchPaths()) {
34 AddBuiltinModule(Console::kModuleName, Console::GetModule);
35 AddBuiltinModule(GTest::kModuleName, GTest::GetModule);
38 FileRunnerDelegate::~FileRunnerDelegate() {
41 void FileRunnerDelegate::UnhandledException(Runner* runner,
42 TryCatch& try_catch) {
43 ModuleRunnerDelegate::UnhandledException(runner, try_catch);
44 FAIL() << try_catch.GetStackTrace();
47 void RunTestFromFile(const base::FilePath& path, FileRunnerDelegate* delegate,
48 bool run_until_idle) {
49 ASSERT_TRUE(base::PathExists(path)) << path.LossyDisplayName();
50 std::string source;
51 ASSERT_TRUE(ReadFileToString(path, &source));
53 base::MessageLoop message_loop;
55 gin::IsolateHolder instance;
56 gin::Runner runner(delegate, instance.isolate());
58 gin::Runner::Scope scope(&runner);
59 v8::V8::SetCaptureStackTraceForUncaughtExceptions(true);
60 runner.Run(source, path.AsUTF8Unsafe());
62 if (run_until_idle) {
63 message_loop.RunUntilIdle();
64 } else {
65 message_loop.Run();
68 v8::Handle<v8::Value> result = runner.context()->Global()->Get(
69 StringToSymbol(runner.isolate(), "result"));
70 EXPECT_EQ("PASS", V8ToString(result));
74 } // namespace gin