| OLD | NEW |
| 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/browser/ui/browser_tabstrip.h" |
| 10 #include "chrome/test/base/in_process_browser_test.h" | 10 #include "chrome/test/base/in_process_browser_test.h" |
| 11 #include "chrome/test/base/ui_test_utils.h" | 11 #include "chrome/test/base/ui_test_utils.h" |
| 12 #include "content/browser/download/download_manager_impl.h" | 12 #include "content/browser/download/download_manager_impl.h" |
| 13 #include "content/browser/web_contents/web_contents_impl.h" | 13 #include "content/browser/web_contents/web_contents_impl.h" |
| 14 #include "content/common/test_url_constants.h" | 14 #include "content/common/test_url_constants.h" |
| 15 #include "content/public/browser/browser_context.h" | 15 #include "content/public/browser/browser_context.h" |
| 16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
| 18 #include "content/public/browser/notification_types.h" | 18 #include "content/public/browser/notification_types.h" |
| 19 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 20 #include "content/public/common/url_constants.h" | 20 #include "content/public/common/url_constants.h" |
| 21 #include "content/public/test/browser_test_utils.h" |
| 21 #include "content/test/net/url_request_failed_job.h" | 22 #include "content/test/net/url_request_failed_job.h" |
| 22 #include "content/test/net/url_request_mock_http_job.h" | 23 #include "content/test/net/url_request_mock_http_job.h" |
| 23 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
| 24 #include "net/cookies/cookie_store.h" | 25 #include "net/cookies/cookie_store.h" |
| 25 #include "net/test/test_server.h" | 26 #include "net/test/test_server.h" |
| 26 #include "net/url_request/url_request_context.h" | 27 #include "net/url_request/url_request_context.h" |
| 27 #include "net/url_request/url_request_context_getter.h" | 28 #include "net/url_request/url_request_context_getter.h" |
| 28 | 29 |
| 29 using content::BrowserContext; | 30 using content::BrowserContext; |
| 30 using content::BrowserThread; | 31 using content::BrowserThread; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 } | 80 } |
| 80 | 81 |
| 81 GURL GetMockURL(const std::string& file) { | 82 GURL GetMockURL(const std::string& file) { |
| 82 return URLRequestMockHTTPJob::GetMockUrl(FilePath().AppendASCII(file)); | 83 return URLRequestMockHTTPJob::GetMockUrl(FilePath().AppendASCII(file)); |
| 83 } | 84 } |
| 84 | 85 |
| 85 void CheckTitleTest(const GURL& url, | 86 void CheckTitleTest(const GURL& url, |
| 86 const std::string& expected_title, | 87 const std::string& expected_title, |
| 87 int expected_navigations) { | 88 int expected_navigations) { |
| 88 string16 expected_title16(ASCIIToUTF16(expected_title)); | 89 string16 expected_title16(ASCIIToUTF16(expected_title)); |
| 89 ui_test_utils::TitleWatcher title_watcher( | 90 content::TitleWatcher title_watcher( |
| 90 chrome::GetActiveWebContents(browser()), expected_title16); | 91 chrome::GetActiveWebContents(browser()), expected_title16); |
| 91 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 92 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 92 browser(), url, expected_navigations); | 93 browser(), url, expected_navigations); |
| 93 EXPECT_EQ(expected_title16, title_watcher.WaitAndGetTitle()); | 94 EXPECT_EQ(expected_title16, title_watcher.WaitAndGetTitle()); |
| 94 } | 95 } |
| 95 | 96 |
| 96 bool GetPopupTitle(const GURL& url, string16* title); | 97 bool GetPopupTitle(const GURL& url, string16* title); |
| 97 | 98 |
| 98 std::string GetCookies(const GURL& url) { | 99 std::string GetCookies(const GURL& url) { |
| 99 std::string cookies; | 100 std::string cookies; |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 // Check that renderer-initiated navigations still work. In a previous bug, | 394 // Check that renderer-initiated navigations still work. In a previous bug, |
| 394 // the ResourceDispatcherHost would think that such navigations were | 395 // the ResourceDispatcherHost would think that such navigations were |
| 395 // 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 |
| 396 // 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 |
| 397 // 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 |
| 398 // redirecting to javascript:window.location='someURL', since javascript: | 399 // redirecting to javascript:window.location='someURL', since javascript: |
| 399 // URLs are prohibited by policy from interacting with sensitive chrome | 400 // URLs are prohibited by policy from interacting with sensitive chrome |
| 400 // 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 |
| 401 // off the navigation, and wait to see that the tab loads. | 402 // off the navigation, and wait to see that the tab loads. |
| 402 string16 expected_title16(ASCIIToUTF16("Title Of Awesomeness")); | 403 string16 expected_title16(ASCIIToUTF16("Title Of Awesomeness")); |
| 403 ui_test_utils::TitleWatcher title_watcher( | 404 content::TitleWatcher title_watcher( |
| 404 chrome::GetActiveWebContents(browser()), expected_title16); | 405 chrome::GetActiveWebContents(browser()), expected_title16); |
| 405 | 406 |
| 406 bool success; | 407 bool success; |
| 407 GURL test_url(test_server()->GetURL("files/title2.html")); | 408 GURL test_url(test_server()->GetURL("files/title2.html")); |
| 408 std::string redirect_script = "window.location='" + | 409 std::string redirect_script = "window.location='" + |
| 409 test_url.possibly_invalid_spec() + "';" + | 410 test_url.possibly_invalid_spec() + "';" + |
| 410 "window.domAutomationController.send(true);"; | 411 "window.domAutomationController.send(true);"; |
| 411 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 412 EXPECT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 412 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), | 413 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), |
| 413 L"", ASCIIToWide(redirect_script), &success)); | 414 L"", ASCIIToWide(redirect_script), &success)); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, | 460 IN_PROC_BROWSER_TEST_F(ResourceDispatcherHostBrowserTest, |
| 460 CrossSiteFailedRequest) { | 461 CrossSiteFailedRequest) { |
| 461 // Visit another URL first to trigger a cross-site navigation. | 462 // Visit another URL first to trigger a cross-site navigation. |
| 462 GURL url(content::kTestNewTabURL); | 463 GURL url(content::kTestNewTabURL); |
| 463 ui_test_utils::NavigateToURL(browser(), url); | 464 ui_test_utils::NavigateToURL(browser(), url); |
| 464 | 465 |
| 465 // Visit a URL that fails without calling ResourceDispatcherHost::Read. | 466 // Visit a URL that fails without calling ResourceDispatcherHost::Read. |
| 466 GURL broken_url("chrome://theme"); | 467 GURL broken_url("chrome://theme"); |
| 467 CheckTitleTest(broken_url, "chrome://theme/ is not available", 1); | 468 CheckTitleTest(broken_url, "chrome://theme/ is not available", 1); |
| 468 } | 469 } |
| OLD | NEW |