Home | History | Annotate | Download | only in test
      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 "base/bind.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"
     17 
     18 namespace gin {
     19 
     20 namespace {
     21 
     22 void Fail(const std::string& description) {
     23   FAIL() << description;
     24 }
     25 
     26 void ExpectTrue(bool condition, const std::string& description) {
     27   EXPECT_TRUE(condition) << description;
     28 }
     29 
     30 void ExpectFalse(bool condition, const std::string& description) {
     31   EXPECT_FALSE(condition) << description;
     32 }
     33 
     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;
     38 }
     39 
     40 WrapperInfo g_wrapper_info = { kEmbedderNativeGin };
     41 
     42 }  // namespace
     43 
     44 const char GTest::kModuleName[] = "gtest";
     45 
     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)
     56         .Build();
     57     data->SetObjectTemplate(&g_wrapper_info, templ);
     58   }
     59   return templ->NewInstance();
     60 }
     61 
     62 }  // namespace gin
     63