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

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

Issue 59153005: Begin implementing V8 bindings for Mojo (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moar copyright 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
(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/gtest.h"
6
7 #include "gin/arguments.h"
8 #include "gin/converter.h"
9 #include "gin/per_isolate_data.h"
10 #include "gin/wrapper_info.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace gin {
14
15 namespace {
16
17 void ExpectTrue(const v8::FunctionCallbackInfo<v8::Value>& info) {
18 Arguments args(info);
19
20 bool value = false;
21 if (!args.Next(&value))
22 return args.ThrowTypeError("Expected bool.");
23
24 std::string description;
25 if (!args.Next(&description))
26 return args.ThrowTypeError("Expected description.");
27
28 EXPECT_TRUE(value) << description;
29 }
30
31 void ExpectFalse(const v8::FunctionCallbackInfo<v8::Value>& info) {
32 Arguments args(info);
33
34 bool value = false;
35 if (!args.Next(&value))
36 return args.ThrowTypeError("Expected bool.");
37
38 std::string description;
39 if (!args.Next(&description))
40 return args.ThrowTypeError("Expected description.");
41
42 EXPECT_FALSE(value) << description;
43 }
44
45 void ExpectEqual(const v8::FunctionCallbackInfo<v8::Value>& info) {
46 Arguments args(info);
47
48 std::string description;
49 if (!ConvertFromV8(info[2], &description))
50 return args.ThrowTypeError("Expected description.");
51
52 EXPECT_TRUE(info[0]->StrictEquals(info[1])) << description;
53 }
54
55 WrapperInfo g_gtest_wrapper_info = {};
56
57 }
58
59 v8::Local<v8::ObjectTemplate> GTestTemplate(v8::Isolate* isolate) {
60 PerIsolateData* data = PerIsolateData::From(isolate);
61 v8::Local<v8::ObjectTemplate> templ;
62 if (!data->GetObjectTemplate(&g_gtest_wrapper_info, &templ)) {
63 templ = v8::ObjectTemplate::New();
64 templ->Set(StringToV8(isolate, "expectTrue"),
65 v8::FunctionTemplate::New(ExpectTrue));
66 templ->Set(StringToV8(isolate, "expectFalse"),
67 v8::FunctionTemplate::New(ExpectFalse));
68 templ->Set(StringToV8(isolate, "expectEqual"),
69 v8::FunctionTemplate::New(ExpectEqual));
70 data->RegisterObjectTemplate(&g_gtest_wrapper_info, templ);
71 }
72 return templ;
73 }
74
75 } // namespace gin
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698