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

Unified Diff: net/disk_cache/simple/simple_index_unittest.cc

Issue 2109503002: Use saturated_cast<> instead of checked_cast<> for converting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: checkpoint Created 4 years, 6 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 | « net/disk_cache/simple/simple_index.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/disk_cache/simple/simple_index_unittest.cc
diff --git a/net/disk_cache/simple/simple_index_unittest.cc b/net/disk_cache/simple/simple_index_unittest.cc
index d763d7f55e1ff0858c3863922fb346408cb11ec9..1b0aee75235b6ca7a94db2955eb3e45d585c783c 100644
--- a/net/disk_cache/simple/simple_index_unittest.cc
+++ b/net/disk_cache/simple/simple_index_unittest.cc
@@ -34,8 +34,7 @@ const uint64_t kTestEntrySize = 789;
} // namespace
-
-class EntryMetadataTest : public testing::Test {
+class EntryMetadataTest : public testing::Test {
public:
EntryMetadata NewEntryMetadataWithValues() {
return EntryMetadata(kTestLastUsedTime, kTestEntrySize);
@@ -186,6 +185,25 @@ TEST_F(EntryMetadataTest, Basics) {
entry_metadata.GetLastUsedTime());
}
+// Tests that setting an unusually small/large last used time results in
+// truncation (rather than crashing).
+TEST_F(EntryMetadataTest, SaturatedLastUsedTime) {
+ EntryMetadata entry_metadata;
+
+ // Set a time that is too large to be represented internally as 32-bit unix
+ // timestamp. Will saturate to a large timestamp (in year 2106).
+ entry_metadata.SetLastUsedTime(base::Time::Max());
+ EXPECT_EQ(INT64_C(15939440895000000),
+ entry_metadata.GetLastUsedTime().ToInternalValue());
+
+ // Set a time that is too small to be represented by a unix timestamp (before
+ // 1970).
+ entry_metadata.SetLastUsedTime(
+ base::Time::FromInternalValue(7u)); // This is a date in 1601.
+ EXPECT_EQ(base::Time::UnixEpoch() + base::TimeDelta::FromSeconds(1),
+ entry_metadata.GetLastUsedTime());
+}
+
TEST_F(EntryMetadataTest, Serialize) {
EntryMetadata entry_metadata = NewEntryMetadataWithValues();
« no previous file with comments | « net/disk_cache/simple/simple_index.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698