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.
5 #include "gin/test/gtest.h"
8 #include "base/logging.h"
9 #include "gin/arguments.h"
10 #include "gin/converter.h"
11 #include "gin/function_template.h"
12 #include "gin/object_template_builder.h"
13 #include "gin/per_isolate_data.h"
14 #include "gin/public/wrapper_info.h"
15 #include "gin/wrappable.h"
16 #include "testing/gtest/include/gtest/gtest.h"
22 void Fail(const std::string
& description
) {
23 FAIL() << description
;
26 void ExpectTrue(bool condition
, const std::string
& description
) {
27 EXPECT_TRUE(condition
) << description
;
30 void ExpectFalse(bool condition
, const std::string
& description
) {
31 EXPECT_FALSE(condition
) << description
;
34 void ExpectEqual(const v8::Handle
<v8::Value
> expected
,
35 const v8::Handle
<v8::Value
> actual
,
36 const std::string
& description
) {
37 EXPECT_TRUE(expected
->StrictEquals(actual
)) << description
;
40 WrapperInfo g_wrapper_info
= { kEmbedderNativeGin
};
44 const char GTest::kModuleName
[] = "gtest";
46 v8::Local
<v8::Value
> GTest::GetModule(v8::Isolate
* isolate
) {
47 PerIsolateData
* data
= PerIsolateData::From(isolate
);
48 v8::Local
<v8::ObjectTemplate
> templ
=
49 data
->GetObjectTemplate(&g_wrapper_info
);
50 if (templ
.IsEmpty()) {
51 templ
= ObjectTemplateBuilder(isolate
)
52 .SetMethod("fail", Fail
)
53 .SetMethod("expectTrue", ExpectTrue
)
54 .SetMethod("expectFalse", ExpectFalse
)
55 .SetMethod("expectEqual", ExpectEqual
)
57 data
->SetObjectTemplate(&g_wrapper_info
, templ
);
59 return templ
->NewInstance();