Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(223)

Side by Side Diff: chrome/browser/renderer_host/resource_dispatcher_host_uitest.cc

Issue 6312154: Remove wstring from RVH's run Javascript command.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/test/test_timeouts.h" 12 #include "base/test/test_timeouts.h"
13 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/net/url_request_failed_dns_job.h" 14 #include "chrome/browser/net/url_request_failed_dns_job.h"
14 #include "chrome/browser/net/url_request_mock_http_job.h" 15 #include "chrome/browser/net/url_request_mock_http_job.h"
15 #include "chrome/common/url_constants.h" 16 #include "chrome/common/url_constants.h"
16 #include "chrome/test/automation/browser_proxy.h" 17 #include "chrome/test/automation/browser_proxy.h"
17 #include "chrome/test/automation/tab_proxy.h" 18 #include "chrome/test/automation/tab_proxy.h"
18 #include "chrome/test/ui/ui_test.h" 19 #include "chrome/test/ui/ui_test.h"
19 #include "net/base/net_util.h" 20 #include "net/base/net_util.h"
20 #include "net/test/test_server.h" 21 #include "net/test/test_server.h"
21 22
22 namespace { 23 namespace {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); 87 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0));
87 ASSERT_TRUE(browser_proxy.get()); 88 ASSERT_TRUE(browser_proxy.get());
88 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); 89 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab());
89 ASSERT_TRUE(tab.get()); 90 ASSERT_TRUE(tab.get());
90 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, 91 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS,
91 tab->NavigateToURL(test_server.GetURL( 92 tab->NavigateToURL(test_server.GetURL(
92 "files/sync_xmlhttprequest.html"))); 93 "files/sync_xmlhttprequest.html")));
93 94
94 // Let's check the XMLHttpRequest ran successfully. 95 // Let's check the XMLHttpRequest ran successfully.
95 bool success = false; 96 bool success = false;
96 EXPECT_TRUE(tab->ExecuteAndExtractBool(L"", 97 EXPECT_TRUE(tab->ExecuteAndExtractBool(
97 L"window.domAutomationController.send(DidSyncRequestSucceed());", 98 string16(),
99 ASCIIToUTF16("window.domAutomationController.send("
100 "DidSyncRequestSucceed());"),
98 &success)); 101 &success));
99 EXPECT_TRUE(success); 102 EXPECT_TRUE(success);
100 } 103 }
101 104
102 // http://code.google.com/p/chromium/issues/detail?id=62776 105 // http://code.google.com/p/chromium/issues/detail?id=62776
103 TEST_F(ResourceDispatcherTest, FLAKY_SyncXMLHttpRequest_Disallowed) { 106 TEST_F(ResourceDispatcherTest, FLAKY_SyncXMLHttpRequest_Disallowed) {
104 net::TestServer test_server(net::TestServer::TYPE_HTTP, 107 net::TestServer test_server(net::TestServer::TYPE_HTTP,
105 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); 108 FilePath(FILE_PATH_LITERAL("chrome/test/data")));
106 ASSERT_TRUE(test_server.Start()); 109 ASSERT_TRUE(test_server.Start());
107 110
108 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); 111 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0));
109 ASSERT_TRUE(browser_proxy.get()); 112 ASSERT_TRUE(browser_proxy.get());
110 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); 113 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab());
111 ASSERT_TRUE(tab.get()); 114 ASSERT_TRUE(tab.get());
112 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, 115 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS,
113 tab->NavigateToURL(test_server.GetURL( 116 tab->NavigateToURL(test_server.GetURL(
114 "files/sync_xmlhttprequest_disallowed.html"))); 117 "files/sync_xmlhttprequest_disallowed.html")));
115 118
116 // Let's check the XMLHttpRequest ran successfully. 119 // Let's check the XMLHttpRequest ran successfully.
117 bool success = false; 120 bool success = false;
118 EXPECT_TRUE(tab->ExecuteAndExtractBool(L"", 121 EXPECT_TRUE(tab->ExecuteAndExtractBool(
119 L"window.domAutomationController.send(DidSucceed());", 122 string16(),
123 ASCIIToUTF16("window.domAutomationController.send(DidSucceed());"),
120 &success)); 124 &success));
121 EXPECT_TRUE(success); 125 EXPECT_TRUE(success);
122 } 126 }
123 127
124 // Test for bug #1159553 -- A synchronous xhr (whose content-type is 128 // Test for bug #1159553 -- A synchronous xhr (whose content-type is
125 // downloadable) would trigger download and hang the renderer process, 129 // downloadable) would trigger download and hang the renderer process,
126 // if executed while navigating to a new page. 130 // if executed while navigating to a new page.
127 // Disabled -- http://code.google.com/p/chromium/issues/detail?id=56264 131 // Disabled -- http://code.google.com/p/chromium/issues/detail?id=56264
128 TEST_F(ResourceDispatcherTest, DISABLED_SyncXMLHttpRequest_DuringUnload) { 132 TEST_F(ResourceDispatcherTest, DISABLED_SyncXMLHttpRequest_DuringUnload) {
129 net::TestServer test_server(net::TestServer::TYPE_HTTP, 133 net::TestServer test_server(net::TestServer::TYPE_HTTP,
130 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); 134 FilePath(FILE_PATH_LITERAL("chrome/test/data")));
131 ASSERT_TRUE(test_server.Start()); 135 ASSERT_TRUE(test_server.Start());
132 136
133 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); 137 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0));
134 ASSERT_TRUE(browser_proxy.get()); 138 ASSERT_TRUE(browser_proxy.get());
135 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); 139 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab());
136 ASSERT_TRUE(tab.get()); 140 ASSERT_TRUE(tab.get());
137 141
138 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, 142 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS,
139 tab->NavigateToURL(test_server.GetURL( 143 tab->NavigateToURL(test_server.GetURL(
140 "files/sync_xmlhttprequest_during_unload.html"))); 144 "files/sync_xmlhttprequest_during_unload.html")));
141 145
142 // Confirm that the page has loaded (since it changes its title during load). 146 // Confirm that the page has loaded (since it changes its title during load).
143 std::wstring tab_title; 147 string16 tab_title;
144 EXPECT_TRUE(tab->GetTabTitle(&tab_title)); 148 EXPECT_TRUE(tab->GetTabTitle(&tab_title));
145 EXPECT_EQ(L"sync xhr on unload", tab_title); 149 EXPECT_EQ(ASCIIToUTF16("sync xhr on unload"), tab_title);
146 150
147 // Navigate to a new page, to dispatch unload event and trigger xhr. 151 // Navigate to a new page, to dispatch unload event and trigger xhr.
148 // (the bug would make this step hang the renderer). 152 // (the bug would make this step hang the renderer).
149 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, 153 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS,
150 tab->NavigateToURL(test_server.GetURL("files/title2.html"))); 154 tab->NavigateToURL(test_server.GetURL("files/title2.html")));
151 155
152 // Check that the new page got loaded, and that no download was triggered. 156 // Check that the new page got loaded, and that no download was triggered.
153 EXPECT_TRUE(tab->GetTabTitle(&tab_title)); 157 EXPECT_TRUE(tab->GetTabTitle(&tab_title));
154 EXPECT_EQ(L"Title Of Awesomeness", tab_title); 158 EXPECT_EQ(ASCIIToUTF16("Title Of Awesomeness"), tab_title);
155 159
156 bool shelf_is_visible = false; 160 bool shelf_is_visible = false;
157 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); 161 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
158 ASSERT_TRUE(browser.get()); 162 ASSERT_TRUE(browser.get());
159 EXPECT_TRUE(browser->IsShelfVisible(&shelf_is_visible)); 163 EXPECT_TRUE(browser->IsShelfVisible(&shelf_is_visible));
160 EXPECT_FALSE(shelf_is_visible); 164 EXPECT_FALSE(shelf_is_visible);
161 } 165 }
162 166
163 // Tests that onunload is run for cross-site requests. (Bug 1114994) 167 // Tests that onunload is run for cross-site requests. (Bug 1114994)
164 TEST_F(ResourceDispatcherTest, CrossSiteOnunloadCookie) { 168 TEST_F(ResourceDispatcherTest, CrossSiteOnunloadCookie) {
165 net::TestServer test_server(net::TestServer::TYPE_HTTP, 169 net::TestServer test_server(net::TestServer::TYPE_HTTP,
166 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); 170 FilePath(FILE_PATH_LITERAL("chrome/test/data")));
167 ASSERT_TRUE(test_server.Start()); 171 ASSERT_TRUE(test_server.Start());
168 172
169 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); 173 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0));
170 ASSERT_TRUE(browser_proxy.get()); 174 ASSERT_TRUE(browser_proxy.get());
171 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); 175 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab());
172 ASSERT_TRUE(tab.get()); 176 ASSERT_TRUE(tab.get());
173 177
174 GURL url(test_server.GetURL("files/onunload_cookie.html")); 178 GURL url(test_server.GetURL("files/onunload_cookie.html"));
175 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(url)); 179 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(url));
176 180
177 // Confirm that the page has loaded (since it changes its title during load). 181 // Confirm that the page has loaded (since it changes its title during load).
178 std::wstring tab_title; 182 string16 tab_title;
179 EXPECT_TRUE(tab->GetTabTitle(&tab_title)); 183 EXPECT_TRUE(tab->GetTabTitle(&tab_title));
180 EXPECT_EQ(L"set cookie on unload", tab_title); 184 EXPECT_EQ(ASCIIToUTF16("set cookie on unload"), tab_title);
181 185
182 // Navigate to a new cross-site page, to dispatch unload event and set the 186 // Navigate to a new cross-site page, to dispatch unload event and set the
183 // cookie. 187 // cookie.
184 CheckTitleTest(L"content-sniffer-test0.html", 188 CheckTitleTest(L"content-sniffer-test0.html",
185 L"Content Sniffer Test 0", 1); 189 L"Content Sniffer Test 0", 1);
186 190
187 // Check that the cookie was set. 191 // Check that the cookie was set.
188 std::string value_result; 192 std::string value_result;
189 ASSERT_TRUE(tab->GetCookieByName(url, "onunloadCookie", &value_result)); 193 ASSERT_TRUE(tab->GetCookieByName(url, "onunloadCookie", &value_result));
190 ASSERT_FALSE(value_result.empty()); 194 ASSERT_FALSE(value_result.empty());
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 260
257 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); 261 scoped_refptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0));
258 ASSERT_TRUE(browser_proxy.get()); 262 ASSERT_TRUE(browser_proxy.get());
259 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab()); 263 scoped_refptr<TabProxy> tab(browser_proxy->GetActiveTab());
260 ASSERT_TRUE(tab.get()); 264 ASSERT_TRUE(tab.get());
261 265
262 GURL url(test_server.GetURL("files/onunload_cookie.html")); 266 GURL url(test_server.GetURL("files/onunload_cookie.html"));
263 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(url)); 267 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(url));
264 268
265 // Confirm that the page has loaded (since it changes its title during load). 269 // Confirm that the page has loaded (since it changes its title during load).
266 std::wstring tab_title; 270 string16 tab_title;
267 EXPECT_TRUE(tab->GetTabTitle(&tab_title)); 271 EXPECT_TRUE(tab->GetTabTitle(&tab_title));
268 EXPECT_EQ(L"set cookie on unload", tab_title); 272 EXPECT_EQ(ASCIIToUTF16("set cookie on unload"), tab_title);
269 273
270 // Navigate to a new cross-site URL that results in an error page. 274 // Navigate to a new cross-site URL that results in an error page.
271 // TODO(creis): If this causes crashes or hangs, it might be for the same 275 // TODO(creis): If this causes crashes or hangs, it might be for the same
272 // reason as ErrorPageTest::DNSError. See bug 1199491 and 276 // reason as ErrorPageTest::DNSError. See bug 1199491 and
273 // http://crbug.com/22877. 277 // http://crbug.com/22877.
274 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, 278 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS,
275 tab->NavigateToURLBlockUntilNavigationsComplete( 279 tab->NavigateToURLBlockUntilNavigationsComplete(
276 GURL(URLRequestFailedDnsJob::kTestUrl), 2)); 280 GURL(URLRequestFailedDnsJob::kTestUrl), 2));
277 EXPECT_NE(L"set cookie on unload", GetActiveTabTitle()); 281 EXPECT_NE(L"set cookie on unload", GetActiveTabTitle());
278 282
279 // Check that the cookie was set, meaning that the onunload handler ran. 283 // Check that the cookie was set, meaning that the onunload handler ran.
280 std::string value_result; 284 std::string value_result;
281 EXPECT_TRUE(tab->GetCookieByName(url, "onunloadCookie", &value_result)); 285 EXPECT_TRUE(tab->GetCookieByName(url, "onunloadCookie", &value_result));
282 EXPECT_FALSE(value_result.empty()); 286 EXPECT_FALSE(value_result.empty());
283 EXPECT_STREQ("foo", value_result.c_str()); 287 EXPECT_STREQ("foo", value_result.c_str());
284 288
285 // Check that renderer-initiated navigations still work. In a previous bug, 289 // Check that renderer-initiated navigations still work. In a previous bug,
286 // the ResourceDispatcherHost would think that such navigations were 290 // the ResourceDispatcherHost would think that such navigations were
287 // cross-site, because we didn't clean up from the previous request. Since 291 // cross-site, because we didn't clean up from the previous request. Since
288 // TabContents was in the NORMAL state, it would ignore the attempt to run 292 // TabContents was in the NORMAL state, it would ignore the attempt to run
289 // the onunload handler, and the navigation would fail. 293 // the onunload handler, and the navigation would fail.
290 // (Test by redirecting to javascript:window.location='someURL'.) 294 // (Test by redirecting to javascript:window.location='someURL'.)
291 GURL test_url(test_server.GetURL("files/title2.html")); 295 GURL test_url(test_server.GetURL("files/title2.html"));
292 std::string redirect_url = "javascript:window.location='" + 296 std::string redirect_url = "javascript:window.location='" +
293 test_url.possibly_invalid_spec() + "'"; 297 test_url.possibly_invalid_spec() + "'";
294 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, 298 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS,
295 tab->NavigateToURL(GURL(redirect_url))); 299 tab->NavigateToURL(GURL(redirect_url)));
296 EXPECT_TRUE(tab->GetTabTitle(&tab_title)); 300 EXPECT_TRUE(tab->GetTabTitle(&tab_title));
297 EXPECT_EQ(L"Title Of Awesomeness", tab_title); 301 EXPECT_EQ(ASCIIToUTF16("Title Of Awesomeness"), tab_title);
298 } 302 }
299 303
300 TEST_F(ResourceDispatcherTest, CrossOriginRedirectBlocked) { 304 TEST_F(ResourceDispatcherTest, CrossOriginRedirectBlocked) {
301 // We expect the following URL requests from this test: 305 // We expect the following URL requests from this test:
302 // 1- http://mock.http/cross-origin-redirect-blocked.html 306 // 1- http://mock.http/cross-origin-redirect-blocked.html
303 // 2- http://mock.http/redirect-to-title2.html 307 // 2- http://mock.http/redirect-to-title2.html
304 // 3- http://mock.http/title2.html 308 // 3- http://mock.http/title2.html
305 // 309 //
306 // If the redirect in #2 were not blocked, we'd also see a request 310 // If the redirect in #2 were not blocked, we'd also see a request
307 // for http://mock.http:4000/title2.html, and the title would be different. 311 // for http://mock.http:4000/title2.html, and the title would be different.
(...skipping 12 matching lines...) Expand all
320 324
321 // Visit another URL first to trigger a cross-site navigation. 325 // Visit another URL first to trigger a cross-site navigation.
322 GURL url(chrome::kChromeUINewTabURL); 326 GURL url(chrome::kChromeUINewTabURL);
323 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(url)); 327 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(url));
324 328
325 // Visit a URL that fails without calling ResourceDispatcherHost::Read. 329 // Visit a URL that fails without calling ResourceDispatcherHost::Read.
326 GURL broken_url("chrome://theme"); 330 GURL broken_url("chrome://theme");
327 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(broken_url)); 331 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(broken_url));
328 332
329 // Make sure the navigation finishes. 333 // Make sure the navigation finishes.
330 std::wstring tab_title; 334 string16 tab_title;
331 EXPECT_TRUE(tab->GetTabTitle(&tab_title)); 335 EXPECT_TRUE(tab->GetTabTitle(&tab_title));
332 EXPECT_EQ(L"chrome://theme/ is not available", tab_title); 336 EXPECT_EQ(ASCIIToUTF16("chrome://theme/ is not available"), tab_title);
333 } 337 }
334 338
335 } // namespace 339 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698