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

Unified Diff: content/browser/fileapi/local_file_stream_reader_unittest.cc

Issue 1308773006: FileAPI: Compare expected modification time with delta on file read (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove 20us test since OSX has 1s resolution. ASSERT->EXPECT Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | storage/browser/fileapi/file_stream_reader.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/fileapi/local_file_stream_reader_unittest.cc
diff --git a/content/browser/fileapi/local_file_stream_reader_unittest.cc b/content/browser/fileapi/local_file_stream_reader_unittest.cc
index d8e30ce7ec56ad846d1713e5caa65719d8d8264b..fefd996095ba521ee18e83f158e52c90cbcce8c1 100644
--- a/content/browser/fileapi/local_file_stream_reader_unittest.cc
+++ b/content/browser/fileapi/local_file_stream_reader_unittest.cc
@@ -95,9 +95,8 @@ class LocalFileStreamReaderTest : public testing::Test {
expected_modification_time);
}
- void TouchTestFile() {
- base::Time new_modified_time =
- test_file_modification_time() - base::TimeDelta::FromSeconds(1);
+ void TouchTestFile(base::TimeDelta delta) {
+ base::Time new_modified_time = test_file_modification_time() + delta;
ASSERT_TRUE(base::TouchFile(test_path(),
test_file_modification_time(),
new_modified_time));
@@ -171,7 +170,7 @@ TEST_F(LocalFileStreamReaderTest, GetLengthNormal) {
TEST_F(LocalFileStreamReaderTest, GetLengthAfterModified) {
// Touch file so that the file's modification time becomes different
// from what we expect.
- TouchTestFile();
+ TouchTestFile(base::TimeDelta::FromSeconds(-1));
scoped_ptr<LocalFileStreamReader> reader(
CreateFileReader(test_path(), 0, test_file_modification_time()));
@@ -212,23 +211,41 @@ TEST_F(LocalFileStreamReaderTest, ReadNormal) {
TEST_F(LocalFileStreamReaderTest, ReadAfterModified) {
// Touch file so that the file's modification time becomes different
- // from what we expect.
- TouchTestFile();
-
+ // from what we expect. Note that the resolution on some filesystems
+ // is 1s so we can't test with deltas less than that.
+ TouchTestFile(base::TimeDelta::FromSeconds(-1));
scoped_ptr<LocalFileStreamReader> reader(
CreateFileReader(test_path(), 0, test_file_modification_time()));
int result = 0;
std::string data;
ReadFromReader(reader.get(), &data, kTestDataSize, &result);
- ASSERT_EQ(net::ERR_UPLOAD_FILE_CHANGED, result);
- ASSERT_EQ(0U, data.size());
+ EXPECT_EQ(net::ERR_UPLOAD_FILE_CHANGED, result);
+ EXPECT_EQ(0U, data.size());
- // With NULL expected modification time this should work.
+ // Due to precision loss converting int64->double->int64 (e.g. through
+ // Blink) the expected/actual time may vary by microseconds. With
+ // modification time delta < 10us this should work.
+ TouchTestFile(base::TimeDelta::FromMicroseconds(1));
+ data.clear();
+ reader.reset(CreateFileReader(test_path(), 0, test_file_modification_time()));
+ ReadFromReader(reader.get(), &data, kTestDataSize, &result);
+ EXPECT_EQ(net::OK, result);
+ EXPECT_EQ(kTestData, data);
+
+ // With matching modification times time this should work.
+ TouchTestFile(base::TimeDelta());
+ data.clear();
+ reader.reset(CreateFileReader(test_path(), 0, test_file_modification_time()));
+ ReadFromReader(reader.get(), &data, kTestDataSize, &result);
+ EXPECT_EQ(net::OK, result);
+ EXPECT_EQ(kTestData, data);
+
+ // And with NULL expected modification time this should work.
data.clear();
reader.reset(CreateFileReader(test_path(), 0, base::Time()));
ReadFromReader(reader.get(), &data, kTestDataSize, &result);
- ASSERT_EQ(net::OK, result);
- ASSERT_EQ(kTestData, data);
+ EXPECT_EQ(net::OK, result);
+ EXPECT_EQ(kTestData, data);
}
TEST_F(LocalFileStreamReaderTest, ReadWithOffset) {
« no previous file with comments | « no previous file | storage/browser/fileapi/file_stream_reader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698