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