OLD | NEW |
(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 std::string description; |
| 22 |
| 23 if (!args.GetNext(&value) || |
| 24 !args.GetNext(&description)) { |
| 25 return args.ThrowError(); |
| 26 } |
| 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 std::string description; |
| 36 |
| 37 if (!args.GetNext(&value) || |
| 38 !args.GetNext(&description)) { |
| 39 return args.ThrowError(); |
| 40 } |
| 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> GetGTestTemplate(v8::Isolate* isolate) { |
| 60 PerIsolateData* data = PerIsolateData::From(isolate); |
| 61 v8::Local<v8::ObjectTemplate> templ = data->GetObjectTemplate( |
| 62 &g_gtest_wrapper_info); |
| 63 if (templ.IsEmpty()) { |
| 64 templ = v8::ObjectTemplate::New(); |
| 65 templ->Set(StringToSymbol(isolate, "expectTrue"), |
| 66 v8::FunctionTemplate::New(ExpectTrue)); |
| 67 templ->Set(StringToSymbol(isolate, "expectFalse"), |
| 68 v8::FunctionTemplate::New(ExpectFalse)); |
| 69 templ->Set(StringToSymbol(isolate, "expectEqual"), |
| 70 v8::FunctionTemplate::New(ExpectEqual)); |
| 71 data->SetObjectTemplate(&g_gtest_wrapper_info, templ); |
| 72 } |
| 73 return templ; |
| 74 } |
| 75 |
| 76 } // namespace gin |
OLD | NEW |