| 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_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 class ResourceDispatcherTest : public UITest { | 23 class ResourceDispatcherTest : public UITest { |
| 24 public: | 24 public: |
| 25 void CheckTitleTest(const std::wstring& file, | 25 void CheckTitleTest(const std::wstring& file, |
| 26 const std::wstring& expected_title) { | 26 const std::wstring& expected_title) { |
| 27 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(file)); | 27 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 28 const int kCheckDelayMs = 100; | 28 const int kCheckDelayMs = 100; |
| 29 int max_wait_time = 5000; | 29 int max_wait_time = 5000; |
| 30 while (max_wait_time > 0) { | 30 while (max_wait_time > 0) { |
| 31 max_wait_time -= kCheckDelayMs; | 31 max_wait_time -= kCheckDelayMs; |
| 32 Sleep(kCheckDelayMs); | 32 PlatformThread::Sleep(kCheckDelayMs); |
| 33 if (expected_title == GetActiveTabTitle()) | 33 if (expected_title == GetActiveTabTitle()) |
| 34 break; | 34 break; |
| 35 } | 35 } |
| 36 | 36 |
| 37 EXPECT_EQ(expected_title, GetActiveTabTitle()); | 37 EXPECT_EQ(expected_title, GetActiveTabTitle()); |
| 38 } | 38 } |
| 39 | 39 |
| 40 protected: | 40 protected: |
| 41 ResourceDispatcherTest() : UITest() { | 41 ResourceDispatcherTest() : UITest() { |
| 42 dom_automation_enabled_ = true; | 42 dom_automation_enabled_ = true; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 58 CheckTitleTest(L"content-sniffer-test1.html", L""); | 58 CheckTitleTest(L"content-sniffer-test1.html", L""); |
| 59 } | 59 } |
| 60 | 60 |
| 61 TEST_F(ResourceDispatcherTest, DoNotSniffHTMLFromImageGIF) { | 61 TEST_F(ResourceDispatcherTest, DoNotSniffHTMLFromImageGIF) { |
| 62 CheckTitleTest(L"content-sniffer-test2.html", L""); | 62 CheckTitleTest(L"content-sniffer-test2.html", L""); |
| 63 } | 63 } |
| 64 | 64 |
| 65 TEST_F(ResourceDispatcherTest, SniffNoContentTypeNoData) { | 65 TEST_F(ResourceDispatcherTest, SniffNoContentTypeNoData) { |
| 66 CheckTitleTest(L"content-sniffer-test3.html", | 66 CheckTitleTest(L"content-sniffer-test3.html", |
| 67 L"Content Sniffer Test 3"); | 67 L"Content Sniffer Test 3"); |
| 68 Sleep(sleep_timeout_ms() * 2); | 68 PlatformThread::Sleep(sleep_timeout_ms() * 2); |
| 69 EXPECT_EQ(1, GetTabCount()); | 69 EXPECT_EQ(1, GetTabCount()); |
| 70 | 70 |
| 71 // Make sure the download shelf is not showing. | 71 // Make sure the download shelf is not showing. |
| 72 scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | 72 scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
| 73 scoped_ptr<TabProxy> dl_tab(browser->GetTab(0)); | 73 scoped_ptr<TabProxy> dl_tab(browser->GetTab(0)); |
| 74 ASSERT_TRUE(dl_tab.get()); | 74 ASSERT_TRUE(dl_tab.get()); |
| 75 | 75 |
| 76 bool visible = false; | 76 bool visible = false; |
| 77 ASSERT_TRUE(dl_tab->IsShelfVisible(&visible)); | 77 ASSERT_TRUE(dl_tab->IsShelfVisible(&visible)); |
| 78 EXPECT_FALSE(visible); | 78 EXPECT_FALSE(visible); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 if (in_process_renderer()) | 203 if (in_process_renderer()) |
| 204 return; | 204 return; |
| 205 | 205 |
| 206 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); | 206 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); |
| 207 EXPECT_TRUE(browser_proxy.get()); | 207 EXPECT_TRUE(browser_proxy.get()); |
| 208 scoped_ptr<TabProxy> tab(browser_proxy->GetActiveTab()); | 208 scoped_ptr<TabProxy> tab(browser_proxy->GetActiveTab()); |
| 209 | 209 |
| 210 // Cause the renderer to crash. | 210 // Cause the renderer to crash. |
| 211 expected_crashes_ = 1; | 211 expected_crashes_ = 1; |
| 212 tab->NavigateToURLAsync(GURL("about:crash")); | 212 tab->NavigateToURLAsync(GURL("about:crash")); |
| 213 Sleep(sleep_timeout_ms()); // Wait for browser to notice the renderer crash. | 213 // Wait for browser to notice the renderer crash. |
| 214 PlatformThread::Sleep(sleep_timeout_ms()); |
| 214 | 215 |
| 215 // Navigate to a new cross-site page. The browser should not wait around for | 216 // Navigate to a new cross-site page. The browser should not wait around for |
| 216 // the old renderer's on{before}unload handlers to run. | 217 // the old renderer's on{before}unload handlers to run. |
| 217 CheckTitleTest(L"content-sniffer-test0.html", | 218 CheckTitleTest(L"content-sniffer-test0.html", |
| 218 L"Content Sniffer Test 0"); | 219 L"Content Sniffer Test 0"); |
| 219 } | 220 } |
| 220 | 221 |
| 221 // Tests that cross-site navigations work when the new page does not go through | 222 // Tests that cross-site navigations work when the new page does not go through |
| 222 // the BufferedEventHandler (e.g., non-http{s} URLs). (Bug 1225872) | 223 // the BufferedEventHandler (e.g., non-http{s} URLs). (Bug 1225872) |
| 223 TEST_F(ResourceDispatcherTest, CrossSiteNavigationNonBuffered) { | 224 TEST_F(ResourceDispatcherTest, CrossSiteNavigationNonBuffered) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 std::wstring tab_title; | 262 std::wstring tab_title; |
| 262 EXPECT_TRUE(tab->GetTabTitle(&tab_title)); | 263 EXPECT_TRUE(tab->GetTabTitle(&tab_title)); |
| 263 EXPECT_EQ(L"set cookie on unload", tab_title); | 264 EXPECT_EQ(L"set cookie on unload", tab_title); |
| 264 | 265 |
| 265 // Navigate to a new cross-site URL that results in an error page. We must | 266 // Navigate to a new cross-site URL that results in an error page. We must |
| 266 // wait for the error page to update the title. | 267 // wait for the error page to update the title. |
| 267 // TODO(creis): If this causes crashes or hangs, it might be for the same | 268 // TODO(creis): If this causes crashes or hangs, it might be for the same |
| 268 // reason as ErrorPageTest::DNSError. See bug 1199491. | 269 // reason as ErrorPageTest::DNSError. See bug 1199491. |
| 269 tab->NavigateToURL(GURL(URLRequestFailedDnsJob::kTestUrl)); | 270 tab->NavigateToURL(GURL(URLRequestFailedDnsJob::kTestUrl)); |
| 270 for (int i = 0; i < 10; ++i) { | 271 for (int i = 0; i < 10; ++i) { |
| 271 Sleep(sleep_timeout_ms()); | 272 PlatformThread::Sleep(sleep_timeout_ms()); |
| 272 if (GetActiveTabTitle() != L"set cookie on unload") { | 273 if (GetActiveTabTitle() != L"set cookie on unload") { |
| 273 // Success, bail out. | 274 // Success, bail out. |
| 274 break; | 275 break; |
| 275 } | 276 } |
| 276 } | 277 } |
| 277 EXPECT_NE(L"set cookie on unload", GetActiveTabTitle()); | 278 EXPECT_NE(L"set cookie on unload", GetActiveTabTitle()); |
| 278 | 279 |
| 279 // Check that the cookie was set, meaning that the onunload handler ran. | 280 // Check that the cookie was set, meaning that the onunload handler ran. |
| 280 std::string value_result; | 281 std::string value_result; |
| 281 EXPECT_TRUE(tab->GetCookieByName(url, "onunloadCookie", &value_result)); | 282 EXPECT_TRUE(tab->GetCookieByName(url, "onunloadCookie", &value_result)); |
| 282 EXPECT_FALSE(value_result.empty()); | 283 EXPECT_FALSE(value_result.empty()); |
| 283 EXPECT_STREQ("foo", value_result.c_str()); | 284 EXPECT_STREQ("foo", value_result.c_str()); |
| 284 | 285 |
| 285 // Check that renderer-initiated navigations still work. In a previous bug, | 286 // Check that renderer-initiated navigations still work. In a previous bug, |
| 286 // the ResourceDispatcherHost would think that such navigations were | 287 // the ResourceDispatcherHost would think that such navigations were |
| 287 // cross-site, because we didn't clean up from the previous request. Since | 288 // cross-site, because we didn't clean up from the previous request. Since |
| 288 // WebContents was in the NORMAL state, it would ignore the attempt to run | 289 // WebContents was in the NORMAL state, it would ignore the attempt to run |
| 289 // the onunload handler, and the navigation would fail. | 290 // the onunload handler, and the navigation would fail. |
| 290 // (Test by redirecting to javascript:window.location='someURL'.) | 291 // (Test by redirecting to javascript:window.location='someURL'.) |
| 291 GURL test_url(server->TestServerPageW(L"files/title2.html")); | 292 GURL test_url(server->TestServerPageW(L"files/title2.html")); |
| 292 std::wstring redirect_url = L"javascript:window.location='" + | 293 std::string redirect_url = "javascript:window.location='" + |
| 293 ASCIIToWide(test_url.possibly_invalid_spec()) + L"'"; | 294 test_url.possibly_invalid_spec() + "'"; |
| 294 tab->NavigateToURLAsync(GURL(redirect_url)); | 295 tab->NavigateToURLAsync(GURL(redirect_url)); |
| 295 Sleep(sleep_timeout_ms()); // Wait for JavaScript redirect to happen. | 296 // Wait for JavaScript redirect to happen. |
| 297 PlatformThread::Sleep(sleep_timeout_ms()); |
| 296 EXPECT_TRUE(tab->GetTabTitle(&tab_title)); | 298 EXPECT_TRUE(tab->GetTabTitle(&tab_title)); |
| 297 EXPECT_EQ(L"Title Of Awesomeness", tab_title); | 299 EXPECT_EQ(L"Title Of Awesomeness", tab_title); |
| 298 } | 300 } |
| OLD | NEW |