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

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

Issue 19492014: PPAPI: Purposely leak ProxyLock, fix shutdown race (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove static initializer Created 7 years, 3 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/proxy_lock.h"
8 #include "ppapi/shared_impl/var.h" 9 #include "ppapi/shared_impl/var.h"
9 #include "ppapi/shared_impl/var_tracker.h" 10 #include "ppapi/shared_impl/var_tracker.h"
10 #include "ppapi/shared_impl/test_globals.h" 11 #include "ppapi/shared_impl/test_globals.h"
11 12
12 namespace ppapi { 13 namespace ppapi {
13 14
14 namespace { 15 namespace {
15 16
16 int mock_var_alive_count = 0; 17 int mock_var_alive_count = 0;
17 18
(...skipping 28 matching lines...) Expand all
46 47
47 } // namespace 48 } // namespace
48 49
49 class VarTrackerTest : public testing::Test { 50 class VarTrackerTest : public testing::Test {
50 public: 51 public:
51 VarTrackerTest() {} 52 VarTrackerTest() {}
52 53
53 // Test implementation. 54 // Test implementation.
54 virtual void SetUp() OVERRIDE { 55 virtual void SetUp() OVERRIDE {
55 ASSERT_EQ(0, mock_var_alive_count); 56 ASSERT_EQ(0, mock_var_alive_count);
57 ProxyLock::EnableLockingOnThreadForTest();
56 } 58 }
57 virtual void TearDown() OVERRIDE { 59 virtual void TearDown() OVERRIDE {
58 } 60 }
59 61
60 VarTracker& var_tracker() { return *globals_.GetVarTracker(); } 62 VarTracker& var_tracker() { return *globals_.GetVarTracker(); }
61 63
62 private: 64 private:
63 TestGlobals globals_; 65 TestGlobals globals_;
64 }; 66 };
65 67
66 // Test that ResetVarID is called when the last PP_Var ref was deleted but the 68 // Test that ResetVarID is called when the last PP_Var ref was deleted but the
67 // object lives on. 69 // object lives on.
68 TEST_F(VarTrackerTest, LastResourceRef) { 70 TEST_F(VarTrackerTest, LastResourceRef) {
71 ProxyAutoLock lock;
69 scoped_refptr<MockStringVar> var(new MockStringVar(std::string("xyz"))); 72 scoped_refptr<MockStringVar> var(new MockStringVar(std::string("xyz")));
70 PP_Var pp_var = var->GetPPVar(); 73 PP_Var pp_var = var->GetPPVar();
71 EXPECT_TRUE(var->HasValidVarID()); 74 EXPECT_TRUE(var->HasValidVarID());
72 EXPECT_TRUE(var_tracker().GetVar(var->GetExistingVarID())); 75 EXPECT_TRUE(var_tracker().GetVar(var->GetExistingVarID()));
73 76
74 // Releasing it should keep the object (because we have a ref) but reset the 77 // Releasing it should keep the object (because we have a ref) but reset the
75 // var_id_. 78 // var_id_.
76 EXPECT_TRUE(var_tracker().ReleaseVar(pp_var)); 79 EXPECT_TRUE(var_tracker().ReleaseVar(pp_var));
77 EXPECT_FALSE(var->HasValidVarID()); 80 EXPECT_FALSE(var->HasValidVarID());
78 EXPECT_EQ(1, mock_var_alive_count); 81 EXPECT_EQ(1, mock_var_alive_count);
79 82
80 var = NULL; 83 var = NULL;
81 EXPECT_EQ(0, mock_var_alive_count); 84 EXPECT_EQ(0, mock_var_alive_count);
82 } 85 }
83 86
84 TEST_F(VarTrackerTest, GetPluginRefAgain) { 87 TEST_F(VarTrackerTest, GetPluginRefAgain) {
88 ProxyAutoLock lock;
85 scoped_refptr<MockStringVar> var(new MockStringVar(std::string("xyz"))); 89 scoped_refptr<MockStringVar> var(new MockStringVar(std::string("xyz")));
86 PP_Var pp_var = var->GetPPVar(); 90 PP_Var pp_var = var->GetPPVar();
87 EXPECT_TRUE(var_tracker().ReleaseVar(pp_var)); 91 EXPECT_TRUE(var_tracker().ReleaseVar(pp_var));
88 EXPECT_FALSE(var->HasValidVarID()); 92 EXPECT_FALSE(var->HasValidVarID());
89 EXPECT_EQ(1, mock_var_alive_count); 93 EXPECT_EQ(1, mock_var_alive_count);
90 94
91 // Obtaining PP_Var ref again, and add ref from VarTracker. 95 // Obtaining PP_Var ref again, and add ref from VarTracker.
92 pp_var = var->GetPPVar(); 96 pp_var = var->GetPPVar();
93 EXPECT_TRUE(var->HasValidVarID()); 97 EXPECT_TRUE(var->HasValidVarID());
94 EXPECT_TRUE(var_tracker().GetVar(var->GetExistingVarID())); 98 EXPECT_TRUE(var_tracker().GetVar(var->GetExistingVarID()));
(...skipping 10 matching lines...) Expand all
105 EXPECT_FALSE(var_tracker().GetVar(pp_var)); 109 EXPECT_FALSE(var_tracker().GetVar(pp_var));
106 EXPECT_EQ(1, mock_var_alive_count); 110 EXPECT_EQ(1, mock_var_alive_count);
107 another_var = NULL; 111 another_var = NULL;
108 EXPECT_FALSE(var_tracker().GetVar(pp_var)); 112 EXPECT_FALSE(var_tracker().GetVar(pp_var));
109 EXPECT_EQ(0, mock_var_alive_count); 113 EXPECT_EQ(0, mock_var_alive_count);
110 } 114 }
111 115
112 // Tests when the plugin is holding a ref to a PP_Var when the instance is 116 // Tests when the plugin is holding a ref to a PP_Var when the instance is
113 // owned only by VarTracker. 117 // owned only by VarTracker.
114 TEST_F(VarTrackerTest, PluginRefWithoutVarRef) { 118 TEST_F(VarTrackerTest, PluginRefWithoutVarRef) {
119 ProxyAutoLock lock;
115 // Make a PP_Var with one ref held by the plugin, and release the reference. 120 // Make a PP_Var with one ref held by the plugin, and release the reference.
116 scoped_refptr<MockStringVar> var(new MockStringVar(std::string("zzz"))); 121 scoped_refptr<MockStringVar> var(new MockStringVar(std::string("zzz")));
117 PP_Var pp_var = var->GetPPVar(); 122 PP_Var pp_var = var->GetPPVar();
118 EXPECT_EQ(1, mock_var_alive_count); 123 EXPECT_EQ(1, mock_var_alive_count);
119 var = NULL; 124 var = NULL;
120 EXPECT_EQ(1, mock_var_alive_count); 125 EXPECT_EQ(1, mock_var_alive_count);
121 126
122 // The var is owned only by VarTracker. PP_Var must be still valid. 127 // The var is owned only by VarTracker. PP_Var must be still valid.
123 EXPECT_TRUE(var_tracker().GetVar(pp_var)); 128 EXPECT_TRUE(var_tracker().GetVar(pp_var));
124 129
125 var_tracker().ReleaseVar(pp_var); 130 var_tracker().ReleaseVar(pp_var);
126 EXPECT_EQ(0, mock_var_alive_count); 131 EXPECT_EQ(0, mock_var_alive_count);
127 EXPECT_FALSE(var_tracker().GetVar(pp_var)); 132 EXPECT_FALSE(var_tracker().GetVar(pp_var));
128 } 133 }
129 134
130 // Tests on Var having type of PP_VARTYPE_OBJECT. 135 // Tests on Var having type of PP_VARTYPE_OBJECT.
131 TEST_F(VarTrackerTest, ObjectRef) { 136 TEST_F(VarTrackerTest, ObjectRef) {
137 ProxyAutoLock lock;
132 scoped_refptr<MockObjectVar> var(new MockObjectVar()); 138 scoped_refptr<MockObjectVar> var(new MockObjectVar());
133 PP_Var pp_var = var->GetPPVar(); 139 PP_Var pp_var = var->GetPPVar();
134 EXPECT_TRUE(var_tracker().ReleaseVar(pp_var)); 140 EXPECT_TRUE(var_tracker().ReleaseVar(pp_var));
135 EXPECT_FALSE(var->HasValidVarID()); 141 EXPECT_FALSE(var->HasValidVarID());
136 EXPECT_EQ(1, mock_var_alive_count); 142 EXPECT_EQ(1, mock_var_alive_count);
137 143
138 // Obtaining PP_Var ref again, and add ref from VarTracker. 144 // Obtaining PP_Var ref again, and add ref from VarTracker.
139 pp_var = var->GetPPVar(); 145 pp_var = var->GetPPVar();
140 EXPECT_TRUE(var->HasValidVarID()); 146 EXPECT_TRUE(var->HasValidVarID());
141 EXPECT_TRUE(var_tracker().GetVar(var->GetExistingVarID())); 147 EXPECT_TRUE(var_tracker().GetVar(var->GetExistingVarID()));
142 scoped_refptr<MockObjectVar> another_var = 148 scoped_refptr<MockObjectVar> another_var =
143 static_cast<MockObjectVar*>(var_tracker().GetVar(pp_var)); 149 static_cast<MockObjectVar*>(var_tracker().GetVar(pp_var));
144 EXPECT_EQ(1, mock_var_alive_count); 150 EXPECT_EQ(1, mock_var_alive_count);
145 151
146 // Releasing all references, then only VarTracker own the instance. 152 // Releasing all references, then only VarTracker own the instance.
147 var = NULL; 153 var = NULL;
148 EXPECT_TRUE(var_tracker().GetVar(pp_var)); 154 EXPECT_TRUE(var_tracker().GetVar(pp_var));
149 EXPECT_EQ(1, mock_var_alive_count); 155 EXPECT_EQ(1, mock_var_alive_count);
150 another_var = NULL; 156 another_var = NULL;
151 EXPECT_TRUE(var_tracker().GetVar(pp_var)); 157 EXPECT_TRUE(var_tracker().GetVar(pp_var));
152 EXPECT_EQ(1, mock_var_alive_count); 158 EXPECT_EQ(1, mock_var_alive_count);
153 159
154 // Releasing plugin reference. 160 // Releasing plugin reference.
155 EXPECT_TRUE(var_tracker().ReleaseVar(pp_var)); 161 EXPECT_TRUE(var_tracker().ReleaseVar(pp_var));
156 EXPECT_EQ(0, mock_var_alive_count); 162 EXPECT_EQ(0, mock_var_alive_count);
157 } 163 }
158 164
159 } // namespace ppapi 165 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/shared_impl/tracked_callback_unittest.cc ('k') | ppapi/shared_impl/var_value_conversions_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698