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 #include <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 | 64 |
65 void DownloadTestObserver::Init() { | 65 void DownloadTestObserver::Init() { |
66 download_manager_->AddObserver(this); // Will call initial ModelChanged(). | 66 download_manager_->AddObserver(this); // Will call initial ModelChanged(). |
67 finished_downloads_at_construction_ = finished_downloads_.size(); | 67 finished_downloads_at_construction_ = finished_downloads_.size(); |
68 states_observed_.clear(); | 68 states_observed_.clear(); |
69 } | 69 } |
70 | 70 |
71 void DownloadTestObserver::WaitForFinished() { | 71 void DownloadTestObserver::WaitForFinished() { |
72 if (!IsFinished()) { | 72 if (!IsFinished()) { |
73 waiting_ = true; | 73 waiting_ = true; |
74 ui_test_utils::RunMessageLoop(); | 74 content::RunMessageLoop(); |
75 waiting_ = false; | 75 waiting_ = false; |
76 } | 76 } |
77 } | 77 } |
78 | 78 |
79 bool DownloadTestObserver::IsFinished() const { | 79 bool DownloadTestObserver::IsFinished() const { |
80 if (finished_downloads_.size() - finished_downloads_at_construction_ >= | 80 if (finished_downloads_.size() - finished_downloads_at_construction_ >= |
81 wait_count_) | 81 wait_count_) |
82 return true; | 82 return true; |
83 return (finish_on_select_file_ && select_file_dialog_seen_); | 83 return (finish_on_select_file_ && select_file_dialog_seen_); |
84 } | 84 } |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 } | 262 } |
263 | 263 |
264 DownloadTestFlushObserver::DownloadTestFlushObserver( | 264 DownloadTestFlushObserver::DownloadTestFlushObserver( |
265 DownloadManager* download_manager) | 265 DownloadManager* download_manager) |
266 : download_manager_(download_manager), | 266 : download_manager_(download_manager), |
267 waiting_for_zero_inprogress_(true) {} | 267 waiting_for_zero_inprogress_(true) {} |
268 | 268 |
269 void DownloadTestFlushObserver::WaitForFlush() { | 269 void DownloadTestFlushObserver::WaitForFlush() { |
270 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 270 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
271 download_manager_->AddObserver(this); | 271 download_manager_->AddObserver(this); |
272 ui_test_utils::RunMessageLoop(); | 272 content::RunMessageLoop(); |
273 } | 273 } |
274 | 274 |
275 void DownloadTestFlushObserver::ModelChanged(DownloadManager* manager) { | 275 void DownloadTestFlushObserver::ModelChanged(DownloadManager* manager) { |
276 // Model has changed, so there may be more DownloadItems to observe. | 276 // Model has changed, so there may be more DownloadItems to observe. |
277 CheckDownloadsInProgress(true); | 277 CheckDownloadsInProgress(true); |
278 } | 278 } |
279 | 279 |
280 void DownloadTestFlushObserver::OnDownloadUpdated(DownloadItem* download) { | 280 void DownloadTestFlushObserver::OnDownloadUpdated(DownloadItem* download) { |
281 // The REMOVING state indicates that the download is being destroyed. | 281 // The REMOVING state indicates that the download is being destroyed. |
282 // Stop observing. Do not do anything with it, as it is about to be gone. | 282 // Stop observing. Do not do anything with it, as it is about to be gone. |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 } | 370 } |
371 | 371 |
372 DownloadTestItemCreationObserver::~DownloadTestItemCreationObserver() { | 372 DownloadTestItemCreationObserver::~DownloadTestItemCreationObserver() { |
373 } | 373 } |
374 | 374 |
375 void DownloadTestItemCreationObserver::WaitForDownloadItemCreation() { | 375 void DownloadTestItemCreationObserver::WaitForDownloadItemCreation() { |
376 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 376 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
377 | 377 |
378 if (called_back_count_ == 0) { | 378 if (called_back_count_ == 0) { |
379 waiting_ = true; | 379 waiting_ = true; |
380 ui_test_utils::RunMessageLoop(); | 380 content::RunMessageLoop(); |
381 waiting_ = false; | 381 waiting_ = false; |
382 } | 382 } |
383 } | 383 } |
384 | 384 |
385 void DownloadTestItemCreationObserver::DownloadItemCreationCallback( | 385 void DownloadTestItemCreationObserver::DownloadItemCreationCallback( |
386 content::DownloadId download_id, net::Error error) { | 386 content::DownloadId download_id, net::Error error) { |
387 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 387 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
388 | 388 |
389 download_id_ = download_id; | 389 download_id_ = download_id; |
390 error_ = error; | 390 error_ = error; |
391 ++called_back_count_; | 391 ++called_back_count_; |
392 DCHECK_EQ(1u, called_back_count_); | 392 DCHECK_EQ(1u, called_back_count_); |
393 | 393 |
394 if (waiting_) | 394 if (waiting_) |
395 MessageLoopForUI::current()->Quit(); | 395 MessageLoopForUI::current()->Quit(); |
396 } | 396 } |
397 | 397 |
398 const content::DownloadUrlParameters::OnStartedCallback | 398 const content::DownloadUrlParameters::OnStartedCallback |
399 DownloadTestItemCreationObserver::callback() { | 399 DownloadTestItemCreationObserver::callback() { |
400 return base::Bind( | 400 return base::Bind( |
401 &DownloadTestItemCreationObserver::DownloadItemCreationCallback, this); | 401 &DownloadTestItemCreationObserver::DownloadItemCreationCallback, this); |
402 } | 402 } |
403 | 403 |
OLD | NEW |