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

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

Issue 18284005: Make ByteStream independent from DownloadInterruptReason (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove CONTENT_EXPORT all Created 7 years, 4 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 // This file contains download browser tests that are known to be runnable 5 // This file contains download browser tests that are known to be runnable
6 // in a pure content context. Over time tests should be migrated here. 6 // in a pure content context. Over time tests should be migrated here.
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "content/browser/byte_stream.h" 14 #include "content/browser/byte_stream.h"
15 #include "content/browser/download/download_file_factory.h" 15 #include "content/browser/download/download_file_factory.h"
16 #include "content/browser/download/download_file_impl.h" 16 #include "content/browser/download/download_file_impl.h"
17 #include "content/browser/download/download_item_impl.h" 17 #include "content/browser/download/download_item_impl.h"
18 #include "content/browser/download/download_manager_impl.h" 18 #include "content/browser/download/download_manager_impl.h"
19 #include "content/browser/download/download_resource_handler.h" 19 #include "content/browser/download/download_resource_handler.h"
20 #include "content/browser/plugin_service_impl.h" 20 #include "content/browser/plugin_service_impl.h"
21 #include "content/browser/web_contents/web_contents_impl.h" 21 #include "content/browser/web_contents/web_contents_impl.h"
22 #include "content/public/browser/download_interrupt_reasons.h"
22 #include "content/public/browser/power_save_blocker.h" 23 #include "content/public/browser/power_save_blocker.h"
23 #include "content/public/common/content_switches.h" 24 #include "content/public/common/content_switches.h"
24 #include "content/public/common/webplugininfo.h" 25 #include "content/public/common/webplugininfo.h"
25 #include "content/public/test/download_test_observer.h" 26 #include "content/public/test/download_test_observer.h"
26 #include "content/public/test/test_file_error_injector.h" 27 #include "content/public/test/test_file_error_injector.h"
27 #include "content/public/test/test_utils.h" 28 #include "content/public/test/test_utils.h"
28 #include "content/shell/shell.h" 29 #include "content/shell/shell.h"
29 #include "content/shell/shell_browser_context.h" 30 #include "content/shell/shell_browser_context.h"
30 #include "content/shell/shell_download_manager_delegate.h" 31 #include "content/shell/shell_download_manager_delegate.h"
31 #include "content/test/content_browser_test.h" 32 #include "content/test/content_browser_test.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 } 98 }
98 99
99 class DownloadFileWithDelay : public DownloadFileImpl { 100 class DownloadFileWithDelay : public DownloadFileImpl {
100 public: 101 public:
101 DownloadFileWithDelay( 102 DownloadFileWithDelay(
102 scoped_ptr<DownloadSaveInfo> save_info, 103 scoped_ptr<DownloadSaveInfo> save_info,
103 const base::FilePath& default_download_directory, 104 const base::FilePath& default_download_directory,
104 const GURL& url, 105 const GURL& url,
105 const GURL& referrer_url, 106 const GURL& referrer_url,
106 bool calculate_hash, 107 bool calculate_hash,
107 scoped_ptr<ByteStreamReader> stream, 108 scoped_ptr<ByteStreamReader<DownloadInterruptReason> > stream,
108 const net::BoundNetLog& bound_net_log, 109 const net::BoundNetLog& bound_net_log,
109 scoped_ptr<PowerSaveBlocker> power_save_blocker, 110 scoped_ptr<PowerSaveBlocker> power_save_blocker,
110 base::WeakPtr<DownloadDestinationObserver> observer, 111 base::WeakPtr<DownloadDestinationObserver> observer,
111 base::WeakPtr<DownloadFileWithDelayFactory> owner); 112 base::WeakPtr<DownloadFileWithDelayFactory> owner);
112 113
113 virtual ~DownloadFileWithDelay(); 114 virtual ~DownloadFileWithDelay();
114 115
115 // Wraps DownloadFileImpl::Rename* and intercepts the return callback, 116 // Wraps DownloadFileImpl::Rename* and intercepts the return callback,
116 // storing it in the factory that produced this object for later 117 // storing it in the factory that produced this object for later
117 // retrieval. 118 // retrieval.
(...skipping 27 matching lines...) Expand all
145 DownloadFileWithDelayFactory(); 146 DownloadFileWithDelayFactory();
146 virtual ~DownloadFileWithDelayFactory(); 147 virtual ~DownloadFileWithDelayFactory();
147 148
148 // DownloadFileFactory interface. 149 // DownloadFileFactory interface.
149 virtual DownloadFile* CreateFile( 150 virtual DownloadFile* CreateFile(
150 scoped_ptr<DownloadSaveInfo> save_info, 151 scoped_ptr<DownloadSaveInfo> save_info,
151 const base::FilePath& default_download_directory, 152 const base::FilePath& default_download_directory,
152 const GURL& url, 153 const GURL& url,
153 const GURL& referrer_url, 154 const GURL& referrer_url,
154 bool calculate_hash, 155 bool calculate_hash,
155 scoped_ptr<ByteStreamReader> stream, 156 scoped_ptr<ByteStreamReader<DownloadInterruptReason> > stream,
156 const net::BoundNetLog& bound_net_log, 157 const net::BoundNetLog& bound_net_log,
157 base::WeakPtr<DownloadDestinationObserver> observer) OVERRIDE; 158 base::WeakPtr<DownloadDestinationObserver> observer) OVERRIDE;
158 159
159 void AddRenameCallback(base::Closure callback); 160 void AddRenameCallback(base::Closure callback);
160 void GetAllRenameCallbacks(std::vector<base::Closure>* results); 161 void GetAllRenameCallbacks(std::vector<base::Closure>* results);
161 162
162 // Do not return until GetAllRenameCallbacks() will return a non-empty list. 163 // Do not return until GetAllRenameCallbacks() will return a non-empty list.
163 void WaitForSomeCallback(); 164 void WaitForSomeCallback();
164 165
165 private: 166 private:
166 base::WeakPtrFactory<DownloadFileWithDelayFactory> weak_ptr_factory_; 167 base::WeakPtrFactory<DownloadFileWithDelayFactory> weak_ptr_factory_;
167 std::vector<base::Closure> rename_callbacks_; 168 std::vector<base::Closure> rename_callbacks_;
168 bool waiting_; 169 bool waiting_;
169 170
170 DISALLOW_COPY_AND_ASSIGN(DownloadFileWithDelayFactory); 171 DISALLOW_COPY_AND_ASSIGN(DownloadFileWithDelayFactory);
171 }; 172 };
172 173
173 DownloadFileWithDelay::DownloadFileWithDelay( 174 DownloadFileWithDelay::DownloadFileWithDelay(
174 scoped_ptr<DownloadSaveInfo> save_info, 175 scoped_ptr<DownloadSaveInfo> save_info,
175 const base::FilePath& default_download_directory, 176 const base::FilePath& default_download_directory,
176 const GURL& url, 177 const GURL& url,
177 const GURL& referrer_url, 178 const GURL& referrer_url,
178 bool calculate_hash, 179 bool calculate_hash,
179 scoped_ptr<ByteStreamReader> stream, 180 scoped_ptr<ByteStreamReader<DownloadInterruptReason> > stream,
180 const net::BoundNetLog& bound_net_log, 181 const net::BoundNetLog& bound_net_log,
181 scoped_ptr<PowerSaveBlocker> power_save_blocker, 182 scoped_ptr<PowerSaveBlocker> power_save_blocker,
182 base::WeakPtr<DownloadDestinationObserver> observer, 183 base::WeakPtr<DownloadDestinationObserver> observer,
183 base::WeakPtr<DownloadFileWithDelayFactory> owner) 184 base::WeakPtr<DownloadFileWithDelayFactory> owner)
184 : DownloadFileImpl( 185 : DownloadFileImpl(
185 save_info.Pass(), default_download_directory, url, referrer_url, 186 save_info.Pass(), default_download_directory, url, referrer_url,
186 calculate_hash, stream.Pass(), bound_net_log, 187 calculate_hash, stream.Pass(), bound_net_log,
187 power_save_blocker.Pass(), observer), 188 power_save_blocker.Pass(), observer),
188 owner_(owner) {} 189 owner_(owner) {}
189 190
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 : weak_ptr_factory_(this), 223 : weak_ptr_factory_(this),
223 waiting_(false) {} 224 waiting_(false) {}
224 DownloadFileWithDelayFactory::~DownloadFileWithDelayFactory() {} 225 DownloadFileWithDelayFactory::~DownloadFileWithDelayFactory() {}
225 226
226 DownloadFile* DownloadFileWithDelayFactory::CreateFile( 227 DownloadFile* DownloadFileWithDelayFactory::CreateFile(
227 scoped_ptr<DownloadSaveInfo> save_info, 228 scoped_ptr<DownloadSaveInfo> save_info,
228 const base::FilePath& default_download_directory, 229 const base::FilePath& default_download_directory,
229 const GURL& url, 230 const GURL& url,
230 const GURL& referrer_url, 231 const GURL& referrer_url,
231 bool calculate_hash, 232 bool calculate_hash,
232 scoped_ptr<ByteStreamReader> stream, 233 scoped_ptr<ByteStreamReader<DownloadInterruptReason> > stream,
233 const net::BoundNetLog& bound_net_log, 234 const net::BoundNetLog& bound_net_log,
234 base::WeakPtr<DownloadDestinationObserver> observer) { 235 base::WeakPtr<DownloadDestinationObserver> observer) {
235 scoped_ptr<PowerSaveBlocker> psb( 236 scoped_ptr<PowerSaveBlocker> psb(
236 PowerSaveBlocker::Create( 237 PowerSaveBlocker::Create(
237 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, 238 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
238 "Download in progress")); 239 "Download in progress"));
239 return new DownloadFileWithDelay( 240 return new DownloadFileWithDelay(
240 save_info.Pass(), default_download_directory, url, referrer_url, 241 save_info.Pass(), default_download_directory, url, referrer_url,
241 calculate_hash, stream.Pass(), bound_net_log, 242 calculate_hash, stream.Pass(), bound_net_log,
242 psb.Pass(), observer, weak_ptr_factory_.GetWeakPtr()); 243 psb.Pass(), observer, weak_ptr_factory_.GetWeakPtr());
(...skipping 23 matching lines...) Expand all
266 } 267 }
267 268
268 class CountingDownloadFile : public DownloadFileImpl { 269 class CountingDownloadFile : public DownloadFileImpl {
269 public: 270 public:
270 CountingDownloadFile( 271 CountingDownloadFile(
271 scoped_ptr<DownloadSaveInfo> save_info, 272 scoped_ptr<DownloadSaveInfo> save_info,
272 const base::FilePath& default_downloads_directory, 273 const base::FilePath& default_downloads_directory,
273 const GURL& url, 274 const GURL& url,
274 const GURL& referrer_url, 275 const GURL& referrer_url,
275 bool calculate_hash, 276 bool calculate_hash,
276 scoped_ptr<ByteStreamReader> stream, 277 scoped_ptr<ByteStreamReader<DownloadInterruptReason> > stream,
277 const net::BoundNetLog& bound_net_log, 278 const net::BoundNetLog& bound_net_log,
278 scoped_ptr<PowerSaveBlocker> power_save_blocker, 279 scoped_ptr<PowerSaveBlocker> power_save_blocker,
279 base::WeakPtr<DownloadDestinationObserver> observer) 280 base::WeakPtr<DownloadDestinationObserver> observer)
280 : DownloadFileImpl(save_info.Pass(), default_downloads_directory, 281 : DownloadFileImpl(save_info.Pass(), default_downloads_directory,
281 url, referrer_url, calculate_hash, 282 url, referrer_url, calculate_hash,
282 stream.Pass(), bound_net_log, 283 stream.Pass(), bound_net_log,
283 power_save_blocker.Pass(), observer) {} 284 power_save_blocker.Pass(), observer) {}
284 285
285 virtual ~CountingDownloadFile() { 286 virtual ~CountingDownloadFile() {
286 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 287 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 CountingDownloadFileFactory() {} 324 CountingDownloadFileFactory() {}
324 virtual ~CountingDownloadFileFactory() {} 325 virtual ~CountingDownloadFileFactory() {}
325 326
326 // DownloadFileFactory interface. 327 // DownloadFileFactory interface.
327 virtual DownloadFile* CreateFile( 328 virtual DownloadFile* CreateFile(
328 scoped_ptr<DownloadSaveInfo> save_info, 329 scoped_ptr<DownloadSaveInfo> save_info,
329 const base::FilePath& default_downloads_directory, 330 const base::FilePath& default_downloads_directory,
330 const GURL& url, 331 const GURL& url,
331 const GURL& referrer_url, 332 const GURL& referrer_url,
332 bool calculate_hash, 333 bool calculate_hash,
333 scoped_ptr<ByteStreamReader> stream, 334 scoped_ptr<ByteStreamReader<DownloadInterruptReason> > stream,
334 const net::BoundNetLog& bound_net_log, 335 const net::BoundNetLog& bound_net_log,
335 base::WeakPtr<DownloadDestinationObserver> observer) OVERRIDE { 336 base::WeakPtr<DownloadDestinationObserver> observer) OVERRIDE {
336 scoped_ptr<PowerSaveBlocker> psb( 337 scoped_ptr<PowerSaveBlocker> psb(
337 PowerSaveBlocker::Create( 338 PowerSaveBlocker::Create(
338 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, 339 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
339 "Download in progress")); 340 "Download in progress"));
340 return new CountingDownloadFile( 341 return new CountingDownloadFile(
341 save_info.Pass(), default_downloads_directory, url, referrer_url, 342 save_info.Pass(), default_downloads_directory, url, referrer_url,
342 calculate_hash, stream.Pass(), bound_net_log, 343 calculate_hash, stream.Pass(), bound_net_log,
343 psb.Pass(), observer); 344 psb.Pass(), observer);
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 class DownloadContentTest : public ContentBrowserTest { 508 class DownloadContentTest : public ContentBrowserTest {
508 protected: 509 protected:
509 // An initial send from a website of at least this size will not be 510 // An initial send from a website of at least this size will not be
510 // help up by buffering in the underlying downloads ByteStream data 511 // help up by buffering in the underlying downloads ByteStream data
511 // transfer. This is important because on resumption tests we wait 512 // transfer. This is important because on resumption tests we wait
512 // until we've gotten the data we expect before allowing the test server 513 // until we've gotten the data we expect before allowing the test server
513 // to send its reset, to get around hard close semantics on the Windows 514 // to send its reset, to get around hard close semantics on the Windows
514 // socket layer implementation. 515 // socket layer implementation.
515 int GetSafeBufferChunk() const { 516 int GetSafeBufferChunk() const {
516 return (DownloadResourceHandler::kDownloadByteStreamSize / 517 return (DownloadResourceHandler::kDownloadByteStreamSize /
517 ByteStreamWriter::kFractionBufferBeforeSending) + 1; 518 ByteStreamWriter<DownloadInterruptReason>::
519 kFractionBufferBeforeSending) + 1;
518 } 520 }
519 521
520 virtual void SetUpOnMainThread() OVERRIDE { 522 virtual void SetUpOnMainThread() OVERRIDE {
521 ASSERT_TRUE(downloads_directory_.CreateUniqueTempDir()); 523 ASSERT_TRUE(downloads_directory_.CreateUniqueTempDir());
522 524
523 TestShellDownloadManagerDelegate* delegate = 525 TestShellDownloadManagerDelegate* delegate =
524 new TestShellDownloadManagerDelegate(); 526 new TestShellDownloadManagerDelegate();
525 delegate->SetDownloadBehaviorForTesting(downloads_directory_.path()); 527 delegate->SetDownloadBehaviorForTesting(downloads_directory_.path());
526 DownloadManager* manager = DownloadManagerForShell(shell()); 528 DownloadManager* manager = DownloadManagerForShell(shell());
527 manager->SetDelegate(delegate); 529 manager->SetDelegate(delegate);
(...skipping 1064 matching lines...) Expand 10 before | Expand all | Expand 10 after
1592 // Start the second download and wait until it's done. The test server is 1594 // Start the second download and wait until it's done. The test server is
1593 // single threaded. The response to this download request should follow the 1595 // single threaded. The response to this download request should follow the
1594 // response to the previous resumption request. 1596 // response to the previous resumption request.
1595 GURL url2(test_server()->GetURL("rangereset?size=100&rst_limit=0&token=x")); 1597 GURL url2(test_server()->GetURL("rangereset?size=100&rst_limit=0&token=x"));
1596 DownloadAndWait(shell(), url2, DownloadItem::COMPLETE); 1598 DownloadAndWait(shell(), url2, DownloadItem::COMPLETE);
1597 1599
1598 EXPECT_TRUE(EnsureNoPendingDownloads()); 1600 EXPECT_TRUE(EnsureNoPendingDownloads());
1599 } 1601 }
1600 1602
1601 } // namespace content 1603 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698