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

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 2nd 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 scoped_ptr<FileStream> stream(new FileStream(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 stream.reset();
mmenke 2013/09/10 22:38:19 Shouldn't this go above the "base::PlatformFileInf
waffles 2013/09/10 22:58:33 Previously, it did, but while changing it, it seem
116 }
117
118 TEST_F(FileStreamTest, AsyncOpenExplicitCloseOrphaned) {
119 base::PlatformFile file = base::kInvalidPlatformFileValue;
120 TestCompletionCallback callback;
121 base::PlatformFileInfo info;
122 scoped_ptr<FileStream> stream(new FileStream(
123 NULL, base::MessageLoopProxy::current()));
124 int flags = base::PLATFORM_FILE_OPEN |
125 base::PLATFORM_FILE_READ |
126 base::PLATFORM_FILE_ASYNC;
127 int rv = stream->Open(temp_file_path(), flags, callback.callback());
128 EXPECT_EQ(ERR_IO_PENDING, rv);
129 EXPECT_EQ(OK, callback.WaitForResult());
130 EXPECT_TRUE(stream->IsOpen());
131 file = stream->GetPlatformFileForTesting();
132 EXPECT_EQ(ERR_IO_PENDING, stream->Close(callback.callback()));
133 stream.reset();
134 // File isn't actually closed yet.
135 EXPECT_TRUE(base::GetPlatformFileInfo(file, &info));
136 base::RunLoop runloop;
137 runloop.RunUntilIdle();
138 // The file should now be closed, though the callback has not been called.
139 EXPECT_FALSE(base::GetPlatformFileInfo(file, &info));
140 }
141
81 TEST_F(FileStreamTest, FileHandleNotLeftOpen) { 142 TEST_F(FileStreamTest, FileHandleNotLeftOpen) {
82 bool created = false; 143 bool created = false;
83 ASSERT_EQ(kTestDataSize, 144 ASSERT_EQ(kTestDataSize,
84 file_util::WriteFile(temp_file_path(), kTestData, kTestDataSize)); 145 file_util::WriteFile(temp_file_path(), kTestData, kTestDataSize));
85 int flags = base::PLATFORM_FILE_OPEN_ALWAYS | base::PLATFORM_FILE_READ; 146 int flags = base::PLATFORM_FILE_OPEN_ALWAYS | base::PLATFORM_FILE_READ;
86 base::PlatformFile file = base::CreatePlatformFile( 147 base::PlatformFile file = base::CreatePlatformFile(
87 temp_file_path(), flags, &created, NULL); 148 temp_file_path(), flags, &created, NULL);
88 149
89 { 150 {
90 // Seek to the beginning of the file and read. 151 // 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); 1156 scoped_refptr<IOBuffer> buf = new WrappedIOBuffer(NULL);
1096 rv = stream->Read(buf.get(), 1, callback.callback()); 1157 rv = stream->Read(buf.get(), 1, callback.callback());
1097 if (rv == ERR_IO_PENDING) 1158 if (rv == ERR_IO_PENDING)
1098 rv = callback.WaitForResult(); 1159 rv = callback.WaitForResult();
1099 EXPECT_LT(rv, 0); 1160 EXPECT_LT(rv, 0);
1100 } 1161 }
1101 1162
1102 } // namespace 1163 } // namespace
1103 1164
1104 } // namespace net 1165 } // 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