| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "chrome/browser/net/url_request_failed_dns_job.h" | 12 #include "chrome/browser/net/url_request_failed_dns_job.h" |
| 13 #include "chrome/browser/net/url_request_mock_http_job.h" | 13 #include "chrome/browser/net/url_request_mock_http_job.h" |
| 14 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
| 15 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
| 16 #include "chrome/test/automation/browser_proxy.h" | 16 #include "chrome/test/automation/browser_proxy.h" |
| 17 #include "chrome/test/automation/tab_proxy.h" | 17 #include "chrome/test/automation/tab_proxy.h" |
| 18 #include "chrome/test/ui/ui_test.h" | 18 #include "chrome/test/ui/ui_test.h" |
| 19 #include "net/base/net_util.h" | 19 #include "net/base/net_util.h" |
| 20 #include "net/url_request/url_request_unittest.h" | 20 #include "net/test/test_server.h" |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 class ResourceDispatcherTest : public UITest { | 24 class ResourceDispatcherTest : public UITest { |
| 25 public: | 25 public: |
| 26 void CheckTitleTest(const std::wstring& file, | 26 void CheckTitleTest(const std::wstring& file, |
| 27 const std::wstring& expected_title, | 27 const std::wstring& expected_title, |
| 28 int expected_navigations) { | 28 int expected_navigations) { |
| 29 NavigateToURLBlockUntilNavigationsComplete( | 29 NavigateToURLBlockUntilNavigationsComplete( |
| 30 URLRequestMockHTTPJob::GetMockUrl(FilePath::FromWStringHack(file)), | 30 URLRequestMockHTTPJob::GetMockUrl(FilePath::FromWStringHack(file)), |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 CheckTitleTest(L"content-disposition-empty.html", L"success", 1); | 72 CheckTitleTest(L"content-disposition-empty.html", L"success", 1); |
| 73 } | 73 } |
| 74 | 74 |
| 75 TEST_F(ResourceDispatcherTest, ContentDispositionInline) { | 75 TEST_F(ResourceDispatcherTest, ContentDispositionInline) { |
| 76 CheckTitleTest(L"content-disposition-inline.html", L"success", 1); | 76 CheckTitleTest(L"content-disposition-inline.html", L"success", 1); |
| 77 } | 77 } |
| 78 | 78 |
| 79 // Test for bug #1091358. | 79 // Test for bug #1091358. |
| 80 TEST_F(ResourceDispatcherTest, SyncXMLHttpRequest) { | 80 TEST_F(ResourceDispatcherTest, SyncXMLHttpRequest) { |
| 81 const wchar_t kDocRoot[] = L"chrome/test/data"; | 81 const wchar_t kDocRoot[] = L"chrome/test/data"; |
| 82 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); | 82 scoped_refptr<net::HTTPTestServer> server( |
| 83 net::HTTPTestServer::CreateServer(kDocRoot)); |
| 83 ASSERT_TRUE(NULL != server.get()); | 84 ASSERT_TRUE(NULL != server.get()); |
| 84 | 85 |
| 85 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 86 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
| 86 ASSERT_TRUE(browser_proxy.get()); | 87 ASSERT_TRUE(browser_proxy.get()); |
| 87 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); | 88 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); |
| 88 ASSERT_TRUE(tab.get()); | 89 ASSERT_TRUE(tab.get()); |
| 89 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, | 90 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, |
| 90 tab->NavigateToURL(server->TestServerPage( | 91 tab->NavigateToURL(server->TestServerPage( |
| 91 "files/sync_xmlhttprequest.html"))); | 92 "files/sync_xmlhttprequest.html"))); |
| 92 | 93 |
| 93 // Let's check the XMLHttpRequest ran successfully. | 94 // Let's check the XMLHttpRequest ran successfully. |
| 94 bool success = false; | 95 bool success = false; |
| 95 EXPECT_TRUE(tab->ExecuteAndExtractBool(L"", | 96 EXPECT_TRUE(tab->ExecuteAndExtractBool(L"", |
| 96 L"window.domAutomationController.send(DidSyncRequestSucceed());", | 97 L"window.domAutomationController.send(DidSyncRequestSucceed());", |
| 97 &success)); | 98 &success)); |
| 98 EXPECT_TRUE(success); | 99 EXPECT_TRUE(success); |
| 99 } | 100 } |
| 100 | 101 |
| 101 TEST_F(ResourceDispatcherTest, SyncXMLHttpRequest_Disallowed) { | 102 TEST_F(ResourceDispatcherTest, SyncXMLHttpRequest_Disallowed) { |
| 102 const wchar_t kDocRoot[] = L"chrome/test/data"; | 103 const wchar_t kDocRoot[] = L"chrome/test/data"; |
| 103 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); | 104 scoped_refptr<net::HTTPTestServer> server( |
| 105 net::HTTPTestServer::CreateServer(kDocRoot)); |
| 104 ASSERT_TRUE(NULL != server.get()); | 106 ASSERT_TRUE(NULL != server.get()); |
| 105 | 107 |
| 106 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 108 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
| 107 ASSERT_TRUE(browser_proxy.get()); | 109 ASSERT_TRUE(browser_proxy.get()); |
| 108 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); | 110 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); |
| 109 ASSERT_TRUE(tab.get()); | 111 ASSERT_TRUE(tab.get()); |
| 110 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, | 112 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, |
| 111 tab->NavigateToURL(server->TestServerPage( | 113 tab->NavigateToURL(server->TestServerPage( |
| 112 "files/sync_xmlhttprequest_disallowed.html"))); | 114 "files/sync_xmlhttprequest_disallowed.html"))); |
| 113 | 115 |
| 114 // Let's check the XMLHttpRequest ran successfully. | 116 // Let's check the XMLHttpRequest ran successfully. |
| 115 bool success = false; | 117 bool success = false; |
| 116 EXPECT_TRUE(tab->ExecuteAndExtractBool(L"", | 118 EXPECT_TRUE(tab->ExecuteAndExtractBool(L"", |
| 117 L"window.domAutomationController.send(DidSucceed());", | 119 L"window.domAutomationController.send(DidSucceed());", |
| 118 &success)); | 120 &success)); |
| 119 EXPECT_TRUE(success); | 121 EXPECT_TRUE(success); |
| 120 } | 122 } |
| 121 | 123 |
| 122 // Test for bug #1159553 -- A synchronous xhr (whose content-type is | 124 // Test for bug #1159553 -- A synchronous xhr (whose content-type is |
| 123 // downloadable) would trigger download and hang the renderer process, | 125 // downloadable) would trigger download and hang the renderer process, |
| 124 // if executed while navigating to a new page. | 126 // if executed while navigating to a new page. |
| 125 TEST_F(ResourceDispatcherTest, SyncXMLHttpRequest_DuringUnload) { | 127 TEST_F(ResourceDispatcherTest, SyncXMLHttpRequest_DuringUnload) { |
| 126 const wchar_t kDocRoot[] = L"chrome/test/data"; | 128 const wchar_t kDocRoot[] = L"chrome/test/data"; |
| 127 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); | 129 scoped_refptr<net::HTTPTestServer> server( |
| 130 net::HTTPTestServer::CreateServer(kDocRoot)); |
| 128 ASSERT_TRUE(NULL != server.get()); | 131 ASSERT_TRUE(NULL != server.get()); |
| 129 | 132 |
| 130 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 133 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
| 131 ASSERT_TRUE(browser_proxy.get()); | 134 ASSERT_TRUE(browser_proxy.get()); |
| 132 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); | 135 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); |
| 133 ASSERT_TRUE(tab.get()); | 136 ASSERT_TRUE(tab.get()); |
| 134 | 137 |
| 135 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, | 138 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, |
| 136 tab->NavigateToURL(server->TestServerPage( | 139 tab->NavigateToURL(server->TestServerPage( |
| 137 "files/sync_xmlhttprequest_during_unload.html"))); | 140 "files/sync_xmlhttprequest_during_unload.html"))); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 153 bool shelf_is_visible = false; | 156 bool shelf_is_visible = false; |
| 154 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | 157 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
| 155 ASSERT_TRUE(browser.get()); | 158 ASSERT_TRUE(browser.get()); |
| 156 EXPECT_TRUE(browser->IsShelfVisible(&shelf_is_visible)); | 159 EXPECT_TRUE(browser->IsShelfVisible(&shelf_is_visible)); |
| 157 EXPECT_FALSE(shelf_is_visible); | 160 EXPECT_FALSE(shelf_is_visible); |
| 158 } | 161 } |
| 159 | 162 |
| 160 // Tests that onunload is run for cross-site requests. (Bug 1114994) | 163 // Tests that onunload is run for cross-site requests. (Bug 1114994) |
| 161 TEST_F(ResourceDispatcherTest, CrossSiteOnunloadCookie) { | 164 TEST_F(ResourceDispatcherTest, CrossSiteOnunloadCookie) { |
| 162 const wchar_t kDocRoot[] = L"chrome/test/data"; | 165 const wchar_t kDocRoot[] = L"chrome/test/data"; |
| 163 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); | 166 scoped_refptr<net::HTTPTestServer> server( |
| 167 net::HTTPTestServer::CreateServer(kDocRoot)); |
| 164 ASSERT_TRUE(NULL != server.get()); | 168 ASSERT_TRUE(NULL != server.get()); |
| 165 | 169 |
| 166 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 170 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
| 167 ASSERT_TRUE(browser_proxy.get()); | 171 ASSERT_TRUE(browser_proxy.get()); |
| 168 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); | 172 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); |
| 169 ASSERT_TRUE(tab.get()); | 173 ASSERT_TRUE(tab.get()); |
| 170 | 174 |
| 171 GURL url(server->TestServerPage("files/onunload_cookie.html")); | 175 GURL url(server->TestServerPage("files/onunload_cookie.html")); |
| 172 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(url)); | 176 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(url)); |
| 173 | 177 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, | 251 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, |
| 248 tab->NavigateToURL(net::FilePathToFileURL(test_file))); | 252 tab->NavigateToURL(net::FilePathToFileURL(test_file))); |
| 249 EXPECT_EQ(L"Title Of Awesomeness", GetActiveTabTitle()); | 253 EXPECT_EQ(L"Title Of Awesomeness", GetActiveTabTitle()); |
| 250 } | 254 } |
| 251 | 255 |
| 252 // Tests that a cross-site navigation to an error page (resulting in the link | 256 // Tests that a cross-site navigation to an error page (resulting in the link |
| 253 // doctor page) still runs the onunload handler and can support navigations | 257 // doctor page) still runs the onunload handler and can support navigations |
| 254 // away from the link doctor page. (Bug 1235537) | 258 // away from the link doctor page. (Bug 1235537) |
| 255 TEST_F(ResourceDispatcherTest, CrossSiteNavigationErrorPage) { | 259 TEST_F(ResourceDispatcherTest, CrossSiteNavigationErrorPage) { |
| 256 const wchar_t kDocRoot[] = L"chrome/test/data"; | 260 const wchar_t kDocRoot[] = L"chrome/test/data"; |
| 257 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); | 261 scoped_refptr<net::HTTPTestServer> server( |
| 262 net::HTTPTestServer::CreateServer(kDocRoot)); |
| 258 ASSERT_TRUE(NULL != server.get()); | 263 ASSERT_TRUE(NULL != server.get()); |
| 259 | 264 |
| 260 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 265 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
| 261 ASSERT_TRUE(browser_proxy.get()); | 266 ASSERT_TRUE(browser_proxy.get()); |
| 262 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); | 267 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); |
| 263 ASSERT_TRUE(tab.get()); | 268 ASSERT_TRUE(tab.get()); |
| 264 | 269 |
| 265 GURL url(server->TestServerPage("files/onunload_cookie.html")); | 270 GURL url(server->TestServerPage("files/onunload_cookie.html")); |
| 266 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(url)); | 271 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(url)); |
| 267 | 272 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 GURL broken_url("chrome://theme"); | 334 GURL broken_url("chrome://theme"); |
| 330 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(broken_url)); | 335 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(broken_url)); |
| 331 | 336 |
| 332 // Make sure the navigation finishes. | 337 // Make sure the navigation finishes. |
| 333 std::wstring tab_title; | 338 std::wstring tab_title; |
| 334 EXPECT_TRUE(tab->GetTabTitle(&tab_title)); | 339 EXPECT_TRUE(tab->GetTabTitle(&tab_title)); |
| 335 EXPECT_EQ(L"chrome://theme/ is not available", tab_title); | 340 EXPECT_EQ(L"chrome://theme/ is not available", tab_title); |
| 336 } | 341 } |
| 337 | 342 |
| 338 } // namespace | 343 } // namespace |
| OLD | NEW |