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 "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/observer_list.h" | 8 #include "base/observer_list.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 static void NullPromptUser( | 173 static void NullPromptUser( |
174 DownloadItem* download, const base::FilePath& suggested_path, | 174 DownloadItem* download, const base::FilePath& suggested_path, |
175 const FileSelectedCallback& callback); | 175 const FileSelectedCallback& callback); |
176 static void NullDetermineLocalPath( | 176 static void NullDetermineLocalPath( |
177 DownloadItem* download, const base::FilePath& virtual_path, | 177 DownloadItem* download, const base::FilePath& virtual_path, |
178 const LocalPathCallback& callback); | 178 const LocalPathCallback& callback); |
179 }; | 179 }; |
180 | 180 |
181 class DownloadTargetDeterminerTest : public ChromeRenderViewHostTestHarness { | 181 class DownloadTargetDeterminerTest : public ChromeRenderViewHostTestHarness { |
182 public: | 182 public: |
183 DownloadTargetDeterminerTest(); | |
184 | |
185 // ::testing::Test | 183 // ::testing::Test |
186 virtual void SetUp() OVERRIDE; | 184 virtual void SetUp() OVERRIDE; |
187 virtual void TearDown() OVERRIDE; | 185 virtual void TearDown() OVERRIDE; |
188 | 186 |
189 // Creates MockDownloadItem and sets up default expectations. | 187 // Creates MockDownloadItem and sets up default expectations. |
190 content::MockDownloadItem* CreateActiveDownloadItem( | 188 content::MockDownloadItem* CreateActiveDownloadItem( |
191 int32 id, | 189 int32 id, |
192 const DownloadTestCase& test_case); | 190 const DownloadTestCase& test_case); |
193 | 191 |
194 // Sets the AutoOpenBasedOnExtension user preference for |path|. | 192 // Sets the AutoOpenBasedOnExtension user preference for |path|. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 DownloadPrefs* download_prefs() { | 238 DownloadPrefs* download_prefs() { |
241 return download_prefs_.get(); | 239 return download_prefs_.get(); |
242 } | 240 } |
243 | 241 |
244 private: | 242 private: |
245 scoped_ptr<DownloadPrefs> download_prefs_; | 243 scoped_ptr<DownloadPrefs> download_prefs_; |
246 ::testing::NiceMock<MockDownloadTargetDeterminerDelegate> delegate_; | 244 ::testing::NiceMock<MockDownloadTargetDeterminerDelegate> delegate_; |
247 NullWebContentsDelegate web_contents_delegate_; | 245 NullWebContentsDelegate web_contents_delegate_; |
248 base::ScopedTempDir test_download_dir_; | 246 base::ScopedTempDir test_download_dir_; |
249 base::FilePath test_virtual_dir_; | 247 base::FilePath test_virtual_dir_; |
250 content::TestBrowserThread ui_thread_; | |
251 content::TestBrowserThread file_thread_; | |
252 }; | 248 }; |
253 | 249 |
254 DownloadTargetDeterminerTest::DownloadTargetDeterminerTest() | |
255 : ChromeRenderViewHostTestHarness(), | |
256 ui_thread_(content::BrowserThread::UI, &message_loop_), | |
257 file_thread_(content::BrowserThread::FILE, &message_loop_) { | |
258 } | |
259 | |
260 void DownloadTargetDeterminerTest::SetUp() { | 250 void DownloadTargetDeterminerTest::SetUp() { |
261 ChromeRenderViewHostTestHarness::SetUp(); | 251 ChromeRenderViewHostTestHarness::SetUp(); |
262 CHECK(profile()); | 252 CHECK(profile()); |
263 download_prefs_.reset(new DownloadPrefs(profile())); | 253 download_prefs_.reset(new DownloadPrefs(profile())); |
264 web_contents()->SetDelegate(&web_contents_delegate_); | 254 web_contents()->SetDelegate(&web_contents_delegate_); |
265 ASSERT_TRUE(test_download_dir_.CreateUniqueTempDir()); | 255 ASSERT_TRUE(test_download_dir_.CreateUniqueTempDir()); |
266 test_virtual_dir_ = test_download_dir().Append(FILE_PATH_LITERAL("virtual")); | 256 test_virtual_dir_ = test_download_dir().Append(FILE_PATH_LITERAL("virtual")); |
267 download_prefs_->SetDownloadPath(test_download_dir()); | 257 download_prefs_->SetDownloadPath(test_download_dir()); |
268 delegate_.SetupDefaults(); | 258 delegate_.SetupDefaults(); |
269 } | 259 } |
270 | 260 |
271 void DownloadTargetDeterminerTest::TearDown() { | 261 void DownloadTargetDeterminerTest::TearDown() { |
272 download_prefs_.reset(); | 262 download_prefs_.reset(); |
273 message_loop_.RunUntilIdle(); | |
274 ChromeRenderViewHostTestHarness::TearDown(); | 263 ChromeRenderViewHostTestHarness::TearDown(); |
275 } | 264 } |
276 | 265 |
277 content::MockDownloadItem* | 266 content::MockDownloadItem* |
278 DownloadTargetDeterminerTest::CreateActiveDownloadItem( | 267 DownloadTargetDeterminerTest::CreateActiveDownloadItem( |
279 int32 id, | 268 int32 id, |
280 const DownloadTestCase& test_case) { | 269 const DownloadTestCase& test_case) { |
281 content::MockDownloadItem* item = | 270 content::MockDownloadItem* item = |
282 new ::testing::NiceMock<content::MockDownloadItem>(); | 271 new ::testing::NiceMock<content::MockDownloadItem>(); |
283 GURL download_url(test_case.url); | 272 GURL download_url(test_case.url); |
(...skipping 1598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1882 GetPathInDownloadDir(kInitialPath), | 1871 GetPathInDownloadDir(kInitialPath), |
1883 download_prefs(), | 1872 download_prefs(), |
1884 delegate(), | 1873 delegate(), |
1885 test_callback); | 1874 test_callback); |
1886 run_loop.Run(); | 1875 run_loop.Run(); |
1887 ::testing::Mock::VerifyAndClearExpectations(delegate()); | 1876 ::testing::Mock::VerifyAndClearExpectations(delegate()); |
1888 } | 1877 } |
1889 } | 1878 } |
1890 | 1879 |
1891 } // namespace | 1880 } // namespace |
OLD | NEW |