From 6d73d2a65253c8fe87f01dc2ee2aa902ea32c6bf Mon Sep 17 00:00:00 2001 From: "sky@chromium.org" Date: Sat, 1 Mar 2014 06:45:10 +0000 Subject: Two gin tests Verifies ModuleRegistry can be looked up from context and that it is no longer available once ContextHolder is destroyed. Similarly verifies PerContextData is available once a ContextHolder is created and that it's context_holder() member points back to the ContextHolder. BUG=none TEST=none R=abarth@chromium.org Review URL: https://codereview.chromium.org/182683005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@254362 0039d316-1c4b-4281-b951-d872f2087c98 --- gin/gin.gyp | 2 ++ gin/modules/module_registry_unittest.cc | 33 ++++++++++++++++++++++++++++++++ gin/per_context_data.cc | 3 +++ gin/per_context_data_unittest.cc | 34 +++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 gin/modules/module_registry_unittest.cc create mode 100644 gin/per_context_data_unittest.cc (limited to 'gin') diff --git a/gin/gin.gyp b/gin/gin.gyp index a827c42..f87c2bc 100644 --- a/gin/gin.gyp +++ b/gin/gin.gyp @@ -116,7 +116,9 @@ ], 'sources': [ 'converter_unittest.cc', + 'modules/module_registry_unittest.cc', 'modules/timer_unittest.cc', + 'per_context_data_unittest.cc', 'shell_runner_unittest.cc', 'test/run_all_unittests.cc', 'test/run_js_tests.cc', diff --git a/gin/modules/module_registry_unittest.cc b/gin/modules/module_registry_unittest.cc new file mode 100644 index 0000000..af9dd00 --- /dev/null +++ b/gin/modules/module_registry_unittest.cc @@ -0,0 +1,33 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "gin/modules/module_registry.h" + +#include "gin/public/context_holder.h" +#include "gin/public/isolate_holder.h" +#include "gin/test/v8_test.h" +#include "v8/include/v8.h" + +namespace gin { + +typedef V8Test ModuleRegistryTest; + +// Verifies ModuleRegistry is not available after ContextHolder has been +// deleted. +TEST_F(ModuleRegistryTest, DestroyedWithContext) { + v8::Isolate::Scope isolate_scope(instance_->isolate()); + v8::HandleScope handle_scope(instance_->isolate()); + v8::Handle context = v8::Context::New( + instance_->isolate(), NULL, v8::Handle()); + { + ContextHolder context_holder(instance_->isolate()); + context_holder.SetContext(context); + ModuleRegistry* registry = ModuleRegistry::From(context); + EXPECT_TRUE(registry != NULL); + } + ModuleRegistry* registry = ModuleRegistry::From(context); + EXPECT_TRUE(registry == NULL); +} + +} // namespace gin diff --git a/gin/per_context_data.cc b/gin/per_context_data.cc index b10c1a0..178c0d1 100644 --- a/gin/per_context_data.cc +++ b/gin/per_context_data.cc @@ -19,6 +19,9 @@ PerContextData::PerContextData(ContextHolder* context_holder, } PerContextData::~PerContextData() { + v8::HandleScope handle_scope(context_holder_->isolate()); + context_holder_->context()->SetAlignedPointerInEmbedderData( + kPerContextDataStartIndex + kEmbedderNativeGin, NULL); } // static diff --git a/gin/per_context_data_unittest.cc b/gin/per_context_data_unittest.cc new file mode 100644 index 0000000..4d79587 --- /dev/null +++ b/gin/per_context_data_unittest.cc @@ -0,0 +1,34 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "gin/per_context_data.h" + +#include "gin/public/context_holder.h" +#include "gin/public/isolate_holder.h" +#include "gin/test/v8_test.h" +#include "v8/include/v8.h" + +namespace gin { + +typedef V8Test PerContextDataTest; + +// Verifies PerContextData can be looked up by context and that it is not +// available once ContextHolder is destroyed. +TEST_F(PerContextDataTest, LookupAndDestruction) { + v8::Isolate::Scope isolate_scope(instance_->isolate()); + v8::HandleScope handle_scope(instance_->isolate()); + v8::Handle context = v8::Context::New( + instance_->isolate(), NULL, v8::Handle()); + { + ContextHolder context_holder(instance_->isolate()); + context_holder.SetContext(context); + PerContextData* per_context_data = PerContextData::From(context); + EXPECT_TRUE(per_context_data != NULL); + EXPECT_EQ(&context_holder, per_context_data->context_holder()); + } + PerContextData* per_context_data = PerContextData::From(context); + EXPECT_TRUE(per_context_data == NULL); +} + +} // namespace gin -- cgit v1.1