Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(464)

Side by Side Diff: content/browser/download/download_browsertest.cc

Issue 23496076: WIP - Refactor programmatic downloads Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "content/browser/byte_stream.h" 14 #include "content/browser/byte_stream.h"
15 #include "content/browser/download/download_file_factory.h" 15 #include "content/browser/download/download_file_factory.h"
16 #include "content/browser/download/download_file_impl.h" 16 #include "content/browser/download/download_file_impl.h"
17 #include "content/browser/download/download_item_impl.h" 17 #include "content/browser/download/download_item_impl.h"
18 #include "content/browser/download/download_manager_impl.h" 18 #include "content/browser/download/download_manager_impl.h"
19 #include "content/browser/download/download_resource_handler.h" 19 #include "content/browser/download/download_request_model.h"
20 #include "content/browser/plugin_service_impl.h" 20 #include "content/browser/plugin_service_impl.h"
21 #include "content/browser/web_contents/web_contents_impl.h" 21 #include "content/browser/web_contents/web_contents_impl.h"
22 #include "content/public/browser/power_save_blocker.h" 22 #include "content/public/browser/power_save_blocker.h"
23 #include "content/public/common/content_switches.h" 23 #include "content/public/common/content_switches.h"
24 #include "content/public/common/webplugininfo.h" 24 #include "content/public/common/webplugininfo.h"
25 #include "content/public/test/browser_test_utils.h" 25 #include "content/public/test/browser_test_utils.h"
26 #include "content/public/test/download_test_observer.h" 26 #include "content/public/test/download_test_observer.h"
27 #include "content/public/test/test_file_error_injector.h" 27 #include "content/public/test/test_file_error_injector.h"
28 #include "content/public/test/test_utils.h" 28 #include "content/public/test/test_utils.h"
29 #include "content/shell/browser/shell.h" 29 #include "content/shell/browser/shell.h"
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 508
509 class DownloadContentTest : public ContentBrowserTest { 509 class DownloadContentTest : public ContentBrowserTest {
510 protected: 510 protected:
511 // An initial send from a website of at least this size will not be 511 // An initial send from a website of at least this size will not be
512 // help up by buffering in the underlying downloads ByteStream data 512 // help up by buffering in the underlying downloads ByteStream data
513 // transfer. This is important because on resumption tests we wait 513 // transfer. This is important because on resumption tests we wait
514 // until we've gotten the data we expect before allowing the test server 514 // until we've gotten the data we expect before allowing the test server
515 // to send its reset, to get around hard close semantics on the Windows 515 // to send its reset, to get around hard close semantics on the Windows
516 // socket layer implementation. 516 // socket layer implementation.
517 int GetSafeBufferChunk() const { 517 int GetSafeBufferChunk() const {
518 return (DownloadResourceHandler::kDownloadByteStreamSize / 518 return (DownloadRequestModel::kDownloadByteStreamSize /
519 ByteStreamWriter::kFractionBufferBeforeSending) + 1; 519 ByteStreamWriter::kFractionBufferBeforeSending) + 1;
520 } 520 }
521 521
522 virtual void SetUpOnMainThread() OVERRIDE { 522 virtual void SetUpOnMainThread() OVERRIDE {
523 ASSERT_TRUE(downloads_directory_.CreateUniqueTempDir()); 523 ASSERT_TRUE(downloads_directory_.CreateUniqueTempDir());
524 524
525 TestShellDownloadManagerDelegate* delegate = 525 TestShellDownloadManagerDelegate* delegate =
526 new TestShellDownloadManagerDelegate(); 526 new TestShellDownloadManagerDelegate();
527 delegate->SetDownloadBehaviorForTesting(downloads_directory_.path()); 527 delegate->SetDownloadBehaviorForTesting(downloads_directory_.path());
528 DownloadManager* manager = DownloadManagerForShell(shell()); 528 DownloadManager* manager = DownloadManagerForShell(shell());
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
1118 recorder.CompareToExpectedRecord(expected_record, arraysize(expected_record)); 1118 recorder.CompareToExpectedRecord(expected_record, arraysize(expected_record));
1119 } 1119 }
1120 1120
1121 // Confirm restart fallback happens if a precondition is failed. 1121 // Confirm restart fallback happens if a precondition is failed.
1122 IN_PROC_BROWSER_TEST_F(DownloadContentTest, 1122 IN_PROC_BROWSER_TEST_F(DownloadContentTest,
1123 ResumeInterruptedDownloadBadPrecondition) { 1123 ResumeInterruptedDownloadBadPrecondition) {
1124 CommandLine::ForCurrentProcess()->AppendSwitch( 1124 CommandLine::ForCurrentProcess()->AppendSwitch(
1125 switches::kEnableDownloadResumption); 1125 switches::kEnableDownloadResumption);
1126 ASSERT_TRUE(test_server()->Start()); 1126 ASSERT_TRUE(test_server()->Start());
1127 1127
1128 GURL url = test_server()->GetURL( 1128 GURL url = test_server()->GetURL(base::StringPrintf(
1129 base::StringPrintf( 1129 // First download hits an RST, rest don't, precondition fail.
1130 // First download hits an RST, rest don't, precondition fail. 1130 "rangereset?size=%d&rst_boundary=%d&"
1131 "rangereset?size=%d&rst_boundary=%d&" 1131 "token=BadPrecondition&rst_limit=1&fail_precondition=2",
1132 "token=NoRange&rst_limit=1&fail_precondition=2", 1132 GetSafeBufferChunk() * 3,
1133 GetSafeBufferChunk() * 3, GetSafeBufferChunk())); 1133 GetSafeBufferChunk()));
1134 1134
1135 // Start the download and wait for first data chunk. 1135 // Start the download and wait for first data chunk.
1136 DownloadItem* download(StartDownloadAndReturnItem(url)); 1136 DownloadItem* download(StartDownloadAndReturnItem(url));
1137 WaitForData(download, GetSafeBufferChunk()); 1137 WaitForData(download, GetSafeBufferChunk());
1138 1138
1139 RecordingDownloadObserver recorder(download); 1139 RecordingDownloadObserver recorder(download);
1140 1140
1141 ReleaseRSTAndConfirmInterruptForResume(download); 1141 ReleaseRSTAndConfirmInterruptForResume(download);
1142 ConfirmFileStatusForResume( 1142 ConfirmFileStatusForResume(
1143 download, true, GetSafeBufferChunk(), GetSafeBufferChunk() * 3, 1143 download, true, GetSafeBufferChunk(), GetSafeBufferChunk() * 3,
1144 base::FilePath(FILE_PATH_LITERAL("rangereset.crdownload"))); 1144 base::FilePath(FILE_PATH_LITERAL("rangereset.crdownload")));
1145 EXPECT_EQ("BadPrecondition2", download->GetETag());
1145 1146
1146 DownloadUpdatedObserver completion_observer( 1147 DownloadUpdatedObserver completion_observer(
1147 download, base::Bind(DownloadCompleteFilter)); 1148 download, base::Bind(DownloadCompleteFilter));
1148 download->Resume(); 1149 download->Resume();
1149 completion_observer.WaitForEvent(); 1150 completion_observer.WaitForEvent();
1150 1151
1151 ConfirmFileStatusForResume( 1152 ConfirmFileStatusForResume(
1152 download, true, GetSafeBufferChunk() * 3, GetSafeBufferChunk() * 3, 1153 download, true, GetSafeBufferChunk() * 3, GetSafeBufferChunk() * 3,
1153 base::FilePath(FILE_PATH_LITERAL("rangereset"))); 1154 base::FilePath(FILE_PATH_LITERAL("rangereset")));
1155 EXPECT_EQ("BadPrecondition0", download->GetETag());
1154 1156
1155 static const RecordingDownloadObserver::RecordStruct expected_record[] = { 1157 static const RecordingDownloadObserver::RecordStruct expected_record[] = {
1156 // Result of RST 1158 // Result of RST
1157 {DownloadItem::INTERRUPTED, GetSafeBufferChunk()}, 1159 {DownloadItem::INTERRUPTED, GetSafeBufferChunk()},
1158 // Starting continuation 1160 // Starting continuation
1159 {DownloadItem::IN_PROGRESS, GetSafeBufferChunk()}, 1161 {DownloadItem::IN_PROGRESS, GetSafeBufferChunk()},
1160 // Server precondition fail. 1162 // Server precondition fail.
1161 {DownloadItem::INTERRUPTED, 0}, 1163 {DownloadItem::INTERRUPTED, 0},
1162 // Notification of successful restart. 1164 // Notification of successful restart.
1163 {DownloadItem::IN_PROGRESS, 0}, 1165 {DownloadItem::IN_PROGRESS, 0},
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
1632 ASSERT_EQ(1u, downloads.size()); 1634 ASSERT_EQ(1u, downloads.size());
1633 ASSERT_EQ(DownloadItem::COMPLETE, downloads[0]->GetState()); 1635 ASSERT_EQ(DownloadItem::COMPLETE, downloads[0]->GetState());
1634 1636
1635 // Check that the cookies were correctly set. 1637 // Check that the cookies were correctly set.
1636 EXPECT_EQ("A=B", 1638 EXPECT_EQ("A=B",
1637 content::GetCookies(shell()->web_contents()->GetBrowserContext(), 1639 content::GetCookies(shell()->web_contents()->GetBrowserContext(),
1638 GURL(download))); 1640 GURL(download)));
1639 } 1641 }
1640 1642
1641 } // namespace content 1643 } // namespace content
OLDNEW
« no previous file with comments | « chrome/common/extensions/api/downloads.idl ('k') | content/browser/download/download_create_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698