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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 return false; | 196 return false; |
197 } | 197 } |
198 | 198 |
199 DISALLOW_COPY_AND_ASSIGN(TestRenderViewContextMenu); | 199 DISALLOW_COPY_AND_ASSIGN(TestRenderViewContextMenu); |
200 }; | 200 }; |
201 | 201 |
202 bool WasAutoOpened(DownloadItem* item) { | 202 bool WasAutoOpened(DownloadItem* item) { |
203 return item->GetAutoOpened(); | 203 return item->GetAutoOpened(); |
204 } | 204 } |
205 | 205 |
206 // Called when a download starts. Marks the download as hidden. | |
207 void SetHiddenDownloadCallback(scoped_refptr<DownloadManager> download_manager, | |
208 content::DownloadId id, | |
209 net::Error error) { | |
210 DownloadItem* item = download_manager->GetDownload(id.local()); | |
211 item->SetShouldShowInShelf(item, false); | |
Randy Smith (Not in Mondays)
2012/10/09 19:36:06
How does this work? Or is it left over from a pre
sail
2012/10/09 19:46:13
Done.
argh, merge conflict. Fixed.
| |
212 } | |
213 | |
206 } // namespace | 214 } // namespace |
207 | 215 |
208 // While an object of this class exists, it will mock out download | 216 // While an object of this class exists, it will mock out download |
209 // opening for all downloads created on the specified download manager. | 217 // opening for all downloads created on the specified download manager. |
210 class MockDownloadOpeningObserver : public DownloadManager::Observer { | 218 class MockDownloadOpeningObserver : public DownloadManager::Observer { |
211 public: | 219 public: |
212 explicit MockDownloadOpeningObserver(DownloadManager* manager) | 220 explicit MockDownloadOpeningObserver(DownloadManager* manager) |
213 : download_manager_(manager) { | 221 : download_manager_(manager) { |
214 download_manager_->AddObserver(this); | 222 download_manager_->AddObserver(this); |
215 } | 223 } |
(...skipping 2021 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2237 GetDownloads(browser(), &download_items); | 2245 GetDownloads(browser(), &download_items); |
2238 ASSERT_EQ(1u, download_items.size()); | 2246 ASSERT_EQ(1u, download_items.size()); |
2239 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), | 2247 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), |
2240 download_items[0]->GetOriginalUrl()); | 2248 download_items[0]->GetOriginalUrl()); |
2241 | 2249 |
2242 // Check that the file contains the expected referrer. | 2250 // Check that the file contains the expected referrer. |
2243 FilePath file(download_items[0]->GetFullPath()); | 2251 FilePath file(download_items[0]->GetFullPath()); |
2244 std::string expected_contents = test_server()->GetURL("").spec(); | 2252 std::string expected_contents = test_server()->GetURL("").spec(); |
2245 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); | 2253 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); |
2246 } | 2254 } |
2255 | |
2256 IN_PROC_BROWSER_TEST_F(DownloadTest, HiddenDownload) { | |
2257 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | |
2258 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | |
2259 | |
2260 scoped_refptr<DownloadManager> download_manager = | |
2261 DownloadManagerForBrowser(browser()); | |
2262 scoped_ptr<content::DownloadTestObserver> observer( | |
2263 new content::DownloadTestObserverTerminal( | |
2264 download_manager, | |
2265 1, | |
2266 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | |
2267 content::DownloadSaveInfo save_info; | |
2268 save_info.prompt_for_save_location = false; | |
2269 | |
2270 // Download and set IsHiddenDownload to true. | |
2271 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | |
2272 scoped_ptr<DownloadUrlParameters> params( | |
2273 DownloadUrlParameters::FromWebContents(web_contents, url, save_info)); | |
2274 params->set_callback( | |
2275 base::Bind(&SetHiddenDownloadCallback, download_manager)); | |
2276 download_manager->DownloadUrl(params.Pass()); | |
2277 observer->WaitForFinished(); | |
2278 | |
2279 // Verify that download shelf is not shown. | |
2280 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | |
2281 } | |
OLD | NEW |