Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: content/renderer/pepper/host_var_tracker_unittest.cc

Issue 635593004: PPAPI: Make V8VarConverter longer-lived (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | content/renderer/pepper/message_channel.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "content/renderer/pepper/host_globals.h" 7 #include "content/renderer/pepper/host_globals.h"
8 #include "content/renderer/pepper/host_var_tracker.h" 8 #include "content/renderer/pepper/host_var_tracker.h"
9 #include "content/renderer/pepper/mock_resource.h" 9 #include "content/renderer/pepper/mock_resource.h"
10 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" 10 #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
11 #include "content/renderer/pepper/pepper_try_catch.h" 11 #include "content/renderer/pepper/pepper_try_catch.h"
12 #include "content/renderer/pepper/v8_var_converter.h"
12 #include "content/renderer/pepper/v8object_var.h" 13 #include "content/renderer/pepper/v8object_var.h"
13 #include "content/test/ppapi_unittest.h" 14 #include "content/test/ppapi_unittest.h"
14 #include "gin/handle.h" 15 #include "gin/handle.h"
15 #include "gin/wrappable.h" 16 #include "gin/wrappable.h"
16 #include "ppapi/c/pp_var.h" 17 #include "ppapi/c/pp_var.h"
17 #include "ppapi/c/ppp_instance.h" 18 #include "ppapi/c/ppp_instance.h"
18 #include "third_party/WebKit/public/web/WebBindings.h" 19 #include "third_party/WebKit/public/web/WebBindings.h"
19 20
20 using ppapi::V8ObjectVar; 21 using ppapi::V8ObjectVar;
21 22
(...skipping 15 matching lines...) Expand all
37 MyObject() { ++g_v8objects_alive; } 38 MyObject() { ++g_v8objects_alive; }
38 virtual ~MyObject() { --g_v8objects_alive; } 39 virtual ~MyObject() { --g_v8objects_alive; }
39 40
40 DISALLOW_COPY_AND_ASSIGN(MyObject); 41 DISALLOW_COPY_AND_ASSIGN(MyObject);
41 }; 42 };
42 43
43 gin::WrapperInfo MyObject::kWrapperInfo = {gin::kEmbedderNativeGin}; 44 gin::WrapperInfo MyObject::kWrapperInfo = {gin::kEmbedderNativeGin};
44 45
45 class PepperTryCatchForTest : public PepperTryCatch { 46 class PepperTryCatchForTest : public PepperTryCatch {
46 public: 47 public:
47 explicit PepperTryCatchForTest(PepperPluginInstanceImpl* instance) 48 PepperTryCatchForTest(PepperPluginInstanceImpl* instance,
48 : PepperTryCatch(instance, V8VarConverter::kAllowObjectVars), 49 V8VarConverter* converter)
50 : PepperTryCatch(instance, converter),
49 handle_scope_(instance->GetIsolate()), 51 handle_scope_(instance->GetIsolate()),
50 context_scope_(v8::Context::New(instance->GetIsolate())) {} 52 context_scope_(v8::Context::New(instance->GetIsolate())) {}
51 53
52 virtual void SetException(const char* message) override { NOTREACHED(); } 54 virtual void SetException(const char* message) override { NOTREACHED(); }
53 virtual bool HasException() override { return false; } 55 virtual bool HasException() override { return false; }
54 virtual v8::Handle<v8::Context> GetContext() override { 56 virtual v8::Handle<v8::Context> GetContext() override {
55 return instance_->GetIsolate()->GetCurrentContext(); 57 return instance_->GetIsolate()->GetCurrentContext();
56 } 58 }
57 59
58 private: 60 private:
(...skipping 21 matching lines...) Expand all
80 82
81 TEST_F(HostVarTrackerTest, DeleteObjectVarWithInstance) { 83 TEST_F(HostVarTrackerTest, DeleteObjectVarWithInstance) {
82 v8::Isolate* test_isolate = v8::Isolate::GetCurrent(); 84 v8::Isolate* test_isolate = v8::Isolate::GetCurrent();
83 85
84 // Make a second instance (the test harness already creates & manages one). 86 // Make a second instance (the test harness already creates & manages one).
85 scoped_refptr<PepperPluginInstanceImpl> instance2( 87 scoped_refptr<PepperPluginInstanceImpl> instance2(
86 PepperPluginInstanceImpl::Create(NULL, module(), NULL, GURL())); 88 PepperPluginInstanceImpl::Create(NULL, module(), NULL, GURL()));
87 PP_Instance pp_instance2 = instance2->pp_instance(); 89 PP_Instance pp_instance2 = instance2->pp_instance();
88 90
89 { 91 {
90 PepperTryCatchForTest try_catch(instance2.get()); 92 V8VarConverter converter(
93 instance2->pp_instance(), V8VarConverter::kAllowObjectVars);
94 PepperTryCatchForTest try_catch(instance2.get(), &converter);
91 // Make an object var. 95 // Make an object var.
92 ppapi::ScopedPPVar var = try_catch.FromV8(MyObject::Create(test_isolate)); 96 ppapi::ScopedPPVar var = try_catch.FromV8(MyObject::Create(test_isolate));
93 EXPECT_EQ(1, g_v8objects_alive); 97 EXPECT_EQ(1, g_v8objects_alive);
94 EXPECT_EQ(1, tracker().GetLiveV8ObjectVarsForTest(pp_instance2)); 98 EXPECT_EQ(1, tracker().GetLiveV8ObjectVarsForTest(pp_instance2));
95 // Purposely leak the var. 99 // Purposely leak the var.
96 var.Release(); 100 var.Release();
97 } 101 }
98 102
99 // Free the instance, this should release the ObjectVar. 103 // Free the instance, this should release the ObjectVar.
100 instance2 = NULL; 104 instance2 = NULL;
101 EXPECT_EQ(0, tracker().GetLiveV8ObjectVarsForTest(pp_instance2)); 105 EXPECT_EQ(0, tracker().GetLiveV8ObjectVarsForTest(pp_instance2));
102 } 106 }
103 107
104 // Make sure that using the same v8 object should give the same PP_Var 108 // Make sure that using the same v8 object should give the same PP_Var
105 // each time. 109 // each time.
106 TEST_F(HostVarTrackerTest, ReuseVar) { 110 TEST_F(HostVarTrackerTest, ReuseVar) {
107 PepperTryCatchForTest try_catch(instance()); 111 V8VarConverter converter(
112 instance()->pp_instance(), V8VarConverter::kAllowObjectVars);
113 PepperTryCatchForTest try_catch(instance(), &converter);
108 114
109 v8::Handle<v8::Value> v8_object = MyObject::Create(v8::Isolate::GetCurrent()); 115 v8::Handle<v8::Value> v8_object = MyObject::Create(v8::Isolate::GetCurrent());
110 ppapi::ScopedPPVar pp_object1 = try_catch.FromV8(v8_object); 116 ppapi::ScopedPPVar pp_object1 = try_catch.FromV8(v8_object);
111 ppapi::ScopedPPVar pp_object2 = try_catch.FromV8(v8_object); 117 ppapi::ScopedPPVar pp_object2 = try_catch.FromV8(v8_object);
112 118
113 // The two results should be the same. 119 // The two results should be the same.
114 EXPECT_EQ(pp_object1.get().value.as_id, pp_object2.get().value.as_id); 120 EXPECT_EQ(pp_object1.get().value.as_id, pp_object2.get().value.as_id);
115 121
116 // The objects should be able to get us back to the associated v8 object. 122 // The objects should be able to get us back to the associated v8 object.
117 { 123 {
118 scoped_refptr<V8ObjectVar> check_object( 124 scoped_refptr<V8ObjectVar> check_object(
119 V8ObjectVar::FromPPVar(pp_object1.get())); 125 V8ObjectVar::FromPPVar(pp_object1.get()));
120 ASSERT_TRUE(check_object.get()); 126 ASSERT_TRUE(check_object.get());
121 EXPECT_EQ(instance(), check_object->instance()); 127 EXPECT_EQ(instance(), check_object->instance());
122 EXPECT_EQ(v8_object, check_object->GetHandle()); 128 EXPECT_EQ(v8_object, check_object->GetHandle());
123 } 129 }
124 130
125 // Remove both of the refs we made above. 131 // Remove both of the refs we made above.
126 pp_object1 = ppapi::ScopedPPVar(); 132 pp_object1 = ppapi::ScopedPPVar();
127 pp_object2 = ppapi::ScopedPPVar(); 133 pp_object2 = ppapi::ScopedPPVar();
128 134
129 // Releasing the resource should free the internal ref, and so making a new 135 // Releasing the resource should free the internal ref, and so making a new
130 // one now should generate a new ID. 136 // one now should generate a new ID.
131 ppapi::ScopedPPVar pp_object3 = try_catch.FromV8(v8_object); 137 ppapi::ScopedPPVar pp_object3 = try_catch.FromV8(v8_object);
132 EXPECT_NE(pp_object1.get().value.as_id, pp_object3.get().value.as_id); 138 EXPECT_NE(pp_object1.get().value.as_id, pp_object3.get().value.as_id);
133 } 139 }
134 140
135 } // namespace content 141 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/renderer/pepper/message_channel.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698