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

Unified Diff: net/base/file_stream_unittest.cc

Issue 23500006: URLFetcher won't call delegate until file is closed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mmenke's 3rd review Created 7 years, 3 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/base/file_stream_metrics.cc ('k') | net/url_request/url_fetcher_response_writer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/base/file_stream_unittest.cc
diff --git a/net/base/file_stream_unittest.cc b/net/base/file_stream_unittest.cc
index 8eed06e0694c408e2b9eb1f65c450d0d1f06302f..addae890b588224d847c011be928d43315365009 100644
--- a/net/base/file_stream_unittest.cc
+++ b/net/base/file_stream_unittest.cc
@@ -78,6 +78,66 @@ TEST_F(FileStreamTest, BasicOpenClose) {
EXPECT_FALSE(base::GetPlatformFileInfo(file, &info));
}
+TEST_F(FileStreamTest, BasicOpenExplicitClose) {
+ base::PlatformFile file = base::kInvalidPlatformFileValue;
+ FileStream stream(NULL);
+ int rv = stream.OpenSync(temp_file_path(),
+ base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ);
+ EXPECT_EQ(OK, rv);
+ EXPECT_TRUE(stream.IsOpen());
+ file = stream.GetPlatformFileForTesting();
+ EXPECT_NE(base::kInvalidPlatformFileValue, file);
+ EXPECT_EQ(OK, stream.CloseSync());
+ EXPECT_FALSE(stream.IsOpen());
+ base::PlatformFileInfo info;
+ // The file should be closed.
+ EXPECT_FALSE(base::GetPlatformFileInfo(file, &info));
+}
+
+TEST_F(FileStreamTest, AsyncOpenExplicitClose) {
+ base::PlatformFile file = base::kInvalidPlatformFileValue;
+ TestCompletionCallback callback;
+ FileStream stream(NULL);
+ int flags = base::PLATFORM_FILE_OPEN |
+ base::PLATFORM_FILE_READ |
+ base::PLATFORM_FILE_ASYNC;
+ int rv = stream.Open(temp_file_path(), flags, callback.callback());
+ EXPECT_EQ(ERR_IO_PENDING, rv);
+ EXPECT_EQ(OK, callback.WaitForResult());
+ EXPECT_TRUE(stream.IsOpen());
+ file = stream.GetPlatformFileForTesting();
+ EXPECT_EQ(ERR_IO_PENDING, stream.Close(callback.callback()));
+ EXPECT_EQ(OK, callback.WaitForResult());
+ EXPECT_FALSE(stream.IsOpen());
+ base::PlatformFileInfo info;
+ // The file should be closed.
+ EXPECT_FALSE(base::GetPlatformFileInfo(file, &info));
+}
+
+TEST_F(FileStreamTest, AsyncOpenExplicitCloseOrphaned) {
+ base::PlatformFile file = base::kInvalidPlatformFileValue;
+ TestCompletionCallback callback;
+ base::PlatformFileInfo info;
+ scoped_ptr<FileStream> stream(new FileStream(
+ NULL, base::MessageLoopProxy::current()));
+ int flags = base::PLATFORM_FILE_OPEN |
+ base::PLATFORM_FILE_READ |
+ base::PLATFORM_FILE_ASYNC;
+ int rv = stream->Open(temp_file_path(), flags, callback.callback());
+ EXPECT_EQ(ERR_IO_PENDING, rv);
+ EXPECT_EQ(OK, callback.WaitForResult());
+ EXPECT_TRUE(stream->IsOpen());
+ file = stream->GetPlatformFileForTesting();
+ EXPECT_EQ(ERR_IO_PENDING, stream->Close(callback.callback()));
+ stream.reset();
+ // File isn't actually closed yet.
+ EXPECT_TRUE(base::GetPlatformFileInfo(file, &info));
+ base::RunLoop runloop;
+ runloop.RunUntilIdle();
+ // The file should now be closed, though the callback has not been called.
+ EXPECT_FALSE(base::GetPlatformFileInfo(file, &info));
+}
+
TEST_F(FileStreamTest, FileHandleNotLeftOpen) {
bool created = false;
ASSERT_EQ(kTestDataSize,
« no previous file with comments | « net/base/file_stream_metrics.cc ('k') | net/url_request/url_fetcher_response_writer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698