OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/url_request/url_fetcher_response_writer.h" | 5 #include "net/url_request/url_fetcher_response_writer.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 rv = writer_->Initialize(callback.callback()); | 50 rv = writer_->Initialize(callback.callback()); |
51 EXPECT_EQ(OK, callback.GetResult(rv)); | 51 EXPECT_EQ(OK, callback.GetResult(rv)); |
52 EXPECT_TRUE(writer_->data().empty()); | 52 EXPECT_TRUE(writer_->data().empty()); |
53 } | 53 } |
54 | 54 |
55 class URLFetcherFileWriterTest : public PlatformTest { | 55 class URLFetcherFileWriterTest : public PlatformTest { |
56 protected: | 56 protected: |
57 virtual void SetUp() OVERRIDE { | 57 virtual void SetUp() OVERRIDE { |
58 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 58 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
59 file_path_ = temp_dir_.path().AppendASCII("test.txt"); | 59 file_path_ = temp_dir_.path().AppendASCII("test.txt"); |
60 writer_.reset(new URLFetcherFileWriter( | 60 writer_.reset(new URLFetcherFileWriter(base::MessageLoopProxy::current(), |
61 base::MessageLoopProxy::current(), file_path_)); | 61 file_path_)); |
62 buf_ = new StringIOBuffer(kData); | 62 buf_ = new StringIOBuffer(kData); |
63 } | 63 } |
64 | 64 |
65 base::ScopedTempDir temp_dir_; | 65 base::ScopedTempDir temp_dir_; |
66 base::FilePath file_path_; | 66 base::FilePath file_path_; |
67 scoped_ptr<URLFetcherFileWriter> writer_; | 67 scoped_ptr<URLFetcherFileWriter> writer_; |
68 scoped_refptr<StringIOBuffer> buf_; | 68 scoped_refptr<StringIOBuffer> buf_; |
69 }; | 69 }; |
70 | 70 |
71 TEST_F(URLFetcherFileWriterTest, WriteToFile) { | 71 TEST_F(URLFetcherFileWriterTest, WriteToFile) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 | 138 |
139 // File is not deleted even after the writer gets destroyed. | 139 // File is not deleted even after the writer gets destroyed. |
140 writer_.reset(); | 140 writer_.reset(); |
141 base::RunLoop().RunUntilIdle(); | 141 base::RunLoop().RunUntilIdle(); |
142 EXPECT_TRUE(base::PathExists(file_path_)); | 142 EXPECT_TRUE(base::PathExists(file_path_)); |
143 } | 143 } |
144 | 144 |
145 class URLFetcherFileWriterTemporaryFileTest : public PlatformTest { | 145 class URLFetcherFileWriterTemporaryFileTest : public PlatformTest { |
146 protected: | 146 protected: |
147 virtual void SetUp() OVERRIDE { | 147 virtual void SetUp() OVERRIDE { |
148 writer_.reset(new URLFetcherFileWriter( | 148 writer_.reset(new URLFetcherFileWriter(base::MessageLoopProxy::current(), |
149 base::MessageLoopProxy::current(), base::FilePath())); | 149 base::FilePath())); |
150 buf_ = new StringIOBuffer(kData); | 150 buf_ = new StringIOBuffer(kData); |
151 } | 151 } |
152 | 152 |
153 scoped_ptr<URLFetcherFileWriter> writer_; | 153 scoped_ptr<URLFetcherFileWriter> writer_; |
154 scoped_refptr<StringIOBuffer> buf_; | 154 scoped_refptr<StringIOBuffer> buf_; |
155 }; | 155 }; |
156 | 156 |
157 TEST_F(URLFetcherFileWriterTemporaryFileTest, WriteToTemporaryFile) { | 157 TEST_F(URLFetcherFileWriterTemporaryFileTest, WriteToTemporaryFile) { |
158 int rv = 0; | 158 int rv = 0; |
159 // Initialize(), Write() and Finish(). | 159 // Initialize(), Write() and Finish(). |
(...skipping 11 matching lines...) Expand all Loading... |
171 EXPECT_EQ(kData, file_contents); | 171 EXPECT_EQ(kData, file_contents); |
172 | 172 |
173 // Destroy the writer. File should be deleted. | 173 // Destroy the writer. File should be deleted. |
174 const base::FilePath file_path = writer_->file_path(); | 174 const base::FilePath file_path = writer_->file_path(); |
175 writer_.reset(); | 175 writer_.reset(); |
176 base::RunLoop().RunUntilIdle(); | 176 base::RunLoop().RunUntilIdle(); |
177 EXPECT_FALSE(base::PathExists(file_path)); | 177 EXPECT_FALSE(base::PathExists(file_path)); |
178 } | 178 } |
179 | 179 |
180 } // namespace net | 180 } // namespace net |
OLD | NEW |