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

Side by Side Diff: chrome/browser/net/predictor_unittest.cc

Issue 10837044: Correct const accessors in base/values.(h|cc), Part II (ListValue) (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: David's comments Created 8 years, 4 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 | « chrome/browser/net/predictor.cc ('k') | chrome/browser/policy/policy_loader_win_unittest.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) 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 <time.h> 5 #include <time.h>
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <sstream> 8 #include <sstream>
9 #include <string> 9 #include <string>
10 10
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 240
241 testing_master.Shutdown(); 241 testing_master.Shutdown();
242 } 242 }
243 243
244 //------------------------------------------------------------------------------ 244 //------------------------------------------------------------------------------
245 // Functions to help synthesize and test serializations of subresource referrer 245 // Functions to help synthesize and test serializations of subresource referrer
246 // lists. 246 // lists.
247 247
248 // Return a motivation_list if we can find one for the given motivating_host (or 248 // Return a motivation_list if we can find one for the given motivating_host (or
249 // NULL if a match is not found). 249 // NULL if a match is not found).
250 static ListValue* FindSerializationMotivation(const GURL& motivation, 250 static const ListValue* FindSerializationMotivation(
251 const ListValue& referral_list) { 251 const GURL& motivation,
252 CHECK_LT(0u, referral_list.GetSize()); // Room for version. 252 const ListValue* referral_list) {
253 CHECK_LT(0u, referral_list->GetSize()); // Room for version.
253 int format_version = -1; 254 int format_version = -1;
254 CHECK(referral_list.GetInteger(0, &format_version)); 255 CHECK(referral_list->GetInteger(0, &format_version));
255 CHECK_EQ(Predictor::kPredictorReferrerVersion, format_version); 256 CHECK_EQ(Predictor::kPredictorReferrerVersion, format_version);
256 ListValue* motivation_list(NULL); 257 const ListValue* motivation_list(NULL);
257 for (size_t i = 1; i < referral_list.GetSize(); ++i) { 258 for (size_t i = 1; i < referral_list->GetSize(); ++i) {
258 referral_list.GetList(i, &motivation_list); 259 referral_list->GetList(i, &motivation_list);
259 std::string existing_spec; 260 std::string existing_spec;
260 EXPECT_TRUE(motivation_list->GetString(0, &existing_spec)); 261 EXPECT_TRUE(motivation_list->GetString(0, &existing_spec));
261 if (motivation == GURL(existing_spec)) 262 if (motivation == GURL(existing_spec))
262 return motivation_list; 263 return motivation_list;
263 } 264 }
264 return NULL; 265 return NULL;
265 } 266 }
266 267
268 static ListValue* FindSerializationMotivation(const GURL& motivation,
269 ListValue* referral_list) {
270 return const_cast<ListValue*>(FindSerializationMotivation(
271 motivation, static_cast<const ListValue*>(referral_list)));
272 }
273
267 // Create a new empty serialization list. 274 // Create a new empty serialization list.
268 static ListValue* NewEmptySerializationList() { 275 static ListValue* NewEmptySerializationList() {
269 base::ListValue* list = new base::ListValue; 276 base::ListValue* list = new base::ListValue;
270 list->Append( 277 list->Append(
271 new base::FundamentalValue(Predictor::kPredictorReferrerVersion)); 278 new base::FundamentalValue(Predictor::kPredictorReferrerVersion));
272 return list; 279 return list;
273 } 280 }
274 281
275 // Add a motivating_url and a subresource_url to a serialized list, using 282 // Add a motivating_url and a subresource_url to a serialized list, using
276 // this given latency. This is a helper function for quickly building these 283 // this given latency. This is a helper function for quickly building these
277 // lists. 284 // lists.
278 static void AddToSerializedList(const GURL& motivation, 285 static void AddToSerializedList(const GURL& motivation,
279 const GURL& subresource, 286 const GURL& subresource,
280 double use_rate, 287 double use_rate,
281 ListValue* referral_list ) { 288 ListValue* referral_list ) {
282 // Find the motivation if it is already used. 289 // Find the motivation if it is already used.
283 ListValue* motivation_list = FindSerializationMotivation(motivation, 290 ListValue* motivation_list = FindSerializationMotivation(motivation,
284 *referral_list); 291 referral_list);
285 if (!motivation_list) { 292 if (!motivation_list) {
286 // This is the first mention of this motivation, so build a list. 293 // This is the first mention of this motivation, so build a list.
287 motivation_list = new ListValue; 294 motivation_list = new ListValue;
288 motivation_list->Append(new StringValue(motivation.spec())); 295 motivation_list->Append(new StringValue(motivation.spec()));
289 // Provide empty subresource list. 296 // Provide empty subresource list.
290 motivation_list->Append(new ListValue()); 297 motivation_list->Append(new ListValue());
291 298
292 // ...and make it part of the serialized referral_list. 299 // ...and make it part of the serialized referral_list.
293 referral_list->Append(motivation_list); 300 referral_list->Append(motivation_list);
294 } 301 }
(...skipping 13 matching lines...) Expand all
308 static const int kLatencyNotFound = -1; 315 static const int kLatencyNotFound = -1;
309 316
310 // For a given motivation, and subresource, find what latency is currently 317 // For a given motivation, and subresource, find what latency is currently
311 // listed. This assume a well formed serialization, which has at most one such 318 // listed. This assume a well formed serialization, which has at most one such
312 // entry for any pair of names. If no such pair is found, then return false. 319 // entry for any pair of names. If no such pair is found, then return false.
313 // Data is written into use_rate arguments. 320 // Data is written into use_rate arguments.
314 static bool GetDataFromSerialization(const GURL& motivation, 321 static bool GetDataFromSerialization(const GURL& motivation,
315 const GURL& subresource, 322 const GURL& subresource,
316 const ListValue& referral_list, 323 const ListValue& referral_list,
317 double* use_rate) { 324 double* use_rate) {
318 ListValue* motivation_list = FindSerializationMotivation(motivation, 325 const ListValue* motivation_list =
319 referral_list); 326 FindSerializationMotivation(motivation, &referral_list);
320 if (!motivation_list) 327 if (!motivation_list)
321 return false; 328 return false;
322 ListValue* subresource_list; 329 const ListValue* subresource_list;
323 EXPECT_TRUE(motivation_list->GetList(1, &subresource_list)); 330 EXPECT_TRUE(motivation_list->GetList(1, &subresource_list));
324 for (size_t i = 0; i < subresource_list->GetSize();) { 331 for (size_t i = 0; i < subresource_list->GetSize();) {
325 std::string url_spec; 332 std::string url_spec;
326 EXPECT_TRUE(subresource_list->GetString(i++, &url_spec)); 333 EXPECT_TRUE(subresource_list->GetString(i++, &url_spec));
327 EXPECT_TRUE(subresource_list->GetDouble(i++, use_rate)); 334 EXPECT_TRUE(subresource_list->GetDouble(i++, use_rate));
328 if (subresource == GURL(url_spec)) { 335 if (subresource == GURL(url_spec)) {
329 return true; 336 return true;
330 } 337 }
331 } 338 }
332 return false; 339 return false;
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 EXPECT_EQ(2U, referral_list.GetSize()); 675 EXPECT_EQ(2U, referral_list.GetSize());
669 676
670 predictor.DiscardAllResults(); 677 predictor.DiscardAllResults();
671 predictor.SerializeReferrers(&referral_list); 678 predictor.SerializeReferrers(&referral_list);
672 EXPECT_EQ(1U, referral_list.GetSize()); 679 EXPECT_EQ(1U, referral_list.GetSize());
673 680
674 predictor.Shutdown(); 681 predictor.Shutdown();
675 } 682 }
676 683
677 } // namespace chrome_browser_net 684 } // namespace chrome_browser_net
OLDNEW
« no previous file with comments | « chrome/browser/net/predictor.cc ('k') | chrome/browser/policy/policy_loader_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698