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

Side by Side Diff: content/browser/renderer_host/resource_dispatcher_host_browsertest.cc

Issue 10539134: TabContentsWrapper -> TabContents, part 57. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: last use Created 8 years, 6 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/string_util.h" 5 #include "base/string_util.h"
6 #include "base/synchronization/waitable_event.h" 6 #include "base/synchronization/waitable_event.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/ui/browser.h" 8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/test/base/in_process_browser_test.h" 9 #include "chrome/test/base/in_process_browser_test.h"
10 #include "chrome/test/base/ui_test_utils.h" 10 #include "chrome/test/base/ui_test_utils.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 BrowserThread::IO, FROM_HERE, 69 BrowserThread::IO, FROM_HERE,
70 base::Bind(&URLRequestFailedJob::AddUrlHandler)); 70 base::Bind(&URLRequestFailedJob::AddUrlHandler));
71 } 71 }
72 72
73 virtual void ModelChanged(DownloadManager* manager) OVERRIDE { 73 virtual void ModelChanged(DownloadManager* manager) OVERRIDE {
74 if (!got_downloads_) 74 if (!got_downloads_)
75 got_downloads_ = !!manager->InProgressCount(); 75 got_downloads_ = !!manager->InProgressCount();
76 } 76 }
77 77
78 content::RenderViewHost* render_view_host() { 78 content::RenderViewHost* render_view_host() {
79 return browser()->GetSelectedWebContents()->GetRenderViewHost(); 79 return browser()->GetActiveWebContents()->GetRenderViewHost();
80 } 80 }
81 81
82 GURL GetMockURL(const std::string& file) { 82 GURL GetMockURL(const std::string& file) {
83 return URLRequestMockHTTPJob::GetMockUrl(FilePath().AppendASCII(file)); 83 return URLRequestMockHTTPJob::GetMockUrl(FilePath().AppendASCII(file));
84 } 84 }
85 85
86 void CheckTitleTest(const GURL& url, 86 void CheckTitleTest(const GURL& url,
87 const std::string& expected_title, 87 const std::string& expected_title,
88 int expected_navigations) { 88 int expected_navigations) {
89 string16 expected_title16(ASCIIToUTF16(expected_title)); 89 string16 expected_title16(ASCIIToUTF16(expected_title));
90 ui_test_utils::TitleWatcher title_watcher( 90 ui_test_utils::TitleWatcher title_watcher(
91 browser()->GetSelectedWebContents(), expected_title16); 91 browser()->GetActiveWebContents(), expected_title16);
92 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 92 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
93 browser(), url, expected_navigations); 93 browser(), url, expected_navigations);
94 EXPECT_EQ(expected_title16, title_watcher.WaitAndGetTitle()); 94 EXPECT_EQ(expected_title16, title_watcher.WaitAndGetTitle());
95 } 95 }
96 96
97 bool GetPopupTitle(const GURL& url, string16* title); 97 bool GetPopupTitle(const GURL& url, string16* title);
98 98
99 std::string GetCookies(const GURL& url) { 99 std::string GetCookies(const GURL& url) {
100 std::string cookies; 100 std::string cookies;
101 base::WaitableEvent event(true, false); 101 base::WaitableEvent event(true, false);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 210
211 // Test for bug #1091358. 211 // Test for bug #1091358.
212 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, SyncXMLHttpRequest) { 212 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, SyncXMLHttpRequest) {
213 ASSERT_TRUE(test_server()->Start()); 213 ASSERT_TRUE(test_server()->Start());
214 ui_test_utils::NavigateToURL( 214 ui_test_utils::NavigateToURL(
215 browser(), test_server()->GetURL("files/sync_xmlhttprequest.html")); 215 browser(), test_server()->GetURL("files/sync_xmlhttprequest.html"));
216 216
217 // Let's check the XMLHttpRequest ran successfully. 217 // Let's check the XMLHttpRequest ran successfully.
218 bool success = false; 218 bool success = false;
219 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 219 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
220 browser()->GetSelectedWebContents()->GetRenderViewHost(), 220 browser()->GetActiveWebContents()->GetRenderViewHost(),
221 L"", 221 L"",
222 L"window.domAutomationController.send(DidSyncRequestSucceed());", 222 L"window.domAutomationController.send(DidSyncRequestSucceed());",
223 &success)); 223 &success));
224 EXPECT_TRUE(success); 224 EXPECT_TRUE(success);
225 } 225 }
226 226
227 // If this flakes, use http://crbug.com/62776. 227 // If this flakes, use http://crbug.com/62776.
228 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, 228 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest,
229 SyncXMLHttpRequest_Disallowed) { 229 SyncXMLHttpRequest_Disallowed) {
230 ASSERT_TRUE(test_server()->Start()); 230 ASSERT_TRUE(test_server()->Start());
231 ui_test_utils::NavigateToURL( 231 ui_test_utils::NavigateToURL(
232 browser(), 232 browser(),
233 test_server()->GetURL("files/sync_xmlhttprequest_disallowed.html")); 233 test_server()->GetURL("files/sync_xmlhttprequest_disallowed.html"));
234 234
235 // Let's check the XMLHttpRequest ran successfully. 235 // Let's check the XMLHttpRequest ran successfully.
236 bool success = false; 236 bool success = false;
237 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 237 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
238 browser()->GetSelectedWebContents()->GetRenderViewHost(), 238 browser()->GetActiveWebContents()->GetRenderViewHost(),
239 L"", 239 L"",
240 L"window.domAutomationController.send(DidSucceed());", 240 L"window.domAutomationController.send(DidSucceed());",
241 &success)); 241 &success));
242 EXPECT_TRUE(success); 242 EXPECT_TRUE(success);
243 } 243 }
244 244
245 // Test for bug #1159553 -- A synchronous xhr (whose content-type is 245 // Test for bug #1159553 -- A synchronous xhr (whose content-type is
246 // downloadable) would trigger download and hang the renderer process, 246 // downloadable) would trigger download and hang the renderer process,
247 // if executed while navigating to a new page. 247 // if executed while navigating to a new page.
248 // If this flakes, use http://crbug.com/56264. 248 // If this flakes, use http://crbug.com/56264.
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 // Navigate to a new cross-site URL that results in an error page. 379 // Navigate to a new cross-site URL that results in an error page.
380 // TODO(creis): If this causes crashes or hangs, it might be for the same 380 // TODO(creis): If this causes crashes or hangs, it might be for the same
381 // reason as ErrorPageTest::DNSError. See bug 1199491 and 381 // reason as ErrorPageTest::DNSError. See bug 1199491 and
382 // http://crbug.com/22877. 382 // http://crbug.com/22877.
383 GURL failed_url = URLRequestFailedJob::GetMockHttpUrl( 383 GURL failed_url = URLRequestFailedJob::GetMockHttpUrl(
384 net::ERR_NAME_NOT_RESOLVED); 384 net::ERR_NAME_NOT_RESOLVED);
385 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 385 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
386 browser(), failed_url, 2); 386 browser(), failed_url, 2);
387 387
388 EXPECT_NE(ASCIIToUTF16("set cookie on unload"), 388 EXPECT_NE(ASCIIToUTF16("set cookie on unload"),
389 browser()->GetSelectedWebContents()->GetTitle()); 389 browser()->GetActiveWebContents()->GetTitle());
390 390
391 // Check that the cookie was set, meaning that the onunload handler ran. 391 // Check that the cookie was set, meaning that the onunload handler ran.
392 EXPECT_EQ("onunloadCookie=foo", GetCookies(url)); 392 EXPECT_EQ("onunloadCookie=foo", GetCookies(url));
393 393
394 // Check that renderer-initiated navigations still work. In a previous bug, 394 // Check that renderer-initiated navigations still work. In a previous bug,
395 // the ResourceDispatcherHost would think that such navigations were 395 // the ResourceDispatcherHost would think that such navigations were
396 // cross-site, because we didn't clean up from the previous request. Since 396 // cross-site, because we didn't clean up from the previous request. Since
397 // WebContentsImpl was in the NORMAL state, it would ignore the attempt to run 397 // WebContentsImpl was in the NORMAL state, it would ignore the attempt to run
398 // the onunload handler, and the navigation would fail. We can't test by 398 // the onunload handler, and the navigation would fail. We can't test by
399 // redirecting to javascript:window.location='someURL', since javascript: 399 // redirecting to javascript:window.location='someURL', since javascript:
400 // URLs are prohibited by policy from interacting with sensitive chrome 400 // URLs are prohibited by policy from interacting with sensitive chrome
401 // pages of which the error page is one. Instead, use automation to kick 401 // pages of which the error page is one. Instead, use automation to kick
402 // off the navigation, and wait to see that the tab loads. 402 // off the navigation, and wait to see that the tab loads.
403 string16 expected_title16(ASCIIToUTF16("Title Of Awesomeness")); 403 string16 expected_title16(ASCIIToUTF16("Title Of Awesomeness"));
404 ui_test_utils::TitleWatcher title_watcher( 404 ui_test_utils::TitleWatcher title_watcher(
405 browser()->GetSelectedWebContents(), expected_title16); 405 browser()->GetActiveWebContents(), expected_title16);
406 406
407 bool success; 407 bool success;
408 GURL test_url(test_server()->GetURL("files/title2.html")); 408 GURL test_url(test_server()->GetURL("files/title2.html"));
409 std::string redirect_script = "window.location='" + 409 std::string redirect_script = "window.location='" +
410 test_url.possibly_invalid_spec() + "';" + 410 test_url.possibly_invalid_spec() + "';" +
411 "window.domAutomationController.send(true);"; 411 "window.domAutomationController.send(true);";
412 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 412 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
413 browser()->GetSelectedWebContents()->GetRenderViewHost(), 413 browser()->GetActiveWebContents()->GetRenderViewHost(),
414 L"", ASCIIToWide(redirect_script), &success)); 414 L"", ASCIIToWide(redirect_script), &success));
415 EXPECT_EQ(expected_title16, title_watcher.WaitAndGetTitle()); 415 EXPECT_EQ(expected_title16, title_watcher.WaitAndGetTitle());
416 } 416 }
417 417
418 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, 418 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest,
419 CrossOriginRedirectBlocked) { 419 CrossOriginRedirectBlocked) {
420 // We expect the following URL requests from this test: 420 // We expect the following URL requests from this test:
421 // 1- http://mock.http/cross-origin-redirect-blocked.html 421 // 1- http://mock.http/cross-origin-redirect-blocked.html
422 // 2- http://mock.http/redirect-to-title2.html 422 // 2- http://mock.http/redirect-to-title2.html
423 // 3- http://mock.http/title2.html 423 // 3- http://mock.http/title2.html
(...skipping 10 matching lines...) Expand all
434 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, 434 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest,
435 CrossSiteFailedRequest) { 435 CrossSiteFailedRequest) {
436 // Visit another URL first to trigger a cross-site navigation. 436 // Visit another URL first to trigger a cross-site navigation.
437 GURL url(chrome::kTestNewTabURL); 437 GURL url(chrome::kTestNewTabURL);
438 ui_test_utils::NavigateToURL(browser(), url); 438 ui_test_utils::NavigateToURL(browser(), url);
439 439
440 // Visit a URL that fails without calling ResourceDispatcherHost::Read. 440 // Visit a URL that fails without calling ResourceDispatcherHost::Read.
441 GURL broken_url("chrome://theme"); 441 GURL broken_url("chrome://theme");
442 CheckTitleTest(broken_url, "chrome://theme/ is not available", 1); 442 CheckTitleTest(broken_url, "chrome://theme/ is not available", 1);
443 } 443 }
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_view_host_manager_browsertest.cc ('k') | content/browser/session_history_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698