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