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

Side by Side Diff: components/history/core/browser/history_backend_db_unittest.cc

Issue 1870223002: [Downloads/History] Comply with RFC 4122 when generating GUIDs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a comment explaining previous GUID generation scheme and why no migration is necessary. Created 4 years, 8 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 | « components/history/core/browser/download_database.cc ('k') | no next file » | 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 // History unit tests come in two flavors: 5 // History unit tests come in two flavors:
6 // 6 //
7 // 1. The more complicated style is that the unit test creates a full history 7 // 1. The more complicated style is that the unit test creates a full history
8 // service. This spawns a background thread for the history backend, and 8 // service. This spawns a background thread for the history backend, and
9 // all communication is asynchronous. This is useful for testing more 9 // all communication is asynchronous. This is useful for testing more
10 // complicated things or end-to-end behavior. 10 // complicated things or end-to-end behavior.
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 { 512 {
513 sql::Statement s(db.GetUniqueStatement( 513 sql::Statement s(db.GetUniqueStatement(
514 "SELECT mime_type, original_mime_type from downloads")); 514 "SELECT mime_type, original_mime_type from downloads"));
515 EXPECT_TRUE(s.Step()); 515 EXPECT_TRUE(s.Step());
516 EXPECT_EQ(std::string(), s.ColumnString(0)); 516 EXPECT_EQ(std::string(), s.ColumnString(0));
517 EXPECT_EQ(std::string(), s.ColumnString(1)); 517 EXPECT_EQ(std::string(), s.ColumnString(1));
518 } 518 }
519 } 519 }
520 } 520 }
521 521
522 bool IsValidRFC4122Ver4GUID(const std::string& guid) {
523 // base::IsValidGUID() doesn't restrict its validation to version (or subtype)
524 // 4 GUIDs as described in RFC 4122. So we check if base::IsValidGUID() thinks
525 // it's a valid GUID first, and then check the additional constraints.
526 //
527 // * Bits 4-7 of time_hi_and_version should be set to 0b0100 == 4
528 // => guid[14] == '4'
529 //
530 // * Bits 6-7 of clk_seq_hi_res should be set to 0b10
531 // => guid[19] in {'8','9','A','B'}
532 //
533 // * All other bits should be random or pseudo random.
534 // => http://dilbert.com/strip/2001-10-25
535 return base::IsValidGUID(guid) && guid[14] == '4' &&
536 (guid[19] == '8' || guid[19] == '9' || guid[19] == 'A' ||
537 guid[19] == 'B');
538 }
539
522 TEST_F(HistoryBackendDBTest, MigrateHashHttpMethodAndGenerateGuids) { 540 TEST_F(HistoryBackendDBTest, MigrateHashHttpMethodAndGenerateGuids) {
523 const size_t kDownloadCount = 100; 541 const size_t kDownloadCount = 100;
524 ASSERT_NO_FATAL_FAILURE(CreateDBVersion(29)); 542 ASSERT_NO_FATAL_FAILURE(CreateDBVersion(29));
525 base::Time now(base::Time::Now()); 543 base::Time now(base::Time::Now());
526 { 544 {
527 sql::Connection db; 545 sql::Connection db;
528 ASSERT_TRUE(db.Open(history_dir_.Append(kHistoryFilename))); 546 ASSERT_TRUE(db.Open(history_dir_.Append(kHistoryFilename)));
529 547
530 // In testing, it appeared that constructing a query where all rows are 548 // In testing, it appeared that constructing a query where all rows are
531 // specified (i.e. looks like "INSERT INTO foo (...) VALUES (...),(...)") 549 // specified (i.e. looks like "INSERT INTO foo (...) VALUES (...),(...)")
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 sql::Statement s(db.GetUniqueStatement( 594 sql::Statement s(db.GetUniqueStatement(
577 "SELECT value FROM meta WHERE key = 'version'")); 595 "SELECT value FROM meta WHERE key = 'version'"));
578 EXPECT_TRUE(s.Step()); 596 EXPECT_TRUE(s.Step());
579 EXPECT_EQ(cur_version, s.ColumnInt(0)); 597 EXPECT_EQ(cur_version, s.ColumnInt(0));
580 } 598 }
581 { 599 {
582 sql::Statement s(db.GetUniqueStatement("SELECT guid from downloads")); 600 sql::Statement s(db.GetUniqueStatement("SELECT guid from downloads"));
583 std::unordered_set<std::string> guids; 601 std::unordered_set<std::string> guids;
584 while (s.Step()) { 602 while (s.Step()) {
585 std::string guid = s.ColumnString(0); 603 std::string guid = s.ColumnString(0);
586 EXPECT_TRUE(base::IsValidGUID(guid)); 604 EXPECT_TRUE(IsValidRFC4122Ver4GUID(guid));
587 EXPECT_EQ(guid, base::ToUpperASCII(guid)); 605 EXPECT_EQ(guid, base::ToUpperASCII(guid));
588 guids.insert(guid); 606 guids.insert(guid);
589 } 607 }
590 EXPECT_TRUE(s.Succeeded()); 608 EXPECT_TRUE(s.Succeeded());
591 EXPECT_EQ(kDownloadCount, guids.size()); 609 EXPECT_EQ(kDownloadCount, guids.size());
592 } 610 }
593 } 611 }
594 } 612 }
595 613
596 TEST_F(HistoryBackendDBTest, DownloadCreateAndQuery) { 614 TEST_F(HistoryBackendDBTest, DownloadCreateAndQuery) {
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 // Current browser version must be already higher than 28. 1034 // Current browser version must be already higher than 28.
1017 ASSERT_LT(28, HistoryDatabase::GetCurrentVersion()); 1035 ASSERT_LT(28, HistoryDatabase::GetCurrentVersion());
1018 // Expect that version in DB remains the same. 1036 // Expect that version in DB remains the same.
1019 EXPECT_EQ(28, meta.GetVersionNumber()); 1037 EXPECT_EQ(28, meta.GetVersionNumber());
1020 } 1038 }
1021 } 1039 }
1022 } 1040 }
1023 1041
1024 } // namespace 1042 } // namespace
1025 } // namespace history 1043 } // namespace history
OLDNEW
« no previous file with comments | « components/history/core/browser/download_database.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698