OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "gin/test/file_runner.h" |
| 6 |
| 7 #include "base/file_util.h" |
| 8 #include "gin/converter.h" |
| 9 #include "gin/modules/module_registry.h" |
| 10 #include "gin/test/gtest.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 |
| 13 namespace gin { |
| 14 |
| 15 namespace { |
| 16 |
| 17 std::string GetExceptionInfo(const v8::TryCatch& try_catch) { |
| 18 std::string info; |
| 19 ConvertFromV8(try_catch.Message()->Get(), &info); |
| 20 return info; |
| 21 } |
| 22 |
| 23 } // namespace |
| 24 |
| 25 FileRunnerDelegate::FileRunnerDelegate() { |
| 26 } |
| 27 |
| 28 FileRunnerDelegate::~FileRunnerDelegate() { |
| 29 } |
| 30 |
| 31 v8::Handle<v8::ObjectTemplate> FileRunnerDelegate::GetGlobalTemplate( |
| 32 Runner* runner) { |
| 33 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); |
| 34 ModuleRegistry::RegisterGlobals(runner->isolate(), templ); |
| 35 return templ; |
| 36 } |
| 37 |
| 38 void FileRunnerDelegate::DidCreateContext(Runner* runner) { |
| 39 v8::Handle<v8::Context> context = runner->context(); |
| 40 ModuleRegistry* registry = ModuleRegistry::From(context); |
| 41 |
| 42 registry->AddBuiltinModule(runner->isolate(), "gtest", |
| 43 GetGTestTemplate(runner->isolate())); |
| 44 } |
| 45 |
| 46 void RunTestFromFile(const base::FilePath& path, RunnerDelegate* delegate) { |
| 47 ASSERT_TRUE(base::PathExists(path)) << path.LossyDisplayName(); |
| 48 std::string source; |
| 49 ASSERT_TRUE(ReadFileToString(path, &source)); |
| 50 gin::Runner runner(delegate, v8::Isolate::GetCurrent()); |
| 51 gin::Runner::Scope scope(&runner); |
| 52 |
| 53 v8::TryCatch try_catch; |
| 54 runner.Run(source); |
| 55 EXPECT_FALSE(try_catch.HasCaught()) << GetExceptionInfo(try_catch); |
| 56 |
| 57 v8::Handle<v8::Value> result = runner.context()->Global()->Get( |
| 58 StringToSymbol(runner.isolate(), "result")); |
| 59 std::string result_string; |
| 60 ASSERT_TRUE(ConvertFromV8(result, &result_string)); |
| 61 EXPECT_EQ("PASS", result_string); |
| 62 } |
| 63 |
| 64 } // namespace gin |
OLD | NEW |