| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/browser/frame_host/navigation_controller_impl.h" | 5 #include "content/browser/frame_host/navigation_controller_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 #include "content/common/view_messages.h" | 34 #include "content/common/view_messages.h" |
| 35 #include "content/public/browser/navigation_details.h" | 35 #include "content/public/browser/navigation_details.h" |
| 36 #include "content/public/browser/notification_registrar.h" | 36 #include "content/public/browser/notification_registrar.h" |
| 37 #include "content/public/browser/notification_types.h" | 37 #include "content/public/browser/notification_types.h" |
| 38 #include "content/public/browser/render_view_host.h" | 38 #include "content/public/browser/render_view_host.h" |
| 39 #include "content/public/browser/web_contents_delegate.h" | 39 #include "content/public/browser/web_contents_delegate.h" |
| 40 #include "content/public/browser/web_contents_observer.h" | 40 #include "content/public/browser/web_contents_observer.h" |
| 41 #include "content/public/common/browser_side_navigation_policy.h" | 41 #include "content/public/common/browser_side_navigation_policy.h" |
| 42 #include "content/public/common/page_state.h" | 42 #include "content/public/common/page_state.h" |
| 43 #include "content/public/common/page_type.h" | 43 #include "content/public/common/page_type.h" |
| 44 #include "content/public/common/resource_request_body.h" |
| 44 #include "content/public/common/url_constants.h" | 45 #include "content/public/common/url_constants.h" |
| 45 #include "content/public/test/mock_render_process_host.h" | 46 #include "content/public/test/mock_render_process_host.h" |
| 46 #include "content/public/test/test_notification_tracker.h" | 47 #include "content/public/test/test_notification_tracker.h" |
| 47 #include "content/public/test/test_utils.h" | 48 #include "content/public/test/test_utils.h" |
| 48 #include "content/test/browser_side_navigation_test_utils.h" | 49 #include "content/test/browser_side_navigation_test_utils.h" |
| 49 #include "content/test/test_render_frame_host.h" | 50 #include "content/test/test_render_frame_host.h" |
| 50 #include "content/test/test_render_view_host.h" | 51 #include "content/test/test_render_view_host.h" |
| 51 #include "content/test/test_web_contents.h" | 52 #include "content/test/test_web_contents.h" |
| 52 #include "skia/ext/platform_canvas.h" | 53 #include "skia/ext/platform_canvas.h" |
| 53 #include "testing/gtest/include/gtest/gtest.h" | 54 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 } | 676 } |
| 676 #if defined(OS_ANDROID) | 677 #if defined(OS_ANDROID) |
| 677 EXPECT_EQ(load_params.data_url_as_string, entry->GetDataURLAsString()); | 678 EXPECT_EQ(load_params.data_url_as_string, entry->GetDataURLAsString()); |
| 678 #endif | 679 #endif |
| 679 if (NavigationController::UA_OVERRIDE_INHERIT != | 680 if (NavigationController::UA_OVERRIDE_INHERIT != |
| 680 load_params.override_user_agent) { | 681 load_params.override_user_agent) { |
| 681 bool should_override = (NavigationController::UA_OVERRIDE_TRUE == | 682 bool should_override = (NavigationController::UA_OVERRIDE_TRUE == |
| 682 load_params.override_user_agent); | 683 load_params.override_user_agent); |
| 683 EXPECT_EQ(should_override, entry->GetIsOverridingUserAgent()); | 684 EXPECT_EQ(should_override, entry->GetIsOverridingUserAgent()); |
| 684 } | 685 } |
| 685 EXPECT_EQ(load_params.browser_initiated_post_data.get(), | 686 EXPECT_EQ(load_params.post_data, entry->GetPostData()); |
| 686 entry->GetBrowserInitiatedPostData()); | |
| 687 EXPECT_EQ(load_params.transferred_global_request_id, | 687 EXPECT_EQ(load_params.transferred_global_request_id, |
| 688 entry->transferred_global_request_id()); | 688 entry->transferred_global_request_id()); |
| 689 } | 689 } |
| 690 | 690 |
| 691 TEST_F(NavigationControllerTest, LoadURLWithParams) { | 691 TEST_F(NavigationControllerTest, LoadURLWithParams) { |
| 692 // Start a navigation in order to have enough state to fake a transfer. | 692 // Start a navigation in order to have enough state to fake a transfer. |
| 693 contents()->NavigateAndCommit(GURL("http://foo")); | 693 contents()->NavigateAndCommit(GURL("http://foo")); |
| 694 contents()->StartNavigation(GURL("http://bar")); | 694 contents()->StartNavigation(GURL("http://bar")); |
| 695 | 695 |
| 696 NavigationControllerImpl& controller = controller_impl(); | 696 NavigationControllerImpl& controller = controller_impl(); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 | 748 |
| 749 CheckNavigationEntryMatchLoadParams(load_params, entry); | 749 CheckNavigationEntryMatchLoadParams(load_params, entry); |
| 750 } | 750 } |
| 751 #endif | 751 #endif |
| 752 | 752 |
| 753 TEST_F(NavigationControllerTest, LoadURLWithExtraParams_HttpPost) { | 753 TEST_F(NavigationControllerTest, LoadURLWithExtraParams_HttpPost) { |
| 754 NavigationControllerImpl& controller = controller_impl(); | 754 NavigationControllerImpl& controller = controller_impl(); |
| 755 | 755 |
| 756 NavigationController::LoadURLParams load_params(GURL("https://posturl")); | 756 NavigationController::LoadURLParams load_params(GURL("https://posturl")); |
| 757 load_params.transition_type = ui::PAGE_TRANSITION_TYPED; | 757 load_params.transition_type = ui::PAGE_TRANSITION_TYPED; |
| 758 load_params.load_type = | 758 load_params.load_type = NavigationController::LOAD_TYPE_HTTP_POST; |
| 759 NavigationController::LOAD_TYPE_BROWSER_INITIATED_HTTP_POST; | |
| 760 load_params.override_user_agent = NavigationController::UA_OVERRIDE_TRUE; | 759 load_params.override_user_agent = NavigationController::UA_OVERRIDE_TRUE; |
| 761 | 760 |
| 762 | 761 const char* raw_data = "d\n\0a2"; |
| 763 const unsigned char* raw_data = | |
| 764 reinterpret_cast<const unsigned char*>("d\n\0a2"); | |
| 765 const int length = 5; | 762 const int length = 5; |
| 766 std::vector<unsigned char> post_data_vector(raw_data, raw_data+length); | 763 load_params.post_data = |
| 767 scoped_refptr<base::RefCountedBytes> data = | 764 ResourceRequestBody::CreateFromBytes(raw_data, length); |
| 768 base::RefCountedBytes::TakeVector(&post_data_vector); | |
| 769 load_params.browser_initiated_post_data = data.get(); | |
| 770 | 765 |
| 771 controller.LoadURLWithParams(load_params); | 766 controller.LoadURLWithParams(load_params); |
| 772 NavigationEntryImpl* entry = controller.GetPendingEntry(); | 767 NavigationEntryImpl* entry = controller.GetPendingEntry(); |
| 773 | 768 |
| 774 CheckNavigationEntryMatchLoadParams(load_params, entry); | 769 CheckNavigationEntryMatchLoadParams(load_params, entry); |
| 775 } | 770 } |
| 776 | 771 |
| 777 // Tests what happens when the same page is loaded again. Should not create a | 772 // Tests what happens when the same page is loaded again. Should not create a |
| 778 // new session history entry. This is what happens when you press enter in the | 773 // new session history entry. This is what happens when you press enter in the |
| 779 // URL bar to reload: a pending entry is created and then it is discarded when | 774 // URL bar to reload: a pending entry is created and then it is discarded when |
| (...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1569 main_test_rfh()->PrepareForCommit(); | 1564 main_test_rfh()->PrepareForCommit(); |
| 1570 main_test_rfh()->SendNavigate(0, entry_id, true, url0); | 1565 main_test_rfh()->SendNavigate(0, entry_id, true, url0); |
| 1571 | 1566 |
| 1572 // Set up the pending entry. | 1567 // Set up the pending entry. |
| 1573 const GURL url1("http://foo/1"); | 1568 const GURL url1("http://foo/1"); |
| 1574 controller.LoadURL( | 1569 controller.LoadURL( |
| 1575 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 1570 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 1576 entry_id = controller.GetPendingEntry()->GetUniqueID(); | 1571 entry_id = controller.GetPendingEntry()->GetUniqueID(); |
| 1577 | 1572 |
| 1578 // Set up some sample values. | 1573 // Set up some sample values. |
| 1579 const unsigned char* raw_data = | 1574 const char* raw_data = "post\n\n\0data"; |
| 1580 reinterpret_cast<const unsigned char*>("post\n\n\0data"); | |
| 1581 const int length = 11; | 1575 const int length = 11; |
| 1582 std::vector<unsigned char> post_data_vector(raw_data, raw_data+length); | |
| 1583 scoped_refptr<base::RefCountedBytes> post_data = | |
| 1584 base::RefCountedBytes::TakeVector(&post_data_vector); | |
| 1585 GlobalRequestID transfer_id(3, 4); | 1576 GlobalRequestID transfer_id(3, 4); |
| 1586 | 1577 |
| 1587 // Set non-persisted values on the pending entry. | 1578 // Set non-persisted values on the pending entry. |
| 1588 NavigationEntryImpl* pending_entry = controller.GetPendingEntry(); | 1579 NavigationEntryImpl* pending_entry = controller.GetPendingEntry(); |
| 1589 pending_entry->SetBrowserInitiatedPostData(post_data.get()); | 1580 pending_entry->SetPostData( |
| 1581 ResourceRequestBody::CreateFromBytes(raw_data, length)); |
| 1590 pending_entry->set_is_renderer_initiated(true); | 1582 pending_entry->set_is_renderer_initiated(true); |
| 1591 pending_entry->set_transferred_global_request_id(transfer_id); | 1583 pending_entry->set_transferred_global_request_id(transfer_id); |
| 1592 pending_entry->set_should_replace_entry(true); | 1584 pending_entry->set_should_replace_entry(true); |
| 1593 pending_entry->set_should_clear_history_list(true); | 1585 pending_entry->set_should_clear_history_list(true); |
| 1594 EXPECT_EQ(post_data.get(), pending_entry->GetBrowserInitiatedPostData()); | 1586 EXPECT_TRUE(pending_entry->GetPostData()); |
| 1595 EXPECT_TRUE(pending_entry->is_renderer_initiated()); | 1587 EXPECT_TRUE(pending_entry->is_renderer_initiated()); |
| 1596 EXPECT_EQ(transfer_id, pending_entry->transferred_global_request_id()); | 1588 EXPECT_EQ(transfer_id, pending_entry->transferred_global_request_id()); |
| 1597 EXPECT_TRUE(pending_entry->should_replace_entry()); | 1589 EXPECT_TRUE(pending_entry->should_replace_entry()); |
| 1598 EXPECT_TRUE(pending_entry->should_clear_history_list()); | 1590 EXPECT_TRUE(pending_entry->should_clear_history_list()); |
| 1599 | 1591 |
| 1600 // Fake a commit response. | 1592 // Fake a commit response. |
| 1601 main_test_rfh()->PrepareForCommit(); | 1593 main_test_rfh()->PrepareForCommit(); |
| 1602 main_test_rfh()->SendNavigateWithReplacement(1, entry_id, true, url1); | 1594 main_test_rfh()->SendNavigateWithReplacement(1, entry_id, true, url1); |
| 1603 | 1595 |
| 1604 // Certain values that are only used for pending entries get reset after | 1596 // Certain values that are only used for pending entries get reset after |
| 1605 // commit. | 1597 // commit. |
| 1606 NavigationEntryImpl* committed_entry = controller.GetLastCommittedEntry(); | 1598 NavigationEntryImpl* committed_entry = controller.GetLastCommittedEntry(); |
| 1607 EXPECT_FALSE(committed_entry->GetBrowserInitiatedPostData()); | 1599 EXPECT_FALSE(committed_entry->GetPostData()); |
| 1608 EXPECT_FALSE(committed_entry->is_renderer_initiated()); | 1600 EXPECT_FALSE(committed_entry->is_renderer_initiated()); |
| 1609 EXPECT_EQ(GlobalRequestID(-1, -1), | 1601 EXPECT_EQ(GlobalRequestID(-1, -1), |
| 1610 committed_entry->transferred_global_request_id()); | 1602 committed_entry->transferred_global_request_id()); |
| 1611 EXPECT_FALSE(committed_entry->should_replace_entry()); | 1603 EXPECT_FALSE(committed_entry->should_replace_entry()); |
| 1612 EXPECT_FALSE(committed_entry->should_clear_history_list()); | 1604 EXPECT_FALSE(committed_entry->should_clear_history_list()); |
| 1613 } | 1605 } |
| 1614 | 1606 |
| 1615 namespace { | 1607 namespace { |
| 1616 void SetRedirects(const std::vector<GURL>& redirects, | 1608 void SetRedirects(const std::vector<GURL>& redirects, |
| 1617 FrameHostMsg_DidCommitProvisionalLoad_Params* params) { | 1609 FrameHostMsg_DidCommitProvisionalLoad_Params* params) { |
| (...skipping 3707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5325 observer.details().ssl_status.num_unknown_scts); | 5317 observer.details().ssl_status.num_unknown_scts); |
| 5326 EXPECT_EQ(default_ssl_status.num_invalid_scts, | 5318 EXPECT_EQ(default_ssl_status.num_invalid_scts, |
| 5327 observer.details().ssl_status.num_invalid_scts); | 5319 observer.details().ssl_status.num_invalid_scts); |
| 5328 EXPECT_EQ(default_ssl_status.num_valid_scts, | 5320 EXPECT_EQ(default_ssl_status.num_valid_scts, |
| 5329 observer.details().ssl_status.num_valid_scts); | 5321 observer.details().ssl_status.num_valid_scts); |
| 5330 | 5322 |
| 5331 EXPECT_EQ(1, main_test_rfh()->GetProcess()->bad_msg_count()); | 5323 EXPECT_EQ(1, main_test_rfh()->GetProcess()->bad_msg_count()); |
| 5332 } | 5324 } |
| 5333 | 5325 |
| 5334 } // namespace content | 5326 } // namespace content |
| OLD | NEW |