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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/history/core/browser/download_database.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/history/core/browser/history_backend_db_unittest.cc
diff --git a/components/history/core/browser/history_backend_db_unittest.cc b/components/history/core/browser/history_backend_db_unittest.cc
index 0973b67b00ec3c6f8ef5ebfabbeda32c467e7a6b..58074479b785a8194a77a56a93da6ce0b00e0f98 100644
--- a/components/history/core/browser/history_backend_db_unittest.cc
+++ b/components/history/core/browser/history_backend_db_unittest.cc
@@ -519,6 +519,24 @@ TEST_F(HistoryBackendDBTest, MigrateDownloadMimeType) {
}
}
+bool IsValidRFC4122Ver4GUID(const std::string& guid) {
+ // base::IsValidGUID() doesn't restrict its validation to version (or subtype)
+ // 4 GUIDs as described in RFC 4122. So we check if base::IsValidGUID() thinks
+ // it's a valid GUID first, and then check the additional constraints.
+ //
+ // * Bits 4-7 of time_hi_and_version should be set to 0b0100 == 4
+ // => guid[14] == '4'
+ //
+ // * Bits 6-7 of clk_seq_hi_res should be set to 0b10
+ // => guid[19] in {'8','9','A','B'}
+ //
+ // * All other bits should be random or pseudo random.
+ // => http://dilbert.com/strip/2001-10-25
+ return base::IsValidGUID(guid) && guid[14] == '4' &&
+ (guid[19] == '8' || guid[19] == '9' || guid[19] == 'A' ||
+ guid[19] == 'B');
+}
+
TEST_F(HistoryBackendDBTest, MigrateHashHttpMethodAndGenerateGuids) {
const size_t kDownloadCount = 100;
ASSERT_NO_FATAL_FAILURE(CreateDBVersion(29));
@@ -583,7 +601,7 @@ TEST_F(HistoryBackendDBTest, MigrateHashHttpMethodAndGenerateGuids) {
std::unordered_set<std::string> guids;
while (s.Step()) {
std::string guid = s.ColumnString(0);
- EXPECT_TRUE(base::IsValidGUID(guid));
+ EXPECT_TRUE(IsValidRFC4122Ver4GUID(guid));
EXPECT_EQ(guid, base::ToUpperASCII(guid));
guids.insert(guid);
}
« 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