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

Side by Side Diff: content/browser/frame_host/navigation_controller_impl_unittest.cc

Issue 1102563003: Fill in FrameNavigationEntries for auto subframe navigations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes Created 5 years, 7 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 unified diff | Download patch
OLDNEW
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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 2086 matching lines...) Expand 10 before | Expand all | Expand 10 after
2097 EXPECT_EQ(2, controller.GetEntryCount()); 2097 EXPECT_EQ(2, controller.GetEntryCount());
2098 2098
2099 // New entry should refer to the new page, but the old URL (entries only 2099 // New entry should refer to the new page, but the old URL (entries only
2100 // reflect the toplevel URL). 2100 // reflect the toplevel URL).
2101 EXPECT_EQ(url1, details.entry->GetURL()); 2101 EXPECT_EQ(url1, details.entry->GetURL());
2102 EXPECT_EQ(params.page_id, details.entry->GetPageID()); 2102 EXPECT_EQ(params.page_id, details.entry->GetPageID());
2103 } 2103 }
2104 2104
2105 // Auto subframes are ones the page loads automatically like ads. They should 2105 // Auto subframes are ones the page loads automatically like ads. They should
2106 // not create new navigation entries. 2106 // not create new navigation entries.
2107 // TODO(creis): Test cross-site and nested iframes.
2108 // TODO(creis): Test updating entries for history auto subframe navigations. 2107 // TODO(creis): Test updating entries for history auto subframe navigations.
2109 TEST_F(NavigationControllerTest, AutoSubframe) { 2108 TEST_F(NavigationControllerTest, AutoSubframe) {
2110 NavigationControllerImpl& controller = controller_impl(); 2109 NavigationControllerImpl& controller = controller_impl();
2111 TestNotificationTracker notifications; 2110 TestNotificationTracker notifications;
2112 RegisterForAllNavNotifications(&notifications, &controller); 2111 RegisterForAllNavNotifications(&notifications, &controller);
2113 2112
2114 const GURL url1("http://foo/1"); 2113 const GURL url1("http://foo/1");
2115 main_test_rfh()->NavigateAndCommitRendererInitiated(1, true, url1); 2114 main_test_rfh()->NavigateAndCommitRendererInitiated(1, true, url1);
2116 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2115 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2117 navigation_entry_committed_counter_ = 0; 2116 navigation_entry_committed_counter_ = 0;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
2163 2162
2164 // Add a second subframe and navigate. 2163 // Add a second subframe and navigate.
2165 main_test_rfh()->OnCreateChildFrame(MSG_ROUTING_NONE, std::string(), 2164 main_test_rfh()->OnCreateChildFrame(MSG_ROUTING_NONE, std::string(),
2166 SandboxFlags::NONE); 2165 SandboxFlags::NONE);
2167 RenderFrameHostImpl* subframe2 = 2166 RenderFrameHostImpl* subframe2 =
2168 contents()->GetFrameTree()->root()->child_at(1)->current_frame_host(); 2167 contents()->GetFrameTree()->root()->child_at(1)->current_frame_host();
2169 const GURL url3("http://foo/3"); 2168 const GURL url3("http://foo/3");
2170 { 2169 {
2171 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2170 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2172 params.page_id = 1; 2171 params.page_id = 1;
2172 params.nav_entry_id = 0;
2173 params.did_create_new_entry = false;
2173 params.url = url3; 2174 params.url = url3;
2174 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; 2175 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
2175 params.should_update_history = false; 2176 params.should_update_history = false;
2176 params.gesture = NavigationGestureUser; 2177 params.gesture = NavigationGestureUser;
2177 params.is_post = false; 2178 params.is_post = false;
2178 params.page_state = PageState::CreateFromURL(url3); 2179 params.page_state = PageState::CreateFromURL(url3);
2179 2180
2180 // Navigating should do nothing. 2181 // Navigating should do nothing.
2181 LoadCommittedDetails details; 2182 LoadCommittedDetails details;
2182 EXPECT_FALSE(controller.RendererDidNavigate(subframe2, params, &details)); 2183 EXPECT_FALSE(controller.RendererDidNavigate(subframe2, params, &details));
(...skipping 13 matching lines...) Expand all
2196 switches::kSitePerProcess)) { 2197 switches::kSitePerProcess)) {
2197 // The entry should now have 2 subframe FrameNavigationEntries. 2198 // The entry should now have 2 subframe FrameNavigationEntries.
2198 ASSERT_EQ(2U, entry->root_node()->children.size()); 2199 ASSERT_EQ(2U, entry->root_node()->children.size());
2199 FrameNavigationEntry* new_frame_entry = 2200 FrameNavigationEntry* new_frame_entry =
2200 entry->root_node()->children[1]->frame_entry.get(); 2201 entry->root_node()->children[1]->frame_entry.get();
2201 EXPECT_EQ(url3, new_frame_entry->url()); 2202 EXPECT_EQ(url3, new_frame_entry->url());
2202 } else { 2203 } else {
2203 // There are no subframe FrameNavigationEntries by default. 2204 // There are no subframe FrameNavigationEntries by default.
2204 EXPECT_EQ(0U, entry->root_node()->children.size()); 2205 EXPECT_EQ(0U, entry->root_node()->children.size());
2205 } 2206 }
2207
2208 // Add a nested subframe and navigate.
2209 subframe->OnCreateChildFrame(MSG_ROUTING_NONE, std::string(),
2210 SandboxFlags::NONE);
2211 RenderFrameHostImpl* subframe3 = contents()
2212 ->GetFrameTree()
2213 ->root()
2214 ->child_at(0)
2215 ->child_at(0)
2216 ->current_frame_host();
2217 const GURL url4("http://foo/4");
2218 {
2219 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2220 params.page_id = 1;
2221 params.nav_entry_id = 0;
2222 params.did_create_new_entry = false;
2223 params.url = url4;
2224 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
2225 params.should_update_history = false;
2226 params.gesture = NavigationGestureUser;
2227 params.is_post = false;
2228 params.page_state = PageState::CreateFromURL(url4);
2229
2230 // Navigating should do nothing.
2231 LoadCommittedDetails details;
2232 EXPECT_FALSE(controller.RendererDidNavigate(subframe3, params, &details));
2233 EXPECT_EQ(0U, notifications.size());
2234 }
2235
2236 // There should still be only one entry, mostly unchanged.
2237 EXPECT_EQ(1, controller.GetEntryCount());
2238 EXPECT_EQ(entry, controller.GetLastCommittedEntry());
2239 EXPECT_EQ(url1, entry->GetURL());
2240 EXPECT_EQ(1, entry->GetPageID());
2241 EXPECT_EQ(root_entry, entry->root_node()->frame_entry.get());
2242 EXPECT_EQ(url1, root_entry->url());
2243
2244 // Verify subframe entries if we're in --site-per-process mode.
2245 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
2246 switches::kSitePerProcess)) {
2247 // The entry should now have a nested FrameNavigationEntry.
2248 EXPECT_EQ(2U, entry->root_node()->children.size());
2249 ASSERT_EQ(1U, entry->root_node()->children[0]->children.size());
2250 FrameNavigationEntry* new_frame_entry =
2251 entry->root_node()->children[0]->children[0]->frame_entry.get();
2252 EXPECT_EQ(url4, new_frame_entry->url());
2253 } else {
2254 // There are no subframe FrameNavigationEntries by default.
2255 EXPECT_EQ(0U, entry->root_node()->children.size());
2256 }
2206 } 2257 }
2207 2258
2208 // Tests navigation and then going back to a subframe navigation. 2259 // Tests navigation and then going back to a subframe navigation.
2209 TEST_F(NavigationControllerTest, BackSubframe) { 2260 TEST_F(NavigationControllerTest, BackSubframe) {
2210 NavigationControllerImpl& controller = controller_impl(); 2261 NavigationControllerImpl& controller = controller_impl();
2211 TestNotificationTracker notifications; 2262 TestNotificationTracker notifications;
2212 RegisterForAllNavNotifications(&notifications, &controller); 2263 RegisterForAllNavNotifications(&notifications, &controller);
2213 2264
2214 // Main page. 2265 // Main page.
2215 const GURL url1("http://foo1"); 2266 const GURL url1("http://foo1");
(...skipping 1341 matching lines...) Expand 10 before | Expand all | Expand 10 after
3557 TEST_F(NavigationControllerTest, SameSubframe) { 3608 TEST_F(NavigationControllerTest, SameSubframe) {
3558 NavigationControllerImpl& controller = controller_impl(); 3609 NavigationControllerImpl& controller = controller_impl();
3559 // Navigate the main frame. 3610 // Navigate the main frame.
3560 const GURL url("http://www.google.com/"); 3611 const GURL url("http://www.google.com/");
3561 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, url); 3612 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, url);
3562 3613
3563 // We should be at the first navigation entry. 3614 // We should be at the first navigation entry.
3564 EXPECT_EQ(controller.GetEntryCount(), 1); 3615 EXPECT_EQ(controller.GetEntryCount(), 1);
3565 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 3616 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
3566 3617
3567 // Navigate a subframe that would normally count as in-page. 3618 // Add and navigate a subframe that would normally count as in-page.
3568 const GURL subframe("http://www.google.com/#"); 3619 main_test_rfh()->OnCreateChildFrame(MSG_ROUTING_NONE, std::string(),
3620 SandboxFlags::NONE);
3621 RenderFrameHostImpl* subframe =
3622 contents()->GetFrameTree()->root()->child_at(0)->current_frame_host();
3623 const GURL subframe_url("http://www.google.com/#");
3569 FrameHostMsg_DidCommitProvisionalLoad_Params params; 3624 FrameHostMsg_DidCommitProvisionalLoad_Params params;
3570 params.page_id = 0; 3625 params.page_id = 0;
3571 params.nav_entry_id = 0; 3626 params.nav_entry_id = 0;
3572 params.did_create_new_entry = false; 3627 params.did_create_new_entry = false;
3573 params.url = subframe; 3628 params.url = subframe_url;
3574 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; 3629 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
3575 params.should_update_history = false; 3630 params.should_update_history = false;
3576 params.gesture = NavigationGestureAuto; 3631 params.gesture = NavigationGestureAuto;
3577 params.is_post = false; 3632 params.is_post = false;
3578 params.page_state = PageState::CreateFromURL(subframe); 3633 params.page_state = PageState::CreateFromURL(subframe_url);
3579 LoadCommittedDetails details; 3634 LoadCommittedDetails details;
3580 EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), params, 3635 EXPECT_FALSE(controller.RendererDidNavigate(subframe, params, &details));
3581 &details));
3582 3636
3583 // Nothing should have changed. 3637 // Nothing should have changed.
3584 EXPECT_EQ(controller.GetEntryCount(), 1); 3638 EXPECT_EQ(controller.GetEntryCount(), 1);
3585 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 3639 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
3586 } 3640 }
3587 3641
3588 // Make sure that on cloning a WebContentsImpl and going back needs_reload is 3642 // Make sure that on cloning a WebContentsImpl and going back needs_reload is
3589 // false. 3643 // false.
3590 TEST_F(NavigationControllerTest, CloneAndGoBack) { 3644 TEST_F(NavigationControllerTest, CloneAndGoBack) {
3591 NavigationControllerImpl& controller = controller_impl(); 3645 NavigationControllerImpl& controller = controller_impl();
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
3705 const GURL url1("http://foo/"); 3759 const GURL url1("http://foo/");
3706 NavigateAndCommit(url1); 3760 NavigateAndCommit(url1);
3707 3761
3708 // Now start a pending load to a totally different page, but don't commit it. 3762 // Now start a pending load to a totally different page, but don't commit it.
3709 const GURL url2("http://bar/"); 3763 const GURL url2("http://bar/");
3710 controller.LoadURL( 3764 controller.LoadURL(
3711 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 3765 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
3712 3766
3713 // Send a subframe update from the first page, as if one had just 3767 // Send a subframe update from the first page, as if one had just
3714 // automatically loaded. Auto subframes don't increment the page ID. 3768 // automatically loaded. Auto subframes don't increment the page ID.
3769 main_test_rfh()->OnCreateChildFrame(MSG_ROUTING_NONE, std::string(),
3770 SandboxFlags::NONE);
3771 RenderFrameHostImpl* subframe =
3772 contents()->GetFrameTree()->root()->child_at(0)->current_frame_host();
3715 const GURL url1_sub("http://foo/subframe"); 3773 const GURL url1_sub("http://foo/subframe");
3716 FrameHostMsg_DidCommitProvisionalLoad_Params params; 3774 FrameHostMsg_DidCommitProvisionalLoad_Params params;
3717 params.page_id = controller.GetLastCommittedEntry()->GetPageID(); 3775 params.page_id = controller.GetLastCommittedEntry()->GetPageID();
3718 params.nav_entry_id = 0; 3776 params.nav_entry_id = 0;
3719 params.did_create_new_entry = false; 3777 params.did_create_new_entry = false;
3720 params.url = url1_sub; 3778 params.url = url1_sub;
3721 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; 3779 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
3722 params.should_update_history = false; 3780 params.should_update_history = false;
3723 params.gesture = NavigationGestureAuto; 3781 params.gesture = NavigationGestureAuto;
3724 params.is_post = false; 3782 params.is_post = false;
3725 params.page_state = PageState::CreateFromURL(url1_sub); 3783 params.page_state = PageState::CreateFromURL(url1_sub);
3726 LoadCommittedDetails details; 3784 LoadCommittedDetails details;
3727 3785
3728 // This should return false meaning that nothing was actually updated. 3786 // This should return false meaning that nothing was actually updated.
3729 EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), params, 3787 EXPECT_FALSE(controller.RendererDidNavigate(subframe, params, &details));
3730 &details));
3731 3788
3732 // The notification should have updated the last committed one, and not 3789 // The notification should have updated the last committed one, and not
3733 // the pending load. 3790 // the pending load.
3734 EXPECT_EQ(url1, controller.GetLastCommittedEntry()->GetURL()); 3791 EXPECT_EQ(url1, controller.GetLastCommittedEntry()->GetURL());
3735 3792
3736 // The active entry should be unchanged by the subframe load. 3793 // The active entry should be unchanged by the subframe load.
3737 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); 3794 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL());
3738 } 3795 }
3739 3796
3740 // Test CopyStateFrom with 2 urls, the first selected and nothing in the target. 3797 // Test CopyStateFrom with 2 urls, the first selected and nothing in the target.
(...skipping 1090 matching lines...) Expand 10 before | Expand all | Expand 10 after
4831 { 4888 {
4832 LoadCommittedDetails details; 4889 LoadCommittedDetails details;
4833 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); 4890 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details);
4834 EXPECT_EQ(PAGE_TYPE_ERROR, 4891 EXPECT_EQ(PAGE_TYPE_ERROR,
4835 controller_impl().GetLastCommittedEntry()->GetPageType()); 4892 controller_impl().GetLastCommittedEntry()->GetPageType());
4836 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, details.type); 4893 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, details.type);
4837 } 4894 }
4838 } 4895 }
4839 4896
4840 } // namespace content 4897 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698