| 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 <utility> | 5 #include <utility> |
| 6 | 6 |
| 7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "content/public/browser/navigation_controller.h" | 10 #include "content/public/browser/navigation_controller.h" |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 EXPECT_EQ("foo", GetTabTitle()); | 462 EXPECT_EQ("foo", GetTabTitle()); |
| 463 | 463 |
| 464 GoBack(); | 464 GoBack(); |
| 465 EXPECT_EQ("Default Title", GetTabTitle()); | 465 EXPECT_EQ("Default Title", GetTabTitle()); |
| 466 } | 466 } |
| 467 | 467 |
| 468 // http://code.google.com/p/chromium/issues/detail?id=56267 | 468 // http://code.google.com/p/chromium/issues/detail?id=56267 |
| 469 IN_PROC_BROWSER_TEST_F(SessionHistoryTest, HistoryLength) { | 469 IN_PROC_BROWSER_TEST_F(SessionHistoryTest, HistoryLength) { |
| 470 int length; | 470 int length; |
| 471 ASSERT_TRUE(ExecuteScriptAndExtractInt( | 471 ASSERT_TRUE(ExecuteScriptAndExtractInt( |
| 472 shell()->web_contents(), | 472 shell(), "domAutomationController.send(history.length)", &length)); |
| 473 "domAutomationController.send(history.length)", | |
| 474 &length)); | |
| 475 EXPECT_EQ(1, length); | 473 EXPECT_EQ(1, length); |
| 476 | 474 |
| 477 NavigateToURL(shell(), GetURL("title1.html")); | 475 NavigateToURL(shell(), GetURL("title1.html")); |
| 478 | 476 |
| 479 ASSERT_TRUE(ExecuteScriptAndExtractInt( | 477 ASSERT_TRUE(ExecuteScriptAndExtractInt( |
| 480 shell()->web_contents(), | 478 shell(), "domAutomationController.send(history.length)", &length)); |
| 481 "domAutomationController.send(history.length)", | |
| 482 &length)); | |
| 483 EXPECT_EQ(2, length); | 479 EXPECT_EQ(2, length); |
| 484 | 480 |
| 485 // Now test that history.length is updated when the navigation is committed. | 481 // Now test that history.length is updated when the navigation is committed. |
| 486 NavigateToURL(shell(), GetURL("record_length.html")); | 482 NavigateToURL(shell(), GetURL("record_length.html")); |
| 487 | 483 |
| 488 ASSERT_TRUE(ExecuteScriptAndExtractInt( | 484 ASSERT_TRUE(ExecuteScriptAndExtractInt( |
| 489 shell()->web_contents(), | 485 shell(), "domAutomationController.send(history.length)", &length)); |
| 490 "domAutomationController.send(history.length)", | |
| 491 &length)); | |
| 492 EXPECT_EQ(3, length); | 486 EXPECT_EQ(3, length); |
| 493 | 487 |
| 494 GoBack(); | 488 GoBack(); |
| 495 GoBack(); | 489 GoBack(); |
| 496 | 490 |
| 497 // Ensure history.length is properly truncated. | 491 // Ensure history.length is properly truncated. |
| 498 NavigateToURL(shell(), GetURL("title2.html")); | 492 NavigateToURL(shell(), GetURL("title2.html")); |
| 499 | 493 |
| 500 ASSERT_TRUE(ExecuteScriptAndExtractInt( | 494 ASSERT_TRUE(ExecuteScriptAndExtractInt( |
| 501 shell()->web_contents(), | 495 shell(), "domAutomationController.send(history.length)", &length)); |
| 502 "domAutomationController.send(history.length)", | |
| 503 &length)); | |
| 504 EXPECT_EQ(2, length); | 496 EXPECT_EQ(2, length); |
| 505 } | 497 } |
| 506 | 498 |
| 507 // Test that verifies that a cross-process transfer doesn't lose session | 499 // Test that verifies that a cross-process transfer doesn't lose session |
| 508 // history state - https://crbug.com/613004. | 500 // history state - https://crbug.com/613004. |
| 509 // | 501 // |
| 510 // Trigerring a cross-process transfer via embedded_test_server requires use of | 502 // Trigerring a cross-process transfer via embedded_test_server requires use of |
| 511 // a HTTP redirect response (to preserve port number). Therefore the test ends | 503 // a HTTP redirect response (to preserve port number). Therefore the test ends |
| 512 // up accidentally testing redirection logic as well - in particular, the test | 504 // up accidentally testing redirection logic as well - in particular, the test |
| 513 // uses 307 (rather than 302) redirect to preserve the body of HTTP POST across | 505 // uses 307 (rather than 302) redirect to preserve the body of HTTP POST across |
| 514 // redirects (as mandated by https://tools.ietf.org/html/rfc7231#section-6.4.7). | 506 // redirects (as mandated by https://tools.ietf.org/html/rfc7231#section-6.4.7). |
| 515 IN_PROC_BROWSER_TEST_F(SessionHistoryTest, GoBackToCrossSitePostWithRedirect) { | 507 IN_PROC_BROWSER_TEST_F(SessionHistoryTest, GoBackToCrossSitePostWithRedirect) { |
| 516 GURL form_url(embedded_test_server()->GetURL( | 508 GURL form_url(embedded_test_server()->GetURL( |
| 517 "a.com", "/session_history/form_that_posts_cross_site.html")); | 509 "a.com", "/session_history/form_that_posts_cross_site.html")); |
| 518 GURL redirect_target_url(embedded_test_server()->GetURL("x.com", "/echoall")); | 510 GURL redirect_target_url(embedded_test_server()->GetURL("x.com", "/echoall")); |
| 519 GURL page_to_go_back_from( | 511 GURL page_to_go_back_from( |
| 520 embedded_test_server()->GetURL("c.com", "/title1.html")); | 512 embedded_test_server()->GetURL("c.com", "/title1.html")); |
| 521 | 513 |
| 522 // Navigate to the page with form that posts via 307 redirection to | 514 // Navigate to the page with form that posts via 307 redirection to |
| 523 // |redirect_target_url| (cross-site from |form_url|). | 515 // |redirect_target_url| (cross-site from |form_url|). |
| 524 EXPECT_TRUE(NavigateToURL(shell(), form_url)); | 516 EXPECT_TRUE(NavigateToURL(shell(), form_url)); |
| 525 | 517 |
| 526 // Submit the form. | 518 // Submit the form. |
| 527 TestNavigationObserver form_post_observer(shell()->web_contents(), 1); | 519 TestNavigationObserver form_post_observer(shell()->web_contents(), 1); |
| 528 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), | 520 EXPECT_TRUE( |
| 529 "document.getElementById('form').submit();")); | 521 ExecuteScript(shell(), "document.getElementById('form').submit();")); |
| 530 form_post_observer.Wait(); | 522 form_post_observer.Wait(); |
| 531 | 523 |
| 532 // Verify that we arrived at the expected, redirected location. | 524 // Verify that we arrived at the expected, redirected location. |
| 533 EXPECT_EQ(redirect_target_url, | 525 EXPECT_EQ(redirect_target_url, |
| 534 shell()->web_contents()->GetLastCommittedURL()); | 526 shell()->web_contents()->GetLastCommittedURL()); |
| 535 | 527 |
| 536 // Verify that POST body got preserved by 307 redirect. This expectation | 528 // Verify that POST body got preserved by 307 redirect. This expectation |
| 537 // comes from: https://tools.ietf.org/html/rfc7231#section-6.4.7 | 529 // comes from: https://tools.ietf.org/html/rfc7231#section-6.4.7 |
| 538 std::string body; | 530 std::string body; |
| 539 EXPECT_TRUE(ExecuteScriptAndExtractString( | 531 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 540 shell()->web_contents(), | 532 shell(), |
| 541 "window.domAutomationController.send(" | 533 "window.domAutomationController.send(" |
| 542 "document.getElementsByTagName('pre')[0].innerText);", | 534 "document.getElementsByTagName('pre')[0].innerText);", |
| 543 &body)); | 535 &body)); |
| 544 EXPECT_EQ("text=value\n", body); | 536 EXPECT_EQ("text=value\n", body); |
| 545 | 537 |
| 546 // Navigate to a page from yet another site. | 538 // Navigate to a page from yet another site. |
| 547 EXPECT_TRUE(NavigateToURL(shell(), page_to_go_back_from)); | 539 EXPECT_TRUE(NavigateToURL(shell(), page_to_go_back_from)); |
| 548 | 540 |
| 549 // Go back - this should resubmit form's post data. | 541 // Go back - this should resubmit form's post data. |
| 550 TestNavigationObserver back_nav_observer(shell()->web_contents(), 1); | 542 TestNavigationObserver back_nav_observer(shell()->web_contents(), 1); |
| 551 shell()->web_contents()->GetController().GoBack(); | 543 shell()->web_contents()->GetController().GoBack(); |
| 552 back_nav_observer.Wait(); | 544 back_nav_observer.Wait(); |
| 553 | 545 |
| 554 // Again verify that we arrived at the expected, redirected location. | 546 // Again verify that we arrived at the expected, redirected location. |
| 555 EXPECT_EQ(redirect_target_url, | 547 EXPECT_EQ(redirect_target_url, |
| 556 shell()->web_contents()->GetLastCommittedURL()); | 548 shell()->web_contents()->GetLastCommittedURL()); |
| 557 | 549 |
| 558 // Again verify that POST body got preserved by 307 redirect. | 550 // Again verify that POST body got preserved by 307 redirect. |
| 559 std::string body_after_back_navigation; | 551 std::string body_after_back_navigation; |
| 560 EXPECT_TRUE(ExecuteScriptAndExtractString( | 552 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 561 shell()->web_contents(), | 553 shell(), |
| 562 "window.domAutomationController.send(" | 554 "window.domAutomationController.send(" |
| 563 "document.getElementsByTagName('pre')[0].innerText);", | 555 "document.getElementsByTagName('pre')[0].innerText);", |
| 564 &body_after_back_navigation)); | 556 &body_after_back_navigation)); |
| 565 EXPECT_EQ("text=value\n", body_after_back_navigation); | 557 EXPECT_EQ("text=value\n", body_after_back_navigation); |
| 566 } | 558 } |
| 567 | 559 |
| 568 } // namespace content | 560 } // namespace content |
| OLD | NEW |