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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 bool DownloadStoredProperly( | 149 bool DownloadStoredProperly( |
150 const GURL& expected_url, | 150 const GURL& expected_url, |
151 const base::FilePath& expected_path, | 151 const base::FilePath& expected_path, |
152 int64 num_files, | 152 int64 num_files, |
153 history::DownloadState expected_state, | 153 history::DownloadState expected_state, |
154 DownloadItem* item, | 154 DownloadItem* item, |
155 const history::DownloadRow& info) { | 155 const history::DownloadRow& info) { |
156 // This function may be called multiple times for a given test. Returning | 156 // This function may be called multiple times for a given test. Returning |
157 // false doesn't necessarily mean that the test has failed or will fail, it | 157 // false doesn't necessarily mean that the test has failed or will fail, it |
158 // might just mean that the test hasn't passed yet. | 158 // might just mean that the test hasn't passed yet. |
159 if (info.target_path != expected_path) { | 159 if (!expected_path.empty() && info.target_path != expected_path) { |
160 DVLOG(20) << __FUNCTION__ << " " << info.target_path.value() | 160 DVLOG(20) << __FUNCTION__ << " " << info.target_path.value() |
161 << " != " << expected_path.value(); | 161 << " != " << expected_path.value(); |
162 return false; | 162 return false; |
163 } | 163 } |
164 if (info.url_chain.size() != 1u) { | 164 if (info.url_chain.size() != 1u) { |
165 DVLOG(20) << __FUNCTION__ << " " << info.url_chain.size() | 165 DVLOG(20) << __FUNCTION__ << " " << info.url_chain.size() |
166 << " != 1"; | 166 << " != 1"; |
167 return false; | 167 return false; |
168 } | 168 } |
169 if (info.url_chain[0] != expected_url) { | 169 if (info.url_chain[0] != expected_url) { |
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 GetDownloadManager())->DownloadPath(); | 766 GetDownloadManager())->DownloadPath(); |
767 base::FilePath filename = download_dir.AppendASCII("dataurl.txt"); | 767 base::FilePath filename = download_dir.AppendASCII("dataurl.txt"); |
768 ASSERT_TRUE(base::PathExists(filename)); | 768 ASSERT_TRUE(base::PathExists(filename)); |
769 std::string contents; | 769 std::string contents; |
770 EXPECT_TRUE(base::ReadFileToString(filename, &contents)); | 770 EXPECT_TRUE(base::ReadFileToString(filename, &contents)); |
771 EXPECT_EQ("foo", contents); | 771 EXPECT_EQ("foo", contents); |
772 } | 772 } |
773 | 773 |
774 // Test that we don't crash when the page contains an iframe that | 774 // Test that we don't crash when the page contains an iframe that |
775 // was handled as a download (http://crbug.com/42212). | 775 // was handled as a download (http://crbug.com/42212). |
776 // Flaky: https://crbug.com/537530. | 776 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveDownloadableIFrame) { |
777 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, DISABLED_SaveDownloadableIFrame) { | |
778 GURL url = URLRequestMockHTTPJob::GetMockUrl( | 777 GURL url = URLRequestMockHTTPJob::GetMockUrl( |
779 "downloads/iframe-src-is-a-download.htm"); | 778 "downloads/iframe-src-is-a-download.htm"); |
780 ui_test_utils::NavigateToURL(browser(), url); | |
781 | 779 |
782 // Wait for and then dismiss the non-save-page-as-related download item | 780 // Wait for and then dismiss the non-save-page-as-related download item |
783 // (the one associated with downloading of "thisdayinhistory.xls" file). | 781 // (the one associated with downloading of "thisdayinhistory.xls" file). |
784 VerifySavePackageExpectations(browser(), url); | 782 { |
785 GetDownloadManager()->RemoveAllDownloads(); | 783 GURL download_url("http://mock.http/downloads/thisdayinhistory.xls"); |
| 784 DownloadPersistedObserver persisted( |
| 785 browser()->profile(), |
| 786 base::Bind(&DownloadStoredProperly, download_url, base::FilePath(), -1, |
| 787 history::DownloadState::COMPLETE)); |
| 788 |
| 789 ui_test_utils::NavigateToURL(browser(), url); |
| 790 |
| 791 ASSERT_TRUE(VerifySavePackageExpectations(browser(), download_url)); |
| 792 persisted.WaitForPersisted(); |
| 793 GetDownloadManager()->RemoveAllDownloads(); |
| 794 } |
786 | 795 |
787 base::FilePath full_file_name, dir; | 796 base::FilePath full_file_name, dir; |
788 SaveCurrentTab(url, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML, | 797 SaveCurrentTab(url, content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML, |
789 "iframe-src-is-a-download", 2, &dir, &full_file_name); | 798 "iframe-src-is-a-download", 2, &dir, &full_file_name); |
790 ASSERT_FALSE(HasFailure()); | 799 ASSERT_FALSE(HasFailure()); |
791 | 800 |
792 EXPECT_TRUE(base::PathExists(full_file_name)); | 801 EXPECT_TRUE(base::PathExists(full_file_name)); |
793 } | 802 } |
794 | 803 |
795 // Test suite that allows testing --site-per-process against cross-site frames. | 804 // Test suite that allows testing --site-per-process against cross-site frames. |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
920 pos = mhtml.find("Content-Type: image/png", pos); | 929 pos = mhtml.find("Content-Type: image/png", pos); |
921 if (pos == std::string::npos) | 930 if (pos == std::string::npos) |
922 break; | 931 break; |
923 count++; | 932 count++; |
924 pos++; | 933 pos++; |
925 } | 934 } |
926 EXPECT_EQ(1, count) << "Verify number of image/png parts in the mhtml output"; | 935 EXPECT_EQ(1, count) << "Verify number of image/png parts in the mhtml output"; |
927 } | 936 } |
928 | 937 |
929 } // namespace | 938 } // namespace |
OLD | NEW |