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

Unified Diff: net/base/file_stream_unittest.cc

Issue 10701050: net: Implement canceling of all async operations in FileStream. (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 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
Index: net/base/file_stream_unittest.cc
===================================================================
--- net/base/file_stream_unittest.cc (revision 147715)
+++ net/base/file_stream_unittest.cc (working copy)
@@ -113,7 +113,7 @@
EXPECT_FALSE(base::GetPlatformFileInfo(file, &info));
}
-TEST_F(FileStreamTest, FileHandleLeftOpen) {
+TEST_F(FileStreamTest, FileHandleNotLeftOpen) {
bool created = false;
ASSERT_EQ(kTestDataSize,
file_util::WriteFile(temp_file_path(), kTestData, kTestDataSize));
@@ -129,10 +129,9 @@
EXPECT_NE(base::kInvalidPlatformFileValue, file);
base::PlatformFileInfo info;
- // The file should still be open.
- EXPECT_TRUE(base::GetPlatformFileInfo(file, &info));
- // Clean up.
- EXPECT_TRUE(base::ClosePlatformFile(file));
+ // The file should be closed.
+ EXPECT_FALSE(base::GetPlatformFileInfo(file, &info));
+ EXPECT_FALSE(base::ClosePlatformFile(file));
}
// Test the use of FileStream with a file handle provided at construction.
@@ -320,47 +319,6 @@
}
}
-// Similar to AsyncRead_EarlyDelete but using a given file handler rather than
-// calling FileStream::Open, to ensure that deleting a stream with in-flight
-// operation without auto-closing feature is also ok.
-TEST_F(FileStreamTest, AsyncRead_EarlyDelete_NoAutoClose) {
- int64 file_size;
- bool ok = file_util::GetFileSize(temp_file_path(), &file_size);
- EXPECT_TRUE(ok);
-
- bool created = false;
- int flags = base::PLATFORM_FILE_OPEN |
- base::PLATFORM_FILE_READ |
- base::PLATFORM_FILE_ASYNC;
- base::PlatformFileError error_code = base::PLATFORM_FILE_ERROR_FAILED;
- base::PlatformFile file = base::CreatePlatformFile(
- temp_file_path(), flags, &created, &error_code);
- EXPECT_EQ(base::PLATFORM_FILE_OK, error_code);
-
- scoped_ptr<FileStream> stream(new FileStream(file, flags, NULL));
- int64 total_bytes_avail = stream->Available();
- EXPECT_EQ(file_size, total_bytes_avail);
-
- TestCompletionCallback callback;
- scoped_refptr<IOBufferWithSize> buf = new IOBufferWithSize(4);
- int rv = stream->Read(buf, buf->size(), callback.callback());
- stream.reset(); // Delete instead of closing it.
- if (rv < 0) {
- EXPECT_EQ(ERR_IO_PENDING, rv);
- // The callback should not be called if the request is cancelled.
- MessageLoop::current()->RunAllPending();
- EXPECT_FALSE(callback.have_result());
- } else {
- EXPECT_EQ(std::string(kTestData, rv), std::string(buf->data(), rv));
- }
-
- base::PlatformFileInfo info;
- // The file should still be open.
- EXPECT_TRUE(base::GetPlatformFileInfo(file, &info));
- // Clean up.
- EXPECT_TRUE(base::ClosePlatformFile(file));
-}
-
TEST_F(FileStreamTest, BasicRead_FromOffset) {
int64 file_size;
bool ok = file_util::GetFileSize(temp_file_path(), &file_size);
@@ -1217,6 +1175,7 @@
// Close the stream without waiting for the completion. Should be safe.
stream.CloseSync();
// open_callback won't be called.
+ MessageLoop::current()->RunAllPending();
EXPECT_FALSE(open_callback.have_result());
}
@@ -1233,6 +1192,7 @@
// complete. Should be safe.
stream.reset();
// open_callback won't be called.
+ MessageLoop::current()->RunAllPending();
EXPECT_FALSE(open_callback.have_result());
}
@@ -1254,6 +1214,7 @@
// complete. Should be safe.
stream.reset();
// close_callback won't be called.
+ MessageLoop::current()->RunAllPending();
EXPECT_FALSE(close_callback.have_result());
}

Powered by Google App Engine
This is Rietveld 408576698