Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(205)

Side by Side Diff: gin/test/file_runner.cc

Issue 74753002: Introduce gin_shell (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "gin/test/file_runner.h" 5 #include "gin/test/file_runner.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/path_service.h"
8 #include "gin/converter.h" 10 #include "gin/converter.h"
9 #include "gin/modules/module_registry.h" 11 #include "gin/modules/module_registry.h"
10 #include "gin/test/gtest.h" 12 #include "gin/test/gtest.h"
13 #include "gin/try_catch.h"
11 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
12 15
13 namespace gin { 16 namespace gin {
14 17
15 namespace { 18 namespace {
16 19
17 std::string GetExceptionInfo(const v8::TryCatch& try_catch) { 20 base::FilePath GetModuleBase() {
18 std::string info; 21 base::FilePath path;
19 ConvertFromV8(try_catch.Message()->Get(), &info); 22 PathService::Get(base::DIR_SOURCE_ROOT, &path);
20 return info; 23 return path;
21 } 24 }
22 25
23 } // namespace 26 } // namespace
24 27
25 FileRunnerDelegate::FileRunnerDelegate() { 28 FileRunnerDelegate::FileRunnerDelegate()
29 : ModuleRunnerDelegate(GetModuleBase()) {
26 } 30 }
27 31
28 FileRunnerDelegate::~FileRunnerDelegate() { 32 FileRunnerDelegate::~FileRunnerDelegate() {
29 } 33 }
30 34
31 v8::Handle<v8::ObjectTemplate> FileRunnerDelegate::GetGlobalTemplate( 35 void FileRunnerDelegate::DidCreateContext(Runner* runner) {
32 Runner* runner) { 36 ModuleRunnerDelegate::DidCreateContext(runner);
33 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New();
34 ModuleRegistry::RegisterGlobals(runner->isolate(), templ);
35 return templ;
36 }
37 37
38 void FileRunnerDelegate::DidCreateContext(Runner* runner) {
39 v8::Handle<v8::Context> context = runner->context(); 38 v8::Handle<v8::Context> context = runner->context();
40 ModuleRegistry* registry = ModuleRegistry::From(context); 39 ModuleRegistry* registry = ModuleRegistry::From(context);
41 40
42 registry->AddBuiltinModule(runner->isolate(), "gtest", 41 registry->AddBuiltinModule(runner->isolate(), "gtest",
43 GetGTestTemplate(runner->isolate())); 42 GetGTestTemplate(runner->isolate()));
44 } 43 }
45 44
45 void FileRunnerDelegate::UnhandledException(Runner* runner,
46 TryCatch& try_catch) {
47 ModuleRunnerDelegate::UnhandledException(runner, try_catch);
48 EXPECT_FALSE(try_catch.HasCaught()) << try_catch.GetPrettyMessage();
49 }
50
46 void RunTestFromFile(const base::FilePath& path, RunnerDelegate* delegate) { 51 void RunTestFromFile(const base::FilePath& path, RunnerDelegate* delegate) {
47 ASSERT_TRUE(base::PathExists(path)) << path.LossyDisplayName(); 52 ASSERT_TRUE(base::PathExists(path)) << path.LossyDisplayName();
48 std::string source; 53 std::string source;
49 ASSERT_TRUE(ReadFileToString(path, &source)); 54 ASSERT_TRUE(ReadFileToString(path, &source));
55
56 base::MessageLoop message_loop;
57
50 gin::Runner runner(delegate, v8::Isolate::GetCurrent()); 58 gin::Runner runner(delegate, v8::Isolate::GetCurrent());
51 gin::Runner::Scope scope(&runner); 59 gin::Runner::Scope scope(&runner);
60 runner.Run(source);
52 61
53 v8::TryCatch try_catch; 62 message_loop.RunUntilIdle();
54 runner.Run(source);
55 EXPECT_FALSE(try_catch.HasCaught()) << GetExceptionInfo(try_catch);
56 63
57 v8::Handle<v8::Value> result = runner.context()->Global()->Get( 64 v8::Handle<v8::Value> result = runner.context()->Global()->Get(
58 StringToSymbol(runner.isolate(), "result")); 65 StringToSymbol(runner.isolate(), "result"));
59 std::string result_string; 66 std::string result_string;
60 ASSERT_TRUE(ConvertFromV8(result, &result_string)); 67 ASSERT_TRUE(ConvertFromV8(result, &result_string));
61 EXPECT_EQ("PASS", result_string); 68 EXPECT_EQ("PASS", result_string);
62 } 69 }
63 70
64 } // namespace gin 71 } // namespace gin
OLDNEW
« gin/gin.gyp ('K') | « gin/test/file_runner.h ('k') | gin/try_catch.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698