| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "webkit/plugins/ppapi/ppapi_unittest.h" | 5 #include "webkit/plugins/ppapi/ppapi_unittest.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "ppapi/c/pp_var.h" | 8 #include "ppapi/c/pp_var.h" |
| 9 #include "ppapi/c/ppp_instance.h" | 9 #include "ppapi/c/ppp_instance.h" |
| 10 #include "third_party/npapi/bindings/npruntime.h" | 10 #include "third_party/npapi/bindings/npruntime.h" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" |
| 12 #include "webkit/plugins/ppapi/host_globals.h" |
| 12 #include "webkit/plugins/ppapi/mock_plugin_delegate.h" | 13 #include "webkit/plugins/ppapi/mock_plugin_delegate.h" |
| 13 #include "webkit/plugins/ppapi/mock_resource.h" | 14 #include "webkit/plugins/ppapi/mock_resource.h" |
| 14 #include "webkit/plugins/ppapi/npapi_glue.h" | 15 #include "webkit/plugins/ppapi/npapi_glue.h" |
| 15 #include "webkit/plugins/ppapi/npobject_var.h" | 16 #include "webkit/plugins/ppapi/npobject_var.h" |
| 16 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 17 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 17 #include "webkit/plugins/ppapi/resource_tracker.h" | 18 #include "webkit/plugins/ppapi/resource_tracker.h" |
| 18 | 19 |
| 19 using ppapi::NPObjectVar; | 20 using ppapi::NPObjectVar; |
| 20 | 21 |
| 21 namespace webkit { | 22 namespace webkit { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 | 72 |
| 72 } // namespace | 73 } // namespace |
| 73 | 74 |
| 74 // ResourceTrackerTest --------------------------------------------------------- | 75 // ResourceTrackerTest --------------------------------------------------------- |
| 75 | 76 |
| 76 class ResourceTrackerTest : public PpapiUnittest { | 77 class ResourceTrackerTest : public PpapiUnittest { |
| 77 public: | 78 public: |
| 78 ResourceTrackerTest() { | 79 ResourceTrackerTest() { |
| 79 } | 80 } |
| 80 | 81 |
| 81 virtual void SetUp() { | 82 ResourceTracker& tracker() { |
| 82 // The singleton override must be installed before the generic setup because | 83 return *HostGlobals::Get()->host_resource_tracker(); |
| 83 // that creates an instance, etc. which uses the tracker. | |
| 84 ResourceTracker::SetSingletonOverride(&tracker_); | |
| 85 PpapiUnittest::SetUp(); | |
| 86 } | 84 } |
| 87 virtual void TearDown() { | |
| 88 // Must do normal tear down before clearing the override for the same rason | |
| 89 // as the SetUp. | |
| 90 PpapiUnittest::TearDown(); | |
| 91 ResourceTracker::ClearSingletonOverride(); | |
| 92 } | |
| 93 | |
| 94 ResourceTracker& tracker() { return tracker_; } | |
| 95 | |
| 96 private: | |
| 97 ResourceTracker tracker_; | |
| 98 }; | 85 }; |
| 99 | 86 |
| 100 TEST_F(ResourceTrackerTest, DeleteObjectVarWithInstance) { | 87 TEST_F(ResourceTrackerTest, DeleteObjectVarWithInstance) { |
| 101 // Make a second instance (the test harness already creates & manages one). | 88 // Make a second instance (the test harness already creates & manages one). |
| 102 scoped_refptr<PluginInstance> instance2( | 89 scoped_refptr<PluginInstance> instance2( |
| 103 PluginInstance::Create1_0(delegate(), module(), | 90 PluginInstance::Create1_0(delegate(), module(), |
| 104 GetMockInterface(PPP_INSTANCE_INTERFACE_1_0))); | 91 GetMockInterface(PPP_INSTANCE_INTERFACE_1_0))); |
| 105 PP_Instance pp_instance2 = instance2->pp_instance(); | 92 PP_Instance pp_instance2 = instance2->pp_instance(); |
| 106 | 93 |
| 107 // Make an object var. | 94 // Make an object var. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 131 // This ObjectVar must be released before we do NPObjectToPPVar again | 118 // This ObjectVar must be released before we do NPObjectToPPVar again |
| 132 // below so it gets freed and we get a new identifier. | 119 // below so it gets freed and we get a new identifier. |
| 133 { | 120 { |
| 134 scoped_refptr<NPObjectVar> check_object(NPObjectVar::FromPPVar(pp_object1)); | 121 scoped_refptr<NPObjectVar> check_object(NPObjectVar::FromPPVar(pp_object1)); |
| 135 ASSERT_TRUE(check_object.get()); | 122 ASSERT_TRUE(check_object.get()); |
| 136 EXPECT_EQ(instance()->pp_instance(), check_object->pp_instance()); | 123 EXPECT_EQ(instance()->pp_instance(), check_object->pp_instance()); |
| 137 EXPECT_EQ(npobject.get(), check_object->np_object()); | 124 EXPECT_EQ(npobject.get(), check_object->np_object()); |
| 138 } | 125 } |
| 139 | 126 |
| 140 // Remove both of the refs we made above. | 127 // Remove both of the refs we made above. |
| 141 ::ppapi::VarTracker* var_tracker = tracker().GetVarTracker(); | 128 ::ppapi::VarTracker* var_tracker = |
| 129 ::ppapi::PpapiGlobals::Get()->GetVarTracker(); |
| 142 var_tracker->ReleaseVar(static_cast<int32_t>(pp_object2.value.as_id)); | 130 var_tracker->ReleaseVar(static_cast<int32_t>(pp_object2.value.as_id)); |
| 143 var_tracker->ReleaseVar(static_cast<int32_t>(pp_object1.value.as_id)); | 131 var_tracker->ReleaseVar(static_cast<int32_t>(pp_object1.value.as_id)); |
| 144 | 132 |
| 145 // Releasing the resource should free the internal ref, and so making a new | 133 // Releasing the resource should free the internal ref, and so making a new |
| 146 // one now should generate a new ID. | 134 // one now should generate a new ID. |
| 147 PP_Var pp_object3 = NPObjectToPPVar(instance(), npobject.get()); | 135 PP_Var pp_object3 = NPObjectToPPVar(instance(), npobject.get()); |
| 148 EXPECT_NE(pp_object1.value.as_id, pp_object3.value.as_id); | 136 EXPECT_NE(pp_object1.value.as_id, pp_object3.value.as_id); |
| 149 var_tracker->ReleaseVar(static_cast<int32_t>(pp_object3.value.as_id)); | 137 var_tracker->ReleaseVar(static_cast<int32_t>(pp_object3.value.as_id)); |
| 150 } | 138 } |
| 151 | 139 |
| 152 } // namespace ppapi | 140 } // namespace ppapi |
| 153 } // namespace webkit | 141 } // namespace webkit |
| OLD | NEW |