| 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 <sstream> | 5 #include <sstream> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 954 // navigate directly to the file we don't want to download because cross-site | 954 // navigate directly to the file we don't want to download because cross-site |
| 955 // navigations reset the TabDownloadState. | 955 // navigations reset the TabDownloadState. |
| 956 FilePath same_site_path(FILE_PATH_LITERAL("download_script.html")); | 956 FilePath same_site_path(FILE_PATH_LITERAL("download_script.html")); |
| 957 GURL same_site_url(URLRequestMockHTTPJob::GetMockUrl(same_site_path)); | 957 GURL same_site_url(URLRequestMockHTTPJob::GetMockUrl(same_site_path)); |
| 958 ui_test_utils::NavigateToURL(browser(), same_site_url); | 958 ui_test_utils::NavigateToURL(browser(), same_site_url); |
| 959 | 959 |
| 960 // Make sure the initial navigation didn't trigger a download. | 960 // Make sure the initial navigation didn't trigger a download. |
| 961 EXPECT_TRUE(EnsureNoPendingDownloads()); | 961 EXPECT_TRUE(EnsureNoPendingDownloads()); |
| 962 | 962 |
| 963 // Disable downloads for the tab. | 963 // Disable downloads for the tab. |
| 964 content::NavigationController* controller = | 964 WebContents* web_contents = browser()->GetSelectedWebContents(); |
| 965 &browser()->GetSelectedWebContents()->GetController(); | |
| 966 DownloadRequestLimiter::TabDownloadState* tab_download_state = | 965 DownloadRequestLimiter::TabDownloadState* tab_download_state = |
| 967 g_browser_process->download_request_limiter()->GetDownloadState( | 966 g_browser_process->download_request_limiter()->GetDownloadState( |
| 968 controller, | 967 web_contents, web_contents, true); |
| 969 controller, | |
| 970 true); | |
| 971 ASSERT_TRUE(tab_download_state); | 968 ASSERT_TRUE(tab_download_state); |
| 972 tab_download_state->set_download_status( | 969 tab_download_state->set_download_status( |
| 973 DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED); | 970 DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED); |
| 974 | 971 |
| 975 // Try to start the download via Javascript and wait for the corresponding | 972 // Try to start the download via Javascript and wait for the corresponding |
| 976 // load stop event. | 973 // load stop event. |
| 977 TestNavigationObserver observer( | 974 TestNavigationObserver observer( |
| 978 content::Source<content::NavigationController>(controller), | 975 content::Source<content::NavigationController>( |
| 976 &web_contents->GetController()), |
| 979 NULL, | 977 NULL, |
| 980 1); | 978 1); |
| 981 bool download_assempted; | 979 bool download_assempted; |
| 982 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 980 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 983 browser()->GetSelectedWebContents()->GetRenderViewHost(), | 981 browser()->GetSelectedWebContents()->GetRenderViewHost(), |
| 984 L"", | 982 L"", |
| 985 L"window.domAutomationController.send(startDownload());", | 983 L"window.domAutomationController.send(startDownload());", |
| 986 &download_assempted)); | 984 &download_assempted)); |
| 987 ASSERT_TRUE(download_assempted); | 985 ASSERT_TRUE(download_assempted); |
| 988 observer.WaitForObservation( | 986 observer.WaitForObservation( |
| (...skipping 1468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2457 GetDownloads(browser(), &download_items); | 2455 GetDownloads(browser(), &download_items); |
| 2458 ASSERT_EQ(1u, download_items.size()); | 2456 ASSERT_EQ(1u, download_items.size()); |
| 2459 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), | 2457 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), |
| 2460 download_items[0]->GetOriginalUrl()); | 2458 download_items[0]->GetOriginalUrl()); |
| 2461 | 2459 |
| 2462 // Check that the file contains the expected referrer. | 2460 // Check that the file contains the expected referrer. |
| 2463 FilePath file(download_items[0]->GetFullPath()); | 2461 FilePath file(download_items[0]->GetFullPath()); |
| 2464 std::string expected_contents = test_server()->GetURL("").spec(); | 2462 std::string expected_contents = test_server()->GetURL("").spec(); |
| 2465 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); | 2463 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); |
| 2466 } | 2464 } |
| OLD | NEW |