| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 // Test for bug #1091358. | 84 // Test for bug #1091358. |
| 85 TEST_F(ResourceDispatcherTest, SyncXMLHttpRequest) { | 85 TEST_F(ResourceDispatcherTest, SyncXMLHttpRequest) { |
| 86 const wchar_t kDocRoot[] = L"chrome/test/data"; | 86 const wchar_t kDocRoot[] = L"chrome/test/data"; |
| 87 scoped_refptr<HTTPTestServer> server = | 87 scoped_refptr<HTTPTestServer> server = |
| 88 HTTPTestServer::CreateServer(kDocRoot, NULL); | 88 HTTPTestServer::CreateServer(kDocRoot, NULL); |
| 89 ASSERT_TRUE(NULL != server.get()); | 89 ASSERT_TRUE(NULL != server.get()); |
| 90 | 90 |
| 91 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 91 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
| 92 EXPECT_TRUE(browser_proxy.get()); | 92 EXPECT_TRUE(browser_proxy.get()); |
| 93 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); | 93 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); |
| 94 ASSERT_TRUE(tab.get()); |
| 94 tab->NavigateToURL(server->TestServerPageW( | 95 tab->NavigateToURL(server->TestServerPageW( |
| 95 L"files/sync_xmlhttprequest.html")); | 96 L"files/sync_xmlhttprequest.html")); |
| 96 | 97 |
| 97 // Let's check the XMLHttpRequest ran successfully. | 98 // Let's check the XMLHttpRequest ran successfully. |
| 98 bool success = false; | 99 bool success = false; |
| 99 EXPECT_TRUE(tab->ExecuteAndExtractBool(L"", | 100 EXPECT_TRUE(tab->ExecuteAndExtractBool(L"", |
| 100 L"window.domAutomationController.send(DidSyncRequestSucceed());", | 101 L"window.domAutomationController.send(DidSyncRequestSucceed());", |
| 101 &success)); | 102 &success)); |
| 102 EXPECT_TRUE(success); | 103 EXPECT_TRUE(success); |
| 103 } | 104 } |
| 104 | 105 |
| 105 TEST_F(ResourceDispatcherTest, SyncXMLHttpRequest_Disallowed) { | 106 TEST_F(ResourceDispatcherTest, SyncXMLHttpRequest_Disallowed) { |
| 106 const wchar_t kDocRoot[] = L"chrome/test/data"; | 107 const wchar_t kDocRoot[] = L"chrome/test/data"; |
| 107 scoped_refptr<HTTPTestServer> server = | 108 scoped_refptr<HTTPTestServer> server = |
| 108 HTTPTestServer::CreateServer(kDocRoot, NULL); | 109 HTTPTestServer::CreateServer(kDocRoot, NULL); |
| 109 ASSERT_TRUE(NULL != server.get()); | 110 ASSERT_TRUE(NULL != server.get()); |
| 110 | 111 |
| 111 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 112 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
| 112 EXPECT_TRUE(browser_proxy.get()); | 113 EXPECT_TRUE(browser_proxy.get()); |
| 113 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); | 114 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); |
| 115 ASSERT_TRUE(tab.get()); |
| 114 tab->NavigateToURL(server->TestServerPageW( | 116 tab->NavigateToURL(server->TestServerPageW( |
| 115 L"files/sync_xmlhttprequest_disallowed.html")); | 117 L"files/sync_xmlhttprequest_disallowed.html")); |
| 116 | 118 |
| 117 // Let's check the XMLHttpRequest ran successfully. | 119 // Let's check the XMLHttpRequest ran successfully. |
| 118 bool success = false; | 120 bool success = false; |
| 119 EXPECT_TRUE(tab->ExecuteAndExtractBool(L"", | 121 EXPECT_TRUE(tab->ExecuteAndExtractBool(L"", |
| 120 L"window.domAutomationController.send(DidSucceed());", | 122 L"window.domAutomationController.send(DidSucceed());", |
| 121 &success)); | 123 &success)); |
| 122 EXPECT_TRUE(success); | 124 EXPECT_TRUE(success); |
| 123 } | 125 } |
| 124 | 126 |
| 125 // Test for bug #1159553 -- A synchronous xhr (whose content-type is | 127 // Test for bug #1159553 -- A synchronous xhr (whose content-type is |
| 126 // downloadable) would trigger download and hang the renderer process, | 128 // downloadable) would trigger download and hang the renderer process, |
| 127 // if executed while navigating to a new page. | 129 // if executed while navigating to a new page. |
| 128 TEST_F(ResourceDispatcherTest, SyncXMLHttpRequest_DuringUnload) { | 130 TEST_F(ResourceDispatcherTest, SyncXMLHttpRequest_DuringUnload) { |
| 129 const wchar_t kDocRoot[] = L"chrome/test/data"; | 131 const wchar_t kDocRoot[] = L"chrome/test/data"; |
| 130 scoped_refptr<HTTPTestServer> server = | 132 scoped_refptr<HTTPTestServer> server = |
| 131 HTTPTestServer::CreateServer(kDocRoot, NULL); | 133 HTTPTestServer::CreateServer(kDocRoot, NULL); |
| 132 ASSERT_TRUE(NULL != server.get()); | 134 ASSERT_TRUE(NULL != server.get()); |
| 133 | 135 |
| 134 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 136 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
| 135 EXPECT_TRUE(browser_proxy.get()); | 137 EXPECT_TRUE(browser_proxy.get()); |
| 136 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); | 138 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); |
| 139 ASSERT_TRUE(tab.get()); |
| 137 | 140 |
| 138 tab->NavigateToURL( | 141 tab->NavigateToURL( |
| 139 server->TestServerPageW(L"files/sync_xmlhttprequest_during_unload.html")); | 142 server->TestServerPageW(L"files/sync_xmlhttprequest_during_unload.html")); |
| 140 | 143 |
| 141 // Confirm that the page has loaded (since it changes its title during load). | 144 // Confirm that the page has loaded (since it changes its title during load). |
| 142 std::wstring tab_title; | 145 std::wstring tab_title; |
| 143 EXPECT_TRUE(tab->GetTabTitle(&tab_title)); | 146 EXPECT_TRUE(tab->GetTabTitle(&tab_title)); |
| 144 EXPECT_EQ(L"sync xhr on unload", tab_title); | 147 EXPECT_EQ(L"sync xhr on unload", tab_title); |
| 145 | 148 |
| 146 // Navigate to a new page, to dispatch unload event and trigger xhr. | 149 // Navigate to a new page, to dispatch unload event and trigger xhr. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 164 // Tests that onunload is run for cross-site requests. (Bug 1114994) | 167 // Tests that onunload is run for cross-site requests. (Bug 1114994) |
| 165 TEST_F(ResourceDispatcherTest, CrossSiteOnunloadCookie) { | 168 TEST_F(ResourceDispatcherTest, CrossSiteOnunloadCookie) { |
| 166 const wchar_t kDocRoot[] = L"chrome/test/data"; | 169 const wchar_t kDocRoot[] = L"chrome/test/data"; |
| 167 scoped_refptr<HTTPTestServer> server = | 170 scoped_refptr<HTTPTestServer> server = |
| 168 HTTPTestServer::CreateServer(kDocRoot, NULL); | 171 HTTPTestServer::CreateServer(kDocRoot, NULL); |
| 169 ASSERT_TRUE(NULL != server.get()); | 172 ASSERT_TRUE(NULL != server.get()); |
| 170 | 173 |
| 171 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 174 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
| 172 EXPECT_TRUE(browser_proxy.get()); | 175 EXPECT_TRUE(browser_proxy.get()); |
| 173 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); | 176 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); |
| 177 ASSERT_TRUE(tab.get()); |
| 174 | 178 |
| 175 GURL url(server->TestServerPageW(L"files/onunload_cookie.html")); | 179 GURL url(server->TestServerPageW(L"files/onunload_cookie.html")); |
| 176 tab->NavigateToURL(url); | 180 tab->NavigateToURL(url); |
| 177 | 181 |
| 178 // Confirm that the page has loaded (since it changes its title during load). | 182 // Confirm that the page has loaded (since it changes its title during load). |
| 179 std::wstring tab_title; | 183 std::wstring tab_title; |
| 180 EXPECT_TRUE(tab->GetTabTitle(&tab_title)); | 184 EXPECT_TRUE(tab->GetTabTitle(&tab_title)); |
| 181 EXPECT_EQ(L"set cookie on unload", tab_title); | 185 EXPECT_EQ(L"set cookie on unload", tab_title); |
| 182 | 186 |
| 183 // Navigate to a new cross-site page, to dispatch unload event and set the | 187 // Navigate to a new cross-site page, to dispatch unload event and set the |
| (...skipping 18 matching lines...) Expand all Loading... |
| 202 // five minutes to complete and isn't conducive to quick turnarounds. As we | 206 // five minutes to complete and isn't conducive to quick turnarounds. As we |
| 203 // don't currently strip the app on the build bots, this is bad times. | 207 // don't currently strip the app on the build bots, this is bad times. |
| 204 TEST_F(ResourceDispatcherTest, CrossSiteAfterCrash) { | 208 TEST_F(ResourceDispatcherTest, CrossSiteAfterCrash) { |
| 205 // This test only works in multi-process mode | 209 // This test only works in multi-process mode |
| 206 if (in_process_renderer()) | 210 if (in_process_renderer()) |
| 207 return; | 211 return; |
| 208 | 212 |
| 209 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 213 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
| 210 EXPECT_TRUE(browser_proxy.get()); | 214 EXPECT_TRUE(browser_proxy.get()); |
| 211 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); | 215 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); |
| 216 ASSERT_TRUE(tab.get()); |
| 212 | 217 |
| 213 // Cause the renderer to crash. | 218 // Cause the renderer to crash. |
| 214 // TODO(albertb): We need to disable this on Linux since | 219 // TODO(albertb): We need to disable this on Linux since |
| 215 // crash_service.exe hasn't been ported yet. | 220 // crash_service.exe hasn't been ported yet. |
| 216 #if defined(OS_WIN) | 221 #if defined(OS_WIN) |
| 217 expected_crashes_ = 1; | 222 expected_crashes_ = 1; |
| 218 #endif | 223 #endif |
| 219 tab->NavigateToURLAsync(GURL("about:crash")); | 224 tab->NavigateToURLAsync(GURL("about:crash")); |
| 220 // Wait for browser to notice the renderer crash. | 225 // Wait for browser to notice the renderer crash. |
| 221 PlatformThread::Sleep(sleep_timeout_ms()); | 226 PlatformThread::Sleep(sleep_timeout_ms()); |
| 222 | 227 |
| 223 // Navigate to a new cross-site page. The browser should not wait around for | 228 // Navigate to a new cross-site page. The browser should not wait around for |
| 224 // the old renderer's on{before}unload handlers to run. | 229 // the old renderer's on{before}unload handlers to run. |
| 225 CheckTitleTest(L"content-sniffer-test0.html", | 230 CheckTitleTest(L"content-sniffer-test0.html", |
| 226 L"Content Sniffer Test 0"); | 231 L"Content Sniffer Test 0"); |
| 227 } | 232 } |
| 228 #endif // !defined(OS_MACOSX) | 233 #endif // !defined(OS_MACOSX) |
| 229 | 234 |
| 230 // Tests that cross-site navigations work when the new page does not go through | 235 // Tests that cross-site navigations work when the new page does not go through |
| 231 // the BufferedEventHandler (e.g., non-http{s} URLs). (Bug 1225872) | 236 // the BufferedEventHandler (e.g., non-http{s} URLs). (Bug 1225872) |
| 232 TEST_F(ResourceDispatcherTest, CrossSiteNavigationNonBuffered) { | 237 TEST_F(ResourceDispatcherTest, CrossSiteNavigationNonBuffered) { |
| 233 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 238 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
| 234 EXPECT_TRUE(browser_proxy.get()); | 239 EXPECT_TRUE(browser_proxy.get()); |
| 235 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); | 240 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); |
| 241 ASSERT_TRUE(tab.get()); |
| 236 | 242 |
| 237 // Start with an HTTP page. | 243 // Start with an HTTP page. |
| 238 CheckTitleTest(L"content-sniffer-test0.html", | 244 CheckTitleTest(L"content-sniffer-test0.html", |
| 239 L"Content Sniffer Test 0"); | 245 L"Content Sniffer Test 0"); |
| 240 | 246 |
| 241 // Now load a file:// page, which does not use the BufferedEventHandler. | 247 // Now load a file:// page, which does not use the BufferedEventHandler. |
| 242 // Make sure that the page loads and displays a title, and doesn't get stuck. | 248 // Make sure that the page loads and displays a title, and doesn't get stuck. |
| 243 FilePath test_file(test_data_directory_); | 249 FilePath test_file(test_data_directory_); |
| 244 test_file = test_file.AppendASCII("title2.html"); | 250 test_file = test_file.AppendASCII("title2.html"); |
| 245 bool timed_out = false; | 251 bool timed_out = false; |
| 246 tab->NavigateToURLWithTimeout(net::FilePathToFileURL(test_file), | 252 tab->NavigateToURLWithTimeout(net::FilePathToFileURL(test_file), |
| 247 action_max_timeout_ms(), | 253 action_max_timeout_ms(), |
| 248 &timed_out); | 254 &timed_out); |
| 249 EXPECT_FALSE(timed_out); | 255 EXPECT_FALSE(timed_out); |
| 250 EXPECT_EQ(L"Title Of Awesomeness", GetActiveTabTitle()); | 256 EXPECT_EQ(L"Title Of Awesomeness", GetActiveTabTitle()); |
| 251 } | 257 } |
| 252 | 258 |
| 253 // Tests that a cross-site navigation to an error page (resulting in the link | 259 // Tests that a cross-site navigation to an error page (resulting in the link |
| 254 // doctor page) still runs the onunload handler and can support navigations | 260 // doctor page) still runs the onunload handler and can support navigations |
| 255 // away from the link doctor page. (Bug 1235537) | 261 // away from the link doctor page. (Bug 1235537) |
| 256 TEST_F(ResourceDispatcherTest, CrossSiteNavigationErrorPage) { | 262 TEST_F(ResourceDispatcherTest, CrossSiteNavigationErrorPage) { |
| 257 const wchar_t kDocRoot[] = L"chrome/test/data"; | 263 const wchar_t kDocRoot[] = L"chrome/test/data"; |
| 258 scoped_refptr<HTTPTestServer> server = | 264 scoped_refptr<HTTPTestServer> server = |
| 259 HTTPTestServer::CreateServer(kDocRoot, NULL); | 265 HTTPTestServer::CreateServer(kDocRoot, NULL); |
| 260 ASSERT_TRUE(NULL != server.get()); | 266 ASSERT_TRUE(NULL != server.get()); |
| 261 | 267 |
| 262 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 268 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
| 263 EXPECT_TRUE(browser_proxy.get()); | 269 EXPECT_TRUE(browser_proxy.get()); |
| 264 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); | 270 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); |
| 271 ASSERT_TRUE(tab.get()); |
| 265 | 272 |
| 266 GURL url(server->TestServerPageW(L"files/onunload_cookie.html")); | 273 GURL url(server->TestServerPageW(L"files/onunload_cookie.html")); |
| 267 tab->NavigateToURL(url); | 274 tab->NavigateToURL(url); |
| 268 | 275 |
| 269 // Confirm that the page has loaded (since it changes its title during load). | 276 // Confirm that the page has loaded (since it changes its title during load). |
| 270 std::wstring tab_title; | 277 std::wstring tab_title; |
| 271 EXPECT_TRUE(tab->GetTabTitle(&tab_title)); | 278 EXPECT_TRUE(tab->GetTabTitle(&tab_title)); |
| 272 EXPECT_EQ(L"set cookie on unload", tab_title); | 279 EXPECT_EQ(L"set cookie on unload", tab_title); |
| 273 | 280 |
| 274 // Navigate to a new cross-site URL that results in an error page. We must | 281 // Navigate to a new cross-site URL that results in an error page. We must |
| (...skipping 26 matching lines...) Expand all Loading... |
| 301 std::string redirect_url = "javascript:window.location='" + | 308 std::string redirect_url = "javascript:window.location='" + |
| 302 test_url.possibly_invalid_spec() + "'"; | 309 test_url.possibly_invalid_spec() + "'"; |
| 303 tab->NavigateToURLAsync(GURL(redirect_url)); | 310 tab->NavigateToURLAsync(GURL(redirect_url)); |
| 304 // Wait for JavaScript redirect to happen. | 311 // Wait for JavaScript redirect to happen. |
| 305 PlatformThread::Sleep(sleep_timeout_ms() * 3); | 312 PlatformThread::Sleep(sleep_timeout_ms() * 3); |
| 306 EXPECT_TRUE(tab->GetTabTitle(&tab_title)); | 313 EXPECT_TRUE(tab->GetTabTitle(&tab_title)); |
| 307 EXPECT_EQ(L"Title Of Awesomeness", tab_title); | 314 EXPECT_EQ(L"Title Of Awesomeness", tab_title); |
| 308 } | 315 } |
| 309 | 316 |
| 310 } // namespace | 317 } // namespace |
| OLD | NEW |