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 // This file contains download browser tests that are known to be runnable | 5 // This file contains download browser tests that are known to be runnable |
6 // in a pure content context. Over time tests should be migrated here. | 6 // in a pure content context. Over time tests should be migrated here. |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <utility> | 10 #include <utility> |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 #include "content/public/test/content_browser_test_utils.h" | 43 #include "content/public/test/content_browser_test_utils.h" |
44 #include "content/public/test/download_test_observer.h" | 44 #include "content/public/test/download_test_observer.h" |
45 #include "content/public/test/test_download_request_handler.h" | 45 #include "content/public/test/test_download_request_handler.h" |
46 #include "content/public/test/test_file_error_injector.h" | 46 #include "content/public/test/test_file_error_injector.h" |
47 #include "content/public/test/test_utils.h" | 47 #include "content/public/test/test_utils.h" |
48 #include "content/shell/browser/shell.h" | 48 #include "content/shell/browser/shell.h" |
49 #include "content/shell/browser/shell_browser_context.h" | 49 #include "content/shell/browser/shell_browser_context.h" |
50 #include "content/shell/browser/shell_download_manager_delegate.h" | 50 #include "content/shell/browser/shell_download_manager_delegate.h" |
51 #include "content/shell/browser/shell_network_delegate.h" | 51 #include "content/shell/browser/shell_network_delegate.h" |
52 #include "device/power_save_blocker/power_save_blocker.h" | 52 #include "device/power_save_blocker/power_save_blocker.h" |
| 53 #include "net/dns/mock_host_resolver.h" |
53 #include "net/test/embedded_test_server/embedded_test_server.h" | 54 #include "net/test/embedded_test_server/embedded_test_server.h" |
54 #include "net/test/embedded_test_server/http_request.h" | 55 #include "net/test/embedded_test_server/http_request.h" |
55 #include "net/test/embedded_test_server/http_response.h" | 56 #include "net/test/embedded_test_server/http_response.h" |
56 #include "net/test/url_request/url_request_mock_http_job.h" | 57 #include "net/test/url_request/url_request_mock_http_job.h" |
57 #include "net/test/url_request/url_request_slow_download_job.h" | 58 #include "net/test/url_request/url_request_slow_download_job.h" |
58 #include "ppapi/features/features.h" | 59 #include "ppapi/features/features.h" |
59 #include "testing/gmock/include/gmock/gmock.h" | 60 #include "testing/gmock/include/gmock/gmock.h" |
60 #include "testing/gtest/include/gtest/gtest.h" | 61 #include "testing/gtest/include/gtest/gtest.h" |
61 #include "url/gurl.h" | 62 #include "url/gurl.h" |
62 | 63 |
(...skipping 2414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2477 | 2478 |
2478 GURL document_url = | 2479 GURL document_url = |
2479 embedded_test_server()->GetURL("/download/download-attribute-blob.html"); | 2480 embedded_test_server()->GetURL("/download/download-attribute-blob.html"); |
2480 DownloadItem* download = StartDownloadAndReturnItem(shell(), document_url); | 2481 DownloadItem* download = StartDownloadAndReturnItem(shell(), document_url); |
2481 WaitForCompletion(download); | 2482 WaitForCompletion(download); |
2482 | 2483 |
2483 EXPECT_STREQ(FILE_PATH_LITERAL("suggested-filename.txt"), | 2484 EXPECT_STREQ(FILE_PATH_LITERAL("suggested-filename.txt"), |
2484 download->GetTargetFilePath().BaseName().value().c_str()); | 2485 download->GetTargetFilePath().BaseName().value().c_str()); |
2485 } | 2486 } |
2486 | 2487 |
| 2488 IN_PROC_BROWSER_TEST_F(DownloadContentTest, DownloadAttributeSameSiteCookie) { |
| 2489 base::ThreadRestrictions::ScopedAllowIO allow_io_during_test; |
| 2490 |
| 2491 const std::string kOriginOne = "one.example"; |
| 2492 const std::string kOriginTwo = "two.example"; |
| 2493 |
| 2494 ASSERT_TRUE(embedded_test_server()->Start()); |
| 2495 |
| 2496 const std::string real_host = embedded_test_server()->host_port_pair().host(); |
| 2497 host_resolver()->AddRule(kOriginOne, real_host); |
| 2498 host_resolver()->AddRule(kOriginTwo, real_host); |
| 2499 |
| 2500 GURL echo_cookie_url = |
| 2501 embedded_test_server()->GetURL(kOriginOne, "/echoheader?cookie"); |
| 2502 |
| 2503 // download-attribute-same-site-cookie sets two cookies. One "A=B" is set with |
| 2504 // SameSite=Strict. The other one "B=C" doesn't have this flag. In general |
| 2505 // a[download] should behave the same as a top level navigation. |
| 2506 // |
| 2507 // The page then simulates a click on an <a download> link whose target is the |
| 2508 // /echoheader handler on the same origin. |
| 2509 DownloadItem* download = StartDownloadAndReturnItem( |
| 2510 shell(), |
| 2511 embedded_test_server()->GetURL( |
| 2512 kOriginOne, |
| 2513 std::string( |
| 2514 "/download/download-attribute-same-site-cookie.html?target=") + |
| 2515 echo_cookie_url.spec())); |
| 2516 WaitForCompletion(download); |
| 2517 |
| 2518 std::string file_contents; |
| 2519 ASSERT_TRUE( |
| 2520 base::ReadFileToString(download->GetTargetFilePath(), &file_contents)); |
| 2521 |
| 2522 // Initiator and target are same-origin. Both cookies should have been |
| 2523 // included in the request. |
| 2524 EXPECT_STREQ("A=B; B=C", file_contents.c_str()); |
| 2525 |
| 2526 // The test isn't complete without verifying that the initiator isn't being |
| 2527 // incorrectly set to be the same as the resource origin. The |
| 2528 // download-attribute test page doesn't set any cookies but creates a download |
| 2529 // via a <a download> link to the target URL. In this case: |
| 2530 // |
| 2531 // Initiator origin: kOriginTwo |
| 2532 // Resource origin: kOriginOne |
| 2533 // First-party origin: kOriginOne |
| 2534 download = StartDownloadAndReturnItem( |
| 2535 shell(), |
| 2536 embedded_test_server()->GetURL( |
| 2537 kOriginTwo, std::string("/download/download-attribute.html?target=") + |
| 2538 echo_cookie_url.spec())); |
| 2539 WaitForCompletion(download); |
| 2540 |
| 2541 ASSERT_TRUE( |
| 2542 base::ReadFileToString(download->GetTargetFilePath(), &file_contents)); |
| 2543 |
| 2544 // The initiator and the target are not same-origin. Only the second cookie |
| 2545 // should be sent along with the request. |
| 2546 EXPECT_STREQ("B=C", file_contents.c_str()); |
| 2547 |
| 2548 // OriginOne redirects through OriginTwo. |
| 2549 // |
| 2550 // Initiator origin: kOriginOne |
| 2551 // Resource origin: kOriginOne |
| 2552 // First-party origin: kOriginOne |
| 2553 GURL redirect_url = embedded_test_server()->GetURL( |
| 2554 kOriginTwo, std::string("/server-redirect?") + echo_cookie_url.spec()); |
| 2555 download = StartDownloadAndReturnItem( |
| 2556 shell(), |
| 2557 embedded_test_server()->GetURL( |
| 2558 kOriginOne, std::string("/download/download-attribute.html?target=") + |
| 2559 redirect_url.spec())); |
| 2560 WaitForCompletion(download); |
| 2561 |
| 2562 ASSERT_TRUE( |
| 2563 base::ReadFileToString(download->GetTargetFilePath(), &file_contents)); |
| 2564 EXPECT_STREQ("A=B; B=C", file_contents.c_str()); |
| 2565 } |
| 2566 |
2487 // The file empty.bin is served with a MIME type of application/octet-stream. | 2567 // The file empty.bin is served with a MIME type of application/octet-stream. |
2488 // The content body is empty. Make sure this case is handled properly and we | 2568 // The content body is empty. Make sure this case is handled properly and we |
2489 // don't regress on http://crbug.com/320394. | 2569 // don't regress on http://crbug.com/320394. |
2490 IN_PROC_BROWSER_TEST_F(DownloadContentTest, DownloadGZipWithNoContent) { | 2570 IN_PROC_BROWSER_TEST_F(DownloadContentTest, DownloadGZipWithNoContent) { |
2491 GURL url = net::URLRequestMockHTTPJob::GetMockUrl("empty.bin"); | 2571 GURL url = net::URLRequestMockHTTPJob::GetMockUrl("empty.bin"); |
2492 NavigateToURLAndWaitForDownload(shell(), url, DownloadItem::COMPLETE); | 2572 NavigateToURLAndWaitForDownload(shell(), url, DownloadItem::COMPLETE); |
2493 // That's it. This should work without crashing. | 2573 // That's it. This should work without crashing. |
2494 } | 2574 } |
2495 | 2575 |
2496 // Make sure that sniffed MIME types are correctly passed through to the | 2576 // Make sure that sniffed MIME types are correctly passed through to the |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2557 GURL document_url = | 2637 GURL document_url = |
2558 origin_two.GetURL("/iframe-host.html?target=" + frame_url.spec()); | 2638 origin_two.GetURL("/iframe-host.html?target=" + frame_url.spec()); |
2559 DownloadItem* download = StartDownloadAndReturnItem(shell(), document_url); | 2639 DownloadItem* download = StartDownloadAndReturnItem(shell(), document_url); |
2560 WaitForCompletion(download); | 2640 WaitForCompletion(download); |
2561 | 2641 |
2562 EXPECT_STREQ(FILE_PATH_LITERAL("download-test.lib"), | 2642 EXPECT_STREQ(FILE_PATH_LITERAL("download-test.lib"), |
2563 download->GetTargetFilePath().BaseName().value().c_str()); | 2643 download->GetTargetFilePath().BaseName().value().c_str()); |
2564 } | 2644 } |
2565 | 2645 |
2566 } // namespace content | 2646 } // namespace content |
OLD | NEW |