Index: content/browser/renderer_host/resource_dispatcher_host_browsertest.cc |
=================================================================== |
--- content/browser/renderer_host/resource_dispatcher_host_browsertest.cc (revision 148962) |
+++ content/browser/renderer_host/resource_dispatcher_host_browsertest.cc (working copy) |
@@ -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 @@ |
} // 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 @@ |
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 @@ |
} |
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 @@ |
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, |
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_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, |
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 @@ |
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 @@ |
// 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 @@ |
// 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 @@ |
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 @@ |
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 @@ |
// 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 @@ |
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 @@ |
// 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, |
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 |