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

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

Issue 23809016: [PPAPI] ResourceVar now reference counts its PP_Resource in the plugin. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix Windows compile. 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
« no previous file with comments | « ppapi/shared_impl/test_globals.h ('k') | ppapi/shared_impl/var.cc » ('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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "ppapi/shared_impl/unittest_utils.h" 5 #include "ppapi/shared_impl/unittest_utils.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/containers/hash_tables.h" 9 #include "base/containers/hash_tables.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "ipc/ipc_message.h"
11 #include "ppapi/shared_impl/array_var.h" 12 #include "ppapi/shared_impl/array_var.h"
12 #include "ppapi/shared_impl/dictionary_var.h" 13 #include "ppapi/shared_impl/dictionary_var.h"
13 #include "ppapi/shared_impl/resource_var.h" 14 #include "ppapi/shared_impl/resource_var.h"
14 #include "ppapi/shared_impl/var.h" 15 #include "ppapi/shared_impl/var.h"
15 #include "ppapi/shared_impl/var_tracker.h" 16 #include "ppapi/shared_impl/var_tracker.h"
16 17
17 namespace ppapi { 18 namespace ppapi {
18 19
19 namespace { 20 namespace {
20 21
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 visited_map)) { 150 visited_map)) {
150 return false; 151 return false;
151 } 152 }
152 } 153 }
153 return true; 154 return true;
154 } 155 }
155 case PP_VARTYPE_RESOURCE: { 156 case PP_VARTYPE_RESOURCE: {
156 ResourceVar* expected_var = ResourceVar::FromPPVar(expected); 157 ResourceVar* expected_var = ResourceVar::FromPPVar(expected);
157 ResourceVar* actual_var = ResourceVar::FromPPVar(actual); 158 ResourceVar* actual_var = ResourceVar::FromPPVar(actual);
158 DCHECK(expected_var && actual_var); 159 DCHECK(expected_var && actual_var);
159 if (expected_var->pp_resource() != actual_var->pp_resource()) { 160 if (expected_var->GetPPResource() != actual_var->GetPPResource()) {
160 LOG(ERROR) << "expected: " << expected_var->pp_resource() << " actual: " 161 LOG(ERROR) << "expected: " << expected_var->GetPPResource()
161 << actual_var->pp_resource(); 162 << " actual: " << actual_var->GetPPResource();
162 return false;
163 }
164 IPC::Message actual_message(actual_var->creation_message());
165 const IPC::Message& expected_message = expected_var->creation_message();
166 if (expected_message.size() != actual_message.size()) {
167 LOG(ERROR) << "expected creation message size: "
168 << expected_message.size() << " actual: "
169 << actual_message.size();
170 return false; 163 return false;
171 } 164 }
172 165
166 const IPC::Message* actual_message = actual_var->GetCreationMessage();
167 const IPC::Message* expected_message =
168 expected_var->GetCreationMessage();
169 if (expected_message->size() != actual_message->size()) {
170 LOG(ERROR) << "expected creation message size: "
171 << expected_message->size() << " actual: "
172 << actual_message->size();
173 return false;
174 }
175
173 // Set the upper 24 bits of actual creation_message flags to the same as 176 // Set the upper 24 bits of actual creation_message flags to the same as
174 // expected. This is an unpredictable reference number that changes 177 // expected. This is an unpredictable reference number that changes
175 // between serialization/deserialization, and we do not want it to cause 178 // between serialization/deserialization, and we do not want it to cause
176 // the comparison to fail. 179 // the comparison to fail.
177 actual_message.SetHeaderValues(actual_message.routing_id(), 180 IPC::Message local_actual_message(*actual_message);
178 actual_message.type(), 181 local_actual_message.SetHeaderValues(
179 (expected_message.flags() & 0xffffff00) | 182 actual_message->routing_id(), actual_message->type(),
180 (actual_message.flags() & 0xff)); 183 (expected_message->flags() & 0xffffff00) |
181 if (memcmp(expected_message.data(), actual_message.data(), 184 (actual_message->flags() & 0xff));
182 expected_message.size()) != 0) { 185 if (memcmp(expected_message->data(), local_actual_message.data(),
186 expected_message->size()) != 0) {
183 LOG(ERROR) << "expected creation message does not match actual."; 187 LOG(ERROR) << "expected creation message does not match actual.";
184 return false; 188 return false;
185 } 189 }
186 return true; 190 return true;
187 } 191 }
188 } 192 }
189 NOTREACHED(); 193 NOTREACHED();
190 return false; 194 return false;
191 } 195 }
192 196
193 } // namespace 197 } // namespace
194 198
195 bool TestEqual(const PP_Var& expected, const PP_Var& actual) { 199 bool TestEqual(const PP_Var& expected, const PP_Var& actual) {
196 base::hash_map<int64_t, int64_t> visited_map; 200 base::hash_map<int64_t, int64_t> visited_map;
197 return Equals(expected, actual, &visited_map); 201 return Equals(expected, actual, &visited_map);
198 } 202 }
199 203
200 } // namespace ppapi 204 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/shared_impl/test_globals.h ('k') | ppapi/shared_impl/var.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698