LCOV - code coverage report
Current view: top level - test/unittests/api - remote-object-unittest.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 46 52 88.5 %
Date: 2019-02-19 Functions: 14 23 60.9 %

          Line data    Source code
       1             : // Copyright 2017 the V8 project 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 "testing/gtest/include/gtest/gtest.h"
       6             : 
       7             : #include "include/v8.h"
       8             : #include "src/api-inl.h"
       9             : #include "src/handles.h"
      10             : #include "src/objects-inl.h"
      11             : #include "test/unittests/test-utils.h"
      12             : 
      13             : namespace v8 {
      14             : namespace remote_object_unittest {
      15             : 
      16             : typedef TestWithIsolate RemoteObjectTest;
      17             : 
      18             : namespace {
      19             : 
      20           0 : bool AccessCheck(Local<Context> accessing_context,
      21             :                  Local<Object> accessed_object, Local<Value> data) {
      22           0 :   return false;
      23             : }
      24             : 
      25           0 : void NamedGetter(Local<Name> property,
      26           0 :                  const PropertyCallbackInfo<Value>& info) {}
      27             : 
      28           0 : void Constructor(const FunctionCallbackInfo<Value>& info) {
      29           0 :   ASSERT_TRUE(info.IsConstructCall());
      30             : }
      31             : 
      32             : }  // namespace
      33             : 
      34       15188 : TEST_F(RemoteObjectTest, CreationContextOfRemoteContext) {
      35           1 :   Local<ObjectTemplate> global_template = ObjectTemplate::New(isolate());
      36             :   global_template->SetAccessCheckCallbackAndHandler(
      37             :       AccessCheck, NamedPropertyHandlerConfiguration(NamedGetter),
      38           1 :       IndexedPropertyHandlerConfiguration());
      39             : 
      40             :   Local<Object> remote_context =
      41           2 :       Context::NewRemoteContext(isolate(), global_template).ToLocalChecked();
      42           2 :   EXPECT_TRUE(remote_context->CreationContext().IsEmpty());
      43           1 : }
      44             : 
      45       15188 : TEST_F(RemoteObjectTest, CreationContextOfRemoteObject) {
      46             :   Local<FunctionTemplate> constructor_template =
      47           1 :       FunctionTemplate::New(isolate(), Constructor);
      48             :   constructor_template->InstanceTemplate()->SetAccessCheckCallbackAndHandler(
      49             :       AccessCheck, NamedPropertyHandlerConfiguration(NamedGetter),
      50           2 :       IndexedPropertyHandlerConfiguration());
      51             : 
      52             :   Local<Object> remote_object =
      53           1 :       constructor_template->NewRemoteInstance().ToLocalChecked();
      54           2 :   EXPECT_TRUE(remote_object->CreationContext().IsEmpty());
      55           1 : }
      56             : 
      57       15188 : TEST_F(RemoteObjectTest, RemoteContextInstanceChecks) {
      58             :   Local<FunctionTemplate> parent_template =
      59           1 :       FunctionTemplate::New(isolate(), Constructor);
      60             : 
      61             :   Local<FunctionTemplate> constructor_template =
      62           1 :       FunctionTemplate::New(isolate(), Constructor);
      63             :   constructor_template->InstanceTemplate()->SetAccessCheckCallbackAndHandler(
      64             :       AccessCheck, NamedPropertyHandlerConfiguration(NamedGetter),
      65           2 :       IndexedPropertyHandlerConfiguration());
      66           1 :   constructor_template->Inherit(parent_template);
      67             : 
      68             :   Local<Object> remote_context =
      69             :       Context::NewRemoteContext(isolate(),
      70           2 :                                 constructor_template->InstanceTemplate())
      71           1 :           .ToLocalChecked();
      72           2 :   EXPECT_TRUE(parent_template->HasInstance(remote_context));
      73           2 :   EXPECT_TRUE(constructor_template->HasInstance(remote_context));
      74           1 : }
      75             : 
      76       15188 : TEST_F(RemoteObjectTest, TypeOfRemoteContext) {
      77           1 :   Local<ObjectTemplate> global_template = ObjectTemplate::New(isolate());
      78             :   global_template->SetAccessCheckCallbackAndHandler(
      79             :       AccessCheck, NamedPropertyHandlerConfiguration(NamedGetter),
      80           1 :       IndexedPropertyHandlerConfiguration());
      81             : 
      82             :   Local<Object> remote_context =
      83           2 :       Context::NewRemoteContext(isolate(), global_template).ToLocalChecked();
      84           2 :   String::Utf8Value result(isolate(), remote_context->TypeOf(isolate()));
      85           2 :   EXPECT_STREQ("object", *result);
      86           1 : }
      87             : 
      88       15188 : TEST_F(RemoteObjectTest, TypeOfRemoteObject) {
      89             :   Local<FunctionTemplate> constructor_template =
      90           1 :       FunctionTemplate::New(isolate(), Constructor);
      91             :   constructor_template->InstanceTemplate()->SetAccessCheckCallbackAndHandler(
      92             :       AccessCheck, NamedPropertyHandlerConfiguration(NamedGetter),
      93           2 :       IndexedPropertyHandlerConfiguration());
      94             : 
      95             :   Local<Object> remote_object =
      96           1 :       constructor_template->NewRemoteInstance().ToLocalChecked();
      97           2 :   String::Utf8Value result(isolate(), remote_object->TypeOf(isolate()));
      98           2 :   EXPECT_STREQ("object", *result);
      99           1 : }
     100             : 
     101       15188 : TEST_F(RemoteObjectTest, ClassOf) {
     102             :   Local<FunctionTemplate> constructor_template =
     103           1 :       FunctionTemplate::New(isolate(), Constructor);
     104             :   constructor_template->InstanceTemplate()->SetAccessCheckCallbackAndHandler(
     105             :       AccessCheck, NamedPropertyHandlerConfiguration(NamedGetter),
     106           2 :       IndexedPropertyHandlerConfiguration());
     107             :   constructor_template->SetClassName(
     108             :       String::NewFromUtf8(isolate(), "test_class", NewStringType::kNormal)
     109           2 :           .ToLocalChecked());
     110             : 
     111             :   Local<Object> remote_object =
     112           1 :       constructor_template->NewRemoteInstance().ToLocalChecked();
     113             :   Local<String> class_name = Utils::ToLocal(
     114           2 :       i::handle(Utils::OpenHandle(*remote_object)->class_name(), i_isolate()));
     115           1 :   String::Utf8Value result(isolate(), class_name);
     116           2 :   EXPECT_STREQ("test_class", *result);
     117           1 : }
     118             : 
     119             : }  // namespace remote_object_unittest
     120        9111 : }  // namespace v8

Generated by: LCOV version 1.10