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

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

Issue 26316005: Move out DidStartProvisionalLoad from WebContentsImpl into Navigator. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixes based on Charlie's latest review. Created 7 years 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 | Annotate | Revision Log
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/file_util.h" 7 #include "base/file_util.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/path_service.h" 9 #include "base/path_service.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/navigation_controller_impl.h" 14 #include "content/browser/frame_host/navigation_controller_impl.h"
15 #include "content/browser/frame_host/navigation_entry_impl.h" 15 #include "content/browser/frame_host/navigation_entry_impl.h"
16 #include "content/browser/frame_host/navigation_entry_screenshot_manager.h" 16 #include "content/browser/frame_host/navigation_entry_screenshot_manager.h"
17 #include "content/browser/frame_host/navigator.h"
17 #include "content/browser/site_instance_impl.h" 18 #include "content/browser/site_instance_impl.h"
18 #include "content/browser/web_contents/web_contents_impl.h" 19 #include "content/browser/web_contents/web_contents_impl.h"
19 #include "content/common/view_messages.h" 20 #include "content/common/view_messages.h"
20 #include "content/public/browser/navigation_details.h" 21 #include "content/public/browser/navigation_details.h"
21 #include "content/public/browser/notification_registrar.h" 22 #include "content/public/browser/notification_registrar.h"
22 #include "content/public/browser/notification_types.h" 23 #include "content/public/browser/notification_types.h"
23 #include "content/public/browser/render_view_host.h" 24 #include "content/public/browser/render_view_host.h"
24 #include "content/public/browser/web_contents_delegate.h" 25 #include "content/public/browser/web_contents_delegate.h"
25 #include "content/public/browser/web_contents_observer.h" 26 #include "content/public/browser/web_contents_observer.h"
26 #include "content/public/common/page_state.h" 27 #include "content/public/common/page_state.h"
(...skipping 2614 matching lines...) Expand 10 before | Expand all | Expand 10 after
2641 ASSERT_EQ(controller.GetEntryCount(), 2); 2642 ASSERT_EQ(controller.GetEntryCount(), 2);
2642 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0); 2643 EXPECT_EQ(controller.GetEntryAtIndex(0)->GetURL(), url0);
2643 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), transient_url); 2644 EXPECT_EQ(controller.GetEntryAtIndex(1)->GetURL(), transient_url);
2644 } 2645 }
2645 2646
2646 // Ensure that renderer initiated pending entries get replaced, so that we 2647 // Ensure that renderer initiated pending entries get replaced, so that we
2647 // don't show a stale virtual URL when a navigation commits. 2648 // don't show a stale virtual URL when a navigation commits.
2648 // See http://crbug.com/266922. 2649 // See http://crbug.com/266922.
2649 TEST_F(NavigationControllerTest, RendererInitiatedPendingEntries) { 2650 TEST_F(NavigationControllerTest, RendererInitiatedPendingEntries) {
2650 NavigationControllerImpl& controller = controller_impl(); 2651 NavigationControllerImpl& controller = controller_impl();
2652 Navigator* navigator =
2653 contents()->GetFrameTree()->root()->navigator();
2651 2654
2652 const GURL url1("nonexistent:12121"); 2655 const GURL url1("nonexistent:12121");
2653 const GURL url1_fixed("http://nonexistent:12121/"); 2656 const GURL url1_fixed("http://nonexistent:12121/");
2654 const GURL url2("http://foo"); 2657 const GURL url2("http://foo");
2655 2658
2656 // We create pending entries for renderer-initiated navigations so that we 2659 // We create pending entries for renderer-initiated navigations so that we
2657 // can show them in new tabs when it is safe. 2660 // can show them in new tabs when it is safe.
2658 contents()->DidStartProvisionalLoadForFrame( 2661 navigator->DidStartProvisionalLoad(main_test_rfh(), 1, -1, true, url1);
2659 test_rvh(), 1, -1, true, url1);
2660 2662
2661 // Simulate what happens if a BrowserURLHandler rewrites the URL, causing 2663 // Simulate what happens if a BrowserURLHandler rewrites the URL, causing
2662 // the virtual URL to differ from the URL. 2664 // the virtual URL to differ from the URL.
2663 controller.GetPendingEntry()->SetURL(url1_fixed); 2665 controller.GetPendingEntry()->SetURL(url1_fixed);
2664 controller.GetPendingEntry()->SetVirtualURL(url1); 2666 controller.GetPendingEntry()->SetVirtualURL(url1);
2665 2667
2666 EXPECT_EQ(url1_fixed, controller.GetPendingEntry()->GetURL()); 2668 EXPECT_EQ(url1_fixed, controller.GetPendingEntry()->GetURL());
2667 EXPECT_EQ(url1, controller.GetPendingEntry()->GetVirtualURL()); 2669 EXPECT_EQ(url1, controller.GetPendingEntry()->GetVirtualURL());
2668 EXPECT_TRUE( 2670 EXPECT_TRUE(
2669 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> 2671 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())->
2670 is_renderer_initiated()); 2672 is_renderer_initiated());
2671 2673
2672 // If the user clicks another link, we should replace the pending entry. 2674 // If the user clicks another link, we should replace the pending entry.
2673 contents()->DidStartProvisionalLoadForFrame( 2675 navigator->DidStartProvisionalLoad(main_test_rfh(), 1, -1, true, url2);
2674 test_rvh(), 1, -1, true, url2);
2675 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL()); 2676 EXPECT_EQ(url2, controller.GetPendingEntry()->GetURL());
2676 EXPECT_EQ(url2, controller.GetPendingEntry()->GetVirtualURL()); 2677 EXPECT_EQ(url2, controller.GetPendingEntry()->GetVirtualURL());
2677 2678
2678 // Once it commits, the URL and virtual URL should reflect the actual page. 2679 // Once it commits, the URL and virtual URL should reflect the actual page.
2679 test_rvh()->SendNavigate(0, url2); 2680 test_rvh()->SendNavigate(0, url2);
2680 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); 2681 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL());
2681 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetVirtualURL()); 2682 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetVirtualURL());
2682 2683
2683 // We should not replace the pending entry for an error URL. 2684 // We should not replace the pending entry for an error URL.
2684 contents()->DidStartProvisionalLoadForFrame( 2685 navigator->DidStartProvisionalLoad(main_test_rfh(), 1, -1, true, url1);
2685 test_rvh(), 1, -1, true, url1);
2686 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); 2686 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL());
2687 contents()->DidStartProvisionalLoadForFrame( 2687 navigator->DidStartProvisionalLoad(
2688 test_rvh(), 1, -1, true, GURL(kUnreachableWebDataURL)); 2688 main_test_rfh(), 1, -1, true, GURL(kUnreachableWebDataURL));
2689 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL()); 2689 EXPECT_EQ(url1, controller.GetPendingEntry()->GetURL());
2690 2690
2691 // We should remember if the pending entry will replace the current one. 2691 // We should remember if the pending entry will replace the current one.
2692 // http://crbug.com/308444. 2692 // http://crbug.com/308444.
2693 contents()->DidStartProvisionalLoadForFrame( 2693 navigator->DidStartProvisionalLoad(main_test_rfh(), 1, -1, true, url1);
2694 test_rvh(), 1, -1, true, url1);
2695 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> 2694 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())->
2696 set_should_replace_entry(true); 2695 set_should_replace_entry(true);
2697 contents()->DidStartProvisionalLoadForFrame( 2696 navigator->DidStartProvisionalLoad(main_test_rfh(), 1, -1, true, url2);
2698 test_rvh(), 1, -1, true, url2);
2699 EXPECT_TRUE( 2697 EXPECT_TRUE(
2700 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())-> 2698 NavigationEntryImpl::FromNavigationEntry(controller.GetPendingEntry())->
2701 should_replace_entry()); 2699 should_replace_entry());
2700 // TODO(nasko): Until OnNavigate is moved to RenderFrameHost, we need
2701 // to go through the RenderViewHost. The TestRenderViewHost routes navigations
2702 // to the main frame.
2702 test_rvh()->SendNavigate(0, url2); 2703 test_rvh()->SendNavigate(0, url2);
2703 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL()); 2704 EXPECT_EQ(url2, controller.GetLastCommittedEntry()->GetURL());
2704 } 2705 }
2705 2706
2706 // Tests that the URLs for renderer-initiated navigations are not displayed to 2707 // Tests that the URLs for renderer-initiated navigations are not displayed to
2707 // the user until the navigation commits, to prevent URL spoof attacks. 2708 // the user until the navigation commits, to prevent URL spoof attacks.
2708 // See http://crbug.com/99016. 2709 // See http://crbug.com/99016.
2709 TEST_F(NavigationControllerTest, DontShowRendererURLUntilCommit) { 2710 TEST_F(NavigationControllerTest, DontShowRendererURLUntilCommit) {
2710 NavigationControllerImpl& controller = controller_impl(); 2711 NavigationControllerImpl& controller = controller_impl();
2711 TestNotificationTracker notifications; 2712 TestNotificationTracker notifications;
(...skipping 1123 matching lines...) Expand 10 before | Expand all | Expand 10 after
3835 EXPECT_EQ(1, controller.GetEntryCount()); 3836 EXPECT_EQ(1, controller.GetEntryCount());
3836 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); 3837 EXPECT_EQ(0, controller.GetCurrentEntryIndex());
3837 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); 3838 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
3838 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 3839 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
3839 EXPECT_FALSE(controller.CanGoBack()); 3840 EXPECT_FALSE(controller.CanGoBack());
3840 EXPECT_FALSE(controller.CanGoForward()); 3841 EXPECT_FALSE(controller.CanGoForward());
3841 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); 3842 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL());
3842 } 3843 }
3843 3844
3844 } // namespace content 3845 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/frame_tree_unittest.cc ('k') | content/browser/frame_host/navigator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698