| 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" |
| (...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 &callback_consumer_, | 700 &callback_consumer_, |
| 701 NewCallback(this, | 701 NewCallback(this, |
| 702 &DownloadsHistoryDataCollector::OnQueryDownloadsComplete)); | 702 &DownloadsHistoryDataCollector::OnQueryDownloadsComplete)); |
| 703 | 703 |
| 704 // Cannot complete immediately because the history backend runs on a | 704 // Cannot complete immediately because the history backend runs on a |
| 705 // separate thread, so we can assume that the RunMessageLoop below will | 705 // separate thread, so we can assume that the RunMessageLoop below will |
| 706 // be exited by the Quit in OnQueryDownloadsComplete. | 706 // be exited by the Quit in OnQueryDownloadsComplete. |
| 707 ui_test_utils::RunMessageLoop(); | 707 ui_test_utils::RunMessageLoop(); |
| 708 } | 708 } |
| 709 | 709 |
| 710 bool GetDownloadsHistoryEntry(DownloadCreateInfo* result) { | 710 bool GetDownloadsHistoryEntry(DownloadHistoryInfo* result) { |
| 711 DCHECK(result); | 711 DCHECK(result); |
| 712 *result = result_; | 712 *result = result_; |
| 713 return result_valid_; | 713 return result_valid_; |
| 714 } | 714 } |
| 715 | 715 |
| 716 private: | 716 private: |
| 717 void OnQueryDownloadsComplete( | 717 void OnQueryDownloadsComplete( |
| 718 std::vector<DownloadCreateInfo>* entries) { | 718 std::vector<DownloadHistoryInfo>* entries) { |
| 719 result_valid_ = false; | 719 result_valid_ = false; |
| 720 for (std::vector<DownloadCreateInfo>::const_iterator it = entries->begin(); | 720 for (std::vector<DownloadHistoryInfo>::const_iterator it = entries->begin(); |
| 721 it != entries->end(); ++it) { | 721 it != entries->end(); ++it) { |
| 722 if (it->db_handle == download_db_handle_) { | 722 if (it->db_handle == download_db_handle_) { |
| 723 result_ = *it; | 723 result_ = *it; |
| 724 result_valid_ = true; | 724 result_valid_ = true; |
| 725 } | 725 } |
| 726 } | 726 } |
| 727 MessageLoopForUI::current()->Quit(); | 727 MessageLoopForUI::current()->Quit(); |
| 728 } | 728 } |
| 729 | 729 |
| 730 DownloadCreateInfo result_; | 730 DownloadHistoryInfo result_; |
| 731 bool result_valid_; | 731 bool result_valid_; |
| 732 int64 download_db_handle_; | 732 int64 download_db_handle_; |
| 733 CancelableRequestConsumer callback_consumer_; | 733 CancelableRequestConsumer callback_consumer_; |
| 734 | 734 |
| 735 DISALLOW_COPY_AND_ASSIGN(DownloadsHistoryDataCollector); | 735 DISALLOW_COPY_AND_ASSIGN(DownloadsHistoryDataCollector); |
| 736 }; | 736 }; |
| 737 | 737 |
| 738 // NOTES: | 738 // NOTES: |
| 739 // | 739 // |
| 740 // Files for these tests are found in DIR_TEST_DATA (currently | 740 // Files for these tests are found in DIR_TEST_DATA (currently |
| (...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1302 | 1302 |
| 1303 // Check state. | 1303 // Check state. |
| 1304 EXPECT_EQ(1, browser()->tab_count()); | 1304 EXPECT_EQ(1, browser()->tab_count()); |
| 1305 CheckDownload(browser(), file, file); | 1305 CheckDownload(browser(), file, file); |
| 1306 EXPECT_TRUE(IsDownloadUIVisible(browser())); | 1306 EXPECT_TRUE(IsDownloadUIVisible(browser())); |
| 1307 | 1307 |
| 1308 // Check history results. | 1308 // Check history results. |
| 1309 DownloadsHistoryDataCollector history_collector( | 1309 DownloadsHistoryDataCollector history_collector( |
| 1310 db_handle, | 1310 db_handle, |
| 1311 browser()->profile()->GetDownloadManager()); | 1311 browser()->profile()->GetDownloadManager()); |
| 1312 DownloadCreateInfo info; | 1312 DownloadHistoryInfo info; |
| 1313 EXPECT_TRUE(history_collector.GetDownloadsHistoryEntry(&info)) << db_handle; | 1313 EXPECT_TRUE(history_collector.GetDownloadsHistoryEntry(&info)) << db_handle; |
| 1314 EXPECT_EQ(file, info.path.BaseName()); | 1314 EXPECT_EQ(file, info.path.BaseName()); |
| 1315 EXPECT_EQ(url, info.url()); | 1315 EXPECT_EQ(url, info.url()); |
| 1316 // Ignore start_time. | 1316 // Ignore start_time. |
| 1317 EXPECT_EQ(origin_size, info.received_bytes); | 1317 EXPECT_EQ(origin_size, info.received_bytes); |
| 1318 EXPECT_EQ(origin_size, info.total_bytes); | 1318 EXPECT_EQ(origin_size, info.total_bytes); |
| 1319 EXPECT_EQ(DownloadItem::COMPLETE, info.state); | 1319 EXPECT_EQ(DownloadItem::COMPLETE, info.state); |
| 1320 } | 1320 } |
| 1321 | 1321 |
| 1322 // Test for crbug.com/14505. This tests that chrome:// urls are still functional | 1322 // 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... |
| 1367 DownloadAndWait(browser(), download_url, EXPECT_NO_SELECT_DIALOG); | 1367 DownloadAndWait(browser(), download_url, EXPECT_NO_SELECT_DIALOG); |
| 1368 | 1368 |
| 1369 ui_test_utils::WindowedNotificationObserver signal( | 1369 ui_test_utils::WindowedNotificationObserver signal( |
| 1370 NotificationType::BROWSER_CLOSED, | 1370 NotificationType::BROWSER_CLOSED, |
| 1371 Source<Browser>(browser())); | 1371 Source<Browser>(browser())); |
| 1372 browser()->CloseWindow(); | 1372 browser()->CloseWindow(); |
| 1373 signal.Wait(); | 1373 signal.Wait(); |
| 1374 } | 1374 } |
| 1375 | 1375 |
| 1376 } // namespace | 1376 } // namespace |
| OLD | NEW |