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

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

Issue 69843003: Implement Mojo message codec in JavaScript (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Seems to work! 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 "gin/converter.h" 8 #include "gin/converter.h"
9 #include "gin/modules/module_registry.h" 9 #include "gin/modules/module_registry.h"
10 #include "gin/test/gtest.h" 10 #include "gin/test/gtest.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 namespace gin { 13 namespace gin {
14 14
15 namespace { 15 namespace {
16 16
17 std::string GetExceptionInfo(const v8::TryCatch& try_catch) { 17 std::string GetExceptionInfo(const v8::TryCatch& try_catch) {
18 std::string info; 18 std::string message;
19 ConvertFromV8(try_catch.Message()->Get(), &info); 19 ConvertFromV8(try_catch.Message()->Get(), &message);
20 return info; 20
21 std::string source_line;
22 if (ConvertFromV8(try_catch.Message()->GetSourceLine(), &source_line))
23 message += "\n" + source_line;
24
25 return message;
21 } 26 }
22 27
23 } // namespace 28 } // namespace
24 29
25 FileRunnerDelegate::FileRunnerDelegate() { 30 FileRunnerDelegate::FileRunnerDelegate() {
26 } 31 }
27 32
28 FileRunnerDelegate::~FileRunnerDelegate() { 33 FileRunnerDelegate::~FileRunnerDelegate() {
29 } 34 }
30 35
31 v8::Handle<v8::ObjectTemplate> FileRunnerDelegate::GetGlobalTemplate( 36 v8::Handle<v8::ObjectTemplate> FileRunnerDelegate::GetGlobalTemplate(
32 Runner* runner) { 37 Runner* runner) {
33 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(); 38 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New();
34 ModuleRegistry::RegisterGlobals(runner->isolate(), templ); 39 ModuleRegistry::RegisterGlobals(runner->isolate(), templ);
35 return templ; 40 return templ;
36 } 41 }
37 42
38 void FileRunnerDelegate::DidCreateContext(Runner* runner) { 43 void FileRunnerDelegate::DidCreateContext(Runner* runner) {
39 v8::Handle<v8::Context> context = runner->context(); 44 v8::Handle<v8::Context> context = runner->context();
40 ModuleRegistry* registry = ModuleRegistry::From(context); 45 ModuleRegistry* registry = ModuleRegistry::From(context);
41 46
42 registry->AddBuiltinModule(runner->isolate(), "gtest", 47 registry->AddBuiltinModule(runner->isolate(), "gtest",
43 GetGTestTemplate(runner->isolate())); 48 GetGTestTemplate(runner->isolate()));
44 } 49 }
45 50
46 void RunTestFromFile(const base::FilePath& path, RunnerDelegate* delegate) { 51 void RunTestFromString(const std::string& source, 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()); 52 gin::Runner runner(delegate, v8::Isolate::GetCurrent());
51 gin::Runner::Scope scope(&runner); 53 gin::Runner::Scope scope(&runner);
52 54
53 v8::TryCatch try_catch; 55 v8::TryCatch try_catch;
54 runner.Run(source); 56 runner.Run(source);
55 EXPECT_FALSE(try_catch.HasCaught()) << GetExceptionInfo(try_catch); 57 EXPECT_FALSE(try_catch.HasCaught()) << GetExceptionInfo(try_catch);
56 58
57 v8::Handle<v8::Value> result = runner.context()->Global()->Get( 59 v8::Handle<v8::Value> result = runner.context()->Global()->Get(
58 StringToSymbol(runner.isolate(), "result")); 60 StringToSymbol(runner.isolate(), "result"));
59 std::string result_string; 61 std::string result_string;
60 ASSERT_TRUE(ConvertFromV8(result, &result_string)); 62 ASSERT_TRUE(ConvertFromV8(result, &result_string));
61 EXPECT_EQ("PASS", result_string); 63 EXPECT_EQ("PASS", result_string);
62 } 64 }
63 65
66 void RunTestFromFile(const base::FilePath& path, RunnerDelegate* delegate) {
67 ASSERT_TRUE(base::PathExists(path)) << path.LossyDisplayName();
68 std::string source;
69 ASSERT_TRUE(ReadFileToString(path, &source));
70 RunTestFromString(source, delegate);
71 }
72
64 } // namespace gin 73 } // namespace gin
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698