| 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/files/file_path.h" | 5 #include "base/files/file_path.h" |
| 6 #include "base/files/scoped_temp_dir.h" | 6 #include "base/files/scoped_temp_dir.h" |
| 7 #include "content/browser/download/download_file_factory.h" | 7 #include "content/browser/download/download_file_factory.h" |
| 8 #include "content/browser/download/download_file_impl.h" | 8 #include "content/browser/download/download_file_impl.h" |
| 9 #include "content/browser/download/download_item_impl.h" | 9 #include "content/browser/download/download_item_impl.h" |
| 10 #include "content/browser/download/download_manager_impl.h" | 10 #include "content/browser/download/download_manager_impl.h" |
| 11 #include "content/browser/download/drag_download_file.h" | 11 #include "content/browser/download/drag_download_file.h" |
| 12 #include "content/browser/download/drag_download_util.h" | 12 #include "content/browser/download/drag_download_util.h" |
| 13 #include "content/browser/web_contents/web_contents_impl.h" | 13 #include "content/browser/web_contents/web_contents_impl.h" |
| 14 #include "content/public/browser/content_browser_client.h" | 14 #include "content/public/browser/content_browser_client.h" |
| 15 #include "content/public/browser/power_save_blocker.h" | 15 #include "content/public/browser/power_save_blocker.h" |
| 16 #include "content/public/common/content_client.h" | 16 #include "content/public/common/content_client.h" |
| 17 #include "content/public/test/content_browser_test.h" | 17 #include "content/public/test/content_browser_test.h" |
| 18 #include "content/public/test/content_browser_test_utils.h" | 18 #include "content/public/test/content_browser_test_utils.h" |
| 19 #include "content/public/test/download_test_observer.h" | 19 #include "content/public/test/download_test_observer.h" |
| 20 #include "content/public/test/test_utils.h" | 20 #include "content/public/test/test_utils.h" |
| 21 #include "content/shell/browser/shell.h" | 21 #include "content/shell/browser/shell.h" |
| 22 #include "content/shell/browser/shell_browser_context.h" | 22 #include "content/shell/browser/shell_browser_context.h" |
| 23 #include "content/shell/browser/shell_download_manager_delegate.h" | 23 #include "content/shell/browser/shell_download_manager_delegate.h" |
| 24 #include "content/test/net/url_request_mock_http_job.h" | |
| 25 #include "content/test/net/url_request_slow_download_job.h" | 24 #include "content/test/net/url_request_slow_download_job.h" |
| 25 #include "net/test/url_request/url_request_mock_http_job.h" |
| 26 #include "testing/gmock/include/gmock/gmock.h" | 26 #include "testing/gmock/include/gmock/gmock.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 28 #include "url/gurl.h" | 28 #include "url/gurl.h" |
| 29 | 29 |
| 30 using testing::_; | 30 using testing::_; |
| 31 using testing::InvokeWithoutArgs; | 31 using testing::InvokeWithoutArgs; |
| 32 | 32 |
| 33 namespace content { | 33 namespace content { |
| 34 | 34 |
| 35 class MockDownloadFileObserver : public ui::DownloadFileObserver { | 35 class MockDownloadFileObserver : public ui::DownloadFileObserver { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 static_cast<ShellDownloadManagerDelegate*>( | 67 static_cast<ShellDownloadManagerDelegate*>( |
| 68 shell()->web_contents()->GetBrowserContext() | 68 shell()->web_contents()->GetBrowserContext() |
| 69 ->GetDownloadManagerDelegate()); | 69 ->GetDownloadManagerDelegate()); |
| 70 delegate->SetDownloadBehaviorForTesting(downloads_directory()); | 70 delegate->SetDownloadBehaviorForTesting(downloads_directory()); |
| 71 } | 71 } |
| 72 | 72 |
| 73 void SetUpServer() { | 73 void SetUpServer() { |
| 74 base::FilePath mock_base(GetTestFilePath("download", "")); | 74 base::FilePath mock_base(GetTestFilePath("download", "")); |
| 75 BrowserThread::PostTask( | 75 BrowserThread::PostTask( |
| 76 BrowserThread::IO, FROM_HERE, | 76 BrowserThread::IO, FROM_HERE, |
| 77 base::Bind(&URLRequestMockHTTPJob::AddUrlHandler, mock_base)); | 77 base::Bind(&net::URLRequestMockHTTPJob::AddUrlHandler, mock_base, |
| 78 make_scoped_refptr( |
| 79 content::BrowserThread::GetBlockingPool()))); |
| 78 } | 80 } |
| 79 | 81 |
| 80 const base::FilePath& downloads_directory() const { | 82 const base::FilePath& downloads_directory() const { |
| 81 return downloads_directory_.path(); | 83 return downloads_directory_.path(); |
| 82 } | 84 } |
| 83 | 85 |
| 84 private: | 86 private: |
| 85 base::ScopedTempDir downloads_directory_; | 87 base::ScopedTempDir downloads_directory_; |
| 86 | 88 |
| 87 DISALLOW_COPY_AND_ASSIGN(DragDownloadFileTest); | 89 DISALLOW_COPY_AND_ASSIGN(DragDownloadFileTest); |
| 88 }; | 90 }; |
| 89 | 91 |
| 90 IN_PROC_BROWSER_TEST_F(DragDownloadFileTest, DragDownloadFileTest_NetError) { | 92 IN_PROC_BROWSER_TEST_F(DragDownloadFileTest, DragDownloadFileTest_NetError) { |
| 91 base::FilePath name(downloads_directory().AppendASCII( | 93 base::FilePath name(downloads_directory().AppendASCII( |
| 92 "DragDownloadFileTest_NetError.txt")); | 94 "DragDownloadFileTest_NetError.txt")); |
| 93 GURL url(URLRequestMockHTTPJob::GetMockUrl(base::FilePath(FILE_PATH_LITERAL( | 95 GURL url(net::URLRequestMockHTTPJob::GetMockUrl( |
| 94 "download-test.lib")))); | 96 base::FilePath(FILE_PATH_LITERAL("download-test.lib")))); |
| 95 Referrer referrer; | 97 Referrer referrer; |
| 96 std::string referrer_encoding; | 98 std::string referrer_encoding; |
| 97 scoped_refptr<DragDownloadFile> file( | 99 scoped_refptr<DragDownloadFile> file( |
| 98 new DragDownloadFile(name, base::File(), url, referrer, | 100 new DragDownloadFile(name, base::File(), url, referrer, |
| 99 referrer_encoding, shell()->web_contents())); | 101 referrer_encoding, shell()->web_contents())); |
| 100 scoped_refptr<MockDownloadFileObserver> observer( | 102 scoped_refptr<MockDownloadFileObserver> observer( |
| 101 new MockDownloadFileObserver()); | 103 new MockDownloadFileObserver()); |
| 102 EXPECT_CALL(*observer.get(), OnDownloadAborted()) | 104 EXPECT_CALL(*observer.get(), OnDownloadAborted()) |
| 103 .WillOnce(InvokeWithoutArgs(this, &DragDownloadFileTest::Succeed)); | 105 .WillOnce(InvokeWithoutArgs(this, &DragDownloadFileTest::Succeed)); |
| 104 ON_CALL(*observer.get(), OnDownloadCompleted(_)) | 106 ON_CALL(*observer.get(), OnDownloadCompleted(_)) |
| 105 .WillByDefault(InvokeWithoutArgs(this, &DragDownloadFileTest::FailFast)); | 107 .WillByDefault(InvokeWithoutArgs(this, &DragDownloadFileTest::FailFast)); |
| 106 file->Start(observer.get()); | 108 file->Start(observer.get()); |
| 107 RunMessageLoop(); | 109 RunMessageLoop(); |
| 108 } | 110 } |
| 109 | 111 |
| 110 IN_PROC_BROWSER_TEST_F(DragDownloadFileTest, DragDownloadFileTest_Complete) { | 112 IN_PROC_BROWSER_TEST_F(DragDownloadFileTest, DragDownloadFileTest_Complete) { |
| 111 base::FilePath name(downloads_directory().AppendASCII( | 113 base::FilePath name(downloads_directory().AppendASCII( |
| 112 "DragDownloadFileTest_Complete.txt")); | 114 "DragDownloadFileTest_Complete.txt")); |
| 113 GURL url(URLRequestMockHTTPJob::GetMockUrl(base::FilePath(FILE_PATH_LITERAL( | 115 GURL url(net::URLRequestMockHTTPJob::GetMockUrl( |
| 114 "download-test.lib")))); | 116 base::FilePath(FILE_PATH_LITERAL("download-test.lib")))); |
| 115 Referrer referrer; | 117 Referrer referrer; |
| 116 std::string referrer_encoding; | 118 std::string referrer_encoding; |
| 117 SetUpServer(); | 119 SetUpServer(); |
| 118 scoped_refptr<DragDownloadFile> file(new DragDownloadFile( | 120 scoped_refptr<DragDownloadFile> file(new DragDownloadFile( |
| 119 name, base::File(), url, referrer, | 121 name, base::File(), url, referrer, |
| 120 referrer_encoding, shell()->web_contents())); | 122 referrer_encoding, shell()->web_contents())); |
| 121 scoped_refptr<MockDownloadFileObserver> observer( | 123 scoped_refptr<MockDownloadFileObserver> observer( |
| 122 new MockDownloadFileObserver()); | 124 new MockDownloadFileObserver()); |
| 123 EXPECT_CALL(*observer.get(), OnDownloadCompleted(_)) | 125 EXPECT_CALL(*observer.get(), OnDownloadCompleted(_)) |
| 124 .WillOnce(InvokeWithoutArgs(this, &DragDownloadFileTest::Succeed)); | 126 .WillOnce(InvokeWithoutArgs(this, &DragDownloadFileTest::Succeed)); |
| 125 ON_CALL(*observer.get(), OnDownloadAborted()) | 127 ON_CALL(*observer.get(), OnDownloadAborted()) |
| 126 .WillByDefault(InvokeWithoutArgs(this, &DragDownloadFileTest::FailFast)); | 128 .WillByDefault(InvokeWithoutArgs(this, &DragDownloadFileTest::FailFast)); |
| 127 file->Start(observer.get()); | 129 file->Start(observer.get()); |
| 128 RunMessageLoop(); | 130 RunMessageLoop(); |
| 129 } | 131 } |
| 130 | 132 |
| 131 // TODO(benjhayden): Test Stop(). | 133 // TODO(benjhayden): Test Stop(). |
| 132 | 134 |
| 133 } // namespace content | 135 } // namespace content |
| OLD | NEW |