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 <sstream> | 5 #include <sstream> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 waiting_ = true; | 138 waiting_ = true; |
139 content::RunMessageLoop(); | 139 content::RunMessageLoop(); |
140 waiting_ = false; | 140 waiting_ = false; |
141 } | 141 } |
142 | 142 |
143 private: | 143 private: |
144 void OnDownloadCreated(content::DownloadManager* manager, | 144 void OnDownloadCreated(content::DownloadManager* manager, |
145 content::DownloadItem* item) override { | 145 content::DownloadItem* item) override { |
146 DCHECK_EQ(manager_, manager); | 146 DCHECK_EQ(manager_, manager); |
147 if (waiting_) | 147 if (waiting_) |
148 base::MessageLoopForUI::current()->Quit(); | 148 base::MessageLoopForUI::current()->QuitWhenIdle(); |
149 } | 149 } |
150 | 150 |
151 content::DownloadManager* manager_; | 151 content::DownloadManager* manager_; |
152 bool waiting_; | 152 bool waiting_; |
153 | 153 |
154 DISALLOW_COPY_AND_ASSIGN(CreatedObserver); | 154 DISALLOW_COPY_AND_ASSIGN(CreatedObserver); |
155 }; | 155 }; |
156 | 156 |
157 class PercentWaiter : public content::DownloadItem::Observer { | 157 class PercentWaiter : public content::DownloadItem::Observer { |
158 public: | 158 public: |
(...skipping 21 matching lines...) Expand all Loading... |
180 | 180 |
181 private: | 181 private: |
182 void OnDownloadUpdated(content::DownloadItem* item) override { | 182 void OnDownloadUpdated(content::DownloadItem* item) override { |
183 DCHECK_EQ(item_, item); | 183 DCHECK_EQ(item_, item); |
184 if (!error_ && | 184 if (!error_ && |
185 ((prev_percent_ > item_->PercentComplete()) || | 185 ((prev_percent_ > item_->PercentComplete()) || |
186 (item_->GetState() == DownloadItem::COMPLETE && | 186 (item_->GetState() == DownloadItem::COMPLETE && |
187 (item_->PercentComplete() != 100)))) { | 187 (item_->PercentComplete() != 100)))) { |
188 error_ = true; | 188 error_ = true; |
189 if (waiting_) | 189 if (waiting_) |
190 base::MessageLoopForUI::current()->Quit(); | 190 base::MessageLoopForUI::current()->QuitWhenIdle(); |
191 } | 191 } |
192 if (item_->GetState() == DownloadItem::COMPLETE && waiting_) | 192 if (item_->GetState() == DownloadItem::COMPLETE && waiting_) |
193 base::MessageLoopForUI::current()->Quit(); | 193 base::MessageLoopForUI::current()->QuitWhenIdle(); |
194 } | 194 } |
195 | 195 |
196 void OnDownloadDestroyed(content::DownloadItem* item) override { | 196 void OnDownloadDestroyed(content::DownloadItem* item) override { |
197 DCHECK_EQ(item_, item); | 197 DCHECK_EQ(item_, item); |
198 item_->RemoveObserver(this); | 198 item_->RemoveObserver(this); |
199 item_ = NULL; | 199 item_ = NULL; |
200 } | 200 } |
201 | 201 |
202 content::DownloadItem* item_; | 202 content::DownloadItem* item_; |
203 bool waiting_; | 203 bool waiting_; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 *results = results_.Pass(); | 267 *results = results_.Pass(); |
268 } | 268 } |
269 return result_valid_; | 269 return result_valid_; |
270 } | 270 } |
271 | 271 |
272 private: | 272 private: |
273 void OnQueryDownloadsComplete( | 273 void OnQueryDownloadsComplete( |
274 scoped_ptr<std::vector<history::DownloadRow> > entries) { | 274 scoped_ptr<std::vector<history::DownloadRow> > entries) { |
275 result_valid_ = true; | 275 result_valid_ = true; |
276 results_ = entries.Pass(); | 276 results_ = entries.Pass(); |
277 base::MessageLoopForUI::current()->Quit(); | 277 base::MessageLoopForUI::current()->QuitWhenIdle(); |
278 } | 278 } |
279 | 279 |
280 Profile* profile_; | 280 Profile* profile_; |
281 scoped_ptr<std::vector<history::DownloadRow> > results_; | 281 scoped_ptr<std::vector<history::DownloadRow> > results_; |
282 bool result_valid_; | 282 bool result_valid_; |
283 | 283 |
284 DISALLOW_COPY_AND_ASSIGN(DownloadsHistoryDataCollector); | 284 DISALLOW_COPY_AND_ASSIGN(DownloadsHistoryDataCollector); |
285 }; | 285 }; |
286 | 286 |
287 // Mock that simulates a permissions dialog where the user denies | 287 // Mock that simulates a permissions dialog where the user denies |
288 // permission to install. TODO(skerner): This could be shared with | 288 // permission to install. TODO(skerner): This could be shared with |
289 // extensions tests. Find a common place for this class. | 289 // extensions tests. Find a common place for this class. |
290 class MockAbortExtensionInstallPrompt : public ExtensionInstallPrompt { | 290 class MockAbortExtensionInstallPrompt : public ExtensionInstallPrompt { |
291 public: | 291 public: |
292 MockAbortExtensionInstallPrompt() : | 292 MockAbortExtensionInstallPrompt() : |
293 ExtensionInstallPrompt(NULL) { | 293 ExtensionInstallPrompt(NULL) { |
294 } | 294 } |
295 | 295 |
296 // Simulate a user abort on an extension installation. | 296 // Simulate a user abort on an extension installation. |
297 void ConfirmInstall(Delegate* delegate, | 297 void ConfirmInstall(Delegate* delegate, |
298 const Extension* extension, | 298 const Extension* extension, |
299 const ShowDialogCallback& show_dialog_callback) override { | 299 const ShowDialogCallback& show_dialog_callback) override { |
300 delegate->InstallUIAbort(true); | 300 delegate->InstallUIAbort(true); |
301 base::MessageLoopForUI::current()->Quit(); | 301 base::MessageLoopForUI::current()->QuitWhenIdle(); |
302 } | 302 } |
303 | 303 |
304 void OnInstallSuccess(const Extension* extension, SkBitmap* icon) override {} | 304 void OnInstallSuccess(const Extension* extension, SkBitmap* icon) override {} |
305 void OnInstallFailure(const extensions::CrxInstallError& error) override {} | 305 void OnInstallFailure(const extensions::CrxInstallError& error) override {} |
306 }; | 306 }; |
307 | 307 |
308 // Mock that simulates a permissions dialog where the user allows | 308 // Mock that simulates a permissions dialog where the user allows |
309 // installation. | 309 // installation. |
310 class MockAutoConfirmExtensionInstallPrompt : public ExtensionInstallPrompt { | 310 class MockAutoConfirmExtensionInstallPrompt : public ExtensionInstallPrompt { |
311 public: | 311 public: |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 callback_ = callback; | 388 callback_ = callback; |
389 } | 389 } |
390 | 390 |
391 void OnDownloadStored(content::DownloadItem* item, | 391 void OnDownloadStored(content::DownloadItem* item, |
392 const history::DownloadRow& info) override { | 392 const history::DownloadRow& info) override { |
393 if (!callback_.is_null() && (!callback_.Run(info))) | 393 if (!callback_.is_null() && (!callback_.Run(info))) |
394 return; | 394 return; |
395 | 395 |
396 seen_stored_ = true; | 396 seen_stored_ = true; |
397 if (waiting_) | 397 if (waiting_) |
398 base::MessageLoopForUI::current()->Quit(); | 398 base::MessageLoopForUI::current()->QuitWhenIdle(); |
399 } | 399 } |
400 | 400 |
401 void OnDownloadHistoryDestroyed() override { | 401 void OnDownloadHistoryDestroyed() override { |
402 DownloadServiceFactory::GetForBrowserContext(profile_)-> | 402 DownloadServiceFactory::GetForBrowserContext(profile_)-> |
403 GetDownloadHistory()->RemoveObserver(this); | 403 GetDownloadHistory()->RemoveObserver(this); |
404 } | 404 } |
405 | 405 |
406 void WaitForStored() { | 406 void WaitForStored() { |
407 if (seen_stored_) | 407 if (seen_stored_) |
408 return; | 408 return; |
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1102 DownloadItem* download = downloads[0]; | 1102 DownloadItem* download = downloads[0]; |
1103 EXPECT_EQ(DownloadItem::INTERRUPTED, download->GetState()); | 1103 EXPECT_EQ(DownloadItem::INTERRUPTED, download->GetState()); |
1104 EXPECT_EQ(error, download->GetLastReason()); | 1104 EXPECT_EQ(error, download->GetLastReason()); |
1105 return download; | 1105 return download; |
1106 } | 1106 } |
1107 | 1107 |
1108 private: | 1108 private: |
1109 static void EnsureNoPendingDownloadJobsOnIO(bool* result) { | 1109 static void EnsureNoPendingDownloadJobsOnIO(bool* result) { |
1110 if (net::URLRequestSlowDownloadJob::NumberOutstandingRequests()) | 1110 if (net::URLRequestSlowDownloadJob::NumberOutstandingRequests()) |
1111 *result = false; | 1111 *result = false; |
1112 BrowserThread::PostTask( | 1112 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
1113 BrowserThread::UI, FROM_HERE, base::MessageLoop::QuitClosure()); | 1113 base::MessageLoop::QuitWhenIdleClosure()); |
1114 } | 1114 } |
1115 | 1115 |
1116 // Location of the test data. | 1116 // Location of the test data. |
1117 base::FilePath test_dir_; | 1117 base::FilePath test_dir_; |
1118 | 1118 |
1119 // Location of the downloads directory for these tests | 1119 // Location of the downloads directory for these tests |
1120 base::ScopedTempDir downloads_directory_; | 1120 base::ScopedTempDir downloads_directory_; |
1121 | 1121 |
1122 scoped_ptr<DownloadTestFileActivityObserver> file_activity_observer_; | 1122 scoped_ptr<DownloadTestFileActivityObserver> file_activity_observer_; |
1123 }; | 1123 }; |
(...skipping 2422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3546 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, PRE_DownloadTest_History) { | 3546 IN_PROC_BROWSER_TEST_F(DownloadTestWithShelf, PRE_DownloadTest_History) { |
3547 // Download a file and wait for it to be stored. | 3547 // Download a file and wait for it to be stored. |
3548 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 3548 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
3549 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); | 3549 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); |
3550 HistoryObserver observer(browser()->profile()); | 3550 HistoryObserver observer(browser()->profile()); |
3551 DownloadAndWait(browser(), download_url); | 3551 DownloadAndWait(browser(), download_url); |
3552 observer.WaitForStored(); | 3552 observer.WaitForStored(); |
3553 HistoryServiceFactory::GetForProfile(browser()->profile(), | 3553 HistoryServiceFactory::GetForProfile(browser()->profile(), |
3554 ServiceAccessType::IMPLICIT_ACCESS) | 3554 ServiceAccessType::IMPLICIT_ACCESS) |
3555 ->FlushForTest(base::Bind( | 3555 ->FlushForTest(base::Bind( |
3556 &base::MessageLoop::Quit, | 3556 &base::MessageLoop::QuitWhenIdle, |
3557 base::Unretained(base::MessageLoop::current()->current()))); | 3557 base::Unretained(base::MessageLoop::current()->current()))); |
3558 content::RunMessageLoop(); | 3558 content::RunMessageLoop(); |
3559 } | 3559 } |
3560 | 3560 |
3561 #if defined(OS_CHROMEOS) | 3561 #if defined(OS_CHROMEOS) |
3562 // Times out on ChromeOS: http://crbug.com/217810 | 3562 // Times out on ChromeOS: http://crbug.com/217810 |
3563 #define MAYBE_DownloadTest_History DISABLED_DownloadTest_History | 3563 #define MAYBE_DownloadTest_History DISABLED_DownloadTest_History |
3564 #else | 3564 #else |
3565 #define MAYBE_DownloadTest_History DownloadTest_History | 3565 #define MAYBE_DownloadTest_History DownloadTest_History |
3566 #endif | 3566 #endif |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3643 | 3643 |
3644 scoped_ptr<content::DownloadTestObserver> observer(DangerousDownloadWaiter( | 3644 scoped_ptr<content::DownloadTestObserver> observer(DangerousDownloadWaiter( |
3645 browser(), 1, content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); | 3645 browser(), 1, content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); |
3646 ui_test_utils::NavigateToURL(browser(), extension_url); | 3646 ui_test_utils::NavigateToURL(browser(), extension_url); |
3647 | 3647 |
3648 observer->WaitForFinished(); | 3648 observer->WaitForFinished(); |
3649 | 3649 |
3650 // Download shelf should close. | 3650 // Download shelf should close. |
3651 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 3651 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
3652 } | 3652 } |
OLD | NEW |