Chromium Code Reviews| 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 "chrome/browser/download/download_browsertest.h" | 5 #include "chrome/browser/download/download_browsertest.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <sstream> | 8 #include <sstream> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 #include "content/public/browser/download_url_parameters.h" | 84 #include "content/public/browser/download_url_parameters.h" |
| 85 #include "content/public/browser/notification_source.h" | 85 #include "content/public/browser/notification_source.h" |
| 86 #include "content/public/browser/render_frame_host.h" | 86 #include "content/public/browser/render_frame_host.h" |
| 87 #include "content/public/browser/render_view_host.h" | 87 #include "content/public/browser/render_view_host.h" |
| 88 #include "content/public/browser/render_widget_host.h" | 88 #include "content/public/browser/render_widget_host.h" |
| 89 #include "content/public/browser/resource_context.h" | 89 #include "content/public/browser/resource_context.h" |
| 90 #include "content/public/browser/web_contents.h" | 90 #include "content/public/browser/web_contents.h" |
| 91 #include "content/public/common/content_features.h" | 91 #include "content/public/common/content_features.h" |
| 92 #include "content/public/common/content_switches.h" | 92 #include "content/public/common/content_switches.h" |
| 93 #include "content/public/common/context_menu_params.h" | 93 #include "content/public/common/context_menu_params.h" |
| 94 #include "content/public/common/quarantine.h" | |
| 94 #include "content/public/test/browser_test_utils.h" | 95 #include "content/public/test/browser_test_utils.h" |
| 95 #include "content/public/test/download_test_observer.h" | 96 #include "content/public/test/download_test_observer.h" |
| 96 #include "content/public/test/test_file_error_injector.h" | 97 #include "content/public/test/test_file_error_injector.h" |
| 97 #include "content/public/test/test_navigation_observer.h" | 98 #include "content/public/test/test_navigation_observer.h" |
| 98 #include "extensions/browser/extension_dialog_auto_confirm.h" | 99 #include "extensions/browser/extension_dialog_auto_confirm.h" |
| 99 #include "extensions/browser/extension_system.h" | 100 #include "extensions/browser/extension_system.h" |
| 100 #include "extensions/common/feature_switch.h" | 101 #include "extensions/common/feature_switch.h" |
| 101 #include "net/base/filename_util.h" | 102 #include "net/base/filename_util.h" |
| 102 #include "net/test/embedded_test_server/embedded_test_server.h" | 103 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 103 #include "net/test/embedded_test_server/http_request.h" | 104 #include "net/test/embedded_test_server/http_request.h" |
| (...skipping 1065 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1169 | 1170 |
| 1170 // Download the file and wait. We do not expect the Select File dialog. | 1171 // Download the file and wait. We do not expect the Select File dialog. |
| 1171 DownloadAndWait(browser(), url); | 1172 DownloadAndWait(browser(), url); |
| 1172 | 1173 |
| 1173 // Check state. | 1174 // Check state. |
| 1174 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 1175 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 1175 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1176 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1176 CheckDownload(browser(), file, file); | 1177 CheckDownload(browser(), file, file); |
| 1177 } | 1178 } |
| 1178 | 1179 |
| 1179 #if defined(OS_WIN) | 1180 #if defined(OS_WIN) || defined(OS_LINUX) |
| 1180 // Download a file and confirm that the zone identifier (on windows) | 1181 // Download a file and confirm that the file is correctly quarantined. |
| 1181 // is set to internet. | 1182 // |
| 1182 IN_PROC_BROWSER_TEST_F(DownloadTest, CheckInternetZone_DependsOnLocalConfig) { | 1183 // TODO(asanka): We should enable the test on Mac as well, but currently |
| 1184 // |browser_tests| aren't run from a process that has LSFileQuarantineEnabled | |
|
Avi (use Gerrit)
2016/12/02 19:58:27
The lack of LSFileQuarantineEnabled shouldn't be a
asanka
2016/12/06 20:34:36
Acknowledged. This is what we do for the unit test
| |
| 1185 // bit set. | |
| 1186 IN_PROC_BROWSER_TEST_F(DownloadTest, Quarantine_DependsOnLocalConfig) { | |
| 1183 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path)); | 1187 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path)); |
| 1184 | 1188 |
| 1185 // Download the file and wait. We do not expect the Select File dialog. | 1189 // Download the file and wait. We do not expect the Select File dialog. |
| 1186 DownloadAndWait(browser(), url); | 1190 DownloadAndWait(browser(), url); |
| 1187 | 1191 |
| 1188 // Check state. Special file state must be checked before CheckDownload, | 1192 // Check state. Special file state must be checked before CheckDownload, |
| 1189 // as CheckDownload will delete the output file. | 1193 // as CheckDownload will delete the output file. |
| 1190 EXPECT_EQ(1, browser()->tab_strip_model()->count()); | 1194 EXPECT_EQ(1, browser()->tab_strip_model()->count()); |
| 1191 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1195 base::FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1192 base::FilePath downloaded_file(DestinationFile(browser(), file)); | 1196 base::FilePath downloaded_file(DestinationFile(browser(), file)); |
| 1193 if (base::VolumeSupportsADS(downloaded_file)) | 1197 EXPECT_TRUE(content::IsFileQuarantined(downloaded_file, url, GURL())); |
| 1194 EXPECT_TRUE(base::HasInternetZoneIdentifier(downloaded_file)); | |
| 1195 CheckDownload(browser(), file, file); | 1198 CheckDownload(browser(), file, file); |
| 1196 } | 1199 } |
| 1200 #endif | |
| 1201 | |
| 1202 #if defined(OS_WIN) | |
| 1203 // A couple of Windows specific tests to make sure we respect OS specific | |
| 1204 // restrictions on MOTW can be applied. While Chrome doesn't directly apply | |
|
brettw
2016/12/06 22:48:42
I don't know what "MOTW" is ("message of the week"
asanka
2016/12/08 15:13:29
Done :-)
| |
| 1205 // these policies, Chrome still needs to make sure the correct APIs are invoked | |
| 1206 // during the download process that result in the expected MOTW behavior. | |
| 1197 | 1207 |
| 1198 // Downloading a file from the local host shouldn't cause the application of a | 1208 // Downloading a file from the local host shouldn't cause the application of a |
| 1199 // zone identifier. | 1209 // zone identifier. |
| 1200 IN_PROC_BROWSER_TEST_F(DownloadTest, CheckLocalhostZone_DependsOnLocalConfig) { | 1210 IN_PROC_BROWSER_TEST_F(DownloadTest, CheckLocalhostZone_DependsOnLocalConfig) { |
| 1201 embedded_test_server()->ServeFilesFromDirectory(GetTestDataDirectory()); | 1211 embedded_test_server()->ServeFilesFromDirectory(GetTestDataDirectory()); |
| 1202 ASSERT_TRUE(embedded_test_server()->Start()); | 1212 ASSERT_TRUE(embedded_test_server()->Start()); |
| 1203 | 1213 |
| 1204 // Assumes that localhost maps to 127.0.0.1. Otherwise the test will fail | 1214 // Assumes that localhost maps to 127.0.0.1. Otherwise the test will fail |
| 1205 // since EmbeddedTestServer is listening on that address. | 1215 // since EmbeddedTestServer is listening on that address. |
| 1206 GURL url = | 1216 GURL url = |
| 1207 embedded_test_server()->GetURL("localhost", "/downloads/a_zip_file.zip"); | 1217 embedded_test_server()->GetURL("localhost", "/downloads/a_zip_file.zip"); |
| 1208 DownloadAndWait(browser(), url); | 1218 DownloadAndWait(browser(), url); |
| 1209 base::FilePath file(FILE_PATH_LITERAL("a_zip_file.zip")); | 1219 base::FilePath file(FILE_PATH_LITERAL("a_zip_file.zip")); |
| 1210 base::FilePath downloaded_file(DestinationFile(browser(), file)); | 1220 base::FilePath downloaded_file(DestinationFile(browser(), file)); |
| 1211 EXPECT_FALSE(base::HasInternetZoneIdentifier(downloaded_file)); | 1221 EXPECT_FALSE(content::IsFileQuarantined(downloaded_file, GURL(), GURL())); |
| 1212 } | 1222 } |
| 1213 | 1223 |
| 1214 // Same as the test above, but uses a file:// URL to a local file. | 1224 // Same as the test above, but uses a file:// URL to a local file. |
| 1215 IN_PROC_BROWSER_TEST_F(DownloadTest, CheckLocalFileZone_DependsOnLocalConfig) { | 1225 IN_PROC_BROWSER_TEST_F(DownloadTest, CheckLocalFileZone_DependsOnLocalConfig) { |
| 1216 base::FilePath source_file = GetTestDataDirectory() | 1226 base::FilePath source_file = GetTestDataDirectory() |
| 1217 .AppendASCII("downloads") | 1227 .AppendASCII("downloads") |
| 1218 .AppendASCII("a_zip_file.zip"); | 1228 .AppendASCII("a_zip_file.zip"); |
| 1219 | 1229 |
| 1220 GURL url = net::FilePathToFileURL(source_file); | 1230 GURL url = net::FilePathToFileURL(source_file); |
| 1221 DownloadAndWait(browser(), url); | 1231 DownloadAndWait(browser(), url); |
| 1222 base::FilePath file(FILE_PATH_LITERAL("a_zip_file.zip")); | 1232 base::FilePath file(FILE_PATH_LITERAL("a_zip_file.zip")); |
| 1223 base::FilePath downloaded_file(DestinationFile(browser(), file)); | 1233 base::FilePath downloaded_file(DestinationFile(browser(), file)); |
| 1224 EXPECT_FALSE(base::HasInternetZoneIdentifier(downloaded_file)); | 1234 EXPECT_FALSE(content::IsFileQuarantined(downloaded_file, GURL(), GURL())); |
| 1225 } | 1235 } |
| 1226 #endif | 1236 #endif |
| 1227 | 1237 |
| 1228 // Put up a Select File dialog when the file is downloaded, due to | 1238 // Put up a Select File dialog when the file is downloaded, due to |
| 1229 // downloads preferences settings. | 1239 // downloads preferences settings. |
| 1230 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeTypeSelect) { | 1240 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeTypeSelect) { |
| 1231 // Re-enable prompting. | 1241 // Re-enable prompting. |
| 1232 browser()->profile()->GetPrefs()->SetBoolean( | 1242 browser()->profile()->GetPrefs()->SetBoolean( |
| 1233 prefs::kPromptForDownload, true); | 1243 prefs::kPromptForDownload, true); |
| 1234 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path)); | 1244 GURL url(URLRequestMockHTTPJob::GetMockUrl(kDownloadTest1Path)); |
| (...skipping 2491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3726 browser(), 1, | 3736 browser(), 1, |
| 3727 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); | 3737 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); |
| 3728 ui_test_utils::NavigateToURL(browser(), extension_url); | 3738 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 3729 | 3739 |
| 3730 observer->WaitForFinished(); | 3740 observer->WaitForFinished(); |
| 3731 | 3741 |
| 3732 // Download shelf should close. | 3742 // Download shelf should close. |
| 3733 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 3743 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 3734 } | 3744 } |
| 3735 #endif // defined(OS_CHROMEOS) | 3745 #endif // defined(OS_CHROMEOS) |
| OLD | NEW |