OLD | NEW |
---|---|
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/gtest.h" | 5 #include "gin/test/gtest.h" |
6 | 6 |
7 #include "base/bind.h" | |
8 #include "base/logging.h" | |
7 #include "gin/arguments.h" | 9 #include "gin/arguments.h" |
8 #include "gin/converter.h" | 10 #include "gin/converter.h" |
11 #include "gin/function_template_util.h" | |
9 #include "gin/per_isolate_data.h" | 12 #include "gin/per_isolate_data.h" |
10 #include "gin/public/wrapper_info.h" | 13 #include "gin/public/wrapper_info.h" |
14 #include "gin/wrappable.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
12 | 16 |
13 using v8::ObjectTemplate; | |
14 | |
15 namespace gin { | 17 namespace gin { |
16 | 18 |
17 namespace { | 19 namespace { |
18 | 20 |
19 void ExpectTrue(const v8::FunctionCallbackInfo<v8::Value>& info) { | 21 void ExpectTrue(bool condition, const std::string& description) { |
20 Arguments args(info); | 22 EXPECT_TRUE(condition) << description; |
21 | |
22 bool value = false; | |
23 std::string description; | |
24 | |
25 if (!args.GetNext(&value) || | |
26 !args.GetNext(&description)) { | |
27 return args.ThrowError(); | |
28 } | |
29 | |
30 EXPECT_TRUE(value) << description; | |
31 } | 23 } |
32 | 24 |
33 void ExpectFalse(const v8::FunctionCallbackInfo<v8::Value>& info) { | 25 void ExpectFalse(bool condition, const std::string& description) { |
34 Arguments args(info); | 26 EXPECT_FALSE(condition) << description; |
35 | |
36 bool value = false; | |
37 std::string description; | |
38 | |
39 if (!args.GetNext(&value) || | |
40 !args.GetNext(&description)) { | |
41 return args.ThrowError(); | |
42 } | |
43 | |
44 EXPECT_FALSE(value) << description; | |
45 } | 27 } |
46 | 28 |
47 void ExpectEqual(const v8::FunctionCallbackInfo<v8::Value>& info) { | 29 void ExpectEqual(const v8::FunctionCallbackInfo<v8::Value>& info) { |
48 Arguments args(info); | 30 Arguments args(info); |
49 | 31 |
50 std::string description; | 32 std::string description; |
51 if (!ConvertFromV8(info[2], &description)) | 33 if (!ConvertFromV8(info[2], &description)) |
52 return args.ThrowTypeError("Expected description."); | 34 return args.ThrowTypeError("Expected description."); |
53 | 35 |
54 EXPECT_TRUE(info[0]->StrictEquals(info[1])) << description; | 36 EXPECT_TRUE(info[0]->StrictEquals(info[1])) << description; |
55 } | 37 } |
56 | 38 |
57 WrapperInfo g_wrapper_info = { kEmbedderNativeGin }; | 39 WrapperInfo g_wrapper_info = { kEmbedderNativeGin }; |
58 | 40 |
59 } // namespace | 41 } // namespace |
60 | 42 |
61 const char GTest::kModuleName[] = "gtest"; | 43 const char GTest::kModuleName[] = "gtest"; |
62 | 44 |
63 v8::Local<ObjectTemplate> GTest::GetTemplate(v8::Isolate* isolate) { | 45 v8::Local<v8::ObjectTemplate> GTest::GetTemplate(v8::Isolate* isolate) { |
46 CallbackHolderBase::Register(isolate); | |
64 PerIsolateData* data = PerIsolateData::From(isolate); | 47 PerIsolateData* data = PerIsolateData::From(isolate); |
65 v8::Local<ObjectTemplate> templ = data->GetObjectTemplate(&g_wrapper_info); | 48 v8::Local<v8::ObjectTemplate> templ = |
49 data->GetObjectTemplate(&g_wrapper_info); | |
66 if (templ.IsEmpty()) { | 50 if (templ.IsEmpty()) { |
67 templ = ObjectTemplate::New(); | 51 templ = v8::ObjectTemplate::New(); |
68 templ->Set(StringToSymbol(isolate, "expectTrue"), | 52 templ->Set(StringToSymbol(isolate, "expectTrue"), |
69 v8::FunctionTemplate::New(ExpectTrue)); | 53 CreateFunctionTempate(isolate, base::Bind(ExpectTrue))); |
70 templ->Set(StringToSymbol(isolate, "expectFalse"), | 54 templ->Set(StringToSymbol(isolate, "expectFalse"), |
71 v8::FunctionTemplate::New(ExpectFalse)); | 55 CreateFunctionTempate(isolate, base::Bind(ExpectFalse))); |
abarth-chromium
2013/11/22 09:17:13
This looks really nice.
| |
72 templ->Set(StringToSymbol(isolate, "expectEqual"), | 56 templ->Set(StringToSymbol(isolate, "expectEqual"), |
73 v8::FunctionTemplate::New(ExpectEqual)); | 57 v8::FunctionTemplate::New(ExpectEqual)); |
74 data->SetObjectTemplate(&g_wrapper_info, templ); | 58 data->SetObjectTemplate(&g_wrapper_info, templ); |
75 } | 59 } |
76 return templ; | 60 return templ; |
77 } | 61 } |
78 | 62 |
79 } // namespace gin | 63 } // namespace gin |
OLD | NEW |