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 <sstream> | 5 #include <sstream> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
13 #include "base/scoped_temp_dir.h" | 13 #include "base/scoped_temp_dir.h" |
14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
15 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
16 #include "base/test/test_file_util.h" | 16 #include "base/test/test_file_util.h" |
17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
18 #include "chrome/app/chrome_command_ids.h" | 18 #include "chrome/app/chrome_command_ids.h" |
19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
20 #include "chrome/browser/cancelable_request.h" | 20 #include "chrome/browser/cancelable_request.h" |
21 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 21 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
22 #include "chrome/browser/download/download_crx_util.h" | 22 #include "chrome/browser/download/download_crx_util.h" |
23 #include "chrome/browser/download/download_history.h" | 23 #include "chrome/browser/download/download_history.h" |
24 #include "chrome/browser/download/download_prefs.h" | 24 #include "chrome/browser/download/download_prefs.h" |
25 #include "chrome/browser/download/download_request_limiter.h" | 25 #include "chrome/browser/download/download_request_limiter.h" |
26 #include "chrome/browser/download/download_shelf.h" | 26 #include "chrome/browser/download/download_shelf.h" |
27 #include "chrome/browser/download/download_test_observer.h" | 27 #include "chrome/browser/download/download_test_file_chooser_observer.h" |
28 #include "chrome/browser/download/download_util.h" | 28 #include "chrome/browser/download/download_util.h" |
29 #include "chrome/browser/extensions/extension_install_prompt.h" | 29 #include "chrome/browser/extensions/extension_install_prompt.h" |
30 #include "chrome/browser/extensions/extension_service.h" | 30 #include "chrome/browser/extensions/extension_service.h" |
31 #include "chrome/browser/history/history.h" | 31 #include "chrome/browser/history/history.h" |
32 #include "chrome/browser/history/history_service_factory.h" | 32 #include "chrome/browser/history/history_service_factory.h" |
33 #include "chrome/browser/net/url_request_mock_util.h" | 33 #include "chrome/browser/net/url_request_mock_util.h" |
34 #include "chrome/browser/prefs/pref_service.h" | 34 #include "chrome/browser/prefs/pref_service.h" |
35 #include "chrome/browser/profiles/profile.h" | 35 #include "chrome/browser/profiles/profile.h" |
36 #include "chrome/browser/tab_contents/render_view_context_menu.h" | 36 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
37 #include "chrome/browser/ui/browser.h" | 37 #include "chrome/browser/ui/browser.h" |
(...skipping 14 matching lines...) Expand all Loading... |
52 #include "content/public/browser/download_persistent_store_info.h" | 52 #include "content/public/browser/download_persistent_store_info.h" |
53 #include "content/public/browser/download_save_info.h" | 53 #include "content/public/browser/download_save_info.h" |
54 #include "content/public/browser/download_url_parameters.h" | 54 #include "content/public/browser/download_url_parameters.h" |
55 #include "content/public/browser/notification_source.h" | 55 #include "content/public/browser/notification_source.h" |
56 #include "content/public/browser/render_view_host.h" | 56 #include "content/public/browser/render_view_host.h" |
57 #include "content/public/browser/resource_context.h" | 57 #include "content/public/browser/resource_context.h" |
58 #include "content/public/browser/web_contents.h" | 58 #include "content/public/browser/web_contents.h" |
59 #include "content/public/common/context_menu_params.h" | 59 #include "content/public/common/context_menu_params.h" |
60 #include "content/public/common/page_transition_types.h" | 60 #include "content/public/common/page_transition_types.h" |
61 #include "content/public/test/browser_test_utils.h" | 61 #include "content/public/test/browser_test_utils.h" |
| 62 #include "content/public/test/download_test_observer.h" |
62 #include "content/public/test/test_file_error_injector.h" | 63 #include "content/public/test/test_file_error_injector.h" |
63 #include "content/public/test/test_navigation_observer.h" | 64 #include "content/public/test/test_navigation_observer.h" |
64 #include "content/test/net/url_request_mock_http_job.h" | 65 #include "content/test/net/url_request_mock_http_job.h" |
65 #include "content/test/net/url_request_slow_download_job.h" | 66 #include "content/test/net/url_request_slow_download_job.h" |
66 #include "net/base/net_util.h" | 67 #include "net/base/net_util.h" |
67 #include "net/test/test_server.h" | 68 #include "net/test/test_server.h" |
68 #include "testing/gtest/include/gtest/gtest.h" | 69 #include "testing/gtest/include/gtest/gtest.h" |
69 | 70 |
70 using content::BrowserContext; | 71 using content::BrowserContext; |
71 using content::BrowserThread; | 72 using content::BrowserThread; |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 return DownloadPrefs::FromDownloadManager( | 340 return DownloadPrefs::FromDownloadManager( |
340 DownloadManagerForBrowser(browser)); | 341 DownloadManagerForBrowser(browser)); |
341 } | 342 } |
342 | 343 |
343 FilePath GetDownloadDirectory(Browser* browser) { | 344 FilePath GetDownloadDirectory(Browser* browser) { |
344 return GetDownloadPrefs(browser)->DownloadPath(); | 345 return GetDownloadPrefs(browser)->DownloadPath(); |
345 } | 346 } |
346 | 347 |
347 // Create a DownloadTestObserverTerminal that will wait for the | 348 // Create a DownloadTestObserverTerminal that will wait for the |
348 // specified number of downloads to finish. | 349 // specified number of downloads to finish. |
349 DownloadTestObserver* CreateWaiter(Browser* browser, int num_downloads) { | 350 content::DownloadTestObserver* CreateWaiter( |
| 351 Browser* browser, int num_downloads) { |
350 DownloadManager* download_manager = DownloadManagerForBrowser(browser); | 352 DownloadManager* download_manager = DownloadManagerForBrowser(browser); |
351 return new DownloadTestObserverTerminal( | 353 return new content::DownloadTestObserverTerminal( |
352 download_manager, num_downloads, | 354 download_manager, num_downloads, |
353 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); | 355 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); |
354 } | 356 } |
355 | 357 |
356 // Create a DownloadTestObserverInProgress that will wait for the | 358 // Create a DownloadTestObserverInProgress that will wait for the |
357 // specified number of downloads to start. | 359 // specified number of downloads to start. |
358 DownloadTestObserver* CreateInProgressWaiter(Browser* browser, | 360 content::DownloadTestObserver* CreateInProgressWaiter( |
359 int num_downloads) { | 361 Browser* browser, int num_downloads) { |
360 DownloadManager* download_manager = DownloadManagerForBrowser(browser); | 362 DownloadManager* download_manager = DownloadManagerForBrowser(browser); |
361 return new DownloadTestObserverInProgress( | 363 return new content::DownloadTestObserverInProgress( |
362 download_manager, num_downloads); | 364 download_manager, num_downloads); |
363 } | 365 } |
364 | 366 |
365 // Create a DownloadTestObserverTerminal that will wait for the | 367 // Create a DownloadTestObserverTerminal that will wait for the |
366 // specified number of downloads to finish, or for | 368 // specified number of downloads to finish, or for |
367 // a dangerous download warning to be shown. | 369 // a dangerous download warning to be shown. |
368 DownloadTestObserver* DangerousDownloadWaiter( | 370 content::DownloadTestObserver* DangerousDownloadWaiter( |
369 Browser* browser, | 371 Browser* browser, |
370 int num_downloads, | 372 int num_downloads, |
371 DownloadTestObserver::DangerousDownloadAction dangerous_download_action) { | 373 content::DownloadTestObserver::DangerousDownloadAction |
| 374 dangerous_download_action) { |
372 DownloadManager* download_manager = DownloadManagerForBrowser(browser); | 375 DownloadManager* download_manager = DownloadManagerForBrowser(browser); |
373 return new DownloadTestObserverTerminal( | 376 return new content::DownloadTestObserverTerminal( |
374 download_manager, num_downloads, | 377 download_manager, num_downloads, |
375 dangerous_download_action); | 378 dangerous_download_action); |
376 } | 379 } |
377 | 380 |
378 void CheckDownloadStatesForBrowser(Browser* browser, | 381 void CheckDownloadStatesForBrowser(Browser* browser, |
379 size_t num, | 382 size_t num, |
380 DownloadItem::DownloadState state) { | 383 DownloadItem::DownloadState state) { |
381 std::vector<DownloadItem*> download_items; | 384 std::vector<DownloadItem*> download_items; |
382 GetDownloads(browser, &download_items); | 385 GetDownloads(browser, &download_items); |
383 | 386 |
(...skipping 11 matching lines...) Expand all Loading... |
395 // Download |url|, then wait for the download to finish. | 398 // Download |url|, then wait for the download to finish. |
396 // |disposition| indicates where the navigation occurs (current tab, new | 399 // |disposition| indicates where the navigation occurs (current tab, new |
397 // foreground tab, etc). | 400 // foreground tab, etc). |
398 // |browser_test_flags| indicate what to wait for, and is an OR of 0 or more | 401 // |browser_test_flags| indicate what to wait for, and is an OR of 0 or more |
399 // values in the ui_test_utils::BrowserTestWaitFlags enum. | 402 // values in the ui_test_utils::BrowserTestWaitFlags enum. |
400 void DownloadAndWaitWithDisposition(Browser* browser, | 403 void DownloadAndWaitWithDisposition(Browser* browser, |
401 const GURL& url, | 404 const GURL& url, |
402 WindowOpenDisposition disposition, | 405 WindowOpenDisposition disposition, |
403 int browser_test_flags) { | 406 int browser_test_flags) { |
404 // Setup notification, navigate, and block. | 407 // Setup notification, navigate, and block. |
405 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(browser, 1)); | 408 scoped_ptr<content::DownloadTestObserver> observer( |
| 409 CreateWaiter(browser, 1)); |
406 // This call will block until the condition specified by | 410 // This call will block until the condition specified by |
407 // |browser_test_flags|, but will not wait for the download to finish. | 411 // |browser_test_flags|, but will not wait for the download to finish. |
408 ui_test_utils::NavigateToURLWithDisposition(browser, | 412 ui_test_utils::NavigateToURLWithDisposition(browser, |
409 url, | 413 url, |
410 disposition, | 414 disposition, |
411 browser_test_flags); | 415 browser_test_flags); |
412 // Waits for the download to complete. | 416 // Waits for the download to complete. |
413 observer->WaitForFinished(); | 417 observer->WaitForFinished(); |
414 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 418 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
415 // We don't expect a file chooser to be shown. | 419 // We don't expect a file chooser to be shown. |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 // |expected_title_finished| need to be checked. | 490 // |expected_title_finished| need to be checked. |
487 FilePath filename; | 491 FilePath filename; |
488 net::FileURLToFilePath(url, &filename); | 492 net::FileURLToFilePath(url, &filename); |
489 string16 expected_title_in_progress( | 493 string16 expected_title_in_progress( |
490 ASCIIToUTF16(partial_indication) + filename.LossyDisplayName()); | 494 ASCIIToUTF16(partial_indication) + filename.LossyDisplayName()); |
491 string16 expected_title_finished( | 495 string16 expected_title_finished( |
492 ASCIIToUTF16(total_indication) + filename.LossyDisplayName()); | 496 ASCIIToUTF16(total_indication) + filename.LossyDisplayName()); |
493 | 497 |
494 // Download a partial web page in a background tab and wait. | 498 // Download a partial web page in a background tab and wait. |
495 // The mock system will not complete until it gets a special URL. | 499 // The mock system will not complete until it gets a special URL. |
496 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(browser, 1)); | 500 scoped_ptr<content::DownloadTestObserver> observer( |
| 501 CreateWaiter(browser, 1)); |
497 ui_test_utils::NavigateToURL(browser, url); | 502 ui_test_utils::NavigateToURL(browser, url); |
498 | 503 |
499 // TODO(ahendrickson): check download status text before downloading. | 504 // TODO(ahendrickson): check download status text before downloading. |
500 // Need to: | 505 // Need to: |
501 // - Add a member function to the |DownloadShelf| interface class, that | 506 // - Add a member function to the |DownloadShelf| interface class, that |
502 // indicates how many members it has. | 507 // indicates how many members it has. |
503 // - Add a member function to |DownloadShelf| to get the status text | 508 // - Add a member function to |DownloadShelf| to get the status text |
504 // of a given member (for example, via the name in |DownloadItemView|'s | 509 // of a given member (for example, via the name in |DownloadItemView|'s |
505 // GetAccessibleState() member function), by index. | 510 // GetAccessibleState() member function), by index. |
506 // - Iterate over browser->window()->GetDownloadShelf()'s members | 511 // - Iterate over browser->window()->GetDownloadShelf()'s members |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 | 627 |
623 std::string server_path = "files/downloads/"; | 628 std::string server_path = "files/downloads/"; |
624 server_path += download_info.url_name; | 629 server_path += download_info.url_name; |
625 GURL url = test_server()->GetURL(server_path); | 630 GURL url = test_server()->GetURL(server_path); |
626 ASSERT_TRUE(url.is_valid()) << s.str(); | 631 ASSERT_TRUE(url.is_valid()) << s.str(); |
627 | 632 |
628 DownloadManager* download_manager = DownloadManagerForBrowser(browser()); | 633 DownloadManager* download_manager = DownloadManagerForBrowser(browser()); |
629 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 634 WebContents* web_contents = chrome::GetActiveWebContents(browser()); |
630 ASSERT_TRUE(web_contents) << s.str(); | 635 ASSERT_TRUE(web_contents) << s.str(); |
631 | 636 |
632 scoped_ptr<DownloadTestObserver> observer( | 637 scoped_ptr<content::DownloadTestObserver> observer( |
633 new DownloadTestObserverTerminal( | 638 new content::DownloadTestObserverTerminal( |
634 download_manager, | 639 download_manager, |
635 1, | 640 1, |
636 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 641 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
637 | 642 |
638 if (download_info.download_method == DOWNLOAD_DIRECT) { | 643 if (download_info.download_method == DOWNLOAD_DIRECT) { |
639 // Go directly to download. Don't wait for navigation. | 644 // Go directly to download. Don't wait for navigation. |
640 content::DownloadSaveInfo save_info; | 645 content::DownloadSaveInfo save_info; |
641 // NOTE: |prompt_for_save_location| may change during the download. | 646 // NOTE: |prompt_for_save_location| may change during the download. |
642 save_info.prompt_for_save_location = false; | 647 save_info.prompt_for_save_location = false; |
643 | 648 |
644 scoped_refptr<DownloadTestItemCreationObserver> creation_observer( | 649 scoped_refptr<content::DownloadTestItemCreationObserver> |
645 new DownloadTestItemCreationObserver); | 650 creation_observer(new content::DownloadTestItemCreationObserver); |
646 | 651 |
647 scoped_ptr<DownloadUrlParameters> params( | 652 scoped_ptr<DownloadUrlParameters> params( |
648 DownloadUrlParameters::FromWebContents(web_contents, url, save_info)); | 653 DownloadUrlParameters::FromWebContents(web_contents, url, save_info)); |
649 params->set_callback(creation_observer->callback()); | 654 params->set_callback(creation_observer->callback()); |
650 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass()); | 655 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass()); |
651 | 656 |
652 // Wait until the item is created, or we have determined that it | 657 // Wait until the item is created, or we have determined that it |
653 // won't be. | 658 // won't be. |
654 creation_observer->WaitForDownloadItemCreation(); | 659 creation_observer->WaitForDownloadItemCreation(); |
655 | 660 |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
887 // Re-enable prompting. | 892 // Re-enable prompting. |
888 browser()->profile()->GetPrefs()->SetBoolean( | 893 browser()->profile()->GetPrefs()->SetBoolean( |
889 prefs::kPromptForDownload, true); | 894 prefs::kPromptForDownload, true); |
890 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 895 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
891 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 896 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
892 | 897 |
893 EnableFileChooser(true); | 898 EnableFileChooser(true); |
894 | 899 |
895 // Download the file and wait. We expect the Select File dialog to appear | 900 // Download the file and wait. We expect the Select File dialog to appear |
896 // due to the MIME type, but we still wait until the download completes. | 901 // due to the MIME type, but we still wait until the download completes. |
897 scoped_ptr<DownloadTestObserver> observer( | 902 scoped_ptr<content::DownloadTestObserver> observer( |
898 new DownloadTestObserverTerminal( | 903 new content::DownloadTestObserverTerminal( |
899 DownloadManagerForBrowser(browser()), | 904 DownloadManagerForBrowser(browser()), |
900 1, | 905 1, |
901 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 906 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
902 ui_test_utils::NavigateToURLWithDisposition( | 907 ui_test_utils::NavigateToURLWithDisposition( |
903 browser(), url, CURRENT_TAB, | 908 browser(), url, CURRENT_TAB, |
904 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 909 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
905 observer->WaitForFinished(); | 910 observer->WaitForFinished(); |
906 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 911 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
907 CheckDownloadStates(1, DownloadItem::COMPLETE); | 912 CheckDownloadStates(1, DownloadItem::COMPLETE); |
908 EXPECT_TRUE(DidShowFileChooser()); | 913 EXPECT_TRUE(DidShowFileChooser()); |
909 | 914 |
910 // Check state. | 915 // Check state. |
911 EXPECT_EQ(1, browser()->tab_count()); | 916 EXPECT_EQ(1, browser()->tab_count()); |
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1402 CheckDownload(browser(), file, file); | 1407 CheckDownload(browser(), file, file); |
1403 } | 1408 } |
1404 | 1409 |
1405 // Check that downloading multiple (in this case, 2) files does not result in | 1410 // Check that downloading multiple (in this case, 2) files does not result in |
1406 // corrupted files. | 1411 // corrupted files. |
1407 IN_PROC_BROWSER_TEST_F(DownloadTest, MultiDownload) { | 1412 IN_PROC_BROWSER_TEST_F(DownloadTest, MultiDownload) { |
1408 EXPECT_EQ(1, browser()->tab_count()); | 1413 EXPECT_EQ(1, browser()->tab_count()); |
1409 | 1414 |
1410 // Create a download, wait until it's started, and confirm | 1415 // Create a download, wait until it's started, and confirm |
1411 // we're in the expected state. | 1416 // we're in the expected state. |
1412 scoped_ptr<DownloadTestObserver> observer1( | 1417 scoped_ptr<content::DownloadTestObserver> observer1( |
1413 CreateInProgressWaiter(browser(), 1)); | 1418 CreateInProgressWaiter(browser(), 1)); |
1414 ui_test_utils::NavigateToURL( | 1419 ui_test_utils::NavigateToURL( |
1415 browser(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); | 1420 browser(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); |
1416 observer1->WaitForFinished(); | 1421 observer1->WaitForFinished(); |
1417 | 1422 |
1418 std::vector<DownloadItem*> downloads; | 1423 std::vector<DownloadItem*> downloads; |
1419 DownloadManagerForBrowser(browser())->SearchDownloads( | 1424 DownloadManagerForBrowser(browser())->SearchDownloads( |
1420 string16(), &downloads); | 1425 string16(), &downloads); |
1421 ASSERT_EQ(1u, downloads.size()); | 1426 ASSERT_EQ(1u, downloads.size()); |
1422 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->GetState()); | 1427 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->GetState()); |
(...skipping 14 matching lines...) Expand all Loading... |
1437 // We don't know the order of the downloads. | 1442 // We don't know the order of the downloads. |
1438 DownloadItem* download2 = downloads[(download1 == downloads[0]) ? 1 : 0]; | 1443 DownloadItem* download2 = downloads[(download1 == downloads[0]) ? 1 : 0]; |
1439 | 1444 |
1440 ASSERT_EQ(DownloadItem::IN_PROGRESS, download1->GetState()); | 1445 ASSERT_EQ(DownloadItem::IN_PROGRESS, download1->GetState()); |
1441 ASSERT_EQ(DownloadItem::COMPLETE, download2->GetState()); | 1446 ASSERT_EQ(DownloadItem::COMPLETE, download2->GetState()); |
1442 // The download shelf should be open. | 1447 // The download shelf should be open. |
1443 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 1448 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
1444 | 1449 |
1445 // Allow the first request to finish. We do this by loading a third URL | 1450 // Allow the first request to finish. We do this by loading a third URL |
1446 // in a separate tab. | 1451 // in a separate tab. |
1447 scoped_ptr<DownloadTestObserver> observer2(CreateWaiter(browser(), 1)); | 1452 scoped_ptr<content::DownloadTestObserver> observer2( |
| 1453 CreateWaiter(browser(), 1)); |
1448 GURL finish_url(URLRequestSlowDownloadJob::kFinishDownloadUrl); | 1454 GURL finish_url(URLRequestSlowDownloadJob::kFinishDownloadUrl); |
1449 ui_test_utils::NavigateToURLWithDisposition( | 1455 ui_test_utils::NavigateToURLWithDisposition( |
1450 browser(), | 1456 browser(), |
1451 finish_url, | 1457 finish_url, |
1452 NEW_FOREGROUND_TAB, | 1458 NEW_FOREGROUND_TAB, |
1453 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 1459 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
1454 observer2->WaitForFinished(); // Wait for the third request. | 1460 observer2->WaitForFinished(); // Wait for the third request. |
1455 EXPECT_EQ(1u, observer2->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 1461 EXPECT_EQ(1u, observer2->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
1456 | 1462 |
1457 // Get the important info from other threads and check it. | 1463 // Get the important info from other threads and check it. |
(...skipping 29 matching lines...) Expand all Loading... |
1487 // navigation would allow the observer to return. However, the only | 1493 // navigation would allow the observer to return. However, the only |
1488 // ModelChanged() event the code will currently fire is in | 1494 // ModelChanged() event the code will currently fire is in |
1489 // OnCreateDownloadEntryComplete, at which point the download item will | 1495 // OnCreateDownloadEntryComplete, at which point the download item will |
1490 // be in the state we need. | 1496 // be in the state we need. |
1491 // The right way to fix this is to create finer grained states on the | 1497 // The right way to fix this is to create finer grained states on the |
1492 // DownloadItem, and wait for the state that indicates the item has been | 1498 // DownloadItem, and wait for the state that indicates the item has been |
1493 // entered in the history and made visible in the UI. | 1499 // entered in the history and made visible in the UI. |
1494 | 1500 |
1495 // Create a download, wait until it's started, and confirm | 1501 // Create a download, wait until it's started, and confirm |
1496 // we're in the expected state. | 1502 // we're in the expected state. |
1497 scoped_ptr<DownloadTestObserver> observer( | 1503 scoped_ptr<content::DownloadTestObserver> observer( |
1498 CreateInProgressWaiter(browser(), 1)); | 1504 CreateInProgressWaiter(browser(), 1)); |
1499 ui_test_utils::NavigateToURL( | 1505 ui_test_utils::NavigateToURL( |
1500 browser(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); | 1506 browser(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); |
1501 observer->WaitForFinished(); | 1507 observer->WaitForFinished(); |
1502 | 1508 |
1503 std::vector<DownloadItem*> downloads; | 1509 std::vector<DownloadItem*> downloads; |
1504 DownloadManagerForBrowser(browser())->SearchDownloads( | 1510 DownloadManagerForBrowser(browser())->SearchDownloads( |
1505 string16(), &downloads); | 1511 string16(), &downloads); |
1506 ASSERT_EQ(1u, downloads.size()); | 1512 ASSERT_EQ(1u, downloads.size()); |
1507 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->GetState()); | 1513 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->GetState()); |
1508 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 1514 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
1509 | 1515 |
1510 // Cancel the download and wait for download system quiesce. | 1516 // Cancel the download and wait for download system quiesce. |
1511 downloads[0]->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); | 1517 downloads[0]->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); |
1512 scoped_refptr<DownloadTestFlushObserver> flush_observer( | 1518 scoped_refptr<content::DownloadTestFlushObserver> flush_observer( |
1513 new DownloadTestFlushObserver( | 1519 new content::DownloadTestFlushObserver( |
1514 DownloadManagerForBrowser(browser()))); | 1520 DownloadManagerForBrowser(browser()))); |
1515 flush_observer->WaitForFlush(); | 1521 flush_observer->WaitForFlush(); |
1516 | 1522 |
1517 // Get the important info from other threads and check it. | 1523 // Get the important info from other threads and check it. |
1518 EXPECT_TRUE(EnsureNoPendingDownloads()); | 1524 EXPECT_TRUE(EnsureNoPendingDownloads()); |
1519 | 1525 |
1520 // Using "DownloadItem::Remove" follows the discard dangerous download path, | 1526 // Using "DownloadItem::Remove" follows the discard dangerous download path, |
1521 // which completely removes the browser from the shelf and closes the shelf | 1527 // which completely removes the browser from the shelf and closes the shelf |
1522 // if it was there. Download panel stays open on ChromeOS. | 1528 // if it was there. Download panel stays open on ChromeOS. |
1523 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1529 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1610 signal.Wait(); | 1616 signal.Wait(); |
1611 } | 1617 } |
1612 | 1618 |
1613 // Test to make sure the 'download' attribute in anchor tag is respected. | 1619 // Test to make sure the 'download' attribute in anchor tag is respected. |
1614 IN_PROC_BROWSER_TEST_F(DownloadTest, AnchorDownloadTag) { | 1620 IN_PROC_BROWSER_TEST_F(DownloadTest, AnchorDownloadTag) { |
1615 FilePath file(FILE_PATH_LITERAL("download-anchor-attrib.html")); | 1621 FilePath file(FILE_PATH_LITERAL("download-anchor-attrib.html")); |
1616 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1622 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1617 | 1623 |
1618 // Create a download, wait until it's complete, and confirm | 1624 // Create a download, wait until it's complete, and confirm |
1619 // we're in the expected state. | 1625 // we're in the expected state. |
1620 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(browser(), 1)); | 1626 scoped_ptr<content::DownloadTestObserver> observer( |
| 1627 CreateWaiter(browser(), 1)); |
1621 ui_test_utils::NavigateToURL(browser(), url); | 1628 ui_test_utils::NavigateToURL(browser(), url); |
1622 observer->WaitForFinished(); | 1629 observer->WaitForFinished(); |
1623 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 1630 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
1624 CheckDownloadStates(1, DownloadItem::COMPLETE); | 1631 CheckDownloadStates(1, DownloadItem::COMPLETE); |
1625 | 1632 |
1626 // Confirm the downloaded data exists. | 1633 // Confirm the downloaded data exists. |
1627 FilePath downloaded_file = GetDownloadDirectory(browser()); | 1634 FilePath downloaded_file = GetDownloadDirectory(browser()); |
1628 downloaded_file = downloaded_file.Append(FILE_PATH_LITERAL("a_red_dot.png")); | 1635 downloaded_file = downloaded_file.Append(FILE_PATH_LITERAL("a_red_dot.png")); |
1629 EXPECT_TRUE(file_util::PathExists(downloaded_file)); | 1636 EXPECT_TRUE(file_util::PathExists(downloaded_file)); |
1630 } | 1637 } |
(...skipping 30 matching lines...) Expand all Loading... |
1661 } | 1668 } |
1662 | 1669 |
1663 // Download an extension. Expect a dangerous download warning. | 1670 // Download an extension. Expect a dangerous download warning. |
1664 // Deny the download. | 1671 // Deny the download. |
1665 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxDenyInstall) { | 1672 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxDenyInstall) { |
1666 if (!extensions::switch_utils::IsEasyOffStoreInstallEnabled()) | 1673 if (!extensions::switch_utils::IsEasyOffStoreInstallEnabled()) |
1667 return; | 1674 return; |
1668 | 1675 |
1669 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); | 1676 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); |
1670 | 1677 |
1671 scoped_ptr<DownloadTestObserver> observer( | 1678 scoped_ptr<content::DownloadTestObserver> observer( |
1672 DangerousDownloadWaiter( | 1679 DangerousDownloadWaiter( |
1673 browser(), 1, | 1680 browser(), 1, |
1674 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); | 1681 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_DENY)); |
1675 ui_test_utils::NavigateToURL(browser(), extension_url); | 1682 ui_test_utils::NavigateToURL(browser(), extension_url); |
1676 | 1683 |
1677 observer->WaitForFinished(); | 1684 observer->WaitForFinished(); |
1678 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::CANCELLED)); | 1685 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::CANCELLED)); |
1679 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1686 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
1680 | 1687 |
1681 // Download shelf should close. Download panel stays open on ChromeOS. | 1688 // Download shelf should close. Download panel stays open on ChromeOS. |
1682 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1689 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
1683 | 1690 |
1684 // Check that the CRX is not installed. | 1691 // Check that the CRX is not installed. |
1685 ExtensionService* extension_service = | 1692 ExtensionService* extension_service = |
1686 browser()->profile()->GetExtensionService(); | 1693 browser()->profile()->GetExtensionService(); |
1687 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1694 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); |
1688 } | 1695 } |
1689 | 1696 |
1690 // Download an extension. Expect a dangerous download warning. | 1697 // Download an extension. Expect a dangerous download warning. |
1691 // Allow the download, deny the install. | 1698 // Allow the download, deny the install. |
1692 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallDenysPermissions) { | 1699 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallDenysPermissions) { |
1693 if (!extensions::switch_utils::IsEasyOffStoreInstallEnabled()) | 1700 if (!extensions::switch_utils::IsEasyOffStoreInstallEnabled()) |
1694 return; | 1701 return; |
1695 | 1702 |
1696 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); | 1703 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); |
1697 | 1704 |
1698 // Install a mock install UI that simulates a user denying permission to | 1705 // Install a mock install UI that simulates a user denying permission to |
1699 // finish the install. | 1706 // finish the install. |
1700 download_crx_util::SetMockInstallPromptForTesting( | 1707 download_crx_util::SetMockInstallPromptForTesting( |
1701 new MockAbortExtensionInstallPrompt()); | 1708 new MockAbortExtensionInstallPrompt()); |
1702 | 1709 |
1703 scoped_ptr<DownloadTestObserver> observer( | 1710 scoped_ptr<content::DownloadTestObserver> observer( |
1704 DangerousDownloadWaiter( | 1711 DangerousDownloadWaiter( |
1705 browser(), 1, | 1712 browser(), 1, |
1706 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); | 1713 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
1707 ui_test_utils::NavigateToURL(browser(), extension_url); | 1714 ui_test_utils::NavigateToURL(browser(), extension_url); |
1708 | 1715 |
1709 observer->WaitForFinished(); | 1716 observer->WaitForFinished(); |
1710 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 1717 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
1711 CheckDownloadStates(1, DownloadItem::COMPLETE); | 1718 CheckDownloadStates(1, DownloadItem::COMPLETE); |
1712 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1719 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
1713 | 1720 |
1714 // Download shelf should close. Download panel stays open on ChromeOS. | 1721 // Download shelf should close. Download panel stays open on ChromeOS. |
1715 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1722 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
1716 | 1723 |
1717 // Check that the extension was not installed. | 1724 // Check that the extension was not installed. |
1718 ExtensionService* extension_service = | 1725 ExtensionService* extension_service = |
1719 browser()->profile()->GetExtensionService(); | 1726 browser()->profile()->GetExtensionService(); |
1720 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1727 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); |
1721 } | 1728 } |
1722 | 1729 |
1723 // Download an extension. Expect a dangerous download warning. | 1730 // Download an extension. Expect a dangerous download warning. |
1724 // Allow the download, and the install. | 1731 // Allow the download, and the install. |
1725 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallAcceptPermissions) { | 1732 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInstallAcceptPermissions) { |
1726 if (!extensions::switch_utils::IsEasyOffStoreInstallEnabled()) | 1733 if (!extensions::switch_utils::IsEasyOffStoreInstallEnabled()) |
1727 return; | 1734 return; |
1728 | 1735 |
1729 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); | 1736 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kGoodCrxPath)); |
1730 | 1737 |
1731 // Install a mock install UI that simulates a user allowing permission to | 1738 // Install a mock install UI that simulates a user allowing permission to |
1732 // finish the install. | 1739 // finish the install. |
1733 SetAllowMockInstallPrompt(); | 1740 SetAllowMockInstallPrompt(); |
1734 | 1741 |
1735 scoped_ptr<DownloadTestObserver> observer( | 1742 scoped_ptr<content::DownloadTestObserver> observer( |
1736 DangerousDownloadWaiter( | 1743 DangerousDownloadWaiter( |
1737 browser(), 1, | 1744 browser(), 1, |
1738 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); | 1745 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
1739 ui_test_utils::NavigateToURL(browser(), extension_url); | 1746 ui_test_utils::NavigateToURL(browser(), extension_url); |
1740 | 1747 |
1741 observer->WaitForFinished(); | 1748 observer->WaitForFinished(); |
1742 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 1749 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
1743 CheckDownloadStates(1, DownloadItem::COMPLETE); | 1750 CheckDownloadStates(1, DownloadItem::COMPLETE); |
1744 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1751 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
1745 | 1752 |
1746 // Download shelf should close. Download panel stays open on ChromeOS. | 1753 // Download shelf should close. Download panel stays open on ChromeOS. |
1747 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1754 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
1748 | 1755 |
1749 // Check that the extension was installed. | 1756 // Check that the extension was installed. |
1750 ExtensionService* extension_service = | 1757 ExtensionService* extension_service = |
1751 browser()->profile()->GetExtensionService(); | 1758 browser()->profile()->GetExtensionService(); |
1752 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1759 ASSERT_TRUE(extension_service->GetExtensionById(kGoodCrxId, false)); |
1753 } | 1760 } |
1754 | 1761 |
1755 // Test installing a CRX that fails integrity checks. | 1762 // Test installing a CRX that fails integrity checks. |
1756 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) { | 1763 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxInvalid) { |
1757 FilePath file(FILE_PATH_LITERAL("extensions/bad_signature.crx")); | 1764 FilePath file(FILE_PATH_LITERAL("extensions/bad_signature.crx")); |
1758 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1765 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1759 | 1766 |
1760 // Install a mock install UI that simulates a user allowing permission to | 1767 // Install a mock install UI that simulates a user allowing permission to |
1761 // finish the install, and dismisses any error message. We check that the | 1768 // finish the install, and dismisses any error message. We check that the |
1762 // install failed below. | 1769 // install failed below. |
1763 SetAllowMockInstallPrompt(); | 1770 SetAllowMockInstallPrompt(); |
1764 | 1771 |
1765 scoped_ptr<DownloadTestObserver> observer( | 1772 scoped_ptr<content::DownloadTestObserver> observer( |
1766 DangerousDownloadWaiter( | 1773 DangerousDownloadWaiter( |
1767 browser(), 1, | 1774 browser(), 1, |
1768 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); | 1775 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
1769 ui_test_utils::NavigateToURL(browser(), extension_url); | 1776 ui_test_utils::NavigateToURL(browser(), extension_url); |
1770 | 1777 |
1771 observer->WaitForFinished(); | 1778 observer->WaitForFinished(); |
1772 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 1779 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
1773 CheckDownloadStates(1, DownloadItem::COMPLETE); | 1780 CheckDownloadStates(1, DownloadItem::COMPLETE); |
1774 | 1781 |
1775 // Check that the extension was not installed. | 1782 // Check that the extension was not installed. |
1776 ExtensionService* extension_service = | 1783 ExtensionService* extension_service = |
1777 browser()->profile()->GetExtensionService(); | 1784 browser()->profile()->GetExtensionService(); |
1778 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); | 1785 ASSERT_FALSE(extension_service->GetExtensionById(kGoodCrxId, false)); |
1779 } | 1786 } |
1780 | 1787 |
1781 // Install a large (100kb) theme. | 1788 // Install a large (100kb) theme. |
1782 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxLargeTheme) { | 1789 IN_PROC_BROWSER_TEST_F(DownloadTest, CrxLargeTheme) { |
1783 if (!extensions::switch_utils::IsEasyOffStoreInstallEnabled()) | 1790 if (!extensions::switch_utils::IsEasyOffStoreInstallEnabled()) |
1784 return; | 1791 return; |
1785 | 1792 |
1786 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kLargeThemePath)); | 1793 GURL extension_url(URLRequestMockHTTPJob::GetMockUrl(kLargeThemePath)); |
1787 | 1794 |
1788 // Install a mock install UI that simulates a user allowing permission to | 1795 // Install a mock install UI that simulates a user allowing permission to |
1789 // finish the install. | 1796 // finish the install. |
1790 SetAllowMockInstallPrompt(); | 1797 SetAllowMockInstallPrompt(); |
1791 | 1798 |
1792 scoped_ptr<DownloadTestObserver> observer( | 1799 scoped_ptr<content::DownloadTestObserver> observer( |
1793 DangerousDownloadWaiter( | 1800 DangerousDownloadWaiter( |
1794 browser(), 1, | 1801 browser(), 1, |
1795 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); | 1802 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
1796 ui_test_utils::NavigateToURL(browser(), extension_url); | 1803 ui_test_utils::NavigateToURL(browser(), extension_url); |
1797 | 1804 |
1798 observer->WaitForFinished(); | 1805 observer->WaitForFinished(); |
1799 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 1806 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
1800 CheckDownloadStates(1, DownloadItem::COMPLETE); | 1807 CheckDownloadStates(1, DownloadItem::COMPLETE); |
1801 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 1808 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
1802 | 1809 |
1803 // Download shelf should close. Download panel stays open on ChromeOS. | 1810 // Download shelf should close. Download panel stays open on ChromeOS. |
1804 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); | 1811 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); |
1805 | 1812 |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1943 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrl) { | 1950 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrl) { |
1944 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); | 1951 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); |
1945 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 1952 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
1946 | 1953 |
1947 // DownloadUrl always prompts; return acceptance of whatever it prompts. | 1954 // DownloadUrl always prompts; return acceptance of whatever it prompts. |
1948 EnableFileChooser(true); | 1955 EnableFileChooser(true); |
1949 | 1956 |
1950 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 1957 WebContents* web_contents = chrome::GetActiveWebContents(browser()); |
1951 ASSERT_TRUE(web_contents); | 1958 ASSERT_TRUE(web_contents); |
1952 | 1959 |
1953 DownloadTestObserver* observer( | 1960 content::DownloadTestObserver* observer( |
1954 new DownloadTestObserverTerminal( | 1961 new content::DownloadTestObserverTerminal( |
1955 DownloadManagerForBrowser(browser()), 1, | 1962 DownloadManagerForBrowser(browser()), 1, |
1956 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 1963 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
1957 content::DownloadSaveInfo save_info; | 1964 content::DownloadSaveInfo save_info; |
1958 save_info.prompt_for_save_location = true; | 1965 save_info.prompt_for_save_location = true; |
1959 scoped_ptr<DownloadUrlParameters> params( | 1966 scoped_ptr<DownloadUrlParameters> params( |
1960 DownloadUrlParameters::FromWebContents(web_contents, url, save_info)); | 1967 DownloadUrlParameters::FromWebContents(web_contents, url, save_info)); |
1961 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass()); | 1968 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass()); |
1962 observer->WaitForFinished(); | 1969 observer->WaitForFinished(); |
1963 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 1970 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
1964 CheckDownloadStates(1, DownloadItem::COMPLETE); | 1971 CheckDownloadStates(1, DownloadItem::COMPLETE); |
1965 EXPECT_TRUE(DidShowFileChooser()); | 1972 EXPECT_TRUE(DidShowFileChooser()); |
1966 | 1973 |
(...skipping 10 matching lines...) Expand all Loading... |
1977 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 1984 WebContents* web_contents = chrome::GetActiveWebContents(browser()); |
1978 ASSERT_TRUE(web_contents); | 1985 ASSERT_TRUE(web_contents); |
1979 | 1986 |
1980 ScopedTempDir other_directory; | 1987 ScopedTempDir other_directory; |
1981 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); | 1988 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); |
1982 FilePath target_file_full_path | 1989 FilePath target_file_full_path |
1983 = other_directory.path().Append(file.BaseName()); | 1990 = other_directory.path().Append(file.BaseName()); |
1984 content::DownloadSaveInfo save_info; | 1991 content::DownloadSaveInfo save_info; |
1985 save_info.file_path = target_file_full_path; | 1992 save_info.file_path = target_file_full_path; |
1986 | 1993 |
1987 DownloadTestObserver* observer(CreateWaiter(browser(), 1)); | 1994 content::DownloadTestObserver* observer(CreateWaiter(browser(), 1)); |
1988 scoped_ptr<DownloadUrlParameters> params( | 1995 scoped_ptr<DownloadUrlParameters> params( |
1989 DownloadUrlParameters::FromWebContents(web_contents, url, save_info)); | 1996 DownloadUrlParameters::FromWebContents(web_contents, url, save_info)); |
1990 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass()); | 1997 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass()); |
1991 observer->WaitForFinished(); | 1998 observer->WaitForFinished(); |
1992 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 1999 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
1993 | 2000 |
1994 // Check state. | 2001 // Check state. |
1995 EXPECT_EQ(1, browser()->tab_count()); | 2002 EXPECT_EQ(1, browser()->tab_count()); |
1996 ASSERT_TRUE(CheckDownloadFullPaths(browser(), | 2003 ASSERT_TRUE(CheckDownloadFullPaths(browser(), |
1997 target_file_full_path, | 2004 target_file_full_path, |
(...skipping 15 matching lines...) Expand all Loading... |
2013 // Cache-Control: no-cache set, which normally requires revalidation | 2020 // Cache-Control: no-cache set, which normally requires revalidation |
2014 // each time. | 2021 // each time. |
2015 GURL url = test_server()->GetURL("files/downloads/image.jpg"); | 2022 GURL url = test_server()->GetURL("files/downloads/image.jpg"); |
2016 ASSERT_TRUE(url.is_valid()); | 2023 ASSERT_TRUE(url.is_valid()); |
2017 ui_test_utils::NavigateToURL(browser(), url); | 2024 ui_test_utils::NavigateToURL(browser(), url); |
2018 | 2025 |
2019 // Stop the test server, and then try to save the page. If cache validation | 2026 // Stop the test server, and then try to save the page. If cache validation |
2020 // is not bypassed then this will fail since the server is no longer | 2027 // is not bypassed then this will fail since the server is no longer |
2021 // reachable. | 2028 // reachable. |
2022 ASSERT_TRUE(test_server()->Stop()); | 2029 ASSERT_TRUE(test_server()->Stop()); |
2023 scoped_ptr<DownloadTestObserver> waiter( | 2030 scoped_ptr<content::DownloadTestObserver> waiter( |
2024 new DownloadTestObserverTerminal( | 2031 new content::DownloadTestObserverTerminal( |
2025 DownloadManagerForBrowser(browser()), 1, | 2032 DownloadManagerForBrowser(browser()), 1, |
2026 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 2033 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
2027 chrome::SavePage(browser()); | 2034 chrome::SavePage(browser()); |
2028 waiter->WaitForFinished(); | 2035 waiter->WaitForFinished(); |
2029 EXPECT_EQ(1u, waiter->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 2036 EXPECT_EQ(1u, waiter->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
2030 CheckDownloadStates(1, DownloadItem::COMPLETE); | 2037 CheckDownloadStates(1, DownloadItem::COMPLETE); |
2031 | 2038 |
2032 // Validate that the correct file was downloaded. | 2039 // Validate that the correct file was downloaded. |
2033 GetDownloads(browser(), &download_items); | 2040 GetDownloads(browser(), &download_items); |
2034 EXPECT_TRUE(DidShowFileChooser()); | 2041 EXPECT_TRUE(DidShowFileChooser()); |
2035 ASSERT_EQ(1u, download_items.size()); | 2042 ASSERT_EQ(1u, download_items.size()); |
2036 ASSERT_EQ(url, download_items[0]->GetOriginalUrl()); | 2043 ASSERT_EQ(url, download_items[0]->GetOriginalUrl()); |
2037 | 2044 |
2038 // Try to download it via a context menu. | 2045 // Try to download it via a context menu. |
2039 scoped_ptr<DownloadTestObserver> waiter_context_menu( | 2046 scoped_ptr<content::DownloadTestObserver> waiter_context_menu( |
2040 new DownloadTestObserverTerminal( | 2047 new content::DownloadTestObserverTerminal( |
2041 DownloadManagerForBrowser(browser()), 1, | 2048 DownloadManagerForBrowser(browser()), 1, |
2042 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 2049 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
2043 content::ContextMenuParams context_menu_params; | 2050 content::ContextMenuParams context_menu_params; |
2044 context_menu_params.media_type = WebKit::WebContextMenuData::MediaTypeImage; | 2051 context_menu_params.media_type = WebKit::WebContextMenuData::MediaTypeImage; |
2045 context_menu_params.src_url = url; | 2052 context_menu_params.src_url = url; |
2046 context_menu_params.page_url = url; | 2053 context_menu_params.page_url = url; |
2047 TestRenderViewContextMenu menu(chrome::GetActiveWebContents(browser()), | 2054 TestRenderViewContextMenu menu(chrome::GetActiveWebContents(browser()), |
2048 context_menu_params); | 2055 context_menu_params); |
2049 menu.Init(); | 2056 menu.Init(); |
2050 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS); | 2057 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS); |
2051 waiter_context_menu->WaitForFinished(); | 2058 waiter_context_menu->WaitForFinished(); |
2052 EXPECT_EQ( | 2059 EXPECT_EQ( |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2092 render_view_host->ExecuteJavascriptInWebFrame( | 2099 render_view_host->ExecuteJavascriptInWebFrame( |
2093 string16(), ASCIIToUTF16("SubmitForm()")); | 2100 string16(), ASCIIToUTF16("SubmitForm()")); |
2094 observer.Wait(); | 2101 observer.Wait(); |
2095 EXPECT_EQ(jpeg_url, web_contents->GetURL()); | 2102 EXPECT_EQ(jpeg_url, web_contents->GetURL()); |
2096 | 2103 |
2097 // Stop the test server, and then try to save the page. If cache validation | 2104 // Stop the test server, and then try to save the page. If cache validation |
2098 // is not bypassed then this will fail since the server is no longer | 2105 // is not bypassed then this will fail since the server is no longer |
2099 // reachable. This will also fail if it tries to be retrieved via "GET" | 2106 // reachable. This will also fail if it tries to be retrieved via "GET" |
2100 // rather than "POST". | 2107 // rather than "POST". |
2101 ASSERT_TRUE(test_server()->Stop()); | 2108 ASSERT_TRUE(test_server()->Stop()); |
2102 scoped_ptr<DownloadTestObserver> waiter( | 2109 scoped_ptr<content::DownloadTestObserver> waiter( |
2103 new DownloadTestObserverTerminal( | 2110 new content::DownloadTestObserverTerminal( |
2104 DownloadManagerForBrowser(browser()), 1, | 2111 DownloadManagerForBrowser(browser()), 1, |
2105 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 2112 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
2106 chrome::SavePage(browser()); | 2113 chrome::SavePage(browser()); |
2107 waiter->WaitForFinished(); | 2114 waiter->WaitForFinished(); |
2108 EXPECT_EQ(1u, waiter->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 2115 EXPECT_EQ(1u, waiter->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
2109 CheckDownloadStates(1, DownloadItem::COMPLETE); | 2116 CheckDownloadStates(1, DownloadItem::COMPLETE); |
2110 | 2117 |
2111 // Validate that the correct file was downloaded. | 2118 // Validate that the correct file was downloaded. |
2112 GetDownloads(browser(), &download_items); | 2119 GetDownloads(browser(), &download_items); |
2113 EXPECT_TRUE(DidShowFileChooser()); | 2120 EXPECT_TRUE(DidShowFileChooser()); |
2114 ASSERT_EQ(1u, download_items.size()); | 2121 ASSERT_EQ(1u, download_items.size()); |
2115 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl()); | 2122 ASSERT_EQ(jpeg_url, download_items[0]->GetOriginalUrl()); |
2116 | 2123 |
2117 // Try to download it via a context menu. | 2124 // Try to download it via a context menu. |
2118 scoped_ptr<DownloadTestObserver> waiter_context_menu( | 2125 scoped_ptr<content::DownloadTestObserver> waiter_context_menu( |
2119 new DownloadTestObserverTerminal( | 2126 new content::DownloadTestObserverTerminal( |
2120 DownloadManagerForBrowser(browser()), 1, | 2127 DownloadManagerForBrowser(browser()), 1, |
2121 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 2128 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
2122 content::ContextMenuParams context_menu_params; | 2129 content::ContextMenuParams context_menu_params; |
2123 context_menu_params.media_type = WebKit::WebContextMenuData::MediaTypeImage; | 2130 context_menu_params.media_type = WebKit::WebContextMenuData::MediaTypeImage; |
2124 context_menu_params.src_url = jpeg_url; | 2131 context_menu_params.src_url = jpeg_url; |
2125 context_menu_params.page_url = jpeg_url; | 2132 context_menu_params.page_url = jpeg_url; |
2126 TestRenderViewContextMenu menu(web_contents, context_menu_params); | 2133 TestRenderViewContextMenu menu(web_contents, context_menu_params); |
2127 menu.Init(); | 2134 menu.Init(); |
2128 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS); | 2135 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS); |
2129 waiter_context_menu->WaitForFinished(); | 2136 waiter_context_menu->WaitForFinished(); |
2130 EXPECT_EQ( | 2137 EXPECT_EQ( |
2131 1u, waiter_context_menu->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 2138 1u, waiter_context_menu->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2404 #endif | 2411 #endif |
2405 | 2412 |
2406 std::string path("files/downloads/download-dangerous-blob.html?filename="); | 2413 std::string path("files/downloads/download-dangerous-blob.html?filename="); |
2407 path += kFilename; | 2414 path += kFilename; |
2408 | 2415 |
2409 // Need to use http urls because the blob js doesn't work on file urls for | 2416 // Need to use http urls because the blob js doesn't work on file urls for |
2410 // security reasons. | 2417 // security reasons. |
2411 ASSERT_TRUE(test_server()->Start()); | 2418 ASSERT_TRUE(test_server()->Start()); |
2412 GURL url(test_server()->GetURL(path)); | 2419 GURL url(test_server()->GetURL(path)); |
2413 | 2420 |
2414 DownloadTestObserver* observer(DangerousDownloadWaiter( | 2421 content::DownloadTestObserver* observer(DangerousDownloadWaiter( |
2415 browser(), 1, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); | 2422 browser(), 1, |
| 2423 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); |
2416 ui_test_utils::NavigateToURL(browser(), url); | 2424 ui_test_utils::NavigateToURL(browser(), url); |
2417 observer->WaitForFinished(); | 2425 observer->WaitForFinished(); |
2418 | 2426 |
2419 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); | 2427 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); |
2420 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); | 2428 EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); |
2421 } | 2429 } |
2422 | 2430 |
2423 IN_PROC_BROWSER_TEST_F(DownloadTest, LoadURLExternallyReferrerPolicy) { | 2431 IN_PROC_BROWSER_TEST_F(DownloadTest, LoadURLExternallyReferrerPolicy) { |
2424 // Do initial setup. | 2432 // Do initial setup. |
2425 ASSERT_TRUE(test_server()->Start()); | 2433 ASSERT_TRUE(test_server()->Start()); |
2426 EnableFileChooser(true); | 2434 EnableFileChooser(true); |
2427 std::vector<DownloadItem*> download_items; | 2435 std::vector<DownloadItem*> download_items; |
2428 GetDownloads(browser(), &download_items); | 2436 GetDownloads(browser(), &download_items); |
2429 ASSERT_TRUE(download_items.empty()); | 2437 ASSERT_TRUE(download_items.empty()); |
2430 | 2438 |
2431 // Navigate to a page with a referrer policy and a link on it. The link points | 2439 // Navigate to a page with a referrer policy and a link on it. The link points |
2432 // to testserver's /echoheader. | 2440 // to testserver's /echoheader. |
2433 GURL url = test_server()->GetURL("files/downloads/referrer_policy.html"); | 2441 GURL url = test_server()->GetURL("files/downloads/referrer_policy.html"); |
2434 ASSERT_TRUE(url.is_valid()); | 2442 ASSERT_TRUE(url.is_valid()); |
2435 ui_test_utils::NavigateToURL(browser(), url); | 2443 ui_test_utils::NavigateToURL(browser(), url); |
2436 | 2444 |
2437 scoped_ptr<DownloadTestObserver> waiter( | 2445 scoped_ptr<content::DownloadTestObserver> waiter( |
2438 new DownloadTestObserverTerminal( | 2446 new content::DownloadTestObserverTerminal( |
2439 DownloadManagerForBrowser(browser()), 1, | 2447 DownloadManagerForBrowser(browser()), 1, |
2440 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); | 2448 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); |
2441 | 2449 |
2442 // Click on the link with the alt key pressed. This will download the link | 2450 // Click on the link with the alt key pressed. This will download the link |
2443 // target. | 2451 // target. |
2444 WebContents* tab = chrome::GetActiveWebContents(browser()); | 2452 WebContents* tab = chrome::GetActiveWebContents(browser()); |
2445 WebKit::WebMouseEvent mouse_event; | 2453 WebKit::WebMouseEvent mouse_event; |
2446 mouse_event.type = WebKit::WebInputEvent::MouseDown; | 2454 mouse_event.type = WebKit::WebInputEvent::MouseDown; |
2447 mouse_event.button = WebKit::WebMouseEvent::ButtonLeft; | 2455 mouse_event.button = WebKit::WebMouseEvent::ButtonLeft; |
2448 mouse_event.x = 15; | 2456 mouse_event.x = 15; |
2449 mouse_event.y = 15; | 2457 mouse_event.y = 15; |
2450 mouse_event.clickCount = 1; | 2458 mouse_event.clickCount = 1; |
(...skipping 10 matching lines...) Expand all Loading... |
2461 GetDownloads(browser(), &download_items); | 2469 GetDownloads(browser(), &download_items); |
2462 ASSERT_EQ(1u, download_items.size()); | 2470 ASSERT_EQ(1u, download_items.size()); |
2463 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), | 2471 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), |
2464 download_items[0]->GetOriginalUrl()); | 2472 download_items[0]->GetOriginalUrl()); |
2465 | 2473 |
2466 // Check that the file contains the expected referrer. | 2474 // Check that the file contains the expected referrer. |
2467 FilePath file(download_items[0]->GetFullPath()); | 2475 FilePath file(download_items[0]->GetFullPath()); |
2468 std::string expected_contents = test_server()->GetURL("").spec(); | 2476 std::string expected_contents = test_server()->GetURL("").spec(); |
2469 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); | 2477 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); |
2470 } | 2478 } |
OLD | NEW |