| 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" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 const wchar_t kDocRoot[] = L"chrome/test/data"; | 81 const wchar_t kDocRoot[] = L"chrome/test/data"; |
| 82 scoped_refptr<HTTPTestServer> server = | 82 scoped_refptr<HTTPTestServer> server = |
| 83 HTTPTestServer::CreateServer(kDocRoot, NULL); | 83 HTTPTestServer::CreateServer(kDocRoot, NULL); |
| 84 ASSERT_TRUE(NULL != server.get()); | 84 ASSERT_TRUE(NULL != server.get()); |
| 85 | 85 |
| 86 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 86 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
| 87 ASSERT_TRUE(browser_proxy.get()); | 87 ASSERT_TRUE(browser_proxy.get()); |
| 88 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); | 88 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); |
| 89 ASSERT_TRUE(tab.get()); | 89 ASSERT_TRUE(tab.get()); |
| 90 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, | 90 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, |
| 91 tab->NavigateToURL(server->TestServerPageW( | 91 tab->NavigateToURL(server->TestServerPage( |
| 92 L"files/sync_xmlhttprequest.html"))); | 92 "files/sync_xmlhttprequest.html"))); |
| 93 | 93 |
| 94 // Let's check the XMLHttpRequest ran successfully. | 94 // Let's check the XMLHttpRequest ran successfully. |
| 95 bool success = false; | 95 bool success = false; |
| 96 EXPECT_TRUE(tab->ExecuteAndExtractBool(L"", | 96 EXPECT_TRUE(tab->ExecuteAndExtractBool(L"", |
| 97 L"window.domAutomationController.send(DidSyncRequestSucceed());", | 97 L"window.domAutomationController.send(DidSyncRequestSucceed());", |
| 98 &success)); | 98 &success)); |
| 99 EXPECT_TRUE(success); | 99 EXPECT_TRUE(success); |
| 100 } | 100 } |
| 101 | 101 |
| 102 TEST_F(ResourceDispatcherTest, SyncXMLHttpRequest_Disallowed) { | 102 TEST_F(ResourceDispatcherTest, SyncXMLHttpRequest_Disallowed) { |
| 103 const wchar_t kDocRoot[] = L"chrome/test/data"; | 103 const wchar_t kDocRoot[] = L"chrome/test/data"; |
| 104 scoped_refptr<HTTPTestServer> server = | 104 scoped_refptr<HTTPTestServer> server = |
| 105 HTTPTestServer::CreateServer(kDocRoot, NULL); | 105 HTTPTestServer::CreateServer(kDocRoot, NULL); |
| 106 ASSERT_TRUE(NULL != server.get()); | 106 ASSERT_TRUE(NULL != server.get()); |
| 107 | 107 |
| 108 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 108 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
| 109 ASSERT_TRUE(browser_proxy.get()); | 109 ASSERT_TRUE(browser_proxy.get()); |
| 110 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); | 110 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); |
| 111 ASSERT_TRUE(tab.get()); | 111 ASSERT_TRUE(tab.get()); |
| 112 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, | 112 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, |
| 113 tab->NavigateToURL(server->TestServerPageW( | 113 tab->NavigateToURL(server->TestServerPage( |
| 114 L"files/sync_xmlhttprequest_disallowed.html"))); | 114 "files/sync_xmlhttprequest_disallowed.html"))); |
| 115 | 115 |
| 116 // Let's check the XMLHttpRequest ran successfully. | 116 // Let's check the XMLHttpRequest ran successfully. |
| 117 bool success = false; | 117 bool success = false; |
| 118 EXPECT_TRUE(tab->ExecuteAndExtractBool(L"", | 118 EXPECT_TRUE(tab->ExecuteAndExtractBool(L"", |
| 119 L"window.domAutomationController.send(DidSucceed());", | 119 L"window.domAutomationController.send(DidSucceed());", |
| 120 &success)); | 120 &success)); |
| 121 EXPECT_TRUE(success); | 121 EXPECT_TRUE(success); |
| 122 } | 122 } |
| 123 | 123 |
| 124 // Test for bug #1159553 -- A synchronous xhr (whose content-type is | 124 // Test for bug #1159553 -- A synchronous xhr (whose content-type is |
| 125 // downloadable) would trigger download and hang the renderer process, | 125 // downloadable) would trigger download and hang the renderer process, |
| 126 // if executed while navigating to a new page. | 126 // if executed while navigating to a new page. |
| 127 TEST_F(ResourceDispatcherTest, SyncXMLHttpRequest_DuringUnload) { | 127 TEST_F(ResourceDispatcherTest, SyncXMLHttpRequest_DuringUnload) { |
| 128 const wchar_t kDocRoot[] = L"chrome/test/data"; | 128 const wchar_t kDocRoot[] = L"chrome/test/data"; |
| 129 scoped_refptr<HTTPTestServer> server = | 129 scoped_refptr<HTTPTestServer> server = |
| 130 HTTPTestServer::CreateServer(kDocRoot, NULL); | 130 HTTPTestServer::CreateServer(kDocRoot, NULL); |
| 131 ASSERT_TRUE(NULL != server.get()); | 131 ASSERT_TRUE(NULL != server.get()); |
| 132 | 132 |
| 133 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 133 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
| 134 ASSERT_TRUE(browser_proxy.get()); | 134 ASSERT_TRUE(browser_proxy.get()); |
| 135 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); | 135 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); |
| 136 ASSERT_TRUE(tab.get()); | 136 ASSERT_TRUE(tab.get()); |
| 137 | 137 |
| 138 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, | 138 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, |
| 139 tab->NavigateToURL(server->TestServerPageW( | 139 tab->NavigateToURL(server->TestServerPage( |
| 140 L"files/sync_xmlhttprequest_during_unload.html"))); | 140 "files/sync_xmlhttprequest_during_unload.html"))); |
| 141 | 141 |
| 142 // Confirm that the page has loaded (since it changes its title during load). | 142 // Confirm that the page has loaded (since it changes its title during load). |
| 143 std::wstring tab_title; | 143 std::wstring tab_title; |
| 144 EXPECT_TRUE(tab->GetTabTitle(&tab_title)); | 144 EXPECT_TRUE(tab->GetTabTitle(&tab_title)); |
| 145 EXPECT_EQ(L"sync xhr on unload", tab_title); | 145 EXPECT_EQ(L"sync xhr on unload", tab_title); |
| 146 | 146 |
| 147 // Navigate to a new page, to dispatch unload event and trigger xhr. | 147 // Navigate to a new page, to dispatch unload event and trigger xhr. |
| 148 // (the bug would make this step hang the renderer). | 148 // (the bug would make this step hang the renderer). |
| 149 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, | 149 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, |
| 150 tab->NavigateToURL(server->TestServerPageW(L"files/title2.html"))); | 150 tab->NavigateToURL(server->TestServerPage("files/title2.html"))); |
| 151 | 151 |
| 152 // Check that the new page got loaded, and that no download was triggered. | 152 // Check that the new page got loaded, and that no download was triggered. |
| 153 EXPECT_TRUE(tab->GetTabTitle(&tab_title)); | 153 EXPECT_TRUE(tab->GetTabTitle(&tab_title)); |
| 154 EXPECT_EQ(L"Title Of Awesomeness", tab_title); | 154 EXPECT_EQ(L"Title Of Awesomeness", tab_title); |
| 155 | 155 |
| 156 bool shelf_is_visible = false; | 156 bool shelf_is_visible = false; |
| 157 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | 157 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
| 158 ASSERT_TRUE(browser.get()); | 158 ASSERT_TRUE(browser.get()); |
| 159 EXPECT_TRUE(browser->IsShelfVisible(&shelf_is_visible)); | 159 EXPECT_TRUE(browser->IsShelfVisible(&shelf_is_visible)); |
| 160 EXPECT_FALSE(shelf_is_visible); | 160 EXPECT_FALSE(shelf_is_visible); |
| 161 } | 161 } |
| 162 | 162 |
| 163 // Tests that onunload is run for cross-site requests. (Bug 1114994) | 163 // Tests that onunload is run for cross-site requests. (Bug 1114994) |
| 164 TEST_F(ResourceDispatcherTest, CrossSiteOnunloadCookie) { | 164 TEST_F(ResourceDispatcherTest, CrossSiteOnunloadCookie) { |
| 165 const wchar_t kDocRoot[] = L"chrome/test/data"; | 165 const wchar_t kDocRoot[] = L"chrome/test/data"; |
| 166 scoped_refptr<HTTPTestServer> server = | 166 scoped_refptr<HTTPTestServer> server = |
| 167 HTTPTestServer::CreateServer(kDocRoot, NULL); | 167 HTTPTestServer::CreateServer(kDocRoot, NULL); |
| 168 ASSERT_TRUE(NULL != server.get()); | 168 ASSERT_TRUE(NULL != server.get()); |
| 169 | 169 |
| 170 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 170 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
| 171 ASSERT_TRUE(browser_proxy.get()); | 171 ASSERT_TRUE(browser_proxy.get()); |
| 172 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); | 172 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); |
| 173 ASSERT_TRUE(tab.get()); | 173 ASSERT_TRUE(tab.get()); |
| 174 | 174 |
| 175 GURL url(server->TestServerPageW(L"files/onunload_cookie.html")); | 175 GURL url(server->TestServerPage("files/onunload_cookie.html")); |
| 176 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(url)); | 176 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(url)); |
| 177 | 177 |
| 178 // Confirm that the page has loaded (since it changes its title during load). | 178 // Confirm that the page has loaded (since it changes its title during load). |
| 179 std::wstring tab_title; | 179 std::wstring tab_title; |
| 180 EXPECT_TRUE(tab->GetTabTitle(&tab_title)); | 180 EXPECT_TRUE(tab->GetTabTitle(&tab_title)); |
| 181 EXPECT_EQ(L"set cookie on unload", tab_title); | 181 EXPECT_EQ(L"set cookie on unload", tab_title); |
| 182 | 182 |
| 183 // Navigate to a new cross-site page, to dispatch unload event and set the | 183 // Navigate to a new cross-site page, to dispatch unload event and set the |
| 184 // cookie. | 184 // cookie. |
| 185 CheckTitleTest(L"content-sniffer-test0.html", | 185 CheckTitleTest(L"content-sniffer-test0.html", |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 const wchar_t kDocRoot[] = L"chrome/test/data"; | 260 const wchar_t kDocRoot[] = L"chrome/test/data"; |
| 261 scoped_refptr<HTTPTestServer> server = | 261 scoped_refptr<HTTPTestServer> server = |
| 262 HTTPTestServer::CreateServer(kDocRoot, NULL); | 262 HTTPTestServer::CreateServer(kDocRoot, NULL); |
| 263 ASSERT_TRUE(NULL != server.get()); | 263 ASSERT_TRUE(NULL != server.get()); |
| 264 | 264 |
| 265 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 265 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
| 266 ASSERT_TRUE(browser_proxy.get()); | 266 ASSERT_TRUE(browser_proxy.get()); |
| 267 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); | 267 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); |
| 268 ASSERT_TRUE(tab.get()); | 268 ASSERT_TRUE(tab.get()); |
| 269 | 269 |
| 270 GURL url(server->TestServerPageW(L"files/onunload_cookie.html")); | 270 GURL url(server->TestServerPage("files/onunload_cookie.html")); |
| 271 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(url)); | 271 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(url)); |
| 272 | 272 |
| 273 // Confirm that the page has loaded (since it changes its title during load). | 273 // Confirm that the page has loaded (since it changes its title during load). |
| 274 std::wstring tab_title; | 274 std::wstring tab_title; |
| 275 EXPECT_TRUE(tab->GetTabTitle(&tab_title)); | 275 EXPECT_TRUE(tab->GetTabTitle(&tab_title)); |
| 276 EXPECT_EQ(L"set cookie on unload", tab_title); | 276 EXPECT_EQ(L"set cookie on unload", tab_title); |
| 277 | 277 |
| 278 // Navigate to a new cross-site URL that results in an error page. | 278 // Navigate to a new cross-site URL that results in an error page. |
| 279 // TODO(creis): If this causes crashes or hangs, it might be for the same | 279 // TODO(creis): If this causes crashes or hangs, it might be for the same |
| 280 // reason as ErrorPageTest::DNSError. See bug 1199491 and | 280 // reason as ErrorPageTest::DNSError. See bug 1199491 and |
| 281 // http://crbug.com/22877. | 281 // http://crbug.com/22877. |
| 282 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, | 282 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, |
| 283 tab->NavigateToURLBlockUntilNavigationsComplete( | 283 tab->NavigateToURLBlockUntilNavigationsComplete( |
| 284 GURL(URLRequestFailedDnsJob::kTestUrl), 2)); | 284 GURL(URLRequestFailedDnsJob::kTestUrl), 2)); |
| 285 EXPECT_NE(L"set cookie on unload", GetActiveTabTitle()); | 285 EXPECT_NE(L"set cookie on unload", GetActiveTabTitle()); |
| 286 | 286 |
| 287 // Check that the cookie was set, meaning that the onunload handler ran. | 287 // Check that the cookie was set, meaning that the onunload handler ran. |
| 288 std::string value_result; | 288 std::string value_result; |
| 289 EXPECT_TRUE(tab->GetCookieByName(url, "onunloadCookie", &value_result)); | 289 EXPECT_TRUE(tab->GetCookieByName(url, "onunloadCookie", &value_result)); |
| 290 EXPECT_FALSE(value_result.empty()); | 290 EXPECT_FALSE(value_result.empty()); |
| 291 EXPECT_STREQ("foo", value_result.c_str()); | 291 EXPECT_STREQ("foo", value_result.c_str()); |
| 292 | 292 |
| 293 // Check that renderer-initiated navigations still work. In a previous bug, | 293 // Check that renderer-initiated navigations still work. In a previous bug, |
| 294 // the ResourceDispatcherHost would think that such navigations were | 294 // the ResourceDispatcherHost would think that such navigations were |
| 295 // cross-site, because we didn't clean up from the previous request. Since | 295 // cross-site, because we didn't clean up from the previous request. Since |
| 296 // TabContents was in the NORMAL state, it would ignore the attempt to run | 296 // TabContents was in the NORMAL state, it would ignore the attempt to run |
| 297 // the onunload handler, and the navigation would fail. | 297 // the onunload handler, and the navigation would fail. |
| 298 // (Test by redirecting to javascript:window.location='someURL'.) | 298 // (Test by redirecting to javascript:window.location='someURL'.) |
| 299 GURL test_url(server->TestServerPageW(L"files/title2.html")); | 299 GURL test_url(server->TestServerPage("files/title2.html")); |
| 300 std::string redirect_url = "javascript:window.location='" + | 300 std::string redirect_url = "javascript:window.location='" + |
| 301 test_url.possibly_invalid_spec() + "'"; | 301 test_url.possibly_invalid_spec() + "'"; |
| 302 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, | 302 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, |
| 303 tab->NavigateToURL(GURL(redirect_url))); | 303 tab->NavigateToURL(GURL(redirect_url))); |
| 304 EXPECT_TRUE(tab->GetTabTitle(&tab_title)); | 304 EXPECT_TRUE(tab->GetTabTitle(&tab_title)); |
| 305 EXPECT_EQ(L"Title Of Awesomeness", tab_title); | 305 EXPECT_EQ(L"Title Of Awesomeness", tab_title); |
| 306 } | 306 } |
| 307 | 307 |
| 308 TEST_F(ResourceDispatcherTest, CrossOriginRedirectBlocked) { | 308 TEST_F(ResourceDispatcherTest, CrossOriginRedirectBlocked) { |
| 309 // We expect the following URL requests from this test: | 309 // We expect the following URL requests from this test: |
| 310 // 1- http://mock.http/cross-origin-redirect-blocked.html | 310 // 1- http://mock.http/cross-origin-redirect-blocked.html |
| 311 // 2- http://mock.http/redirect-to-title2.html | 311 // 2- http://mock.http/redirect-to-title2.html |
| 312 // 3- http://mock.http/title2.html | 312 // 3- http://mock.http/title2.html |
| 313 // | 313 // |
| 314 // If the redirect in #2 were not blocked, we'd also see a request | 314 // If the redirect in #2 were not blocked, we'd also see a request |
| 315 // for http://mock.http:4000/title2.html, and the title would be different. | 315 // for http://mock.http:4000/title2.html, and the title would be different. |
| 316 CheckTitleTest(L"cross-origin-redirect-blocked.html", | 316 CheckTitleTest(L"cross-origin-redirect-blocked.html", |
| 317 L"Title Of More Awesomeness", 2); | 317 L"Title Of More Awesomeness", 2); |
| 318 } | 318 } |
| 319 | 319 |
| 320 } // namespace | 320 } // namespace |
| OLD | NEW |