1 // Copyright 2014 The Chromium Authors
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/per_context_data.h"
7 #include "gin/public/context_holder.h"
8 #include "gin/public/isolate_holder.h"
9 #include "gin/test/v8_test.h"
10 #include "v8/include/v8-context.h"
11 #include "v8/include/v8-isolate.h"
15 typedef V8Test PerContextDataTest;
17 // Verifies PerContextData can be looked up by context and that it is not
18 // available once ContextHolder is destroyed.
19 TEST_F(PerContextDataTest, LookupAndDestruction) {
20 v8::Isolate::Scope isolate_scope(instance_->isolate());
21 v8::HandleScope handle_scope(instance_->isolate());
22 v8::Local<v8::Context> context = v8::Context::New(
23 instance_->isolate(), NULL, v8::Local<v8::ObjectTemplate>());
25 ContextHolder context_holder(instance_->isolate());
26 context_holder.SetContext(context);
27 PerContextData* per_context_data = PerContextData::From(context);
28 EXPECT_TRUE(per_context_data != NULL);
29 EXPECT_EQ(&context_holder, per_context_data->context_holder());
31 PerContextData* per_context_data = PerContextData::From(context);
32 EXPECT_TRUE(per_context_data == NULL);