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

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

Issue 1143653002: Create FrameNavigationEntries for manual subframe navigations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use MatchesFrame 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 2050 matching lines...) Expand 10 before | Expand all | Expand 10 after
2061 } 2061 }
2062 2062
2063 // Tests navigation via link click within a subframe. A new navigation entry 2063 // Tests navigation via link click within a subframe. A new navigation entry
2064 // should be created. 2064 // should be created.
2065 TEST_F(NavigationControllerTest, NewSubframe) { 2065 TEST_F(NavigationControllerTest, NewSubframe) {
2066 NavigationControllerImpl& controller = controller_impl(); 2066 NavigationControllerImpl& controller = controller_impl();
2067 TestNotificationTracker notifications; 2067 TestNotificationTracker notifications;
2068 RegisterForAllNavNotifications(&notifications, &controller); 2068 RegisterForAllNavNotifications(&notifications, &controller);
2069 2069
2070 const GURL url1("http://foo1"); 2070 const GURL url1("http://foo1");
2071 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, url1); 2071 main_test_rfh()->NavigateAndCommitRendererInitiated(1, true, url1);
2072 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2072 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2073 navigation_entry_committed_counter_ = 0; 2073 navigation_entry_committed_counter_ = 0;
2074 2074
2075 // Prereq: add a subframe with an initial auto-subframe navigation.
2076 main_test_rfh()->OnCreateChildFrame(MSG_ROUTING_NONE, std::string(),
2077 SandboxFlags::NONE);
2078 RenderFrameHostImpl* subframe =
2079 contents()->GetFrameTree()->root()->child_at(0)->current_frame_host();
2080 const GURL subframe_url("http://foo1/subframe");
2081 {
2082 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2083 params.page_id = 1;
2084 params.nav_entry_id = 0;
2085 params.did_create_new_entry = false;
2086 params.url = subframe_url;
2087 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
2088 params.should_update_history = false;
2089 params.gesture = NavigationGestureUser;
2090 params.is_post = false;
2091 params.page_state = PageState::CreateFromURL(subframe_url);
2092
2093 // Navigating should do nothing.
2094 LoadCommittedDetails details;
2095 EXPECT_FALSE(controller.RendererDidNavigate(subframe, params, &details));
2096 EXPECT_EQ(0U, notifications.size());
2097 }
2098
2099 // Now do a new navigation in the frame.
2075 const GURL url2("http://foo2"); 2100 const GURL url2("http://foo2");
2076 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2101 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2077 params.page_id = 1; 2102 params.page_id = 2;
2078 params.nav_entry_id = 0; 2103 params.nav_entry_id = 0;
2079 params.did_create_new_entry = true; 2104 params.did_create_new_entry = true;
2080 params.url = url2; 2105 params.url = url2;
2081 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; 2106 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME;
2082 params.should_update_history = false; 2107 params.should_update_history = false;
2083 params.gesture = NavigationGestureUser; 2108 params.gesture = NavigationGestureUser;
2084 params.is_post = false; 2109 params.is_post = false;
2085 params.page_state = PageState::CreateFromURL(url2); 2110 params.page_state = PageState::CreateFromURL(url2);
2086 2111
2087 LoadCommittedDetails details; 2112 LoadCommittedDetails details;
2088 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 2113 EXPECT_TRUE(controller.RendererDidNavigate(subframe, params, &details));
2089 &details));
2090 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2114 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2091 navigation_entry_committed_counter_ = 0; 2115 navigation_entry_committed_counter_ = 0;
2092 EXPECT_EQ(url1, details.previous_url); 2116 EXPECT_EQ(url1, details.previous_url);
2093 EXPECT_FALSE(details.is_in_page); 2117 EXPECT_FALSE(details.is_in_page);
2094 EXPECT_FALSE(details.is_main_frame); 2118 EXPECT_FALSE(details.is_main_frame);
2095 2119
2096 // The new entry should be appended. 2120 // The new entry should be appended.
2121 NavigationEntryImpl* entry = controller.GetLastCommittedEntry();
2097 EXPECT_EQ(2, controller.GetEntryCount()); 2122 EXPECT_EQ(2, controller.GetEntryCount());
2123 EXPECT_EQ(entry, details.entry);
2098 2124
2099 // New entry should refer to the new page, but the old URL (entries only 2125 // New entry should refer to the new page, but the old URL (entries only
2100 // reflect the toplevel URL). 2126 // reflect the toplevel URL).
2101 EXPECT_EQ(url1, details.entry->GetURL()); 2127 EXPECT_EQ(url1, entry->GetURL());
2102 EXPECT_EQ(params.page_id, details.entry->GetPageID()); 2128 EXPECT_EQ(params.page_id, entry->GetPageID());
2129
2130 // Verify subframe entries if we're in --site-per-process mode.
2131 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
2132 switches::kSitePerProcess)) {
2133 // The entry should have a subframe FrameNavigationEntry.
2134 ASSERT_EQ(1U, entry->root_node()->children.size());
2135 EXPECT_EQ(url2, entry->root_node()->children[0]->frame_entry->url());
2136 } else {
2137 // There are no subframe FrameNavigationEntries by default.
2138 EXPECT_EQ(0U, entry->root_node()->children.size());
2139 }
2103 } 2140 }
2104 2141
2105 // Auto subframes are ones the page loads automatically like ads. They should 2142 // Auto subframes are ones the page loads automatically like ads. They should
2106 // not create new navigation entries. 2143 // not create new navigation entries.
2107 // TODO(creis): Test updating entries for history auto subframe navigations. 2144 // TODO(creis): Test updating entries for history auto subframe navigations.
2108 TEST_F(NavigationControllerTest, AutoSubframe) { 2145 TEST_F(NavigationControllerTest, AutoSubframe) {
2109 NavigationControllerImpl& controller = controller_impl(); 2146 NavigationControllerImpl& controller = controller_impl();
2110 TestNotificationTracker notifications; 2147 TestNotificationTracker notifications;
2111 RegisterForAllNavNotifications(&notifications, &controller); 2148 RegisterForAllNavNotifications(&notifications, &controller);
2112 2149
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
2257 } 2294 }
2258 2295
2259 // Tests navigation and then going back to a subframe navigation. 2296 // Tests navigation and then going back to a subframe navigation.
2260 TEST_F(NavigationControllerTest, BackSubframe) { 2297 TEST_F(NavigationControllerTest, BackSubframe) {
2261 NavigationControllerImpl& controller = controller_impl(); 2298 NavigationControllerImpl& controller = controller_impl();
2262 TestNotificationTracker notifications; 2299 TestNotificationTracker notifications;
2263 RegisterForAllNavNotifications(&notifications, &controller); 2300 RegisterForAllNavNotifications(&notifications, &controller);
2264 2301
2265 // Main page. 2302 // Main page.
2266 const GURL url1("http://foo1"); 2303 const GURL url1("http://foo1");
2267 main_test_rfh()->NavigateAndCommitRendererInitiated(0, true, url1); 2304 main_test_rfh()->NavigateAndCommitRendererInitiated(1, true, url1);
2268 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2305 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2269 NavigationEntry* entry1 = controller.GetLastCommittedEntry(); 2306 NavigationEntry* entry1 = controller.GetLastCommittedEntry();
2270 navigation_entry_committed_counter_ = 0; 2307 navigation_entry_committed_counter_ = 0;
2271 2308
2309 // Prereq: add a subframe with an initial auto-subframe navigation.
2310 main_test_rfh()->OnCreateChildFrame(MSG_ROUTING_NONE, std::string(),
2311 SandboxFlags::NONE);
2312 RenderFrameHostImpl* subframe =
2313 contents()->GetFrameTree()->root()->child_at(0)->current_frame_host();
2314 const GURL subframe_url("http://foo1/subframe");
2315 {
2316 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2317 params.page_id = 1;
2318 params.nav_entry_id = 0;
2319 params.did_create_new_entry = false;
2320 params.url = subframe_url;
2321 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
2322 params.should_update_history = false;
2323 params.gesture = NavigationGestureUser;
2324 params.is_post = false;
2325 params.page_state = PageState::CreateFromURL(subframe_url);
2326
2327 // Navigating should do nothing.
2328 LoadCommittedDetails details;
2329 EXPECT_FALSE(controller.RendererDidNavigate(subframe, params, &details));
2330 EXPECT_EQ(0U, notifications.size());
2331 }
2332
2272 // First manual subframe navigation. 2333 // First manual subframe navigation.
2273 const GURL url2("http://foo2"); 2334 const GURL url2("http://foo2");
2274 FrameHostMsg_DidCommitProvisionalLoad_Params params; 2335 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2275 params.page_id = 1; 2336 params.page_id = 2;
2276 params.nav_entry_id = 0; 2337 params.nav_entry_id = 0;
2277 params.did_create_new_entry = true; 2338 params.did_create_new_entry = true;
2278 params.url = url2; 2339 params.url = url2;
2279 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; 2340 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME;
2280 params.should_update_history = false; 2341 params.should_update_history = false;
2281 params.gesture = NavigationGestureUser; 2342 params.gesture = NavigationGestureUser;
2282 params.is_post = false; 2343 params.is_post = false;
2283 params.page_state = PageState::CreateFromURL(url2); 2344 params.page_state = PageState::CreateFromURL(url2);
2284 2345
2285 // This should generate a new entry. 2346 // This should generate a new entry.
2286 LoadCommittedDetails details; 2347 LoadCommittedDetails details;
2287 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 2348 EXPECT_TRUE(controller.RendererDidNavigate(subframe, params, &details));
2288 &details)); 2349 NavigationEntryImpl* entry2 = controller.GetLastCommittedEntry();
2289 NavigationEntry* entry2 = controller.GetLastCommittedEntry();
2290 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2350 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2291 navigation_entry_committed_counter_ = 0; 2351 navigation_entry_committed_counter_ = 0;
2292 EXPECT_EQ(2, controller.GetEntryCount()); 2352 EXPECT_EQ(2, controller.GetEntryCount());
2293 2353
2354 // Verify subframe entries if we're in --site-per-process mode.
2355 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
2356 switches::kSitePerProcess)) {
2357 // The entry should have a subframe FrameNavigationEntry.
2358 ASSERT_EQ(1U, entry2->root_node()->children.size());
2359 EXPECT_EQ(url2, entry2->root_node()->children[0]->frame_entry->url());
2360 } else {
2361 // There are no subframe FrameNavigationEntries by default.
2362 EXPECT_EQ(0U, entry2->root_node()->children.size());
2363 }
2364
2294 // Second manual subframe navigation should also make a new entry. 2365 // Second manual subframe navigation should also make a new entry.
2295 const GURL url3("http://foo3"); 2366 const GURL url3("http://foo3");
2296 params.page_id = 2; 2367 params.page_id = 3;
2297 params.nav_entry_id = 0; 2368 params.nav_entry_id = 0;
2298 params.did_create_new_entry = true; 2369 params.did_create_new_entry = true;
2299 params.url = url3; 2370 params.url = url3;
2300 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME; 2371 params.transition = ui::PAGE_TRANSITION_MANUAL_SUBFRAME;
2301 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 2372 EXPECT_TRUE(controller.RendererDidNavigate(subframe, params, &details));
2302 &details));
2303 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2373 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2304 navigation_entry_committed_counter_ = 0; 2374 navigation_entry_committed_counter_ = 0;
2375 NavigationEntryImpl* entry3 = controller.GetLastCommittedEntry();
2305 EXPECT_EQ(3, controller.GetEntryCount()); 2376 EXPECT_EQ(3, controller.GetEntryCount());
2306 EXPECT_EQ(2, controller.GetCurrentEntryIndex()); 2377 EXPECT_EQ(2, controller.GetCurrentEntryIndex());
2307 2378
2379 // Verify subframe entries if we're in --site-per-process mode.
2380 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
2381 switches::kSitePerProcess)) {
2382 // The entry should have a subframe FrameNavigationEntry.
2383 ASSERT_EQ(1U, entry3->root_node()->children.size());
2384 EXPECT_EQ(url3, entry3->root_node()->children[0]->frame_entry->url());
2385 } else {
2386 // There are no subframe FrameNavigationEntries by default.
2387 EXPECT_EQ(0U, entry3->root_node()->children.size());
2388 }
2389
2308 // Go back one. 2390 // Go back one.
2309 controller.GoBack(); 2391 controller.GoBack();
2310 params.page_id = 1; 2392 params.page_id = 2;
2311 params.nav_entry_id = entry2->GetUniqueID(); 2393 params.nav_entry_id = entry2->GetUniqueID();
2312 params.did_create_new_entry = false; 2394 params.did_create_new_entry = false;
2313 params.url = url2; 2395 params.url = url2;
2314 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; 2396 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
2315 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 2397 EXPECT_TRUE(controller.RendererDidNavigate(subframe, params, &details));
2316 &details));
2317 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2398 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2318 navigation_entry_committed_counter_ = 0; 2399 navigation_entry_committed_counter_ = 0;
2400 EXPECT_EQ(entry2, controller.GetLastCommittedEntry());
2319 EXPECT_EQ(3, controller.GetEntryCount()); 2401 EXPECT_EQ(3, controller.GetEntryCount());
2320 EXPECT_EQ(1, controller.GetCurrentEntryIndex()); 2402 EXPECT_EQ(1, controller.GetCurrentEntryIndex());
2321 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 2403 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
2322 EXPECT_FALSE(controller.GetPendingEntry()); 2404 EXPECT_FALSE(controller.GetPendingEntry());
2323 2405
2324 // Go back one more. 2406 // Go back one more.
2325 controller.GoBack(); 2407 controller.GoBack();
2326 params.page_id = 0; 2408 params.page_id = 1;
2327 params.nav_entry_id = entry1->GetUniqueID(); 2409 params.nav_entry_id = entry1->GetUniqueID();
2328 params.did_create_new_entry = false; 2410 params.did_create_new_entry = false;
2329 params.url = url1; 2411 params.url = url1;
2330 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; 2412 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
2331 EXPECT_TRUE(controller.RendererDidNavigate(main_test_rfh(), params, 2413 EXPECT_TRUE(controller.RendererDidNavigate(subframe, params, &details));
2332 &details));
2333 EXPECT_EQ(1U, navigation_entry_committed_counter_); 2414 EXPECT_EQ(1U, navigation_entry_committed_counter_);
2334 navigation_entry_committed_counter_ = 0; 2415 navigation_entry_committed_counter_ = 0;
2416 EXPECT_EQ(entry1, controller.GetLastCommittedEntry());
2335 EXPECT_EQ(3, controller.GetEntryCount()); 2417 EXPECT_EQ(3, controller.GetEntryCount());
2336 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); 2418 EXPECT_EQ(0, controller.GetCurrentEntryIndex());
2337 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 2419 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
2338 EXPECT_FALSE(controller.GetPendingEntry()); 2420 EXPECT_FALSE(controller.GetPendingEntry());
2339 } 2421 }
2340 2422
2341 TEST_F(NavigationControllerTest, LinkClick) { 2423 TEST_F(NavigationControllerTest, LinkClick) {
2342 NavigationControllerImpl& controller = controller_impl(); 2424 NavigationControllerImpl& controller = controller_impl();
2343 TestNotificationTracker notifications; 2425 TestNotificationTracker notifications;
2344 RegisterForAllNavNotifications(&notifications, &controller); 2426 RegisterForAllNavNotifications(&notifications, &controller);
(...skipping 2543 matching lines...) Expand 10 before | Expand all | Expand 10 after
4888 { 4970 {
4889 LoadCommittedDetails details; 4971 LoadCommittedDetails details;
4890 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); 4972 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details);
4891 EXPECT_EQ(PAGE_TYPE_ERROR, 4973 EXPECT_EQ(PAGE_TYPE_ERROR,
4892 controller_impl().GetLastCommittedEntry()->GetPageType()); 4974 controller_impl().GetLastCommittedEntry()->GetPageType());
4893 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, details.type); 4975 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, details.type);
4894 } 4976 }
4895 } 4977 }
4896 4978
4897 } // namespace content 4979 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698