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