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

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: Relax check 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2162 } 2161 }
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;
Avi (use Gerrit) 2015/05/14 18:01:11 params.nav_entry_id = 0; params.did_create_new_ent
Charlie Reis 2015/05/14 19:00:37 Done.
2173 params.url = url3; 2172 params.url = url3;
2174 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; 2173 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
2175 params.should_update_history = false; 2174 params.should_update_history = false;
2176 params.gesture = NavigationGestureUser; 2175 params.gesture = NavigationGestureUser;
2177 params.is_post = false; 2176 params.is_post = false;
2178 params.page_state = PageState::CreateFromURL(url3); 2177 params.page_state = PageState::CreateFromURL(url3);
2179 2178
2180 // Navigating should do nothing. 2179 // Navigating should do nothing.
2181 LoadCommittedDetails details; 2180 LoadCommittedDetails details;
2182 EXPECT_FALSE(controller.RendererDidNavigate(subframe2, params, &details)); 2181 EXPECT_FALSE(controller.RendererDidNavigate(subframe2, params, &details));
(...skipping 13 matching lines...) Expand all
2196 switches::kSitePerProcess)) { 2195 switches::kSitePerProcess)) {
2197 // The entry should now have 2 subframe FrameNavigationEntries. 2196 // The entry should now have 2 subframe FrameNavigationEntries.
2198 ASSERT_EQ(2U, entry->root_node()->children.size()); 2197 ASSERT_EQ(2U, entry->root_node()->children.size());
2199 FrameNavigationEntry* new_frame_entry = 2198 FrameNavigationEntry* new_frame_entry =
2200 entry->root_node()->children[1]->frame_entry.get(); 2199 entry->root_node()->children[1]->frame_entry.get();
2201 EXPECT_EQ(url3, new_frame_entry->url()); 2200 EXPECT_EQ(url3, new_frame_entry->url());
2202 } else { 2201 } else {
2203 // There are no subframe FrameNavigationEntries by default. 2202 // There are no subframe FrameNavigationEntries by default.
2204 EXPECT_EQ(0U, entry->root_node()->children.size()); 2203 EXPECT_EQ(0U, entry->root_node()->children.size());
2205 } 2204 }
2205
2206 // Add a nested subframe and navigate.
2207 subframe->OnCreateChildFrame(MSG_ROUTING_NONE, std::string(),
2208 SandboxFlags::NONE);
2209 RenderFrameHostImpl* subframe3 = contents()
2210 ->GetFrameTree()
2211 ->root()
2212 ->child_at(0)
2213 ->child_at(0)
2214 ->current_frame_host();
2215 const GURL url4("http://foo/4");
2216 {
2217 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2218 params.page_id = 1;
Avi (use Gerrit) 2015/05/14 18:01:11 params.nav_entry_id = 0; params.did_create_new_ent
Charlie Reis 2015/05/14 19:00:37 Done.
2219 params.url = url4;
2220 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
2221 params.should_update_history = false;
2222 params.gesture = NavigationGestureUser;
2223 params.is_post = false;
2224 params.page_state = PageState::CreateFromURL(url4);
2225
2226 // Navigating should do nothing.
2227 LoadCommittedDetails details;
2228 EXPECT_FALSE(controller.RendererDidNavigate(subframe3, params, &details));
2229 EXPECT_EQ(0U, notifications.size());
2230 }
2231
2232 // There should still be only one entry, mostly unchanged.
2233 EXPECT_EQ(1, controller.GetEntryCount());
2234 EXPECT_EQ(entry, controller.GetLastCommittedEntry());
2235 EXPECT_EQ(url1, entry->GetURL());
2236 EXPECT_EQ(1, entry->GetPageID());
2237 EXPECT_EQ(root_entry, entry->root_node()->frame_entry.get());
2238 EXPECT_EQ(url1, root_entry->url());
2239
2240 // Verify subframe entries if we're in --site-per-process mode.
2241 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
2242 switches::kSitePerProcess)) {
2243 // The entry should now have a nested FrameNavigationEntry.
2244 EXPECT_EQ(2U, entry->root_node()->children.size());
2245 ASSERT_EQ(1U, entry->root_node()->children[0]->children.size());
2246 FrameNavigationEntry* new_frame_entry =
2247 entry->root_node()->children[0]->children[0]->frame_entry.get();
2248 EXPECT_EQ(url4, new_frame_entry->url());
2249 } else {
2250 // There are no subframe FrameNavigationEntries by default.
2251 EXPECT_EQ(0U, entry->root_node()->children.size());
2252 }
2206 } 2253 }
2207 2254
2208 // Tests navigation and then going back to a subframe navigation. 2255 // Tests navigation and then going back to a subframe navigation.
2209 TEST_F(NavigationControllerTest, BackSubframe) { 2256 TEST_F(NavigationControllerTest, BackSubframe) {
2210 NavigationControllerImpl& controller = controller_impl(); 2257 NavigationControllerImpl& controller = controller_impl();
2211 TestNotificationTracker notifications; 2258 TestNotificationTracker notifications;
2212 RegisterForAllNavNotifications(&notifications, &controller); 2259 RegisterForAllNavNotifications(&notifications, &controller);
2213 2260
2214 // Main page. 2261 // Main page.
2215 const GURL url1("http://foo1"); 2262 const GURL url1("http://foo1");
(...skipping 1341 matching lines...) Expand 10 before | Expand all | Expand 10 after
3557 TEST_F(NavigationControllerTest, SameSubframe) { 3604 TEST_F(NavigationControllerTest, SameSubframe) {
3558 NavigationControllerImpl& controller = controller_impl(); 3605 NavigationControllerImpl& controller = controller_impl();
3559 // Navigate the main frame. 3606 // Navigate the main frame.
3560 const GURL url("http://www.google.com/"); 3607 const GURL url("http://www.google.com/");
3561 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, url); 3608 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, url);
3562 3609
3563 // We should be at the first navigation entry. 3610 // We should be at the first navigation entry.
3564 EXPECT_EQ(controller.GetEntryCount(), 1); 3611 EXPECT_EQ(controller.GetEntryCount(), 1);
3565 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 3612 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
3566 3613
3567 // Navigate a subframe that would normally count as in-page. 3614 // Add and navigate a subframe that would normally count as in-page.
3568 const GURL subframe("http://www.google.com/#"); 3615 main_test_rfh()->OnCreateChildFrame(MSG_ROUTING_NONE, std::string(),
3616 SandboxFlags::NONE);
3617 RenderFrameHostImpl* subframe =
3618 contents()->GetFrameTree()->root()->child_at(0)->current_frame_host();
3619 const GURL subframe_url("http://www.google.com/#");
3569 FrameHostMsg_DidCommitProvisionalLoad_Params params; 3620 FrameHostMsg_DidCommitProvisionalLoad_Params params;
3570 params.page_id = 0; 3621 params.page_id = 0;
3571 params.nav_entry_id = 0; 3622 params.nav_entry_id = 0;
3572 params.did_create_new_entry = false; 3623 params.did_create_new_entry = false;
3573 params.url = subframe; 3624 params.url = subframe_url;
3574 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; 3625 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
3575 params.should_update_history = false; 3626 params.should_update_history = false;
3576 params.gesture = NavigationGestureAuto; 3627 params.gesture = NavigationGestureAuto;
3577 params.is_post = false; 3628 params.is_post = false;
3578 params.page_state = PageState::CreateFromURL(subframe); 3629 params.page_state = PageState::CreateFromURL(subframe_url);
3579 LoadCommittedDetails details; 3630 LoadCommittedDetails details;
3580 EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), params, 3631 EXPECT_FALSE(controller.RendererDidNavigate(subframe, params, &details));
3581 &details));
3582 3632
3583 // Nothing should have changed. 3633 // Nothing should have changed.
3584 EXPECT_EQ(controller.GetEntryCount(), 1); 3634 EXPECT_EQ(controller.GetEntryCount(), 1);
3585 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0); 3635 EXPECT_EQ(controller.GetLastCommittedEntryIndex(), 0);
3586 } 3636 }
3587 3637
3588 // Make sure that on cloning a WebContentsImpl and going back needs_reload is 3638 // Make sure that on cloning a WebContentsImpl and going back needs_reload is
3589 // false. 3639 // false.
3590 TEST_F(NavigationControllerTest, CloneAndGoBack) { 3640 TEST_F(NavigationControllerTest, CloneAndGoBack) {
3591 NavigationControllerImpl& controller = controller_impl(); 3641 NavigationControllerImpl& controller = controller_impl();
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
3705 const GURL url1("http://foo/"); 3755 const GURL url1("http://foo/");
3706 NavigateAndCommit(url1); 3756 NavigateAndCommit(url1);
3707 3757
3708 // Now start a pending load to a totally different page, but don't commit it. 3758 // Now start a pending load to a totally different page, but don't commit it.
3709 const GURL url2("http://bar/"); 3759 const GURL url2("http://bar/");
3710 controller.LoadURL( 3760 controller.LoadURL(
3711 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 3761 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
3712 3762
3713 // Send a subframe update from the first page, as if one had just 3763 // Send a subframe update from the first page, as if one had just
3714 // automatically loaded. Auto subframes don't increment the page ID. 3764 // automatically loaded. Auto subframes don't increment the page ID.
3765 main_test_rfh()->OnCreateChildFrame(MSG_ROUTING_NONE, std::string(),
3766 SandboxFlags::NONE);
3767 RenderFrameHostImpl* subframe =
3768 contents()->GetFrameTree()->root()->child_at(0)->current_frame_host();
3715 const GURL url1_sub("http://foo/subframe"); 3769 const GURL url1_sub("http://foo/subframe");
3716 FrameHostMsg_DidCommitProvisionalLoad_Params params; 3770 FrameHostMsg_DidCommitProvisionalLoad_Params params;
3717 params.page_id = controller.GetLastCommittedEntry()->GetPageID(); 3771 params.page_id = controller.GetLastCommittedEntry()->GetPageID();
3718 params.nav_entry_id = 0; 3772 params.nav_entry_id = 0;
3719 params.did_create_new_entry = false; 3773 params.did_create_new_entry = false;
3720 params.url = url1_sub; 3774 params.url = url1_sub;
3721 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; 3775 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
3722 params.should_update_history = false; 3776 params.should_update_history = false;
3723 params.gesture = NavigationGestureAuto; 3777 params.gesture = NavigationGestureAuto;
3724 params.is_post = false; 3778 params.is_post = false;
3725 params.page_state = PageState::CreateFromURL(url1_sub); 3779 params.page_state = PageState::CreateFromURL(url1_sub);
3726 LoadCommittedDetails details; 3780 LoadCommittedDetails details;
3727 3781
3728 // This should return false meaning that nothing was actually updated. 3782 // This should return false meaning that nothing was actually updated.
3729 EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), params, 3783 EXPECT_FALSE(controller.RendererDidNavigate(subframe, params, &details));
3730 &details));
3731 3784
3732 // The notification should have updated the last committed one, and not 3785 // The notification should have updated the last committed one, and not
3733 // the pending load. 3786 // the pending load.
3734 EXPECT_EQ(url1, controller.GetLastCommittedEntry()->GetURL()); 3787 EXPECT_EQ(url1, controller.GetLastCommittedEntry()->GetURL());
3735 3788
3736 // The active entry should be unchanged by the subframe load. 3789 // The active entry should be unchanged by the subframe load.
3737 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL()); 3790 EXPECT_EQ(url2, controller.GetVisibleEntry()->GetURL());
3738 } 3791 }
3739 3792
3740 // Test CopyStateFrom with 2 urls, the first selected and nothing in the target. 3793 // 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 { 4884 {
4832 LoadCommittedDetails details; 4885 LoadCommittedDetails details;
4833 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); 4886 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details);
4834 EXPECT_EQ(PAGE_TYPE_ERROR, 4887 EXPECT_EQ(PAGE_TYPE_ERROR,
4835 controller_impl().GetLastCommittedEntry()->GetPageType()); 4888 controller_impl().GetLastCommittedEntry()->GetPageType());
4836 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, details.type); 4889 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, details.type);
4837 } 4890 }
4838 } 4891 }
4839 4892
4840 } // namespace content 4893 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698