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

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

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

Powered by Google App Engine
This is Rietveld 408576698