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/bind.h" | 5 #include "base/bind.h" |
6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 DCHECK(downloads); | 572 DCHECK(downloads); |
573 DownloadManager* manager = DownloadManagerForBrowser(browser); | 573 DownloadManager* manager = DownloadManagerForBrowser(browser); |
574 manager->SearchDownloads(string16(), downloads); | 574 manager->SearchDownloads(string16(), downloads); |
575 } | 575 } |
576 | 576 |
577 // Check that the download UI (shelf on non-chromeos or panel on chromeos) | 577 // Check that the download UI (shelf on non-chromeos or panel on chromeos) |
578 // is visible or not as expected. Additionally, check that the filename | 578 // is visible or not as expected. Additionally, check that the filename |
579 // is present in the UI (currently only on chromeos). | 579 // is present in the UI (currently only on chromeos). |
580 void CheckDownloadUI(Browser* browser, bool expected_non_cros, | 580 void CheckDownloadUI(Browser* browser, bool expected_non_cros, |
581 bool expected_cros, const FilePath& filename) { | 581 bool expected_cros, const FilePath& filename) { |
582 #if defined(OS_CHROMEOS) | 582 #if defined(OS_CHROMEOS) && !defined(USE_AURA) |
583 #if defined(TOUCH_UI) | 583 #if defined(TOUCH_UI) |
584 TabContents* download_contents = ActiveDownloadsUI::GetPopup(NULL); | 584 TabContents* download_contents = ActiveDownloadsUI::GetPopup(NULL); |
585 EXPECT_EQ(expected_cros, download_contents != NULL); | 585 EXPECT_EQ(expected_cros, download_contents != NULL); |
586 if (!download_contents || filename.empty()) | 586 if (!download_contents || filename.empty()) |
587 return; | 587 return; |
588 | 588 |
589 ActiveDownloadsUI* downloads_ui = static_cast<ActiveDownloadsUI*>( | 589 ActiveDownloadsUI* downloads_ui = static_cast<ActiveDownloadsUI*>( |
590 download_contents->web_ui()); | 590 download_contents->web_ui()); |
591 #else | 591 #else |
592 Browser* popup = ActiveDownloadsUI::GetPopup(); | 592 Browser* popup = ActiveDownloadsUI::GetPopup(); |
(...skipping 18 matching lines...) Expand all Loading... |
611 break; | 611 break; |
612 } | 612 } |
613 } | 613 } |
614 EXPECT_TRUE(exists); | 614 EXPECT_TRUE(exists); |
615 #else | 615 #else |
616 EXPECT_EQ(expected_non_cros, browser->window()->IsDownloadShelfVisible()); | 616 EXPECT_EQ(expected_non_cros, browser->window()->IsDownloadShelfVisible()); |
617 // TODO: Check for filename match in download shelf. | 617 // TODO: Check for filename match in download shelf. |
618 #endif | 618 #endif |
619 } | 619 } |
620 static void ExpectWindowCountAfterDownload(size_t expected) { | 620 static void ExpectWindowCountAfterDownload(size_t expected) { |
621 #if defined(OS_CHROMEOS) | 621 #if defined(OS_CHROMEOS) && !defined(USE_AURA) |
622 // On ChromeOS, a download panel is created to display | 622 // On ChromeOS, a download panel is created to display |
623 // download information, and this counts as a window. | 623 // download information, and this counts as a window. |
624 expected++; | 624 expected++; |
625 #endif | 625 #endif |
626 EXPECT_EQ(expected, BrowserList::size()); | 626 EXPECT_EQ(expected, BrowserList::size()); |
627 } | 627 } |
628 | 628 |
629 // Arrange for select file calls on the given browser from the | 629 // Arrange for select file calls on the given browser from the |
630 // download manager to always choose the suggested file. | 630 // download manager to always choose the suggested file. |
631 void NullSelectFile(Browser* browser) { | 631 void NullSelectFile(Browser* browser) { |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 // Download a file and wait. | 777 // Download a file and wait. |
778 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 778 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); |
779 | 779 |
780 CheckDownload(browser(), download_file, file); | 780 CheckDownload(browser(), download_file, file); |
781 | 781 |
782 // Check state. | 782 // Check state. |
783 EXPECT_EQ(1, browser()->tab_count()); | 783 EXPECT_EQ(1, browser()->tab_count()); |
784 CheckDownloadUI(browser(), true, true, download_file); | 784 CheckDownloadUI(browser(), true, true, download_file); |
785 } | 785 } |
786 | 786 |
787 #if !defined(OS_CHROMEOS) // Download shelf is not per-window on ChromeOS. | 787 #if !defined(OS_CHROMEOS) || defined(USE_AURA) |
| 788 // Download shelf is not per-window on ChromeOS. |
788 // Test that the download shelf is per-window by starting a download in one | 789 // Test that the download shelf is per-window by starting a download in one |
789 // tab, opening a second tab, closing the shelf, going back to the first tab, | 790 // tab, opening a second tab, closing the shelf, going back to the first tab, |
790 // and checking that the shelf is closed. | 791 // and checking that the shelf is closed. |
791 IN_PROC_BROWSER_TEST_F(DownloadTest, PerWindowShelf) { | 792 IN_PROC_BROWSER_TEST_F(DownloadTest, PerWindowShelf) { |
792 ASSERT_TRUE(InitialSetup(false)); | 793 ASSERT_TRUE(InitialSetup(false)); |
793 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); | 794 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); |
794 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 795 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
795 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); | 796 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); |
796 | 797 |
797 // Download a file and wait. | 798 // Download a file and wait. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
844 ASSERT_TRUE(RunSizeTest(browser(), SIZE_TEST_TYPE_KNOWN, | 845 ASSERT_TRUE(RunSizeTest(browser(), SIZE_TEST_TYPE_KNOWN, |
845 "71% - ", "100% - ")); | 846 "71% - ", "100% - ")); |
846 } | 847 } |
847 | 848 |
848 // Test that when downloading an item in Incognito mode, we don't crash when | 849 // Test that when downloading an item in Incognito mode, we don't crash when |
849 // closing the last Incognito window (http://crbug.com/13983). | 850 // closing the last Incognito window (http://crbug.com/13983). |
850 // Also check that the download shelf is not visible after closing the | 851 // Also check that the download shelf is not visible after closing the |
851 // Incognito window. | 852 // Incognito window. |
852 IN_PROC_BROWSER_TEST_F(DownloadTest, IncognitoDownload) { | 853 IN_PROC_BROWSER_TEST_F(DownloadTest, IncognitoDownload) { |
853 ASSERT_TRUE(InitialSetup(false)); | 854 ASSERT_TRUE(InitialSetup(false)); |
854 | |
855 // Open an Incognito window. | 855 // Open an Incognito window. |
856 Browser* incognito = CreateIncognitoBrowser(); // Waits. | 856 Browser* incognito = CreateIncognitoBrowser(); // Waits. |
857 ASSERT_TRUE(incognito); | 857 ASSERT_TRUE(incognito); |
858 int window_count = BrowserList::size(); | 858 int window_count = BrowserList::size(); |
859 EXPECT_EQ(2, window_count); | 859 EXPECT_EQ(2, window_count); |
860 | 860 |
861 // Download a file in the Incognito window and wait. | 861 // Download a file in the Incognito window and wait. |
862 CreateAndSetDownloadsDirectory(incognito); | 862 CreateAndSetDownloadsDirectory(incognito); |
863 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 863 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
864 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 864 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
(...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1675 search_results.clear(); | 1675 search_results.clear(); |
1676 | 1676 |
1677 manager->SearchDownloads(UTF8ToUTF16("another_file"), &search_results); | 1677 manager->SearchDownloads(UTF8ToUTF16("another_file"), &search_results); |
1678 ASSERT_EQ(2u, search_results.size()); | 1678 ASSERT_EQ(2u, search_results.size()); |
1679 std::sort(search_results.begin(), search_results.end(), | 1679 std::sort(search_results.begin(), search_results.end(), |
1680 DownloadItemSorter); | 1680 DownloadItemSorter); |
1681 EXPECT_EQ(2, search_results[0]->db_handle()); | 1681 EXPECT_EQ(2, search_results[0]->db_handle()); |
1682 EXPECT_EQ(3, search_results[1]->db_handle()); | 1682 EXPECT_EQ(3, search_results[1]->db_handle()); |
1683 search_results.clear(); | 1683 search_results.clear(); |
1684 } | 1684 } |
OLD | NEW |