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

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

Issue 12213066: Use base namespace for FilePath in content/browser (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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
« no previous file with comments | « content/browser/download/base_file_win.cc ('k') | content/browser/download/download_file.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 // 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_path.h" 9 #include "base/file_path.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 // is a DownloadManagerImpl. 72 // is a DownloadManagerImpl.
73 return static_cast<DownloadManagerImpl*>( 73 return static_cast<DownloadManagerImpl*>(
74 BrowserContext::GetDownloadManager( 74 BrowserContext::GetDownloadManager(
75 shell->web_contents()->GetBrowserContext())); 75 shell->web_contents()->GetBrowserContext()));
76 } 76 }
77 77
78 class DownloadFileWithDelay : public DownloadFileImpl { 78 class DownloadFileWithDelay : public DownloadFileImpl {
79 public: 79 public:
80 DownloadFileWithDelay( 80 DownloadFileWithDelay(
81 scoped_ptr<DownloadSaveInfo> save_info, 81 scoped_ptr<DownloadSaveInfo> save_info,
82 const FilePath& default_download_directory, 82 const base::FilePath& default_download_directory,
83 const GURL& url, 83 const GURL& url,
84 const GURL& referrer_url, 84 const GURL& referrer_url,
85 bool calculate_hash, 85 bool calculate_hash,
86 scoped_ptr<ByteStreamReader> stream, 86 scoped_ptr<ByteStreamReader> stream,
87 const net::BoundNetLog& bound_net_log, 87 const net::BoundNetLog& bound_net_log,
88 scoped_ptr<PowerSaveBlocker> power_save_blocker, 88 scoped_ptr<PowerSaveBlocker> power_save_blocker,
89 base::WeakPtr<DownloadDestinationObserver> observer, 89 base::WeakPtr<DownloadDestinationObserver> observer,
90 base::WeakPtr<DownloadFileWithDelayFactory> owner); 90 base::WeakPtr<DownloadFileWithDelayFactory> owner);
91 91
92 virtual ~DownloadFileWithDelay(); 92 virtual ~DownloadFileWithDelay();
93 93
94 // Wraps DownloadFileImpl::Rename* and intercepts the return callback, 94 // Wraps DownloadFileImpl::Rename* and intercepts the return callback,
95 // storing it in the factory that produced this object for later 95 // storing it in the factory that produced this object for later
96 // retrieval. 96 // retrieval.
97 virtual void RenameAndUniquify( 97 virtual void RenameAndUniquify(
98 const FilePath& full_path, 98 const base::FilePath& full_path,
99 const RenameCompletionCallback& callback) OVERRIDE; 99 const RenameCompletionCallback& callback) OVERRIDE;
100 virtual void RenameAndAnnotate( 100 virtual void RenameAndAnnotate(
101 const FilePath& full_path, 101 const base::FilePath& full_path,
102 const RenameCompletionCallback& callback) OVERRIDE; 102 const RenameCompletionCallback& callback) OVERRIDE;
103 103
104 private: 104 private:
105 static void RenameCallbackWrapper( 105 static void RenameCallbackWrapper(
106 DownloadFileWithDelayFactory* factory, 106 DownloadFileWithDelayFactory* factory,
107 const RenameCompletionCallback& original_callback, 107 const RenameCompletionCallback& original_callback,
108 DownloadInterruptReason reason, 108 DownloadInterruptReason reason,
109 const FilePath& path); 109 const base::FilePath& path);
110 110
111 // This variable may only be read on the FILE thread, and may only be 111 // This variable may only be read on the FILE thread, and may only be
112 // indirected through (e.g. methods on DownloadFileWithDelayFactory called) 112 // indirected through (e.g. methods on DownloadFileWithDelayFactory called)
113 // on the UI thread. This is because after construction, 113 // on the UI thread. This is because after construction,
114 // DownloadFileWithDelay lives on the file thread, but 114 // DownloadFileWithDelay lives on the file thread, but
115 // DownloadFileWithDelayFactory is purely a UI thread object. 115 // DownloadFileWithDelayFactory is purely a UI thread object.
116 base::WeakPtr<DownloadFileWithDelayFactory> owner_; 116 base::WeakPtr<DownloadFileWithDelayFactory> owner_;
117 117
118 DISALLOW_COPY_AND_ASSIGN(DownloadFileWithDelay); 118 DISALLOW_COPY_AND_ASSIGN(DownloadFileWithDelay);
119 }; 119 };
120 120
121 // All routines on this class must be called on the UI thread. 121 // All routines on this class must be called on the UI thread.
122 class DownloadFileWithDelayFactory : public DownloadFileFactory { 122 class DownloadFileWithDelayFactory : public DownloadFileFactory {
123 public: 123 public:
124 DownloadFileWithDelayFactory(); 124 DownloadFileWithDelayFactory();
125 virtual ~DownloadFileWithDelayFactory(); 125 virtual ~DownloadFileWithDelayFactory();
126 126
127 // DownloadFileFactory interface. 127 // DownloadFileFactory interface.
128 virtual DownloadFile* CreateFile( 128 virtual DownloadFile* CreateFile(
129 scoped_ptr<DownloadSaveInfo> save_info, 129 scoped_ptr<DownloadSaveInfo> save_info,
130 const FilePath& default_download_directory, 130 const base::FilePath& default_download_directory,
131 const GURL& url, 131 const GURL& url,
132 const GURL& referrer_url, 132 const GURL& referrer_url,
133 bool calculate_hash, 133 bool calculate_hash,
134 scoped_ptr<ByteStreamReader> stream, 134 scoped_ptr<ByteStreamReader> stream,
135 const net::BoundNetLog& bound_net_log, 135 const net::BoundNetLog& bound_net_log,
136 base::WeakPtr<DownloadDestinationObserver> observer) OVERRIDE; 136 base::WeakPtr<DownloadDestinationObserver> observer) OVERRIDE;
137 137
138 void AddRenameCallback(base::Closure callback); 138 void AddRenameCallback(base::Closure callback);
139 void GetAllRenameCallbacks(std::vector<base::Closure>* results); 139 void GetAllRenameCallbacks(std::vector<base::Closure>* results);
140 140
141 // Do not return until GetAllRenameCallbacks() will return a non-empty list. 141 // Do not return until GetAllRenameCallbacks() will return a non-empty list.
142 void WaitForSomeCallback(); 142 void WaitForSomeCallback();
143 143
144 private: 144 private:
145 base::WeakPtrFactory<DownloadFileWithDelayFactory> weak_ptr_factory_; 145 base::WeakPtrFactory<DownloadFileWithDelayFactory> weak_ptr_factory_;
146 std::vector<base::Closure> rename_callbacks_; 146 std::vector<base::Closure> rename_callbacks_;
147 bool waiting_; 147 bool waiting_;
148 148
149 DISALLOW_COPY_AND_ASSIGN(DownloadFileWithDelayFactory); 149 DISALLOW_COPY_AND_ASSIGN(DownloadFileWithDelayFactory);
150 }; 150 };
151 151
152 DownloadFileWithDelay::DownloadFileWithDelay( 152 DownloadFileWithDelay::DownloadFileWithDelay(
153 scoped_ptr<DownloadSaveInfo> save_info, 153 scoped_ptr<DownloadSaveInfo> save_info,
154 const FilePath& default_download_directory, 154 const base::FilePath& default_download_directory,
155 const GURL& url, 155 const GURL& url,
156 const GURL& referrer_url, 156 const GURL& referrer_url,
157 bool calculate_hash, 157 bool calculate_hash,
158 scoped_ptr<ByteStreamReader> stream, 158 scoped_ptr<ByteStreamReader> stream,
159 const net::BoundNetLog& bound_net_log, 159 const net::BoundNetLog& bound_net_log,
160 scoped_ptr<PowerSaveBlocker> power_save_blocker, 160 scoped_ptr<PowerSaveBlocker> power_save_blocker,
161 base::WeakPtr<DownloadDestinationObserver> observer, 161 base::WeakPtr<DownloadDestinationObserver> observer,
162 base::WeakPtr<DownloadFileWithDelayFactory> owner) 162 base::WeakPtr<DownloadFileWithDelayFactory> owner)
163 : DownloadFileImpl( 163 : DownloadFileImpl(
164 save_info.Pass(), default_download_directory, url, referrer_url, 164 save_info.Pass(), default_download_directory, url, referrer_url,
165 calculate_hash, stream.Pass(), bound_net_log, 165 calculate_hash, stream.Pass(), bound_net_log,
166 power_save_blocker.Pass(), observer), 166 power_save_blocker.Pass(), observer),
167 owner_(owner) {} 167 owner_(owner) {}
168 168
169 DownloadFileWithDelay::~DownloadFileWithDelay() {} 169 DownloadFileWithDelay::~DownloadFileWithDelay() {}
170 170
171 void DownloadFileWithDelay::RenameAndUniquify( 171 void DownloadFileWithDelay::RenameAndUniquify(
172 const FilePath& full_path, const RenameCompletionCallback& callback) { 172 const base::FilePath& full_path,
173 const RenameCompletionCallback& callback) {
173 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 174 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
174 DownloadFileImpl::RenameAndUniquify( 175 DownloadFileImpl::RenameAndUniquify(
175 full_path, base::Bind(DownloadFileWithDelay::RenameCallbackWrapper, 176 full_path, base::Bind(DownloadFileWithDelay::RenameCallbackWrapper,
176 owner_, callback)); 177 owner_, callback));
177 } 178 }
178 179
179 void DownloadFileWithDelay::RenameAndAnnotate( 180 void DownloadFileWithDelay::RenameAndAnnotate(
180 const FilePath& full_path, const RenameCompletionCallback& callback) { 181 const base::FilePath& full_path, const RenameCompletionCallback& callback) {
181 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 182 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
182 DownloadFileImpl::RenameAndAnnotate( 183 DownloadFileImpl::RenameAndAnnotate(
183 full_path, base::Bind(DownloadFileWithDelay::RenameCallbackWrapper, 184 full_path, base::Bind(DownloadFileWithDelay::RenameCallbackWrapper,
184 owner_, callback)); 185 owner_, callback));
185 } 186 }
186 187
187 // static 188 // static
188 void DownloadFileWithDelay::RenameCallbackWrapper( 189 void DownloadFileWithDelay::RenameCallbackWrapper(
189 DownloadFileWithDelayFactory* factory, 190 DownloadFileWithDelayFactory* factory,
190 const RenameCompletionCallback& original_callback, 191 const RenameCompletionCallback& original_callback,
191 DownloadInterruptReason reason, 192 DownloadInterruptReason reason,
192 const FilePath& path) { 193 const base::FilePath& path) {
193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 194 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
194 factory->AddRenameCallback(base::Bind(original_callback, reason, path)); 195 factory->AddRenameCallback(base::Bind(original_callback, reason, path));
195 } 196 }
196 197
197 DownloadFileWithDelayFactory::DownloadFileWithDelayFactory() 198 DownloadFileWithDelayFactory::DownloadFileWithDelayFactory()
198 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 199 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
199 waiting_(false) {} 200 waiting_(false) {}
200 DownloadFileWithDelayFactory::~DownloadFileWithDelayFactory() {} 201 DownloadFileWithDelayFactory::~DownloadFileWithDelayFactory() {}
201 202
202 DownloadFile* DownloadFileWithDelayFactory::CreateFile( 203 DownloadFile* DownloadFileWithDelayFactory::CreateFile(
203 scoped_ptr<DownloadSaveInfo> save_info, 204 scoped_ptr<DownloadSaveInfo> save_info,
204 const FilePath& default_download_directory, 205 const base::FilePath& default_download_directory,
205 const GURL& url, 206 const GURL& url,
206 const GURL& referrer_url, 207 const GURL& referrer_url,
207 bool calculate_hash, 208 bool calculate_hash,
208 scoped_ptr<ByteStreamReader> stream, 209 scoped_ptr<ByteStreamReader> stream,
209 const net::BoundNetLog& bound_net_log, 210 const net::BoundNetLog& bound_net_log,
210 base::WeakPtr<DownloadDestinationObserver> observer) { 211 base::WeakPtr<DownloadDestinationObserver> observer) {
211 scoped_ptr<PowerSaveBlocker> psb( 212 scoped_ptr<PowerSaveBlocker> psb(
212 PowerSaveBlocker::Create( 213 PowerSaveBlocker::Create(
213 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, 214 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
214 "Download in progress")); 215 "Download in progress"));
(...skipping 23 matching lines...) Expand all
238 waiting_ = true; 239 waiting_ = true;
239 RunMessageLoop(); 240 RunMessageLoop();
240 waiting_ = false; 241 waiting_ = false;
241 } 242 }
242 } 243 }
243 244
244 class CountingDownloadFile : public DownloadFileImpl { 245 class CountingDownloadFile : public DownloadFileImpl {
245 public: 246 public:
246 CountingDownloadFile( 247 CountingDownloadFile(
247 scoped_ptr<DownloadSaveInfo> save_info, 248 scoped_ptr<DownloadSaveInfo> save_info,
248 const FilePath& default_downloads_directory, 249 const base::FilePath& default_downloads_directory,
249 const GURL& url, 250 const GURL& url,
250 const GURL& referrer_url, 251 const GURL& referrer_url,
251 bool calculate_hash, 252 bool calculate_hash,
252 scoped_ptr<ByteStreamReader> stream, 253 scoped_ptr<ByteStreamReader> stream,
253 const net::BoundNetLog& bound_net_log, 254 const net::BoundNetLog& bound_net_log,
254 scoped_ptr<PowerSaveBlocker> power_save_blocker, 255 scoped_ptr<PowerSaveBlocker> power_save_blocker,
255 base::WeakPtr<DownloadDestinationObserver> observer) 256 base::WeakPtr<DownloadDestinationObserver> observer)
256 : DownloadFileImpl(save_info.Pass(), default_downloads_directory, 257 : DownloadFileImpl(save_info.Pass(), default_downloads_directory,
257 url, referrer_url, calculate_hash, 258 url, referrer_url, calculate_hash,
258 stream.Pass(), bound_net_log, 259 stream.Pass(), bound_net_log,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 int CountingDownloadFile::active_files_ = 0; 294 int CountingDownloadFile::active_files_ = 0;
294 295
295 class CountingDownloadFileFactory : public DownloadFileFactory { 296 class CountingDownloadFileFactory : public DownloadFileFactory {
296 public: 297 public:
297 CountingDownloadFileFactory() {} 298 CountingDownloadFileFactory() {}
298 virtual ~CountingDownloadFileFactory() {} 299 virtual ~CountingDownloadFileFactory() {}
299 300
300 // DownloadFileFactory interface. 301 // DownloadFileFactory interface.
301 virtual DownloadFile* CreateFile( 302 virtual DownloadFile* CreateFile(
302 scoped_ptr<DownloadSaveInfo> save_info, 303 scoped_ptr<DownloadSaveInfo> save_info,
303 const FilePath& default_downloads_directory, 304 const base::FilePath& default_downloads_directory,
304 const GURL& url, 305 const GURL& url,
305 const GURL& referrer_url, 306 const GURL& referrer_url,
306 bool calculate_hash, 307 bool calculate_hash,
307 scoped_ptr<ByteStreamReader> stream, 308 scoped_ptr<ByteStreamReader> stream,
308 const net::BoundNetLog& bound_net_log, 309 const net::BoundNetLog& bound_net_log,
309 base::WeakPtr<DownloadDestinationObserver> observer) OVERRIDE { 310 base::WeakPtr<DownloadDestinationObserver> observer) OVERRIDE {
310 scoped_ptr<PowerSaveBlocker> psb( 311 scoped_ptr<PowerSaveBlocker> psb(
311 PowerSaveBlocker::Create( 312 PowerSaveBlocker::Create(
312 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, 313 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension,
313 "Download in progress")); 314 "Download in progress"));
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 TestShellDownloadManagerDelegate* delegate = 387 TestShellDownloadManagerDelegate* delegate =
387 new TestShellDownloadManagerDelegate(); 388 new TestShellDownloadManagerDelegate();
388 delegate->SetDownloadBehaviorForTesting(downloads_directory_.path()); 389 delegate->SetDownloadBehaviorForTesting(downloads_directory_.path());
389 DownloadManager* manager = DownloadManagerForShell(shell()); 390 DownloadManager* manager = DownloadManagerForShell(shell());
390 manager->SetDelegate(delegate); 391 manager->SetDelegate(delegate);
391 delegate->SetDownloadManager(manager); 392 delegate->SetDownloadManager(manager);
392 393
393 BrowserThread::PostTask( 394 BrowserThread::PostTask(
394 BrowserThread::IO, FROM_HERE, 395 BrowserThread::IO, FROM_HERE,
395 base::Bind(&URLRequestSlowDownloadJob::AddUrlHandler)); 396 base::Bind(&URLRequestSlowDownloadJob::AddUrlHandler));
396 FilePath mock_base(GetTestFilePath("download", "")); 397 base::FilePath mock_base(GetTestFilePath("download", ""));
397 BrowserThread::PostTask( 398 BrowserThread::PostTask(
398 BrowserThread::IO, FROM_HERE, 399 BrowserThread::IO, FROM_HERE,
399 base::Bind(&URLRequestMockHTTPJob::AddUrlHandler, mock_base)); 400 base::Bind(&URLRequestMockHTTPJob::AddUrlHandler, mock_base));
400 } 401 }
401 402
402 TestShellDownloadManagerDelegate* GetDownloadManagerDelegate( 403 TestShellDownloadManagerDelegate* GetDownloadManagerDelegate(
403 DownloadManager* manager) { 404 DownloadManager* manager) {
404 return static_cast<TestShellDownloadManagerDelegate*>( 405 return static_cast<TestShellDownloadManagerDelegate*>(
405 manager->GetDelegate()); 406 manager->GetDelegate());
406 } 407 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 void DownloadAndWait(Shell* shell, const GURL& url, 443 void DownloadAndWait(Shell* shell, const GURL& url,
443 DownloadItem::DownloadState expected_terminal_state) { 444 DownloadItem::DownloadState expected_terminal_state) {
444 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(shell, 1)); 445 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(shell, 1));
445 NavigateToURL(shell, url); 446 NavigateToURL(shell, url);
446 observer->WaitForFinished(); 447 observer->WaitForFinished();
447 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(expected_terminal_state)); 448 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(expected_terminal_state));
448 } 449 }
449 450
450 // Checks that |path| is has |file_size| bytes, and matches the |value| 451 // Checks that |path| is has |file_size| bytes, and matches the |value|
451 // string. 452 // string.
452 bool VerifyFile(const FilePath& path, 453 bool VerifyFile(const base::FilePath& path,
453 const std::string& value, 454 const std::string& value,
454 const int64 file_size) { 455 const int64 file_size) {
455 std::string file_contents; 456 std::string file_contents;
456 457
457 bool read = file_util::ReadFileToString(path, &file_contents); 458 bool read = file_util::ReadFileToString(path, &file_contents);
458 EXPECT_TRUE(read) << "Failed reading file: " << path.value() << std::endl; 459 EXPECT_TRUE(read) << "Failed reading file: " << path.value() << std::endl;
459 if (!read) 460 if (!read)
460 return false; // Couldn't read the file. 461 return false; // Couldn't read the file.
461 462
462 // Note: we don't handle really large files (more than size_t can hold) 463 // Note: we don't handle really large files (more than size_t can hold)
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 NavigateToURL(shell(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); 525 NavigateToURL(shell(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl));
525 observer1->WaitForFinished(); 526 observer1->WaitForFinished();
526 527
527 std::vector<DownloadItem*> downloads; 528 std::vector<DownloadItem*> downloads;
528 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); 529 DownloadManagerForShell(shell())->GetAllDownloads(&downloads);
529 ASSERT_EQ(1u, downloads.size()); 530 ASSERT_EQ(1u, downloads.size());
530 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->GetState()); 531 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->GetState());
531 DownloadItem* download1 = downloads[0]; // The only download. 532 DownloadItem* download1 = downloads[0]; // The only download.
532 533
533 // Start the second download and wait until it's done. 534 // Start the second download and wait until it's done.
534 FilePath file(FILE_PATH_LITERAL("download-test.lib")); 535 base::FilePath file(FILE_PATH_LITERAL("download-test.lib"));
535 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 536 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
536 // Download the file and wait. 537 // Download the file and wait.
537 DownloadAndWait(shell(), url, DownloadItem::COMPLETE); 538 DownloadAndWait(shell(), url, DownloadItem::COMPLETE);
538 539
539 // Should now have 2 items on the manager. 540 // Should now have 2 items on the manager.
540 downloads.clear(); 541 downloads.clear();
541 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); 542 DownloadManagerForShell(shell())->GetAllDownloads(&downloads);
542 ASSERT_EQ(2u, downloads.size()); 543 ASSERT_EQ(2u, downloads.size());
543 // We don't know the order of the downloads. 544 // We don't know the order of the downloads.
544 DownloadItem* download2 = downloads[(download1 == downloads[0]) ? 1 : 0]; 545 DownloadItem* download2 = downloads[(download1 == downloads[0]) ? 1 : 0];
545 546
546 ASSERT_EQ(DownloadItem::IN_PROGRESS, download1->GetState()); 547 ASSERT_EQ(DownloadItem::IN_PROGRESS, download1->GetState());
547 ASSERT_EQ(DownloadItem::COMPLETE, download2->GetState()); 548 ASSERT_EQ(DownloadItem::COMPLETE, download2->GetState());
548 549
549 // Allow the first request to finish. 550 // Allow the first request to finish.
550 scoped_ptr<DownloadTestObserver> observer2(CreateWaiter(shell(), 1)); 551 scoped_ptr<DownloadTestObserver> observer2(CreateWaiter(shell(), 1));
551 NavigateToURL(shell(), GURL(URLRequestSlowDownloadJob::kFinishDownloadUrl)); 552 NavigateToURL(shell(), GURL(URLRequestSlowDownloadJob::kFinishDownloadUrl));
552 observer2->WaitForFinished(); // Wait for the third request. 553 observer2->WaitForFinished(); // Wait for the third request.
553 EXPECT_EQ(1u, observer2->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 554 EXPECT_EQ(1u, observer2->NumDownloadsSeenInState(DownloadItem::COMPLETE));
554 555
555 // Get the important info from other threads and check it. 556 // Get the important info from other threads and check it.
556 EXPECT_TRUE(EnsureNoPendingDownloads()); 557 EXPECT_TRUE(EnsureNoPendingDownloads());
557 558
558 // The |DownloadItem|s should now be done and have the final file names. 559 // The |DownloadItem|s should now be done and have the final file names.
559 // Verify that the files have the expected data and size. 560 // Verify that the files have the expected data and size.
560 // |file1| should be full of '*'s, and |file2| should be the same as the 561 // |file1| should be full of '*'s, and |file2| should be the same as the
561 // source file. 562 // source file.
562 FilePath file1(download1->GetFullPath()); 563 base::FilePath file1(download1->GetFullPath());
563 size_t file_size1 = URLRequestSlowDownloadJob::kFirstDownloadSize + 564 size_t file_size1 = URLRequestSlowDownloadJob::kFirstDownloadSize +
564 URLRequestSlowDownloadJob::kSecondDownloadSize; 565 URLRequestSlowDownloadJob::kSecondDownloadSize;
565 std::string expected_contents(file_size1, '*'); 566 std::string expected_contents(file_size1, '*');
566 ASSERT_TRUE(VerifyFile(file1, expected_contents, file_size1)); 567 ASSERT_TRUE(VerifyFile(file1, expected_contents, file_size1));
567 568
568 FilePath file2(download2->GetFullPath()); 569 base::FilePath file2(download2->GetFullPath());
569 ASSERT_TRUE(file_util::ContentsEqual( 570 ASSERT_TRUE(file_util::ContentsEqual(
570 file2, GetTestFilePath("download", "download-test.lib"))); 571 file2, GetTestFilePath("download", "download-test.lib")));
571 } 572 }
572 573
573 // Try to cancel just before we release the download file, by delaying final 574 // Try to cancel just before we release the download file, by delaying final
574 // rename callback. 575 // rename callback.
575 IN_PROC_BROWSER_TEST_F(DownloadContentTest, CancelAtFinalRename) { 576 IN_PROC_BROWSER_TEST_F(DownloadContentTest, CancelAtFinalRename) {
576 // Setup new factory. 577 // Setup new factory.
577 DownloadFileWithDelayFactory* file_factory = 578 DownloadFileWithDelayFactory* file_factory =
578 new DownloadFileWithDelayFactory(); 579 new DownloadFileWithDelayFactory();
579 DownloadManagerImpl* download_manager(DownloadManagerForShell(shell())); 580 DownloadManagerImpl* download_manager(DownloadManagerForShell(shell()));
580 download_manager->SetDownloadFileFactoryForTesting( 581 download_manager->SetDownloadFileFactoryForTesting(
581 scoped_ptr<DownloadFileFactory>(file_factory).Pass()); 582 scoped_ptr<DownloadFileFactory>(file_factory).Pass());
582 583
583 // Create a download 584 // Create a download
584 FilePath file(FILE_PATH_LITERAL("download-test.lib")); 585 base::FilePath file(FILE_PATH_LITERAL("download-test.lib"));
585 NavigateToURL(shell(), URLRequestMockHTTPJob::GetMockUrl(file)); 586 NavigateToURL(shell(), URLRequestMockHTTPJob::GetMockUrl(file));
586 587
587 // Wait until the first (intermediate file) rename and execute the callback. 588 // Wait until the first (intermediate file) rename and execute the callback.
588 file_factory->WaitForSomeCallback(); 589 file_factory->WaitForSomeCallback();
589 std::vector<base::Closure> callbacks; 590 std::vector<base::Closure> callbacks;
590 file_factory->GetAllRenameCallbacks(&callbacks); 591 file_factory->GetAllRenameCallbacks(&callbacks);
591 ASSERT_EQ(1u, callbacks.size()); 592 ASSERT_EQ(1u, callbacks.size());
592 callbacks[0].Run(); 593 callbacks[0].Run();
593 callbacks.clear(); 594 callbacks.clear();
594 595
(...skipping 28 matching lines...) Expand all
623 // Mark delegate for delayed open. 624 // Mark delegate for delayed open.
624 GetDownloadManagerDelegate(download_manager)->SetDelayedOpen(true); 625 GetDownloadManagerDelegate(download_manager)->SetDelayedOpen(true);
625 626
626 // Setup new factory. 627 // Setup new factory.
627 DownloadFileWithDelayFactory* file_factory = 628 DownloadFileWithDelayFactory* file_factory =
628 new DownloadFileWithDelayFactory(); 629 new DownloadFileWithDelayFactory();
629 download_manager->SetDownloadFileFactoryForTesting( 630 download_manager->SetDownloadFileFactoryForTesting(
630 scoped_ptr<DownloadFileFactory>(file_factory).Pass()); 631 scoped_ptr<DownloadFileFactory>(file_factory).Pass());
631 632
632 // Create a download 633 // Create a download
633 FilePath file(FILE_PATH_LITERAL("download-test.lib")); 634 base::FilePath file(FILE_PATH_LITERAL("download-test.lib"));
634 NavigateToURL(shell(), URLRequestMockHTTPJob::GetMockUrl(file)); 635 NavigateToURL(shell(), URLRequestMockHTTPJob::GetMockUrl(file));
635 636
636 // Wait until the first (intermediate file) rename and execute the callback. 637 // Wait until the first (intermediate file) rename and execute the callback.
637 file_factory->WaitForSomeCallback(); 638 file_factory->WaitForSomeCallback();
638 std::vector<base::Closure> callbacks; 639 std::vector<base::Closure> callbacks;
639 file_factory->GetAllRenameCallbacks(&callbacks); 640 file_factory->GetAllRenameCallbacks(&callbacks);
640 ASSERT_EQ(1u, callbacks.size()); 641 ASSERT_EQ(1u, callbacks.size());
641 callbacks[0].Run(); 642 callbacks[0].Run();
642 callbacks.clear(); 643 callbacks.clear();
643 644
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 // Mark delegate for delayed open. 720 // Mark delegate for delayed open.
720 GetDownloadManagerDelegate(download_manager)->SetDelayedOpen(true); 721 GetDownloadManagerDelegate(download_manager)->SetDelayedOpen(true);
721 722
722 // Setup new factory. 723 // Setup new factory.
723 DownloadFileWithDelayFactory* file_factory = 724 DownloadFileWithDelayFactory* file_factory =
724 new DownloadFileWithDelayFactory(); 725 new DownloadFileWithDelayFactory();
725 download_manager->SetDownloadFileFactoryForTesting( 726 download_manager->SetDownloadFileFactoryForTesting(
726 scoped_ptr<DownloadFileFactory>(file_factory).Pass()); 727 scoped_ptr<DownloadFileFactory>(file_factory).Pass());
727 728
728 // Create a download 729 // Create a download
729 FilePath file(FILE_PATH_LITERAL("download-test.lib")); 730 base::FilePath file(FILE_PATH_LITERAL("download-test.lib"));
730 NavigateToURL(shell(), URLRequestMockHTTPJob::GetMockUrl(file)); 731 NavigateToURL(shell(), URLRequestMockHTTPJob::GetMockUrl(file));
731 732
732 // Wait until the first (intermediate file) rename and execute the callback. 733 // Wait until the first (intermediate file) rename and execute the callback.
733 file_factory->WaitForSomeCallback(); 734 file_factory->WaitForSomeCallback();
734 std::vector<base::Closure> callbacks; 735 std::vector<base::Closure> callbacks;
735 file_factory->GetAllRenameCallbacks(&callbacks); 736 file_factory->GetAllRenameCallbacks(&callbacks);
736 ASSERT_EQ(1u, callbacks.size()); 737 ASSERT_EQ(1u, callbacks.size());
737 callbacks[0].Run(); 738 callbacks[0].Run();
738 callbacks.clear(); 739 callbacks.clear();
739 740
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 ASSERT_TRUE(file_util::ReadFileToString( 850 ASSERT_TRUE(file_util::ReadFileToString(
850 download->GetFullPath(), &file_contents)); 851 download->GetFullPath(), &file_contents));
851 EXPECT_EQ(static_cast<size_t>(initial_chunk * 2), file_contents.size()); 852 EXPECT_EQ(static_cast<size_t>(initial_chunk * 2), file_contents.size());
852 // In conditional to avoid spamming the console with two 800 char strings. 853 // In conditional to avoid spamming the console with two 800 char strings.
853 if (expected_contents != file_contents) 854 if (expected_contents != file_contents)
854 EXPECT_TRUE(false) << "File contents do not have expected value."; 855 EXPECT_TRUE(false) << "File contents do not have expected value.";
855 } 856 }
856 } 857 }
857 858
858 } // namespace content 859 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/base_file_win.cc ('k') | content/browser/download/download_file.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698