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

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

Issue 1029893002: OOPIF: Create subframe FrameNavigationEntries for AUTO_SUBFRAME navigations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "content/browser/frame_host/cross_site_transferring_request.h" 14 #include "content/browser/frame_host/cross_site_transferring_request.h"
15 #include "content/browser/frame_host/frame_navigation_entry.h"
15 #include "content/browser/frame_host/navigation_controller_impl.h" 16 #include "content/browser/frame_host/navigation_controller_impl.h"
16 #include "content/browser/frame_host/navigation_entry_impl.h" 17 #include "content/browser/frame_host/navigation_entry_impl.h"
17 #include "content/browser/frame_host/navigation_entry_screenshot_manager.h" 18 #include "content/browser/frame_host/navigation_entry_screenshot_manager.h"
18 #include "content/browser/frame_host/navigation_request.h" 19 #include "content/browser/frame_host/navigation_request.h"
19 #include "content/browser/frame_host/navigator.h" 20 #include "content/browser/frame_host/navigator.h"
20 #include "content/browser/frame_host/navigator_impl.h" 21 #include "content/browser/frame_host/navigator_impl.h"
21 #include "content/browser/site_instance_impl.h" 22 #include "content/browser/site_instance_impl.h"
22 #include "content/browser/web_contents/web_contents_impl.h" 23 #include "content/browser/web_contents/web_contents_impl.h"
23 #include "content/common/frame_messages.h" 24 #include "content/common/frame_messages.h"
24 #include "content/common/view_messages.h" 25 #include "content/common/view_messages.h"
(...skipping 1934 matching lines...) Expand 10 before | Expand all | Expand 10 after
1959 EXPECT_EQ(2, controller.GetEntryCount()); 1960 EXPECT_EQ(2, controller.GetEntryCount());
1960 1961
1961 // New entry should refer to the new page, but the old URL (entries only 1962 // New entry should refer to the new page, but the old URL (entries only
1962 // reflect the toplevel URL). 1963 // reflect the toplevel URL).
1963 EXPECT_EQ(url1, details.entry->GetURL()); 1964 EXPECT_EQ(url1, details.entry->GetURL());
1964 EXPECT_EQ(params.page_id, details.entry->GetPageID()); 1965 EXPECT_EQ(params.page_id, details.entry->GetPageID());
1965 } 1966 }
1966 1967
1967 // Auto subframes are ones the page loads automatically like ads. They should 1968 // Auto subframes are ones the page loads automatically like ads. They should
1968 // not create new navigation entries. 1969 // not create new navigation entries.
1970 // TODO(creis): Test cross-site and nested iframes.
1971 // TODO(creis): Test updating entries for history auto subframe navigations.
1969 TEST_F(NavigationControllerTest, AutoSubframe) { 1972 TEST_F(NavigationControllerTest, AutoSubframe) {
1970 NavigationControllerImpl& controller = controller_impl(); 1973 NavigationControllerImpl& controller = controller_impl();
1971 TestNotificationTracker notifications; 1974 TestNotificationTracker notifications;
1972 RegisterForAllNavNotifications(&notifications, &controller); 1975 RegisterForAllNavNotifications(&notifications, &controller);
1973 1976
1974 const GURL url1("http://foo1"); 1977 const GURL url1("http://foo/1");
1975 main_test_rfh()->SendNavigate(0, url1); 1978 main_test_rfh()->SendNavigate(1, url1);
1976 EXPECT_EQ(1U, navigation_entry_committed_counter_); 1979 EXPECT_EQ(1U, navigation_entry_committed_counter_);
1977 navigation_entry_committed_counter_ = 0; 1980 navigation_entry_committed_counter_ = 0;
1978 1981
1979 const GURL url2("http://foo2"); 1982 // Add a subframe and navigate it.
1980 FrameHostMsg_DidCommitProvisionalLoad_Params params; 1983 main_test_rfh()->OnCreateChildFrame(MSG_ROUTING_NONE, std::string(),
1981 params.page_id = 0; 1984 SandboxFlags::NONE);
1982 params.url = url2; 1985 RenderFrameHostImpl* subframe =
1983 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME; 1986 contents()->GetFrameTree()->root()->child_at(0)->current_frame_host();
1984 params.should_update_history = false; 1987 const GURL url2("http://foo/2");
1985 params.gesture = NavigationGestureUser; 1988 {
1986 params.is_post = false; 1989 FrameHostMsg_DidCommitProvisionalLoad_Params params;
1987 params.page_state = PageState::CreateFromURL(url2); 1990 params.page_id = 1;
1991 params.url = url2;
1992 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
1993 params.should_update_history = false;
1994 params.gesture = NavigationGestureUser;
1995 params.is_post = false;
1996 params.page_state = PageState::CreateFromURL(url2);
1988 1997
1989 // Navigating should do nothing. 1998 // Navigating should do nothing.
1990 LoadCommittedDetails details; 1999 LoadCommittedDetails details;
1991 EXPECT_FALSE(controller.RendererDidNavigate(main_test_rfh(), params, 2000 EXPECT_FALSE(controller.RendererDidNavigate(subframe, params, &details));
1992 &details)); 2001 EXPECT_EQ(0U, notifications.size());
1993 EXPECT_EQ(0U, notifications.size()); 2002 }
1994 2003
1995 // There should still be only one entry. 2004 // There should still be only one entry.
1996 EXPECT_EQ(1, controller.GetEntryCount()); 2005 EXPECT_EQ(1, controller.GetEntryCount());
2006 NavigationEntryImpl* entry = controller.GetLastCommittedEntry();
2007 EXPECT_EQ(url1, entry->GetURL());
2008 EXPECT_EQ(1, entry->GetPageID());
2009 FrameNavigationEntry* root_entry = entry->root_node()->frame_entry.get();
2010 EXPECT_EQ(url1, root_entry->url());
2011
2012 // Verify subframe entries if we're in --site-per-process mode.
2013 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
2014 switches::kSitePerProcess)) {
2015 // The entry should now have a subframe FrameNavigationEntry.
2016 ASSERT_EQ(1U, entry->root_node()->children.size());
2017 FrameNavigationEntry* frame_entry =
2018 entry->root_node()->children[0]->frame_entry.get();
2019 EXPECT_EQ(url2, frame_entry->url());
2020 } else {
2021 // There are no subframe FrameNavigationEntries by default.
2022 EXPECT_EQ(0U, entry->root_node()->children.size());
2023 }
2024
2025 // Add a second subframe and navigate.
2026 main_test_rfh()->OnCreateChildFrame(MSG_ROUTING_NONE, std::string(),
2027 SandboxFlags::NONE);
2028 RenderFrameHostImpl* subframe2 =
2029 contents()->GetFrameTree()->root()->child_at(1)->current_frame_host();
2030 const GURL url3("http://foo/3");
2031 {
2032 FrameHostMsg_DidCommitProvisionalLoad_Params params;
2033 params.page_id = 1;
2034 params.url = url3;
2035 params.transition = ui::PAGE_TRANSITION_AUTO_SUBFRAME;
2036 params.should_update_history = false;
2037 params.gesture = NavigationGestureUser;
2038 params.is_post = false;
2039 params.page_state = PageState::CreateFromURL(url3);
2040
2041 // Navigating should do nothing.
2042 LoadCommittedDetails details;
2043 EXPECT_FALSE(controller.RendererDidNavigate(subframe2, params, &details));
2044 EXPECT_EQ(0U, notifications.size());
2045 }
2046
2047 // There should still be only one entry, mostly unchanged.
2048 EXPECT_EQ(1, controller.GetEntryCount());
2049 EXPECT_EQ(entry, controller.GetLastCommittedEntry());
2050 EXPECT_EQ(url1, entry->GetURL());
2051 EXPECT_EQ(1, entry->GetPageID());
2052 EXPECT_EQ(root_entry, entry->root_node()->frame_entry.get());
2053 EXPECT_EQ(url1, root_entry->url());
2054
2055 // Verify subframe entries if we're in --site-per-process mode.
2056 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
2057 switches::kSitePerProcess)) {
2058 // The entry should now have 2 subframe FrameNavigationEntries.
2059 ASSERT_EQ(2U, entry->root_node()->children.size());
2060 FrameNavigationEntry* new_frame_entry =
2061 entry->root_node()->children[1]->frame_entry.get();
2062 EXPECT_EQ(url3, new_frame_entry->url());
2063 } else {
2064 // There are no subframe FrameNavigationEntries by default.
2065 EXPECT_EQ(0U, entry->root_node()->children.size());
2066 }
1997 } 2067 }
1998 2068
1999 // Tests navigation and then going back to a subframe navigation. 2069 // Tests navigation and then going back to a subframe navigation.
2000 TEST_F(NavigationControllerTest, BackSubframe) { 2070 TEST_F(NavigationControllerTest, BackSubframe) {
2001 NavigationControllerImpl& controller = controller_impl(); 2071 NavigationControllerImpl& controller = controller_impl();
2002 TestNotificationTracker notifications; 2072 TestNotificationTracker notifications;
2003 RegisterForAllNavNotifications(&notifications, &controller); 2073 RegisterForAllNavNotifications(&notifications, &controller);
2004 2074
2005 // Main page. 2075 // Main page.
2006 const GURL url1("http://foo1"); 2076 const GURL url1("http://foo1");
(...skipping 2516 matching lines...) Expand 10 before | Expand all | Expand 10 after
4523 { 4593 {
4524 LoadCommittedDetails details; 4594 LoadCommittedDetails details;
4525 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details); 4595 controller_impl().RendererDidNavigate(main_test_rfh(), params, &details);
4526 EXPECT_EQ(PAGE_TYPE_ERROR, 4596 EXPECT_EQ(PAGE_TYPE_ERROR,
4527 controller_impl().GetLastCommittedEntry()->GetPageType()); 4597 controller_impl().GetLastCommittedEntry()->GetPageType());
4528 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, details.type); 4598 EXPECT_EQ(NAVIGATION_TYPE_IN_PAGE, details.type);
4529 } 4599 }
4530 } 4600 }
4531 4601
4532 } // namespace content 4602 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698