Chromium Code Reviews| 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 <sstream> | 5 #include <sstream> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 return item->GetAutoOpened(); | 160 return item->GetAutoOpened(); |
| 161 } | 161 } |
| 162 | 162 |
| 163 // Called when a download starts. Marks the download as hidden. | 163 // Called when a download starts. Marks the download as hidden. |
| 164 void SetHiddenDownloadCallback(DownloadItem* item, net::Error error) { | 164 void SetHiddenDownloadCallback(DownloadItem* item, net::Error error) { |
| 165 DownloadItemModel(item).SetShouldShowInShelf(false); | 165 DownloadItemModel(item).SetShouldShowInShelf(false); |
| 166 } | 166 } |
| 167 | 167 |
| 168 } // namespace | 168 } // namespace |
| 169 | 169 |
| 170 // While an object of this class exists, it will mock out download | |
| 171 // opening for all downloads created on the specified download manager. | |
| 172 class MockDownloadOpeningObserver : public DownloadManager::Observer { | |
| 173 public: | |
| 174 explicit MockDownloadOpeningObserver(DownloadManager* manager) | |
| 175 : download_manager_(manager) { | |
| 176 download_manager_->AddObserver(this); | |
| 177 } | |
| 178 | |
| 179 ~MockDownloadOpeningObserver() { | |
| 180 download_manager_->RemoveObserver(this); | |
| 181 } | |
| 182 | |
| 183 virtual void OnDownloadCreated( | |
| 184 DownloadManager* manager, DownloadItem* item) OVERRIDE { | |
| 185 item->MockDownloadOpenForTesting(); | |
| 186 } | |
| 187 | |
| 188 private: | |
| 189 DownloadManager* download_manager_; | |
| 190 | |
| 191 DISALLOW_COPY_AND_ASSIGN(MockDownloadOpeningObserver); | |
| 192 }; | |
| 193 | |
| 194 class HistoryObserver : public DownloadHistory::Observer { | 170 class HistoryObserver : public DownloadHistory::Observer { |
| 195 public: | 171 public: |
| 196 explicit HistoryObserver(Profile* profile) | 172 explicit HistoryObserver(Profile* profile) |
| 197 : profile_(profile), | 173 : profile_(profile), |
| 198 waiting_(false), | 174 waiting_(false), |
| 199 seen_stored_(false) { | 175 seen_stored_(false) { |
| 200 DownloadServiceFactory::GetForProfile(profile_)-> | 176 DownloadServiceFactory::GetForProfile(profile_)-> |
| 201 GetDownloadHistory()->AddObserver(this); | 177 GetDownloadHistory()->AddObserver(this); |
| 202 } | 178 } |
| 203 | 179 |
| (...skipping 1276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1480 } | 1456 } |
| 1481 | 1457 |
| 1482 // Test to make sure auto-open works. | 1458 // Test to make sure auto-open works. |
| 1483 IN_PROC_BROWSER_TEST_F(DownloadTest, AutoOpen) { | 1459 IN_PROC_BROWSER_TEST_F(DownloadTest, AutoOpen) { |
| 1484 FilePath file(FILE_PATH_LITERAL("download-autoopen.txt")); | 1460 FilePath file(FILE_PATH_LITERAL("download-autoopen.txt")); |
| 1485 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1461 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1486 | 1462 |
| 1487 ASSERT_TRUE( | 1463 ASSERT_TRUE( |
| 1488 GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file)); | 1464 GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file)); |
| 1489 | 1465 |
| 1490 // Mock out external opening on all downloads until end of test. | 1466 DownloadManagerForBrowser(browser())->MockDownloadOpenForTesting(); |
|
Randy Smith (Not in Mondays)
2013/01/18 18:53:37
The better way to do this (given that the DMD now
hashimoto
2013/01/21 10:54:25
Filed in http://crbug.com/171224.
| |
| 1491 MockDownloadOpeningObserver observer(DownloadManagerForBrowser(browser())); | |
| 1492 | 1467 |
| 1493 DownloadAndWait(browser(), url); | 1468 DownloadAndWait(browser(), url); |
| 1494 | 1469 |
| 1495 // Find the download and confirm it was opened. | 1470 // Find the download and confirm it was opened. |
| 1496 std::vector<DownloadItem*> downloads; | 1471 std::vector<DownloadItem*> downloads; |
| 1497 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); | 1472 DownloadManagerForBrowser(browser())->GetAllDownloads(&downloads); |
| 1498 ASSERT_EQ(1u, downloads.size()); | 1473 ASSERT_EQ(1u, downloads.size()); |
| 1499 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0]->GetState()); | 1474 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0]->GetState()); |
| 1500 | 1475 |
| 1501 // Unfortunately, this will block forever, causing a timeout, if | 1476 // Unfortunately, this will block forever, causing a timeout, if |
| (...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2225 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 2200 WebContents* web_contents = chrome::GetActiveWebContents(browser()); |
| 2226 scoped_ptr<DownloadUrlParameters> params( | 2201 scoped_ptr<DownloadUrlParameters> params( |
| 2227 DownloadUrlParameters::FromWebContents(web_contents, url)); | 2202 DownloadUrlParameters::FromWebContents(web_contents, url)); |
| 2228 params->set_callback(base::Bind(&SetHiddenDownloadCallback)); | 2203 params->set_callback(base::Bind(&SetHiddenDownloadCallback)); |
| 2229 download_manager->DownloadUrl(params.Pass()); | 2204 download_manager->DownloadUrl(params.Pass()); |
| 2230 observer->WaitForFinished(); | 2205 observer->WaitForFinished(); |
| 2231 | 2206 |
| 2232 // Verify that download shelf is not shown. | 2207 // Verify that download shelf is not shown. |
| 2233 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 2208 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
| 2234 } | 2209 } |
| OLD | NEW |