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

Unified Diff: chrome/browser/ui/browser_navigator_browsertest.cc

Issue 21378002: Support POST in browser navaigation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: move PageNavigator Destructor body back Created 7 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/browser_navigator_browsertest.h ('k') | content/public/browser/page_navigator.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/browser_navigator_browsertest.cc
===================================================================
--- chrome/browser/ui/browser_navigator_browsertest.cc (revision 215511)
+++ chrome/browser/ui/browser_navigator_browsertest.cc (working copy)
@@ -6,6 +6,7 @@
#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"
@@ -32,6 +33,9 @@
namespace {
+const char kExpectedTitle[] = "PASSED!";
+const char kEchoTitleCommand[] = "echotitle";
+
GURL GetGoogleURL() {
return GURL("http://www.google.com/");
}
@@ -62,7 +66,7 @@
return GURL(url_string);
}
-} // namespace
+} // namespace
chrome::NavigateParams BrowserNavigatorTest::MakeNavigateParams() const {
return MakeNavigateParams(browser());
@@ -76,6 +80,34 @@
return params;
}
+bool BrowserNavigatorTest::OpenPOSTURLInNewForegroundTabAndGetTitle(
+ const GURL& url, const std::string& post_data, bool is_browser_initiated,
+ base::string16* title) {
+ chrome::NavigateParams param(MakeNavigateParams());
+ param.disposition = NEW_FOREGROUND_TAB;
+ param.url = url;
+ param.is_renderer_initiated = !is_browser_initiated;
+ param.uses_post = true;
+ param.browser_initiated_post_data = new base::RefCountedStaticMemory(
+ reinterpret_cast<const uint8*>(post_data.data()), post_data.size());
+
+ ui_test_utils::NavigateToURL(&param);
+ if (!param.target_contents)
+ return false;
+
+ // Navigate() should have opened the contents in new foreground tab in the
+ // current Browser.
+ EXPECT_EQ(browser(), param.browser);
+ EXPECT_EQ(browser()->tab_strip_model()->GetActiveWebContents(),
+ param.target_contents);
+ // We should have one window, with one tab.
+ EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
+ EXPECT_EQ(2, browser()->tab_strip_model()->count());
+
+ *title = param.target_contents->GetTitle();
+ return true;
+}
+
Browser* BrowserNavigatorTest::CreateEmptyBrowserForType(Browser::Type type,
Profile* profile) {
Browser* browser = new Browser(
@@ -1291,4 +1323,36 @@
EXPECT_EQ(-1, chrome::GetIndexOfSingletonTab(&singleton_params));
}
-} // namespace
+// This test verifies that browser initiated navigations can send requests
+// using POST.
+IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
+ SendBrowserInitiatedRequestUsingPOST) {
+ // Uses a test sever to verify POST request.
+ ASSERT_TRUE(test_server()->Start());
+
+ // Open a browser initiated POST request in new foreground tab.
+ string16 expected_title(base::ASCIIToUTF16(kExpectedTitle));
+ std::string post_data = kExpectedTitle;
+ string16 title;
+ ASSERT_TRUE(OpenPOSTURLInNewForegroundTabAndGetTitle(
+ test_server()->GetURL(kEchoTitleCommand), post_data, true, &title));
+ EXPECT_EQ(expected_title, title);
+}
+
+// This test verifies that renderer initiated navigations can NOT send requests
+// using POST.
+IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest,
+ SendRendererInitiatedRequestUsingPOST) {
+ // Uses a test sever to verify POST request.
+ ASSERT_TRUE(test_server()->Start());
+
+ // Open a renderer initiated POST request in new foreground tab.
+ string16 expected_title(base::ASCIIToUTF16(kExpectedTitle));
+ std::string post_data = kExpectedTitle;
+ string16 title;
+ ASSERT_TRUE(OpenPOSTURLInNewForegroundTabAndGetTitle(
+ test_server()->GetURL(kEchoTitleCommand), post_data, false, &title));
+ EXPECT_NE(expected_title, title);
+}
+
+} // namespace
« no previous file with comments | « chrome/browser/ui/browser_navigator_browsertest.h ('k') | content/public/browser/page_navigator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698