diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-30 17:26:30 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-30 17:26:30 +0000 |
commit | 854e131abba37f4c5350888942c577614424f524 (patch) | |
tree | 953703d1ddf9dcca9c547fc619b73603d026c25b | |
parent | 3dfa4c08bd73745edd13e38b9d832eac0dabd925 (diff) | |
download | chromium_src-854e131abba37f4c5350888942c577614424f524.zip chromium_src-854e131abba37f4c5350888942c577614424f524.tar.gz chromium_src-854e131abba37f4c5350888942c577614424f524.tar.bz2 |
Move resource_dispatcher_host_browsertest.cc to content_browsertests.
BUG=90448
Review URL: https://chromiumcodereview.appspot.com/10829070
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148966 0039d316-1c4b-4281-b951-d872f2087c98
30 files changed, 91 insertions, 420 deletions
diff --git a/chrome/browser_tests.isolate b/chrome/browser_tests.isolate index 744310e..e0ae5c8 100644 --- a/chrome/browser_tests.isolate +++ b/chrome/browser_tests.isolate @@ -79,14 +79,6 @@ ], 'isolate_dependency_touched': [ '../third_party/pyftpdlib/src/pyftpdlib/__init__.py', - 'test/data/content-disposition-empty.html', - 'test/data/content-disposition-inline.html', - 'test/data/content-sniffer-test0.html', - 'test/data/content-sniffer-test1.html', - 'test/data/content-sniffer-test2.html', - 'test/data/content-sniffer-test3-frame.txt', - 'test/data/content-sniffer-test3.html', - 'test/data/nosniff-test.html', 'test/data/title2.html', ], }, @@ -333,26 +325,11 @@ 'test/data/autofill/heuristics/output/20_register_epson.com.mx.out', 'test/data/beforeunload.html', 'test/data/cancelled_redirect_test.html', - 'test/data/content-disposition-empty.html', - 'test/data/content-disposition-empty.html.mock-http-headers', - 'test/data/content-disposition-inline.html', - 'test/data/content-disposition-inline.html.mock-http-headers', - 'test/data/content-sniffer-test0.html', - 'test/data/content-sniffer-test0.html.mock-http-headers', - 'test/data/content-sniffer-test1.html', - 'test/data/content-sniffer-test1.html.mock-http-headers', - 'test/data/content-sniffer-test2.html', - 'test/data/content-sniffer-test2.html.mock-http-headers', - 'test/data/content-sniffer-test3-frame.txt.mock-http-headers', - 'test/data/content-sniffer-test3.html', - 'test/data/content-sniffer-test3.html.mock-http-headers', 'test/data/cookie1.html', 'test/data/custom_handler_foo.html', 'test/data/download-test2.html', 'test/data/download-test2.html.mock-http-headers', 'test/data/download-test3.gif', - 'test/data/dynamic1.html', - 'test/data/dynamic2.html', 'test/data/empty.html', 'test/data/english_page.html', 'test/data/extensions/api_test/app_process/manifest.json', @@ -542,8 +519,6 @@ 'test/data/iframe_in_empty_frame.js', 'test/data/is_search_provider_installed.html', 'test/data/is_search_provider_installed_with_exception.html', - 'test/data/nosniff-test.html', - 'test/data/nosniff-test.html.mock-http-headers', 'test/data/notifications/notifications_request_function.html', 'test/data/notifications/notifications_request_inline.html', 'test/data/page_cycler/animate2.gif', @@ -641,8 +616,6 @@ 'test/data/ssl/unsafe_worker.js', 'test/data/ssl/wss_close.html', 'test/data/ssl/wss_close_slave.html', - 'test/data/sync_xmlhttprequest_disallowed.html', - 'test/data/sync_xmlhttprequest_during_unload.html', 'test/data/title1.html', 'test/data/title3.html', 'test/data/webui/async.js', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index bae35e2..8158757 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -3007,7 +3007,6 @@ # TODO(craig): Rename this and run from base_unittests when the test # is safe to run there. See http://crbug.com/78722 for details. '../base/files/file_path_watcher_browsertest.cc', - '../content/browser/renderer_host/resource_dispatcher_host_browsertest.cc', ], 'rules': [ { diff --git a/chrome/test/data/content-disposition-empty.html b/chrome/test/data/content-disposition-empty.html deleted file mode 100644 index 7dd9c0f..0000000 --- a/chrome/test/data/content-disposition-empty.html +++ /dev/null @@ -1,4 +0,0 @@ -<html> -<head><title>success</title></head> -<body>this page should be displayed instead of downloaded</body> -</html> diff --git a/chrome/test/data/content-disposition-empty.html.mock-http-headers b/chrome/test/data/content-disposition-empty.html.mock-http-headers deleted file mode 100644 index 1d114d5..0000000 --- a/chrome/test/data/content-disposition-empty.html.mock-http-headers +++ /dev/null @@ -1,6 +0,0 @@ -HTTP/1.1 200 OK -Content-Type: text/html -Content-Length: 116 -Content-Disposition: filename="foo.html" -Date: Mon, 13 Nov 2006 21:38:09 GMT -Expires: Tue, 14 Nov 2006 19:23:58 GMT diff --git a/chrome/test/data/content-disposition-inline.html b/chrome/test/data/content-disposition-inline.html deleted file mode 100644 index 7dd9c0f..0000000 --- a/chrome/test/data/content-disposition-inline.html +++ /dev/null @@ -1,4 +0,0 @@ -<html> -<head><title>success</title></head> -<body>this page should be displayed instead of downloaded</body> -</html> diff --git a/chrome/test/data/content-disposition-inline.html.mock-http-headers b/chrome/test/data/content-disposition-inline.html.mock-http-headers deleted file mode 100644 index 6846a51..0000000 --- a/chrome/test/data/content-disposition-inline.html.mock-http-headers +++ /dev/null @@ -1,6 +0,0 @@ -HTTP/1.1 200 OK -Content-Type: text/html -Content-Length: 116 -Content-Disposition: inline; filename="foo.html" -Date: Mon, 13 Nov 2006 21:38:09 GMT -Expires: Tue, 14 Nov 2006 19:23:58 GMT diff --git a/chrome/test/data/content-sniffer-test0.html b/chrome/test/data/content-sniffer-test0.html deleted file mode 100644 index 597a51b..0000000 --- a/chrome/test/data/content-sniffer-test0.html +++ /dev/null @@ -1,4 +0,0 @@ -<html> -<head><title>Content Sniffer Test 0</title></head> -<body>We should sniff this content as HTML.</body> -</html> diff --git a/chrome/test/data/content-sniffer-test0.html.mock-http-headers b/chrome/test/data/content-sniffer-test0.html.mock-http-headers deleted file mode 100644 index 47a3b3c..0000000 --- a/chrome/test/data/content-sniffer-test0.html.mock-http-headers +++ /dev/null @@ -1,2 +0,0 @@ -HTTP/1.1 200 OK -Content-Length: 121 diff --git a/chrome/test/data/content-sniffer-test1.html b/chrome/test/data/content-sniffer-test1.html deleted file mode 100644 index c3bfc9b..0000000 --- a/chrome/test/data/content-sniffer-test1.html +++ /dev/null @@ -1,4 +0,0 @@ -<html> -<head><title>Content Sniffer Test 1</title></head> -<body>We should not sniff this content as HTML.</body> -</html> diff --git a/chrome/test/data/content-sniffer-test1.html.mock-http-headers b/chrome/test/data/content-sniffer-test1.html.mock-http-headers deleted file mode 100644 index 2aa3579..0000000 --- a/chrome/test/data/content-sniffer-test1.html.mock-http-headers +++ /dev/null @@ -1,3 +0,0 @@ -HTTP/1.1 200 OK -Content-Type: text/plain; charset=utf-8 -Content-Length: 125 diff --git a/chrome/test/data/content-sniffer-test2.html b/chrome/test/data/content-sniffer-test2.html deleted file mode 100644 index c4b99f8..0000000 --- a/chrome/test/data/content-sniffer-test2.html +++ /dev/null @@ -1,4 +0,0 @@ -<html> -<head><title>Content Sniffer Test 2</title></head> -<body>We should not sniff this as HTML as server says its a GIF.</body> -</html> diff --git a/chrome/test/data/content-sniffer-test2.html.mock-http-headers b/chrome/test/data/content-sniffer-test2.html.mock-http-headers deleted file mode 100644 index 5c28dff..0000000 --- a/chrome/test/data/content-sniffer-test2.html.mock-http-headers +++ /dev/null @@ -1,3 +0,0 @@ -HTTP/1.1 200 OK -Content-Type: image/gif -Content-Length: 142 diff --git a/chrome/test/data/content-sniffer-test3-frame.txt b/chrome/test/data/content-sniffer-test3-frame.txt deleted file mode 100644 index e69de29..0000000 --- a/chrome/test/data/content-sniffer-test3-frame.txt +++ /dev/null diff --git a/chrome/test/data/content-sniffer-test3-frame.txt.mock-http-headers b/chrome/test/data/content-sniffer-test3-frame.txt.mock-http-headers deleted file mode 100644 index 194bc62..0000000 --- a/chrome/test/data/content-sniffer-test3-frame.txt.mock-http-headers +++ /dev/null @@ -1,2 +0,0 @@ -HTTP/1.1 200 OK -Content-Length: 0 diff --git a/chrome/test/data/content-sniffer-test3.html b/chrome/test/data/content-sniffer-test3.html deleted file mode 100644 index becc181..0000000 --- a/chrome/test/data/content-sniffer-test3.html +++ /dev/null @@ -1,16 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> -<html> -<head> -<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"> -<title>Content Sniffer Test 3</title> -</head> -<body> -<script id="sc"> -var iframe = document.createElement('iframe'); -iframe.frameBorder = iframe.width = iframe.height = 0; -iframe.src = "http://mock.http/content-sniffer-test3-frame.txt"; -document.body.appendChild(iframe); -</script> -<pre>Do NOT download!!</pre> -</body> -</html> diff --git a/chrome/test/data/content-sniffer-test3.html.mock-http-headers b/chrome/test/data/content-sniffer-test3.html.mock-http-headers deleted file mode 100644 index 9dd16d4..0000000 --- a/chrome/test/data/content-sniffer-test3.html.mock-http-headers +++ /dev/null @@ -1,3 +0,0 @@ -HTTP/1.1 200 OK -Content-Length: 472 -Content-Type: text/html diff --git a/chrome/test/data/cross-origin-redirect-blocked.html b/chrome/test/data/cross-origin-redirect-blocked.html deleted file mode 100644 index d0e8ee9..0000000 --- a/chrome/test/data/cross-origin-redirect-blocked.html +++ /dev/null @@ -1,56 +0,0 @@ -<html> -<head> - <title></title> -</head> -<body> -<script> - -function NewXHR(url) { - var r = new XMLHttpRequest - r.open("GET", url); - return r; -} - -function SignalSuccess() { - document.location = "title3.html"; -} - -function SignalFailure() { - document.location = "title1.html"; -} - -function CreateDummyRequest() { - dummy_request = NewXHR("http://mock.http/title2.html"); - dummy_request.onload = SignalSuccess; - dummy_request.send(null); -} - -function RedirectFailed() { - // Good, the redirect was blocked by WebKit. - // - // We also care that the underlying network stack does not send the redirect. - // We cannot detect that from JS, but our test harness is designed to detect - // that (see ResourceDispatcherTest::CrossOriginRedirectBlocked). Before - // calling SignalSuccess, we want to allow the browser time to notice a request - // to follow the redirect if one should exist. To do that, we just need to - // make another network request. - // - // The setTimeout call is intended to delay CreateDummyRequest so that any - // processing associated with the current "error" handler completes. - setTimeout(CreateDummyRequest, 0); -} - -function RedirectSucceeded() { - // Oops, the redirect should have been denied! - SignalFailure(); -} - -// Kick off a request that will attempt a cross-origin redirect. -request = NewXHR("http://mock.http/redirect-to-title2.html"); -request.onerror = RedirectFailed; -request.onload = RedirectSucceeded; -request.send(null); - -</script> -</body> -</html> diff --git a/chrome/test/data/dynamic1.html b/chrome/test/data/dynamic1.html deleted file mode 100644 index 07ff336..0000000 --- a/chrome/test/data/dynamic1.html +++ /dev/null @@ -1,27 +0,0 @@ -<html> -<head> -<title>Test Title</title> -<script type="text/javascript"> -function OpenPopup() { - // Create a new popup window - var oWnd = window.open('','MyPopupName','width=350,height=300',false); - - // Dynamically generate the HTML content for popup window - var sHtml = - '<html>' - + '<head><title>My Popup Title</title></head>' - + '<body></body>' - + '</html>'; - - // Push the HTML into that window - oWnd.document.write(sHtml); - - // Finish - oWnd.document.close(); -} -</script> -</head> -<body> - <p>This is dynamic1.html</p> -</body> -</html> diff --git a/chrome/test/data/dynamic2.html b/chrome/test/data/dynamic2.html deleted file mode 100644 index 297c534..0000000 --- a/chrome/test/data/dynamic2.html +++ /dev/null @@ -1,31 +0,0 @@ -<html> -<head> -<title>Test Title</title> -<script type="text/javascript"> -function OpenPopup() { - // Create a new popup window - var oWnd = window.open('','MyPopupName','width=350,height=300',false); - - // Dynamically generate the HTML content for popup window - var sHtml = - '<html>' - + '<head><title>My Popup Title</title></head>' - + '<body>' - + '<script type="text/javascript">' - + 'document.title="My Dynamic Title";' - + '<\/script>' - + '</body>' - + '</html>'; - - // Push the HTML into that window - oWnd.document.write(sHtml); - - // Finish - oWnd.document.close(); -} -</script> -</head> -<body> - <p>This is dynamic2.html</p> -</body> -</html> diff --git a/chrome/test/data/nosniff-test.html b/chrome/test/data/nosniff-test.html deleted file mode 100644 index a7ab8ba..0000000 --- a/chrome/test/data/nosniff-test.html +++ /dev/null @@ -1,4 +0,0 @@ -<html> -<head><title>nosniff Test</title></head> -<body>We should NOT sniff this content as HTML.</body> -</html> diff --git a/chrome/test/data/nosniff-test.html.mock-http-headers b/chrome/test/data/nosniff-test.html.mock-http-headers deleted file mode 100644 index 78ff33d..0000000 --- a/chrome/test/data/nosniff-test.html.mock-http-headers +++ /dev/null @@ -1,3 +0,0 @@ -HTTP/1.1 200 OK -Content-Length: 111 -X-Content-Type-Options: nosniff diff --git a/chrome/test/data/onunload_cookie.html b/chrome/test/data/onunload_cookie.html deleted file mode 100644 index 0a7de8d..0000000 --- a/chrome/test/data/onunload_cookie.html +++ /dev/null @@ -1,18 +0,0 @@ -<html> - <head> - <title>Loading...</title> - </head> - <body onload="attachUnloadListener()"> - <script> - function attachUnloadListener() { - window.addEventListener('unload', onUnload, false); - document.title = "set cookie on unload"; - } - - function onUnload() { - document.cookie = "onunloadCookie=foo"; - } - </script> - <p>Navigate to another page to set cookie</p> - </body> -</html> diff --git a/chrome/test/data/sync_xmlhttprequest.html b/chrome/test/data/sync_xmlhttprequest.html deleted file mode 100644 index cf3e8d6..0000000 --- a/chrome/test/data/sync_xmlhttprequest.html +++ /dev/null @@ -1,32 +0,0 @@ -<html> -<head> -<script> -var request_success = false; - -function OnLoad() { - var request = new XMLHttpRequest(); - request.open("GET", "title1.html", false); - request.send(""); - - var my_div = document.getElementById("my_div"); - if (request.readyState == 4 && request.status == 200) { - request_success = true; - my_div.innerHTML = "Got a successful response: " + request.responseText; - } else { - my_div.innerHTML = "Request failed: ready state=" + request.readyState + - " status=" + request.status; - } -} - -function DidSyncRequestSucceed() { - return request_success; -} - -</script> -</head> -<body onload="OnLoad();"> -This page sends a synchronous XMLHttpRequest. -<br><br> -<div id="my_div"></div> -</body> -</html> diff --git a/chrome/test/data/sync_xmlhttprequest_disallowed.html b/chrome/test/data/sync_xmlhttprequest_disallowed.html deleted file mode 100644 index 130533f..0000000 --- a/chrome/test/data/sync_xmlhttprequest_disallowed.html +++ /dev/null @@ -1,29 +0,0 @@ -<html> -<head> -<script> -var success = false; - -function OnLoad() { - try { - var request = new XMLHttpRequest(); - request.open("GET", "file:///c:/foo.txt", false); - request.send(null); - } catch (e) { - success = true; - } - document.getElementById("console").appendChild( - document.createTextNode(success ? "SUCCESS" : "FAILURE")); -} - -function DidSucceed() { - return success; -} - -</script> -</head> -<body onload="OnLoad();"> -This page sends a synchronous XMLHttpRequest to fetch a local file, which -should not be allowed. -<div id="console"></div> -</body> -</html> diff --git a/chrome/test/data/sync_xmlhttprequest_during_unload.html b/chrome/test/data/sync_xmlhttprequest_during_unload.html deleted file mode 100644 index 6b726b1..0000000 --- a/chrome/test/data/sync_xmlhttprequest_during_unload.html +++ /dev/null @@ -1,20 +0,0 @@ -<html> - <head> - <title>Loading...</title> - </head> - <body onload="attachUnloadListener()"> - <script> - function attachUnloadListener() { - window.addEventListener('unload', onUnload, false); - document.title = "sync xhr on unload"; - } - - var req = new XMLHttpRequest(); - function onUnload() { - req.open('GET','download-test1.lib', false); - req.send(null); - } - </script> - <p>Navigate to another page to trigger synch xmlhttprequest</p> - </body> -</html> diff --git a/chrome/test/perf/shutdown_test.cc b/chrome/test/perf/shutdown_test.cc index 5a61fa1..43f5f85 100644 --- a/chrome/test/perf/shutdown_test.cc +++ b/chrome/test/perf/shutdown_test.cc @@ -53,7 +53,7 @@ class ShutdownTest : public UIPerfTest { ui_test_utils::GetTestFilePath(kCurrentDir, FilePath(FILE_PATH_LITERAL("french_page.html"))), ui_test_utils::GetTestFilePath(kCurrentDir, - FilePath(FILE_PATH_LITERAL("onunload_cookie.html"))), + FilePath(FILE_PATH_LITERAL("setcookie.html"))), }; for (size_t i = 0; i < arraysize(test_cases); i++) { diff --git a/content/browser/renderer_host/resource_dispatcher_host_browsertest.cc b/content/browser/renderer_host/resource_dispatcher_host_browsertest.cc index b095499..88070a0 100644 --- a/content/browser/renderer_host/resource_dispatcher_host_browsertest.cc +++ b/content/browser/renderer_host/resource_dispatcher_host_browsertest.cc @@ -5,10 +5,6 @@ #include "base/string_util.h" #include "base/synchronization/waitable_event.h" #include "base/utf_string_conversions.h" -#include "chrome/browser/ui/browser.h" -#include "chrome/browser/ui/browser_tabstrip.h" -#include "chrome/test/base/in_process_browser_test.h" -#include "chrome/test/base/ui_test_utils.h" #include "content/browser/download/download_manager_impl.h" #include "content/browser/web_contents/web_contents_impl.h" #include "content/common/test_url_constants.h" @@ -19,6 +15,10 @@ #include "content/public/browser/web_contents.h" #include "content/public/common/url_constants.h" #include "content/public/test/browser_test_utils.h" +#include "content/public/test/test_utils.h" +#include "content/shell/shell.h" +#include "content/test/content_browser_test.h" +#include "content/test/content_browser_test_utils.h" #include "content/test/net/url_request_failed_job.h" #include "content/test/net/url_request_mock_http_job.h" #include "net/base/net_errors.h" @@ -27,9 +27,7 @@ #include "net/url_request/url_request_context.h" #include "net/url_request/url_request_context_getter.h" -using content::BrowserContext; -using content::BrowserThread; -using content::DownloadManager; +namespace content { namespace { @@ -54,14 +52,14 @@ void GetCookiesOnIOThread(const GURL& url, } // namespace -class ResourceDispatcherHostBrowserTest : public InProcessBrowserTest, +class ResourceDispatcherHostBrowserTest : public ContentBrowserTest, public DownloadManager::Observer { public: ResourceDispatcherHostBrowserTest() : got_downloads_(false) {} protected: virtual void SetUpOnMainThread() OVERRIDE { - FilePath path = ui_test_utils::GetTestFilePath(FilePath(), FilePath()); + FilePath path = GetTestFilePath("", ""); BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, base::Bind(&URLRequestMockHTTPJob::AddUrlHandler, path)); @@ -75,8 +73,8 @@ class ResourceDispatcherHostBrowserTest : public InProcessBrowserTest, got_downloads_ = !!manager->InProgressCount(); } - content::RenderViewHost* render_view_host() { - return chrome::GetActiveWebContents(browser())->GetRenderViewHost(); + RenderViewHost* render_view_host() { + return shell()->web_contents()->GetRenderViewHost(); } GURL GetMockURL(const std::string& file) { @@ -84,23 +82,32 @@ class ResourceDispatcherHostBrowserTest : public InProcessBrowserTest, } void CheckTitleTest(const GURL& url, - const std::string& expected_title, - int expected_navigations) { + const std::string& expected_title) { string16 expected_title16(ASCIIToUTF16(expected_title)); - content::TitleWatcher title_watcher( - chrome::GetActiveWebContents(browser()), expected_title16); - ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( - browser(), url, expected_navigations); + TitleWatcher title_watcher(shell()->web_contents(), expected_title16); + NavigateToURL(shell(), url); EXPECT_EQ(expected_title16, title_watcher.WaitAndGetTitle()); } - bool GetPopupTitle(const GURL& url, string16* title); + bool GetPopupTitle(const GURL& url, string16* title) { + NavigateToURL(shell(), url); + + ShellAddedObserver new_shell_observer; + + // Create dynamic popup. + if (!ExecuteJavaScript(render_view_host(), L"", L"OpenPopup();")) + return false; + + Shell* new_shell = new_shell_observer.GetShell(); + *title = new_shell->web_contents()->GetTitle(); + return true; + } std::string GetCookies(const GURL& url) { std::string cookies; base::WaitableEvent event(true, false); net::URLRequestContextGetter* context_getter = - GetBrowserContext()->GetRequestContext(); + shell()->web_contents()->GetBrowserContext()->GetRequestContext(); BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, @@ -116,29 +123,6 @@ class ResourceDispatcherHostBrowserTest : public InProcessBrowserTest, bool got_downloads_; }; -bool ResourceDispatcherHostBrowserTest::GetPopupTitle(const GURL& url, - string16* title) { - ui_test_utils::NavigateToURL(browser(), url); - - ui_test_utils::WindowedTabAddedNotificationObserver observer( - content::NotificationService::AllSources()); - - // Create dynamic popup. - if (!content::ExecuteJavaScript(render_view_host(), L"", L"OpenPopup();")) - return false; - - observer.Wait(); - - std::set<Browser*> excluded; - excluded.insert(browser()); - Browser* popup = ui_test_utils::GetBrowserNotInSet(excluded); - if (!popup) - return false; - - *title = popup->GetWindowTitleForCurrentTab(); - return true; -} - // Test title for content created by javascript window.open(). // See http://crbug.com/5988 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, DynamicTitle1) { @@ -166,57 +150,58 @@ IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, DynamicTitle2) { IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, SniffHTMLWithNoContentType) { CheckTitleTest(GetMockURL("content-sniffer-test0.html"), - "Content Sniffer Test 0", 1); + "Content Sniffer Test 0"); } IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, RespectNoSniffDirective) { CheckTitleTest(GetMockURL("nosniff-test.html"), - "mock.http/nosniff-test.html", 1); + "mock.http/nosniff-test.html"); } IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, DoNotSniffHTMLFromTextPlain) { CheckTitleTest(GetMockURL("content-sniffer-test1.html"), - "mock.http/content-sniffer-test1.html", 1); + "mock.http/content-sniffer-test1.html"); } IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, DoNotSniffHTMLFromImageGIF) { CheckTitleTest(GetMockURL("content-sniffer-test2.html"), - "mock.http/content-sniffer-test2.html", 1); + "mock.http/content-sniffer-test2.html"); } IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, SniffNoContentTypeNoData) { // Make sure no downloads start. - BrowserContext::GetDownloadManager(GetBrowserContext())->AddObserver(this); + BrowserContext::GetDownloadManager( + shell()->web_contents()->GetBrowserContext())->AddObserver(this); CheckTitleTest(GetMockURL("content-sniffer-test3.html"), - "Content Sniffer Test 3", 1); - EXPECT_EQ(1, browser()->tab_count()); + "Content Sniffer Test 3"); + EXPECT_EQ(1u, Shell::windows().size()); ASSERT_FALSE(got_downloads()); } IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, ContentDispositionEmpty) { - CheckTitleTest(GetMockURL("content-disposition-empty.html"), "success", 1); + CheckTitleTest(GetMockURL("content-disposition-empty.html"), "success"); } IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, ContentDispositionInline) { - CheckTitleTest(GetMockURL("content-disposition-inline.html"), "success", 1); + CheckTitleTest(GetMockURL("content-disposition-inline.html"), "success"); } // Test for bug #1091358. IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, SyncXMLHttpRequest) { ASSERT_TRUE(test_server()->Start()); - ui_test_utils::NavigateToURL( - browser(), test_server()->GetURL("files/sync_xmlhttprequest.html")); + NavigateToURL( + shell(), test_server()->GetURL("files/sync_xmlhttprequest.html")); // Let's check the XMLHttpRequest ran successfully. bool success = false; - EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( - chrome::GetActiveWebContents(browser())->GetRenderViewHost(), + EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( + shell()->web_contents()->GetRenderViewHost(), L"", L"window.domAutomationController.send(DidSyncRequestSucceed());", &success)); @@ -227,14 +212,14 @@ IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, SyncXMLHttpRequest) { IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, SyncXMLHttpRequest_Disallowed) { ASSERT_TRUE(test_server()->Start()); - ui_test_utils::NavigateToURL( - browser(), + NavigateToURL( + shell(), test_server()->GetURL("files/sync_xmlhttprequest_disallowed.html")); // Let's check the XMLHttpRequest ran successfully. bool success = false; - EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( - chrome::GetActiveWebContents(browser())->GetRenderViewHost(), + EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( + shell()->web_contents()->GetRenderViewHost(), L"", L"window.domAutomationController.send(DidSucceed());", &success)); @@ -248,17 +233,17 @@ IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, SyncXMLHttpRequest_DuringUnload) { ASSERT_TRUE(test_server()->Start()); - BrowserContext::GetDownloadManager(GetBrowserContext())->AddObserver(this); + BrowserContext::GetDownloadManager( + shell()->web_contents()->GetBrowserContext())->AddObserver(this); CheckTitleTest( test_server()->GetURL("files/sync_xmlhttprequest_during_unload.html"), - "sync xhr on unload", 1); + "sync xhr on unload"); // Navigate to a new page, to dispatch unload event and trigger xhr. // (the bug would make this step hang the renderer). CheckTitleTest( - test_server()->GetURL("files/title2.html"), - "Title Of Awesomeness", 1); + test_server()->GetURL("files/title2.html"), "Title Of Awesomeness"); ASSERT_FALSE(got_downloads()); } @@ -269,39 +254,30 @@ IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, ASSERT_TRUE(test_server()->Start()); GURL url = test_server()->GetURL("files/onunload_cookie.html"); - CheckTitleTest(url, "set cookie on unload", 1); + CheckTitleTest(url, "set cookie on unload"); // Navigate to a new cross-site page, to dispatch unload event and set the // cookie. CheckTitleTest(GetMockURL("content-sniffer-test0.html"), - "Content Sniffer Test 0", 1); + "Content Sniffer Test 0"); // Check that the cookie was set. EXPECT_EQ("onunloadCookie=foo", GetCookies(url)); } -// ResourceDispatcherHostBrowserTest.CrossSiteImmediateLoadOnunloadCookie is -// flaky on Windows. http://crbug.com/130404 -#if defined (OS_WIN) -#define MAYBE_CrossSiteImmediateLoadOnunloadCookie \ - DISABLED_CrossSiteImmediateLoadOnunloadCookie -#else -#define MAYBE_CrossSiteImmediateLoadOnunloadCookie \ - CrossSiteImmediateLoadOnunloadCookie -#endif - +// If this flakes, use http://crbug.com/130404 // Tests that onunload is run for cross-site requests to URLs that complete // without network loads (e.g., about:blank, data URLs). IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, - MAYBE_CrossSiteImmediateLoadOnunloadCookie) { + CrossSiteImmediateLoadOnunloadCookie) { ASSERT_TRUE(test_server()->Start()); GURL url = test_server()->GetURL("files/onunload_cookie.html"); - CheckTitleTest(url, "set cookie on unload", 1); + CheckTitleTest(url, "set cookie on unload"); // Navigate to a cross-site page that loads immediately without making a // network request. The unload event should still be run. - ui_test_utils::NavigateToURL(browser(), GURL("about:blank")); + NavigateToURL(shell(), GURL("about:blank")); // Check that the cookie was set. EXPECT_EQ("onunloadCookie=foo", GetCookies(url)); @@ -315,10 +291,10 @@ IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, // Start with a URL that sets a cookie in its unload handler. GURL url = test_server()->GetURL("files/onunload_cookie.html"); - CheckTitleTest(url, "set cookie on unload", 1); + CheckTitleTest(url, "set cookie on unload"); // Navigate to a cross-site URL that returns a 204 No Content response. - ui_test_utils::NavigateToURL(browser(), test_server()->GetURL("nocontent")); + NavigateToURL(shell(), test_server()->GetURL("nocontent")); // Check that the unload cookie was not set. EXPECT_EQ("", GetCookies(url)); @@ -335,17 +311,17 @@ IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, // strip the app on the build bots, this is bad times. IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, CrossSiteAfterCrash) { // Cause the renderer to crash. - content::WindowedNotificationObserver crash_observer( - content::NOTIFICATION_RENDERER_PROCESS_CLOSED, - content::NotificationService::AllSources()); - ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUICrashURL)); + WindowedNotificationObserver crash_observer( + NOTIFICATION_RENDERER_PROCESS_CLOSED, + NotificationService::AllSources()); + NavigateToURL(shell(), GURL(chrome::kChromeUICrashURL)); // Wait for browser to notice the renderer crash. crash_observer.Wait(); // Navigate to a new cross-site page. The browser should not wait around for // the old renderer's on{before}unload handlers to run. CheckTitleTest(GetMockURL("content-sniffer-test0.html"), - "Content Sniffer Test 0", 1); + "Content Sniffer Test 0"); } #endif // !defined(OS_MACOSX) @@ -355,13 +331,12 @@ IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, CrossSiteNavigationNonBuffered) { // Start with an HTTP page. CheckTitleTest(GetMockURL("content-sniffer-test0.html"), - "Content Sniffer Test 0", 1); + "Content Sniffer Test 0"); // Now load a file:// page, which does not use the BufferedEventHandler. // Make sure that the page loads and displays a title, and doesn't get stuck. - GURL url = ui_test_utils::GetTestUrl(FilePath(), - FilePath().AppendASCII("title2.html")); - CheckTitleTest(url, "Title Of Awesomeness", 1); + GURL url = GetTestUrl("", "title2.html"); + CheckTitleTest(url, "Title Of Awesomeness"); } // Tests that a cross-site navigation to an error page (resulting in the link @@ -373,19 +348,18 @@ IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, ASSERT_TRUE(test_server()->Start()); GURL url(test_server()->GetURL("files/onunload_cookie.html")); - CheckTitleTest(url, "set cookie on unload", 1); + CheckTitleTest(url, "set cookie on unload"); - // Navigate to a new cross-site URL that results in an error page. + // Navigate to a new cross-site URL that results in an error. // TODO(creis): If this causes crashes or hangs, it might be for the same // reason as ErrorPageTest::DNSError. See bug 1199491 and // http://crbug.com/22877. GURL failed_url = URLRequestFailedJob::GetMockHttpUrl( net::ERR_NAME_NOT_RESOLVED); - ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( - browser(), failed_url, 2); + NavigateToURL(shell(), failed_url); EXPECT_NE(ASCIIToUTF16("set cookie on unload"), - chrome::GetActiveWebContents(browser())->GetTitle()); + shell()->web_contents()->GetTitle()); // Check that the cookie was set, meaning that the onunload handler ran. EXPECT_EQ("onunloadCookie=foo", GetCookies(url)); @@ -400,16 +374,15 @@ IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, // pages of which the error page is one. Instead, use automation to kick // off the navigation, and wait to see that the tab loads. string16 expected_title16(ASCIIToUTF16("Title Of Awesomeness")); - content::TitleWatcher title_watcher( - chrome::GetActiveWebContents(browser()), expected_title16); + TitleWatcher title_watcher(shell()->web_contents(), expected_title16); bool success; GURL test_url(test_server()->GetURL("files/title2.html")); std::string redirect_script = "window.location='" + test_url.possibly_invalid_spec() + "';" + "window.domAutomationController.send(true);"; - EXPECT_TRUE(content::ExecuteJavaScriptAndExtractBool( - chrome::GetActiveWebContents(browser())->GetRenderViewHost(), + EXPECT_TRUE(ExecuteJavaScriptAndExtractBool( + shell()->web_contents()->GetRenderViewHost(), L"", ASCIIToWide(redirect_script), &success)); EXPECT_EQ(expected_title16, title_watcher.WaitAndGetTitle()); } @@ -419,25 +392,23 @@ IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, ASSERT_TRUE(test_server()->Start()); GURL url(test_server()->GetURL("files/title2.html")); - CheckTitleTest(url, "Title Of Awesomeness", 1); + CheckTitleTest(url, "Title Of Awesomeness"); - // Navigate to a new cross-site URL that results in an error page. + // Navigate to a new cross-site URL that results in an error. // TODO(creis): If this causes crashes or hangs, it might be for the same // reason as ErrorPageTest::DNSError. See bug 1199491 and // http://crbug.com/22877. GURL failed_url = URLRequestFailedJob::GetMockHttpUrl( net::ERR_NAME_NOT_RESOLVED); - ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( - browser(), failed_url, 2); + NavigateToURL(shell(), failed_url); EXPECT_NE(ASCIIToUTF16("Title Of Awesomeness"), - chrome::GetActiveWebContents(browser())->GetTitle()); + shell()->web_contents()->GetTitle()); // Repeat navigation. We are testing that this completes. - ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( - browser(), failed_url, 2); + NavigateToURL(shell(), failed_url); EXPECT_NE(ASCIIToUTF16("Title Of Awesomeness"), - chrome::GetActiveWebContents(browser())->GetTitle()); + shell()->web_contents()->GetTitle()); } IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, @@ -450,7 +421,7 @@ IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, // If the redirect in #2 were not blocked, we'd also see a request // for http://mock.http:4000/title2.html, and the title would be different. CheckTitleTest(GetMockURL("cross-origin-redirect-blocked.html"), - "Title Of More Awesomeness", 2); + "Title Of More Awesomeness"); } // Tests that ResourceRequestInfoImpl is updated correctly on failed @@ -459,10 +430,11 @@ IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, CrossSiteFailedRequest) { // Visit another URL first to trigger a cross-site navigation. - GURL url(content::kTestNewTabURL); - ui_test_utils::NavigateToURL(browser(), url); + NavigateToURL(shell(), GetTestUrl("", "simple_page.html")); // Visit a URL that fails without calling ResourceDispatcherHost::Read. GURL broken_url("chrome://theme"); - CheckTitleTest(broken_url, "chrome://theme/ is not available", 1); + NavigateToURL(shell(), broken_url); } + +} // namespace content diff --git a/content/content_tests.gypi b/content/content_tests.gypi index aa2db8a..462be24 100644 --- a/content/content_tests.gypi +++ b/content/content_tests.gypi @@ -576,6 +576,7 @@ 'browser/plugin_service_impl_browsertest.cc', 'browser/renderer_host/render_view_host_browsertest.cc', 'browser/renderer_host/render_view_host_manager_browsertest.cc', + 'browser/renderer_host/resource_dispatcher_host_browsertest.cc', 'browser/session_history_browsertest.cc', 'browser/speech/speech_recognition_browsertest.cc', 'browser/webkit_browsertest.cc', diff --git a/content/shell/shell_download_manager_delegate.cc b/content/shell/shell_download_manager_delegate.cc index 604285a..172b7d3 100644 --- a/content/shell/shell_download_manager_delegate.cc +++ b/content/shell/shell_download_manager_delegate.cc @@ -24,6 +24,8 @@ namespace content { ShellDownloadManagerDelegate::ShellDownloadManagerDelegate() : download_manager_(NULL) { + // Balanced in Shutdown(); + AddRef(); } ShellDownloadManagerDelegate::~ShellDownloadManagerDelegate(){ @@ -35,6 +37,10 @@ void ShellDownloadManagerDelegate::SetDownloadManager( download_manager_ = download_manager; } +void ShellDownloadManagerDelegate::Shutdown() { + Release(); +} + bool ShellDownloadManagerDelegate::DetermineDownloadTarget( DownloadItem* download, const DownloadTargetCallback& callback) { diff --git a/content/shell/shell_download_manager_delegate.h b/content/shell/shell_download_manager_delegate.h index 12cc5ee..3608177 100644 --- a/content/shell/shell_download_manager_delegate.h +++ b/content/shell/shell_download_manager_delegate.h @@ -21,6 +21,7 @@ class ShellDownloadManagerDelegate void SetDownloadManager(DownloadManager* manager); + virtual void Shutdown() OVERRIDE; virtual bool DetermineDownloadTarget( DownloadItem* download, const DownloadTargetCallback& callback) OVERRIDE; |