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

Side by Side Diff: content/browser/download/download_file_unittest.cc

Issue 11028131: Shift passage of FileStream in downloads system to be by scoped_ptr<>. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Incorporated Al's comments. Created 8 years, 2 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 | Annotate | Revision Log
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 "base/file_util.h" 5 #include "base/file_util.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "base/string_number_conversions.h" 7 #include "base/string_number_conversions.h"
8 #include "base/test/test_file_util.h" 8 #include "base/test/test_file_util.h"
9 #include "content/browser/browser_thread_impl.h" 9 #include "content/browser/browser_thread_impl.h"
10 #include "content/browser/download/byte_stream.h" 10 #include "content/browser/download/byte_stream.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 DCHECK(!download_file_.get()); 132 DCHECK(!download_file_.get());
133 133
134 input_stream_ = new StrictMock<MockByteStreamReader>(); 134 input_stream_ = new StrictMock<MockByteStreamReader>();
135 135
136 // TODO: Need to actually create a function that'll set the variables 136 // TODO: Need to actually create a function that'll set the variables
137 // based on the inputs from the callback. 137 // based on the inputs from the callback.
138 EXPECT_CALL(*input_stream_, RegisterCallback(_)) 138 EXPECT_CALL(*input_stream_, RegisterCallback(_))
139 .WillOnce(Invoke(this, &DownloadFileTest::RegisterCallback)) 139 .WillOnce(Invoke(this, &DownloadFileTest::RegisterCallback))
140 .RetiresOnSaturation(); 140 .RetiresOnSaturation();
141 141
142 DownloadCreateInfo info; 142 scoped_ptr<DownloadCreateInfo> info(new DownloadCreateInfo());
143 // info.request_handle default constructed to null. 143 // info.request_handle default constructed to null.
144 info.download_id = DownloadId(kValidIdDomain, kDummyDownloadId + offset); 144 info->download_id = DownloadId(kValidIdDomain, kDummyDownloadId + offset);
145 info.save_info.file_stream = file_stream_;
146 download_file_.reset( 145 download_file_.reset(
147 new DownloadFileImpl( 146 new DownloadFileImpl(
148 &info, 147 info.Pass(),
149 scoped_ptr<content::ByteStreamReader>(input_stream_).Pass(), 148 scoped_ptr<content::ByteStreamReader>(input_stream_).Pass(),
150 new DownloadRequestHandle(), 149 scoped_ptr<DownloadRequestHandleInterface>(
150 new DownloadRequestHandle()),
151 download_manager_, calculate_hash, 151 download_manager_, calculate_hash,
152 scoped_ptr<content::PowerSaveBlocker>(NULL).Pass(), 152 scoped_ptr<content::PowerSaveBlocker>(),
153 net::BoundNetLog())); 153 net::BoundNetLog()));
154 154
155 EXPECT_CALL(*input_stream_, Read(_, _)) 155 EXPECT_CALL(*input_stream_, Read(_, _))
156 .WillOnce(Return(content::ByteStreamReader::STREAM_EMPTY)) 156 .WillOnce(Return(content::ByteStreamReader::STREAM_EMPTY))
157 .RetiresOnSaturation(); 157 .RetiresOnSaturation();
158 content::DownloadInterruptReason result = download_file_->Initialize(); 158 content::DownloadInterruptReason result = download_file_->Initialize();
159 ::testing::Mock::VerifyAndClearExpectations(input_stream_); 159 ::testing::Mock::VerifyAndClearExpectations(input_stream_);
160 return result == content::DOWNLOAD_INTERRUPT_REASON_NONE; 160 return result == content::DOWNLOAD_INTERRUPT_REASON_NONE;
161 } 161 }
162 162
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 &result_reason, result_path_p)); 267 &result_reason, result_path_p));
268 loop_.RunAllPending(); 268 loop_.RunAllPending();
269 269
270 EXPECT_TRUE(callback_was_called); 270 EXPECT_TRUE(callback_was_called);
271 return result_reason; 271 return result_reason;
272 } 272 }
273 273
274 protected: 274 protected:
275 scoped_refptr<StrictMock<LocalMockDownloadManager> > download_manager_; 275 scoped_refptr<StrictMock<LocalMockDownloadManager> > download_manager_;
276 276
277 linked_ptr<net::FileStream> file_stream_;
278
279 // DownloadFile instance we are testing. 277 // DownloadFile instance we are testing.
280 scoped_ptr<DownloadFile> download_file_; 278 scoped_ptr<DownloadFile> download_file_;
281 279
282 // Stream for sending data into the download file. 280 // Stream for sending data into the download file.
283 // Owned by download_file_; will be alive for lifetime of download_file_. 281 // Owned by download_file_; will be alive for lifetime of download_file_.
284 StrictMock<MockByteStreamReader>* input_stream_; 282 StrictMock<MockByteStreamReader>* input_stream_;
285 283
286 // Sink callback data for stream. 284 // Sink callback data for stream.
287 base::Closure sink_callback_; 285 base::Closure sink_callback_;
288 286
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 base::TimeDelta::FromMilliseconds(750)); 600 base::TimeDelta::FromMilliseconds(750));
603 loop_.Run(); 601 loop_.Run();
604 602
605 EXPECT_EQ(static_cast<int64>(strlen(kTestData1) + strlen(kTestData2)), 603 EXPECT_EQ(static_cast<int64>(strlen(kTestData1) + strlen(kTestData2)),
606 bytes_); 604 bytes_);
607 EXPECT_EQ(download_file_->GetHashState(), hash_state_); 605 EXPECT_EQ(download_file_->GetHashState(), hash_state_);
608 606
609 FinishStream(content::DOWNLOAD_INTERRUPT_REASON_NONE, true); 607 FinishStream(content::DOWNLOAD_INTERRUPT_REASON_NONE, true);
610 DestroyDownloadFile(0); 608 DestroyDownloadFile(0);
611 } 609 }
OLDNEW
« no previous file with comments | « content/browser/download/download_file_manager_unittest.cc ('k') | content/browser/download/download_item_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698