per_context_data_unittest.cc 1.2 KB

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