| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 | 383 |
| 384 DownloadPrefs* GetDownloadPrefs(Browser* browser) { | 384 DownloadPrefs* GetDownloadPrefs(Browser* browser) { |
| 385 return DownloadPrefs::FromDownloadManager( | 385 return DownloadPrefs::FromDownloadManager( |
| 386 DownloadManagerForBrowser(browser)); | 386 DownloadManagerForBrowser(browser)); |
| 387 } | 387 } |
| 388 | 388 |
| 389 FilePath GetDownloadDirectory(Browser* browser) { | 389 FilePath GetDownloadDirectory(Browser* browser) { |
| 390 return GetDownloadPrefs(browser)->download_path(); | 390 return GetDownloadPrefs(browser)->download_path(); |
| 391 } | 391 } |
| 392 | 392 |
| 393 // Create a DownloadTestObserver that will wait for the | 393 // Create a DownloadTestObserverTerminal that will wait for the |
| 394 // specified number of downloads to finish. | 394 // specified number of downloads to finish. |
| 395 DownloadTestObserver* CreateWaiter(Browser* browser, int num_downloads) { | 395 DownloadTestObserver* CreateWaiter(Browser* browser, int num_downloads) { |
| 396 DownloadManager* download_manager = DownloadManagerForBrowser(browser); | 396 DownloadManager* download_manager = DownloadManagerForBrowser(browser); |
| 397 return new DownloadTestObserver( | 397 return new DownloadTestObserverTerminal( |
| 398 download_manager, num_downloads, | 398 download_manager, num_downloads, |
| 399 DownloadItem::COMPLETE, // Really done | |
| 400 true, // Bail on select file | 399 true, // Bail on select file |
| 401 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); | 400 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); |
| 402 } | 401 } |
| 403 | 402 |
| 404 // Create a DownloadTestObserver that will wait for the | 403 // Create a DownloadTestObserverInProgress that will wait for the |
| 405 // specified number of downloads to start. | 404 // specified number of downloads to start. |
| 406 DownloadTestObserver* CreateInProgressWaiter(Browser* browser, | 405 DownloadTestObserver* CreateInProgressWaiter(Browser* browser, |
| 407 int num_downloads) { | 406 int num_downloads) { |
| 408 DownloadManager* download_manager = DownloadManagerForBrowser(browser); | 407 DownloadManager* download_manager = DownloadManagerForBrowser(browser); |
| 409 return new DownloadTestObserver( | 408 return new DownloadTestObserverInProgress( |
| 410 download_manager, num_downloads, | 409 download_manager, num_downloads, true); // Bail on select file. |
| 411 DownloadItem::IN_PROGRESS, // Has started | |
| 412 true, // Bail on select file | |
| 413 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); | |
| 414 } | 410 } |
| 415 | 411 |
| 416 // Create a DownloadTestObserver that will wait for the | 412 // Create a DownloadTestObserverTerminal that will wait for the |
| 417 // specified number of downloads to finish, or for | 413 // specified number of downloads to finish, or for |
| 418 // a dangerous download warning to be shown. | 414 // a dangerous download warning to be shown. |
| 419 DownloadTestObserver* DangerousInstallWaiter( | 415 DownloadTestObserver* DangerousInstallWaiter( |
| 420 Browser* browser, | 416 Browser* browser, |
| 421 int num_downloads, | 417 int num_downloads, |
| 422 DownloadItem::DownloadState final_state, | |
| 423 DownloadTestObserver::DangerousDownloadAction dangerous_download_action) { | 418 DownloadTestObserver::DangerousDownloadAction dangerous_download_action) { |
| 424 DownloadManager* download_manager = DownloadManagerForBrowser(browser); | 419 DownloadManager* download_manager = DownloadManagerForBrowser(browser); |
| 425 return new DownloadTestObserver( | 420 return new DownloadTestObserverTerminal( |
| 426 download_manager, num_downloads, | 421 download_manager, num_downloads, |
| 427 final_state, | |
| 428 true, // Bail on select file | 422 true, // Bail on select file |
| 429 dangerous_download_action); | 423 dangerous_download_action); |
| 430 } | 424 } |
| 431 | 425 |
| 426 void CheckDownloadStatesForBrowser(Browser* browser, |
| 427 size_t num, |
| 428 DownloadItem::DownloadState state) { |
| 429 std::vector<DownloadItem*> download_items; |
| 430 GetDownloads(browser, &download_items); |
| 431 |
| 432 EXPECT_EQ(num, download_items.size()); |
| 433 |
| 434 for (size_t i = 0; i < download_items.size(); ++i) { |
| 435 EXPECT_EQ(state, download_items[i]->GetState()) << " Item " << i; |
| 436 } |
| 437 } |
| 438 |
| 439 void CheckDownloadStates(size_t num, DownloadItem::DownloadState state) { |
| 440 CheckDownloadStatesForBrowser(browser(), num, state); |
| 441 } |
| 442 |
| 432 // Download |url|, then wait for the download to finish. | 443 // Download |url|, then wait for the download to finish. |
| 433 // |disposition| indicates where the navigation occurs (current tab, new | 444 // |disposition| indicates where the navigation occurs (current tab, new |
| 434 // foreground tab, etc). | 445 // foreground tab, etc). |
| 435 // |expectation| indicates whether or not a Select File dialog should be | 446 // |expectation| indicates whether or not a Select File dialog should be |
| 436 // open when the download is finished, or if we don't care. | 447 // open when the download is finished, or if we don't care. |
| 437 // If the dialog appears, the routine exits. The only effect |expectation| | 448 // If the dialog appears, the routine exits. The only effect |expectation| |
| 438 // has is whether or not the test succeeds. | 449 // has is whether or not the test succeeds. |
| 439 // |browser_test_flags| indicate what to wait for, and is an OR of 0 or more | 450 // |browser_test_flags| indicate what to wait for, and is an OR of 0 or more |
| 440 // values in the ui_test_utils::BrowserTestWaitFlags enum. | 451 // values in the ui_test_utils::BrowserTestWaitFlags enum. |
| 441 void DownloadAndWaitWithDisposition(Browser* browser, | 452 void DownloadAndWaitWithDisposition(Browser* browser, |
| 442 const GURL& url, | 453 const GURL& url, |
| 443 WindowOpenDisposition disposition, | 454 WindowOpenDisposition disposition, |
| 444 SelectExpectation expectation, | 455 SelectExpectation expectation, |
| 445 int browser_test_flags) { | 456 int browser_test_flags) { |
| 446 // Setup notification, navigate, and block. | 457 // Setup notification, navigate, and block. |
| 447 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(browser, 1)); | 458 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(browser, 1)); |
| 448 // This call will block until the condition specified by | 459 // This call will block until the condition specified by |
| 449 // |browser_test_flags|, but will not wait for the download to finish. | 460 // |browser_test_flags|, but will not wait for the download to finish. |
| 450 ui_test_utils::NavigateToURLWithDisposition(browser, | 461 ui_test_utils::NavigateToURLWithDisposition(browser, |
| 451 url, | 462 url, |
| 452 disposition, | 463 disposition, |
| 453 browser_test_flags); | 464 browser_test_flags); |
| 454 // Waits for the download to complete. | 465 // Waits for the download to complete. |
| 455 observer->WaitForFinished(); | 466 observer->WaitForFinished(); |
| 467 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 456 | 468 |
| 457 // If specified, check the state of the select file dialog. | 469 // If specified, check the state of the select file dialog. |
| 458 if (expectation != EXPECT_NOTHING) { | 470 if (expectation != EXPECT_NOTHING) { |
| 459 EXPECT_EQ(expectation == EXPECT_SELECT_DIALOG, | 471 EXPECT_EQ(expectation == EXPECT_SELECT_DIALOG, |
| 460 observer->select_file_dialog_seen()); | 472 observer->select_file_dialog_seen()); |
| 461 } | 473 } |
| 462 } | 474 } |
| 463 | 475 |
| 464 // Download a file in the current tab, then wait for the download to finish. | 476 // Download a file in the current tab, then wait for the download to finish. |
| 465 void DownloadAndWait(Browser* browser, | 477 void DownloadAndWait(Browser* browser, |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 | 570 |
| 559 // Allow the request to finish. We do this by loading a second URL in a | 571 // Allow the request to finish. We do this by loading a second URL in a |
| 560 // separate tab. | 572 // separate tab. |
| 561 GURL finish_url(URLRequestSlowDownloadJob::kFinishDownloadUrl); | 573 GURL finish_url(URLRequestSlowDownloadJob::kFinishDownloadUrl); |
| 562 ui_test_utils::NavigateToURLWithDisposition( | 574 ui_test_utils::NavigateToURLWithDisposition( |
| 563 browser, | 575 browser, |
| 564 finish_url, | 576 finish_url, |
| 565 NEW_FOREGROUND_TAB, | 577 NEW_FOREGROUND_TAB, |
| 566 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 578 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 567 observer->WaitForFinished(); | 579 observer->WaitForFinished(); |
| 580 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 581 CheckDownloadStatesForBrowser(browser, 1, DownloadItem::COMPLETE); |
| 568 | 582 |
| 569 EXPECT_EQ(2, browser->tab_count()); | 583 EXPECT_EQ(2, browser->tab_count()); |
| 570 | 584 |
| 571 // TODO(ahendrickson): check download status text after downloading. | 585 // TODO(ahendrickson): check download status text after downloading. |
| 572 | 586 |
| 573 FilePath basefilename(filename.BaseName()); | 587 FilePath basefilename(filename.BaseName()); |
| 574 net::FileURLToFilePath(url, &filename); | 588 net::FileURLToFilePath(url, &filename); |
| 575 FilePath download_path = downloads_directory_.path().Append(basefilename); | 589 FilePath download_path = downloads_directory_.path().Append(basefilename); |
| 576 CheckDownloadUI(browser, true, true, basefilename); | 590 CheckDownloadUI(browser, true, true, basefilename); |
| 577 | 591 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 GetDownloads(browser(), &download_items); | 702 GetDownloads(browser(), &download_items); |
| 689 ASSERT_TRUE(download_items.empty()); | 703 ASSERT_TRUE(download_items.empty()); |
| 690 | 704 |
| 691 std::string server_path = "files/downloads/"; | 705 std::string server_path = "files/downloads/"; |
| 692 server_path += download_info.url_name; | 706 server_path += download_info.url_name; |
| 693 GURL url = test_server()->GetURL(server_path); | 707 GURL url = test_server()->GetURL(server_path); |
| 694 ASSERT_TRUE(url.is_valid()); | 708 ASSERT_TRUE(url.is_valid()); |
| 695 | 709 |
| 696 DownloadManager* download_manager = DownloadManagerForBrowser(browser()); | 710 DownloadManager* download_manager = DownloadManagerForBrowser(browser()); |
| 697 scoped_ptr<DownloadTestObserver> observer( | 711 scoped_ptr<DownloadTestObserver> observer( |
| 698 new DownloadTestObserver( | 712 new DownloadTestObserverTerminal( |
| 699 download_manager, | 713 download_manager, |
| 700 1, | 714 1, |
| 701 download_info.reason == content::DOWNLOAD_INTERRUPT_REASON_NONE ? | |
| 702 DownloadItem::COMPLETE : // Really done | |
| 703 DownloadItem::INTERRUPTED, | |
| 704 true, // Bail on select file | 715 true, // Bail on select file |
| 705 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 716 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 706 | 717 |
| 707 if (download_info.download_method == DOWNLOAD_DIRECT) { | 718 if (download_info.download_method == DOWNLOAD_DIRECT) { |
| 708 // Go directly to download. | 719 // Go directly to download. |
| 709 WebContents* web_contents = browser()->GetSelectedWebContents(); | 720 WebContents* web_contents = browser()->GetSelectedWebContents(); |
| 710 ASSERT_TRUE(web_contents); | 721 ASSERT_TRUE(web_contents); |
| 711 DownloadSaveInfo save_info; | 722 DownloadSaveInfo save_info; |
| 712 save_info.prompt_for_save_location = false; | 723 save_info.prompt_for_save_location = false; |
| 713 | 724 |
| 714 DownloadManagerForBrowser(browser())->DownloadUrl( | 725 DownloadManagerForBrowser(browser())->DownloadUrl( |
| 715 url, GURL(""), "", false, -1, save_info, web_contents); | 726 url, GURL(""), "", false, -1, save_info, web_contents); |
| 716 } else { | 727 } else { |
| 717 // Navigate to URL normally, wait until done. | 728 // Navigate to URL normally, wait until done. |
| 718 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), | 729 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), |
| 719 url, | 730 url, |
| 720 1); | 731 1); |
| 721 } | 732 } |
| 722 | 733 |
| 723 if (download_info.show_download_item) | 734 if (download_info.show_download_item) { |
| 724 observer->WaitForFinished(); | 735 observer->WaitForFinished(); |
| 736 DownloadItem::DownloadState final_state = |
| 737 (download_info.reason == content::DOWNLOAD_INTERRUPT_REASON_NONE) ? |
| 738 DownloadItem::COMPLETE : |
| 739 DownloadItem::INTERRUPTED; |
| 740 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(final_state)); |
| 741 } |
| 725 | 742 |
| 726 // Validate that the correct file was downloaded. | 743 // Validate that the correct file was downloaded. |
| 727 download_items.clear(); | 744 download_items.clear(); |
| 728 GetDownloads(browser(), &download_items); | 745 GetDownloads(browser(), &download_items); |
| 729 size_t item_count = download_info.show_download_item ? 1 : 0; | 746 size_t item_count = download_info.show_download_item ? 1 : 0; |
| 730 ASSERT_EQ(item_count, download_items.size()); | 747 ASSERT_EQ(item_count, download_items.size()); |
| 731 | 748 |
| 732 if (download_info.show_download_item) { | 749 if (download_info.show_download_item) { |
| 733 DownloadItem* item = download_items[0]; | 750 DownloadItem* item = download_items[0]; |
| 734 ASSERT_EQ(url, item->GetOriginalUrl()); | 751 ASSERT_EQ(url, item->GetOriginalUrl()); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 793 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeTypeSelect) { | 810 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeTypeSelect) { |
| 794 ASSERT_TRUE(InitialSetup(true)); | 811 ASSERT_TRUE(InitialSetup(true)); |
| 795 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 812 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 796 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 813 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 797 | 814 |
| 798 NullSelectFile(browser()); | 815 NullSelectFile(browser()); |
| 799 | 816 |
| 800 // Download the file and wait. We expect the Select File dialog to appear | 817 // Download the file and wait. We expect the Select File dialog to appear |
| 801 // due to the MIME type, but we still wait until the download completes. | 818 // due to the MIME type, but we still wait until the download completes. |
| 802 scoped_ptr<DownloadTestObserver> observer( | 819 scoped_ptr<DownloadTestObserver> observer( |
| 803 new DownloadTestObserver( | 820 new DownloadTestObserverTerminal( |
| 804 DownloadManagerForBrowser(browser()), | 821 DownloadManagerForBrowser(browser()), |
| 805 1, | 822 1, |
| 806 DownloadItem::COMPLETE, // Really done | |
| 807 false, // Continue on select file. | 823 false, // Continue on select file. |
| 808 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 824 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 809 ui_test_utils::NavigateToURLWithDisposition( | 825 ui_test_utils::NavigateToURLWithDisposition( |
| 810 browser(), url, CURRENT_TAB, | 826 browser(), url, CURRENT_TAB, |
| 811 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 827 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 812 observer->WaitForFinished(); | 828 observer->WaitForFinished(); |
| 829 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 830 CheckDownloadStates(1, DownloadItem::COMPLETE); |
| 813 EXPECT_TRUE(observer->select_file_dialog_seen()); | 831 EXPECT_TRUE(observer->select_file_dialog_seen()); |
| 814 | 832 |
| 815 // Check state. | 833 // Check state. |
| 816 EXPECT_EQ(1, browser()->tab_count()); | 834 EXPECT_EQ(1, browser()->tab_count()); |
| 817 CheckDownload(browser(), file, file); | 835 CheckDownload(browser(), file, file); |
| 818 CheckDownloadUI(browser(), true, true, file); | 836 CheckDownloadUI(browser(), true, true, file); |
| 819 } | 837 } |
| 820 | 838 |
| 821 // Access a file with a viewable mime-type, verify that a download | 839 // Access a file with a viewable mime-type, verify that a download |
| 822 // did not initiate. | 840 // did not initiate. |
| (...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1323 // Allow the first request to finish. We do this by loading a third URL | 1341 // Allow the first request to finish. We do this by loading a third URL |
| 1324 // in a separate tab. | 1342 // in a separate tab. |
| 1325 scoped_ptr<DownloadTestObserver> observer2(CreateWaiter(browser(), 1)); | 1343 scoped_ptr<DownloadTestObserver> observer2(CreateWaiter(browser(), 1)); |
| 1326 GURL finish_url(URLRequestSlowDownloadJob::kFinishDownloadUrl); | 1344 GURL finish_url(URLRequestSlowDownloadJob::kFinishDownloadUrl); |
| 1327 ui_test_utils::NavigateToURLWithDisposition( | 1345 ui_test_utils::NavigateToURLWithDisposition( |
| 1328 browser(), | 1346 browser(), |
| 1329 finish_url, | 1347 finish_url, |
| 1330 NEW_FOREGROUND_TAB, | 1348 NEW_FOREGROUND_TAB, |
| 1331 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 1349 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 1332 observer2->WaitForFinished(); // Wait for the third request. | 1350 observer2->WaitForFinished(); // Wait for the third request. |
| 1351 EXPECT_EQ(1u, observer2->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 1333 | 1352 |
| 1334 // Get the important info from other threads and check it. | 1353 // Get the important info from other threads and check it. |
| 1335 scoped_refptr<CancelTestDataCollector> info(new CancelTestDataCollector()); | 1354 scoped_refptr<CancelTestDataCollector> info(new CancelTestDataCollector()); |
| 1336 info->WaitForDataCollected(); | 1355 info->WaitForDataCollected(); |
| 1337 EXPECT_EQ(0, info->dfm_pending_downloads()); | 1356 EXPECT_EQ(0, info->dfm_pending_downloads()); |
| 1338 | 1357 |
| 1339 CheckDownloadUI(browser(), true, true, FilePath()); | 1358 CheckDownloadUI(browser(), true, true, FilePath()); |
| 1340 | 1359 |
| 1341 // The |DownloadItem|s should now be done and have the final file names. | 1360 // The |DownloadItem|s should now be done and have the final file names. |
| 1342 // Verify that the files have the expected data and size. | 1361 // Verify that the files have the expected data and size. |
| 1343 // |file1| should be full of '*'s, and |file2| should be the same as the | 1362 // |file1| should be full of '*'s, and |file2| should be the same as the |
| 1344 // source file. | 1363 // source file. |
| 1345 FilePath file1(download1->GetFullPath()); | 1364 FilePath file1(download1->GetFullPath()); |
| 1346 size_t file_size1 = URLRequestSlowDownloadJob::kFirstDownloadSize + | 1365 size_t file_size1 = URLRequestSlowDownloadJob::kFirstDownloadSize + |
| 1347 URLRequestSlowDownloadJob::kSecondDownloadSize; | 1366 URLRequestSlowDownloadJob::kSecondDownloadSize; |
| 1348 std::string expected_contents(file_size1, '*'); | 1367 std::string expected_contents(file_size1, '*'); |
| 1349 ASSERT_TRUE(VerifyFile(file1, expected_contents, file_size1)); | 1368 ASSERT_TRUE(VerifyFile(file1, expected_contents, file_size1)); |
| 1350 | 1369 |
| 1351 FilePath file2(download2->GetFullPath()); | 1370 FilePath file2(download2->GetFullPath()); |
| 1352 ASSERT_TRUE(file_util::ContentsEqual(OriginFile(file), file2)); | 1371 ASSERT_TRUE(file_util::ContentsEqual(OriginFile(file), file2)); |
| 1353 } | 1372 } |
| 1354 | 1373 |
| 1355 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadCancelled) { | 1374 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadCancelled) { |
| 1356 ASSERT_TRUE(InitialSetup(false)); | 1375 ASSERT_TRUE(InitialSetup(false)); |
| 1357 EXPECT_EQ(1, browser()->tab_count()); | 1376 EXPECT_EQ(1, browser()->tab_count()); |
| 1358 | 1377 |
| 1359 // TODO(rdsmith): Fragile code warning! The code below relies on the | 1378 // TODO(rdsmith): Fragile code warning! The code below relies on the |
| 1360 // DownloadTestObserver only finishing when the new download has reached | 1379 // DownloadTestObserverInProgress only finishing when the new download |
| 1361 // the state of being entered into the history and being user-visible | 1380 // has reached the state of being entered into the history and being |
| 1362 // (that's what's required for the Remove to be valid and for the | 1381 // user-visible (that's what's required for the Remove to be valid and |
| 1363 // download shelf to be visible). By the pure semantics of | 1382 // for the download shelf to be visible). By the pure semantics of |
| 1364 // DownloadTestObserver, that's not guaranteed; DownloadItems are created | 1383 // DownloadTestObserverInProgress, that's not guaranteed; DownloadItems |
| 1365 // in the IN_PROGRESS state and made known to the DownloadManager | 1384 // are created in the IN_PROGRESS state and made known to the DownloadManager |
| 1366 // immediately, so any ModelChanged event on the DownloadManager after | 1385 // immediately, so any ModelChanged event on the DownloadManager after |
| 1367 // navigation would allow the observer to return. However, the only | 1386 // navigation would allow the observer to return. However, the only |
| 1368 // ModelChanged() event the code will currently fire is in | 1387 // ModelChanged() event the code will currently fire is in |
| 1369 // OnCreateDownloadEntryComplete, at which point the download item will | 1388 // OnCreateDownloadEntryComplete, at which point the download item will |
| 1370 // be in the state we need. | 1389 // be in the state we need. |
| 1371 // The right way to fix this is to create finer grained states on the | 1390 // The right way to fix this is to create finer grained states on the |
| 1372 // DownloadItem, and wait for the state that indicates the item has been | 1391 // DownloadItem, and wait for the state that indicates the item has been |
| 1373 // entered in the history and made visible in the UI. | 1392 // entered in the history and made visible in the UI. |
| 1374 | 1393 |
| 1375 // Create a download, wait until it's started, and confirm | 1394 // Create a download, wait until it's started, and confirm |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1501 IN_PROC_BROWSER_TEST_F(DownloadTest, AnchorDownloadTag) { | 1520 IN_PROC_BROWSER_TEST_F(DownloadTest, AnchorDownloadTag) { |
| 1502 ASSERT_TRUE(InitialSetup(false)); | 1521 ASSERT_TRUE(InitialSetup(false)); |
| 1503 FilePath file(FILE_PATH_LITERAL("download-anchor-attrib.html")); | 1522 FilePath file(FILE_PATH_LITERAL("download-anchor-attrib.html")); |
| 1504 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1523 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1505 | 1524 |
| 1506 // Create a download, wait until it's complete, and confirm | 1525 // Create a download, wait until it's complete, and confirm |
| 1507 // we're in the expected state. | 1526 // we're in the expected state. |
| 1508 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(browser(), 1)); | 1527 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(browser(), 1)); |
| 1509 ui_test_utils::NavigateToURL(browser(), url); | 1528 ui_test_utils::NavigateToURL(browser(), url); |
| 1510 observer->WaitForFinished(); | 1529 observer->WaitForFinished(); |
| 1530 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 1531 CheckDownloadStates(1, DownloadItem::COMPLETE); |
| 1511 | 1532 |
| 1512 // Confirm the downloaded data exists. | 1533 // Confirm the downloaded data exists. |
| 1513 FilePath downloaded_file = GetDownloadDirectory(browser()); | 1534 FilePath downloaded_file = GetDownloadDirectory(browser()); |
| 1514 downloaded_file = downloaded_file.Append(FILE_PATH_LITERAL("a_red_dot.png")); | 1535 downloaded_file = downloaded_file.Append(FILE_PATH_LITERAL("a_red_dot.png")); |
| 1515 EXPECT_TRUE(file_util::PathExists(downloaded_file)); | 1536 EXPECT_TRUE(file_util::PathExists(downloaded_file)); |
| 1516 } | 1537 } |
| 1517 | 1538 |
| 1518 // Test to make sure auto-open works. | 1539 // Test to make sure auto-open works. |
| 1519 IN_PROC_BROWSER_TEST_F(DownloadTest, AutoOpen) { | 1540 IN_PROC_BROWSER_TEST_F(DownloadTest, AutoOpen) { |
| 1520 ASSERT_TRUE(InitialSetup(false)); | 1541 ASSERT_TRUE(InitialSetup(false)); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1546 } | 1567 } |
| 1547 | 1568 |
| 1548 // Download an extension. Expect a dangerous download warning. | 1569 // Download an extension. Expect a dangerous download warning. |
| 1549 // Deny the download. | 1570 // Deny the download. |
| 1550 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxDenyInstall) { | 1571 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxDenyInstall) { |
| 1551 ASSERT_TRUE(InitialSetup(false)); | 1572 ASSERT_TRUE(InitialSetup(false)); |
| 1552 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); | 1573 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); |
| 1553 | 1574 |
| 1554 scoped_ptr<DownloadTestObserver> observer( | 1575 scoped_ptr<DownloadTestObserver> observer( |
| 1555 DangerousInstallWaiter( | 1576 DangerousInstallWaiter( |
| 1556 browser(), 1, DownloadItem::CANCELLED, | 1577 browser(), 1, |
| 1557 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); | 1578 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); |
| 1558 ui_test_utils::NavigateToURL(browser(), extension_url); | 1579 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 1559 | 1580 |
| 1560 observer->WaitForFinished(); | 1581 observer->WaitForFinished(); |
| 1582 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::CANCELLED)); |
| 1561 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1583 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
| 1562 | 1584 |
| 1563 // Download shelf should close. Download panel stays open on ChromeOS. | 1585 // Download shelf should close. Download panel stays open on ChromeOS. |
| 1564 CheckDownloadUI(browser(), false, true, FilePath()); | 1586 CheckDownloadUI(browser(), false, true, FilePath()); |
| 1565 | 1587 |
| 1566 // Check that the CRX is not installed. | 1588 // Check that the CRX is not installed. |
| 1567 ExtensionService* extension_service = | 1589 ExtensionService* extension_service = |
| 1568 browser()->profile()->GetExtensionService(); | 1590 browser()->profile()->GetExtensionService(); |
| 1569 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1591 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); |
| 1570 } | 1592 } |
| 1571 | 1593 |
| 1572 // Download an extension. Expect a dangerous download warning. | 1594 // Download an extension. Expect a dangerous download warning. |
| 1573 // Allow the download, deny the install. | 1595 // Allow the download, deny the install. |
| 1574 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallDenysPermissions) { | 1596 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallDenysPermissions) { |
| 1575 ASSERT_TRUE(InitialSetup(false)); | 1597 ASSERT_TRUE(InitialSetup(false)); |
| 1576 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); | 1598 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); |
| 1577 | 1599 |
| 1578 // Install a mock install UI that simulates a user denying permission to | 1600 // Install a mock install UI that simulates a user denying permission to |
| 1579 // finish the install. | 1601 // finish the install. |
| 1580 download_crx_util::SetMockInstallUIForTesting( | 1602 download_crx_util::SetMockInstallUIForTesting( |
| 1581 new MockAbortExtensionInstallUI()); | 1603 new MockAbortExtensionInstallUI()); |
| 1582 | 1604 |
| 1583 scoped_ptr<DownloadTestObserver> observer( | 1605 scoped_ptr<DownloadTestObserver> observer( |
| 1584 DangerousInstallWaiter( | 1606 DangerousInstallWaiter( |
| 1585 browser(), 1, DownloadItem::COMPLETE, | 1607 browser(), 1, |
| 1586 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); | 1608 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
| 1587 ui_test_utils::NavigateToURL(browser(), extension_url); | 1609 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 1588 | 1610 |
| 1589 observer->WaitForFinished(); | 1611 observer->WaitForFinished(); |
| 1612 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 1613 CheckDownloadStates(1, DownloadItem::COMPLETE); |
| 1590 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1614 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
| 1591 | 1615 |
| 1592 // Download shelf should close. Download panel stays open on ChromeOS. | 1616 // Download shelf should close. Download panel stays open on ChromeOS. |
| 1593 CheckDownloadUI(browser(), false, true, FilePath()); | 1617 CheckDownloadUI(browser(), false, true, FilePath()); |
| 1594 | 1618 |
| 1595 // Check that the extension was not installed. | 1619 // Check that the extension was not installed. |
| 1596 ExtensionService* extension_service = | 1620 ExtensionService* extension_service = |
| 1597 browser()->profile()->GetExtensionService(); | 1621 browser()->profile()->GetExtensionService(); |
| 1598 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1622 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); |
| 1599 } | 1623 } |
| 1600 | 1624 |
| 1601 // Download an extension. Expect a dangerous download warning. | 1625 // Download an extension. Expect a dangerous download warning. |
| 1602 // Allow the download, and the install. | 1626 // Allow the download, and the install. |
| 1603 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallAcceptPermissions) { | 1627 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallAcceptPermissions) { |
| 1604 ASSERT_TRUE(InitialSetup(false)); | 1628 ASSERT_TRUE(InitialSetup(false)); |
| 1605 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); | 1629 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); |
| 1606 | 1630 |
| 1607 // Install a mock install UI that simulates a user allowing permission to | 1631 // Install a mock install UI that simulates a user allowing permission to |
| 1608 // finish the install. | 1632 // finish the install. |
| 1609 download_crx_util::SetMockInstallUIForTesting( | 1633 download_crx_util::SetMockInstallUIForTesting( |
| 1610 new MockAutoConfirmExtensionInstallUI(browser()->profile())); | 1634 new MockAutoConfirmExtensionInstallUI(browser()->profile())); |
| 1611 | 1635 |
| 1612 scoped_ptr<DownloadTestObserver> observer( | 1636 scoped_ptr<DownloadTestObserver> observer( |
| 1613 DangerousInstallWaiter( | 1637 DangerousInstallWaiter( |
| 1614 browser(), 1, DownloadItem::COMPLETE, | 1638 browser(), 1, |
| 1615 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); | 1639 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
| 1616 ui_test_utils::NavigateToURL(browser(), extension_url); | 1640 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 1617 | 1641 |
| 1618 observer->WaitForFinished(); | 1642 observer->WaitForFinished(); |
| 1643 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 1644 CheckDownloadStates(1, DownloadItem::COMPLETE); |
| 1619 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1645 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
| 1620 | 1646 |
| 1621 // Download shelf should close. Download panel stays open on ChromeOS. | 1647 // Download shelf should close. Download panel stays open on ChromeOS. |
| 1622 CheckDownloadUI(browser(), false, true, FilePath()); | 1648 CheckDownloadUI(browser(), false, true, FilePath()); |
| 1623 | 1649 |
| 1624 // Check that the extension was installed. | 1650 // Check that the extension was installed. |
| 1625 ExtensionService* extension_service = | 1651 ExtensionService* extension_service = |
| 1626 browser()->profile()->GetExtensionService(); | 1652 browser()->profile()->GetExtensionService(); |
| 1627 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1653 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false)); |
| 1628 } | 1654 } |
| 1629 | 1655 |
| 1630 // Test installing a CRX that fails integrity checks. | 1656 // Test installing a CRX that fails integrity checks. |
| 1631 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) { | 1657 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) { |
| 1632 ASSERT_TRUE(InitialSetup(false)); | 1658 ASSERT_TRUE(InitialSetup(false)); |
| 1633 FilePath file(FILE_PATH_LITERAL("extensions/bad_signature.crx")); | 1659 FilePath file(FILE_PATH_LITERAL("extensions/bad_signature.crx")); |
| 1634 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1660 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1635 | 1661 |
| 1636 // Install a mock install UI that simulates a user allowing permission to | 1662 // Install a mock install UI that simulates a user allowing permission to |
| 1637 // finish the install, and dismisses any error message. We check that the | 1663 // finish the install, and dismisses any error message. We check that the |
| 1638 // install failed below. | 1664 // install failed below. |
| 1639 download_crx_util::SetMockInstallUIForTesting( | 1665 download_crx_util::SetMockInstallUIForTesting( |
| 1640 new MockAutoConfirmExtensionInstallUI(browser()->profile())); | 1666 new MockAutoConfirmExtensionInstallUI(browser()->profile())); |
| 1641 | 1667 |
| 1642 scoped_ptr<DownloadTestObserver> observer( | 1668 scoped_ptr<DownloadTestObserver> observer( |
| 1643 DangerousInstallWaiter( | 1669 DangerousInstallWaiter( |
| 1644 browser(), 1, DownloadItem::COMPLETE, | 1670 browser(), 1, |
| 1645 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); | 1671 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
| 1646 ui_test_utils::NavigateToURL(browser(), extension_url); | 1672 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 1647 | 1673 |
| 1648 observer->WaitForFinished(); | 1674 observer->WaitForFinished(); |
| 1675 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 1676 CheckDownloadStates(1, DownloadItem::COMPLETE); |
| 1649 | 1677 |
| 1650 // Check that the extension was not installed. | 1678 // Check that the extension was not installed. |
| 1651 ExtensionService* extension_service = | 1679 ExtensionService* extension_service = |
| 1652 browser()->profile()->GetExtensionService(); | 1680 browser()->profile()->GetExtensionService(); |
| 1653 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1681 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); |
| 1654 } | 1682 } |
| 1655 | 1683 |
| 1656 // Install a large (100kb) theme. | 1684 // Install a large (100kb) theme. |
| 1657 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxLargeTheme) { | 1685 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxLargeTheme) { |
| 1658 ASSERT_TRUE(InitialSetup(false)); | 1686 ASSERT_TRUE(InitialSetup(false)); |
| 1659 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kLargeThemePath)); | 1687 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kLargeThemePath)); |
| 1660 | 1688 |
| 1661 // Install a mock install UI that simulates a user allowing permission to | 1689 // Install a mock install UI that simulates a user allowing permission to |
| 1662 // finish the install. | 1690 // finish the install. |
| 1663 download_crx_util::SetMockInstallUIForTesting( | 1691 download_crx_util::SetMockInstallUIForTesting( |
| 1664 new MockAutoConfirmExtensionInstallUI(browser()->profile())); | 1692 new MockAutoConfirmExtensionInstallUI(browser()->profile())); |
| 1665 | 1693 |
| 1666 scoped_ptr<DownloadTestObserver> observer( | 1694 scoped_ptr<DownloadTestObserver> observer( |
| 1667 DangerousInstallWaiter( | 1695 DangerousInstallWaiter( |
| 1668 browser(), 1, DownloadItem::COMPLETE, | 1696 browser(), 1, |
| 1669 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); | 1697 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
| 1670 ui_test_utils::NavigateToURL(browser(), extension_url); | 1698 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 1671 | 1699 |
| 1672 observer->WaitForFinished(); | 1700 observer->WaitForFinished(); |
| 1701 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 1702 CheckDownloadStates(1, DownloadItem::COMPLETE); |
| 1673 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1703 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
| 1674 | 1704 |
| 1675 // Download shelf should close. Download panel stays open on ChromeOS. | 1705 // Download shelf should close. Download panel stays open on ChromeOS. |
| 1676 CheckDownloadUI(browser(), false, true, FilePath()); | 1706 CheckDownloadUI(browser(), false, true, FilePath()); |
| 1677 | 1707 |
| 1678 // Check that the extension was installed. | 1708 // Check that the extension was installed. |
| 1679 ExtensionService* extension_service = | 1709 ExtensionService* extension_service = |
| 1680 browser()->profile()->GetExtensionService(); | 1710 browser()->profile()->GetExtensionService(); |
| 1681 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); | 1711 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); |
| 1682 } | 1712 } |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1819 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1849 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1820 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1850 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1821 | 1851 |
| 1822 // DownloadUrl always prompts; return acceptance of whatever it prompts. | 1852 // DownloadUrl always prompts; return acceptance of whatever it prompts. |
| 1823 NullSelectFile(browser()); | 1853 NullSelectFile(browser()); |
| 1824 | 1854 |
| 1825 WebContents* web_contents = browser()->GetSelectedWebContents(); | 1855 WebContents* web_contents = browser()->GetSelectedWebContents(); |
| 1826 ASSERT_TRUE(web_contents); | 1856 ASSERT_TRUE(web_contents); |
| 1827 | 1857 |
| 1828 DownloadTestObserver* observer( | 1858 DownloadTestObserver* observer( |
| 1829 new DownloadTestObserver( | 1859 new DownloadTestObserverTerminal( |
| 1830 DownloadManagerForBrowser(browser()), 1, | 1860 DownloadManagerForBrowser(browser()), 1, |
| 1831 DownloadItem::COMPLETE, // Really done | 1861 false, // Ignore select file. |
| 1832 false, // Ignore select file. | 1862 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 1833 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | |
| 1834 DownloadSaveInfo save_info; | 1863 DownloadSaveInfo save_info; |
| 1835 save_info.prompt_for_save_location = true; | 1864 save_info.prompt_for_save_location = true; |
| 1836 DownloadManagerForBrowser(browser())->DownloadUrl( | 1865 DownloadManagerForBrowser(browser())->DownloadUrl( |
| 1837 url, GURL(""), "", false, -1, save_info, web_contents); | 1866 url, GURL(""), "", false, -1, save_info, web_contents); |
| 1838 observer->WaitForFinished(); | 1867 observer->WaitForFinished(); |
| 1868 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 1869 CheckDownloadStates(1, DownloadItem::COMPLETE); |
| 1839 EXPECT_TRUE(observer->select_file_dialog_seen()); | 1870 EXPECT_TRUE(observer->select_file_dialog_seen()); |
| 1840 | 1871 |
| 1841 // Check state. | 1872 // Check state. |
| 1842 EXPECT_EQ(1, browser()->tab_count()); | 1873 EXPECT_EQ(1, browser()->tab_count()); |
| 1843 ASSERT_TRUE(CheckDownload(browser(), file, file)); | 1874 ASSERT_TRUE(CheckDownload(browser(), file, file)); |
| 1844 CheckDownloadUI(browser(), true, true, file); | 1875 CheckDownloadUI(browser(), true, true, file); |
| 1845 } | 1876 } |
| 1846 | 1877 |
| 1847 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { | 1878 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { |
| 1848 ASSERT_TRUE(InitialSetup(false)); | 1879 ASSERT_TRUE(InitialSetup(false)); |
| 1849 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1880 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1850 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1881 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1851 | 1882 |
| 1852 WebContents* web_contents = browser()->GetSelectedWebContents(); | 1883 WebContents* web_contents = browser()->GetSelectedWebContents(); |
| 1853 ASSERT_TRUE(web_contents); | 1884 ASSERT_TRUE(web_contents); |
| 1854 | 1885 |
| 1855 ScopedTempDir other_directory; | 1886 ScopedTempDir other_directory; |
| 1856 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); | 1887 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); |
| 1857 FilePath target_file_full_path | 1888 FilePath target_file_full_path |
| 1858 = other_directory.path().Append(file.BaseName()); | 1889 = other_directory.path().Append(file.BaseName()); |
| 1859 DownloadSaveInfo save_info; | 1890 DownloadSaveInfo save_info; |
| 1860 save_info.file_path = target_file_full_path; | 1891 save_info.file_path = target_file_full_path; |
| 1861 | 1892 |
| 1862 DownloadTestObserver* observer(CreateWaiter(browser(), 1)); | 1893 DownloadTestObserver* observer(CreateWaiter(browser(), 1)); |
| 1863 DownloadManagerForBrowser(browser())->DownloadUrl( | 1894 DownloadManagerForBrowser(browser())->DownloadUrl( |
| 1864 url, GURL(""), "", false, -1, save_info, web_contents); | 1895 url, GURL(""), "", false, -1, save_info, web_contents); |
| 1865 observer->WaitForFinished(); | 1896 observer->WaitForFinished(); |
| 1897 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 1866 | 1898 |
| 1867 // Check state. | 1899 // Check state. |
| 1868 EXPECT_EQ(1, browser()->tab_count()); | 1900 EXPECT_EQ(1, browser()->tab_count()); |
| 1869 ASSERT_TRUE(CheckDownloadFullPaths(browser(), | 1901 ASSERT_TRUE(CheckDownloadFullPaths(browser(), |
| 1870 target_file_full_path, | 1902 target_file_full_path, |
| 1871 OriginFile(file))); | 1903 OriginFile(file))); |
| 1872 | 1904 |
| 1873 // Temporary downloads won't be visible. | 1905 // Temporary downloads won't be visible. |
| 1874 CheckDownloadUI(browser(), false, false, file); | 1906 CheckDownloadUI(browser(), false, false, file); |
| 1875 } | 1907 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1888 // each time. | 1920 // each time. |
| 1889 GURL url = test_server()->GetURL("files/downloads/image.jpg"); | 1921 GURL url = test_server()->GetURL("files/downloads/image.jpg"); |
| 1890 ASSERT_TRUE(url.is_valid()); | 1922 ASSERT_TRUE(url.is_valid()); |
| 1891 ui_test_utils::NavigateToURL(browser(), url); | 1923 ui_test_utils::NavigateToURL(browser(), url); |
| 1892 | 1924 |
| 1893 // Stop the test server, and then try to save the page. If cache validation | 1925 // Stop the test server, and then try to save the page. If cache validation |
| 1894 // is not bypassed then this will fail since the server is no longer | 1926 // is not bypassed then this will fail since the server is no longer |
| 1895 // reachable. | 1927 // reachable. |
| 1896 ASSERT_TRUE(test_server()->Stop()); | 1928 ASSERT_TRUE(test_server()->Stop()); |
| 1897 scoped_ptr<DownloadTestObserver> waiter( | 1929 scoped_ptr<DownloadTestObserver> waiter( |
| 1898 new DownloadTestObserver( | 1930 new DownloadTestObserverTerminal( |
| 1899 DownloadManagerForBrowser(browser()), 1, DownloadItem::COMPLETE, | 1931 DownloadManagerForBrowser(browser()), 1, |
| 1900 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 1932 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 1901 browser()->SavePage(); | 1933 browser()->SavePage(); |
| 1902 waiter->WaitForFinished(); | 1934 waiter->WaitForFinished(); |
| 1935 EXPECT_EQ(1u, waiter->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 1936 CheckDownloadStates(1, DownloadItem::COMPLETE); |
| 1903 | 1937 |
| 1904 // Validate that the correct file was downloaded. | 1938 // Validate that the correct file was downloaded. |
| 1905 GetDownloads(browser(), &download_items); | 1939 GetDownloads(browser(), &download_items); |
| 1906 EXPECT_TRUE(waiter->select_file_dialog_seen()); | 1940 EXPECT_TRUE(waiter->select_file_dialog_seen()); |
| 1907 ASSERT_EQ(1u, download_items.size()); | 1941 ASSERT_EQ(1u, download_items.size()); |
| 1908 ASSERT_EQ(url, download_items[0]->GetOriginalUrl()); | 1942 ASSERT_EQ(url, download_items[0]->GetOriginalUrl()); |
| 1909 | 1943 |
| 1910 // Try to download it via a context menu. | 1944 // Try to download it via a context menu. |
| 1911 scoped_ptr<DownloadTestObserver> waiter_context_menu( | 1945 scoped_ptr<DownloadTestObserver> waiter_context_menu( |
| 1912 new DownloadTestObserver( | 1946 new DownloadTestObserverTerminal( |
| 1913 DownloadManagerForBrowser(browser()), 1, DownloadItem::COMPLETE, | 1947 DownloadManagerForBrowser(browser()), 1, |
| 1914 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 1948 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 1915 content::ContextMenuParams context_menu_params; | 1949 content::ContextMenuParams context_menu_params; |
| 1916 context_menu_params.media_type = WebKit::WebContextMenuData::MediaTypeImage; | 1950 context_menu_params.media_type = WebKit::WebContextMenuData::MediaTypeImage; |
| 1917 context_menu_params.src_url = url; | 1951 context_menu_params.src_url = url; |
| 1918 context_menu_params.page_url = url; | 1952 context_menu_params.page_url = url; |
| 1919 TestRenderViewContextMenu menu(browser()->GetSelectedWebContents(), | 1953 TestRenderViewContextMenu menu(browser()->GetSelectedWebContents(), |
| 1920 context_menu_params); | 1954 context_menu_params); |
| 1921 menu.Init(); | 1955 menu.Init(); |
| 1922 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS); | 1956 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS); |
| 1923 waiter_context_menu->WaitForFinished(); | 1957 waiter_context_menu->WaitForFinished(); |
| 1958 EXPECT_EQ( |
| 1959 1u, waiter_context_menu->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 1960 CheckDownloadStates(2, DownloadItem::COMPLETE); |
| 1924 | 1961 |
| 1925 // Validate that the correct file was downloaded via the context menu. | 1962 // Validate that the correct file was downloaded via the context menu. |
| 1926 download_items.clear(); | 1963 download_items.clear(); |
| 1927 GetDownloads(browser(), &download_items); | 1964 GetDownloads(browser(), &download_items); |
| 1928 EXPECT_TRUE(waiter_context_menu->select_file_dialog_seen()); | 1965 EXPECT_TRUE(waiter_context_menu->select_file_dialog_seen()); |
| 1929 ASSERT_EQ(2u, download_items.size()); | 1966 ASSERT_EQ(2u, download_items.size()); |
| 1930 ASSERT_EQ(url, download_items[0]->GetOriginalUrl()); | 1967 ASSERT_EQ(url, download_items[0]->GetOriginalUrl()); |
| 1931 ASSERT_EQ(url, download_items[1]->GetOriginalUrl()); | 1968 ASSERT_EQ(url, download_items[1]->GetOriginalUrl()); |
| 1932 } | 1969 } |
| 1933 | 1970 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1963 string16(), ASCIIToUTF16("SubmitForm()")); | 2000 string16(), ASCIIToUTF16("SubmitForm()")); |
| 1964 observer.Wait(); | 2001 observer.Wait(); |
| 1965 EXPECT_EQ(jpeg_url, web_contents->GetURL()); | 2002 EXPECT_EQ(jpeg_url, web_contents->GetURL()); |
| 1966 | 2003 |
| 1967 // Stop the test server, and then try to save the page. If cache validation | 2004 // Stop the test server, and then try to save the page. If cache validation |
| 1968 // is not bypassed then this will fail since the server is no longer | 2005 // is not bypassed then this will fail since the server is no longer |
| 1969 // reachable. This will also fail if it tries to be retrieved via "GET" | 2006 // reachable. This will also fail if it tries to be retrieved via "GET" |
| 1970 // rather than "POST". | 2007 // rather than "POST". |
| 1971 ASSERT_TRUE(test_server()->Stop()); | 2008 ASSERT_TRUE(test_server()->Stop()); |
| 1972 scoped_ptr<DownloadTestObserver> waiter( | 2009 scoped_ptr<DownloadTestObserver> waiter( |
| 1973 new DownloadTestObserver( | 2010 new DownloadTestObserverTerminal( |
| 1974 DownloadManagerForBrowser(browser()), 1, DownloadItem::COMPLETE, | 2011 DownloadManagerForBrowser(browser()), 1, |
| 1975 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 2012 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 1976 browser()->SavePage(); | 2013 browser()->SavePage(); |
| 1977 waiter->WaitForFinished(); | 2014 waiter->WaitForFinished(); |
| 2015 EXPECT_EQ(1u, waiter->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 2016 CheckDownloadStates(1, DownloadItem::COMPLETE); |
| 1978 | 2017 |
| 1979 // Validate that the correct file was downloaded. | 2018 // Validate that the correct file was downloaded. |
| 1980 GetDownloads(browser(), &download_items); | 2019 GetDownloads(browser(), &download_items); |
| 1981 EXPECT_TRUE(waiter->select_file_dialog_seen()); | 2020 EXPECT_TRUE(waiter->select_file_dialog_seen()); |
| 1982 ASSERT_EQ(1u, download_items.size()); | 2021 ASSERT_EQ(1u, download_items.size()); |
| 1983 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl()); | 2022 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl()); |
| 1984 | 2023 |
| 1985 // Try to download it via a context menu. | 2024 // Try to download it via a context menu. |
| 1986 scoped_ptr<DownloadTestObserver> waiter_context_menu( | 2025 scoped_ptr<DownloadTestObserver> waiter_context_menu( |
| 1987 new DownloadTestObserver( | 2026 new DownloadTestObserverTerminal( |
| 1988 DownloadManagerForBrowser(browser()), 1, DownloadItem::COMPLETE, | 2027 DownloadManagerForBrowser(browser()), 1, |
| 1989 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 2028 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 1990 content::ContextMenuParams context_menu_params; | 2029 content::ContextMenuParams context_menu_params; |
| 1991 context_menu_params.media_type = WebKit::WebContextMenuData::MediaTypeImage; | 2030 context_menu_params.media_type = WebKit::WebContextMenuData::MediaTypeImage; |
| 1992 context_menu_params.src_url = jpeg_url; | 2031 context_menu_params.src_url = jpeg_url; |
| 1993 context_menu_params.page_url = jpeg_url; | 2032 context_menu_params.page_url = jpeg_url; |
| 1994 TestRenderViewContextMenu menu(web_contents, context_menu_params); | 2033 TestRenderViewContextMenu menu(web_contents, context_menu_params); |
| 1995 menu.Init(); | 2034 menu.Init(); |
| 1996 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS); | 2035 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS); |
| 1997 waiter_context_menu->WaitForFinished(); | 2036 waiter_context_menu->WaitForFinished(); |
| 2037 EXPECT_EQ( |
| 2038 1u, waiter_context_menu->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 2039 CheckDownloadStates(2, DownloadItem::COMPLETE); |
| 1998 | 2040 |
| 1999 // Validate that the correct file was downloaded via the context menu. | 2041 // Validate that the correct file was downloaded via the context menu. |
| 2000 download_items.clear(); | 2042 download_items.clear(); |
| 2001 GetDownloads(browser(), &download_items); | 2043 GetDownloads(browser(), &download_items); |
| 2002 EXPECT_TRUE(waiter_context_menu->select_file_dialog_seen()); | 2044 EXPECT_TRUE(waiter_context_menu->select_file_dialog_seen()); |
| 2003 ASSERT_EQ(2u, download_items.size()); | 2045 ASSERT_EQ(2u, download_items.size()); |
| 2004 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl()); | 2046 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl()); |
| 2005 ASSERT_EQ(jpeg_url, download_items[1]->GetOriginalUrl()); | 2047 ASSERT_EQ(jpeg_url, download_items[1]->GetOriginalUrl()); |
| 2006 } | 2048 } |
| 2007 | 2049 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2075 "zip_file_not_found.zip", | 2117 "zip_file_not_found.zip", |
| 2076 DOWNLOAD_NAVIGATE, | 2118 DOWNLOAD_NAVIGATE, |
| 2077 content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, | 2119 content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, |
| 2078 false | 2120 false |
| 2079 }; | 2121 }; |
| 2080 | 2122 |
| 2081 // Do initial setup. | 2123 // Do initial setup. |
| 2082 ASSERT_TRUE(InitialSetup(false)); | 2124 ASSERT_TRUE(InitialSetup(false)); |
| 2083 DownloadFileCheckErrors(download_info); | 2125 DownloadFileCheckErrors(download_info); |
| 2084 } | 2126 } |
| OLD | NEW |