| 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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 | 328 |
| 329 DownloadPrefs* GetDownloadPrefs(Browser* browser) { | 329 DownloadPrefs* GetDownloadPrefs(Browser* browser) { |
| 330 return DownloadPrefs::FromDownloadManager( | 330 return DownloadPrefs::FromDownloadManager( |
| 331 DownloadManagerForBrowser(browser)); | 331 DownloadManagerForBrowser(browser)); |
| 332 } | 332 } |
| 333 | 333 |
| 334 FilePath GetDownloadDirectory(Browser* browser) { | 334 FilePath GetDownloadDirectory(Browser* browser) { |
| 335 return GetDownloadPrefs(browser)->download_path(); | 335 return GetDownloadPrefs(browser)->download_path(); |
| 336 } | 336 } |
| 337 | 337 |
| 338 // Create a DownloadTestObserver that will wait for the | 338 // Create a DownloadTestObserverTerminal that will wait for the |
| 339 // specified number of downloads to finish. | 339 // specified number of downloads to finish. |
| 340 DownloadTestObserver* CreateWaiter(Browser* browser, int num_downloads) { | 340 DownloadTestObserver* CreateWaiter(Browser* browser, int num_downloads) { |
| 341 DownloadManager* download_manager = DownloadManagerForBrowser(browser); | 341 DownloadManager* download_manager = DownloadManagerForBrowser(browser); |
| 342 return new DownloadTestObserver( | 342 return new DownloadTestObserverTerminal( |
| 343 download_manager, num_downloads, | 343 download_manager, num_downloads, |
| 344 DownloadItem::COMPLETE, // Really done | |
| 345 true, // Bail on select file | 344 true, // Bail on select file |
| 346 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); | 345 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); |
| 347 } | 346 } |
| 348 | 347 |
| 349 // Create a DownloadTestObserver that will wait for the | 348 // Create a DownloadTestObserverInProgress that will wait for the |
| 350 // specified number of downloads to start. | 349 // specified number of downloads to start. |
| 351 DownloadTestObserver* CreateInProgressWaiter(Browser* browser, | 350 DownloadTestObserver* CreateInProgressWaiter(Browser* browser, |
| 352 int num_downloads) { | 351 int num_downloads) { |
| 353 DownloadManager* download_manager = DownloadManagerForBrowser(browser); | 352 DownloadManager* download_manager = DownloadManagerForBrowser(browser); |
| 354 return new DownloadTestObserver( | 353 return new DownloadTestObserverInProgress( |
| 355 download_manager, num_downloads, | 354 download_manager, num_downloads, true); // Bail on select file. |
| 356 DownloadItem::IN_PROGRESS, // Has started | |
| 357 true, // Bail on select file | |
| 358 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); | |
| 359 } | 355 } |
| 360 | 356 |
| 361 // Create a DownloadTestObserver that will wait for the | 357 // Create a DownloadTestObserverTerminal that will wait for the |
| 362 // specified number of downloads to finish, or for | 358 // specified number of downloads to finish, or for |
| 363 // a dangerous download warning to be shown. | 359 // a dangerous download warning to be shown. |
| 364 DownloadTestObserver* DangerousInstallWaiter( | 360 DownloadTestObserver* DangerousInstallWaiter( |
| 365 Browser* browser, | 361 Browser* browser, |
| 366 int num_downloads, | 362 int num_downloads, |
| 367 DownloadItem::DownloadState final_state, | |
| 368 DownloadTestObserver::DangerousDownloadAction dangerous_download_action) { | 363 DownloadTestObserver::DangerousDownloadAction dangerous_download_action) { |
| 369 DownloadManager* download_manager = DownloadManagerForBrowser(browser); | 364 DownloadManager* download_manager = DownloadManagerForBrowser(browser); |
| 370 return new DownloadTestObserver( | 365 return new DownloadTestObserverTerminal( |
| 371 download_manager, num_downloads, | 366 download_manager, num_downloads, |
| 372 final_state, | |
| 373 true, // Bail on select file | 367 true, // Bail on select file |
| 374 dangerous_download_action); | 368 dangerous_download_action); |
| 375 } | 369 } |
| 376 | 370 |
| 371 void CheckDownloadStatesForBrowser(Browser* browser, |
| 372 size_t num, |
| 373 DownloadItem::DownloadState state) { |
| 374 std::vector<DownloadItem*> download_items; |
| 375 GetDownloads(browser, &download_items); |
| 376 |
| 377 EXPECT_EQ(num, download_items.size()); |
| 378 |
| 379 for (size_t i = 0; i < download_items.size(); ++i) { |
| 380 EXPECT_EQ(state, download_items[i]->GetState()) << " Item " << i; |
| 381 } |
| 382 } |
| 383 |
| 384 void CheckDownloadStates(size_t num, DownloadItem::DownloadState state) { |
| 385 CheckDownloadStatesForBrowser(browser(), num, state); |
| 386 } |
| 387 |
| 377 // Download |url|, then wait for the download to finish. | 388 // Download |url|, then wait for the download to finish. |
| 378 // |disposition| indicates where the navigation occurs (current tab, new | 389 // |disposition| indicates where the navigation occurs (current tab, new |
| 379 // foreground tab, etc). | 390 // foreground tab, etc). |
| 380 // |expectation| indicates whether or not a Select File dialog should be | 391 // |expectation| indicates whether or not a Select File dialog should be |
| 381 // open when the download is finished, or if we don't care. | 392 // open when the download is finished, or if we don't care. |
| 382 // If the dialog appears, the routine exits. The only effect |expectation| | 393 // If the dialog appears, the routine exits. The only effect |expectation| |
| 383 // has is whether or not the test succeeds. | 394 // has is whether or not the test succeeds. |
| 384 // |browser_test_flags| indicate what to wait for, and is an OR of 0 or more | 395 // |browser_test_flags| indicate what to wait for, and is an OR of 0 or more |
| 385 // values in the ui_test_utils::BrowserTestWaitFlags enum. | 396 // values in the ui_test_utils::BrowserTestWaitFlags enum. |
| 386 void DownloadAndWaitWithDisposition(Browser* browser, | 397 void DownloadAndWaitWithDisposition(Browser* browser, |
| 387 const GURL& url, | 398 const GURL& url, |
| 388 WindowOpenDisposition disposition, | 399 WindowOpenDisposition disposition, |
| 389 SelectExpectation expectation, | 400 SelectExpectation expectation, |
| 390 int browser_test_flags) { | 401 int browser_test_flags) { |
| 391 // Setup notification, navigate, and block. | 402 // Setup notification, navigate, and block. |
| 392 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(browser, 1)); | 403 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(browser, 1)); |
| 393 // This call will block until the condition specified by | 404 // This call will block until the condition specified by |
| 394 // |browser_test_flags|, but will not wait for the download to finish. | 405 // |browser_test_flags|, but will not wait for the download to finish. |
| 395 ui_test_utils::NavigateToURLWithDisposition(browser, | 406 ui_test_utils::NavigateToURLWithDisposition(browser, |
| 396 url, | 407 url, |
| 397 disposition, | 408 disposition, |
| 398 browser_test_flags); | 409 browser_test_flags); |
| 399 // Waits for the download to complete. | 410 // Waits for the download to complete. |
| 400 observer->WaitForFinished(); | 411 observer->WaitForFinished(); |
| 412 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 401 | 413 |
| 402 // If specified, check the state of the select file dialog. | 414 // If specified, check the state of the select file dialog. |
| 403 if (expectation != EXPECT_NOTHING) { | 415 if (expectation != EXPECT_NOTHING) { |
| 404 EXPECT_EQ(expectation == EXPECT_SELECT_DIALOG, | 416 EXPECT_EQ(expectation == EXPECT_SELECT_DIALOG, |
| 405 observer->select_file_dialog_seen()); | 417 observer->select_file_dialog_seen()); |
| 406 } | 418 } |
| 407 } | 419 } |
| 408 | 420 |
| 409 // Download a file in the current tab, then wait for the download to finish. | 421 // Download a file in the current tab, then wait for the download to finish. |
| 410 void DownloadAndWait(Browser* browser, | 422 void DownloadAndWait(Browser* browser, |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 | 515 |
| 504 // Allow the request to finish. We do this by loading a second URL in a | 516 // Allow the request to finish. We do this by loading a second URL in a |
| 505 // separate tab. | 517 // separate tab. |
| 506 GURL finish_url(URLRequestSlowDownloadJob::kFinishDownloadUrl); | 518 GURL finish_url(URLRequestSlowDownloadJob::kFinishDownloadUrl); |
| 507 ui_test_utils::NavigateToURLWithDisposition( | 519 ui_test_utils::NavigateToURLWithDisposition( |
| 508 browser, | 520 browser, |
| 509 finish_url, | 521 finish_url, |
| 510 NEW_FOREGROUND_TAB, | 522 NEW_FOREGROUND_TAB, |
| 511 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 523 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 512 observer->WaitForFinished(); | 524 observer->WaitForFinished(); |
| 525 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 526 CheckDownloadStatesForBrowser(browser, 1, DownloadItem::COMPLETE); |
| 513 | 527 |
| 514 EXPECT_EQ(2, browser->tab_count()); | 528 EXPECT_EQ(2, browser->tab_count()); |
| 515 | 529 |
| 516 // TODO(ahendrickson): check download status text after downloading. | 530 // TODO(ahendrickson): check download status text after downloading. |
| 517 | 531 |
| 518 FilePath basefilename(filename.BaseName()); | 532 FilePath basefilename(filename.BaseName()); |
| 519 net::FileURLToFilePath(url, &filename); | 533 net::FileURLToFilePath(url, &filename); |
| 520 FilePath download_path = downloads_directory_.path().Append(basefilename); | 534 FilePath download_path = downloads_directory_.path().Append(basefilename); |
| 521 CheckDownloadUI(browser, true, true, basefilename); | 535 CheckDownloadUI(browser, true, true, basefilename); |
| 522 | 536 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 GetDownloads(browser(), &download_items); | 647 GetDownloads(browser(), &download_items); |
| 634 ASSERT_TRUE(download_items.empty()); | 648 ASSERT_TRUE(download_items.empty()); |
| 635 | 649 |
| 636 std::string server_path = "files/downloads/"; | 650 std::string server_path = "files/downloads/"; |
| 637 server_path += download_info.url_name; | 651 server_path += download_info.url_name; |
| 638 GURL url = test_server()->GetURL(server_path); | 652 GURL url = test_server()->GetURL(server_path); |
| 639 ASSERT_TRUE(url.is_valid()); | 653 ASSERT_TRUE(url.is_valid()); |
| 640 | 654 |
| 641 DownloadManager* download_manager = DownloadManagerForBrowser(browser()); | 655 DownloadManager* download_manager = DownloadManagerForBrowser(browser()); |
| 642 scoped_ptr<DownloadTestObserver> observer( | 656 scoped_ptr<DownloadTestObserver> observer( |
| 643 new DownloadTestObserver( | 657 new DownloadTestObserverTerminal( |
| 644 download_manager, | 658 download_manager, |
| 645 1, | 659 1, |
| 646 download_info.reason == content::DOWNLOAD_INTERRUPT_REASON_NONE ? | |
| 647 DownloadItem::COMPLETE : // Really done | |
| 648 DownloadItem::INTERRUPTED, | |
| 649 true, // Bail on select file | 660 true, // Bail on select file |
| 650 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 661 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 651 | 662 |
| 652 if (download_info.download_method == DOWNLOAD_DIRECT) { | 663 if (download_info.download_method == DOWNLOAD_DIRECT) { |
| 653 // Go directly to download. | 664 // Go directly to download. |
| 654 WebContents* web_contents = browser()->GetSelectedWebContents(); | 665 WebContents* web_contents = browser()->GetSelectedWebContents(); |
| 655 ASSERT_TRUE(web_contents); | 666 ASSERT_TRUE(web_contents); |
| 656 DownloadSaveInfo save_info; | 667 DownloadSaveInfo save_info; |
| 657 save_info.prompt_for_save_location = false; | 668 save_info.prompt_for_save_location = false; |
| 658 | 669 |
| 659 DownloadManagerForBrowser(browser())->DownloadUrl( | 670 DownloadManagerForBrowser(browser())->DownloadUrl( |
| 660 url, GURL(""), "", false, -1, save_info, web_contents); | 671 url, GURL(""), "", false, -1, save_info, web_contents); |
| 661 } else { | 672 } else { |
| 662 // Navigate to URL normally, wait until done. | 673 // Navigate to URL normally, wait until done. |
| 663 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), | 674 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), |
| 664 url, | 675 url, |
| 665 1); | 676 1); |
| 666 } | 677 } |
| 667 | 678 |
| 668 if (download_info.show_download_item) | 679 if (download_info.show_download_item) { |
| 669 observer->WaitForFinished(); | 680 observer->WaitForFinished(); |
| 681 DownloadItem::DownloadState final_state = |
| 682 (download_info.reason == content::DOWNLOAD_INTERRUPT_REASON_NONE) ? |
| 683 DownloadItem::COMPLETE : |
| 684 DownloadItem::INTERRUPTED; |
| 685 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(final_state)); |
| 686 } |
| 670 | 687 |
| 671 // Validate that the correct file was downloaded. | 688 // Validate that the correct file was downloaded. |
| 672 download_items.clear(); | 689 download_items.clear(); |
| 673 GetDownloads(browser(), &download_items); | 690 GetDownloads(browser(), &download_items); |
| 674 size_t item_count = download_info.show_download_item ? 1 : 0; | 691 size_t item_count = download_info.show_download_item ? 1 : 0; |
| 675 ASSERT_EQ(item_count, download_items.size()); | 692 ASSERT_EQ(item_count, download_items.size()); |
| 676 | 693 |
| 677 if (download_info.show_download_item) { | 694 if (download_info.show_download_item) { |
| 678 DownloadItem* item = download_items[0]; | 695 DownloadItem* item = download_items[0]; |
| 679 ASSERT_EQ(url, item->GetOriginalUrl()); | 696 ASSERT_EQ(url, item->GetOriginalUrl()); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeTypeSelect) { | 755 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadMimeTypeSelect) { |
| 739 ASSERT_TRUE(InitialSetup(true)); | 756 ASSERT_TRUE(InitialSetup(true)); |
| 740 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 757 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 741 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 758 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 742 | 759 |
| 743 NullSelectFile(browser()); | 760 NullSelectFile(browser()); |
| 744 | 761 |
| 745 // Download the file and wait. We expect the Select File dialog to appear | 762 // Download the file and wait. We expect the Select File dialog to appear |
| 746 // due to the MIME type, but we still wait until the download completes. | 763 // due to the MIME type, but we still wait until the download completes. |
| 747 scoped_ptr<DownloadTestObserver> observer( | 764 scoped_ptr<DownloadTestObserver> observer( |
| 748 new DownloadTestObserver( | 765 new DownloadTestObserverTerminal( |
| 749 DownloadManagerForBrowser(browser()), | 766 DownloadManagerForBrowser(browser()), |
| 750 1, | 767 1, |
| 751 DownloadItem::COMPLETE, // Really done | |
| 752 false, // Continue on select file. | 768 false, // Continue on select file. |
| 753 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 769 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 754 ui_test_utils::NavigateToURLWithDisposition( | 770 ui_test_utils::NavigateToURLWithDisposition( |
| 755 browser(), url, CURRENT_TAB, | 771 browser(), url, CURRENT_TAB, |
| 756 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 772 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 757 observer->WaitForFinished(); | 773 observer->WaitForFinished(); |
| 774 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 775 CheckDownloadStates(1, DownloadItem::COMPLETE); |
| 758 EXPECT_TRUE(observer->select_file_dialog_seen()); | 776 EXPECT_TRUE(observer->select_file_dialog_seen()); |
| 759 | 777 |
| 760 // Check state. | 778 // Check state. |
| 761 EXPECT_EQ(1, browser()->tab_count()); | 779 EXPECT_EQ(1, browser()->tab_count()); |
| 762 CheckDownload(browser(), file, file); | 780 CheckDownload(browser(), file, file); |
| 763 CheckDownloadUI(browser(), true, true, file); | 781 CheckDownloadUI(browser(), true, true, file); |
| 764 } | 782 } |
| 765 | 783 |
| 766 // Access a file with a viewable mime-type, verify that a download | 784 // Access a file with a viewable mime-type, verify that a download |
| 767 // did not initiate. | 785 // did not initiate. |
| (...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1265 // Allow the first request to finish. We do this by loading a third URL | 1283 // Allow the first request to finish. We do this by loading a third URL |
| 1266 // in a separate tab. | 1284 // in a separate tab. |
| 1267 scoped_ptr<DownloadTestObserver> observer2(CreateWaiter(browser(), 1)); | 1285 scoped_ptr<DownloadTestObserver> observer2(CreateWaiter(browser(), 1)); |
| 1268 GURL finish_url(URLRequestSlowDownloadJob::kFinishDownloadUrl); | 1286 GURL finish_url(URLRequestSlowDownloadJob::kFinishDownloadUrl); |
| 1269 ui_test_utils::NavigateToURLWithDisposition( | 1287 ui_test_utils::NavigateToURLWithDisposition( |
| 1270 browser(), | 1288 browser(), |
| 1271 finish_url, | 1289 finish_url, |
| 1272 NEW_FOREGROUND_TAB, | 1290 NEW_FOREGROUND_TAB, |
| 1273 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 1291 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 1274 observer2->WaitForFinished(); // Wait for the third request. | 1292 observer2->WaitForFinished(); // Wait for the third request. |
| 1293 EXPECT_EQ(1u, observer2->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 1275 | 1294 |
| 1276 // Get the important info from other threads and check it. | 1295 // Get the important info from other threads and check it. |
| 1277 EXPECT_TRUE(DownloadManager::EnsureNoPendingDownloadsForTesting()); | 1296 EXPECT_TRUE(DownloadManager::EnsureNoPendingDownloadsForTesting()); |
| 1278 | 1297 |
| 1279 CheckDownloadUI(browser(), true, true, FilePath()); | 1298 CheckDownloadUI(browser(), true, true, FilePath()); |
| 1280 | 1299 |
| 1281 // The |DownloadItem|s should now be done and have the final file names. | 1300 // The |DownloadItem|s should now be done and have the final file names. |
| 1282 // Verify that the files have the expected data and size. | 1301 // Verify that the files have the expected data and size. |
| 1283 // |file1| should be full of '*'s, and |file2| should be the same as the | 1302 // |file1| should be full of '*'s, and |file2| should be the same as the |
| 1284 // source file. | 1303 // source file. |
| 1285 FilePath file1(download1->GetFullPath()); | 1304 FilePath file1(download1->GetFullPath()); |
| 1286 size_t file_size1 = URLRequestSlowDownloadJob::kFirstDownloadSize + | 1305 size_t file_size1 = URLRequestSlowDownloadJob::kFirstDownloadSize + |
| 1287 URLRequestSlowDownloadJob::kSecondDownloadSize; | 1306 URLRequestSlowDownloadJob::kSecondDownloadSize; |
| 1288 std::string expected_contents(file_size1, '*'); | 1307 std::string expected_contents(file_size1, '*'); |
| 1289 ASSERT_TRUE(VerifyFile(file1, expected_contents, file_size1)); | 1308 ASSERT_TRUE(VerifyFile(file1, expected_contents, file_size1)); |
| 1290 | 1309 |
| 1291 FilePath file2(download2->GetFullPath()); | 1310 FilePath file2(download2->GetFullPath()); |
| 1292 ASSERT_TRUE(file_util::ContentsEqual(OriginFile(file), file2)); | 1311 ASSERT_TRUE(file_util::ContentsEqual(OriginFile(file), file2)); |
| 1293 } | 1312 } |
| 1294 | 1313 |
| 1295 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadCancelled) { | 1314 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadCancelled) { |
| 1296 ASSERT_TRUE(InitialSetup(false)); | 1315 ASSERT_TRUE(InitialSetup(false)); |
| 1297 EXPECT_EQ(1, browser()->tab_count()); | 1316 EXPECT_EQ(1, browser()->tab_count()); |
| 1298 | 1317 |
| 1299 // TODO(rdsmith): Fragile code warning! The code below relies on the | 1318 // TODO(rdsmith): Fragile code warning! The code below relies on the |
| 1300 // DownloadTestObserver only finishing when the new download has reached | 1319 // DownloadTestObserverInProgress only finishing when the new download |
| 1301 // the state of being entered into the history and being user-visible | 1320 // has reached the state of being entered into the history and being |
| 1302 // (that's what's required for the Remove to be valid and for the | 1321 // user-visible (that's what's required for the Remove to be valid and |
| 1303 // download shelf to be visible). By the pure semantics of | 1322 // for the download shelf to be visible). By the pure semantics of |
| 1304 // DownloadTestObserver, that's not guaranteed; DownloadItems are created | 1323 // DownloadTestObserverInProgress, that's not guaranteed; DownloadItems |
| 1305 // in the IN_PROGRESS state and made known to the DownloadManager | 1324 // are created in the IN_PROGRESS state and made known to the DownloadManager |
| 1306 // immediately, so any ModelChanged event on the DownloadManager after | 1325 // immediately, so any ModelChanged event on the DownloadManager after |
| 1307 // navigation would allow the observer to return. However, the only | 1326 // navigation would allow the observer to return. However, the only |
| 1308 // ModelChanged() event the code will currently fire is in | 1327 // ModelChanged() event the code will currently fire is in |
| 1309 // OnCreateDownloadEntryComplete, at which point the download item will | 1328 // OnCreateDownloadEntryComplete, at which point the download item will |
| 1310 // be in the state we need. | 1329 // be in the state we need. |
| 1311 // The right way to fix this is to create finer grained states on the | 1330 // The right way to fix this is to create finer grained states on the |
| 1312 // DownloadItem, and wait for the state that indicates the item has been | 1331 // DownloadItem, and wait for the state that indicates the item has been |
| 1313 // entered in the history and made visible in the UI. | 1332 // entered in the history and made visible in the UI. |
| 1314 | 1333 |
| 1315 // Create a download, wait until it's started, and confirm | 1334 // Create a download, wait until it's started, and confirm |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1438 IN_PROC_BROWSER_TEST_F(DownloadTest, AnchorDownloadTag) { | 1457 IN_PROC_BROWSER_TEST_F(DownloadTest, AnchorDownloadTag) { |
| 1439 ASSERT_TRUE(InitialSetup(false)); | 1458 ASSERT_TRUE(InitialSetup(false)); |
| 1440 FilePath file(FILE_PATH_LITERAL("download-anchor-attrib.html")); | 1459 FilePath file(FILE_PATH_LITERAL("download-anchor-attrib.html")); |
| 1441 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1460 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1442 | 1461 |
| 1443 // Create a download, wait until it's complete, and confirm | 1462 // Create a download, wait until it's complete, and confirm |
| 1444 // we're in the expected state. | 1463 // we're in the expected state. |
| 1445 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(browser(), 1)); | 1464 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(browser(), 1)); |
| 1446 ui_test_utils::NavigateToURL(browser(), url); | 1465 ui_test_utils::NavigateToURL(browser(), url); |
| 1447 observer->WaitForFinished(); | 1466 observer->WaitForFinished(); |
| 1467 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 1468 CheckDownloadStates(1, DownloadItem::COMPLETE); |
| 1448 | 1469 |
| 1449 // Confirm the downloaded data exists. | 1470 // Confirm the downloaded data exists. |
| 1450 FilePath downloaded_file = GetDownloadDirectory(browser()); | 1471 FilePath downloaded_file = GetDownloadDirectory(browser()); |
| 1451 downloaded_file = downloaded_file.Append(FILE_PATH_LITERAL("a_red_dot.png")); | 1472 downloaded_file = downloaded_file.Append(FILE_PATH_LITERAL("a_red_dot.png")); |
| 1452 EXPECT_TRUE(file_util::PathExists(downloaded_file)); | 1473 EXPECT_TRUE(file_util::PathExists(downloaded_file)); |
| 1453 } | 1474 } |
| 1454 | 1475 |
| 1455 // Test to make sure auto-open works. | 1476 // Test to make sure auto-open works. |
| 1456 IN_PROC_BROWSER_TEST_F(DownloadTest, AutoOpen) { | 1477 IN_PROC_BROWSER_TEST_F(DownloadTest, AutoOpen) { |
| 1457 ASSERT_TRUE(InitialSetup(false)); | 1478 ASSERT_TRUE(InitialSetup(false)); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1483 } | 1504 } |
| 1484 | 1505 |
| 1485 // Download an extension. Expect a dangerous download warning. | 1506 // Download an extension. Expect a dangerous download warning. |
| 1486 // Deny the download. | 1507 // Deny the download. |
| 1487 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxDenyInstall) { | 1508 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxDenyInstall) { |
| 1488 ASSERT_TRUE(InitialSetup(false)); | 1509 ASSERT_TRUE(InitialSetup(false)); |
| 1489 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); | 1510 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); |
| 1490 | 1511 |
| 1491 scoped_ptr<DownloadTestObserver> observer( | 1512 scoped_ptr<DownloadTestObserver> observer( |
| 1492 DangerousInstallWaiter( | 1513 DangerousInstallWaiter( |
| 1493 browser(), 1, DownloadItem::CANCELLED, | 1514 browser(), 1, |
| 1494 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); | 1515 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); |
| 1495 ui_test_utils::NavigateToURL(browser(), extension_url); | 1516 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 1496 | 1517 |
| 1497 observer->WaitForFinished(); | 1518 observer->WaitForFinished(); |
| 1519 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::CANCELLED)); |
| 1498 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1520 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
| 1499 | 1521 |
| 1500 // Download shelf should close. Download panel stays open on ChromeOS. | 1522 // Download shelf should close. Download panel stays open on ChromeOS. |
| 1501 CheckDownloadUI(browser(), false, true, FilePath()); | 1523 CheckDownloadUI(browser(), false, true, FilePath()); |
| 1502 | 1524 |
| 1503 // Check that the CRX is not installed. | 1525 // Check that the CRX is not installed. |
| 1504 ExtensionService* extension_service = | 1526 ExtensionService* extension_service = |
| 1505 browser()->profile()->GetExtensionService(); | 1527 browser()->profile()->GetExtensionService(); |
| 1506 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1528 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); |
| 1507 } | 1529 } |
| 1508 | 1530 |
| 1509 // Download an extension. Expect a dangerous download warning. | 1531 // Download an extension. Expect a dangerous download warning. |
| 1510 // Allow the download, deny the install. | 1532 // Allow the download, deny the install. |
| 1511 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallDenysPermissions) { | 1533 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallDenysPermissions) { |
| 1512 ASSERT_TRUE(InitialSetup(false)); | 1534 ASSERT_TRUE(InitialSetup(false)); |
| 1513 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); | 1535 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); |
| 1514 | 1536 |
| 1515 // Install a mock install UI that simulates a user denying permission to | 1537 // Install a mock install UI that simulates a user denying permission to |
| 1516 // finish the install. | 1538 // finish the install. |
| 1517 download_crx_util::SetMockInstallUIForTesting( | 1539 download_crx_util::SetMockInstallUIForTesting( |
| 1518 new MockAbortExtensionInstallUI()); | 1540 new MockAbortExtensionInstallUI()); |
| 1519 | 1541 |
| 1520 scoped_ptr<DownloadTestObserver> observer( | 1542 scoped_ptr<DownloadTestObserver> observer( |
| 1521 DangerousInstallWaiter( | 1543 DangerousInstallWaiter( |
| 1522 browser(), 1, DownloadItem::COMPLETE, | 1544 browser(), 1, |
| 1523 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); | 1545 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
| 1524 ui_test_utils::NavigateToURL(browser(), extension_url); | 1546 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 1525 | 1547 |
| 1526 observer->WaitForFinished(); | 1548 observer->WaitForFinished(); |
| 1549 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 1550 CheckDownloadStates(1, DownloadItem::COMPLETE); |
| 1527 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1551 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
| 1528 | 1552 |
| 1529 // Download shelf should close. Download panel stays open on ChromeOS. | 1553 // Download shelf should close. Download panel stays open on ChromeOS. |
| 1530 CheckDownloadUI(browser(), false, true, FilePath()); | 1554 CheckDownloadUI(browser(), false, true, FilePath()); |
| 1531 | 1555 |
| 1532 // Check that the extension was not installed. | 1556 // Check that the extension was not installed. |
| 1533 ExtensionService* extension_service = | 1557 ExtensionService* extension_service = |
| 1534 browser()->profile()->GetExtensionService(); | 1558 browser()->profile()->GetExtensionService(); |
| 1535 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1559 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); |
| 1536 } | 1560 } |
| 1537 | 1561 |
| 1538 // Download an extension. Expect a dangerous download warning. | 1562 // Download an extension. Expect a dangerous download warning. |
| 1539 // Allow the download, and the install. | 1563 // Allow the download, and the install. |
| 1540 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallAcceptPermissions) { | 1564 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallAcceptPermissions) { |
| 1541 ASSERT_TRUE(InitialSetup(false)); | 1565 ASSERT_TRUE(InitialSetup(false)); |
| 1542 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); | 1566 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); |
| 1543 | 1567 |
| 1544 // Install a mock install UI that simulates a user allowing permission to | 1568 // Install a mock install UI that simulates a user allowing permission to |
| 1545 // finish the install. | 1569 // finish the install. |
| 1546 download_crx_util::SetMockInstallUIForTesting( | 1570 download_crx_util::SetMockInstallUIForTesting( |
| 1547 new MockAutoConfirmExtensionInstallUI(browser()->profile())); | 1571 new MockAutoConfirmExtensionInstallUI(browser()->profile())); |
| 1548 | 1572 |
| 1549 scoped_ptr<DownloadTestObserver> observer( | 1573 scoped_ptr<DownloadTestObserver> observer( |
| 1550 DangerousInstallWaiter( | 1574 DangerousInstallWaiter( |
| 1551 browser(), 1, DownloadItem::COMPLETE, | 1575 browser(), 1, |
| 1552 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); | 1576 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
| 1553 ui_test_utils::NavigateToURL(browser(), extension_url); | 1577 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 1554 | 1578 |
| 1555 observer->WaitForFinished(); | 1579 observer->WaitForFinished(); |
| 1580 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 1581 CheckDownloadStates(1, DownloadItem::COMPLETE); |
| 1556 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1582 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
| 1557 | 1583 |
| 1558 // Download shelf should close. Download panel stays open on ChromeOS. | 1584 // Download shelf should close. Download panel stays open on ChromeOS. |
| 1559 CheckDownloadUI(browser(), false, true, FilePath()); | 1585 CheckDownloadUI(browser(), false, true, FilePath()); |
| 1560 | 1586 |
| 1561 // Check that the extension was installed. | 1587 // Check that the extension was installed. |
| 1562 ExtensionService* extension_service = | 1588 ExtensionService* extension_service = |
| 1563 browser()->profile()->GetExtensionService(); | 1589 browser()->profile()->GetExtensionService(); |
| 1564 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1590 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false)); |
| 1565 } | 1591 } |
| 1566 | 1592 |
| 1567 // Test installing a CRX that fails integrity checks. | 1593 // Test installing a CRX that fails integrity checks. |
| 1568 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) { | 1594 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) { |
| 1569 ASSERT_TRUE(InitialSetup(false)); | 1595 ASSERT_TRUE(InitialSetup(false)); |
| 1570 FilePath file(FILE_PATH_LITERAL("extensions/bad_signature.crx")); | 1596 FilePath file(FILE_PATH_LITERAL("extensions/bad_signature.crx")); |
| 1571 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1597 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1572 | 1598 |
| 1573 // Install a mock install UI that simulates a user allowing permission to | 1599 // Install a mock install UI that simulates a user allowing permission to |
| 1574 // finish the install, and dismisses any error message. We check that the | 1600 // finish the install, and dismisses any error message. We check that the |
| 1575 // install failed below. | 1601 // install failed below. |
| 1576 download_crx_util::SetMockInstallUIForTesting( | 1602 download_crx_util::SetMockInstallUIForTesting( |
| 1577 new MockAutoConfirmExtensionInstallUI(browser()->profile())); | 1603 new MockAutoConfirmExtensionInstallUI(browser()->profile())); |
| 1578 | 1604 |
| 1579 scoped_ptr<DownloadTestObserver> observer( | 1605 scoped_ptr<DownloadTestObserver> observer( |
| 1580 DangerousInstallWaiter( | 1606 DangerousInstallWaiter( |
| 1581 browser(), 1, DownloadItem::COMPLETE, | 1607 browser(), 1, |
| 1582 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); | 1608 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
| 1583 ui_test_utils::NavigateToURL(browser(), extension_url); | 1609 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 1584 | 1610 |
| 1585 observer->WaitForFinished(); | 1611 observer->WaitForFinished(); |
| 1612 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 1613 CheckDownloadStates(1, DownloadItem::COMPLETE); |
| 1586 | 1614 |
| 1587 // Check that the extension was not installed. | 1615 // Check that the extension was not installed. |
| 1588 ExtensionService* extension_service = | 1616 ExtensionService* extension_service = |
| 1589 browser()->profile()->GetExtensionService(); | 1617 browser()->profile()->GetExtensionService(); |
| 1590 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1618 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); |
| 1591 } | 1619 } |
| 1592 | 1620 |
| 1593 // Install a large (100kb) theme. | 1621 // Install a large (100kb) theme. |
| 1594 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxLargeTheme) { | 1622 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxLargeTheme) { |
| 1595 ASSERT_TRUE(InitialSetup(false)); | 1623 ASSERT_TRUE(InitialSetup(false)); |
| 1596 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kLargeThemePath)); | 1624 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kLargeThemePath)); |
| 1597 | 1625 |
| 1598 // Install a mock install UI that simulates a user allowing permission to | 1626 // Install a mock install UI that simulates a user allowing permission to |
| 1599 // finish the install. | 1627 // finish the install. |
| 1600 download_crx_util::SetMockInstallUIForTesting( | 1628 download_crx_util::SetMockInstallUIForTesting( |
| 1601 new MockAutoConfirmExtensionInstallUI(browser()->profile())); | 1629 new MockAutoConfirmExtensionInstallUI(browser()->profile())); |
| 1602 | 1630 |
| 1603 scoped_ptr<DownloadTestObserver> observer( | 1631 scoped_ptr<DownloadTestObserver> observer( |
| 1604 DangerousInstallWaiter( | 1632 DangerousInstallWaiter( |
| 1605 browser(), 1, DownloadItem::COMPLETE, | 1633 browser(), 1, |
| 1606 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); | 1634 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
| 1607 ui_test_utils::NavigateToURL(browser(), extension_url); | 1635 ui_test_utils::NavigateToURL(browser(), extension_url); |
| 1608 | 1636 |
| 1609 observer->WaitForFinished(); | 1637 observer->WaitForFinished(); |
| 1638 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 1639 CheckDownloadStates(1, DownloadItem::COMPLETE); |
| 1610 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1640 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
| 1611 | 1641 |
| 1612 // Download shelf should close. Download panel stays open on ChromeOS. | 1642 // Download shelf should close. Download panel stays open on ChromeOS. |
| 1613 CheckDownloadUI(browser(), false, true, FilePath()); | 1643 CheckDownloadUI(browser(), false, true, FilePath()); |
| 1614 | 1644 |
| 1615 // Check that the extension was installed. | 1645 // Check that the extension was installed. |
| 1616 ExtensionService* extension_service = | 1646 ExtensionService* extension_service = |
| 1617 browser()->profile()->GetExtensionService(); | 1647 browser()->profile()->GetExtensionService(); |
| 1618 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); | 1648 ASSERT_TRUE(extension_service->GetExtensionById(kLargeThemeCrxId, false)); |
| 1619 } | 1649 } |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1756 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1786 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1757 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1787 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1758 | 1788 |
| 1759 // DownloadUrl always prompts; return acceptance of whatever it prompts. | 1789 // DownloadUrl always prompts; return acceptance of whatever it prompts. |
| 1760 NullSelectFile(browser()); | 1790 NullSelectFile(browser()); |
| 1761 | 1791 |
| 1762 WebContents* web_contents = browser()->GetSelectedWebContents(); | 1792 WebContents* web_contents = browser()->GetSelectedWebContents(); |
| 1763 ASSERT_TRUE(web_contents); | 1793 ASSERT_TRUE(web_contents); |
| 1764 | 1794 |
| 1765 DownloadTestObserver* observer( | 1795 DownloadTestObserver* observer( |
| 1766 new DownloadTestObserver( | 1796 new DownloadTestObserverTerminal( |
| 1767 DownloadManagerForBrowser(browser()), 1, | 1797 DownloadManagerForBrowser(browser()), 1, |
| 1768 DownloadItem::COMPLETE, // Really done | 1798 false, // Ignore select file. |
| 1769 false, // Ignore select file. | 1799 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 1770 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | |
| 1771 DownloadSaveInfo save_info; | 1800 DownloadSaveInfo save_info; |
| 1772 save_info.prompt_for_save_location = true; | 1801 save_info.prompt_for_save_location = true; |
| 1773 DownloadManagerForBrowser(browser())->DownloadUrl( | 1802 DownloadManagerForBrowser(browser())->DownloadUrl( |
| 1774 url, GURL(""), "", false, -1, save_info, web_contents); | 1803 url, GURL(""), "", false, -1, save_info, web_contents); |
| 1775 observer->WaitForFinished(); | 1804 observer->WaitForFinished(); |
| 1805 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 1806 CheckDownloadStates(1, DownloadItem::COMPLETE); |
| 1776 EXPECT_TRUE(observer->select_file_dialog_seen()); | 1807 EXPECT_TRUE(observer->select_file_dialog_seen()); |
| 1777 | 1808 |
| 1778 // Check state. | 1809 // Check state. |
| 1779 EXPECT_EQ(1, browser()->tab_count()); | 1810 EXPECT_EQ(1, browser()->tab_count()); |
| 1780 ASSERT_TRUE(CheckDownload(browser(), file, file)); | 1811 ASSERT_TRUE(CheckDownload(browser(), file, file)); |
| 1781 CheckDownloadUI(browser(), true, true, file); | 1812 CheckDownloadUI(browser(), true, true, file); |
| 1782 } | 1813 } |
| 1783 | 1814 |
| 1784 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { | 1815 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { |
| 1785 ASSERT_TRUE(InitialSetup(false)); | 1816 ASSERT_TRUE(InitialSetup(false)); |
| 1786 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1817 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
| 1787 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1818 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 1788 | 1819 |
| 1789 WebContents* web_contents = browser()->GetSelectedWebContents(); | 1820 WebContents* web_contents = browser()->GetSelectedWebContents(); |
| 1790 ASSERT_TRUE(web_contents); | 1821 ASSERT_TRUE(web_contents); |
| 1791 | 1822 |
| 1792 ScopedTempDir other_directory; | 1823 ScopedTempDir other_directory; |
| 1793 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); | 1824 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); |
| 1794 FilePath target_file_full_path | 1825 FilePath target_file_full_path |
| 1795 = other_directory.path().Append(file.BaseName()); | 1826 = other_directory.path().Append(file.BaseName()); |
| 1796 DownloadSaveInfo save_info; | 1827 DownloadSaveInfo save_info; |
| 1797 save_info.file_path = target_file_full_path; | 1828 save_info.file_path = target_file_full_path; |
| 1798 | 1829 |
| 1799 DownloadTestObserver* observer(CreateWaiter(browser(), 1)); | 1830 DownloadTestObserver* observer(CreateWaiter(browser(), 1)); |
| 1800 DownloadManagerForBrowser(browser())->DownloadUrl( | 1831 DownloadManagerForBrowser(browser())->DownloadUrl( |
| 1801 url, GURL(""), "", false, -1, save_info, web_contents); | 1832 url, GURL(""), "", false, -1, save_info, web_contents); |
| 1802 observer->WaitForFinished(); | 1833 observer->WaitForFinished(); |
| 1834 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 1803 | 1835 |
| 1804 // Check state. | 1836 // Check state. |
| 1805 EXPECT_EQ(1, browser()->tab_count()); | 1837 EXPECT_EQ(1, browser()->tab_count()); |
| 1806 ASSERT_TRUE(CheckDownloadFullPaths(browser(), | 1838 ASSERT_TRUE(CheckDownloadFullPaths(browser(), |
| 1807 target_file_full_path, | 1839 target_file_full_path, |
| 1808 OriginFile(file))); | 1840 OriginFile(file))); |
| 1809 | 1841 |
| 1810 // Temporary downloads won't be visible. | 1842 // Temporary downloads won't be visible. |
| 1811 CheckDownloadUI(browser(), false, false, file); | 1843 CheckDownloadUI(browser(), false, false, file); |
| 1812 } | 1844 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1825 // each time. | 1857 // each time. |
| 1826 GURL url = test_server()->GetURL("files/downloads/image.jpg"); | 1858 GURL url = test_server()->GetURL("files/downloads/image.jpg"); |
| 1827 ASSERT_TRUE(url.is_valid()); | 1859 ASSERT_TRUE(url.is_valid()); |
| 1828 ui_test_utils::NavigateToURL(browser(), url); | 1860 ui_test_utils::NavigateToURL(browser(), url); |
| 1829 | 1861 |
| 1830 // Stop the test server, and then try to save the page. If cache validation | 1862 // Stop the test server, and then try to save the page. If cache validation |
| 1831 // is not bypassed then this will fail since the server is no longer | 1863 // is not bypassed then this will fail since the server is no longer |
| 1832 // reachable. | 1864 // reachable. |
| 1833 ASSERT_TRUE(test_server()->Stop()); | 1865 ASSERT_TRUE(test_server()->Stop()); |
| 1834 scoped_ptr<DownloadTestObserver> waiter( | 1866 scoped_ptr<DownloadTestObserver> waiter( |
| 1835 new DownloadTestObserver( | 1867 new DownloadTestObserverTerminal( |
| 1836 DownloadManagerForBrowser(browser()), 1, DownloadItem::COMPLETE, | 1868 DownloadManagerForBrowser(browser()), 1, |
| 1837 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 1869 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 1838 browser()->SavePage(); | 1870 browser()->SavePage(); |
| 1839 waiter->WaitForFinished(); | 1871 waiter->WaitForFinished(); |
| 1872 EXPECT_EQ(1u, waiter->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 1873 CheckDownloadStates(1, DownloadItem::COMPLETE); |
| 1840 | 1874 |
| 1841 // Validate that the correct file was downloaded. | 1875 // Validate that the correct file was downloaded. |
| 1842 GetDownloads(browser(), &download_items); | 1876 GetDownloads(browser(), &download_items); |
| 1843 EXPECT_TRUE(waiter->select_file_dialog_seen()); | 1877 EXPECT_TRUE(waiter->select_file_dialog_seen()); |
| 1844 ASSERT_EQ(1u, download_items.size()); | 1878 ASSERT_EQ(1u, download_items.size()); |
| 1845 ASSERT_EQ(url, download_items[0]->GetOriginalUrl()); | 1879 ASSERT_EQ(url, download_items[0]->GetOriginalUrl()); |
| 1846 | 1880 |
| 1847 // Try to download it via a context menu. | 1881 // Try to download it via a context menu. |
| 1848 scoped_ptr<DownloadTestObserver> waiter_context_menu( | 1882 scoped_ptr<DownloadTestObserver> waiter_context_menu( |
| 1849 new DownloadTestObserver( | 1883 new DownloadTestObserverTerminal( |
| 1850 DownloadManagerForBrowser(browser()), 1, DownloadItem::COMPLETE, | 1884 DownloadManagerForBrowser(browser()), 1, |
| 1851 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 1885 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 1852 content::ContextMenuParams context_menu_params; | 1886 content::ContextMenuParams context_menu_params; |
| 1853 context_menu_params.media_type = WebKit::WebContextMenuData::MediaTypeImage; | 1887 context_menu_params.media_type = WebKit::WebContextMenuData::MediaTypeImage; |
| 1854 context_menu_params.src_url = url; | 1888 context_menu_params.src_url = url; |
| 1855 context_menu_params.page_url = url; | 1889 context_menu_params.page_url = url; |
| 1856 TestRenderViewContextMenu menu(browser()->GetSelectedWebContents(), | 1890 TestRenderViewContextMenu menu(browser()->GetSelectedWebContents(), |
| 1857 context_menu_params); | 1891 context_menu_params); |
| 1858 menu.Init(); | 1892 menu.Init(); |
| 1859 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS); | 1893 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS); |
| 1860 waiter_context_menu->WaitForFinished(); | 1894 waiter_context_menu->WaitForFinished(); |
| 1895 EXPECT_EQ( |
| 1896 1u, waiter_context_menu->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 1897 CheckDownloadStates(2, DownloadItem::COMPLETE); |
| 1861 | 1898 |
| 1862 // Validate that the correct file was downloaded via the context menu. | 1899 // Validate that the correct file was downloaded via the context menu. |
| 1863 download_items.clear(); | 1900 download_items.clear(); |
| 1864 GetDownloads(browser(), &download_items); | 1901 GetDownloads(browser(), &download_items); |
| 1865 EXPECT_TRUE(waiter_context_menu->select_file_dialog_seen()); | 1902 EXPECT_TRUE(waiter_context_menu->select_file_dialog_seen()); |
| 1866 ASSERT_EQ(2u, download_items.size()); | 1903 ASSERT_EQ(2u, download_items.size()); |
| 1867 ASSERT_EQ(url, download_items[0]->GetOriginalUrl()); | 1904 ASSERT_EQ(url, download_items[0]->GetOriginalUrl()); |
| 1868 ASSERT_EQ(url, download_items[1]->GetOriginalUrl()); | 1905 ASSERT_EQ(url, download_items[1]->GetOriginalUrl()); |
| 1869 } | 1906 } |
| 1870 | 1907 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1900 string16(), ASCIIToUTF16("SubmitForm()")); | 1937 string16(), ASCIIToUTF16("SubmitForm()")); |
| 1901 observer.Wait(); | 1938 observer.Wait(); |
| 1902 EXPECT_EQ(jpeg_url, web_contents->GetURL()); | 1939 EXPECT_EQ(jpeg_url, web_contents->GetURL()); |
| 1903 | 1940 |
| 1904 // Stop the test server, and then try to save the page. If cache validation | 1941 // Stop the test server, and then try to save the page. If cache validation |
| 1905 // is not bypassed then this will fail since the server is no longer | 1942 // is not bypassed then this will fail since the server is no longer |
| 1906 // reachable. This will also fail if it tries to be retrieved via "GET" | 1943 // reachable. This will also fail if it tries to be retrieved via "GET" |
| 1907 // rather than "POST". | 1944 // rather than "POST". |
| 1908 ASSERT_TRUE(test_server()->Stop()); | 1945 ASSERT_TRUE(test_server()->Stop()); |
| 1909 scoped_ptr<DownloadTestObserver> waiter( | 1946 scoped_ptr<DownloadTestObserver> waiter( |
| 1910 new DownloadTestObserver( | 1947 new DownloadTestObserverTerminal( |
| 1911 DownloadManagerForBrowser(browser()), 1, DownloadItem::COMPLETE, | 1948 DownloadManagerForBrowser(browser()), 1, |
| 1912 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 1949 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 1913 browser()->SavePage(); | 1950 browser()->SavePage(); |
| 1914 waiter->WaitForFinished(); | 1951 waiter->WaitForFinished(); |
| 1952 EXPECT_EQ(1u, waiter->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 1953 CheckDownloadStates(1, DownloadItem::COMPLETE); |
| 1915 | 1954 |
| 1916 // Validate that the correct file was downloaded. | 1955 // Validate that the correct file was downloaded. |
| 1917 GetDownloads(browser(), &download_items); | 1956 GetDownloads(browser(), &download_items); |
| 1918 EXPECT_TRUE(waiter->select_file_dialog_seen()); | 1957 EXPECT_TRUE(waiter->select_file_dialog_seen()); |
| 1919 ASSERT_EQ(1u, download_items.size()); | 1958 ASSERT_EQ(1u, download_items.size()); |
| 1920 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl()); | 1959 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl()); |
| 1921 | 1960 |
| 1922 // Try to download it via a context menu. | 1961 // Try to download it via a context menu. |
| 1923 scoped_ptr<DownloadTestObserver> waiter_context_menu( | 1962 scoped_ptr<DownloadTestObserver> waiter_context_menu( |
| 1924 new DownloadTestObserver( | 1963 new DownloadTestObserverTerminal( |
| 1925 DownloadManagerForBrowser(browser()), 1, DownloadItem::COMPLETE, | 1964 DownloadManagerForBrowser(browser()), 1, |
| 1926 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 1965 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
| 1927 content::ContextMenuParams context_menu_params; | 1966 content::ContextMenuParams context_menu_params; |
| 1928 context_menu_params.media_type = WebKit::WebContextMenuData::MediaTypeImage; | 1967 context_menu_params.media_type = WebKit::WebContextMenuData::MediaTypeImage; |
| 1929 context_menu_params.src_url = jpeg_url; | 1968 context_menu_params.src_url = jpeg_url; |
| 1930 context_menu_params.page_url = jpeg_url; | 1969 context_menu_params.page_url = jpeg_url; |
| 1931 TestRenderViewContextMenu menu(web_contents, context_menu_params); | 1970 TestRenderViewContextMenu menu(web_contents, context_menu_params); |
| 1932 menu.Init(); | 1971 menu.Init(); |
| 1933 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS); | 1972 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS); |
| 1934 waiter_context_menu->WaitForFinished(); | 1973 waiter_context_menu->WaitForFinished(); |
| 1974 EXPECT_EQ( |
| 1975 1u, waiter_context_menu->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
| 1976 CheckDownloadStates(2, DownloadItem::COMPLETE); |
| 1935 | 1977 |
| 1936 // Validate that the correct file was downloaded via the context menu. | 1978 // Validate that the correct file was downloaded via the context menu. |
| 1937 download_items.clear(); | 1979 download_items.clear(); |
| 1938 GetDownloads(browser(), &download_items); | 1980 GetDownloads(browser(), &download_items); |
| 1939 EXPECT_TRUE(waiter_context_menu->select_file_dialog_seen()); | 1981 EXPECT_TRUE(waiter_context_menu->select_file_dialog_seen()); |
| 1940 ASSERT_EQ(2u, download_items.size()); | 1982 ASSERT_EQ(2u, download_items.size()); |
| 1941 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl()); | 1983 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl()); |
| 1942 ASSERT_EQ(jpeg_url, download_items[1]->GetOriginalUrl()); | 1984 ASSERT_EQ(jpeg_url, download_items[1]->GetOriginalUrl()); |
| 1943 } | 1985 } |
| 1944 | 1986 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2012 "zip_file_not_found.zip", | 2054 "zip_file_not_found.zip", |
| 2013 DOWNLOAD_NAVIGATE, | 2055 DOWNLOAD_NAVIGATE, |
| 2014 content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, | 2056 content::DOWNLOAD_INTERRUPT_REASON_SERVER_FAILED, |
| 2015 false | 2057 false |
| 2016 }; | 2058 }; |
| 2017 | 2059 |
| 2018 // Do initial setup. | 2060 // Do initial setup. |
| 2019 ASSERT_TRUE(InitialSetup(false)); | 2061 ASSERT_TRUE(InitialSetup(false)); |
| 2020 DownloadFileCheckErrors(download_info); | 2062 DownloadFileCheckErrors(download_info); |
| 2021 } | 2063 } |
| OLD | NEW |