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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/base/file_stream.h" 5 #include "net/base/file_stream.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 EXPECT_EQ(OK, rv); 71 EXPECT_EQ(OK, rv);
72 EXPECT_TRUE(stream.IsOpen()); 72 EXPECT_TRUE(stream.IsOpen());
73 file = stream.GetPlatformFileForTesting(); 73 file = stream.GetPlatformFileForTesting();
74 } 74 }
75 EXPECT_NE(base::kInvalidPlatformFileValue, file); 75 EXPECT_NE(base::kInvalidPlatformFileValue, file);
76 base::PlatformFileInfo info; 76 base::PlatformFileInfo info;
77 // The file should be closed. 77 // The file should be closed.
78 EXPECT_FALSE(base::GetPlatformFileInfo(file, &info)); 78 EXPECT_FALSE(base::GetPlatformFileInfo(file, &info));
79 } 79 }
80 80
81 TEST_F(FileStreamTest, BasicOpenExplicitClose) {
82 base::PlatformFile file = base::kInvalidPlatformFileValue;
83 FileStream stream(NULL);
84 int rv = stream.OpenSync(temp_file_path(),
85 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ);
86 EXPECT_EQ(OK, rv);
87 EXPECT_TRUE(stream.IsOpen());
88 file = stream.GetPlatformFileForTesting();
89 EXPECT_NE(base::kInvalidPlatformFileValue, file);
90 EXPECT_EQ(OK, stream.CloseSync());
91 EXPECT_FALSE(stream.IsOpen());
92 base::PlatformFileInfo info;
93 // The file should be closed.
94 EXPECT_FALSE(base::GetPlatformFileInfo(file, &info));
95 }
96
97 TEST_F(FileStreamTest, AsyncOpenExplicitClose) {
98 base::PlatformFile file = base::kInvalidPlatformFileValue;
99 TestCompletionCallback callback;
100 FileStream stream(NULL);
101 int flags = base::PLATFORM_FILE_OPEN |
102 base::PLATFORM_FILE_READ |
103 base::PLATFORM_FILE_ASYNC;
104 int rv = stream.Open(temp_file_path(), flags, callback.callback());
105 EXPECT_EQ(ERR_IO_PENDING, rv);
106 EXPECT_EQ(OK, callback.WaitForResult());
107 EXPECT_TRUE(stream.IsOpen());
108 file = stream.GetPlatformFileForTesting();
109 EXPECT_EQ(ERR_IO_PENDING, stream.Close(callback.callback()));
110 EXPECT_EQ(OK, callback.WaitForResult());
111 EXPECT_FALSE(stream.IsOpen());
112 base::PlatformFileInfo info;
113 // The file should be closed.
114 EXPECT_FALSE(base::GetPlatformFileInfo(file, &info));
115 }
116
117 TEST_F(FileStreamTest, AsyncOpenExplicitCloseOrphaned) {
118 base::PlatformFile file = base::kInvalidPlatformFileValue;
119 TestCompletionCallback callback;
120 base::PlatformFileInfo info;
121 scoped_ptr<FileStream> stream(new FileStream(
122 NULL, base::MessageLoopProxy::current()));
123 int flags = base::PLATFORM_FILE_OPEN |
124 base::PLATFORM_FILE_READ |
125 base::PLATFORM_FILE_ASYNC;
126 int rv = stream->Open(temp_file_path(), flags, callback.callback());
127 EXPECT_EQ(ERR_IO_PENDING, rv);
128 EXPECT_EQ(OK, callback.WaitForResult());
129 EXPECT_TRUE(stream->IsOpen());
130 file = stream->GetPlatformFileForTesting();
131 EXPECT_EQ(ERR_IO_PENDING, stream->Close(callback.callback()));
132 stream.reset();
133 // File isn't actually closed yet.
134 EXPECT_TRUE(base::GetPlatformFileInfo(file, &info));
135 base::RunLoop runloop;
136 runloop.RunUntilIdle();
137 // The file should now be closed, though the callback has not been called.
138 EXPECT_FALSE(base::GetPlatformFileInfo(file, &info));
139 }
140
81 TEST_F(FileStreamTest, FileHandleNotLeftOpen) { 141 TEST_F(FileStreamTest, FileHandleNotLeftOpen) {
82 bool created = false; 142 bool created = false;
83 ASSERT_EQ(kTestDataSize, 143 ASSERT_EQ(kTestDataSize,
84 file_util::WriteFile(temp_file_path(), kTestData, kTestDataSize)); 144 file_util::WriteFile(temp_file_path(), kTestData, kTestDataSize));
85 int flags = base::PLATFORM_FILE_OPEN_ALWAYS | base::PLATFORM_FILE_READ; 145 int flags = base::PLATFORM_FILE_OPEN_ALWAYS | base::PLATFORM_FILE_READ;
86 base::PlatformFile file = base::CreatePlatformFile( 146 base::PlatformFile file = base::CreatePlatformFile(
87 temp_file_path(), flags, &created, NULL); 147 temp_file_path(), flags, &created, NULL);
88 148
89 { 149 {
90 // Seek to the beginning of the file and read. 150 // Seek to the beginning of the file and read.
(...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after
1095 scoped_refptr<IOBuffer> buf = new WrappedIOBuffer(NULL); 1155 scoped_refptr<IOBuffer> buf = new WrappedIOBuffer(NULL);
1096 rv = stream->Read(buf.get(), 1, callback.callback()); 1156 rv = stream->Read(buf.get(), 1, callback.callback());
1097 if (rv == ERR_IO_PENDING) 1157 if (rv == ERR_IO_PENDING)
1098 rv = callback.WaitForResult(); 1158 rv = callback.WaitForResult();
1099 EXPECT_LT(rv, 0); 1159 EXPECT_LT(rv, 0);
1100 } 1160 }
1101 1161
1102 } // namespace 1162 } // namespace
1103 1163
1104 } // namespace net 1164 } // namespace net
OLDNEW
« 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