Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Side by Side Diff: chrome/browser/download/download_browsertest.cc

Issue 10704052: Download filename determination refactor (3/3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge with r148594 to and resolve conflicts with r148576 Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/scoped_temp_dir.h" 13 #include "base/scoped_temp_dir.h"
14 #include "base/stl_util.h" 14 #include "base/stl_util.h"
15 #include "base/stringprintf.h" 15 #include "base/stringprintf.h"
16 #include "base/test/test_file_util.h" 16 #include "base/test/test_file_util.h"
17 #include "base/utf_string_conversions.h" 17 #include "base/utf_string_conversions.h"
18 #include "chrome/app/chrome_command_ids.h" 18 #include "chrome/app/chrome_command_ids.h"
19 #include "chrome/browser/browser_process.h" 19 #include "chrome/browser/browser_process.h"
20 #include "chrome/browser/cancelable_request.h" 20 #include "chrome/browser/cancelable_request.h"
21 #include "chrome/browser/download/chrome_download_manager_delegate.h" 21 #include "chrome/browser/download/chrome_download_manager_delegate.h"
22 #include "chrome/browser/download/download_crx_util.h" 22 #include "chrome/browser/download/download_crx_util.h"
23 #include "chrome/browser/download/download_history.h" 23 #include "chrome/browser/download/download_history.h"
24 #include "chrome/browser/download/download_prefs.h" 24 #include "chrome/browser/download/download_prefs.h"
25 #include "chrome/browser/download/download_request_limiter.h" 25 #include "chrome/browser/download/download_request_limiter.h"
26 #include "chrome/browser/download/download_service.h"
27 #include "chrome/browser/download/download_service_factory.h"
28 #include "chrome/browser/download/download_shelf.h" 26 #include "chrome/browser/download/download_shelf.h"
29 #include "chrome/browser/download/download_test_observer.h" 27 #include "chrome/browser/download/download_test_observer.h"
30 #include "chrome/browser/download/download_util.h" 28 #include "chrome/browser/download/download_util.h"
31 #include "chrome/browser/extensions/extension_install_prompt.h" 29 #include "chrome/browser/extensions/extension_install_prompt.h"
32 #include "chrome/browser/extensions/extension_service.h" 30 #include "chrome/browser/extensions/extension_service.h"
33 #include "chrome/browser/history/history.h" 31 #include "chrome/browser/history/history.h"
34 #include "chrome/browser/history/history_service_factory.h" 32 #include "chrome/browser/history/history_service_factory.h"
35 #include "chrome/browser/net/url_request_mock_util.h" 33 #include "chrome/browser/net/url_request_mock_util.h"
36 #include "chrome/browser/prefs/pref_service.h" 34 #include "chrome/browser/prefs/pref_service.h"
37 #include "chrome/browser/profiles/profile.h" 35 #include "chrome/browser/profiles/profile.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 78
81 namespace { 79 namespace {
82 80
83 // IDs and paths of CRX files used in tests. 81 // IDs and paths of CRX files used in tests.
84 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; 82 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf";
85 const FilePath kGoodCrxPath(FILE_PATH_LITERAL("extensions/good.crx")); 83 const FilePath kGoodCrxPath(FILE_PATH_LITERAL("extensions/good.crx"));
86 84
87 const char kLargeThemeCrxId[] = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; 85 const char kLargeThemeCrxId[] = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf";
88 const FilePath kLargeThemePath(FILE_PATH_LITERAL("extensions/theme2.crx")); 86 const FilePath kLargeThemePath(FILE_PATH_LITERAL("extensions/theme2.crx"));
89 87
90 class PickSuggestedFileDelegate : public ChromeDownloadManagerDelegate {
91 public:
92 explicit PickSuggestedFileDelegate(Profile* profile)
93 : ChromeDownloadManagerDelegate(profile) {
94 }
95
96 virtual void ChooseDownloadPath(DownloadItem* item) OVERRIDE {
97 if (download_manager_)
98 download_manager_->FileSelected(item->GetTargetFilePath(), item->GetId());
99 }
100
101 protected:
102 virtual ~PickSuggestedFileDelegate() {}
103 };
104
105 // Get History Information. 88 // Get History Information.
106 class DownloadsHistoryDataCollector { 89 class DownloadsHistoryDataCollector {
107 public: 90 public:
108 DownloadsHistoryDataCollector(int64 download_db_handle, 91 DownloadsHistoryDataCollector(int64 download_db_handle,
109 DownloadManager* manager) 92 DownloadManager* manager)
110 : result_valid_(false), 93 : result_valid_(false),
111 download_db_handle_(download_db_handle) { 94 download_db_handle_(download_db_handle) {
112 HistoryService* hs = HistoryServiceFactory::GetForProfile( 95 HistoryService* hs = HistoryServiceFactory::GetForProfile(
113 Profile::FromBrowserContext(manager->GetBrowserContext()), 96 Profile::FromBrowserContext(manager->GetBrowserContext()),
114 Profile::EXPLICIT_ACCESS); 97 Profile::EXPLICIT_ACCESS);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 } 224 }
242 225
243 private: 226 private:
244 DownloadManager* download_manager_; 227 DownloadManager* download_manager_;
245 228
246 DISALLOW_COPY_AND_ASSIGN(MockDownloadOpeningObserver); 229 DISALLOW_COPY_AND_ASSIGN(MockDownloadOpeningObserver);
247 }; 230 };
248 231
249 class DownloadTest : public InProcessBrowserTest { 232 class DownloadTest : public InProcessBrowserTest {
250 public: 233 public:
251 enum SelectExpectation {
252 EXPECT_NO_SELECT_DIALOG = -1,
253 EXPECT_NOTHING,
254 EXPECT_SELECT_DIALOG
255 };
256
257 // Choice of navigation or direct fetch. Used by |DownloadFileCheckErrors()|. 234 // Choice of navigation or direct fetch. Used by |DownloadFileCheckErrors()|.
258 enum DownloadMethod { 235 enum DownloadMethod {
259 DOWNLOAD_NAVIGATE, 236 DOWNLOAD_NAVIGATE,
260 DOWNLOAD_DIRECT 237 DOWNLOAD_DIRECT
261 }; 238 };
262 239
263 // Information passed in to |DownloadFileCheckErrors()|. 240 // Information passed in to |DownloadFileCheckErrors()|.
264 struct DownloadInfo { 241 struct DownloadInfo {
265 const char* url_name; // URL for the download. 242 const char* url_name; // URL for the download.
266 DownloadMethod download_method; // Navigation or Direct. 243 DownloadMethod download_method; // Navigation or Direct.
267 // Download interrupt reason (NONE is OK). 244 // Download interrupt reason (NONE is OK).
268 content::DownloadInterruptReason reason; 245 content::DownloadInterruptReason reason;
269 bool show_download_item; // True if the download item appears on the shelf. 246 bool show_download_item; // True if the download item appears on the shelf.
270 bool should_redirect_to_documents; // True if we save it in "My Documents". 247 bool should_redirect_to_documents; // True if we save it in "My Documents".
271 }; 248 };
272 249
273 struct FileErrorInjectInfo { 250 struct FileErrorInjectInfo {
274 DownloadInfo download_info; 251 DownloadInfo download_info;
275 content::TestFileErrorInjector::FileErrorInfo error_info; 252 content::TestFileErrorInjector::FileErrorInfo error_info;
276 }; 253 };
277 254
278 DownloadTest() {} 255 DownloadTest() {}
279 256
280 void SetUpOnMainThread() OVERRIDE { 257 virtual void SetUpOnMainThread() OVERRIDE {
281 BrowserThread::PostTask( 258 BrowserThread::PostTask(
282 BrowserThread::IO, FROM_HERE, 259 BrowserThread::IO, FROM_HERE,
283 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); 260 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true));
284 ASSERT_TRUE(InitialSetup()); 261 ASSERT_TRUE(InitialSetup());
285 } 262 }
286 263
264 virtual void CleanUpOnMainThread() OVERRIDE {
265 // Needs to be torn down on the main thread. file_chooser_observer_ holds a
266 // reference to the ChromeDownloadManagerDelegate which should be destroyed
267 // on the UI thread.
268 file_chooser_observer_.reset();
269 }
270
287 // Returning false indicates a failure of the setup, and should be asserted 271 // Returning false indicates a failure of the setup, and should be asserted
288 // in the caller. 272 // in the caller.
289 virtual bool InitialSetup() { 273 virtual bool InitialSetup() {
290 bool have_test_dir = PathService::Get(chrome::DIR_TEST_DATA, &test_dir_); 274 bool have_test_dir = PathService::Get(chrome::DIR_TEST_DATA, &test_dir_);
291 EXPECT_TRUE(have_test_dir); 275 EXPECT_TRUE(have_test_dir);
292 if (!have_test_dir) 276 if (!have_test_dir)
293 return false; 277 return false;
294 278
295 // Sanity check default values for window / tab count and shelf visibility. 279 // Sanity check default values for window / tab count and shelf visibility.
296 int window_count = BrowserList::size(); 280 int window_count = BrowserList::size();
297 EXPECT_EQ(1, window_count); 281 EXPECT_EQ(1, window_count);
298 EXPECT_EQ(1, browser()->tab_count()); 282 EXPECT_EQ(1, browser()->tab_count());
299 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); 283 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
300 284
301 // Set up the temporary download folder. 285 // Set up the temporary download folder.
302 bool created_downloads_dir = CreateAndSetDownloadsDirectory(browser()); 286 bool created_downloads_dir = CreateAndSetDownloadsDirectory(browser());
303 EXPECT_TRUE(created_downloads_dir); 287 EXPECT_TRUE(created_downloads_dir);
304 if (!created_downloads_dir) 288 if (!created_downloads_dir)
305 return false; 289 return false;
306 browser()->profile()->GetPrefs()->SetBoolean( 290 browser()->profile()->GetPrefs()->SetBoolean(
307 prefs::kPromptForDownload, false); 291 prefs::kPromptForDownload, false);
308 292
309 DownloadManager* manager = DownloadManagerForBrowser(browser()); 293 DownloadManager* manager = DownloadManagerForBrowser(browser());
310 DownloadPrefs::FromDownloadManager(manager)->ResetAutoOpen(); 294 DownloadPrefs::FromDownloadManager(manager)->ResetAutoOpen();
311 manager->RemoveAllDownloads(); 295 manager->RemoveAllDownloads();
312 296
297 file_chooser_observer_.reset(
298 new DownloadTestFileChooserObserver(browser()->profile()));
299
313 return true; 300 return true;
314 } 301 }
315 302
316 protected: 303 protected:
317 304
318 enum SizeTestType { 305 enum SizeTestType {
319 SIZE_TEST_TYPE_KNOWN, 306 SIZE_TEST_TYPE_KNOWN,
320 SIZE_TEST_TYPE_UNKNOWN, 307 SIZE_TEST_TYPE_UNKNOWN,
321 }; 308 };
322 309
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 FilePath GetDownloadDirectory(Browser* browser) { 343 FilePath GetDownloadDirectory(Browser* browser) {
357 return GetDownloadPrefs(browser)->DownloadPath(); 344 return GetDownloadPrefs(browser)->DownloadPath();
358 } 345 }
359 346
360 // Create a DownloadTestObserverTerminal that will wait for the 347 // Create a DownloadTestObserverTerminal that will wait for the
361 // specified number of downloads to finish. 348 // specified number of downloads to finish.
362 DownloadTestObserver* CreateWaiter(Browser* browser, int num_downloads) { 349 DownloadTestObserver* CreateWaiter(Browser* browser, int num_downloads) {
363 DownloadManager* download_manager = DownloadManagerForBrowser(browser); 350 DownloadManager* download_manager = DownloadManagerForBrowser(browser);
364 return new DownloadTestObserverTerminal( 351 return new DownloadTestObserverTerminal(
365 download_manager, num_downloads, 352 download_manager, num_downloads,
366 true, // Bail on select file
367 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); 353 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL);
368 } 354 }
369 355
370 // Create a DownloadTestObserverInProgress that will wait for the 356 // Create a DownloadTestObserverInProgress that will wait for the
371 // specified number of downloads to start. 357 // specified number of downloads to start.
372 DownloadTestObserver* CreateInProgressWaiter(Browser* browser, 358 DownloadTestObserver* CreateInProgressWaiter(Browser* browser,
373 int num_downloads) { 359 int num_downloads) {
374 DownloadManager* download_manager = DownloadManagerForBrowser(browser); 360 DownloadManager* download_manager = DownloadManagerForBrowser(browser);
375 return new DownloadTestObserverInProgress( 361 return new DownloadTestObserverInProgress(
376 download_manager, num_downloads, true); // Bail on select file. 362 download_manager, num_downloads);
377 } 363 }
378 364
379 // Create a DownloadTestObserverTerminal that will wait for the 365 // Create a DownloadTestObserverTerminal that will wait for the
380 // specified number of downloads to finish, or for 366 // specified number of downloads to finish, or for
381 // a dangerous download warning to be shown. 367 // a dangerous download warning to be shown.
382 DownloadTestObserver* DangerousDownloadWaiter( 368 DownloadTestObserver* DangerousDownloadWaiter(
383 Browser* browser, 369 Browser* browser,
384 int num_downloads, 370 int num_downloads,
385 DownloadTestObserver::DangerousDownloadAction dangerous_download_action) { 371 DownloadTestObserver::DangerousDownloadAction dangerous_download_action) {
386 DownloadManager* download_manager = DownloadManagerForBrowser(browser); 372 DownloadManager* download_manager = DownloadManagerForBrowser(browser);
387 return new DownloadTestObserverTerminal( 373 return new DownloadTestObserverTerminal(
388 download_manager, num_downloads, 374 download_manager, num_downloads,
389 true, // Bail on select file
390 dangerous_download_action); 375 dangerous_download_action);
391 } 376 }
392 377
393 void CheckDownloadStatesForBrowser(Browser* browser, 378 void CheckDownloadStatesForBrowser(Browser* browser,
394 size_t num, 379 size_t num,
395 DownloadItem::DownloadState state) { 380 DownloadItem::DownloadState state) {
396 std::vector<DownloadItem*> download_items; 381 std::vector<DownloadItem*> download_items;
397 GetDownloads(browser, &download_items); 382 GetDownloads(browser, &download_items);
398 383
399 EXPECT_EQ(num, download_items.size()); 384 EXPECT_EQ(num, download_items.size());
400 385
401 for (size_t i = 0; i < download_items.size(); ++i) { 386 for (size_t i = 0; i < download_items.size(); ++i) {
402 EXPECT_EQ(state, download_items[i]->GetState()) << " Item " << i; 387 EXPECT_EQ(state, download_items[i]->GetState()) << " Item " << i;
403 } 388 }
404 } 389 }
405 390
406 void CheckDownloadStates(size_t num, DownloadItem::DownloadState state) { 391 void CheckDownloadStates(size_t num, DownloadItem::DownloadState state) {
407 CheckDownloadStatesForBrowser(browser(), num, state); 392 CheckDownloadStatesForBrowser(browser(), num, state);
408 } 393 }
409 394
410 // Download |url|, then wait for the download to finish. 395 // Download |url|, then wait for the download to finish.
411 // |disposition| indicates where the navigation occurs (current tab, new 396 // |disposition| indicates where the navigation occurs (current tab, new
412 // foreground tab, etc). 397 // foreground tab, etc).
413 // |expectation| indicates whether or not a Select File dialog should be
414 // open when the download is finished, or if we don't care.
415 // If the dialog appears, the routine exits. The only effect |expectation|
416 // has is whether or not the test succeeds.
417 // |browser_test_flags| indicate what to wait for, and is an OR of 0 or more 398 // |browser_test_flags| indicate what to wait for, and is an OR of 0 or more
418 // values in the ui_test_utils::BrowserTestWaitFlags enum. 399 // values in the ui_test_utils::BrowserTestWaitFlags enum.
419 void DownloadAndWaitWithDisposition(Browser* browser, 400 void DownloadAndWaitWithDisposition(Browser* browser,
420 const GURL& url, 401 const GURL& url,
421 WindowOpenDisposition disposition, 402 WindowOpenDisposition disposition,
422 SelectExpectation expectation,
423 int browser_test_flags) { 403 int browser_test_flags) {
424 // Setup notification, navigate, and block. 404 // Setup notification, navigate, and block.
425 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(browser, 1)); 405 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(browser, 1));
426 // This call will block until the condition specified by 406 // This call will block until the condition specified by
427 // |browser_test_flags|, but will not wait for the download to finish. 407 // |browser_test_flags|, but will not wait for the download to finish.
428 ui_test_utils::NavigateToURLWithDisposition(browser, 408 ui_test_utils::NavigateToURLWithDisposition(browser,
429 url, 409 url,
430 disposition, 410 disposition,
431 browser_test_flags); 411 browser_test_flags);
432 // Waits for the download to complete. 412 // Waits for the download to complete.
433 observer->WaitForFinished(); 413 observer->WaitForFinished();
434 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 414 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
435 415 // We don't expect a file chooser to be shown.
436 // If specified, check the state of the select file dialog. 416 EXPECT_FALSE(DidShowFileChooser());
437 if (expectation != EXPECT_NOTHING) {
438 EXPECT_EQ(expectation == EXPECT_SELECT_DIALOG,
439 observer->select_file_dialog_seen());
440 }
441 } 417 }
442 418
443 // Download a file in the current tab, then wait for the download to finish. 419 // Download a file in the current tab, then wait for the download to finish.
444 void DownloadAndWait(Browser* browser, 420 void DownloadAndWait(Browser* browser,
445 const GURL& url, 421 const GURL& url) {
446 SelectExpectation expectation) {
447 DownloadAndWaitWithDisposition( 422 DownloadAndWaitWithDisposition(
448 browser, 423 browser,
449 url, 424 url,
450 CURRENT_TAB, 425 CURRENT_TAB,
451 expectation,
452 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 426 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
453 } 427 }
454 428
455 // Should only be called when the download is known to have finished 429 // Should only be called when the download is known to have finished
456 // (in error or not). 430 // (in error or not).
457 // Returning false indicates a failure of the function, and should be asserted 431 // Returning false indicates a failure of the function, and should be asserted
458 // in the caller. 432 // in the caller.
459 bool CheckDownload(Browser* browser, 433 bool CheckDownload(Browser* browser,
460 const FilePath& downloaded_filename, 434 const FilePath& downloaded_filename,
461 const FilePath& origin_filename) { 435 const FilePath& origin_filename) {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 void GetDownloads(Browser* browser, std::vector<DownloadItem*>* downloads) { 548 void GetDownloads(Browser* browser, std::vector<DownloadItem*>* downloads) {
575 DCHECK(downloads); 549 DCHECK(downloads);
576 DownloadManager* manager = DownloadManagerForBrowser(browser); 550 DownloadManager* manager = DownloadManagerForBrowser(browser);
577 manager->SearchDownloads(string16(), downloads); 551 manager->SearchDownloads(string16(), downloads);
578 } 552 }
579 553
580 static void ExpectWindowCountAfterDownload(size_t expected) { 554 static void ExpectWindowCountAfterDownload(size_t expected) {
581 EXPECT_EQ(expected, BrowserList::size()); 555 EXPECT_EQ(expected, BrowserList::size());
582 } 556 }
583 557
584 // Arrange for select file calls on the given browser from the 558 void EnableFileChooser(bool enable) {
585 // download manager to always choose the suggested file. 559 file_chooser_observer_->EnableFileChooser(enable);
586 void NullSelectFile(Browser* browser) { 560 }
587 PickSuggestedFileDelegate* new_delegate =
588 new PickSuggestedFileDelegate(browser->profile());
589 561
590 // Gives ownership to DownloadService. 562 bool DidShowFileChooser() {
591 DownloadServiceFactory::GetForProfile( 563 return file_chooser_observer_->TestAndResetDidShowFileChooser();
592 browser->profile())->SetDownloadManagerDelegateForTesting(new_delegate);
593 } 564 }
594 565
595 // Checks that |path| is has |file_size| bytes, and matches the |value| 566 // Checks that |path| is has |file_size| bytes, and matches the |value|
596 // string. 567 // string.
597 bool VerifyFile(const FilePath& path, 568 bool VerifyFile(const FilePath& path,
598 const std::string& value, 569 const std::string& value,
599 const int64 file_size) { 570 const int64 file_size) {
600 std::string file_contents; 571 std::string file_contents;
601 572
602 bool read = file_util::ReadFileToString(path, &file_contents); 573 bool read = file_util::ReadFileToString(path, &file_contents);
(...skipping 19 matching lines...) Expand all
622 } 593 }
623 594
624 // Attempts to download a file, based on information in |download_info|. 595 // Attempts to download a file, based on information in |download_info|.
625 // If a Select File dialog opens, will automatically choose the default. 596 // If a Select File dialog opens, will automatically choose the default.
626 void DownloadFilesCheckErrorsSetup() { 597 void DownloadFilesCheckErrorsSetup() {
627 ASSERT_TRUE(test_server()->Start()); 598 ASSERT_TRUE(test_server()->Start());
628 std::vector<DownloadItem*> download_items; 599 std::vector<DownloadItem*> download_items;
629 GetDownloads(browser(), &download_items); 600 GetDownloads(browser(), &download_items);
630 ASSERT_TRUE(download_items.empty()); 601 ASSERT_TRUE(download_items.empty());
631 602
632 NullSelectFile(browser()); 603 EnableFileChooser(true);
633 } 604 }
634 605
635 void DownloadFilesCheckErrorsLoopBody(const DownloadInfo& download_info, 606 void DownloadFilesCheckErrorsLoopBody(const DownloadInfo& download_info,
636 size_t i) { 607 size_t i) {
637 std::stringstream s; 608 std::stringstream s;
638 s << " " << __FUNCTION__ << "()" 609 s << " " << __FUNCTION__ << "()"
639 << " index = " << i 610 << " index = " << i
640 << " url = '" << download_info.url_name << "'" 611 << " url = '" << download_info.url_name << "'"
641 << " method = " 612 << " method = "
642 << ((download_info.download_method == DOWNLOAD_DIRECT) ? 613 << ((download_info.download_method == DOWNLOAD_DIRECT) ?
(...skipping 12 matching lines...) Expand all
655 ASSERT_TRUE(url.is_valid()) << s.str(); 626 ASSERT_TRUE(url.is_valid()) << s.str();
656 627
657 DownloadManager* download_manager = DownloadManagerForBrowser(browser()); 628 DownloadManager* download_manager = DownloadManagerForBrowser(browser());
658 WebContents* web_contents = chrome::GetActiveWebContents(browser()); 629 WebContents* web_contents = chrome::GetActiveWebContents(browser());
659 ASSERT_TRUE(web_contents) << s.str(); 630 ASSERT_TRUE(web_contents) << s.str();
660 631
661 scoped_ptr<DownloadTestObserver> observer( 632 scoped_ptr<DownloadTestObserver> observer(
662 new DownloadTestObserverTerminal( 633 new DownloadTestObserverTerminal(
663 download_manager, 634 download_manager,
664 1, 635 1,
665 false, // Don't bail on select file.
666 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 636 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
667 637
668 if (download_info.download_method == DOWNLOAD_DIRECT) { 638 if (download_info.download_method == DOWNLOAD_DIRECT) {
669 // Go directly to download. Don't wait for navigation. 639 // Go directly to download. Don't wait for navigation.
670 content::DownloadSaveInfo save_info; 640 content::DownloadSaveInfo save_info;
671 // NOTE: |prompt_for_save_location| may change during the download. 641 // NOTE: |prompt_for_save_location| may change during the download.
672 save_info.prompt_for_save_location = false; 642 save_info.prompt_for_save_location = false;
673 643
674 scoped_refptr<DownloadTestItemCreationObserver> creation_observer( 644 scoped_refptr<DownloadTestItemCreationObserver> creation_observer(
675 new DownloadTestItemCreationObserver); 645 new DownloadTestItemCreationObserver);
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 *result = false; 829 *result = false;
860 BrowserThread::PostTask( 830 BrowserThread::PostTask(
861 BrowserThread::UI, FROM_HERE, MessageLoop::QuitClosure()); 831 BrowserThread::UI, FROM_HERE, MessageLoop::QuitClosure());
862 } 832 }
863 833
864 // Location of the test data. 834 // Location of the test data.
865 FilePath test_dir_; 835 FilePath test_dir_;
866 836
867 // Location of the downloads directory for these tests 837 // Location of the downloads directory for these tests
868 ScopedTempDir downloads_directory_; 838 ScopedTempDir downloads_directory_;
839
840 scoped_ptr<DownloadTestFileChooserObserver> file_chooser_observer_;
869 }; 841 };
870 842
871 // NOTES: 843 // NOTES:
872 // 844 //
873 // Files for these tests are found in DIR_TEST_DATA (currently 845 // Files for these tests are found in DIR_TEST_DATA (currently
874 // "chrome\test\data\", see chrome_paths.cc). 846 // "chrome\test\data\", see chrome_paths.cc).
875 // Mock responses have extension .mock-http-headers appended to the file name. 847 // Mock responses have extension .mock-http-headers appended to the file name.
876 848
877 // Download a file due to the associated MIME type. 849 // Download a file due to the associated MIME type.
878 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeType) { 850 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeType) {
879 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 851 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
880 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 852 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
881 853
882 // Download the file and wait. We do not expect the Select File dialog. 854 // Download the file and wait. We do not expect the Select File dialog.
883 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); 855 DownloadAndWait(browser(), url);
884 856
885 // Check state. 857 // Check state.
886 EXPECT_EQ(1, browser()->tab_count()); 858 EXPECT_EQ(1, browser()->tab_count());
887 CheckDownload(browser(), file, file); 859 CheckDownload(browser(), file, file);
888 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 860 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
889 } 861 }
890 862
891 #if defined(OS_WIN) 863 #if defined(OS_WIN)
892 // Download a file and confirm that the zone identifier (on windows) 864 // Download a file and confirm that the zone identifier (on windows)
893 // is set to internet. 865 // is set to internet.
894 IN_PROC_BROWSER_TEST_F(DownloadTest, CheckInternetZone) { 866 IN_PROC_BROWSER_TEST_F(DownloadTest, CheckInternetZone) {
895 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 867 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
896 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 868 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
897 869
898 // Download the file and wait. We do not expect the Select File dialog. 870 // Download the file and wait. We do not expect the Select File dialog.
899 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); 871 DownloadAndWait(browser(), url);
900 872
901 // Check state. Special file state must be checked before CheckDownload, 873 // Check state. Special file state must be checked before CheckDownload,
902 // as CheckDownload will delete the output file. 874 // as CheckDownload will delete the output file.
903 EXPECT_EQ(1, browser()->tab_count()); 875 EXPECT_EQ(1, browser()->tab_count());
904 FilePath downloaded_file(DestinationFile(browser(), file)); 876 FilePath downloaded_file(DestinationFile(browser(), file));
905 if (file_util::VolumeSupportsADS(downloaded_file)) 877 if (file_util::VolumeSupportsADS(downloaded_file))
906 EXPECT_TRUE(file_util::HasInternetZoneIdentifier(downloaded_file)); 878 EXPECT_TRUE(file_util::HasInternetZoneIdentifier(downloaded_file));
907 CheckDownload(browser(), file, file); 879 CheckDownload(browser(), file, file);
908 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 880 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
909 } 881 }
910 #endif 882 #endif
911 883
912 // Put up a Select File dialog when the file is downloaded, due to 884 // Put up a Select File dialog when the file is downloaded, due to
913 // downloads preferences settings. 885 // downloads preferences settings.
914 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeTypeSelect) { 886 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeTypeSelect) {
915 // Re-enable prompting. 887 // Re-enable prompting.
916 browser()->profile()->GetPrefs()->SetBoolean( 888 browser()->profile()->GetPrefs()->SetBoolean(
917 prefs::kPromptForDownload, true); 889 prefs::kPromptForDownload, true);
918 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 890 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
919 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 891 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
920 892
921 NullSelectFile(browser()); 893 EnableFileChooser(true);
922 894
923 // Download the file and wait. We expect the Select File dialog to appear 895 // Download the file and wait. We expect the Select File dialog to appear
924 // due to the MIME type, but we still wait until the download completes. 896 // due to the MIME type, but we still wait until the download completes.
925 scoped_ptr<DownloadTestObserver> observer( 897 scoped_ptr<DownloadTestObserver> observer(
926 new DownloadTestObserverTerminal( 898 new DownloadTestObserverTerminal(
927 DownloadManagerForBrowser(browser()), 899 DownloadManagerForBrowser(browser()),
928 1, 900 1,
929 false, // Continue on select file.
930 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 901 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
931 ui_test_utils::NavigateToURLWithDisposition( 902 ui_test_utils::NavigateToURLWithDisposition(
932 browser(), url, CURRENT_TAB, 903 browser(), url, CURRENT_TAB,
933 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 904 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
934 observer->WaitForFinished(); 905 observer->WaitForFinished();
935 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 906 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
936 CheckDownloadStates(1, DownloadItem::COMPLETE); 907 CheckDownloadStates(1, DownloadItem::COMPLETE);
937 EXPECT_TRUE(observer->select_file_dialog_seen()); 908 EXPECT_TRUE(DidShowFileChooser());
938 909
939 // Check state. 910 // Check state.
940 EXPECT_EQ(1, browser()->tab_count()); 911 EXPECT_EQ(1, browser()->tab_count());
941 CheckDownload(browser(), file, file); 912 CheckDownload(browser(), file, file);
942 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 913 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
943 } 914 }
944 915
945 // Access a file with a viewable mime-type, verify that a download 916 // Access a file with a viewable mime-type, verify that a download
946 // did not initiate. 917 // did not initiate.
947 IN_PROC_BROWSER_TEST_F(DownloadTest, NoDownload) { 918 IN_PROC_BROWSER_TEST_F(DownloadTest, NoDownload) {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1054 // Download a 0-size file with a content-disposition header, verify that the 1025 // Download a 0-size file with a content-disposition header, verify that the
1055 // download tab opened and the file exists as the filename specified in the 1026 // download tab opened and the file exists as the filename specified in the
1056 // header. This also ensures we properly handle empty file downloads. 1027 // header. This also ensures we properly handle empty file downloads.
1057 // The download shelf should be visible in the current tab. 1028 // The download shelf should be visible in the current tab.
1058 IN_PROC_BROWSER_TEST_F(DownloadTest, ContentDisposition) { 1029 IN_PROC_BROWSER_TEST_F(DownloadTest, ContentDisposition) {
1059 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); 1030 FilePath file(FILE_PATH_LITERAL("download-test3.gif"));
1060 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1031 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1061 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); 1032 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif"));
1062 1033
1063 // Download a file and wait. 1034 // Download a file and wait.
1064 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); 1035 DownloadAndWait(browser(), url);
1065 1036
1066 CheckDownload(browser(), download_file, file); 1037 CheckDownload(browser(), download_file, file);
1067 1038
1068 // Check state. 1039 // Check state.
1069 EXPECT_EQ(1, browser()->tab_count()); 1040 EXPECT_EQ(1, browser()->tab_count());
1070 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 1041 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
1071 } 1042 }
1072 1043
1073 // Test that the download shelf is per-window by starting a download in one 1044 // Test that the download shelf is per-window by starting a download in one
1074 // tab, opening a second tab, closing the shelf, going back to the first tab, 1045 // tab, opening a second tab, closing the shelf, going back to the first tab,
1075 // and checking that the shelf is closed. 1046 // and checking that the shelf is closed.
1076 IN_PROC_BROWSER_TEST_F(DownloadTest, PerWindowShelf) { 1047 IN_PROC_BROWSER_TEST_F(DownloadTest, PerWindowShelf) {
1077 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); 1048 FilePath file(FILE_PATH_LITERAL("download-test3.gif"));
1078 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1049 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1079 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); 1050 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif"));
1080 1051
1081 // Download a file and wait. 1052 // Download a file and wait.
1082 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); 1053 DownloadAndWait(browser(), url);
1083 1054
1084 CheckDownload(browser(), download_file, file); 1055 CheckDownload(browser(), download_file, file);
1085 1056
1086 // Check state. 1057 // Check state.
1087 EXPECT_EQ(1, browser()->tab_count()); 1058 EXPECT_EQ(1, browser()->tab_count());
1088 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 1059 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
1089 1060
1090 // Open a second tab and wait. 1061 // Open a second tab and wait.
1091 EXPECT_NE(static_cast<TabContents*>(NULL), 1062 EXPECT_NE(static_cast<TabContents*>(NULL),
1092 chrome::AddSelectedTabWithURL(browser(), GURL(), 1063 chrome::AddSelectedTabWithURL(browser(), GURL(),
(...skipping 13 matching lines...) Expand all
1106 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); 1077 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
1107 } 1078 }
1108 1079
1109 // Check whether the downloads shelf is closed when the downloads tab is 1080 // Check whether the downloads shelf is closed when the downloads tab is
1110 // invoked. 1081 // invoked.
1111 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseShelfOnDownloadsTab) { 1082 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseShelfOnDownloadsTab) {
1112 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1083 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1113 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1084 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1114 1085
1115 // Download the file and wait. We do not expect the Select File dialog. 1086 // Download the file and wait. We do not expect the Select File dialog.
1116 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); 1087 DownloadAndWait(browser(), url);
1117 1088
1118 // Check state. 1089 // Check state.
1119 EXPECT_EQ(1, browser()->tab_count()); 1090 EXPECT_EQ(1, browser()->tab_count());
1120 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 1091 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
1121 1092
1122 // Open the downloads tab. 1093 // Open the downloads tab.
1123 chrome::ShowDownloads(browser()); 1094 chrome::ShowDownloads(browser());
1124 // The shelf should now be closed. 1095 // The shelf should now be closed.
1125 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); 1096 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
1126 } 1097 }
(...skipping 27 matching lines...) Expand all
1154 int window_count = BrowserList::size(); 1125 int window_count = BrowserList::size();
1155 EXPECT_EQ(2, window_count); 1126 EXPECT_EQ(2, window_count);
1156 1127
1157 // Download a file in the Incognito window and wait. 1128 // Download a file in the Incognito window and wait.
1158 CreateAndSetDownloadsDirectory(incognito); 1129 CreateAndSetDownloadsDirectory(incognito);
1159 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1130 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1160 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1131 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1161 // Since |incognito| is a separate browser, we have to set it up explicitly. 1132 // Since |incognito| is a separate browser, we have to set it up explicitly.
1162 incognito->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload, 1133 incognito->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload,
1163 false); 1134 false);
1164 DownloadAndWait(incognito, url, EXPECT_NO_SELECT_DIALOG); 1135 DownloadAndWait(incognito, url);
1165 1136
1166 // We should still have 2 windows. 1137 // We should still have 2 windows.
1167 ExpectWindowCountAfterDownload(2); 1138 ExpectWindowCountAfterDownload(2);
1168 1139
1169 // Verify that the download shelf is showing for the Incognito window. 1140 // Verify that the download shelf is showing for the Incognito window.
1170 EXPECT_TRUE(incognito->window()->IsDownloadShelfVisible()); 1141 EXPECT_TRUE(incognito->window()->IsDownloadShelfVisible());
1171 1142
1172 #if !defined(OS_MACOSX) 1143 #if !defined(OS_MACOSX)
1173 // On Mac OS X, the UI window close is delayed until the outermost 1144 // On Mac OS X, the UI window close is delayed until the outermost
1174 // message loop runs. So it isn't possible to get a BROWSER_CLOSED 1145 // message loop runs. So it isn't possible to get a BROWSER_CLOSED
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 // automatically, and that the download shelf is visible in the current tab. 1189 // automatically, and that the download shelf is visible in the current tab.
1219 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseNewTab1) { 1190 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseNewTab1) {
1220 // Download a file in a new background tab and wait. The tab is automatically 1191 // Download a file in a new background tab and wait. The tab is automatically
1221 // closed when the download begins. 1192 // closed when the download begins.
1222 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1193 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1223 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1194 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1224 DownloadAndWaitWithDisposition( 1195 DownloadAndWaitWithDisposition(
1225 browser(), 1196 browser(),
1226 url, 1197 url,
1227 NEW_BACKGROUND_TAB, 1198 NEW_BACKGROUND_TAB,
1228 EXPECT_NO_SELECT_DIALOG,
1229 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 1199 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
1230 1200
1231 // When the download finishes, we should still have one tab. 1201 // When the download finishes, we should still have one tab.
1232 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 1202 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
1233 EXPECT_EQ(1, browser()->tab_count()); 1203 EXPECT_EQ(1, browser()->tab_count());
1234 1204
1235 CheckDownload(browser(), file, file); 1205 CheckDownload(browser(), file, file);
1236 } 1206 }
1237 1207
1238 // Open a web page in the current tab, then download a file in another tab via 1208 // Open a web page in the current tab, then download a file in another tab via
(...skipping 10 matching lines...) Expand all
1249 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1)); 1219 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1));
1250 1220
1251 // Open a web page and wait. 1221 // Open a web page and wait.
1252 ui_test_utils::NavigateToURL(browser(), url); 1222 ui_test_utils::NavigateToURL(browser(), url);
1253 1223
1254 // Download a file in a new tab and wait (via Javascript). 1224 // Download a file in a new tab and wait (via Javascript).
1255 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1225 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1256 DownloadAndWaitWithDisposition(browser(), 1226 DownloadAndWaitWithDisposition(browser(),
1257 GURL("javascript:openNew()"), 1227 GURL("javascript:openNew()"),
1258 CURRENT_TAB, 1228 CURRENT_TAB,
1259 EXPECT_NO_SELECT_DIALOG,
1260 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 1229 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
1261 1230
1262 // When the download finishes, we should have two tabs. 1231 // When the download finishes, we should have two tabs.
1263 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 1232 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
1264 EXPECT_EQ(2, browser()->tab_count()); 1233 EXPECT_EQ(2, browser()->tab_count());
1265 1234
1266 CheckDownload(browser(), file, file); 1235 CheckDownload(browser(), file, file);
1267 } 1236 }
1268 1237
1269 // Open a web page in the current tab, open another tab via a Javascript call, 1238 // Open a web page in the current tab, open another tab via a Javascript call,
(...skipping 20 matching lines...) Expand all
1290 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 1259 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
1291 1260
1292 EXPECT_EQ(2, browser()->tab_count()); 1261 EXPECT_EQ(2, browser()->tab_count());
1293 1262
1294 // Download a file and wait. 1263 // Download a file and wait.
1295 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1264 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1296 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1265 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1297 DownloadAndWaitWithDisposition(browser(), 1266 DownloadAndWaitWithDisposition(browser(),
1298 url, 1267 url,
1299 CURRENT_TAB, 1268 CURRENT_TAB,
1300 EXPECT_NO_SELECT_DIALOG,
1301 ui_test_utils::BROWSER_TEST_NONE); 1269 ui_test_utils::BROWSER_TEST_NONE);
1302 1270
1303 // When the download finishes, we should have two tabs. 1271 // When the download finishes, we should have two tabs.
1304 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 1272 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
1305 EXPECT_EQ(2, browser()->tab_count()); 1273 EXPECT_EQ(2, browser()->tab_count());
1306 1274
1307 CheckDownload(browser(), file, file); 1275 CheckDownload(browser(), file, file);
1308 } 1276 }
1309 1277
1310 // Open a web page in the current tab, then download a file via Javascript, 1278 // Open a web page in the current tab, then download a file via Javascript,
(...skipping 11 matching lines...) Expand all
1322 1290
1323 // Open a web page and wait. 1291 // Open a web page and wait.
1324 ui_test_utils::NavigateToURL(browser(), url); 1292 ui_test_utils::NavigateToURL(browser(), url);
1325 1293
1326 // Download a file and wait. 1294 // Download a file and wait.
1327 // The file to download is "download-test1.lib". 1295 // The file to download is "download-test1.lib".
1328 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1296 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1329 DownloadAndWaitWithDisposition(browser(), 1297 DownloadAndWaitWithDisposition(browser(),
1330 GURL("javascript:openNew()"), 1298 GURL("javascript:openNew()"),
1331 CURRENT_TAB, 1299 CURRENT_TAB,
1332 EXPECT_NO_SELECT_DIALOG,
1333 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 1300 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
1334 1301
1335 // When the download finishes, we should still have one tab. 1302 // When the download finishes, we should still have one tab.
1336 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 1303 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
1337 EXPECT_EQ(1, browser()->tab_count()); 1304 EXPECT_EQ(1, browser()->tab_count());
1338 1305
1339 CheckDownload(browser(), file, file); 1306 CheckDownload(browser(), file, file);
1340 } 1307 }
1341 1308
1342 // Open a web page in the current tab, then call Javascript via a button to 1309 // Open a web page in the current tab, then call Javascript via a button to
(...skipping 13 matching lines...) Expand all
1356 ui_test_utils::NavigateToURL(browser(), url); 1323 ui_test_utils::NavigateToURL(browser(), url);
1357 1324
1358 // Download a file in a new tab and wait. The tab will automatically close 1325 // Download a file in a new tab and wait. The tab will automatically close
1359 // when the download begins. 1326 // when the download begins.
1360 // The file to download is "download-test1.lib". 1327 // The file to download is "download-test1.lib".
1361 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1328 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1362 DownloadAndWaitWithDisposition( 1329 DownloadAndWaitWithDisposition(
1363 browser(), 1330 browser(),
1364 GURL("javascript:document.getElementById('form').submit()"), 1331 GURL("javascript:document.getElementById('form').submit()"),
1365 CURRENT_TAB, 1332 CURRENT_TAB,
1366 EXPECT_NO_SELECT_DIALOG,
1367 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); 1333 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
1368 1334
1369 // When the download finishes, we should still have one tab. 1335 // When the download finishes, we should still have one tab.
1370 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 1336 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
1371 EXPECT_EQ(1, browser()->tab_count()); 1337 EXPECT_EQ(1, browser()->tab_count());
1372 1338
1373 CheckDownload(browser(), file, file); 1339 CheckDownload(browser(), file, file);
1374 } 1340 }
1375 1341
1376 // Download a file in a new window. 1342 // Download a file in a new window.
1377 // Verify that we have 2 windows, and the download shelf is not visible in the 1343 // Verify that we have 2 windows, and the download shelf is not visible in the
1378 // first window, but is visible in the second window. 1344 // first window, but is visible in the second window.
1379 // Close the new window. 1345 // Close the new window.
1380 // Verify that we have 1 window, and the download shelf is not visible. 1346 // Verify that we have 1 window, and the download shelf is not visible.
1381 // 1347 //
1382 // Regression test for http://crbug.com/44454 1348 // Regression test for http://crbug.com/44454
1383 IN_PROC_BROWSER_TEST_F(DownloadTest, NewWindow) { 1349 IN_PROC_BROWSER_TEST_F(DownloadTest, NewWindow) {
1384 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1350 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1385 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1351 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1386 #if !defined(OS_MACOSX) 1352 #if !defined(OS_MACOSX)
1387 // See below. 1353 // See below.
1388 Browser* first_browser = browser(); 1354 Browser* first_browser = browser();
1389 #endif 1355 #endif
1390 1356
1391 // Download a file in a new window and wait. 1357 // Download a file in a new window and wait.
1392 DownloadAndWaitWithDisposition(browser(), 1358 DownloadAndWaitWithDisposition(browser(),
1393 url, 1359 url,
1394 NEW_WINDOW, 1360 NEW_WINDOW,
1395 EXPECT_NO_SELECT_DIALOG,
1396 ui_test_utils::BROWSER_TEST_NONE); 1361 ui_test_utils::BROWSER_TEST_NONE);
1397 1362
1398 // When the download finishes, the download shelf SHOULD NOT be visible in 1363 // When the download finishes, the download shelf SHOULD NOT be visible in
1399 // the first window. 1364 // the first window.
1400 ExpectWindowCountAfterDownload(2); 1365 ExpectWindowCountAfterDownload(2);
1401 EXPECT_EQ(1, browser()->tab_count()); 1366 EXPECT_EQ(1, browser()->tab_count());
1402 // Download shelf should close. Download panel stays open on ChromeOS. 1367 // Download shelf should close. Download panel stays open on ChromeOS.
1403 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); 1368 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
1404 1369
1405 // The download shelf SHOULD be visible in the second window. 1370 // The download shelf SHOULD be visible in the second window.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1455 string16(), &downloads); 1420 string16(), &downloads);
1456 ASSERT_EQ(1u, downloads.size()); 1421 ASSERT_EQ(1u, downloads.size());
1457 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->GetState()); 1422 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->GetState());
1458 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 1423 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
1459 DownloadItem* download1 = downloads[0]; // The only download. 1424 DownloadItem* download1 = downloads[0]; // The only download.
1460 1425
1461 // Start the second download and wait until it's done. 1426 // Start the second download and wait until it's done.
1462 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1427 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1463 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1428 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1464 // Download the file and wait. We do not expect the Select File dialog. 1429 // Download the file and wait. We do not expect the Select File dialog.
1465 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); 1430 DownloadAndWait(browser(), url);
1466 1431
1467 // Should now have 2 items on the download shelf. 1432 // Should now have 2 items on the download shelf.
1468 downloads.clear(); 1433 downloads.clear();
1469 DownloadManagerForBrowser(browser())->SearchDownloads( 1434 DownloadManagerForBrowser(browser())->SearchDownloads(
1470 string16(), &downloads); 1435 string16(), &downloads);
1471 ASSERT_EQ(2u, downloads.size()); 1436 ASSERT_EQ(2u, downloads.size());
1472 // We don't know the order of the downloads. 1437 // We don't know the order of the downloads.
1473 DownloadItem* download2 = downloads[(download1 == downloads[0]) ? 1 : 0]; 1438 DownloadItem* download2 = downloads[(download1 == downloads[0]) ? 1 : 0];
1474 1439
1475 ASSERT_EQ(DownloadItem::IN_PROGRESS, download1->GetState()); 1440 ASSERT_EQ(DownloadItem::IN_PROGRESS, download1->GetState());
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1560 1525
1561 // Confirm a download makes it into the history properly. 1526 // Confirm a download makes it into the history properly.
1562 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryCheck) { 1527 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryCheck) {
1563 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1528 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1564 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1529 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1565 FilePath origin_file(OriginFile(file)); 1530 FilePath origin_file(OriginFile(file));
1566 int64 origin_size; 1531 int64 origin_size;
1567 file_util::GetFileSize(origin_file, &origin_size); 1532 file_util::GetFileSize(origin_file, &origin_size);
1568 1533
1569 // Download the file and wait. We do not expect the Select File dialog. 1534 // Download the file and wait. We do not expect the Select File dialog.
1570 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); 1535 DownloadAndWait(browser(), url);
1571 1536
1572 // Get details of what downloads have just happened. 1537 // Get details of what downloads have just happened.
1573 std::vector<DownloadItem*> downloads; 1538 std::vector<DownloadItem*> downloads;
1574 GetDownloads(browser(), &downloads); 1539 GetDownloads(browser(), &downloads);
1575 ASSERT_EQ(1u, downloads.size()); 1540 ASSERT_EQ(1u, downloads.size());
1576 int64 db_handle = downloads[0]->GetDbHandle(); 1541 int64 db_handle = downloads[0]->GetDbHandle();
1577 1542
1578 // Check state. 1543 // Check state.
1579 EXPECT_EQ(1, browser()->tab_count()); 1544 EXPECT_EQ(1, browser()->tab_count());
1580 CheckDownload(browser(), file, file); 1545 CheckDownload(browser(), file, file);
(...skipping 15 matching lines...) Expand all
1596 1561
1597 // Test for crbug.com/14505. This tests that chrome:// urls are still functional 1562 // Test for crbug.com/14505. This tests that chrome:// urls are still functional
1598 // after download of a file while viewing another chrome://. 1563 // after download of a file while viewing another chrome://.
1599 IN_PROC_BROWSER_TEST_F(DownloadTest, ChromeURLAfterDownload) { 1564 IN_PROC_BROWSER_TEST_F(DownloadTest, ChromeURLAfterDownload) {
1600 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1565 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1601 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); 1566 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file));
1602 GURL flags_url(chrome::kChromeUIFlagsURL); 1567 GURL flags_url(chrome::kChromeUIFlagsURL);
1603 GURL extensions_url(chrome::kChromeUIExtensionsFrameURL); 1568 GURL extensions_url(chrome::kChromeUIExtensionsFrameURL);
1604 1569
1605 ui_test_utils::NavigateToURL(browser(), flags_url); 1570 ui_test_utils::NavigateToURL(browser(), flags_url);
1606 DownloadAndWait(browser(), download_url, EXPECT_NO_SELECT_DIALOG); 1571 DownloadAndWait(browser(), download_url);
1607 ui_test_utils::NavigateToURL(browser(), extensions_url); 1572 ui_test_utils::NavigateToURL(browser(), extensions_url);
1608 WebContents* contents = chrome::GetActiveWebContents(browser()); 1573 WebContents* contents = chrome::GetActiveWebContents(browser());
1609 ASSERT_TRUE(contents); 1574 ASSERT_TRUE(contents);
1610 bool webui_responded = false; 1575 bool webui_responded = false;
1611 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( 1576 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool(
1612 contents->GetRenderViewHost(), 1577 contents->GetRenderViewHost(),
1613 L"", 1578 L"",
1614 L"window.domAutomationController.send(window.webui_responded_);", 1579 L"window.domAutomationController.send(window.webui_responded_);",
1615 &webui_responded)); 1580 &webui_responded));
1616 EXPECT_TRUE(webui_responded); 1581 EXPECT_TRUE(webui_responded);
(...skipping 12 matching lines...) Expand all
1629 ASSERT_TRUE(contents); 1594 ASSERT_TRUE(contents);
1630 bool result = false; 1595 bool result = false;
1631 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( 1596 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool(
1632 contents->GetRenderViewHost(), 1597 contents->GetRenderViewHost(),
1633 L"", 1598 L"",
1634 L"window.onunload = function() { var do_nothing = 0; }; " 1599 L"window.onunload = function() { var do_nothing = 0; }; "
1635 L"window.domAutomationController.send(true);", 1600 L"window.domAutomationController.send(true);",
1636 &result)); 1601 &result));
1637 EXPECT_TRUE(result); 1602 EXPECT_TRUE(result);
1638 1603
1639 DownloadAndWait(browser(), download_url, EXPECT_NO_SELECT_DIALOG); 1604 DownloadAndWait(browser(), download_url);
1640 1605
1641 content::WindowedNotificationObserver signal( 1606 content::WindowedNotificationObserver signal(
1642 chrome::NOTIFICATION_BROWSER_CLOSED, 1607 chrome::NOTIFICATION_BROWSER_CLOSED,
1643 content::Source<Browser>(browser())); 1608 content::Source<Browser>(browser()));
1644 chrome::CloseWindow(browser()); 1609 chrome::CloseWindow(browser());
1645 signal.Wait(); 1610 signal.Wait();
1646 } 1611 }
1647 1612
1648 // Test to make sure the 'download' attribute in anchor tag is respected. 1613 // Test to make sure the 'download' attribute in anchor tag is respected.
1649 IN_PROC_BROWSER_TEST_F(DownloadTest, AnchorDownloadTag) { 1614 IN_PROC_BROWSER_TEST_F(DownloadTest, AnchorDownloadTag) {
(...skipping 21 matching lines...) Expand all
1671 FilePath file(FILE_PATH_LITERAL("download-autoopen.txt")); 1636 FilePath file(FILE_PATH_LITERAL("download-autoopen.txt"));
1672 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1637 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1673 1638
1674 ASSERT_TRUE( 1639 ASSERT_TRUE(
1675 GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file)); 1640 GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file));
1676 1641
1677 // Mock out external opening on all downloads until end of test. 1642 // Mock out external opening on all downloads until end of test.
1678 MockDownloadOpeningObserver observer( 1643 MockDownloadOpeningObserver observer(
1679 DownloadManagerForBrowser(browser())); 1644 DownloadManagerForBrowser(browser()));
1680 1645
1681 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); 1646 DownloadAndWait(browser(), url);
1682 1647
1683 // Find the download and confirm it was opened. 1648 // Find the download and confirm it was opened.
1684 std::vector<DownloadItem*> downloads; 1649 std::vector<DownloadItem*> downloads;
1685 DownloadManagerForBrowser(browser())->SearchDownloads( 1650 DownloadManagerForBrowser(browser())->SearchDownloads(
1686 string16(), &downloads); 1651 string16(), &downloads);
1687 ASSERT_EQ(1u, downloads.size()); 1652 ASSERT_EQ(1u, downloads.size());
1688 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0]->GetState()); 1653 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0]->GetState());
1689 EXPECT_TRUE(downloads[0]->GetOpened()); 1654 EXPECT_TRUE(downloads[0]->GetOpened());
1690 1655
1691 // As long as we're here, confirmed everything else is good. 1656 // As long as we're here, confirmed everything else is good.
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
1973 EXPECT_EQ(3, search_results[1]->GetDbHandle()); 1938 EXPECT_EQ(3, search_results[1]->GetDbHandle());
1974 search_results.clear(); 1939 search_results.clear();
1975 } 1940 }
1976 1941
1977 // Tests for download initiation functions. 1942 // Tests for download initiation functions.
1978 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrl) { 1943 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrl) {
1979 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1944 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1980 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1945 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1981 1946
1982 // DownloadUrl always prompts; return acceptance of whatever it prompts. 1947 // DownloadUrl always prompts; return acceptance of whatever it prompts.
1983 NullSelectFile(browser()); 1948 EnableFileChooser(true);
1984 1949
1985 WebContents* web_contents = chrome::GetActiveWebContents(browser()); 1950 WebContents* web_contents = chrome::GetActiveWebContents(browser());
1986 ASSERT_TRUE(web_contents); 1951 ASSERT_TRUE(web_contents);
1987 1952
1988 DownloadTestObserver* observer( 1953 DownloadTestObserver* observer(
1989 new DownloadTestObserverTerminal( 1954 new DownloadTestObserverTerminal(
1990 DownloadManagerForBrowser(browser()), 1, 1955 DownloadManagerForBrowser(browser()), 1,
1991 false, // Ignore select file.
1992 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 1956 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
1993 content::DownloadSaveInfo save_info; 1957 content::DownloadSaveInfo save_info;
1994 save_info.prompt_for_save_location = true; 1958 save_info.prompt_for_save_location = true;
1995 scoped_ptr<DownloadUrlParameters> params( 1959 scoped_ptr<DownloadUrlParameters> params(
1996 DownloadUrlParameters::FromWebContents(web_contents, url, save_info)); 1960 DownloadUrlParameters::FromWebContents(web_contents, url, save_info));
1997 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass()); 1961 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass());
1998 observer->WaitForFinished(); 1962 observer->WaitForFinished();
1999 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 1963 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
2000 CheckDownloadStates(1, DownloadItem::COMPLETE); 1964 CheckDownloadStates(1, DownloadItem::COMPLETE);
2001 EXPECT_TRUE(observer->select_file_dialog_seen()); 1965 EXPECT_TRUE(DidShowFileChooser());
2002 1966
2003 // Check state. 1967 // Check state.
2004 EXPECT_EQ(1, browser()->tab_count()); 1968 EXPECT_EQ(1, browser()->tab_count());
2005 ASSERT_TRUE(CheckDownload(browser(), file, file)); 1969 ASSERT_TRUE(CheckDownload(browser(), file, file));
2006 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 1970 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
2007 } 1971 }
2008 1972
2009 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { 1973 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) {
2010 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1974 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
2011 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1975 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
(...skipping 21 matching lines...) Expand all
2033 target_file_full_path, 1997 target_file_full_path,
2034 OriginFile(file))); 1998 OriginFile(file)));
2035 1999
2036 // Temporary downloads won't be visible. 2000 // Temporary downloads won't be visible.
2037 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); 2001 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
2038 } 2002 }
2039 2003
2040 IN_PROC_BROWSER_TEST_F(DownloadTest, SavePageNonHTMLViaGet) { 2004 IN_PROC_BROWSER_TEST_F(DownloadTest, SavePageNonHTMLViaGet) {
2041 // Do initial setup. 2005 // Do initial setup.
2042 ASSERT_TRUE(test_server()->Start()); 2006 ASSERT_TRUE(test_server()->Start());
2043 NullSelectFile(browser()); 2007 EnableFileChooser(true);
2044 std::vector<DownloadItem*> download_items; 2008 std::vector<DownloadItem*> download_items;
2045 GetDownloads(browser(), &download_items); 2009 GetDownloads(browser(), &download_items);
2046 ASSERT_TRUE(download_items.empty()); 2010 ASSERT_TRUE(download_items.empty());
2047 2011
2048 // Navigate to a non-HTML resource. The resource also has 2012 // Navigate to a non-HTML resource. The resource also has
2049 // Cache-Control: no-cache set, which normally requires revalidation 2013 // Cache-Control: no-cache set, which normally requires revalidation
2050 // each time. 2014 // each time.
2051 GURL url = test_server()->GetURL("files/downloads/image.jpg"); 2015 GURL url = test_server()->GetURL("files/downloads/image.jpg");
2052 ASSERT_TRUE(url.is_valid()); 2016 ASSERT_TRUE(url.is_valid());
2053 ui_test_utils::NavigateToURL(browser(), url); 2017 ui_test_utils::NavigateToURL(browser(), url);
2054 2018
2055 // Stop the test server, and then try to save the page. If cache validation 2019 // Stop the test server, and then try to save the page. If cache validation
2056 // is not bypassed then this will fail since the server is no longer 2020 // is not bypassed then this will fail since the server is no longer
2057 // reachable. 2021 // reachable.
2058 ASSERT_TRUE(test_server()->Stop()); 2022 ASSERT_TRUE(test_server()->Stop());
2059 scoped_ptr<DownloadTestObserver> waiter( 2023 scoped_ptr<DownloadTestObserver> waiter(
2060 new DownloadTestObserverTerminal( 2024 new DownloadTestObserverTerminal(
2061 DownloadManagerForBrowser(browser()), 1, 2025 DownloadManagerForBrowser(browser()), 1,
2062 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 2026 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
2063 chrome::SavePage(browser()); 2027 chrome::SavePage(browser());
2064 waiter->WaitForFinished(); 2028 waiter->WaitForFinished();
2065 EXPECT_EQ(1u, waiter->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 2029 EXPECT_EQ(1u, waiter->NumDownloadsSeenInState(DownloadItem::COMPLETE));
2066 CheckDownloadStates(1, DownloadItem::COMPLETE); 2030 CheckDownloadStates(1, DownloadItem::COMPLETE);
2067 2031
2068 // Validate that the correct file was downloaded. 2032 // Validate that the correct file was downloaded.
2069 GetDownloads(browser(), &download_items); 2033 GetDownloads(browser(), &download_items);
2070 EXPECT_TRUE(waiter->select_file_dialog_seen()); 2034 EXPECT_TRUE(DidShowFileChooser());
2071 ASSERT_EQ(1u, download_items.size()); 2035 ASSERT_EQ(1u, download_items.size());
2072 ASSERT_EQ(url, download_items[0]->GetOriginalUrl()); 2036 ASSERT_EQ(url, download_items[0]->GetOriginalUrl());
2073 2037
2074 // Try to download it via a context menu. 2038 // Try to download it via a context menu.
2075 scoped_ptr<DownloadTestObserver> waiter_context_menu( 2039 scoped_ptr<DownloadTestObserver> waiter_context_menu(
2076 new DownloadTestObserverTerminal( 2040 new DownloadTestObserverTerminal(
2077 DownloadManagerForBrowser(browser()), 1, 2041 DownloadManagerForBrowser(browser()), 1,
2078 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 2042 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
2079 content::ContextMenuParams context_menu_params; 2043 content::ContextMenuParams context_menu_params;
2080 context_menu_params.media_type = WebKit::WebContextMenuData::MediaTypeImage; 2044 context_menu_params.media_type = WebKit::WebContextMenuData::MediaTypeImage;
2081 context_menu_params.src_url = url; 2045 context_menu_params.src_url = url;
2082 context_menu_params.page_url = url; 2046 context_menu_params.page_url = url;
2083 TestRenderViewContextMenu menu(chrome::GetActiveWebContents(browser()), 2047 TestRenderViewContextMenu menu(chrome::GetActiveWebContents(browser()),
2084 context_menu_params); 2048 context_menu_params);
2085 menu.Init(); 2049 menu.Init();
2086 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS); 2050 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS);
2087 waiter_context_menu->WaitForFinished(); 2051 waiter_context_menu->WaitForFinished();
2088 EXPECT_EQ( 2052 EXPECT_EQ(
2089 1u, waiter_context_menu->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 2053 1u, waiter_context_menu->NumDownloadsSeenInState(DownloadItem::COMPLETE));
2090 CheckDownloadStates(2, DownloadItem::COMPLETE); 2054 CheckDownloadStates(2, DownloadItem::COMPLETE);
2091 2055
2092 // Validate that the correct file was downloaded via the context menu. 2056 // Validate that the correct file was downloaded via the context menu.
2093 download_items.clear(); 2057 download_items.clear();
2094 GetDownloads(browser(), &download_items); 2058 GetDownloads(browser(), &download_items);
2095 EXPECT_TRUE(waiter_context_menu->select_file_dialog_seen()); 2059 EXPECT_TRUE(DidShowFileChooser());
2096 ASSERT_EQ(2u, download_items.size()); 2060 ASSERT_EQ(2u, download_items.size());
2097 ASSERT_EQ(url, download_items[0]->GetOriginalUrl()); 2061 ASSERT_EQ(url, download_items[0]->GetOriginalUrl());
2098 ASSERT_EQ(url, download_items[1]->GetOriginalUrl()); 2062 ASSERT_EQ(url, download_items[1]->GetOriginalUrl());
2099 } 2063 }
2100 2064
2101 IN_PROC_BROWSER_TEST_F(DownloadTest, SavePageNonHTMLViaPost) { 2065 IN_PROC_BROWSER_TEST_F(DownloadTest, SavePageNonHTMLViaPost) {
2102 // Do initial setup. 2066 // Do initial setup.
2103 ASSERT_TRUE(test_server()->Start()); 2067 ASSERT_TRUE(test_server()->Start());
2104 NullSelectFile(browser()); 2068 EnableFileChooser(true);
2105 std::vector<DownloadItem*> download_items; 2069 std::vector<DownloadItem*> download_items;
2106 GetDownloads(browser(), &download_items); 2070 GetDownloads(browser(), &download_items);
2107 ASSERT_TRUE(download_items.empty()); 2071 ASSERT_TRUE(download_items.empty());
2108 2072
2109 // Navigate to a form page. 2073 // Navigate to a form page.
2110 GURL form_url = test_server()->GetURL( 2074 GURL form_url = test_server()->GetURL(
2111 "files/downloads/form_page_to_post.html"); 2075 "files/downloads/form_page_to_post.html");
2112 ASSERT_TRUE(form_url.is_valid()); 2076 ASSERT_TRUE(form_url.is_valid());
2113 ui_test_utils::NavigateToURL(browser(), form_url); 2077 ui_test_utils::NavigateToURL(browser(), form_url);
2114 2078
(...skipping 16 matching lines...) Expand all
2131 EXPECT_EQ(jpeg_url, web_contents->GetURL()); 2095 EXPECT_EQ(jpeg_url, web_contents->GetURL());
2132 2096
2133 // Stop the test server, and then try to save the page. If cache validation 2097 // Stop the test server, and then try to save the page. If cache validation
2134 // is not bypassed then this will fail since the server is no longer 2098 // is not bypassed then this will fail since the server is no longer
2135 // reachable. This will also fail if it tries to be retrieved via "GET" 2099 // reachable. This will also fail if it tries to be retrieved via "GET"
2136 // rather than "POST". 2100 // rather than "POST".
2137 ASSERT_TRUE(test_server()->Stop()); 2101 ASSERT_TRUE(test_server()->Stop());
2138 scoped_ptr<DownloadTestObserver> waiter( 2102 scoped_ptr<DownloadTestObserver> waiter(
2139 new DownloadTestObserverTerminal( 2103 new DownloadTestObserverTerminal(
2140 DownloadManagerForBrowser(browser()), 1, 2104 DownloadManagerForBrowser(browser()), 1,
2141 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 2105 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
2142 chrome::SavePage(browser()); 2106 chrome::SavePage(browser());
2143 waiter->WaitForFinished(); 2107 waiter->WaitForFinished();
2144 EXPECT_EQ(1u, waiter->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 2108 EXPECT_EQ(1u, waiter->NumDownloadsSeenInState(DownloadItem::COMPLETE));
2145 CheckDownloadStates(1, DownloadItem::COMPLETE); 2109 CheckDownloadStates(1, DownloadItem::COMPLETE);
2146 2110
2147 // Validate that the correct file was downloaded. 2111 // Validate that the correct file was downloaded.
2148 GetDownloads(browser(), &download_items); 2112 GetDownloads(browser(), &download_items);
2149 EXPECT_TRUE(waiter->select_file_dialog_seen()); 2113 EXPECT_TRUE(DidShowFileChooser());
2150 ASSERT_EQ(1u, download_items.size()); 2114 ASSERT_EQ(1u, download_items.size());
2151 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl()); 2115 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl());
2152 2116
2153 // Try to download it via a context menu. 2117 // Try to download it via a context menu.
2154 scoped_ptr<DownloadTestObserver> waiter_context_menu( 2118 scoped_ptr<DownloadTestObserver> waiter_context_menu(
2155 new DownloadTestObserverTerminal( 2119 new DownloadTestObserverTerminal(
2156 DownloadManagerForBrowser(browser()), 1, 2120 DownloadManagerForBrowser(browser()), 1,
2157 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 2121 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
2158 content::ContextMenuParams context_menu_params; 2122 content::ContextMenuParams context_menu_params;
2159 context_menu_params.media_type = WebKit::WebContextMenuData::MediaTypeImage; 2123 context_menu_params.media_type = WebKit::WebContextMenuData::MediaTypeImage;
2160 context_menu_params.src_url = jpeg_url; 2124 context_menu_params.src_url = jpeg_url;
2161 context_menu_params.page_url = jpeg_url; 2125 context_menu_params.page_url = jpeg_url;
2162 TestRenderViewContextMenu menu(web_contents, context_menu_params); 2126 TestRenderViewContextMenu menu(web_contents, context_menu_params);
2163 menu.Init(); 2127 menu.Init();
2164 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS); 2128 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS);
2165 waiter_context_menu->WaitForFinished(); 2129 waiter_context_menu->WaitForFinished();
2166 EXPECT_EQ( 2130 EXPECT_EQ(
2167 1u, waiter_context_menu->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 2131 1u, waiter_context_menu->NumDownloadsSeenInState(DownloadItem::COMPLETE));
2168 CheckDownloadStates(2, DownloadItem::COMPLETE); 2132 CheckDownloadStates(2, DownloadItem::COMPLETE);
2169 2133
2170 // Validate that the correct file was downloaded via the context menu. 2134 // Validate that the correct file was downloaded via the context menu.
2171 download_items.clear(); 2135 download_items.clear();
2172 GetDownloads(browser(), &download_items); 2136 GetDownloads(browser(), &download_items);
2173 EXPECT_TRUE(waiter_context_menu->select_file_dialog_seen()); 2137 EXPECT_TRUE(DidShowFileChooser());
2174 ASSERT_EQ(2u, download_items.size()); 2138 ASSERT_EQ(2u, download_items.size());
2175 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl()); 2139 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl());
2176 ASSERT_EQ(jpeg_url, download_items[1]->GetOriginalUrl()); 2140 ASSERT_EQ(jpeg_url, download_items[1]->GetOriginalUrl());
2177 } 2141 }
2178 2142
2179 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorsServer) { 2143 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorsServer) {
2180 DownloadInfo download_info[] = { 2144 DownloadInfo download_info[] = {
2181 { // Normal navigated download. 2145 { // Normal navigated download.
2182 "a_zip_file.zip", 2146 "a_zip_file.zip",
2183 DOWNLOAD_NAVIGATE, 2147 DOWNLOAD_NAVIGATE,
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
2452 ui_test_utils::NavigateToURL(browser(), url); 2416 ui_test_utils::NavigateToURL(browser(), url);
2453 observer->WaitForFinished(); 2417 observer->WaitForFinished();
2454 2418
2455 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 2419 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
2456 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); 2420 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen());
2457 } 2421 }
2458 2422
2459 IN_PROC_BROWSER_TEST_F(DownloadTest, LoadURLExternallyReferrerPolicy) { 2423 IN_PROC_BROWSER_TEST_F(DownloadTest, LoadURLExternallyReferrerPolicy) {
2460 // Do initial setup. 2424 // Do initial setup.
2461 ASSERT_TRUE(test_server()->Start()); 2425 ASSERT_TRUE(test_server()->Start());
2462 NullSelectFile(browser()); 2426 EnableFileChooser(true);
2463 std::vector<DownloadItem*> download_items; 2427 std::vector<DownloadItem*> download_items;
2464 GetDownloads(browser(), &download_items); 2428 GetDownloads(browser(), &download_items);
2465 ASSERT_TRUE(download_items.empty()); 2429 ASSERT_TRUE(download_items.empty());
2466 2430
2467 // Navigate to a page with a referrer policy and a link on it. The link points 2431 // Navigate to a page with a referrer policy and a link on it. The link points
2468 // to testserver's /echoheader. 2432 // to testserver's /echoheader.
2469 GURL url = test_server()->GetURL("files/downloads/referrer_policy.html"); 2433 GURL url = test_server()->GetURL("files/downloads/referrer_policy.html");
2470 ASSERT_TRUE(url.is_valid()); 2434 ASSERT_TRUE(url.is_valid());
2471 ui_test_utils::NavigateToURL(browser(), url); 2435 ui_test_utils::NavigateToURL(browser(), url);
2472 2436
2473 scoped_ptr<DownloadTestObserver> waiter( 2437 scoped_ptr<DownloadTestObserver> waiter(
2474 new DownloadTestObserverTerminal( 2438 new DownloadTestObserverTerminal(
2475 DownloadManagerForBrowser(browser()), 1, 2439 DownloadManagerForBrowser(browser()), 1,
2476 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 2440 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
2477 2441
2478 // Click on the link with the alt key pressed. This will download the link 2442 // Click on the link with the alt key pressed. This will download the link
2479 // target. 2443 // target.
2480 WebContents* tab = chrome::GetActiveWebContents(browser()); 2444 WebContents* tab = chrome::GetActiveWebContents(browser());
2481 WebKit::WebMouseEvent mouse_event; 2445 WebKit::WebMouseEvent mouse_event;
2482 mouse_event.type = WebKit::WebInputEvent::MouseDown; 2446 mouse_event.type = WebKit::WebInputEvent::MouseDown;
2483 mouse_event.button = WebKit::WebMouseEvent::ButtonLeft; 2447 mouse_event.button = WebKit::WebMouseEvent::ButtonLeft;
2484 mouse_event.x = 15; 2448 mouse_event.x = 15;
2485 mouse_event.y = 15; 2449 mouse_event.y = 15;
2486 mouse_event.clickCount = 1; 2450 mouse_event.clickCount = 1;
(...skipping 10 matching lines...) Expand all
2497 GetDownloads(browser(), &download_items); 2461 GetDownloads(browser(), &download_items);
2498 ASSERT_EQ(1u, download_items.size()); 2462 ASSERT_EQ(1u, download_items.size());
2499 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), 2463 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"),
2500 download_items[0]->GetOriginalUrl()); 2464 download_items[0]->GetOriginalUrl());
2501 2465
2502 // Check that the file contains the expected referrer. 2466 // Check that the file contains the expected referrer.
2503 FilePath file(download_items[0]->GetFullPath()); 2467 FilePath file(download_items[0]->GetFullPath());
2504 std::string expected_contents = test_server()->GetURL("").spec(); 2468 std::string expected_contents = test_server()->GetURL("").spec();
2505 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); 2469 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length()));
2506 } 2470 }
OLDNEW
« no previous file with comments | « chrome/browser/download/chrome_download_manager_delegate_unittest.cc ('k') | chrome/browser/download/download_file_picker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698