| 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 "chrome/browser/ui/browser_navigator_browsertest.h" | 5 #include "chrome/browser/ui/browser_navigator_browsertest.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
| 27 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
| 28 #include "chrome/test/base/ui_test_utils.h" | 28 #include "chrome/test/base/ui_test_utils.h" |
| 29 #include "components/omnibox/browser/omnibox_view.h" | 29 #include "components/omnibox/browser/omnibox_view.h" |
| 30 #include "components/prefs/pref_service.h" | 30 #include "components/prefs/pref_service.h" |
| 31 #include "content/public/browser/notification_service.h" | 31 #include "content/public/browser/notification_service.h" |
| 32 #include "content/public/browser/notification_types.h" | 32 #include "content/public/browser/notification_types.h" |
| 33 #include "content/public/browser/render_frame_host.h" | 33 #include "content/public/browser/render_frame_host.h" |
| 34 #include "content/public/browser/render_process_host.h" | 34 #include "content/public/browser/render_process_host.h" |
| 35 #include "content/public/browser/web_contents.h" | 35 #include "content/public/browser/web_contents.h" |
| 36 #include "content/public/common/resource_request_body.h" |
| 36 #include "content/public/test/browser_test_utils.h" | 37 #include "content/public/test/browser_test_utils.h" |
| 37 #include "net/test/embedded_test_server/embedded_test_server.h" | 38 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 38 | 39 |
| 39 using content::WebContents; | 40 using content::WebContents; |
| 40 | 41 |
| 41 namespace { | 42 namespace { |
| 42 | 43 |
| 43 const char kExpectedTitle[] = "PASSED!"; | 44 const char kExpectedTitle[] = "PASSED!"; |
| 44 const char kEchoTitleCommand[] = "/echotitle"; | 45 const char kEchoTitleCommand[] = "/echotitle"; |
| 45 | 46 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 } | 89 } |
| 89 | 90 |
| 90 bool BrowserNavigatorTest::OpenPOSTURLInNewForegroundTabAndGetTitle( | 91 bool BrowserNavigatorTest::OpenPOSTURLInNewForegroundTabAndGetTitle( |
| 91 const GURL& url, const std::string& post_data, bool is_browser_initiated, | 92 const GURL& url, const std::string& post_data, bool is_browser_initiated, |
| 92 base::string16* title) { | 93 base::string16* title) { |
| 93 chrome::NavigateParams param(MakeNavigateParams()); | 94 chrome::NavigateParams param(MakeNavigateParams()); |
| 94 param.disposition = NEW_FOREGROUND_TAB; | 95 param.disposition = NEW_FOREGROUND_TAB; |
| 95 param.url = url; | 96 param.url = url; |
| 96 param.is_renderer_initiated = !is_browser_initiated; | 97 param.is_renderer_initiated = !is_browser_initiated; |
| 97 param.uses_post = true; | 98 param.uses_post = true; |
| 98 param.browser_initiated_post_data = new base::RefCountedStaticMemory( | 99 param.post_data = content::ResourceRequestBody::CreateFromBytes(post_data); |
| 99 post_data.data(), post_data.size()); | |
| 100 | 100 |
| 101 ui_test_utils::NavigateToURL(¶m); | 101 ui_test_utils::NavigateToURL(¶m); |
| 102 if (!param.target_contents) | 102 if (!param.target_contents) |
| 103 return false; | 103 return false; |
| 104 | 104 |
| 105 // Navigate() should have opened the contents in new foreground tab in the | 105 // Navigate() should have opened the contents in new foreground tab in the |
| 106 // current Browser. | 106 // current Browser. |
| 107 EXPECT_EQ(browser(), param.browser); | 107 EXPECT_EQ(browser(), param.browser); |
| 108 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(), | 108 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(), |
| 109 param.target_contents); | 109 param.target_contents); |
| (...skipping 1291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1401 // Open a browser initiated POST request in new foreground tab. | 1401 // Open a browser initiated POST request in new foreground tab. |
| 1402 base::string16 expected_title(base::ASCIIToUTF16(kExpectedTitle)); | 1402 base::string16 expected_title(base::ASCIIToUTF16(kExpectedTitle)); |
| 1403 std::string post_data = kExpectedTitle; | 1403 std::string post_data = kExpectedTitle; |
| 1404 base::string16 title; | 1404 base::string16 title; |
| 1405 ASSERT_TRUE(OpenPOSTURLInNewForegroundTabAndGetTitle( | 1405 ASSERT_TRUE(OpenPOSTURLInNewForegroundTabAndGetTitle( |
| 1406 embedded_test_server()->GetURL(kEchoTitleCommand), post_data, true, | 1406 embedded_test_server()->GetURL(kEchoTitleCommand), post_data, true, |
| 1407 &title)); | 1407 &title)); |
| 1408 EXPECT_EQ(expected_title, title); | 1408 EXPECT_EQ(expected_title, title); |
| 1409 } | 1409 } |
| 1410 | 1410 |
| 1411 // This test verifies that renderer initiated navigations can NOT send requests | 1411 // This test verifies that renderer initiated navigations can also send requests |
| 1412 // using POST. | 1412 // using POST. |
| 1413 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, | 1413 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 1414 SendRendererInitiatedRequestUsingPOST) { | 1414 SendRendererInitiatedRequestUsingPOST) { |
| 1415 // Uses a test sever to verify POST request. | 1415 // Uses a test sever to verify POST request. |
| 1416 ASSERT_TRUE(embedded_test_server()->Start()); | 1416 ASSERT_TRUE(embedded_test_server()->Start()); |
| 1417 | 1417 |
| 1418 // Open a renderer initiated POST request in new foreground tab. | 1418 // Open a renderer initiated POST request in new foreground tab. |
| 1419 base::string16 expected_title(base::ASCIIToUTF16(kExpectedTitle)); | 1419 base::string16 expected_title(base::ASCIIToUTF16(kExpectedTitle)); |
| 1420 std::string post_data = kExpectedTitle; | 1420 std::string post_data = kExpectedTitle; |
| 1421 base::string16 title; | 1421 base::string16 title; |
| 1422 ASSERT_TRUE(OpenPOSTURLInNewForegroundTabAndGetTitle( | 1422 ASSERT_TRUE(OpenPOSTURLInNewForegroundTabAndGetTitle( |
| 1423 embedded_test_server()->GetURL(kEchoTitleCommand), post_data, false, | 1423 embedded_test_server()->GetURL(kEchoTitleCommand), post_data, false, |
| 1424 &title)); | 1424 &title)); |
| 1425 EXPECT_NE(expected_title, title); | 1425 EXPECT_EQ(expected_title, title); |
| 1426 } | 1426 } |
| 1427 | 1427 |
| 1428 // This test navigates to a data URL that contains BiDi control | 1428 // This test navigates to a data URL that contains BiDi control |
| 1429 // characters. For security reasons, BiDi control chars should always be | 1429 // characters. For security reasons, BiDi control chars should always be |
| 1430 // escaped in the URL but they should be unescaped in the loaded HTML. | 1430 // escaped in the URL but they should be unescaped in the loaded HTML. |
| 1431 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, | 1431 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, |
| 1432 NavigateToDataURLWithBiDiControlChars) { | 1432 NavigateToDataURLWithBiDiControlChars) { |
| 1433 // Text in Arabic. | 1433 // Text in Arabic. |
| 1434 std::string text = "\xD8\xA7\xD8\xAE\xD8\xAA\xD8\xA8\xD8\xA7\xD8\xB1"; | 1434 std::string text = "\xD8\xA7\xD8\xAE\xD8\xAA\xD8\xA8\xD8\xA7\xD8\xB1"; |
| 1435 // Page title starts with RTL mark. | 1435 // Page title starts with RTL mark. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1454 EXPECT_EQ(expected_title, params.target_contents->GetTitle()); | 1454 EXPECT_EQ(expected_title, params.target_contents->GetTitle()); |
| 1455 // GURL always keeps non-ASCII characters escaped, but check them anyways. | 1455 // GURL always keeps non-ASCII characters escaped, but check them anyways. |
| 1456 EXPECT_EQ(GURL(expected_url).spec(), params.target_contents->GetURL().spec()); | 1456 EXPECT_EQ(GURL(expected_url).spec(), params.target_contents->GetURL().spec()); |
| 1457 // Check the omnibox text. It should have escaped RTL with unescaped text. | 1457 // Check the omnibox text. It should have escaped RTL with unescaped text. |
| 1458 LocationBar* location_bar = browser()->window()->GetLocationBar(); | 1458 LocationBar* location_bar = browser()->window()->GetLocationBar(); |
| 1459 OmniboxView* omnibox_view = location_bar->GetOmniboxView(); | 1459 OmniboxView* omnibox_view = location_bar->GetOmniboxView(); |
| 1460 EXPECT_EQ(base::UTF8ToUTF16(expected_url), omnibox_view->GetText()); | 1460 EXPECT_EQ(base::UTF8ToUTF16(expected_url), omnibox_view->GetText()); |
| 1461 } | 1461 } |
| 1462 | 1462 |
| 1463 } // namespace | 1463 } // namespace |
| OLD | NEW |