Chromium Code Reviews| Index: chrome/browser/ui/browser_navigator_browsertest.cc |
| =================================================================== |
| --- chrome/browser/ui/browser_navigator_browsertest.cc (revision 215313) |
| +++ chrome/browser/ui/browser_navigator_browsertest.cc (working copy) |
| @@ -4,8 +4,11 @@ |
| #include "chrome/browser/ui/browser_navigator_browsertest.h" |
| +#include <string> |
| + |
| #include "base/command_line.h" |
| #include "base/prefs/pref_service.h" |
| +#include "base/strings/utf_string_conversions.h" |
| #include "chrome/app/chrome_command_ids.h" |
| #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| #include "chrome/browser/profiles/profile.h" |
| @@ -62,7 +65,7 @@ |
| return GURL(url_string); |
| } |
| -} // namespace |
| +} // namespace |
| chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams() const { |
| return MakeNavigateParams(browser()); |
| @@ -1291,4 +1294,37 @@ |
| EXPECT_EQ(-1, chrome::GetIndexOfSingletonTab(&singleton_params)); |
| } |
| -} // namespace |
| +// 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.
|
| +IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, SendRequestUsingPOST) { |
| + const char kExpectedTitle[] = "PASSED!"; |
| + const char kEchoTitleCommand[] = "echotitle"; |
| + // Uses a test sever to verify POST request. |
| + ASSERT_TRUE(test_server()->Start()); |
| + |
| + // Open POST request in new foreground tab. |
| + 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.
|
| + p.disposition = NEW_FOREGROUND_TAB; |
| + p.url = test_server()->GetURL(kEchoTitleCommand); |
| + 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.
|
| + p.uses_post = true; |
| + std::string post_data = kExpectedTitle; |
| + p.browser_initiated_post_data = |
| + base::RefCountedString::TakeString(&post_data); |
| + |
| + string16 expected_title(base::ASCIIToUTF16(kExpectedTitle)); |
| + ui_test_utils::NavigateToURL(&p); |
| + 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.
|
| + // The title should match the post data. |
| + ASSERT_EQ(expected_title, p.target_contents->GetTitle()); |
| + |
| + // Navigate() should have opened the contents in new foreground tab in the |
| + // current Browser. |
| + EXPECT_EQ(browser(), p.browser); |
| + EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(), |
| + p.target_contents); |
| + // We should have one window, with one tab. |
| + EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); |
| + EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
| +} |
| + |
| +} // namespace |