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

Unified Diff: chrome/browser/prerender/prerender_browsertest.cc

Issue 2165133003: Allow forking for POST method (+ test that this works with prerender). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Actual CL. Created 4 years, 5 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 | « no previous file | chrome/renderer/chrome_content_renderer_client.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/prerender/prerender_browsertest.cc
diff --git a/chrome/browser/prerender/prerender_browsertest.cc b/chrome/browser/prerender/prerender_browsertest.cc
index 542c9f652747f57ee4e631fe75849ef53889e3bf..63a3ec102bd7f14a4067ce1478f2ec82032a8264 100644
--- a/chrome/browser/prerender/prerender_browsertest.cc
+++ b/chrome/browser/prerender/prerender_browsertest.cc
@@ -122,6 +122,8 @@
#include "net/url_request/url_request_interceptor.h"
#include "net/url_request/url_request_job.h"
#include "ppapi/shared_impl/ppapi_switches.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/l10n/l10n_util.h"
#include "url/gurl.h"
@@ -3787,6 +3789,50 @@ IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, PrerenderWindowClose) {
FINAL_STATUS_CLOSED, 0);
}
+// Tests interaction between prerender and POST (i.e. POST request should still
+// be made and POST data should not be dropped when the POST target is the same
+// as a prerender link).
+IN_PROC_BROWSER_TEST_F(PrerenderBrowserTest, HttpPost) {
+ // Expect that the prerendered contents won't get used (i.e. the prerendered
+ // content should be destroyed when the test closes the browser under test).
+ std::unique_ptr<TestPrerender> prerender =
+ ExpectPrerender(FINAL_STATUS_APP_TERMINATING);
+
+ // Navigate to a page containing a form that targets a prerendered link.
+ GURL main_url(embedded_test_server()->GetURL(
+ "/prerender/form_that_posts_to_prerendered_echoall.html"));
+ ui_test_utils::NavigateToURL(current_browser(), main_url);
+
+ // Wait for the prerender to be ready.
+ prerender->WaitForStart();
+ prerender->WaitForLoads(1);
+ EXPECT_THAT(prerender->contents()->prerender_url().spec(),
+ ::testing::MatchesRegex("^http://127.0.0.1.*:\\d+/echoall$"));
+
+ // Submit the form.
+ content::WebContents* web_contents =
+ current_browser()->tab_strip_model()->GetActiveWebContents();
+ TestNavigationObserver form_post_observer(web_contents, 1);
+ EXPECT_TRUE(
+ ExecuteScript(web_contents, "document.getElementById('form').submit();"));
+ form_post_observer.Wait();
+
+ // Verify that we arrived at the expected location.
+ GURL target_url(embedded_test_server()->GetURL("/echoall"));
+ EXPECT_EQ(target_url, web_contents->GetLastCommittedURL());
+
+ // Verify that POST body was correctly passed to the server and ended up in
+ // the body of the page (i.e. verify that we haven't used the prerendered
+ // page that doesn't contain the POST body).
+ std::string body;
+ EXPECT_TRUE(ExecuteScriptAndExtractString(
+ web_contents,
+ "window.domAutomationController.send("
+ "document.getElementsByTagName('pre')[0].innerText);",
+ &body));
+ EXPECT_EQ("text=value\n", body);
+}
+
class PrerenderIncognitoBrowserTest : public PrerenderBrowserTest {
public:
void SetUpOnMainThread() override {
« no previous file with comments | « no previous file | chrome/renderer/chrome_content_renderer_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698