OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/file_path.h" | 5 #include "base/file_path.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/memory/scoped_temp_dir.h" | 8 #include "base/memory/scoped_temp_dir.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/test/test_file_util.h" | 10 #include "base/test/test_file_util.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/download/download_item.h" | 13 #include "chrome/browser/download/download_item.h" |
14 #include "chrome/browser/download/download_file_manager.h" | 14 #include "chrome/browser/download/download_file_manager.h" |
15 #include "chrome/browser/download/download_manager.h" | 15 #include "chrome/browser/download/download_manager.h" |
16 #include "chrome/browser/download/download_prefs.h" | 16 #include "chrome/browser/download/download_prefs.h" |
17 #include "chrome/browser/download/download_shelf.h" | 17 #include "chrome/browser/download/download_shelf.h" |
18 #include "chrome/browser/history/download_create_info.h" | 18 #include "chrome/browser/history/download_history_info.h" |
19 #include "chrome/browser/history/history.h" | 19 #include "chrome/browser/history/history.h" |
20 #include "chrome/browser/net/url_request_mock_http_job.h" | 20 #include "chrome/browser/net/url_request_mock_http_job.h" |
21 #include "chrome/browser/net/url_request_slow_download_job.h" | 21 #include "chrome/browser/net/url_request_slow_download_job.h" |
22 #include "chrome/browser/prefs/pref_service.h" | 22 #include "chrome/browser/prefs/pref_service.h" |
23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
25 #include "chrome/browser/ui/browser_list.h" | 25 #include "chrome/browser/ui/browser_list.h" |
26 #include "chrome/browser/ui/browser_window.h" | 26 #include "chrome/browser/ui/browser_window.h" |
27 #include "chrome/browser/ui/webui/active_downloads_ui.h" | 27 #include "chrome/browser/ui/webui/active_downloads_ui.h" |
28 #include "chrome/common/chrome_paths.h" | 28 #include "chrome/common/chrome_paths.h" |
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 &callback_consumer_, | 691 &callback_consumer_, |
692 NewCallback(this, | 692 NewCallback(this, |
693 &DownloadsHistoryDataCollector::OnQueryDownloadsComplete)); | 693 &DownloadsHistoryDataCollector::OnQueryDownloadsComplete)); |
694 | 694 |
695 // Cannot complete immediately because the history backend runs on a | 695 // Cannot complete immediately because the history backend runs on a |
696 // separate thread, so we can assume that the RunMessageLoop below will | 696 // separate thread, so we can assume that the RunMessageLoop below will |
697 // be exited by the Quit in OnQueryDownloadsComplete. | 697 // be exited by the Quit in OnQueryDownloadsComplete. |
698 ui_test_utils::RunMessageLoop(); | 698 ui_test_utils::RunMessageLoop(); |
699 } | 699 } |
700 | 700 |
701 bool GetDownloadsHistoryEntry(DownloadCreateInfo* result) { | 701 bool GetDownloadsHistoryEntry(DownloadHistoryInfo* result) { |
702 DCHECK(result); | 702 DCHECK(result); |
703 *result = result_; | 703 *result = result_; |
704 return result_valid_; | 704 return result_valid_; |
705 } | 705 } |
706 | 706 |
707 private: | 707 private: |
708 void OnQueryDownloadsComplete( | 708 void OnQueryDownloadsComplete( |
709 std::vector<DownloadCreateInfo>* entries) { | 709 std::vector<DownloadHistoryInfo>* entries) { |
710 result_valid_ = false; | 710 result_valid_ = false; |
711 for (std::vector<DownloadCreateInfo>::const_iterator it = entries->begin(); | 711 for (std::vector<DownloadHistoryInfo>::const_iterator it = entries->begin(); |
712 it != entries->end(); ++it) { | 712 it != entries->end(); ++it) { |
713 if (it->db_handle == download_db_handle_) { | 713 if (it->db_handle == download_db_handle_) { |
714 result_ = *it; | 714 result_ = *it; |
715 result_valid_ = true; | 715 result_valid_ = true; |
716 } | 716 } |
717 } | 717 } |
718 MessageLoopForUI::current()->Quit(); | 718 MessageLoopForUI::current()->Quit(); |
719 } | 719 } |
720 | 720 |
721 DownloadCreateInfo result_; | 721 DownloadHistoryInfo result_; |
722 bool result_valid_; | 722 bool result_valid_; |
723 int64 download_db_handle_; | 723 int64 download_db_handle_; |
724 CancelableRequestConsumer callback_consumer_; | 724 CancelableRequestConsumer callback_consumer_; |
725 | 725 |
726 DISALLOW_COPY_AND_ASSIGN(DownloadsHistoryDataCollector); | 726 DISALLOW_COPY_AND_ASSIGN(DownloadsHistoryDataCollector); |
727 }; | 727 }; |
728 | 728 |
729 // NOTES: | 729 // NOTES: |
730 // | 730 // |
731 // Files for these tests are found in DIR_TEST_DATA (currently | 731 // Files for these tests are found in DIR_TEST_DATA (currently |
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1277 | 1277 |
1278 // Check state. | 1278 // Check state. |
1279 EXPECT_EQ(1, browser()->tab_count()); | 1279 EXPECT_EQ(1, browser()->tab_count()); |
1280 CheckDownload(browser(), file, file); | 1280 CheckDownload(browser(), file, file); |
1281 EXPECT_TRUE(IsDownloadUIVisible(browser())); | 1281 EXPECT_TRUE(IsDownloadUIVisible(browser())); |
1282 | 1282 |
1283 // Check history results. | 1283 // Check history results. |
1284 DownloadsHistoryDataCollector history_collector( | 1284 DownloadsHistoryDataCollector history_collector( |
1285 db_handle, | 1285 db_handle, |
1286 browser()->profile()->GetDownloadManager()); | 1286 browser()->profile()->GetDownloadManager()); |
1287 DownloadCreateInfo info; | 1287 DownloadHistoryInfo info; |
1288 EXPECT_TRUE(history_collector.GetDownloadsHistoryEntry(&info)) << db_handle; | 1288 EXPECT_TRUE(history_collector.GetDownloadsHistoryEntry(&info)) << db_handle; |
1289 EXPECT_EQ(file, info.path.BaseName()); | 1289 EXPECT_EQ(file, info.path.BaseName()); |
1290 EXPECT_EQ(url, info.url()); | 1290 EXPECT_EQ(url, info.url()); |
1291 // Ignore start_time. | 1291 // Ignore start_time. |
1292 EXPECT_EQ(origin_size, info.received_bytes); | 1292 EXPECT_EQ(origin_size, info.received_bytes); |
1293 EXPECT_EQ(origin_size, info.total_bytes); | 1293 EXPECT_EQ(origin_size, info.total_bytes); |
1294 EXPECT_EQ(DownloadItem::COMPLETE, info.state); | 1294 EXPECT_EQ(DownloadItem::COMPLETE, info.state); |
1295 } | 1295 } |
1296 | 1296 |
1297 // Test for crbug.com/14505. This tests that chrome:// urls are still functional | 1297 // Test for crbug.com/14505. This tests that chrome:// urls are still functional |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1342 DownloadAndWait(browser(), download_url, EXPECT_NO_SELECT_DIALOG); | 1342 DownloadAndWait(browser(), download_url, EXPECT_NO_SELECT_DIALOG); |
1343 | 1343 |
1344 ui_test_utils::WindowedNotificationObserver signal( | 1344 ui_test_utils::WindowedNotificationObserver signal( |
1345 NotificationType::BROWSER_CLOSED, | 1345 NotificationType::BROWSER_CLOSED, |
1346 Source<Browser>(browser())); | 1346 Source<Browser>(browser())); |
1347 browser()->CloseWindow(); | 1347 browser()->CloseWindow(); |
1348 signal.Wait(); | 1348 signal.Wait(); |
1349 } | 1349 } |
1350 | 1350 |
1351 } // namespace | 1351 } // namespace |
OLD | NEW |