Chromium Code Reviews| 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 <string> | |
| 8 | |
| 7 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 8 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 11 #include "base/strings/utf_string_conversions.h" | |
| 9 #include "chrome/app/chrome_command_ids.h" | 12 #include "chrome/app/chrome_command_ids.h" |
| 10 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 13 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/browser_commands.h" | 16 #include "chrome/browser/ui/browser_commands.h" |
| 14 #include "chrome/browser/ui/browser_finder.h" | 17 #include "chrome/browser/ui/browser_finder.h" |
| 15 #include "chrome/browser/ui/browser_navigator.h" | 18 #include "chrome/browser/ui/browser_navigator.h" |
| 16 #include "chrome/browser/ui/browser_tabstrip.h" | 19 #include "chrome/browser/ui/browser_tabstrip.h" |
| 17 #include "chrome/browser/ui/browser_window.h" | 20 #include "chrome/browser/ui/browser_window.h" |
| 18 #include "chrome/browser/ui/chrome_pages.h" | 21 #include "chrome/browser/ui/chrome_pages.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 GURL ShortenUberURL(const GURL& url) { | 58 GURL ShortenUberURL(const GURL& url) { |
| 56 std::string url_string = url.spec(); | 59 std::string url_string = url.spec(); |
| 57 const std::string long_prefix = "chrome://chrome/"; | 60 const std::string long_prefix = "chrome://chrome/"; |
| 58 const std::string short_prefix = "chrome://"; | 61 const std::string short_prefix = "chrome://"; |
| 59 if (url_string.find(long_prefix) != 0) | 62 if (url_string.find(long_prefix) != 0) |
| 60 return url; | 63 return url; |
| 61 url_string.replace(0, long_prefix.length(), short_prefix); | 64 url_string.replace(0, long_prefix.length(), short_prefix); |
| 62 return GURL(url_string); | 65 return GURL(url_string); |
| 63 } | 66 } |
| 64 | 67 |
| 65 } // namespace | 68 } // namespace |
| 66 | 69 |
| 67 chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams() const { | 70 chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams() const { |
| 68 return MakeNavigateParams(browser()); | 71 return MakeNavigateParams(browser()); |
| 69 } | 72 } |
| 70 | 73 |
| 71 chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams( | 74 chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams( |
| 72 Browser* browser) const { | 75 Browser* browser) const { |
| 73 chrome::NavigateParams params(browser, GetGoogleURL(), | 76 chrome::NavigateParams params(browser, GetGoogleURL(), |
| 74 content::PAGE_TRANSITION_LINK); | 77 content::PAGE_TRANSITION_LINK); |
| 75 params.window_action = chrome::NavigateParams::SHOW_WINDOW; | 78 params.window_action = chrome::NavigateParams::SHOW_WINDOW; |
| (...skipping 1208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1284 content::PAGE_TRANSITION_LINK); | 1287 content::PAGE_TRANSITION_LINK); |
| 1285 ui_test_utils::NavigateToURL(&viewsource_params); | 1288 ui_test_utils::NavigateToURL(&viewsource_params); |
| 1286 | 1289 |
| 1287 chrome::NavigateParams singleton_params(browser(), | 1290 chrome::NavigateParams singleton_params(browser(), |
| 1288 GURL(chrome::kChromeUIVersionURL), | 1291 GURL(chrome::kChromeUIVersionURL), |
| 1289 content::PAGE_TRANSITION_LINK); | 1292 content::PAGE_TRANSITION_LINK); |
| 1290 singleton_params.disposition = SINGLETON_TAB; | 1293 singleton_params.disposition = SINGLETON_TAB; |
| 1291 EXPECT_EQ(-1, chrome::GetIndexOfSingletonTab(&singleton_params)); | 1294 EXPECT_EQ(-1, chrome::GetIndexOfSingletonTab(&singleton_params)); |
| 1292 } | 1295 } |
| 1293 | 1296 |
| 1294 } // namespace | 1297 // This test verifies that navigation can send request using POST. |
|
Charlie Reis
2013/08/02 23:53:43
nit: s/navigation/browser initiated navigations/
s
Johnny(Jianning) Ding
2013/08/03 01:11:17
Done.
| |
| 1298 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, SendRequestUsingPOST) { | |
| 1299 const char kExpectedTitle[] = "PASSED!"; | |
| 1300 const char kEchoTitleCommand[] = "echotitle"; | |
| 1301 // Uses a test sever to verify POST request. | |
| 1302 ASSERT_TRUE(test_server()->Start()); | |
| 1303 | |
| 1304 // Open POST request in new foreground tab. | |
| 1305 chrome::NavigateParams p(MakeNavigateParams()); | |
|
Charlie Reis
2013/08/02 23:53:43
nit: s/p/params/
Johnny(Jianning) Ding
2013/08/03 01:11:17
Done.
| |
| 1306 p.disposition = NEW_FOREGROUND_TAB; | |
| 1307 p.url = test_server()->GetURL(kEchoTitleCommand); | |
| 1308 LOG(INFO) << p.url.spec(); | |
|
Charlie Reis
2013/08/02 23:53:43
Probably best to remove this log statement unless
Johnny(Jianning) Ding
2013/08/03 01:11:17
Done.
| |
| 1309 p.uses_post = true; | |
| 1310 std::string post_data = kExpectedTitle; | |
| 1311 p.browser_initiated_post_data = | |
| 1312 base::RefCountedString::TakeString(&post_data); | |
| 1313 | |
| 1314 string16 expected_title(base::ASCIIToUTF16(kExpectedTitle)); | |
| 1315 ui_test_utils::NavigateToURL(&p); | |
| 1316 ASSERT_TRUE(p.target_contents != NULL); | |
|
Charlie Reis
2013/08/02 23:53:43
nit: Don't need != NULL
Johnny(Jianning) Ding
2013/08/03 01:11:17
Done.
| |
| 1317 // The title should match the post data. | |
| 1318 ASSERT_EQ(expected_title, p.target_contents->GetTitle()); | |
| 1319 | |
| 1320 // Navigate() should have opened the contents in new foreground tab in the | |
| 1321 // current Browser. | |
| 1322 EXPECT_EQ(browser(), p.browser); | |
| 1323 EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(), | |
| 1324 p.target_contents); | |
| 1325 // We should have one window, with one tab. | |
| 1326 EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); | |
| 1327 EXPECT_EQ(2, browser()->tab_strip_model()->count()); | |
| 1328 } | |
| 1329 | |
| 1330 } // namespace | |
| OLD | NEW |