OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 CheckTitleTest("content-sniffer-test0.html", | 186 CheckTitleTest("content-sniffer-test0.html", |
187 "Content Sniffer Test 0", 1); | 187 "Content Sniffer Test 0", 1); |
188 | 188 |
189 // Check that the cookie was set. | 189 // Check that the cookie was set. |
190 std::string value_result; | 190 std::string value_result; |
191 ASSERT_TRUE(tab->GetCookieByName(url, "onunloadCookie", &value_result)); | 191 ASSERT_TRUE(tab->GetCookieByName(url, "onunloadCookie", &value_result)); |
192 ASSERT_FALSE(value_result.empty()); | 192 ASSERT_FALSE(value_result.empty()); |
193 ASSERT_STREQ("foo", value_result.c_str()); | 193 ASSERT_STREQ("foo", value_result.c_str()); |
194 } | 194 } |
195 | 195 |
| 196 // Tests that onunload is run for cross-site requests to URLs that complete |
| 197 // without network loads (e.g., about:blank, data URLs). |
| 198 TEST_F(ResourceDispatcherTest, CrossSiteImmediateLoadOnunloadCookie) { |
| 199 net::TestServer test_server(net::TestServer::TYPE_HTTP, |
| 200 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
| 201 ASSERT_TRUE(test_server.Start()); |
| 202 |
| 203 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
| 204 ASSERT_TRUE(browser_proxy.get()); |
| 205 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); |
| 206 ASSERT_TRUE(tab.get()); |
| 207 |
| 208 GURL url(test_server.GetURL("files/onunload_cookie.html")); |
| 209 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(url)); |
| 210 |
| 211 // Confirm that the page has loaded (since it changes its title during load). |
| 212 std::wstring tab_title; |
| 213 EXPECT_TRUE(tab->GetTabTitle(&tab_title)); |
| 214 EXPECT_EQ(L"set cookie on unload", tab_title); |
| 215 |
| 216 // Navigate to a cross-site page that loads immediately without making a |
| 217 // network request. The unload event should still be run. |
| 218 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, |
| 219 tab->NavigateToURL(GURL("about:blank"))); |
| 220 |
| 221 // Check that the cookie was set. |
| 222 std::string value_result; |
| 223 ASSERT_TRUE(tab->GetCookieByName(url, "onunloadCookie", &value_result)); |
| 224 ASSERT_FALSE(value_result.empty()); |
| 225 ASSERT_STREQ("foo", value_result.c_str()); |
| 226 } |
| 227 |
196 // Tests that the unload handler is not run for 204 responses. | 228 // Tests that the unload handler is not run for 204 responses. |
197 TEST_F(ResourceDispatcherTest, CrossSiteNoUnloadOn204) { | 229 TEST_F(ResourceDispatcherTest, CrossSiteNoUnloadOn204) { |
198 net::TestServer test_server(net::TestServer::TYPE_HTTP, | 230 net::TestServer test_server(net::TestServer::TYPE_HTTP, |
199 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | 231 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); |
200 ASSERT_TRUE(test_server.Start()); | 232 ASSERT_TRUE(test_server.Start()); |
201 | 233 |
202 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 234 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
203 ASSERT_TRUE(browser_proxy.get()); | 235 ASSERT_TRUE(browser_proxy.get()); |
204 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); | 236 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); |
205 ASSERT_TRUE(tab.get()); | 237 ASSERT_TRUE(tab.get()); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 GURL broken_url("chrome://theme"); | 391 GURL broken_url("chrome://theme"); |
360 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(broken_url)); | 392 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(broken_url)); |
361 | 393 |
362 // Make sure the navigation finishes. | 394 // Make sure the navigation finishes. |
363 std::wstring tab_title; | 395 std::wstring tab_title; |
364 EXPECT_TRUE(tab->GetTabTitle(&tab_title)); | 396 EXPECT_TRUE(tab->GetTabTitle(&tab_title)); |
365 EXPECT_EQ(L"chrome://theme/ is not available", tab_title); | 397 EXPECT_EQ(L"chrome://theme/ is not available", tab_title); |
366 } | 398 } |
367 | 399 |
368 } // namespace | 400 } // namespace |
OLD | NEW |