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

Side by Side Diff: content/browser/quota/quota_database_unittest.cc

Issue 654403002: Convert ARRAYSIZE_UNSAFE -> arraysize in content/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <algorithm> 5 #include <algorithm>
6 #include <iterator> 6 #include <iterator>
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 EXPECT_TRUE(kDbFile.empty() || base::PathExists(kDbFile)); 48 EXPECT_TRUE(kDbFile.empty() || base::PathExists(kDbFile));
49 } 49 }
50 50
51 void UpgradeSchemaV2toV3(const base::FilePath& kDbFile) { 51 void UpgradeSchemaV2toV3(const base::FilePath& kDbFile) {
52 const QuotaTableEntry entries[] = { 52 const QuotaTableEntry entries[] = {
53 QuotaTableEntry("a", kStorageTypeTemporary, 1), 53 QuotaTableEntry("a", kStorageTypeTemporary, 1),
54 QuotaTableEntry("b", kStorageTypeTemporary, 2), 54 QuotaTableEntry("b", kStorageTypeTemporary, 2),
55 QuotaTableEntry("c", kStorageTypePersistent, 3), 55 QuotaTableEntry("c", kStorageTypePersistent, 3),
56 }; 56 };
57 57
58 CreateV2Database(kDbFile, entries, ARRAYSIZE_UNSAFE(entries)); 58 CreateV2Database(kDbFile, entries, arraysize(entries));
59 59
60 QuotaDatabase db(kDbFile); 60 QuotaDatabase db(kDbFile);
61 EXPECT_TRUE(db.LazyOpen(true)); 61 EXPECT_TRUE(db.LazyOpen(true));
62 EXPECT_TRUE(db.db_.get()); 62 EXPECT_TRUE(db.db_.get());
63 63
64 typedef EntryVerifier<QuotaTableEntry> Verifier; 64 typedef EntryVerifier<QuotaTableEntry> Verifier;
65 Verifier verifier(entries, entries + ARRAYSIZE_UNSAFE(entries)); 65 Verifier verifier(entries, entries + arraysize(entries));
66 EXPECT_TRUE(db.DumpQuotaTable( 66 EXPECT_TRUE(db.DumpQuotaTable(
67 base::Bind(&Verifier::Run, base::Unretained(&verifier)))); 67 base::Bind(&Verifier::Run, base::Unretained(&verifier))));
68 EXPECT_TRUE(verifier.table.empty()); 68 EXPECT_TRUE(verifier.table.empty());
69 } 69 }
70 70
71 void HostQuota(const base::FilePath& kDbFile) { 71 void HostQuota(const base::FilePath& kDbFile) {
72 QuotaDatabase db(kDbFile); 72 QuotaDatabase db(kDbFile);
73 ASSERT_TRUE(db.LazyOpen(true)); 73 ASSERT_TRUE(db.LazyOpen(true));
74 74
75 const char* kHost = "foo.com"; 75 const char* kHost = "foo.com";
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 EXPECT_EQ(0U, origins.count(kOrigin3)); 280 EXPECT_EQ(0U, origins.count(kOrigin3));
281 } 281 }
282 282
283 void RegisterInitialOriginInfo(const base::FilePath& kDbFile) { 283 void RegisterInitialOriginInfo(const base::FilePath& kDbFile) {
284 QuotaDatabase db(kDbFile); 284 QuotaDatabase db(kDbFile);
285 285
286 const GURL kOrigins[] = { 286 const GURL kOrigins[] = {
287 GURL("http://a/"), 287 GURL("http://a/"),
288 GURL("http://b/"), 288 GURL("http://b/"),
289 GURL("http://c/") }; 289 GURL("http://c/") };
290 std::set<GURL> origins(kOrigins, kOrigins + ARRAYSIZE_UNSAFE(kOrigins)); 290 std::set<GURL> origins(kOrigins, kOrigins + arraysize(kOrigins));
291 291
292 EXPECT_TRUE(db.RegisterInitialOriginInfo(origins, kStorageTypeTemporary)); 292 EXPECT_TRUE(db.RegisterInitialOriginInfo(origins, kStorageTypeTemporary));
293 293
294 int used_count = -1; 294 int used_count = -1;
295 EXPECT_TRUE(db.FindOriginUsedCount(GURL("http://a/"), 295 EXPECT_TRUE(db.FindOriginUsedCount(GURL("http://a/"),
296 kStorageTypeTemporary, 296 kStorageTypeTemporary,
297 &used_count)); 297 &used_count));
298 EXPECT_EQ(0, used_count); 298 EXPECT_EQ(0, used_count);
299 299
300 EXPECT_TRUE(db.SetOriginLastAccessTime( 300 EXPECT_TRUE(db.SetOriginLastAccessTime(
(...skipping 28 matching lines...) Expand all
329 } 329 }
330 }; 330 };
331 331
332 void DumpQuotaTable(const base::FilePath& kDbFile) { 332 void DumpQuotaTable(const base::FilePath& kDbFile) {
333 QuotaTableEntry kTableEntries[] = { 333 QuotaTableEntry kTableEntries[] = {
334 QuotaTableEntry("http://go/", kStorageTypeTemporary, 1), 334 QuotaTableEntry("http://go/", kStorageTypeTemporary, 1),
335 QuotaTableEntry("http://oo/", kStorageTypeTemporary, 2), 335 QuotaTableEntry("http://oo/", kStorageTypeTemporary, 2),
336 QuotaTableEntry("http://gle/", kStorageTypePersistent, 3) 336 QuotaTableEntry("http://gle/", kStorageTypePersistent, 3)
337 }; 337 };
338 QuotaTableEntry* begin = kTableEntries; 338 QuotaTableEntry* begin = kTableEntries;
339 QuotaTableEntry* end = kTableEntries + ARRAYSIZE_UNSAFE(kTableEntries); 339 QuotaTableEntry* end = kTableEntries + arraysize(kTableEntries);
340 340
341 QuotaDatabase db(kDbFile); 341 QuotaDatabase db(kDbFile);
342 EXPECT_TRUE(db.LazyOpen(true)); 342 EXPECT_TRUE(db.LazyOpen(true));
343 AssignQuotaTable(db.db_.get(), begin, end); 343 AssignQuotaTable(db.db_.get(), begin, end);
344 db.Commit(); 344 db.Commit();
345 345
346 typedef EntryVerifier<QuotaTableEntry> Verifier; 346 typedef EntryVerifier<QuotaTableEntry> Verifier;
347 Verifier verifier(begin, end); 347 Verifier verifier(begin, end);
348 EXPECT_TRUE(db.DumpQuotaTable( 348 EXPECT_TRUE(db.DumpQuotaTable(
349 base::Bind(&Verifier::Run, base::Unretained(&verifier)))); 349 base::Bind(&Verifier::Run, base::Unretained(&verifier))));
350 EXPECT_TRUE(verifier.table.empty()); 350 EXPECT_TRUE(verifier.table.empty());
351 } 351 }
352 352
353 void DumpOriginInfoTable(const base::FilePath& kDbFile) { 353 void DumpOriginInfoTable(const base::FilePath& kDbFile) {
354 base::Time now(base::Time::Now()); 354 base::Time now(base::Time::Now());
355 typedef QuotaDatabase::OriginInfoTableEntry Entry; 355 typedef QuotaDatabase::OriginInfoTableEntry Entry;
356 Entry kTableEntries[] = { 356 Entry kTableEntries[] = {
357 Entry(GURL("http://go/"), kStorageTypeTemporary, 2147483647, now, now), 357 Entry(GURL("http://go/"), kStorageTypeTemporary, 2147483647, now, now),
358 Entry(GURL("http://oo/"), kStorageTypeTemporary, 0, now, now), 358 Entry(GURL("http://oo/"), kStorageTypeTemporary, 0, now, now),
359 Entry(GURL("http://gle/"), kStorageTypeTemporary, 1, now, now), 359 Entry(GURL("http://gle/"), kStorageTypeTemporary, 1, now, now),
360 }; 360 };
361 Entry* begin = kTableEntries; 361 Entry* begin = kTableEntries;
362 Entry* end = kTableEntries + ARRAYSIZE_UNSAFE(kTableEntries); 362 Entry* end = kTableEntries + arraysize(kTableEntries);
363 363
364 QuotaDatabase db(kDbFile); 364 QuotaDatabase db(kDbFile);
365 EXPECT_TRUE(db.LazyOpen(true)); 365 EXPECT_TRUE(db.LazyOpen(true));
366 AssignOriginInfoTable(db.db_.get(), begin, end); 366 AssignOriginInfoTable(db.db_.get(), begin, end);
367 db.Commit(); 367 db.Commit();
368 368
369 typedef EntryVerifier<Entry> Verifier; 369 typedef EntryVerifier<Entry> Verifier;
370 Verifier verifier(begin, end); 370 Verifier verifier(begin, end);
371 EXPECT_TRUE(db.DumpOriginInfoTable( 371 EXPECT_TRUE(db.DumpOriginInfoTable(
372 base::Bind(&Verifier::Run, base::Unretained(&verifier)))); 372 base::Bind(&Verifier::Run, base::Unretained(&verifier))));
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 { "OriginLastAccessIndex", 460 { "OriginLastAccessIndex",
461 kOriginLastAccessTable, 461 kOriginLastAccessTable,
462 "(origin, last_access_time)", 462 "(origin, last_access_time)",
463 false }, 463 false },
464 }; 464 };
465 465
466 ASSERT_TRUE(OpenDatabase(db.get(), kDbFile)); 466 ASSERT_TRUE(OpenDatabase(db.get(), kDbFile));
467 EXPECT_TRUE(QuotaDatabase::CreateSchema( 467 EXPECT_TRUE(QuotaDatabase::CreateSchema(
468 db.get(), meta_table.get(), 468 db.get(), meta_table.get(),
469 kCurrentVersion, kCompatibleVersion, 469 kCurrentVersion, kCompatibleVersion,
470 kTables, ARRAYSIZE_UNSAFE(kTables), 470 kTables, arraysize(kTables),
471 kIndexes, ARRAYSIZE_UNSAFE(kIndexes))); 471 kIndexes, arraysize(kIndexes)));
472 472
473 // V2 and V3 QuotaTable are compatible, so we can simply use 473 // V2 and V3 QuotaTable are compatible, so we can simply use
474 // AssignQuotaTable to poplulate v2 database here. 474 // AssignQuotaTable to poplulate v2 database here.
475 db->BeginTransaction(); 475 db->BeginTransaction();
476 AssignQuotaTable(db.get(), entries, entries + entries_size); 476 AssignQuotaTable(db.get(), entries, entries + entries_size);
477 db->CommitTransaction(); 477 db->CommitTransaction();
478 } 478 }
479 479
480 base::MessageLoop message_loop_; 480 base::MessageLoop message_loop_;
481 }; 481 };
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 } 558 }
559 559
560 TEST_F(QuotaDatabaseTest, DumpOriginInfoTable) { 560 TEST_F(QuotaDatabaseTest, DumpOriginInfoTable) {
561 base::ScopedTempDir data_dir; 561 base::ScopedTempDir data_dir;
562 ASSERT_TRUE(data_dir.CreateUniqueTempDir()); 562 ASSERT_TRUE(data_dir.CreateUniqueTempDir());
563 const base::FilePath kDbFile = data_dir.path().AppendASCII(kDBFileName); 563 const base::FilePath kDbFile = data_dir.path().AppendASCII(kDBFileName);
564 DumpOriginInfoTable(kDbFile); 564 DumpOriginInfoTable(kDbFile);
565 DumpOriginInfoTable(base::FilePath()); 565 DumpOriginInfoTable(base::FilePath());
566 } 566 }
567 } // namespace content 567 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/media/media_internals.cc ('k') | content/browser/quota/quota_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698