| 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/file_path.h" | 5 #include "base/file_path.h" |
| 6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "content/browser/download/download_file_factory.h" | 8 #include "content/browser/download/download_file_factory.h" |
| 9 #include "content/browser/download/download_file_impl.h" | 9 #include "content/browser/download/download_file_impl.h" |
| 10 #include "content/browser/download/download_item_impl.h" | 10 #include "content/browser/download/download_item_impl.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 using testing::_; | 31 using testing::_; |
| 32 using testing::InvokeWithoutArgs; | 32 using testing::InvokeWithoutArgs; |
| 33 | 33 |
| 34 namespace content { | 34 namespace content { |
| 35 | 35 |
| 36 class MockDownloadFileObserver : public ui::DownloadFileObserver { | 36 class MockDownloadFileObserver : public ui::DownloadFileObserver { |
| 37 public: | 37 public: |
| 38 MockDownloadFileObserver() {} | 38 MockDownloadFileObserver() {} |
| 39 | 39 |
| 40 MOCK_METHOD1(OnDownloadCompleted, void(const FilePath& file_path)); | 40 MOCK_METHOD1(OnDownloadCompleted, void(const base::FilePath& file_path)); |
| 41 MOCK_METHOD0(OnDownloadAborted, void()); | 41 MOCK_METHOD0(OnDownloadAborted, void()); |
| 42 | 42 |
| 43 private: | 43 private: |
| 44 virtual ~MockDownloadFileObserver() {} | 44 virtual ~MockDownloadFileObserver() {} |
| 45 | 45 |
| 46 DISALLOW_COPY_AND_ASSIGN(MockDownloadFileObserver); | 46 DISALLOW_COPY_AND_ASSIGN(MockDownloadFileObserver); |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 class DragDownloadFileTest : public ContentBrowserTest { | 49 class DragDownloadFileTest : public ContentBrowserTest { |
| 50 public: | 50 public: |
| (...skipping 14 matching lines...) Expand all Loading... |
| 65 virtual void SetUpOnMainThread() OVERRIDE { | 65 virtual void SetUpOnMainThread() OVERRIDE { |
| 66 ASSERT_TRUE(downloads_directory_.CreateUniqueTempDir()); | 66 ASSERT_TRUE(downloads_directory_.CreateUniqueTempDir()); |
| 67 ShellDownloadManagerDelegate* delegate = | 67 ShellDownloadManagerDelegate* delegate = |
| 68 static_cast<ShellDownloadManagerDelegate*>( | 68 static_cast<ShellDownloadManagerDelegate*>( |
| 69 shell()->web_contents()->GetBrowserContext() | 69 shell()->web_contents()->GetBrowserContext() |
| 70 ->GetDownloadManagerDelegate()); | 70 ->GetDownloadManagerDelegate()); |
| 71 delegate->SetDownloadBehaviorForTesting(downloads_directory()); | 71 delegate->SetDownloadBehaviorForTesting(downloads_directory()); |
| 72 } | 72 } |
| 73 | 73 |
| 74 void SetUpServer() { | 74 void SetUpServer() { |
| 75 FilePath mock_base(GetTestFilePath("download", "")); | 75 base::FilePath mock_base(GetTestFilePath("download", "")); |
| 76 BrowserThread::PostTask( | 76 BrowserThread::PostTask( |
| 77 BrowserThread::IO, FROM_HERE, | 77 BrowserThread::IO, FROM_HERE, |
| 78 base::Bind(&URLRequestMockHTTPJob::AddUrlHandler, mock_base)); | 78 base::Bind(&URLRequestMockHTTPJob::AddUrlHandler, mock_base)); |
| 79 } | 79 } |
| 80 | 80 |
| 81 const FilePath& downloads_directory() const { | 81 const base::FilePath& downloads_directory() const { |
| 82 return downloads_directory_.path(); | 82 return downloads_directory_.path(); |
| 83 } | 83 } |
| 84 | 84 |
| 85 private: | 85 private: |
| 86 base::ScopedTempDir downloads_directory_; | 86 base::ScopedTempDir downloads_directory_; |
| 87 | 87 |
| 88 DISALLOW_COPY_AND_ASSIGN(DragDownloadFileTest); | 88 DISALLOW_COPY_AND_ASSIGN(DragDownloadFileTest); |
| 89 }; | 89 }; |
| 90 | 90 |
| 91 IN_PROC_BROWSER_TEST_F(DragDownloadFileTest, DragDownloadFileTest_NetError) { | 91 IN_PROC_BROWSER_TEST_F(DragDownloadFileTest, DragDownloadFileTest_NetError) { |
| 92 FilePath name(downloads_directory().AppendASCII( | 92 base::FilePath name(downloads_directory().AppendASCII( |
| 93 "DragDownloadFileTest_NetError.txt")); | 93 "DragDownloadFileTest_NetError.txt")); |
| 94 GURL url(URLRequestMockHTTPJob::GetMockUrl(FilePath(FILE_PATH_LITERAL( | 94 GURL url(URLRequestMockHTTPJob::GetMockUrl(base::FilePath(FILE_PATH_LITERAL( |
| 95 "download-test.lib")))); | 95 "download-test.lib")))); |
| 96 Referrer referrer; | 96 Referrer referrer; |
| 97 std::string referrer_encoding; | 97 std::string referrer_encoding; |
| 98 DragDownloadFile* file = new DragDownloadFile( | 98 DragDownloadFile* file = new DragDownloadFile( |
| 99 name, scoped_ptr<net::FileStream>(NULL), url, referrer, | 99 name, scoped_ptr<net::FileStream>(NULL), url, referrer, |
| 100 referrer_encoding, shell()->web_contents()); | 100 referrer_encoding, shell()->web_contents()); |
| 101 scoped_refptr<MockDownloadFileObserver> observer( | 101 scoped_refptr<MockDownloadFileObserver> observer( |
| 102 new MockDownloadFileObserver()); | 102 new MockDownloadFileObserver()); |
| 103 EXPECT_CALL(*observer, OnDownloadAborted()).WillOnce(InvokeWithoutArgs( | 103 EXPECT_CALL(*observer, OnDownloadAborted()).WillOnce(InvokeWithoutArgs( |
| 104 this, &DragDownloadFileTest::Succeed)); | 104 this, &DragDownloadFileTest::Succeed)); |
| 105 ON_CALL(*observer, OnDownloadCompleted(_)).WillByDefault(InvokeWithoutArgs( | 105 ON_CALL(*observer, OnDownloadCompleted(_)).WillByDefault(InvokeWithoutArgs( |
| 106 this, &DragDownloadFileTest::FailFast)); | 106 this, &DragDownloadFileTest::FailFast)); |
| 107 file->Start(observer); | 107 file->Start(observer); |
| 108 RunMessageLoop(); | 108 RunMessageLoop(); |
| 109 } | 109 } |
| 110 | 110 |
| 111 IN_PROC_BROWSER_TEST_F(DragDownloadFileTest, DragDownloadFileTest_Complete) { | 111 IN_PROC_BROWSER_TEST_F(DragDownloadFileTest, DragDownloadFileTest_Complete) { |
| 112 FilePath name(downloads_directory().AppendASCII( | 112 base::FilePath name(downloads_directory().AppendASCII( |
| 113 "DragDownloadFileTest_Complete.txt")); | 113 "DragDownloadFileTest_Complete.txt")); |
| 114 GURL url(URLRequestMockHTTPJob::GetMockUrl(FilePath(FILE_PATH_LITERAL( | 114 GURL url(URLRequestMockHTTPJob::GetMockUrl(base::FilePath(FILE_PATH_LITERAL( |
| 115 "download-test.lib")))); | 115 "download-test.lib")))); |
| 116 Referrer referrer; | 116 Referrer referrer; |
| 117 std::string referrer_encoding; | 117 std::string referrer_encoding; |
| 118 net::FileStream* stream = NULL; | 118 net::FileStream* stream = NULL; |
| 119 #if defined(OS_POSIX) | 119 #if defined(OS_POSIX) |
| 120 stream = CreateFileStreamForDrop( | 120 stream = CreateFileStreamForDrop( |
| 121 &name, GetContentClient()->browser()->GetNetLog()); | 121 &name, GetContentClient()->browser()->GetNetLog()); |
| 122 #endif | 122 #endif |
| 123 SetUpServer(); | 123 SetUpServer(); |
| 124 DragDownloadFile* file = new DragDownloadFile( | 124 DragDownloadFile* file = new DragDownloadFile( |
| 125 name, scoped_ptr<net::FileStream>(stream), url, referrer, | 125 name, scoped_ptr<net::FileStream>(stream), url, referrer, |
| 126 referrer_encoding, shell()->web_contents()); | 126 referrer_encoding, shell()->web_contents()); |
| 127 scoped_refptr<MockDownloadFileObserver> observer( | 127 scoped_refptr<MockDownloadFileObserver> observer( |
| 128 new MockDownloadFileObserver()); | 128 new MockDownloadFileObserver()); |
| 129 EXPECT_CALL(*observer, OnDownloadCompleted(_)).WillOnce(InvokeWithoutArgs( | 129 EXPECT_CALL(*observer, OnDownloadCompleted(_)).WillOnce(InvokeWithoutArgs( |
| 130 this, &DragDownloadFileTest::Succeed)); | 130 this, &DragDownloadFileTest::Succeed)); |
| 131 ON_CALL(*observer, OnDownloadAborted()).WillByDefault(InvokeWithoutArgs( | 131 ON_CALL(*observer, OnDownloadAborted()).WillByDefault(InvokeWithoutArgs( |
| 132 this, &DragDownloadFileTest::FailFast)); | 132 this, &DragDownloadFileTest::FailFast)); |
| 133 file->Start(observer); | 133 file->Start(observer); |
| 134 RunMessageLoop(); | 134 RunMessageLoop(); |
| 135 } | 135 } |
| 136 | 136 |
| 137 // TODO(benjhayden): Test Stop(). | 137 // TODO(benjhayden): Test Stop(). |
| 138 | 138 |
| 139 } // namespace content | 139 } // namespace content |
| OLD | NEW |