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

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

Issue 10795090: Move ExecuteJavaScript functions from ui_test_utils.h to browser_test_utils.h so they can be reused… (Closed) Base URL: svn://chrome-svn/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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 #include "content/public/browser/download_manager.h" 53 #include "content/public/browser/download_manager.h"
54 #include "content/public/browser/download_persistent_store_info.h" 54 #include "content/public/browser/download_persistent_store_info.h"
55 #include "content/public/browser/download_save_info.h" 55 #include "content/public/browser/download_save_info.h"
56 #include "content/public/browser/download_url_parameters.h" 56 #include "content/public/browser/download_url_parameters.h"
57 #include "content/public/browser/notification_source.h" 57 #include "content/public/browser/notification_source.h"
58 #include "content/public/browser/render_view_host.h" 58 #include "content/public/browser/render_view_host.h"
59 #include "content/public/browser/resource_context.h" 59 #include "content/public/browser/resource_context.h"
60 #include "content/public/browser/web_contents.h" 60 #include "content/public/browser/web_contents.h"
61 #include "content/public/common/context_menu_params.h" 61 #include "content/public/common/context_menu_params.h"
62 #include "content/public/common/page_transition_types.h" 62 #include "content/public/common/page_transition_types.h"
63 #include "content/public/test/browser_test_utils.h"
63 #include "content/public/test/test_file_error_injector.h" 64 #include "content/public/test/test_file_error_injector.h"
64 #include "content/public/test/test_navigation_observer.h" 65 #include "content/public/test/test_navigation_observer.h"
65 #include "content/test/net/url_request_mock_http_job.h" 66 #include "content/test/net/url_request_mock_http_job.h"
66 #include "content/test/net/url_request_slow_download_job.h" 67 #include "content/test/net/url_request_slow_download_job.h"
67 #include "net/base/net_util.h" 68 #include "net/base/net_util.h"
68 #include "net/test/test_server.h" 69 #include "net/test/test_server.h"
69 #include "testing/gtest/include/gtest/gtest.h" 70 #include "testing/gtest/include/gtest/gtest.h"
70 71
71 using content::BrowserContext; 72 using content::BrowserContext;
72 using content::BrowserThread; 73 using content::BrowserThread;
(...skipping 946 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED); 1020 DownloadRequestLimiter::DOWNLOADS_NOT_ALLOWED);
1020 1021
1021 // Try to start the download via Javascript and wait for the corresponding 1022 // Try to start the download via Javascript and wait for the corresponding
1022 // load stop event. 1023 // load stop event.
1023 content::TestNavigationObserver observer( 1024 content::TestNavigationObserver observer(
1024 content::Source<content::NavigationController>( 1025 content::Source<content::NavigationController>(
1025 &web_contents->GetController()), 1026 &web_contents->GetController()),
1026 NULL, 1027 NULL,
1027 1); 1028 1);
1028 bool download_assempted; 1029 bool download_assempted;
1029 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 1030 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool(
1030 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), 1031 chrome::GetActiveWebContents(browser())->GetRenderViewHost(),
1031 L"", 1032 L"",
1032 L"window.domAutomationController.send(startDownload());", 1033 L"window.domAutomationController.send(startDownload());",
1033 &download_assempted)); 1034 &download_assempted));
1034 ASSERT_TRUE(download_assempted); 1035 ASSERT_TRUE(download_assempted);
1035 observer.WaitForObservation( 1036 observer.WaitForObservation(
1036 base::Bind(&ui_test_utils::RunMessageLoop), 1037 base::Bind(&ui_test_utils::RunMessageLoop),
1037 base::Bind(&MessageLoop::Quit, 1038 base::Bind(&MessageLoop::Quit,
1038 base::Unretained(MessageLoopForUI::current()))); 1039 base::Unretained(MessageLoopForUI::current())));
1039 1040
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
1600 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); 1601 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file));
1601 GURL flags_url(chrome::kChromeUIFlagsURL); 1602 GURL flags_url(chrome::kChromeUIFlagsURL);
1602 GURL extensions_url(chrome::kChromeUIExtensionsFrameURL); 1603 GURL extensions_url(chrome::kChromeUIExtensionsFrameURL);
1603 1604
1604 ui_test_utils::NavigateToURL(browser(), flags_url); 1605 ui_test_utils::NavigateToURL(browser(), flags_url);
1605 DownloadAndWait(browser(), download_url, EXPECT_NO_SELECT_DIALOG); 1606 DownloadAndWait(browser(), download_url, EXPECT_NO_SELECT_DIALOG);
1606 ui_test_utils::NavigateToURL(browser(), extensions_url); 1607 ui_test_utils::NavigateToURL(browser(), extensions_url);
1607 WebContents* contents = chrome::GetActiveWebContents(browser()); 1608 WebContents* contents = chrome::GetActiveWebContents(browser());
1608 ASSERT_TRUE(contents); 1609 ASSERT_TRUE(contents);
1609 bool webui_responded = false; 1610 bool webui_responded = false;
1610 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 1611 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool(
1611 contents->GetRenderViewHost(), 1612 contents->GetRenderViewHost(),
1612 L"", 1613 L"",
1613 L"window.domAutomationController.send(window.webui_responded_);", 1614 L"window.domAutomationController.send(window.webui_responded_);",
1614 &webui_responded)); 1615 &webui_responded));
1615 EXPECT_TRUE(webui_responded); 1616 EXPECT_TRUE(webui_responded);
1616 } 1617 }
1617 1618
1618 // Test for crbug.com/12745. This tests that if a download is initiated from 1619 // Test for crbug.com/12745. This tests that if a download is initiated from
1619 // a chrome:// page that has registered and onunload handler, the browser 1620 // a chrome:// page that has registered and onunload handler, the browser
1620 // will be able to close. 1621 // will be able to close.
1621 IN_PROC_BROWSER_TEST_F(DownloadTest, BrowserCloseAfterDownload) { 1622 IN_PROC_BROWSER_TEST_F(DownloadTest, BrowserCloseAfterDownload) {
1622 GURL downloads_url(chrome::kChromeUIFlagsURL); 1623 GURL downloads_url(chrome::kChromeUIFlagsURL);
1623 FilePath file(FILE_PATH_LITERAL("download-test1.lib")); 1624 FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
1624 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file)); 1625 GURL download_url(URLRequestMockHTTPJob::GetMockUrl(file));
1625 1626
1626 ui_test_utils::NavigateToURL(browser(), downloads_url); 1627 ui_test_utils::NavigateToURL(browser(), downloads_url);
1627 WebContents* contents = chrome::GetActiveWebContents(browser()); 1628 WebContents* contents = chrome::GetActiveWebContents(browser());
1628 ASSERT_TRUE(contents); 1629 ASSERT_TRUE(contents);
1629 bool result = false; 1630 bool result = false;
1630 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 1631 EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool(
1631 contents->GetRenderViewHost(), 1632 contents->GetRenderViewHost(),
1632 L"", 1633 L"",
1633 L"window.onunload = function() { var do_nothing = 0; }; " 1634 L"window.onunload = function() { var do_nothing = 0; }; "
1634 L"window.domAutomationController.send(true);", 1635 L"window.domAutomationController.send(true);",
1635 &result)); 1636 &result));
1636 EXPECT_TRUE(result); 1637 EXPECT_TRUE(result);
1637 1638
1638 DownloadAndWait(browser(), download_url, EXPECT_NO_SELECT_DIALOG); 1639 DownloadAndWait(browser(), download_url, EXPECT_NO_SELECT_DIALOG);
1639 1640
1640 content::WindowedNotificationObserver signal( 1641 content::WindowedNotificationObserver signal(
(...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after
2496 GetDownloads(browser(), &download_items); 2497 GetDownloads(browser(), &download_items);
2497 ASSERT_EQ(1u, download_items.size()); 2498 ASSERT_EQ(1u, download_items.size());
2498 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"), 2499 ASSERT_EQ(test_server()->GetURL("echoheader?Referer"),
2499 download_items[0]->GetOriginalUrl()); 2500 download_items[0]->GetOriginalUrl());
2500 2501
2501 // Check that the file contains the expected referrer. 2502 // Check that the file contains the expected referrer.
2502 FilePath file(download_items[0]->GetFullPath()); 2503 FilePath file(download_items[0]->GetFullPath());
2503 std::string expected_contents = test_server()->GetURL("").spec(); 2504 std::string expected_contents = test_server()->GetURL("").spec();
2504 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length())); 2505 ASSERT_TRUE(VerifyFile(file, expected_contents, expected_contents.length()));
2505 } 2506 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698