OLD | NEW |
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/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 base::WeakPtr<DownloadDestinationObserver> observer, | 122 base::WeakPtr<DownloadDestinationObserver> observer, |
123 base::WeakPtr<DownloadFileWithDelayFactory> owner); | 123 base::WeakPtr<DownloadFileWithDelayFactory> owner); |
124 | 124 |
125 virtual ~DownloadFileWithDelay(); | 125 virtual ~DownloadFileWithDelay(); |
126 | 126 |
127 // Wraps DownloadFileImpl::Rename* and intercepts the return callback, | 127 // Wraps DownloadFileImpl::Rename* and intercepts the return callback, |
128 // storing it in the factory that produced this object for later | 128 // storing it in the factory that produced this object for later |
129 // retrieval. | 129 // retrieval. |
130 virtual void RenameAndUniquify( | 130 virtual void RenameAndUniquify( |
131 const base::FilePath& full_path, | 131 const base::FilePath& full_path, |
132 const RenameCompletionCallback& callback) OVERRIDE; | 132 const RenameCompletionCallback& callback) override; |
133 virtual void RenameAndAnnotate( | 133 virtual void RenameAndAnnotate( |
134 const base::FilePath& full_path, | 134 const base::FilePath& full_path, |
135 const RenameCompletionCallback& callback) OVERRIDE; | 135 const RenameCompletionCallback& callback) override; |
136 | 136 |
137 private: | 137 private: |
138 static void RenameCallbackWrapper( | 138 static void RenameCallbackWrapper( |
139 const base::WeakPtr<DownloadFileWithDelayFactory>& factory, | 139 const base::WeakPtr<DownloadFileWithDelayFactory>& factory, |
140 const RenameCompletionCallback& original_callback, | 140 const RenameCompletionCallback& original_callback, |
141 DownloadInterruptReason reason, | 141 DownloadInterruptReason reason, |
142 const base::FilePath& path); | 142 const base::FilePath& path); |
143 | 143 |
144 // This variable may only be read on the FILE thread, and may only be | 144 // This variable may only be read on the FILE thread, and may only be |
145 // indirected through (e.g. methods on DownloadFileWithDelayFactory called) | 145 // indirected through (e.g. methods on DownloadFileWithDelayFactory called) |
(...skipping 13 matching lines...) Expand all Loading... |
159 | 159 |
160 // DownloadFileFactory interface. | 160 // DownloadFileFactory interface. |
161 virtual DownloadFile* CreateFile( | 161 virtual DownloadFile* CreateFile( |
162 scoped_ptr<DownloadSaveInfo> save_info, | 162 scoped_ptr<DownloadSaveInfo> save_info, |
163 const base::FilePath& default_download_directory, | 163 const base::FilePath& default_download_directory, |
164 const GURL& url, | 164 const GURL& url, |
165 const GURL& referrer_url, | 165 const GURL& referrer_url, |
166 bool calculate_hash, | 166 bool calculate_hash, |
167 scoped_ptr<ByteStreamReader> stream, | 167 scoped_ptr<ByteStreamReader> stream, |
168 const net::BoundNetLog& bound_net_log, | 168 const net::BoundNetLog& bound_net_log, |
169 base::WeakPtr<DownloadDestinationObserver> observer) OVERRIDE; | 169 base::WeakPtr<DownloadDestinationObserver> observer) override; |
170 | 170 |
171 void AddRenameCallback(base::Closure callback); | 171 void AddRenameCallback(base::Closure callback); |
172 void GetAllRenameCallbacks(std::vector<base::Closure>* results); | 172 void GetAllRenameCallbacks(std::vector<base::Closure>* results); |
173 | 173 |
174 // Do not return until GetAllRenameCallbacks() will return a non-empty list. | 174 // Do not return until GetAllRenameCallbacks() will return a non-empty list. |
175 void WaitForSomeCallback(); | 175 void WaitForSomeCallback(); |
176 | 176 |
177 private: | 177 private: |
178 base::WeakPtrFactory<DownloadFileWithDelayFactory> weak_ptr_factory_; | 178 base::WeakPtrFactory<DownloadFileWithDelayFactory> weak_ptr_factory_; |
179 std::vector<base::Closure> rename_callbacks_; | 179 std::vector<base::Closure> rename_callbacks_; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 base::WeakPtr<DownloadDestinationObserver> observer) | 290 base::WeakPtr<DownloadDestinationObserver> observer) |
291 : DownloadFileImpl(save_info.Pass(), default_downloads_directory, | 291 : DownloadFileImpl(save_info.Pass(), default_downloads_directory, |
292 url, referrer_url, calculate_hash, | 292 url, referrer_url, calculate_hash, |
293 stream.Pass(), bound_net_log, observer) {} | 293 stream.Pass(), bound_net_log, observer) {} |
294 | 294 |
295 virtual ~CountingDownloadFile() { | 295 virtual ~CountingDownloadFile() { |
296 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 296 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
297 active_files_--; | 297 active_files_--; |
298 } | 298 } |
299 | 299 |
300 virtual void Initialize(const InitializeCallback& callback) OVERRIDE { | 300 virtual void Initialize(const InitializeCallback& callback) override { |
301 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 301 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
302 active_files_++; | 302 active_files_++; |
303 return DownloadFileImpl::Initialize(callback); | 303 return DownloadFileImpl::Initialize(callback); |
304 } | 304 } |
305 | 305 |
306 static void GetNumberActiveFiles(int* result) { | 306 static void GetNumberActiveFiles(int* result) { |
307 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 307 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
308 *result = active_files_; | 308 *result = active_files_; |
309 } | 309 } |
310 | 310 |
(...skipping 24 matching lines...) Expand all Loading... |
335 | 335 |
336 // DownloadFileFactory interface. | 336 // DownloadFileFactory interface. |
337 virtual DownloadFile* CreateFile( | 337 virtual DownloadFile* CreateFile( |
338 scoped_ptr<DownloadSaveInfo> save_info, | 338 scoped_ptr<DownloadSaveInfo> save_info, |
339 const base::FilePath& default_downloads_directory, | 339 const base::FilePath& default_downloads_directory, |
340 const GURL& url, | 340 const GURL& url, |
341 const GURL& referrer_url, | 341 const GURL& referrer_url, |
342 bool calculate_hash, | 342 bool calculate_hash, |
343 scoped_ptr<ByteStreamReader> stream, | 343 scoped_ptr<ByteStreamReader> stream, |
344 const net::BoundNetLog& bound_net_log, | 344 const net::BoundNetLog& bound_net_log, |
345 base::WeakPtr<DownloadDestinationObserver> observer) OVERRIDE { | 345 base::WeakPtr<DownloadDestinationObserver> observer) override { |
346 scoped_ptr<PowerSaveBlocker> psb( | 346 scoped_ptr<PowerSaveBlocker> psb( |
347 PowerSaveBlocker::Create( | 347 PowerSaveBlocker::Create( |
348 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, | 348 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, |
349 "Download in progress")); | 349 "Download in progress")); |
350 return new CountingDownloadFile( | 350 return new CountingDownloadFile( |
351 save_info.Pass(), default_downloads_directory, url, referrer_url, | 351 save_info.Pass(), default_downloads_directory, url, referrer_url, |
352 calculate_hash, stream.Pass(), bound_net_log, | 352 calculate_hash, stream.Pass(), bound_net_log, |
353 psb.Pass(), observer); | 353 psb.Pass(), observer); |
354 } | 354 } |
355 }; | 355 }; |
356 | 356 |
357 class TestShellDownloadManagerDelegate : public ShellDownloadManagerDelegate { | 357 class TestShellDownloadManagerDelegate : public ShellDownloadManagerDelegate { |
358 public: | 358 public: |
359 TestShellDownloadManagerDelegate() | 359 TestShellDownloadManagerDelegate() |
360 : delay_download_open_(false) {} | 360 : delay_download_open_(false) {} |
361 virtual ~TestShellDownloadManagerDelegate() {} | 361 virtual ~TestShellDownloadManagerDelegate() {} |
362 | 362 |
363 virtual bool ShouldOpenDownload( | 363 virtual bool ShouldOpenDownload( |
364 DownloadItem* item, | 364 DownloadItem* item, |
365 const DownloadOpenDelayedCallback& callback) OVERRIDE { | 365 const DownloadOpenDelayedCallback& callback) override { |
366 if (delay_download_open_) { | 366 if (delay_download_open_) { |
367 delayed_callbacks_.push_back(callback); | 367 delayed_callbacks_.push_back(callback); |
368 return false; | 368 return false; |
369 } | 369 } |
370 return true; | 370 return true; |
371 } | 371 } |
372 | 372 |
373 void SetDelayedOpen(bool delay) { | 373 void SetDelayedOpen(bool delay) { |
374 delay_download_open_ = delay; | 374 delay_download_open_ = delay; |
375 } | 375 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 EXPECT_EQ(size, record_.size()); | 408 EXPECT_EQ(size, record_.size()); |
409 int min = size > record_.size() ? record_.size() : size; | 409 int min = size > record_.size() ? record_.size() : size; |
410 for (int i = 0; i < min; ++i) { | 410 for (int i = 0; i < min; ++i) { |
411 EXPECT_EQ(expected[i].state, record_[i].state) << "Iteration " << i; | 411 EXPECT_EQ(expected[i].state, record_[i].state) << "Iteration " << i; |
412 EXPECT_EQ(expected[i].bytes_received, record_[i].bytes_received) | 412 EXPECT_EQ(expected[i].bytes_received, record_[i].bytes_received) |
413 << "Iteration " << i; | 413 << "Iteration " << i; |
414 } | 414 } |
415 } | 415 } |
416 | 416 |
417 private: | 417 private: |
418 virtual void OnDownloadUpdated(DownloadItem* download) OVERRIDE { | 418 virtual void OnDownloadUpdated(DownloadItem* download) override { |
419 DCHECK_EQ(download_, download); | 419 DCHECK_EQ(download_, download); |
420 DownloadItem::DownloadState state = download->GetState(); | 420 DownloadItem::DownloadState state = download->GetState(); |
421 int bytes = download->GetReceivedBytes(); | 421 int bytes = download->GetReceivedBytes(); |
422 if (last_state_.state != state || last_state_.bytes_received > bytes) { | 422 if (last_state_.state != state || last_state_.bytes_received > bytes) { |
423 last_state_.state = state; | 423 last_state_.state = state; |
424 last_state_.bytes_received = bytes; | 424 last_state_.bytes_received = bytes; |
425 record_.push_back(last_state_); | 425 record_.push_back(last_state_); |
426 } | 426 } |
427 } | 427 } |
428 | 428 |
429 virtual void OnDownloadDestroyed(DownloadItem* download) OVERRIDE { | 429 virtual void OnDownloadDestroyed(DownloadItem* download) override { |
430 DCHECK_EQ(download_, download); | 430 DCHECK_EQ(download_, download); |
431 RemoveObserver(); | 431 RemoveObserver(); |
432 } | 432 } |
433 | 433 |
434 void RemoveObserver() { | 434 void RemoveObserver() { |
435 if (download_) { | 435 if (download_) { |
436 download_->RemoveObserver(this); | 436 download_->RemoveObserver(this); |
437 download_ = NULL; | 437 download_ = NULL; |
438 } | 438 } |
439 } | 439 } |
(...skipping 12 matching lines...) Expand all Loading... |
452 waiting_(false) { | 452 waiting_(false) { |
453 manager_->AddObserver(this); | 453 manager_->AddObserver(this); |
454 } | 454 } |
455 | 455 |
456 virtual ~DownloadCreateObserver() { | 456 virtual ~DownloadCreateObserver() { |
457 if (manager_) | 457 if (manager_) |
458 manager_->RemoveObserver(this); | 458 manager_->RemoveObserver(this); |
459 manager_ = NULL; | 459 manager_ = NULL; |
460 } | 460 } |
461 | 461 |
462 virtual void ManagerGoingDown(DownloadManager* manager) OVERRIDE { | 462 virtual void ManagerGoingDown(DownloadManager* manager) override { |
463 DCHECK_EQ(manager_, manager); | 463 DCHECK_EQ(manager_, manager); |
464 manager_->RemoveObserver(this); | 464 manager_->RemoveObserver(this); |
465 manager_ = NULL; | 465 manager_ = NULL; |
466 } | 466 } |
467 | 467 |
468 virtual void OnDownloadCreated(DownloadManager* manager, | 468 virtual void OnDownloadCreated(DownloadManager* manager, |
469 DownloadItem* download) OVERRIDE { | 469 DownloadItem* download) override { |
470 if (!item_) | 470 if (!item_) |
471 item_ = download; | 471 item_ = download; |
472 | 472 |
473 if (waiting_) | 473 if (waiting_) |
474 base::MessageLoopForUI::current()->Quit(); | 474 base::MessageLoopForUI::current()->Quit(); |
475 } | 475 } |
476 | 476 |
477 DownloadItem* WaitForFinished() { | 477 DownloadItem* WaitForFinished() { |
478 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 478 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
479 if (!item_) { | 479 if (!item_) { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 // help up by buffering in the underlying downloads ByteStream data | 567 // help up by buffering in the underlying downloads ByteStream data |
568 // transfer. This is important because on resumption tests we wait | 568 // transfer. This is important because on resumption tests we wait |
569 // until we've gotten the data we expect before allowing the test server | 569 // until we've gotten the data we expect before allowing the test server |
570 // to send its reset, to get around hard close semantics on the Windows | 570 // to send its reset, to get around hard close semantics on the Windows |
571 // socket layer implementation. | 571 // socket layer implementation. |
572 int GetSafeBufferChunk() const { | 572 int GetSafeBufferChunk() const { |
573 return (DownloadResourceHandler::kDownloadByteStreamSize / | 573 return (DownloadResourceHandler::kDownloadByteStreamSize / |
574 ByteStreamWriter::kFractionBufferBeforeSending) + 1; | 574 ByteStreamWriter::kFractionBufferBeforeSending) + 1; |
575 } | 575 } |
576 | 576 |
577 virtual void SetUpOnMainThread() OVERRIDE { | 577 virtual void SetUpOnMainThread() override { |
578 ASSERT_TRUE(downloads_directory_.CreateUniqueTempDir()); | 578 ASSERT_TRUE(downloads_directory_.CreateUniqueTempDir()); |
579 | 579 |
580 test_delegate_.reset(new TestShellDownloadManagerDelegate()); | 580 test_delegate_.reset(new TestShellDownloadManagerDelegate()); |
581 test_delegate_->SetDownloadBehaviorForTesting(downloads_directory_.path()); | 581 test_delegate_->SetDownloadBehaviorForTesting(downloads_directory_.path()); |
582 DownloadManager* manager = DownloadManagerForShell(shell()); | 582 DownloadManager* manager = DownloadManagerForShell(shell()); |
583 manager->GetDelegate()->Shutdown(); | 583 manager->GetDelegate()->Shutdown(); |
584 manager->SetDelegate(test_delegate_.get()); | 584 manager->SetDelegate(test_delegate_.get()); |
585 test_delegate_->SetDownloadManager(manager); | 585 test_delegate_->SetDownloadManager(manager); |
586 | 586 |
587 BrowserThread::PostTask( | 587 BrowserThread::PostTask( |
(...skipping 1226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1814 ASSERT_TRUE(test_server.InitializeAndWaitUntilReady()); | 1814 ASSERT_TRUE(test_server.InitializeAndWaitUntilReady()); |
1815 | 1815 |
1816 GURL url = test_server.GetURL("/empty.bin"); | 1816 GURL url = test_server.GetURL("/empty.bin"); |
1817 test_server.ServeFilesFromDirectory(GetTestFilePath("download", "")); | 1817 test_server.ServeFilesFromDirectory(GetTestFilePath("download", "")); |
1818 | 1818 |
1819 NavigateToURLAndWaitForDownload(shell(), url, DownloadItem::COMPLETE); | 1819 NavigateToURLAndWaitForDownload(shell(), url, DownloadItem::COMPLETE); |
1820 // That's it. This should work without crashing. | 1820 // That's it. This should work without crashing. |
1821 } | 1821 } |
1822 | 1822 |
1823 } // namespace content | 1823 } // namespace content |
OLD | NEW |