OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/file_path.h" | 5 #include "base/file_path.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/scoped_temp_dir.h" | 9 #include "base/scoped_temp_dir.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "base/string_util.h" |
11 #include "base/test/test_file_util.h" | 12 #include "base/test/test_file_util.h" |
12 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
13 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/download/download_crx_util.h" | 15 #include "chrome/browser/download/download_crx_util.h" |
15 #include "chrome/browser/download/download_file_manager.h" | 16 #include "chrome/browser/download/download_file_manager.h" |
16 #include "chrome/browser/download/download_history.h" | 17 #include "chrome/browser/download/download_history.h" |
17 #include "chrome/browser/download/download_item.h" | 18 #include "chrome/browser/download/download_item.h" |
18 #include "chrome/browser/download/download_manager.h" | 19 #include "chrome/browser/download/download_manager.h" |
19 #include "chrome/browser/download/download_prefs.h" | 20 #include "chrome/browser/download/download_prefs.h" |
20 #include "chrome/browser/download/download_shelf.h" | 21 #include "chrome/browser/download/download_shelf.h" |
21 #include "chrome/browser/download/download_util.h" | 22 #include "chrome/browser/download/download_util.h" |
22 #include "chrome/browser/extensions/extension_install_ui.h" | 23 #include "chrome/browser/extensions/extension_install_ui.h" |
23 #include "chrome/browser/extensions/extension_service.h" | 24 #include "chrome/browser/extensions/extension_service.h" |
24 #include "chrome/browser/history/download_history_info.h" | 25 #include "chrome/browser/history/download_history_info.h" |
25 #include "chrome/browser/history/history.h" | 26 #include "chrome/browser/history/history.h" |
26 #include "chrome/browser/prefs/pref_service.h" | 27 #include "chrome/browser/prefs/pref_service.h" |
27 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
28 #include "chrome/browser/ui/browser.h" | 29 #include "chrome/browser/ui/browser.h" |
29 #include "chrome/browser/ui/browser_list.h" | 30 #include "chrome/browser/ui/browser_list.h" |
30 #include "chrome/browser/ui/browser_window.h" | 31 #include "chrome/browser/ui/browser_window.h" |
31 #include "chrome/browser/ui/webui/active_downloads_ui.h" | 32 #include "chrome/browser/ui/webui/active_downloads_ui.h" |
32 #include "chrome/common/chrome_notification_types.h" | 33 #include "chrome/common/chrome_notification_types.h" |
33 #include "chrome/common/chrome_paths.h" | 34 #include "chrome/common/chrome_paths.h" |
34 #include "chrome/common/pref_names.h" | 35 #include "chrome/common/pref_names.h" |
| 36 #include "chrome/common/random.h" |
35 #include "chrome/common/url_constants.h" | 37 #include "chrome/common/url_constants.h" |
36 #include "chrome/test/base/in_process_browser_test.h" | 38 #include "chrome/test/base/in_process_browser_test.h" |
37 #include "chrome/test/base/ui_test_utils.h" | 39 #include "chrome/test/base/ui_test_utils.h" |
38 #include "content/browser/cancelable_request.h" | 40 #include "content/browser/cancelable_request.h" |
39 #include "content/browser/net/url_request_mock_http_job.h" | 41 #include "content/browser/net/url_request_mock_http_job.h" |
40 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 42 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
41 #include "content/browser/tab_contents/tab_contents.h" | 43 #include "content/browser/tab_contents/tab_contents.h" |
42 #include "content/browser/net/url_request_slow_download_job.h" | 44 #include "content/browser/net/url_request_slow_download_job.h" |
43 #include "content/common/page_transition_types.h" | 45 #include "content/common/page_transition_types.h" |
44 #include "net/base/net_util.h" | 46 #include "net/base/net_util.h" |
| 47 #include "net/url_request/url_request_filter.h" |
45 #include "testing/gtest/include/gtest/gtest.h" | 48 #include "testing/gtest/include/gtest/gtest.h" |
46 | 49 |
47 namespace { | 50 namespace { |
48 | 51 |
49 // IDs and paths of CRX files used in tests. | 52 // IDs and paths of CRX files used in tests. |
50 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; | 53 const char kGoodCrxId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; |
51 const FilePath kGoodCrxPath(FILE_PATH_LITERAL("extensions/good.crx")); | 54 const FilePath kGoodCrxPath(FILE_PATH_LITERAL("extensions/good.crx")); |
52 | 55 |
53 const char kLargeThemeCrxId[] = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; | 56 const char kLargeThemeCrxId[] = "pjpgmfcmabopnnfonnhmdjglfpjjfkbf"; |
54 const FilePath kLargeThemePath(FILE_PATH_LITERAL("extensions/theme2.crx")); | 57 const FilePath kLargeThemePath(FILE_PATH_LITERAL("extensions/theme2.crx")); |
55 | 58 |
| 59 // The test file used in SavePageBrowserTest.SaveFolder3. |
| 60 static const FilePath kTestFile(FILE_PATH_LITERAL("download-test1.lib")); |
| 61 |
56 // Action a test should take if a dangerous download is encountered. | 62 // Action a test should take if a dangerous download is encountered. |
57 enum DangerousDownloadAction { | 63 enum DangerousDownloadAction { |
58 ON_DANGEROUS_DOWNLOAD_ACCEPT, // Accept the download | 64 ON_DANGEROUS_DOWNLOAD_ACCEPT, // Accept the download |
59 ON_DANGEROUS_DOWNLOAD_DENY, // Deny the download | 65 ON_DANGEROUS_DOWNLOAD_DENY, // Deny the download |
60 ON_DANGEROUS_DOWNLOAD_FAIL // Fail if a dangerous download is seen | 66 ON_DANGEROUS_DOWNLOAD_FAIL // Fail if a dangerous download is seen |
61 }; | 67 }; |
62 | 68 |
63 // Fake user click on "Accept". | 69 // Fake user click on "Accept". |
64 void AcceptDangerousDownload(scoped_refptr<DownloadManager> download_manager, | 70 void AcceptDangerousDownload(scoped_refptr<DownloadManager> download_manager, |
65 int32 download_id) { | 71 int32 download_id) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 ~DownloadsObserver() { | 127 ~DownloadsObserver() { |
122 std::set<DownloadItem*>::iterator it = downloads_observed_.begin(); | 128 std::set<DownloadItem*>::iterator it = downloads_observed_.begin(); |
123 for (; it != downloads_observed_.end(); ++it) | 129 for (; it != downloads_observed_.end(); ++it) |
124 (*it)->RemoveObserver(this); | 130 (*it)->RemoveObserver(this); |
125 | 131 |
126 download_manager_->RemoveObserver(this); | 132 download_manager_->RemoveObserver(this); |
127 } | 133 } |
128 | 134 |
129 // State accessors. | 135 // State accessors. |
130 bool select_file_dialog_seen() { return select_file_dialog_seen_; } | 136 bool select_file_dialog_seen() { return select_file_dialog_seen_; } |
| 137 const FilePath& suggested_path() { return suggested_path_; } |
131 | 138 |
132 // Wait for whatever state was specified in the constructor. | 139 // Wait for whatever state was specified in the constructor. |
133 void WaitForFinished() { | 140 void WaitForFinished() { |
134 if (!IsFinished()) { | 141 if (!IsFinished()) { |
135 waiting_ = true; | 142 waiting_ = true; |
136 ui_test_utils::RunMessageLoop(); | 143 ui_test_utils::RunMessageLoop(); |
137 waiting_ = false; | 144 waiting_ = false; |
138 } | 145 } |
139 } | 146 } |
140 | 147 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 // If it is finished and we are observing it, stop. | 240 // If it is finished and we are observing it, stop. |
234 if (finished_it != finished_downloads_.end() && | 241 if (finished_it != finished_downloads_.end() && |
235 observed_it != downloads_observed_.end()) { | 242 observed_it != downloads_observed_.end()) { |
236 (*it)->RemoveObserver(this); | 243 (*it)->RemoveObserver(this); |
237 downloads_observed_.erase(observed_it); | 244 downloads_observed_.erase(observed_it); |
238 continue; | 245 continue; |
239 } | 246 } |
240 } | 247 } |
241 } | 248 } |
242 | 249 |
243 virtual void SelectFileDialogDisplayed(int32 /* id */) { | 250 virtual void SelectFileDialogDisplayed( |
| 251 int32 /* id */, const FilePath& suggested_path) { |
244 select_file_dialog_seen_ = true; | 252 select_file_dialog_seen_ = true; |
| 253 suggested_path_ = suggested_path; |
245 SignalIfFinished(); | 254 SignalIfFinished(); |
246 } | 255 } |
247 | 256 |
248 virtual size_t NumDangerousDownloadsSeen() const { | 257 virtual size_t NumDangerousDownloadsSeen() const { |
249 return dangerous_downloads_seen_.size(); | 258 return dangerous_downloads_seen_.size(); |
250 } | 259 } |
251 | 260 |
252 private: | 261 private: |
253 // Called when we know that a download item is in a final state. | 262 // Called when we know that a download item is in a final state. |
254 // Note that this is not the same as it first transitioning in to the | 263 // Note that this is not the same as it first transitioning in to the |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 | 319 |
311 // True if we've seen the select file dialog. | 320 // True if we've seen the select file dialog. |
312 bool select_file_dialog_seen_; | 321 bool select_file_dialog_seen_; |
313 | 322 |
314 // Action to take if a dangerous download is encountered. | 323 // Action to take if a dangerous download is encountered. |
315 DangerousDownloadAction dangerous_download_action_; | 324 DangerousDownloadAction dangerous_download_action_; |
316 | 325 |
317 // Holds the download ids which were dangerous. | 326 // Holds the download ids which were dangerous. |
318 std::set<int32> dangerous_downloads_seen_; | 327 std::set<int32> dangerous_downloads_seen_; |
319 | 328 |
| 329 // The suggested file path in the select file dialog. |
| 330 FilePath suggested_path_; |
| 331 |
320 DISALLOW_COPY_AND_ASSIGN(DownloadsObserver); | 332 DISALLOW_COPY_AND_ASSIGN(DownloadsObserver); |
321 }; | 333 }; |
322 | 334 |
323 // WaitForFlush() returns after: | 335 // WaitForFlush() returns after: |
324 // * There are no IN_PROGRESS download items remaining on the | 336 // * There are no IN_PROGRESS download items remaining on the |
325 // DownloadManager. | 337 // DownloadManager. |
326 // * There have been two round trip messages through the file and | 338 // * There have been two round trip messages through the file and |
327 // IO threads. | 339 // IO threads. |
328 // This almost certainly means that a Download cancel has propagated through | 340 // This almost certainly means that a Download cancel has propagated through |
329 // the system. | 341 // the system. |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 ResourceDispatcherHost* resource_dispatcher_host_; | 497 ResourceDispatcherHost* resource_dispatcher_host_; |
486 DownloadFileManager* download_file_manager_; | 498 DownloadFileManager* download_file_manager_; |
487 int rdh_pending_requests_; | 499 int rdh_pending_requests_; |
488 int dfm_pending_downloads_; | 500 int dfm_pending_downloads_; |
489 | 501 |
490 DISALLOW_COPY_AND_ASSIGN(CancelTestDataCollector); | 502 DISALLOW_COPY_AND_ASSIGN(CancelTestDataCollector); |
491 }; | 503 }; |
492 | 504 |
493 class DownloadTest : public InProcessBrowserTest { | 505 class DownloadTest : public InProcessBrowserTest { |
494 public: | 506 public: |
495 enum SelectExpectation { | |
496 EXPECT_NO_SELECT_DIALOG = -1, | |
497 EXPECT_NOTHING, | |
498 EXPECT_SELECT_DIALOG | |
499 }; | |
500 | |
501 DownloadTest() { | 507 DownloadTest() { |
502 EnableDOMAutomation(); | 508 EnableDOMAutomation(); |
503 } | 509 } |
504 | 510 |
505 // Returning false indicates a failure of the setup, and should be asserted | 511 // Returning false indicates a failure of the setup, and should be asserted |
506 // in the caller. | 512 // in the caller. |
507 virtual bool InitialSetup(bool prompt_for_download) { | 513 virtual bool InitialSetup(bool prompt_for_download) { |
508 bool have_test_dir = PathService::Get(chrome::DIR_TEST_DATA, &test_dir_); | 514 bool have_test_dir = PathService::Get(chrome::DIR_TEST_DATA, &test_dir_); |
509 EXPECT_TRUE(have_test_dir); | 515 EXPECT_TRUE(have_test_dir); |
510 if (!have_test_dir) | 516 if (!have_test_dir) |
(...skipping 27 matching lines...) Expand all Loading... |
538 SIZE_TEST_TYPE_UNKNOWN, | 544 SIZE_TEST_TYPE_UNKNOWN, |
539 }; | 545 }; |
540 | 546 |
541 // Location of the file source (the place from which it is downloaded). | 547 // Location of the file source (the place from which it is downloaded). |
542 FilePath OriginFile(FilePath file) { | 548 FilePath OriginFile(FilePath file) { |
543 return test_dir_.Append(file); | 549 return test_dir_.Append(file); |
544 } | 550 } |
545 | 551 |
546 // Location of the file destination (place to which it is downloaded). | 552 // Location of the file destination (place to which it is downloaded). |
547 FilePath DestinationFile(Browser* browser, FilePath file) { | 553 FilePath DestinationFile(Browser* browser, FilePath file) { |
548 return GetDownloadDirectory(browser).Append(file); | 554 return GetDownloadSaveDirectory(browser).Append(file); |
549 } | 555 } |
550 | 556 |
551 // Must be called after browser creation. Creates a temporary | 557 // Must be called after browser creation. Creates a temporary |
552 // directory for downloads that is auto-deleted on destruction. | 558 // directory for downloads that is auto-deleted on destruction. |
553 // Returning false indicates a failure of the function, and should be asserted | 559 // Returning false indicates a failure of the function, and should be asserted |
554 // in the caller. | 560 // in the caller. |
555 bool CreateAndSetDownloadsDirectory(Browser* browser) { | 561 bool CreateAndSetDownloadsDirectory(Browser* browser) { |
556 if (!browser) | 562 if (!browser) |
557 return false; | 563 return false; |
558 | 564 |
559 if (!downloads_directory_.CreateUniqueTempDir()) | 565 if (!downloads_directory_.CreateUniqueTempDir()) |
560 return false; | 566 return false; |
561 | 567 |
562 browser->profile()->GetPrefs()->SetFilePath( | 568 browser->profile()->GetPrefs()->SetFilePath( |
563 prefs::kDownloadDefaultDirectory, | 569 prefs::kDownloadDefaultDirectory, |
564 downloads_directory_.path()); | 570 downloads_directory_.path()); |
565 | 571 |
566 return true; | 572 return true; |
567 } | 573 } |
568 | 574 |
| 575 // Delete the default folder for downloaded files. |
| 576 bool DeleteDownloadsDirectory() { |
| 577 return downloads_directory_.Delete(); |
| 578 } |
| 579 |
569 DownloadPrefs* GetDownloadPrefs(Browser* browser) { | 580 DownloadPrefs* GetDownloadPrefs(Browser* browser) { |
570 return browser->profile()->GetDownloadManager()->download_prefs(); | 581 return browser->profile()->GetDownloadManager()->download_prefs(); |
571 } | 582 } |
572 | 583 |
573 FilePath GetDownloadDirectory(Browser* browser) { | 584 FilePath GetDownloadSaveDirectory(Browser* browser) { |
574 DownloadManager* download_mananger = | 585 DownloadManager* download_mananger = |
575 browser->profile()->GetDownloadManager(); | 586 browser->profile()->GetDownloadManager(); |
576 return download_mananger->download_prefs()->download_path(); | 587 return download_mananger->download_prefs()->download_path(); |
577 } | 588 } |
578 | 589 |
579 // Create a DownloadsObserver that will wait for the | 590 // Create a DownloadsObserver that will wait for the |
580 // specified number of downloads to finish. | 591 // specified number of downloads to finish. |
581 DownloadsObserver* CreateWaiter(Browser* browser, int num_downloads) { | 592 // If |finish_on_select_file| is true, the object will also be |
| 593 // considered finished when the select file dialog is displayed. |
| 594 DownloadsObserver* CreateWaiter(Browser* browser, |
| 595 int num_downloads, |
| 596 bool finish_on_select_file) { |
582 DownloadManager* download_manager = | 597 DownloadManager* download_manager = |
583 browser->profile()->GetDownloadManager(); | 598 browser->profile()->GetDownloadManager(); |
584 return new DownloadsObserver( | 599 return new DownloadsObserver( |
585 download_manager, num_downloads, | 600 download_manager, num_downloads, |
586 DownloadItem::COMPLETE, // Really done | 601 DownloadItem::COMPLETE, // Really done |
587 false, // Bail on select file | 602 finish_on_select_file, // Bail on select file |
588 ON_DANGEROUS_DOWNLOAD_FAIL); | 603 ON_DANGEROUS_DOWNLOAD_FAIL); |
589 } | 604 } |
590 | 605 |
591 // Create a DownloadsObserver that will wait for the | 606 // Create a DownloadsObserver that will wait for the |
592 // specified number of downloads to start. | 607 // specified number of downloads to start. |
593 DownloadsObserver* CreateInProgressWaiter(Browser* browser, | 608 DownloadsObserver* CreateInProgressWaiter(Browser* browser, |
594 int num_downloads) { | 609 int num_downloads) { |
595 DownloadManager* download_manager = | 610 DownloadManager* download_manager = |
596 browser->profile()->GetDownloadManager(); | 611 browser->profile()->GetDownloadManager(); |
597 return new DownloadsObserver( | 612 return new DownloadsObserver( |
(...skipping 16 matching lines...) Expand all Loading... |
614 return new DownloadsObserver( | 629 return new DownloadsObserver( |
615 download_manager, num_downloads, | 630 download_manager, num_downloads, |
616 final_state, | 631 final_state, |
617 true, // Bail on select file | 632 true, // Bail on select file |
618 dangerous_download_action); | 633 dangerous_download_action); |
619 } | 634 } |
620 | 635 |
621 // Download |url|, then wait for the download to finish. | 636 // Download |url|, then wait for the download to finish. |
622 // |disposition| indicates where the navigation occurs (current tab, new | 637 // |disposition| indicates where the navigation occurs (current tab, new |
623 // foreground tab, etc). | 638 // foreground tab, etc). |
624 // |expectation| indicates whether or not a Select File dialog should be | 639 // |expect_file_dialog| indicates whether a select file dialog should be |
625 // open when the download is finished, or if we don't care. | 640 // open when the download is finished, or if we don't care. |
626 // If the dialog appears, the routine exits. The only effect |expectation| | 641 // If the dialog appears, the routine exits. The only effect |
627 // has is whether or not the test succeeds. | 642 // |expect_file_dialog| has is whether or not the test succeeds. |
| 643 // |expected_suggested_path| is the path expected to be suggested in the |
| 644 // select file dialog. This |expected_suggested_path| must be specified |
| 645 // if |expect_file_dialog| is true. If |expect_file_dialog| is false, |
| 646 // |expected_suggested_path| is ignored. |
628 // |browser_test_flags| indicate what to wait for, and is an OR of 0 or more | 647 // |browser_test_flags| indicate what to wait for, and is an OR of 0 or more |
629 // values in the ui_test_utils::BrowserTestWaitFlags enum. | 648 // values in the ui_test_utils::BrowserTestWaitFlags enum. |
630 void DownloadAndWaitWithDisposition(Browser* browser, | 649 void DownloadAndWaitWithDisposition(Browser* browser, |
631 const GURL& url, | 650 const GURL& url, |
632 WindowOpenDisposition disposition, | 651 WindowOpenDisposition disposition, |
633 SelectExpectation expectation, | 652 bool expect_file_dialog, |
| 653 const FilePath& expected_suggested_path, |
634 int browser_test_flags) { | 654 int browser_test_flags) { |
635 // Setup notification, navigate, and block. | 655 // Setup notification, navigate, and block. |
636 scoped_ptr<DownloadsObserver> observer(CreateWaiter(browser, 1)); | 656 scoped_ptr<DownloadsObserver> observer( |
| 657 CreateWaiter(browser, 1, expect_file_dialog)); |
637 // This call will block until the condition specified by | 658 // This call will block until the condition specified by |
638 // |browser_test_flags|, but will not wait for the download to finish. | 659 // |browser_test_flags|, but will not wait for the download to finish. |
639 ui_test_utils::NavigateToURLWithDisposition(browser, | 660 ui_test_utils::NavigateToURLWithDisposition(browser, |
640 url, | 661 url, |
641 disposition, | 662 disposition, |
642 browser_test_flags); | 663 browser_test_flags); |
643 // Waits for the download to complete. | 664 // Waits for the download to complete. |
644 observer->WaitForFinished(); | 665 observer->WaitForFinished(); |
645 | 666 |
646 // If specified, check the state of the select file dialog. | 667 // Checks if the select file dialog was displayed as expected. |
647 if (expectation != EXPECT_NOTHING) { | 668 // If displayed, checks the suggested path in the dialog. |
648 EXPECT_EQ(expectation == EXPECT_SELECT_DIALOG, | 669 if (expect_file_dialog) { |
649 observer->select_file_dialog_seen()); | 670 EXPECT_TRUE(observer->select_file_dialog_seen()); |
| 671 EXPECT_EQ(observer->suggested_path(), expected_suggested_path); |
| 672 } else { |
| 673 EXPECT_FALSE(observer->select_file_dialog_seen()); |
650 } | 674 } |
651 } | 675 } |
652 | 676 |
653 // Download a file in the current tab, then wait for the download to finish. | 677 // Download a file in the current tab, then wait for the download to finish. |
654 void DownloadAndWait(Browser* browser, | 678 // Expect that no select file dialog is displayed. |
655 const GURL& url, | 679 void DownloadAndWait(Browser* browser, const GURL& url) { |
656 SelectExpectation expectation) { | |
657 DownloadAndWaitWithDisposition( | 680 DownloadAndWaitWithDisposition( |
658 browser, | 681 browser, url, CURRENT_TAB, false, FilePath(), |
659 url, | |
660 CURRENT_TAB, | |
661 expectation, | |
662 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 682 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
663 } | 683 } |
664 | 684 |
| 685 // Download a file in the current tab, then wait for the download to finish. |
| 686 // Expect that a select file dialog suggesting |expected_suggested_path| |
| 687 // is displayed. |
| 688 void DownloadAndWaitWithDialog(Browser* browser, const GURL& url, |
| 689 const FilePath& expected_suggested_path) { |
| 690 DownloadAndWaitWithDisposition( |
| 691 browser, url, CURRENT_TAB, true, expected_suggested_path, |
| 692 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 693 } |
| 694 |
665 // Should only be called when the download is known to have finished | 695 // Should only be called when the download is known to have finished |
666 // (in error or not). | 696 // (in error or not). |
667 // Returning false indicates a failure of the function, and should be asserted | 697 // Returning false indicates a failure of the function, and should be asserted |
668 // in the caller. | 698 // in the caller. |
669 bool CheckDownload(Browser* browser, | 699 bool CheckDownload(Browser* browser, |
670 const FilePath& downloaded_filename, | 700 const FilePath& downloaded_filename, |
671 const FilePath& origin_filename) { | 701 const FilePath& origin_filename) { |
672 // Find the path to which the data will be downloaded. | 702 // Find the path to which the data will be downloaded. |
673 FilePath downloaded_file(DestinationFile(browser, downloaded_filename)); | 703 FilePath downloaded_file(DestinationFile(browser, downloaded_filename)); |
674 | 704 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
717 // |expected_title_finished| need to be checked. | 747 // |expected_title_finished| need to be checked. |
718 FilePath filename; | 748 FilePath filename; |
719 net::FileURLToFilePath(url, &filename); | 749 net::FileURLToFilePath(url, &filename); |
720 string16 expected_title_in_progress( | 750 string16 expected_title_in_progress( |
721 ASCIIToUTF16(partial_indication) + filename.LossyDisplayName()); | 751 ASCIIToUTF16(partial_indication) + filename.LossyDisplayName()); |
722 string16 expected_title_finished( | 752 string16 expected_title_finished( |
723 ASCIIToUTF16(total_indication) + filename.LossyDisplayName()); | 753 ASCIIToUTF16(total_indication) + filename.LossyDisplayName()); |
724 | 754 |
725 // Download a partial web page in a background tab and wait. | 755 // Download a partial web page in a background tab and wait. |
726 // The mock system will not complete until it gets a special URL. | 756 // The mock system will not complete until it gets a special URL. |
727 scoped_ptr<DownloadsObserver> observer(CreateWaiter(browser, 1)); | 757 scoped_ptr<DownloadsObserver> observer(CreateWaiter(browser, 1, false)); |
728 ui_test_utils::NavigateToURL(browser, url); | 758 ui_test_utils::NavigateToURL(browser, url); |
729 | 759 |
730 // TODO(ahendrickson): check download status text before downloading. | 760 // TODO(ahendrickson): check download status text before downloading. |
731 // Need to: | 761 // Need to: |
732 // - Add a member function to the |DownloadShelf| interface class, that | 762 // - Add a member function to the |DownloadShelf| interface class, that |
733 // indicates how many members it has. | 763 // indicates how many members it has. |
734 // - Add a member function to |DownloadShelf| to get the status text | 764 // - Add a member function to |DownloadShelf| to get the status text |
735 // of a given member (for example, via the name in |DownloadItemView|'s | 765 // of a given member (for example, via the name in |DownloadItemView|'s |
736 // GetAccessibleState() member function), by index. | 766 // GetAccessibleState() member function), by index. |
737 // - Iterate over browser->window()->GetDownloadShelf()'s members | 767 // - Iterate over browser->window()->GetDownloadShelf()'s members |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
799 exists = true; | 829 exists = true; |
800 break; | 830 break; |
801 } | 831 } |
802 } | 832 } |
803 EXPECT_TRUE(exists); | 833 EXPECT_TRUE(exists); |
804 #else | 834 #else |
805 EXPECT_EQ(expected_non_cros, browser->window()->IsDownloadShelfVisible()); | 835 EXPECT_EQ(expected_non_cros, browser->window()->IsDownloadShelfVisible()); |
806 // TODO: Check for filename match in download shelf. | 836 // TODO: Check for filename match in download shelf. |
807 #endif | 837 #endif |
808 } | 838 } |
| 839 |
809 static void ExpectWindowCountAfterDownload(size_t expected) { | 840 static void ExpectWindowCountAfterDownload(size_t expected) { |
810 #if defined(OS_CHROMEOS) | 841 #if defined(OS_CHROMEOS) |
811 // On ChromeOS, a download panel is created to display | 842 // On ChromeOS, a download panel is created to display |
812 // download information, and this counts as a window. | 843 // download information, and this counts as a window. |
813 expected++; | 844 expected++; |
814 #endif | 845 #endif |
815 EXPECT_EQ(expected, BrowserList::size()); | 846 EXPECT_EQ(expected, BrowserList::size()); |
816 } | 847 } |
817 | 848 |
| 849 // Returns "src/chrome/test/data/{kTestFile}", whatever URL is given. |
| 850 static net::URLRequestJob* FactoryForTestFile( |
| 851 net::URLRequest* request, const std::string& scheme) { |
| 852 FilePath test_dir; |
| 853 if (!PathService::Get(chrome::DIR_TEST_DATA, &test_dir)) |
| 854 NOTREACHED(); |
| 855 return new URLRequestMockHTTPJob(request, test_dir.Append(kTestFile)); |
| 856 } |
| 857 |
818 private: | 858 private: |
819 // Location of the test data. | 859 // Location of the test data. |
820 FilePath test_dir_; | 860 FilePath test_dir_; |
821 | 861 |
822 // Location of the downloads directory for these tests | 862 // Location of the downloads directory for these tests |
823 ScopedTempDir downloads_directory_; | 863 ScopedTempDir downloads_directory_; |
824 }; | 864 }; |
825 | 865 |
826 // Get History Information. | 866 // Get History Information. |
827 class DownloadsHistoryDataCollector { | 867 class DownloadsHistoryDataCollector { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
942 // Files for these tests are found in DIR_TEST_DATA (currently | 982 // Files for these tests are found in DIR_TEST_DATA (currently |
943 // "chrome\test\data\", see chrome_paths.cc). | 983 // "chrome\test\data\", see chrome_paths.cc). |
944 // Mock responses have extension .mock-http-headers appended to the file name. | 984 // Mock responses have extension .mock-http-headers appended to the file name. |
945 | 985 |
946 // Download a file due to the associated MIME type. | 986 // Download a file due to the associated MIME type. |
947 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeType) { | 987 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeType) { |
948 ASSERT_TRUE(InitialSetup(false)); | 988 ASSERT_TRUE(InitialSetup(false)); |
949 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 989 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
950 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 990 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
951 | 991 |
952 // Download the file and wait. We do not expect the Select File dialog. | 992 // Download the file and wait. |
953 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 993 DownloadAndWait(browser(), url); |
954 | 994 |
955 // Check state. | 995 // Check state. |
956 EXPECT_EQ(1, browser()->tab_count()); | 996 EXPECT_EQ(1, browser()->tab_count()); |
957 CheckDownload(browser(), file, file); | 997 CheckDownload(browser(), file, file); |
958 CheckDownloadUI(browser(), true, true, file); | 998 CheckDownloadUI(browser(), true, true, file); |
959 } | 999 } |
960 | 1000 |
| 1001 // Checks if a file is saved to the user's "Downloads" folder |
| 1002 // in the following situation: |
| 1003 // The default folder for downloaded files does not exist. |
| 1004 // The user's "Downloads" folder exists. |
| 1005 // |
| 1006 // This test creates and deletes a file on the user's real "Downloads" folder, |
| 1007 // which is globally shared among all tests on the testing environment. |
| 1008 // Therefore, if we run browser tests in parallel, the file created by one |
| 1009 // browser test may be deleted by another broswer test when the file name |
| 1010 // conflicts. In order to avoid this problem, we use a special mock URL |
| 1011 // "http://mock.testfile.http/<random path>" for this download test. |
| 1012 // Since we redirect "http://mock.testfile.http/<random path>" to |
| 1013 // "chrome/test/data/{kTestFile}" using FactoryForTestFile(), |
| 1014 // "chrome/test/data/{kTestFile}" is used for the file to be downloaded. |
| 1015 // Then, the downloaded file is saved as a name "Downloads/<random path>", |
| 1016 // which is a unique file name in the user's real "Downloads" folder. |
| 1017 // |
| 1018 // Ideally, in the first place, we should not use the user's "Downloads" folder. |
| 1019 // Instead, we should create a temporary "Downloads" folder for each test. |
| 1020 // However, we concluded that creating temporary "Downloads" folder for each |
| 1021 // test requires very invasive code changes to many places. See also here: |
| 1022 // http://codereview.chromium.org/6973052/ |
| 1023 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadFolder) { |
| 1024 ASSERT_TRUE(InitialSetup(false)); |
| 1025 FilePath file(kTestFile); |
| 1026 |
| 1027 // Redirects "http://mock.testfile.http/<random path>" |
| 1028 // to "src/chrome/test/data/{kTestFile}", whatever the <random path> is. |
| 1029 std::string kMockHostnameForTestFile = "mock.testfile.http"; |
| 1030 net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance(); |
| 1031 filter->AddHostnameHandler( |
| 1032 "http", kMockHostnameForTestFile, FactoryForTestFile); |
| 1033 std::string random_string = Generate128BitRandomBase64String(); |
| 1034 RemoveChars(random_string, "/", &random_string); |
| 1035 GURL url("http://" + kMockHostnameForTestFile + "/" + random_string); |
| 1036 |
| 1037 FilePath default_download_dir = |
| 1038 download_util::GetDefaultDownloadDirectoryFromPathService(); |
| 1039 FilePath downloaded_file = default_download_dir.Append(random_string); |
| 1040 // Make sure that the target file does not exist. |
| 1041 file_util::Delete(downloaded_file, false); |
| 1042 // Make sure that the temporary file does not exist. |
| 1043 FilePath temporary_file = |
| 1044 default_download_dir.Append(random_string + ".crdownload"); |
| 1045 std::cout << temporary_file.value() << std::endl; |
| 1046 file_util::Delete(temporary_file, false); |
| 1047 |
| 1048 // Delete the default folder for downloaded files. |
| 1049 ASSERT_TRUE(DeleteDownloadsDirectory()); |
| 1050 ASSERT_FALSE(file_util::PathExists(GetDownloadSaveDirectory(browser()))); |
| 1051 |
| 1052 // Download the file and wait. |
| 1053 DownloadAndWaitWithDialog(browser(), url, downloaded_file); |
| 1054 |
| 1055 EXPECT_FALSE(file_util::PathExists(downloaded_file)); |
| 1056 EXPECT_FALSE(file_util::PathExists(GetDownloadSaveDirectory(browser()))); |
| 1057 EXPECT_EQ(1, browser()->tab_count()); |
| 1058 |
| 1059 // Clean up the generated files. |
| 1060 file_util::Delete(downloaded_file, false); |
| 1061 file_util::Delete(temporary_file, false); |
| 1062 } |
| 1063 |
961 #if defined(OS_WIN) | 1064 #if defined(OS_WIN) |
962 // Download a file and confirm that the zone identifier (on windows) | 1065 // Download a file and confirm that the zone identifier (on windows) |
963 // is set to internet. | 1066 // is set to internet. |
964 IN_PROC_BROWSER_TEST_F(DownloadTest, CheckInternetZone) { | 1067 IN_PROC_BROWSER_TEST_F(DownloadTest, CheckInternetZone) { |
965 ASSERT_TRUE(InitialSetup(false)); | 1068 ASSERT_TRUE(InitialSetup(false)); |
966 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1069 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
967 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1070 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
968 | 1071 |
969 // Download the file and wait. We do not expect the Select File dialog. | 1072 // Download the file and wait. |
970 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 1073 DownloadAndWait(browser(), url); |
971 | 1074 |
972 // Check state. Special file state must be checked before CheckDownload, | 1075 // Check state. Special file state must be checked before CheckDownload, |
973 // as CheckDownload will delete the output file. | 1076 // as CheckDownload will delete the output file. |
974 EXPECT_EQ(1, browser()->tab_count()); | 1077 EXPECT_EQ(1, browser()->tab_count()); |
975 FilePath downloaded_file(DestinationFile(browser(), file)); | 1078 FilePath downloaded_file(DestinationFile(browser(), file)); |
976 if (file_util::VolumeSupportsADS(downloaded_file)) | 1079 if (file_util::VolumeSupportsADS(downloaded_file)) |
977 EXPECT_TRUE(file_util::HasInternetZoneIdentifier(downloaded_file)); | 1080 EXPECT_TRUE(file_util::HasInternetZoneIdentifier(downloaded_file)); |
978 CheckDownload(browser(), file, file); | 1081 CheckDownload(browser(), file, file); |
979 CheckDownloadUI(browser(), true, true, file); | 1082 CheckDownloadUI(browser(), true, true, file); |
980 } | 1083 } |
981 #endif | 1084 #endif |
982 | 1085 |
983 // Put up a Select File dialog when the file is downloaded, due to its MIME | 1086 // Put up a select file dialog when the file is downloaded, due to its MIME |
984 // type. | 1087 // type. |
985 // | 1088 // |
986 // This test runs correctly, but leaves behind turds in the test user's | 1089 // This test runs correctly, but leaves behind turds in the test user's |
987 // download directory because of http://crbug.com/62099. No big loss; it | 1090 // download directory because of http://crbug.com/62099. No big loss; it |
988 // was primarily confirming DownloadsObserver wait on select file dialog | 1091 // was primarily confirming DownloadsObserver wait on select file dialog |
989 // functionality anyway. | 1092 // functionality anyway. |
990 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_DownloadMimeTypeSelect) { | 1093 IN_PROC_BROWSER_TEST_F(DownloadTest, DISABLED_DownloadMimeTypeSelect) { |
991 ASSERT_TRUE(InitialSetup(true)); | 1094 ASSERT_TRUE(InitialSetup(true)); |
992 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1095 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
993 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1096 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1097 FilePath file_path(DestinationFile(browser(), file)); |
994 | 1098 |
995 // Download the file and wait. We expect the Select File dialog to appear | 1099 // Download the file and wait. We expect the select file dialog to appear |
996 // due to the MIME type. | 1100 // due to the MIME type. |
997 DownloadAndWait(browser(), url, EXPECT_SELECT_DIALOG); | 1101 DownloadAndWaitWithDialog(browser(), url, file_path); |
998 | 1102 |
999 // Check state. | 1103 // Check state. |
1000 EXPECT_EQ(1, browser()->tab_count()); | 1104 EXPECT_EQ(1, browser()->tab_count()); |
1001 // Since we exited while the Select File dialog was visible, there should not | 1105 // Since we exited while the select file dialog was visible, there should not |
1002 // be anything in the download shelf and so it should not be visible. | 1106 // be anything in the download shelf and so it should not be visible. |
1003 CheckDownloadUI(browser(), false, false, FilePath()); | 1107 CheckDownloadUI(browser(), false, false, FilePath()); |
1004 } | 1108 } |
1005 | 1109 |
1006 // Access a file with a viewable mime-type, verify that a download | 1110 // Access a file with a viewable mime-type, verify that a download |
1007 // did not initiate. | 1111 // did not initiate. |
1008 IN_PROC_BROWSER_TEST_F(DownloadTest, NoDownload) { | 1112 IN_PROC_BROWSER_TEST_F(DownloadTest, NoDownload) { |
1009 ASSERT_TRUE(InitialSetup(false)); | 1113 ASSERT_TRUE(InitialSetup(false)); |
1010 FilePath file(FILE_PATH_LITERAL("download-test2.html")); | 1114 FilePath file(FILE_PATH_LITERAL("download-test2.html")); |
1011 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1115 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
(...skipping 14 matching lines...) Expand all Loading... |
1026 // download tab opened and the file exists as the filename specified in the | 1130 // download tab opened and the file exists as the filename specified in the |
1027 // header. This also ensures we properly handle empty file downloads. | 1131 // header. This also ensures we properly handle empty file downloads. |
1028 // The download shelf should be visible in the current tab. | 1132 // The download shelf should be visible in the current tab. |
1029 IN_PROC_BROWSER_TEST_F(DownloadTest, ContentDisposition) { | 1133 IN_PROC_BROWSER_TEST_F(DownloadTest, ContentDisposition) { |
1030 ASSERT_TRUE(InitialSetup(false)); | 1134 ASSERT_TRUE(InitialSetup(false)); |
1031 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); | 1135 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); |
1032 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1136 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1033 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); | 1137 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); |
1034 | 1138 |
1035 // Download a file and wait. | 1139 // Download a file and wait. |
1036 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 1140 DownloadAndWait(browser(), url); |
1037 | 1141 |
1038 CheckDownload(browser(), download_file, file); | 1142 CheckDownload(browser(), download_file, file); |
1039 | 1143 |
1040 // Check state. | 1144 // Check state. |
1041 EXPECT_EQ(1, browser()->tab_count()); | 1145 EXPECT_EQ(1, browser()->tab_count()); |
1042 CheckDownloadUI(browser(), true, true, download_file); | 1146 CheckDownloadUI(browser(), true, true, download_file); |
1043 } | 1147 } |
1044 | 1148 |
1045 #if !defined(OS_CHROMEOS) // Download shelf is not per-window on ChromeOS. | 1149 #if !defined(OS_CHROMEOS) // Download shelf is not per-window on ChromeOS. |
1046 // Test that the download shelf is per-window by starting a download in one | 1150 // Test that the download shelf is per-window by starting a download in one |
1047 // tab, opening a second tab, closing the shelf, going back to the first tab, | 1151 // tab, opening a second tab, closing the shelf, going back to the first tab, |
1048 // and checking that the shelf is closed. | 1152 // and checking that the shelf is closed. |
1049 IN_PROC_BROWSER_TEST_F(DownloadTest, PerWindowShelf) { | 1153 IN_PROC_BROWSER_TEST_F(DownloadTest, PerWindowShelf) { |
1050 ASSERT_TRUE(InitialSetup(false)); | 1154 ASSERT_TRUE(InitialSetup(false)); |
1051 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); | 1155 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); |
1052 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1156 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1053 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); | 1157 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); |
1054 | 1158 |
1055 // Download a file and wait. | 1159 // Download a file and wait. |
1056 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 1160 DownloadAndWait(browser(), url); |
1057 | 1161 |
1058 CheckDownload(browser(), download_file, file); | 1162 CheckDownload(browser(), download_file, file); |
1059 | 1163 |
1060 // Check state. | 1164 // Check state. |
1061 EXPECT_EQ(1, browser()->tab_count()); | 1165 EXPECT_EQ(1, browser()->tab_count()); |
1062 CheckDownloadUI(browser(), true, true, download_file); | 1166 CheckDownloadUI(browser(), true, true, download_file); |
1063 | 1167 |
1064 // Open a second tab and wait. | 1168 // Open a second tab and wait. |
1065 EXPECT_NE(static_cast<TabContentsWrapper*>(NULL), | 1169 EXPECT_NE(static_cast<TabContentsWrapper*>(NULL), |
1066 browser()->AddSelectedTabWithURL(GURL(), PageTransition::TYPED)); | 1170 browser()->AddSelectedTabWithURL(GURL(), PageTransition::TYPED)); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1111 int window_count = BrowserList::size(); | 1215 int window_count = BrowserList::size(); |
1112 EXPECT_EQ(2, window_count); | 1216 EXPECT_EQ(2, window_count); |
1113 | 1217 |
1114 // Download a file in the Incognito window and wait. | 1218 // Download a file in the Incognito window and wait. |
1115 CreateAndSetDownloadsDirectory(incognito); | 1219 CreateAndSetDownloadsDirectory(incognito); |
1116 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1220 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1117 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1221 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1118 // Since |incognito| is a separate browser, we have to set it up explicitly. | 1222 // Since |incognito| is a separate browser, we have to set it up explicitly. |
1119 incognito->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload, | 1223 incognito->profile()->GetPrefs()->SetBoolean(prefs::kPromptForDownload, |
1120 false); | 1224 false); |
1121 DownloadAndWait(incognito, url, EXPECT_NO_SELECT_DIALOG); | 1225 DownloadAndWait(incognito, url); |
1122 | 1226 |
1123 // We should still have 2 windows. | 1227 // We should still have 2 windows. |
1124 ExpectWindowCountAfterDownload(2); | 1228 ExpectWindowCountAfterDownload(2); |
1125 | 1229 |
1126 // Verify that the download shelf is showing for the Incognito window. | 1230 // Verify that the download shelf is showing for the Incognito window. |
1127 CheckDownloadUI(incognito, true, true, file); | 1231 CheckDownloadUI(incognito, true, true, file); |
1128 | 1232 |
1129 #if !defined(OS_MACOSX) | 1233 #if !defined(OS_MACOSX) |
1130 // On Mac OS X, the UI window close is delayed until the outermost | 1234 // On Mac OS X, the UI window close is delayed until the outermost |
1131 // message loop runs. So it isn't possible to get a BROWSER_CLOSED | 1235 // message loop runs. So it isn't possible to get a BROWSER_CLOSED |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1178 ASSERT_TRUE(InitialSetup(false)); | 1282 ASSERT_TRUE(InitialSetup(false)); |
1179 | 1283 |
1180 // Download a file in a new background tab and wait. The tab is automatically | 1284 // Download a file in a new background tab and wait. The tab is automatically |
1181 // closed when the download begins. | 1285 // closed when the download begins. |
1182 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1286 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1183 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1287 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1184 DownloadAndWaitWithDisposition( | 1288 DownloadAndWaitWithDisposition( |
1185 browser(), | 1289 browser(), |
1186 url, | 1290 url, |
1187 NEW_BACKGROUND_TAB, | 1291 NEW_BACKGROUND_TAB, |
1188 EXPECT_NO_SELECT_DIALOG, | 1292 false, |
| 1293 FilePath(), |
1189 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 1294 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
1190 | 1295 |
1191 // When the download finishes, we should still have one tab. | 1296 // When the download finishes, we should still have one tab. |
1192 CheckDownloadUI(browser(), true, true, file); | 1297 CheckDownloadUI(browser(), true, true, file); |
1193 EXPECT_EQ(1, browser()->tab_count()); | 1298 EXPECT_EQ(1, browser()->tab_count()); |
1194 | 1299 |
1195 CheckDownload(browser(), file, file); | 1300 CheckDownload(browser(), file, file); |
1196 } | 1301 } |
1197 | 1302 |
1198 // Open a web page in the current tab, then download a file in another tab via | 1303 // Open a web page in the current tab, then download a file in another tab via |
(...skipping 11 matching lines...) Expand all Loading... |
1210 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1)); | 1315 GURL url(URLRequestMockHTTPJob::GetMockUrl(file1)); |
1211 | 1316 |
1212 // Open a web page and wait. | 1317 // Open a web page and wait. |
1213 ui_test_utils::NavigateToURL(browser(), url); | 1318 ui_test_utils::NavigateToURL(browser(), url); |
1214 | 1319 |
1215 // Download a file in a new tab and wait (via Javascript). | 1320 // Download a file in a new tab and wait (via Javascript). |
1216 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1321 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1217 DownloadAndWaitWithDisposition(browser(), | 1322 DownloadAndWaitWithDisposition(browser(), |
1218 GURL("javascript:openNew()"), | 1323 GURL("javascript:openNew()"), |
1219 CURRENT_TAB, | 1324 CURRENT_TAB, |
1220 EXPECT_NO_SELECT_DIALOG, | 1325 false, |
| 1326 FilePath(), |
1221 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 1327 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
1222 | 1328 |
1223 // When the download finishes, we should have two tabs. | 1329 // When the download finishes, we should have two tabs. |
1224 CheckDownloadUI(browser(), true, true, file); | 1330 CheckDownloadUI(browser(), true, true, file); |
1225 EXPECT_EQ(2, browser()->tab_count()); | 1331 EXPECT_EQ(2, browser()->tab_count()); |
1226 | 1332 |
1227 CheckDownload(browser(), file, file); | 1333 CheckDownload(browser(), file, file); |
1228 } | 1334 } |
1229 | 1335 |
1230 // Open a web page in the current tab, open another tab via a Javascript call, | 1336 // Open a web page in the current tab, open another tab via a Javascript call, |
(...skipping 21 matching lines...) Expand all Loading... |
1252 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 1358 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
1253 | 1359 |
1254 EXPECT_EQ(2, browser()->tab_count()); | 1360 EXPECT_EQ(2, browser()->tab_count()); |
1255 | 1361 |
1256 // Download a file and wait. | 1362 // Download a file and wait. |
1257 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1363 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1258 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1364 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1259 DownloadAndWaitWithDisposition(browser(), | 1365 DownloadAndWaitWithDisposition(browser(), |
1260 url, | 1366 url, |
1261 CURRENT_TAB, | 1367 CURRENT_TAB, |
1262 EXPECT_NO_SELECT_DIALOG, | 1368 false, |
| 1369 FilePath(), |
1263 ui_test_utils::BROWSER_TEST_NONE); | 1370 ui_test_utils::BROWSER_TEST_NONE); |
1264 | 1371 |
1265 // When the download finishes, we should have two tabs. | 1372 // When the download finishes, we should have two tabs. |
1266 CheckDownloadUI(browser(), true, true, file); | 1373 CheckDownloadUI(browser(), true, true, file); |
1267 EXPECT_EQ(2, browser()->tab_count()); | 1374 EXPECT_EQ(2, browser()->tab_count()); |
1268 | 1375 |
1269 CheckDownload(browser(), file, file); | 1376 CheckDownload(browser(), file, file); |
1270 } | 1377 } |
1271 | 1378 |
1272 // Open a web page in the current tab, then download a file via Javascript, | 1379 // Open a web page in the current tab, then download a file via Javascript, |
(...skipping 12 matching lines...) Expand all Loading... |
1285 | 1392 |
1286 // Open a web page and wait. | 1393 // Open a web page and wait. |
1287 ui_test_utils::NavigateToURL(browser(), url); | 1394 ui_test_utils::NavigateToURL(browser(), url); |
1288 | 1395 |
1289 // Download a file and wait. | 1396 // Download a file and wait. |
1290 // The file to download is "download-test1.lib". | 1397 // The file to download is "download-test1.lib". |
1291 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1398 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1292 DownloadAndWaitWithDisposition(browser(), | 1399 DownloadAndWaitWithDisposition(browser(), |
1293 GURL("javascript:openNew()"), | 1400 GURL("javascript:openNew()"), |
1294 CURRENT_TAB, | 1401 CURRENT_TAB, |
1295 EXPECT_NO_SELECT_DIALOG, | 1402 false, |
| 1403 FilePath(), |
1296 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 1404 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
1297 | 1405 |
1298 // When the download finishes, we should still have one tab. | 1406 // When the download finishes, we should still have one tab. |
1299 CheckDownloadUI(browser(), true, true, file); | 1407 CheckDownloadUI(browser(), true, true, file); |
1300 EXPECT_EQ(1, browser()->tab_count()); | 1408 EXPECT_EQ(1, browser()->tab_count()); |
1301 | 1409 |
1302 CheckDownload(browser(), file, file); | 1410 CheckDownload(browser(), file, file); |
1303 } | 1411 } |
1304 | 1412 |
1305 // Open a web page in the current tab, then call Javascript via a button to | 1413 // Open a web page in the current tab, then call Javascript via a button to |
(...skipping 14 matching lines...) Expand all Loading... |
1320 ui_test_utils::NavigateToURL(browser(), url); | 1428 ui_test_utils::NavigateToURL(browser(), url); |
1321 | 1429 |
1322 // Download a file in a new tab and wait. The tab will automatically close | 1430 // Download a file in a new tab and wait. The tab will automatically close |
1323 // when the download begins. | 1431 // when the download begins. |
1324 // The file to download is "download-test1.lib". | 1432 // The file to download is "download-test1.lib". |
1325 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1433 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1326 DownloadAndWaitWithDisposition( | 1434 DownloadAndWaitWithDisposition( |
1327 browser(), | 1435 browser(), |
1328 GURL("javascript:document.getElementById('form').submit()"), | 1436 GURL("javascript:document.getElementById('form').submit()"), |
1329 CURRENT_TAB, | 1437 CURRENT_TAB, |
1330 EXPECT_NO_SELECT_DIALOG, | 1438 false, |
| 1439 FilePath(), |
1331 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 1440 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
1332 | 1441 |
1333 // When the download finishes, we should still have one tab. | 1442 // When the download finishes, we should still have one tab. |
1334 CheckDownloadUI(browser(), true, true, file); | 1443 CheckDownloadUI(browser(), true, true, file); |
1335 EXPECT_EQ(1, browser()->tab_count()); | 1444 EXPECT_EQ(1, browser()->tab_count()); |
1336 | 1445 |
1337 CheckDownload(browser(), file, file); | 1446 CheckDownload(browser(), file, file); |
1338 } | 1447 } |
1339 | 1448 |
1340 // Download a file in a new window. | 1449 // Download a file in a new window. |
1341 // Verify that we have 2 windows, and the download shelf is not visible in the | 1450 // Verify that we have 2 windows, and the download shelf is not visible in the |
1342 // first window, but is visible in the second window. | 1451 // first window, but is visible in the second window. |
1343 // Close the new window. | 1452 // Close the new window. |
1344 // Verify that we have 1 window, and the download shelf is not visible. | 1453 // Verify that we have 1 window, and the download shelf is not visible. |
1345 // | 1454 // |
1346 // Regression test for http://crbug.com/44454 | 1455 // Regression test for http://crbug.com/44454 |
1347 IN_PROC_BROWSER_TEST_F(DownloadTest, NewWindow) { | 1456 IN_PROC_BROWSER_TEST_F(DownloadTest, NewWindow) { |
1348 ASSERT_TRUE(InitialSetup(false)); | 1457 ASSERT_TRUE(InitialSetup(false)); |
1349 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1458 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1350 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1459 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1351 #if !defined(OS_MACOSX) | 1460 #if !defined(OS_MACOSX) |
1352 // See below. | 1461 // See below. |
1353 Browser* first_browser = browser(); | 1462 Browser* first_browser = browser(); |
1354 #endif | 1463 #endif |
1355 | 1464 |
1356 // Download a file in a new window and wait. | 1465 // Download a file in a new window and wait. |
1357 DownloadAndWaitWithDisposition(browser(), | 1466 DownloadAndWaitWithDisposition(browser(), |
1358 url, | 1467 url, |
1359 NEW_WINDOW, | 1468 NEW_WINDOW, |
1360 EXPECT_NO_SELECT_DIALOG, | 1469 false, |
| 1470 FilePath(), |
1361 ui_test_utils::BROWSER_TEST_NONE); | 1471 ui_test_utils::BROWSER_TEST_NONE); |
1362 | 1472 |
1363 // When the download finishes, the download shelf SHOULD NOT be visible in | 1473 // When the download finishes, the download shelf SHOULD NOT be visible in |
1364 // the first window. | 1474 // the first window. |
1365 ExpectWindowCountAfterDownload(2); | 1475 ExpectWindowCountAfterDownload(2); |
1366 EXPECT_EQ(1, browser()->tab_count()); | 1476 EXPECT_EQ(1, browser()->tab_count()); |
1367 // Download shelf should close. Download panel stays open on ChromeOS. | 1477 // Download shelf should close. Download panel stays open on ChromeOS. |
1368 CheckDownloadUI(browser(), false, true, file); | 1478 CheckDownloadUI(browser(), false, true, file); |
1369 | 1479 |
1370 // The download shelf SHOULD be visible in the second window. | 1480 // The download shelf SHOULD be visible in the second window. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1457 | 1567 |
1458 // Confirm a download makes it into the history properly. | 1568 // Confirm a download makes it into the history properly. |
1459 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryCheck) { | 1569 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadHistoryCheck) { |
1460 ASSERT_TRUE(InitialSetup(false)); | 1570 ASSERT_TRUE(InitialSetup(false)); |
1461 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1571 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1462 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1572 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1463 FilePath origin_file(OriginFile(file)); | 1573 FilePath origin_file(OriginFile(file)); |
1464 int64 origin_size; | 1574 int64 origin_size; |
1465 file_util::GetFileSize(origin_file, &origin_size); | 1575 file_util::GetFileSize(origin_file, &origin_size); |
1466 | 1576 |
1467 // Download the file and wait. We do not expect the Select File dialog. | 1577 // Download the file and wait. |
1468 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 1578 DownloadAndWait(browser(), url); |
1469 | 1579 |
1470 // Get details of what downloads have just happened. | 1580 // Get details of what downloads have just happened. |
1471 std::vector<DownloadItem*> downloads; | 1581 std::vector<DownloadItem*> downloads; |
1472 GetDownloads(browser(), &downloads); | 1582 GetDownloads(browser(), &downloads); |
1473 ASSERT_EQ(1u, downloads.size()); | 1583 ASSERT_EQ(1u, downloads.size()); |
1474 int64 db_handle = downloads[0]->db_handle(); | 1584 int64 db_handle = downloads[0]->db_handle(); |
1475 | 1585 |
1476 // Check state. | 1586 // Check state. |
1477 EXPECT_EQ(1, browser()->tab_count()); | 1587 EXPECT_EQ(1, browser()->tab_count()); |
1478 CheckDownload(browser(), file, file); | 1588 CheckDownload(browser(), file, file); |
(...skipping 16 matching lines...) Expand all Loading... |
1495 // Test for crbug.com/14505. This tests that chrome:// urls are still functional | 1605 // Test for crbug.com/14505. This tests that chrome:// urls are still functional |
1496 // after download of a file while viewing another chrome://. | 1606 // after download of a file while viewing another chrome://. |
1497 IN_PROC_BROWSER_TEST_F(DownloadTest, ChromeURLAfterDownload) { | 1607 IN_PROC_BROWSER_TEST_F(DownloadTest, ChromeURLAfterDownload) { |
1498 ASSERT_TRUE(InitialSetup(false)); | 1608 ASSERT_TRUE(InitialSetup(false)); |
1499 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1609 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1500 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1610 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1501 GURL flags_url(chrome::kChromeUIFlagsURL); | 1611 GURL flags_url(chrome::kChromeUIFlagsURL); |
1502 GURL extensions_url(chrome::kChromeUIExtensionsURL); | 1612 GURL extensions_url(chrome::kChromeUIExtensionsURL); |
1503 | 1613 |
1504 ui_test_utils::NavigateToURL(browser(), flags_url); | 1614 ui_test_utils::NavigateToURL(browser(), flags_url); |
1505 DownloadAndWait(browser(), download_url, EXPECT_NO_SELECT_DIALOG); | 1615 DownloadAndWait(browser(), download_url); |
1506 ui_test_utils::NavigateToURL(browser(), extensions_url); | 1616 ui_test_utils::NavigateToURL(browser(), extensions_url); |
1507 TabContents* contents = browser()->GetSelectedTabContents(); | 1617 TabContents* contents = browser()->GetSelectedTabContents(); |
1508 ASSERT_TRUE(contents); | 1618 ASSERT_TRUE(contents); |
1509 bool webui_responded = false; | 1619 bool webui_responded = false; |
1510 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 1620 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
1511 contents->render_view_host(), | 1621 contents->render_view_host(), |
1512 L"", | 1622 L"", |
1513 L"window.domAutomationController.send(window.webui_responded_);", | 1623 L"window.domAutomationController.send(window.webui_responded_);", |
1514 &webui_responded)); | 1624 &webui_responded)); |
1515 EXPECT_TRUE(webui_responded); | 1625 EXPECT_TRUE(webui_responded); |
(...skipping 16 matching lines...) Expand all Loading... |
1532 ASSERT_TRUE(contents); | 1642 ASSERT_TRUE(contents); |
1533 bool result = false; | 1643 bool result = false; |
1534 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 1644 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
1535 contents->render_view_host(), | 1645 contents->render_view_host(), |
1536 L"", | 1646 L"", |
1537 L"window.onunload = function() { var do_nothing = 0; }; " | 1647 L"window.onunload = function() { var do_nothing = 0; }; " |
1538 L"window.domAutomationController.send(true);", | 1648 L"window.domAutomationController.send(true);", |
1539 &result)); | 1649 &result)); |
1540 EXPECT_TRUE(result); | 1650 EXPECT_TRUE(result); |
1541 | 1651 |
1542 DownloadAndWait(browser(), download_url, EXPECT_NO_SELECT_DIALOG); | 1652 DownloadAndWait(browser(), download_url); |
1543 | 1653 |
1544 ui_test_utils::WindowedNotificationObserver signal( | 1654 ui_test_utils::WindowedNotificationObserver signal( |
1545 chrome::NOTIFICATION_BROWSER_CLOSED, | 1655 chrome::NOTIFICATION_BROWSER_CLOSED, |
1546 Source<Browser>(browser())); | 1656 Source<Browser>(browser())); |
1547 browser()->CloseWindow(); | 1657 browser()->CloseWindow(); |
1548 signal.Wait(); | 1658 signal.Wait(); |
1549 } | 1659 } |
1550 | 1660 |
1551 // Test to make sure the 'download' attribute in anchor tag is respected. | 1661 // Test to make sure the 'download' attribute in anchor tag is respected. |
1552 IN_PROC_BROWSER_TEST_F(DownloadTest, AnchorDownloadTag) { | 1662 IN_PROC_BROWSER_TEST_F(DownloadTest, AnchorDownloadTag) { |
1553 ASSERT_TRUE(InitialSetup(false)); | 1663 ASSERT_TRUE(InitialSetup(false)); |
1554 FilePath file(FILE_PATH_LITERAL("download-anchor-attrib.html")); | 1664 FilePath file(FILE_PATH_LITERAL("download-anchor-attrib.html")); |
1555 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1665 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1556 | 1666 |
1557 // Create a download, wait until it's complete, and confirm | 1667 // Create a download, wait until it's complete, and confirm |
1558 // we're in the expected state. | 1668 // we're in the expected state. |
1559 scoped_ptr<DownloadsObserver> observer(CreateWaiter(browser(), 1)); | 1669 scoped_ptr<DownloadsObserver> observer(CreateWaiter(browser(), 1, false)); |
1560 ui_test_utils::NavigateToURL(browser(), url); | 1670 ui_test_utils::NavigateToURL(browser(), url); |
1561 observer->WaitForFinished(); | 1671 observer->WaitForFinished(); |
1562 | 1672 |
1563 // Confirm the downloaded data exists. | 1673 // Confirm the downloaded data exists. |
1564 FilePath downloaded_file = GetDownloadDirectory(browser()); | 1674 FilePath downloaded_file( |
1565 downloaded_file = downloaded_file.Append(FILE_PATH_LITERAL("a_red_dot.png")); | 1675 DestinationFile(browser(), FilePath(FILE_PATH_LITERAL("a_red_dot.png")))); |
1566 EXPECT_TRUE(file_util::PathExists(downloaded_file)); | 1676 EXPECT_TRUE(file_util::PathExists(downloaded_file)); |
1567 } | 1677 } |
1568 | 1678 |
1569 // Test to make sure auto-open works. | 1679 // Test to make sure auto-open works. |
1570 IN_PROC_BROWSER_TEST_F(DownloadTest, AutoOpen) { | 1680 IN_PROC_BROWSER_TEST_F(DownloadTest, AutoOpen) { |
1571 ASSERT_TRUE(InitialSetup(false)); | 1681 ASSERT_TRUE(InitialSetup(false)); |
1572 FilePath file(FILE_PATH_LITERAL("download-autoopen.txt")); | 1682 FilePath file(FILE_PATH_LITERAL("download-autoopen.txt")); |
1573 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1683 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1574 | 1684 |
1575 ASSERT_TRUE( | 1685 ASSERT_TRUE( |
1576 GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file)); | 1686 GetDownloadPrefs(browser())->EnableAutoOpenBasedOnExtension(file)); |
1577 | 1687 |
1578 // Mock out external opening on all downloads until end of test. | 1688 // Mock out external opening on all downloads until end of test. |
1579 MockDownloadOpeningObserver observer( | 1689 MockDownloadOpeningObserver observer( |
1580 browser()->profile()->GetDownloadManager()); | 1690 browser()->profile()->GetDownloadManager()); |
1581 | 1691 |
1582 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); | 1692 DownloadAndWait(browser(), url); |
1583 | 1693 |
1584 // Find the download and confirm it was opened. | 1694 // Find the download and confirm it was opened. |
1585 std::vector<DownloadItem*> downloads; | 1695 std::vector<DownloadItem*> downloads; |
1586 browser()->profile()->GetDownloadManager()->SearchDownloads( | 1696 browser()->profile()->GetDownloadManager()->SearchDownloads( |
1587 string16(), &downloads); | 1697 string16(), &downloads); |
1588 ASSERT_EQ(1u, downloads.size()); | 1698 ASSERT_EQ(1u, downloads.size()); |
1589 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0]->state()); | 1699 EXPECT_EQ(DownloadItem::COMPLETE, downloads[0]->state()); |
1590 EXPECT_TRUE(downloads[0]->opened()); | 1700 EXPECT_TRUE(downloads[0]->opened()); |
1591 | 1701 |
1592 // As long as we're here, confirmed everything else is good. | 1702 // As long as we're here, confirmed everything else is good. |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1729 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1839 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
1730 | 1840 |
1731 // Download shelf should close. Download panel stays open on ChromeOS. | 1841 // Download shelf should close. Download panel stays open on ChromeOS. |
1732 CheckDownloadUI(browser(), false, true, FilePath()); | 1842 CheckDownloadUI(browser(), false, true, FilePath()); |
1733 | 1843 |
1734 // Check that the extension was installed. | 1844 // Check that the extension was installed. |
1735 ExtensionService* extension_service = | 1845 ExtensionService* extension_service = |
1736 browser()->profile()->GetExtensionService(); | 1846 browser()->profile()->GetExtensionService(); |
1737 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); | 1847 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); |
1738 } | 1848 } |
OLD | NEW |