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

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

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