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

Side by Side Diff: ppapi/shared_impl/resource_tracker_unittest.cc

Issue 8316008: Add a new globals object for PPAPI tracking information. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 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 | Annotate | Revision Log
OLDNEW
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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "ppapi/shared_impl/resource.h" 8 #include "ppapi/shared_impl/resource.h"
9 #include "ppapi/shared_impl/resource_tracker.h" 9 #include "ppapi/shared_impl/resource_tracker.h"
10 #include "ppapi/shared_impl/test_globals.h"
10 #include "ppapi/shared_impl/tracker_base.h" 11 #include "ppapi/shared_impl/tracker_base.h"
11 12
12 namespace ppapi { 13 namespace ppapi {
13 14
14 namespace { 15 namespace {
15 16
16 int mock_resource_alive_count = 0; 17 int mock_resource_alive_count = 0;
17 int last_plugin_ref_was_deleted_count = 0; 18 int last_plugin_ref_was_deleted_count = 0;
18 int instance_was_deleted_count = 0; 19 int instance_was_deleted_count = 0;
19 20
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 my_tracker_base = NULL; 62 my_tracker_base = NULL;
62 TrackerBase::Init(NULL); 63 TrackerBase::Init(NULL);
63 } 64 }
64 65
65 // TrackerBase implementation. 66 // TrackerBase implementation.
66 virtual FunctionGroupBase* GetFunctionAPI( 67 virtual FunctionGroupBase* GetFunctionAPI(
67 PP_Instance inst, 68 PP_Instance inst,
68 ppapi::proxy::InterfaceID id) OVERRIDE { 69 ppapi::proxy::InterfaceID id) OVERRIDE {
69 return NULL; 70 return NULL;
70 } 71 }
71 virtual VarTracker* GetVarTracker() OVERRIDE {
72 return NULL;
73 }
74 virtual ResourceTracker* GetResourceTracker() OVERRIDE {
75 return &resource_tracker_;
76 }
77 virtual PP_Module GetModuleForInstance(PP_Instance /* instance */) OVERRIDE { 72 virtual PP_Module GetModuleForInstance(PP_Instance /* instance */) OVERRIDE {
78 return 0; 73 return 0;
79 } 74 }
80 75
81 ResourceTracker& resource_tracker() { return resource_tracker_; } 76 ResourceTracker& resource_tracker() { return *globals_.GetResourceTracker(); }
82 77
83 private: 78 private:
84 ResourceTracker resource_tracker_; 79 TestGlobals globals_;
85 }; 80 };
86 81
87 // Test that LastPluginRefWasDeleted is called when the last plugin ref was 82 // Test that LastPluginRefWasDeleted is called when the last plugin ref was
88 // deleted but the object lives on. 83 // deleted but the object lives on.
89 TEST_F(ResourceTrackerTest, LastPluginRef) { 84 TEST_F(ResourceTrackerTest, LastPluginRef) {
90 PP_Instance instance = 0x1234567; 85 PP_Instance instance = 0x1234567;
91 resource_tracker().DidCreateInstance(instance); 86 resource_tracker().DidCreateInstance(instance);
92 87
93 scoped_refptr<MyMockResource> resource(new MyMockResource(instance)); 88 scoped_refptr<MyMockResource> resource(new MyMockResource(instance));
94 PP_Resource pp_resource = resource->GetReference(); 89 PP_Resource pp_resource = resource->GetReference();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 EXPECT_EQ(1, mock_resource_alive_count); 137 EXPECT_EQ(1, mock_resource_alive_count);
143 EXPECT_EQ(1, last_plugin_ref_was_deleted_count); 138 EXPECT_EQ(1, last_plugin_ref_was_deleted_count);
144 EXPECT_EQ(1, instance_was_deleted_count); 139 EXPECT_EQ(1, instance_was_deleted_count);
145 EXPECT_EQ(0, resource->pp_instance()); 140 EXPECT_EQ(0, resource->pp_instance());
146 141
147 resource = NULL; 142 resource = NULL;
148 EXPECT_EQ(0, mock_resource_alive_count); 143 EXPECT_EQ(0, mock_resource_alive_count);
149 } 144 }
150 145
151 } // namespace ppapi 146 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698