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

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: Address Aaron's comments 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
« no previous file with comments | « gin/test/file_runner.h ('k') | gin/test/gtest.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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" 8 #include "base/message_loop/message_loop.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "gin/converter.h" 10 #include "gin/converter.h"
11 #include "gin/modules/module_registry.h" 11 #include "gin/modules/module_registry.h"
12 #include "gin/test/gtest.h" 12 #include "gin/test/gtest.h"
13 #include "gin/try_catch.h" 13 #include "gin/try_catch.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 namespace gin { 16 namespace gin {
17 17
18 namespace { 18 namespace {
19 19
20 base::FilePath GetModuleBase() { 20 base::FilePath GetModuleBase() {
21 base::FilePath path; 21 base::FilePath path;
22 PathService::Get(base::DIR_SOURCE_ROOT, &path); 22 PathService::Get(base::DIR_SOURCE_ROOT, &path);
23 return path; 23 return path;
24 } 24 }
25 25
26 } // namespace 26 } // namespace
27 27
28 FileRunnerDelegate::FileRunnerDelegate() 28 FileRunnerDelegate::FileRunnerDelegate()
29 : ModuleRunnerDelegate(GetModuleBase()) { 29 : ModuleRunnerDelegate(GetModuleBase()) {
30 AddBuiltinModule(GTest::kModuleName, GTest::GetTemplate);
30 } 31 }
31 32
32 FileRunnerDelegate::~FileRunnerDelegate() { 33 FileRunnerDelegate::~FileRunnerDelegate() {
33 } 34 }
34 35
35 void FileRunnerDelegate::DidCreateContext(Runner* runner) {
36 ModuleRunnerDelegate::DidCreateContext(runner);
37
38 v8::Handle<v8::Context> context = runner->context();
39 ModuleRegistry* registry = ModuleRegistry::From(context);
40
41 registry->AddBuiltinModule(runner->isolate(), "gtest",
42 GetGTestTemplate(runner->isolate()));
43 }
44
45 void FileRunnerDelegate::UnhandledException(Runner* runner, 36 void FileRunnerDelegate::UnhandledException(Runner* runner,
46 TryCatch& try_catch) { 37 TryCatch& try_catch) {
47 ModuleRunnerDelegate::UnhandledException(runner, try_catch); 38 ModuleRunnerDelegate::UnhandledException(runner, try_catch);
48 EXPECT_FALSE(try_catch.HasCaught()) << try_catch.GetPrettyMessage(); 39 EXPECT_FALSE(try_catch.HasCaught()) << try_catch.GetPrettyMessage();
49 } 40 }
50 41
51 void RunTestFromFile(const base::FilePath& path, RunnerDelegate* delegate) { 42 void RunTestFromFile(const base::FilePath& path, FileRunnerDelegate* delegate) {
52 ASSERT_TRUE(base::PathExists(path)) << path.LossyDisplayName(); 43 ASSERT_TRUE(base::PathExists(path)) << path.LossyDisplayName();
53 std::string source; 44 std::string source;
54 ASSERT_TRUE(ReadFileToString(path, &source)); 45 ASSERT_TRUE(ReadFileToString(path, &source));
55 46
56 base::MessageLoop message_loop; 47 base::MessageLoop message_loop;
57 48
58 gin::Runner runner(delegate, v8::Isolate::GetCurrent()); 49 gin::Runner runner(delegate, v8::Isolate::GetCurrent());
59 gin::Runner::Scope scope(&runner); 50 gin::Runner::Scope scope(&runner);
60 runner.Run(source); 51 runner.Run(source);
61 52
62 message_loop.RunUntilIdle(); 53 message_loop.RunUntilIdle();
63 54
64 v8::Handle<v8::Value> result = runner.context()->Global()->Get( 55 v8::Handle<v8::Value> result = runner.context()->Global()->Get(
65 StringToSymbol(runner.isolate(), "result")); 56 StringToSymbol(runner.isolate(), "result"));
66 std::string result_string; 57 std::string result_string;
67 ASSERT_TRUE(ConvertFromV8(result, &result_string)); 58 ASSERT_TRUE(ConvertFromV8(result, &result_string));
68 EXPECT_EQ("PASS", result_string); 59 EXPECT_EQ("PASS", result_string);
69 } 60 }
70 61
71 } // namespace gin 62 } // namespace gin
OLDNEW
« no previous file with comments | « gin/test/file_runner.h ('k') | gin/test/gtest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698