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" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "gin/arguments.h" | 9 #include "gin/arguments.h" |
10 #include "gin/converter.h" | 10 #include "gin/converter.h" |
11 #include "gin/function_template.h" | 11 #include "gin/function_template.h" |
| 12 #include "gin/object_template_builder.h" |
12 #include "gin/per_isolate_data.h" | 13 #include "gin/per_isolate_data.h" |
13 #include "gin/public/wrapper_info.h" | 14 #include "gin/public/wrapper_info.h" |
14 #include "gin/wrappable.h" | 15 #include "gin/wrappable.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 | 17 |
17 namespace gin { | 18 namespace gin { |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 void Fail(const v8::FunctionCallbackInfo<v8::Value>& info) { | 22 void Fail(const std::string& description) { |
22 Arguments args(info); | |
23 | |
24 std::string description; | |
25 if (!args.GetNext(&description)) | |
26 return args.ThrowError(); | |
27 | |
28 FAIL() << description; | 23 FAIL() << description; |
29 } | 24 } |
30 | 25 |
31 void ExpectTrue(bool condition, const std::string& description) { | 26 void ExpectTrue(bool condition, const std::string& description) { |
32 EXPECT_TRUE(condition) << description; | 27 EXPECT_TRUE(condition) << description; |
33 } | 28 } |
34 | 29 |
35 void ExpectFalse(bool condition, const std::string& description) { | 30 void ExpectFalse(bool condition, const std::string& description) { |
36 EXPECT_FALSE(condition) << description; | 31 EXPECT_FALSE(condition) << description; |
37 } | 32 } |
38 | 33 |
39 void ExpectEqual(const v8::Handle<v8::Value> expected, | 34 void ExpectEqual(const v8::Handle<v8::Value> expected, |
40 const v8::Handle<v8::Value> actual, | 35 const v8::Handle<v8::Value> actual, |
41 const std::string& description) { | 36 const std::string& description) { |
42 EXPECT_TRUE(expected->StrictEquals(actual)) << description; | 37 EXPECT_TRUE(expected->StrictEquals(actual)) << description; |
43 } | 38 } |
44 | 39 |
45 WrapperInfo g_wrapper_info = { kEmbedderNativeGin }; | 40 WrapperInfo g_wrapper_info = { kEmbedderNativeGin }; |
46 | 41 |
47 } // namespace | 42 } // namespace |
48 | 43 |
49 const char GTest::kModuleName[] = "gtest"; | 44 const char GTest::kModuleName[] = "gtest"; |
50 | 45 |
51 v8::Local<v8::ObjectTemplate> GTest::GetTemplate(v8::Isolate* isolate) { | 46 v8::Local<v8::ObjectTemplate> GTest::GetTemplate(v8::Isolate* isolate) { |
52 PerIsolateData* data = PerIsolateData::From(isolate); | 47 PerIsolateData* data = PerIsolateData::From(isolate); |
53 v8::Local<v8::ObjectTemplate> templ = | 48 v8::Local<v8::ObjectTemplate> templ = |
54 data->GetObjectTemplate(&g_wrapper_info); | 49 data->GetObjectTemplate(&g_wrapper_info); |
55 if (templ.IsEmpty()) { | 50 if (templ.IsEmpty()) { |
56 templ = v8::ObjectTemplate::New(); | 51 templ = ObjectTemplateBuilder(isolate) |
57 templ->Set(StringToSymbol(isolate, "fail"), | 52 .SetMethod("fail", Fail) |
58 v8::FunctionTemplate::New(Fail)); | 53 .SetMethod("expectTrue", ExpectTrue) |
59 templ->Set(StringToSymbol(isolate, "expectTrue"), | 54 .SetMethod("expectFalse", ExpectFalse) |
60 CreateFunctionTemplate(isolate, base::Bind(ExpectTrue))); | 55 .SetMethod("expectEqual", ExpectEqual) |
61 templ->Set(StringToSymbol(isolate, "expectFalse"), | 56 .Build(); |
62 CreateFunctionTemplate(isolate, base::Bind(ExpectFalse))); | |
63 templ->Set(StringToSymbol(isolate, "expectEqual"), | |
64 CreateFunctionTemplate(isolate, base::Bind(ExpectEqual))); | |
65 data->SetObjectTemplate(&g_wrapper_info, templ); | 57 data->SetObjectTemplate(&g_wrapper_info, templ); |
66 } | 58 } |
67 return templ; | 59 return templ; |
68 } | 60 } |
69 | 61 |
70 } // namespace gin | 62 } // namespace gin |
OLD | NEW |