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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/macros.h" | 6 #include "base/macros.h" |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 8 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 9 #include "content/public/browser/navigation_entry.h" | 9 #include "content/public/browser/navigation_entry.h" |
| 10 #include "content/public/browser/render_view_host.h" | |
| 10 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 11 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
| 11 #include "content/public/browser/resource_throttle.h" | 12 #include "content/public/browser/resource_throttle.h" |
| 12 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 14 #include "content/public/common/renderer_preferences.h" | |
| 13 #include "content/public/test/browser_test_utils.h" | 15 #include "content/public/test/browser_test_utils.h" |
| 14 #include "content/public/test/content_browser_test.h" | 16 #include "content/public/test/content_browser_test.h" |
| 15 #include "content/public/test/content_browser_test_utils.h" | 17 #include "content/public/test/content_browser_test_utils.h" |
| 16 #include "content/public/test/test_navigation_observer.h" | 18 #include "content/public/test/test_navigation_observer.h" |
| 17 #include "content/shell/browser/shell.h" | 19 #include "content/shell/browser/shell.h" |
| 18 #include "content/shell/browser/shell_content_browser_client.h" | 20 #include "content/shell/browser/shell_content_browser_client.h" |
| 19 #include "content/shell/browser/shell_resource_dispatcher_host_delegate.h" | 21 #include "content/shell/browser/shell_resource_dispatcher_host_delegate.h" |
| 20 #include "net/base/escape.h" | 22 #include "net/base/escape.h" |
| 21 #include "net/dns/mock_host_resolver.h" | 23 #include "net/dns/mock_host_resolver.h" |
| 22 #include "net/test/embedded_test_server/embedded_test_server.h" | 24 #include "net/test/embedded_test_server/embedded_test_server.h" |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 411 EXPECT_EQ(1, controller.GetEntryCount()); | 413 EXPECT_EQ(1, controller.GetEntryCount()); |
| 412 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); | 414 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); |
| 413 EXPECT_EQ(url1, controller.GetEntryAtIndex(0)->GetURL()); | 415 EXPECT_EQ(url1, controller.GetEntryAtIndex(0)->GetURL()); |
| 414 | 416 |
| 415 // Make sure the request for url2 did not complete. | 417 // Make sure the request for url2 did not complete. |
| 416 EXPECT_FALSE(tracking_delegate().WaitForTrackedURLAndGetCompleted()); | 418 EXPECT_FALSE(tracking_delegate().WaitForTrackedURLAndGetCompleted()); |
| 417 | 419 |
| 418 shell()->web_contents()->SetDelegate(old_delegate); | 420 shell()->web_contents()->SetDelegate(old_delegate); |
| 419 } | 421 } |
| 420 | 422 |
| 423 // Tests that POST body is not lost when decidePolicyForNavigation tells the | |
| 424 // renderer to route the request via FrameHostMsg_OpenURL sent to the browser. | |
| 425 // See also https://crbug.com/344348. | |
| 426 IN_PROC_BROWSER_TEST_F(CrossSiteTransferTest, PostViaOpenUrlMsg) { | |
|
Łukasz Anforowicz
2016/05/20 23:24:22
Is this a reasonable location for this new test?
| |
| 427 GURL main_url( | |
| 428 embedded_test_server()->GetURL("/form_that_posts_to_echoall.html")); | |
| 429 EXPECT_TRUE(NavigateToURL(shell(), main_url)); | |
| 430 | |
| 431 // Ask the renderer to go through OpenURL FrameHostMsg_OpenURL IPC message. | |
| 432 // Without this, the test wouldn't repro https://crbug.com/344348. | |
| 433 shell() | |
| 434 ->web_contents() | |
| 435 ->GetMutableRendererPrefs() | |
| 436 ->browser_handles_all_top_level_requests = true; | |
| 437 shell()->web_contents()->GetRenderViewHost()->SyncRendererPrefs(); | |
| 438 | |
| 439 // Submit the form. | |
| 440 TestNavigationObserver form_post_observer(shell()->web_contents(), 1); | |
| 441 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), | |
| 442 "document.getElementById('form').submit();")); | |
| 443 form_post_observer.Wait(); | |
| 444 | |
| 445 // Verify that we arrived at the expected, redirected location. | |
| 446 GURL target_url(embedded_test_server()->GetURL("/echoall")); | |
| 447 EXPECT_EQ(target_url, shell()->web_contents()->GetLastCommittedURL()); | |
| 448 | |
| 449 // Verify that POST body was correctly passed to the server. | |
| 450 std::string body; | |
| 451 EXPECT_TRUE(ExecuteScriptAndExtractString( | |
| 452 shell()->web_contents(), | |
| 453 "window.domAutomationController.send(" | |
| 454 "document.getElementsByTagName('pre')[0].innerText);", | |
| 455 &body)); | |
| 456 EXPECT_EQ("text=value\n", body); | |
| 457 } | |
| 458 | |
| 421 } // namespace content | 459 } // namespace content |
| OLD | NEW |