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

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

Issue 10702029: Move tab functions off Browser into browser_tabstrip and browser_tabrestore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 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 <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"
(...skipping 21 matching lines...) Expand all
32 #include "chrome/browser/extensions/extension_service.h" 32 #include "chrome/browser/extensions/extension_service.h"
33 #include "chrome/browser/history/history.h" 33 #include "chrome/browser/history/history.h"
34 #include "chrome/browser/history/history_service_factory.h" 34 #include "chrome/browser/history/history_service_factory.h"
35 #include "chrome/browser/net/url_request_mock_util.h" 35 #include "chrome/browser/net/url_request_mock_util.h"
36 #include "chrome/browser/prefs/pref_service.h" 36 #include "chrome/browser/prefs/pref_service.h"
37 #include "chrome/browser/profiles/profile.h" 37 #include "chrome/browser/profiles/profile.h"
38 #include "chrome/browser/tab_contents/render_view_context_menu.h" 38 #include "chrome/browser/tab_contents/render_view_context_menu.h"
39 #include "chrome/browser/ui/browser.h" 39 #include "chrome/browser/ui/browser.h"
40 #include "chrome/browser/ui/browser_commands.h" 40 #include "chrome/browser/ui/browser_commands.h"
41 #include "chrome/browser/ui/browser_list.h" 41 #include "chrome/browser/ui/browser_list.h"
42 #include "chrome/browser/ui/browser_tabstrip.h"
42 #include "chrome/browser/ui/browser_window.h" 43 #include "chrome/browser/ui/browser_window.h"
43 #include "chrome/browser/ui/chrome_pages.h" 44 #include "chrome/browser/ui/chrome_pages.h"
44 #include "chrome/common/chrome_notification_types.h" 45 #include "chrome/common/chrome_notification_types.h"
45 #include "chrome/common/chrome_paths.h" 46 #include "chrome/common/chrome_paths.h"
46 #include "chrome/common/extensions/extension_switch_utils.h" 47 #include "chrome/common/extensions/extension_switch_utils.h"
47 #include "chrome/common/pref_names.h" 48 #include "chrome/common/pref_names.h"
48 #include "chrome/common/url_constants.h" 49 #include "chrome/common/url_constants.h"
49 #include "chrome/test/base/in_process_browser_test.h" 50 #include "chrome/test/base/in_process_browser_test.h"
50 #include "chrome/test/base/ui_test_utils.h" 51 #include "chrome/test/base/ui_test_utils.h"
51 #include "content/public/browser/download_item.h" 52 #include "content/public/browser/download_item.h"
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 std::vector<DownloadItem*> download_items; 645 std::vector<DownloadItem*> download_items;
645 GetDownloads(browser(), &download_items); 646 GetDownloads(browser(), &download_items);
646 size_t downloads_expected = download_items.size(); 647 size_t downloads_expected = download_items.size();
647 648
648 std::string server_path = "files/downloads/"; 649 std::string server_path = "files/downloads/";
649 server_path += download_info.url_name; 650 server_path += download_info.url_name;
650 GURL url = test_server()->GetURL(server_path); 651 GURL url = test_server()->GetURL(server_path);
651 ASSERT_TRUE(url.is_valid()) << s.str(); 652 ASSERT_TRUE(url.is_valid()) << s.str();
652 653
653 DownloadManager* download_manager = DownloadManagerForBrowser(browser()); 654 DownloadManager* download_manager = DownloadManagerForBrowser(browser());
654 WebContents* web_contents = browser()->GetActiveWebContents(); 655 WebContents* web_contents = chrome::GetActiveWebContents(browser());
655 ASSERT_TRUE(web_contents) << s.str(); 656 ASSERT_TRUE(web_contents) << s.str();
656 657
657 scoped_ptr<DownloadTestObserver> observer( 658 scoped_ptr<DownloadTestObserver> observer(
658 new DownloadTestObserverTerminal( 659 new DownloadTestObserverTerminal(
659 download_manager, 660 download_manager,
660 1, 661 1,
661 false, // Don't bail on select file. 662 false, // Don't bail on select file.
662 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 663 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
663 664
664 if (download_info.download_method == DOWNLOAD_DIRECT) { 665 if (download_info.download_method == DOWNLOAD_DIRECT) {
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 // navigate directly to the file we don't want to download because cross-site 954 // navigate directly to the file we don't want to download because cross-site
954 // navigations reset the TabDownloadState. 955 // navigations reset the TabDownloadState.
955 FilePath same_site_path(FILE_PATH_LITERAL("download_script.html")); 956 FilePath same_site_path(FILE_PATH_LITERAL("download_script.html"));
956 GURL same_site_url(URLRequestMockHTTPJob::GetMockUrl(same_site_path)); 957 GURL same_site_url(URLRequestMockHTTPJob::GetMockUrl(same_site_path));
957 ui_test_utils::NavigateToURL(browser(), same_site_url); 958 ui_test_utils::NavigateToURL(browser(), same_site_url);
958 959
959 // Make sure the initial navigation didn't trigger a download. 960 // Make sure the initial navigation didn't trigger a download.
960 EXPECT_TRUE(EnsureNoPendingDownloads()); 961 EXPECT_TRUE(EnsureNoPendingDownloads());
961 962
962 // Disable downloads for the tab. 963 // Disable downloads for the tab.
963 WebContents* web_contents = browser()->GetActiveWebContents(); 964 WebContents* web_contents = chrome::GetActiveWebContents(browser());
964 DownloadRequestLimiter::TabDownloadState* tab_download_state = 965 DownloadRequestLimiter::TabDownloadState* tab_download_state =
965 g_browser_process->download_request_limiter()->GetDownloadState( 966 g_browser_process->download_request_limiter()->GetDownloadState(
966 web_contents, web_contents, true); 967 web_contents, web_contents, true);
967 ASSERT_TRUE(tab_download_state); 968 ASSERT_TRUE(tab_download_state);
968 tab_download_state->set_download_status( 969 tab_download_state->set_download_status(
969 DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED); 970 DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED);
970 971
971 // Try to start the download via Javascript and wait for the corresponding 972 // Try to start the download via Javascript and wait for the corresponding
972 // load stop event. 973 // load stop event.
973 content::TestNavigationObserver observer( 974 content::TestNavigationObserver observer(
974 content::Source<content::NavigationController>( 975 content::Source<content::NavigationController>(
975 &web_contents->GetController()), 976 &web_contents->GetController()),
976 NULL, 977 NULL,
977 1); 978 1);
978 bool download_assempted; 979 bool download_assempted;
979 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 980 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
980 browser()->GetActiveWebContents()->GetRenderViewHost(), 981 chrome::GetActiveWebContents(browser())->GetRenderViewHost(),
981 L"", 982 L"",
982 L"window.domAutomationController.send(startDownload());", 983 L"window.domAutomationController.send(startDownload());",
983 &download_assempted)); 984 &download_assempted));
984 ASSERT_TRUE(download_assempted); 985 ASSERT_TRUE(download_assempted);
985 observer.WaitForObservation( 986 observer.WaitForObservation(
986 base::Bind(&ui_test_utils::RunMessageLoop), 987 base::Bind(&ui_test_utils::RunMessageLoop),
987 base::Bind(&MessageLoop::Quit, 988 base::Bind(&MessageLoop::Quit,
988 base::Unretained(MessageLoopForUI::current()))); 989 base::Unretained(MessageLoopForUI::current())));
989 990
990 // Check that we did not download the file. 991 // Check that we did not download the file.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG); 1032 DownloadAndWait(browser(), url, EXPECT_NO_SELECT_DIALOG);
1032 1033
1033 CheckDownload(browser(), download_file, file); 1034 CheckDownload(browser(), download_file, file);
1034 1035
1035 // Check state. 1036 // Check state.
1036 EXPECT_EQ(1, browser()->tab_count()); 1037 EXPECT_EQ(1, browser()->tab_count());
1037 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 1038 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
1038 1039
1039 // Open a second tab and wait. 1040 // Open a second tab and wait.
1040 EXPECT_NE(static_cast<TabContents*>(NULL), 1041 EXPECT_NE(static_cast<TabContents*>(NULL),
1041 browser()->AddSelectedTabWithURL( 1042 chrome::AddSelectedTabWithURL(browser(), GURL(),
1042 GURL(), content::PAGE_TRANSITION_TYPED)); 1043 content::PAGE_TRANSITION_TYPED));
1043 EXPECT_EQ(2, browser()->tab_count()); 1044 EXPECT_EQ(2, browser()->tab_count());
1044 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 1045 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
1045 1046
1046 // Hide the download shelf. 1047 // Hide the download shelf.
1047 browser()->window()->GetDownloadShelf()->Close(); 1048 browser()->window()->GetDownloadShelf()->Close();
1048 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); 1049 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
1049 1050
1050 // Go to the first tab. 1051 // Go to the first tab.
1051 browser()->ActivateTabAt(0, true); 1052 chrome::ActivateTabAt(browser(), 0, true);
1052 EXPECT_EQ(2, browser()->tab_count()); 1053 EXPECT_EQ(2, browser()->tab_count());
1053 1054
1054 // The download shelf should not be visible. 1055 // The download shelf should not be visible.
1055 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible()); 1056 EXPECT_FALSE(browser()->window()->IsDownloadShelfVisible());
1056 } 1057 }
1057 1058
1058 // Check whether the downloads shelf is closed when the downloads tab is 1059 // Check whether the downloads shelf is closed when the downloads tab is
1059 // invoked. 1060 // invoked.
1060 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseShelfOnDownloadsTab) { 1061 IN_PROC_BROWSER_TEST_F(DownloadTest, CloseShelfOnDownloadsTab) {
1061 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1062 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
1547 // after download of a file while viewing another chrome://. 1548 // after download of a file while viewing another chrome://.
1548 IN_PROC_BROWSER_TEST_F(DownloadTest, ChromeURLAfterDownload) { 1549 IN_PROC_BROWSER_TEST_F(DownloadTest, ChromeURLAfterDownload) {
1549 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1550 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1550 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); 1551 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file));
1551 GURL flags_url(chrome::kChromeUIFlagsURL); 1552 GURL flags_url(chrome::kChromeUIFlagsURL);
1552 GURL extensions_url(chrome::kChromeUIExtensionsFrameURL); 1553 GURL extensions_url(chrome::kChromeUIExtensionsFrameURL);
1553 1554
1554 ui_test_utils::NavigateToURL(browser(), flags_url); 1555 ui_test_utils::NavigateToURL(browser(), flags_url);
1555 DownloadAndWait(browser(), download_url, EXPECT_NO_SELECT_DIALOG); 1556 DownloadAndWait(browser(), download_url, EXPECT_NO_SELECT_DIALOG);
1556 ui_test_utils::NavigateToURL(browser(), extensions_url); 1557 ui_test_utils::NavigateToURL(browser(), extensions_url);
1557 WebContents* contents = browser()->GetActiveWebContents(); 1558 WebContents* contents = chrome::GetActiveWebContents(browser());
1558 ASSERT_TRUE(contents); 1559 ASSERT_TRUE(contents);
1559 bool webui_responded = false; 1560 bool webui_responded = false;
1560 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 1561 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
1561 contents->GetRenderViewHost(), 1562 contents->GetRenderViewHost(),
1562 L"", 1563 L"",
1563 L"window.domAutomationController.send(window.webui_responded_);", 1564 L"window.domAutomationController.send(window.webui_responded_);",
1564 &webui_responded)); 1565 &webui_responded));
1565 EXPECT_TRUE(webui_responded); 1566 EXPECT_TRUE(webui_responded);
1566 } 1567 }
1567 1568
1568 // Test for crbug.com/12745. This tests that if a download is initiated from 1569 // Test for crbug.com/12745. This tests that if a download is initiated from
1569 // a chrome:// page that has registered and onunload handler, the browser 1570 // a chrome:// page that has registered and onunload handler, the browser
1570 // will be able to close. 1571 // will be able to close.
1571 IN_PROC_BROWSER_TEST_F(DownloadTest, BrowserCloseAfterDownload) { 1572 IN_PROC_BROWSER_TEST_F(DownloadTest, BrowserCloseAfterDownload) {
1572 GURL downloads_url(chrome::kChromeUIFlagsURL); 1573 GURL downloads_url(chrome::kChromeUIFlagsURL);
1573 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1574 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1574 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); 1575 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file));
1575 1576
1576 ui_test_utils::NavigateToURL(browser(), downloads_url); 1577 ui_test_utils::NavigateToURL(browser(), downloads_url);
1577 WebContents* contents = browser()->GetActiveWebContents(); 1578 WebContents* contents = chrome::GetActiveWebContents(browser());
1578 ASSERT_TRUE(contents); 1579 ASSERT_TRUE(contents);
1579 bool result = false; 1580 bool result = false;
1580 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 1581 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
1581 contents->GetRenderViewHost(), 1582 contents->GetRenderViewHost(),
1582 L"", 1583 L"",
1583 L"window.onunload = function() { var do_nothing = 0; }; " 1584 L"window.onunload = function() { var do_nothing = 0; }; "
1584 L"window.domAutomationController.send(true);", 1585 L"window.domAutomationController.send(true);",
1585 &result)); 1586 &result));
1586 EXPECT_TRUE(result); 1587 EXPECT_TRUE(result);
1587 1588
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
1927 } 1928 }
1928 1929
1929 // Tests for download initiation functions. 1930 // Tests for download initiation functions.
1930 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrl) { 1931 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrl) {
1931 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1932 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1932 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1933 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1933 1934
1934 // DownloadUrl always prompts; return acceptance of whatever it prompts. 1935 // DownloadUrl always prompts; return acceptance of whatever it prompts.
1935 NullSelectFile(browser()); 1936 NullSelectFile(browser());
1936 1937
1937 WebContents* web_contents = browser()->GetActiveWebContents(); 1938 WebContents* web_contents = chrome::GetActiveWebContents(browser());
1938 ASSERT_TRUE(web_contents); 1939 ASSERT_TRUE(web_contents);
1939 1940
1940 DownloadTestObserver* observer( 1941 DownloadTestObserver* observer(
1941 new DownloadTestObserverTerminal( 1942 new DownloadTestObserverTerminal(
1942 DownloadManagerForBrowser(browser()), 1, 1943 DownloadManagerForBrowser(browser()), 1,
1943 false, // Ignore select file. 1944 false, // Ignore select file.
1944 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 1945 DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
1945 content::DownloadSaveInfo save_info; 1946 content::DownloadSaveInfo save_info;
1946 save_info.prompt_for_save_location = true; 1947 save_info.prompt_for_save_location = true;
1947 scoped_ptr<DownloadUrlParameters> params( 1948 scoped_ptr<DownloadUrlParameters> params(
1948 DownloadUrlParameters::FromWebContents(web_contents, url, save_info)); 1949 DownloadUrlParameters::FromWebContents(web_contents, url, save_info));
1949 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass()); 1950 DownloadManagerForBrowser(browser())->DownloadUrl(params.Pass());
1950 observer->WaitForFinished(); 1951 observer->WaitForFinished();
1951 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 1952 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE));
1952 CheckDownloadStates(1, DownloadItem::COMPLETE); 1953 CheckDownloadStates(1, DownloadItem::COMPLETE);
1953 EXPECT_TRUE(observer->select_file_dialog_seen()); 1954 EXPECT_TRUE(observer->select_file_dialog_seen());
1954 1955
1955 // Check state. 1956 // Check state.
1956 EXPECT_EQ(1, browser()->tab_count()); 1957 EXPECT_EQ(1, browser()->tab_count());
1957 ASSERT_TRUE(CheckDownload(browser(), file, file)); 1958 ASSERT_TRUE(CheckDownload(browser(), file, file));
1958 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 1959 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
1959 } 1960 }
1960 1961
1961 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) { 1962 IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadUrlToPath) {
1962 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1963 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1963 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 1964 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
1964 1965
1965 WebContents* web_contents = browser()->GetActiveWebContents(); 1966 WebContents* web_contents = chrome::GetActiveWebContents(browser());
1966 ASSERT_TRUE(web_contents); 1967 ASSERT_TRUE(web_contents);
1967 1968
1968 ScopedTempDir other_directory; 1969 ScopedTempDir other_directory;
1969 ASSERT_TRUE(other_directory.CreateUniqueTempDir()); 1970 ASSERT_TRUE(other_directory.CreateUniqueTempDir());
1970 FilePath target_file_full_path 1971 FilePath target_file_full_path
1971 = other_directory.path().Append(file.BaseName()); 1972 = other_directory.path().Append(file.BaseName());
1972 content::DownloadSaveInfo save_info; 1973 content::DownloadSaveInfo save_info;
1973 save_info.file_path = target_file_full_path; 1974 save_info.file_path = target_file_full_path;
1974 1975
1975 DownloadTestObserver* observer(CreateWaiter(browser(), 1)); 1976 DownloadTestObserver* observer(CreateWaiter(browser(), 1));
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
2025 2026
2026 // Try to download it via a context menu. 2027 // Try to download it via a context menu.
2027 scoped_ptr<DownloadTestObserver> waiter_context_menu( 2028 scoped_ptr<DownloadTestObserver> waiter_context_menu(
2028 new DownloadTestObserverTerminal( 2029 new DownloadTestObserverTerminal(
2029 DownloadManagerForBrowser(browser()), 1, 2030 DownloadManagerForBrowser(browser()), 1,
2030 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 2031 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
2031 content::ContextMenuParams context_menu_params; 2032 content::ContextMenuParams context_menu_params;
2032 context_menu_params.media_type = WebKit::WebContextMenuData::MediaTypeImage; 2033 context_menu_params.media_type = WebKit::WebContextMenuData::MediaTypeImage;
2033 context_menu_params.src_url = url; 2034 context_menu_params.src_url = url;
2034 context_menu_params.page_url = url; 2035 context_menu_params.page_url = url;
2035 TestRenderViewContextMenu menu(browser()->GetActiveWebContents(), 2036 TestRenderViewContextMenu menu(chrome::GetActiveWebContents(browser()),
2036 context_menu_params); 2037 context_menu_params);
2037 menu.Init(); 2038 menu.Init();
2038 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS); 2039 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_SAVEIMAGEAS);
2039 waiter_context_menu->WaitForFinished(); 2040 waiter_context_menu->WaitForFinished();
2040 EXPECT_EQ( 2041 EXPECT_EQ(
2041 1u, waiter_context_menu->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 2042 1u, waiter_context_menu->NumDownloadsSeenInState(DownloadItem::COMPLETE));
2042 CheckDownloadStates(2, DownloadItem::COMPLETE); 2043 CheckDownloadStates(2, DownloadItem::COMPLETE);
2043 2044
2044 // Validate that the correct file was downloaded via the context menu. 2045 // Validate that the correct file was downloaded via the context menu.
2045 download_items.clear(); 2046 download_items.clear();
(...skipping 16 matching lines...) Expand all
2062 GURL form_url = test_server()->GetURL( 2063 GURL form_url = test_server()->GetURL(
2063 "files/downloads/form_page_to_post.html"); 2064 "files/downloads/form_page_to_post.html");
2064 ASSERT_TRUE(form_url.is_valid()); 2065 ASSERT_TRUE(form_url.is_valid());
2065 ui_test_utils::NavigateToURL(browser(), form_url); 2066 ui_test_utils::NavigateToURL(browser(), form_url);
2066 2067
2067 // Submit the form. This will send a POST reqeuest, and the response is a 2068 // Submit the form. This will send a POST reqeuest, and the response is a
2068 // JPEG image. The resource also has Cache-Control: no-cache set, 2069 // JPEG image. The resource also has Cache-Control: no-cache set,
2069 // which normally requires revalidation each time. 2070 // which normally requires revalidation each time.
2070 GURL jpeg_url = test_server()->GetURL("files/post/downloads/image.jpg"); 2071 GURL jpeg_url = test_server()->GetURL("files/post/downloads/image.jpg");
2071 ASSERT_TRUE(jpeg_url.is_valid()); 2072 ASSERT_TRUE(jpeg_url.is_valid());
2072 WebContents* web_contents = browser()->GetActiveWebContents(); 2073 WebContents* web_contents = chrome::GetActiveWebContents(browser());
2073 ASSERT_TRUE(web_contents != NULL); 2074 ASSERT_TRUE(web_contents != NULL);
2074 ui_test_utils::WindowedNotificationObserver observer( 2075 ui_test_utils::WindowedNotificationObserver observer(
2075 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 2076 content::NOTIFICATION_NAV_ENTRY_COMMITTED,
2076 content::Source<content::NavigationController>( 2077 content::Source<content::NavigationController>(
2077 &web_contents->GetController())); 2078 &web_contents->GetController()));
2078 content::RenderViewHost* render_view_host = web_contents->GetRenderViewHost(); 2079 content::RenderViewHost* render_view_host = web_contents->GetRenderViewHost();
2079 ASSERT_TRUE(render_view_host != NULL); 2080 ASSERT_TRUE(render_view_host != NULL);
2080 render_view_host->ExecuteJavascriptInWebFrame( 2081 render_view_host->ExecuteJavascriptInWebFrame(
2081 string16(), ASCIIToUTF16("SubmitForm()")); 2082 string16(), ASCIIToUTF16("SubmitForm()"));
2082 observer.Wait(); 2083 observer.Wait();
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
2422 ASSERT_TRUE(url.is_valid()); 2423 ASSERT_TRUE(url.is_valid());
2423 ui_test_utils::NavigateToURL(browser(), url); 2424 ui_test_utils::NavigateToURL(browser(), url);
2424 2425
2425 scoped_ptr<DownloadTestObserver> waiter( 2426 scoped_ptr<DownloadTestObserver> waiter(
2426 new DownloadTestObserverTerminal( 2427 new DownloadTestObserverTerminal(
2427 DownloadManagerForBrowser(browser()), 1, 2428 DownloadManagerForBrowser(browser()), 1,
2428 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL)); 2429 false, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL));
2429 2430
2430 // Click on the link with the alt key pressed. This will download the link 2431 // Click on the link with the alt key pressed. This will download the link
2431 // target. 2432 // target.
2432 WebContents* tab = browser()->GetActiveWebContents(); 2433 WebContents* tab = chrome::GetActiveWebContents(browser());
2433 WebKit::WebMouseEvent mouse_event; 2434 WebKit::WebMouseEvent mouse_event;
2434 mouse_event.type = WebKit::WebInputEvent::MouseDown; 2435 mouse_event.type = WebKit::WebInputEvent::MouseDown;
2435 mouse_event.button = WebKit::WebMouseEvent::ButtonLeft; 2436 mouse_event.button = WebKit::WebMouseEvent::ButtonLeft;
2436 mouse_event.x = 15; 2437 mouse_event.x = 15;
2437 mouse_event.y = 15; 2438 mouse_event.y = 15;
2438 mouse_event.clickCount = 1; 2439 mouse_event.clickCount = 1;
2439 mouse_event.modifiers = WebKit::WebInputEvent::AltKey; 2440 mouse_event.modifiers = WebKit::WebInputEvent::AltKey;
2440 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); 2441 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event);
2441 mouse_event.type = WebKit::WebInputEvent::MouseUp; 2442 mouse_event.type = WebKit::WebInputEvent::MouseUp;
2442 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); 2443 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event);
2443 2444
2444 waiter->WaitForFinished(); 2445 waiter->WaitForFinished();
2445 EXPECT_EQ(1u, waiter->NumDownloadsSeenInState(DownloadItem::COMPLETE)); 2446 EXPECT_EQ(1u, waiter->NumDownloadsSeenInState(DownloadItem::COMPLETE));
2446 CheckDownloadStates(1, DownloadItem::COMPLETE); 2447 CheckDownloadStates(1, DownloadItem::COMPLETE);
2447 2448
2448 // Validate that the correct file was downloaded. 2449 // Validate that the correct file was downloaded.
2449 GetDownloads(browser(), &download_items); 2450 GetDownloads(browser(), &download_items);
2450 ASSERT_EQ(1u, download_items.size()); 2451 ASSERT_EQ(1u, download_items.size());
2451 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), 2452 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"),
2452 download_items[0]->GetOriginalUrl()); 2453 download_items[0]->GetOriginalUrl());
2453 2454
2454 // Check that the file contains the expected referrer. 2455 // Check that the file contains the expected referrer.
2455 FilePath file(download_items[0]->GetFullPath()); 2456 FilePath file(download_items[0]->GetFullPath());
2456 std::string expected_contents = test_server()->GetURL("").spec(); 2457 std::string expected_contents = test_server()->GetURL("").spec();
2457 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); 2458 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length()));
2458 } 2459 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698