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

Side by Side Diff: content/browser/web_contents/web_contents_impl_unittest.cc

Issue 983973002: Revert of Refactor the loading tracking logic in WebContentsImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed patch conflict 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
« no previous file with comments | « content/browser/web_contents/web_contents_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/command_line.h" 5 #include "base/command_line.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "content/browser/frame_host/cross_site_transferring_request.h" 8 #include "content/browser/frame_host/cross_site_transferring_request.h"
9 #include "content/browser/frame_host/interstitial_page_impl.h" 9 #include "content/browser/frame_host/interstitial_page_impl.h"
10 #include "content/browser/frame_host/navigation_entry_impl.h" 10 #include "content/browser/frame_host/navigation_entry_impl.h"
(...skipping 2866 matching lines...) Expand 10 before | Expand all | Expand 10 after
2877 EXPECT_TRUE(observer.is_loading()); 2877 EXPECT_TRUE(observer.is_loading());
2878 2878
2879 // Send the DidStopLoading for the main frame and ensure it isn't loading 2879 // Send the DidStopLoading for the main frame and ensure it isn't loading
2880 // anymore. 2880 // anymore.
2881 orig_rfh->OnMessageReceived( 2881 orig_rfh->OnMessageReceived(
2882 FrameHostMsg_DidStopLoading(orig_rfh->GetRoutingID())); 2882 FrameHostMsg_DidStopLoading(orig_rfh->GetRoutingID()));
2883 EXPECT_FALSE(contents()->IsLoading()); 2883 EXPECT_FALSE(contents()->IsLoading());
2884 EXPECT_FALSE(observer.is_loading()); 2884 EXPECT_FALSE(observer.is_loading());
2885 } 2885 }
2886 2886
2887 // Ensure that WebContentsImpl does not stop loading too early when there still
2888 // is a pending renderer. This can happen if a same-process non user-initiated
2889 // navigation completes while there is an ongoing cross-process navigation.
2890 // TODO(fdegans): Rewrite the test for PlzNavigate when DidStartLoading and
2891 // DidStopLoading are properly called.
2892 TEST_F(WebContentsImplTest, NoEarlyStop) {
2893 const GURL kUrl1("http://www.chromium.org");
2894 const GURL kUrl2("http://www.google.com");
2895 const GURL kUrl3("http://www.wikipedia.org");
2896
2897 contents()->NavigateAndCommit(kUrl1);
2898
2899 TestRenderFrameHost* current_rfh = contents()->GetMainFrame();
2900
2901 // Start a browser-initiated cross-process navigation to |kUrl2|. There should
2902 // be a pending RenderFrameHost and the WebContents should be loading.
2903 controller().LoadURL(
2904 kUrl2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
2905 EXPECT_TRUE(contents()->cross_navigation_pending());
2906 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame();
2907 ASSERT_TRUE(pending_rfh);
2908 EXPECT_TRUE(contents()->IsLoading());
2909
2910 // The current RenderFrameHost starts a non user-initiated render-initiated
2911 // navigation and sends a DidStartLoading IPC. The WebContents should still be
2912 // loading.
2913 current_rfh->OnMessageReceived(
2914 FrameHostMsg_DidStartLoading(current_rfh->GetRoutingID(), false));
2915 EXPECT_TRUE(contents()->IsLoading());
2916
2917 // Simulate the pending RenderFrameHost DidStartLoading. There should still be
2918 // a pending RenderFrameHost and the WebContents should still be loading.
2919 pending_rfh->PrepareForCommit();
2920 pending_rfh->OnMessageReceived(
2921 FrameHostMsg_DidStartLoading(pending_rfh->GetRoutingID(), false));
2922 EXPECT_EQ(contents()->GetPendingMainFrame(), pending_rfh);
2923 EXPECT_TRUE(contents()->IsLoading());
2924
2925 // Simulate the commit and DidStopLoading from the renderer-initiated
2926 // navigation in the current RenderFrameHost. There should still be a pending
2927 // RenderFrameHost and the WebContents should still be loading.
2928 current_rfh->SendNavigate(1, kUrl3);
2929 current_rfh->OnMessageReceived(
2930 FrameHostMsg_DidStopLoading(current_rfh->GetRoutingID()));
2931 EXPECT_EQ(contents()->GetPendingMainFrame(), pending_rfh);
2932 EXPECT_TRUE(contents()->IsLoading());
2933
2934 // Commit the navigation. The formerly pending RenderFrameHost should now be
2935 // the current RenderFrameHost and the WebContents should still be loading.
2936 contents()->TestDidNavigate(pending_rfh, 1, kUrl2,
2937 ui::PAGE_TRANSITION_TYPED);
2938 EXPECT_FALSE(contents()->GetPendingMainFrame());
2939 TestRenderFrameHost* new_current_rfh = contents()->GetMainFrame();
2940 EXPECT_EQ(new_current_rfh, pending_rfh);
2941 EXPECT_TRUE(contents()->IsLoading());
2942
2943 // Simulate the new current RenderFrameHost DidStopLoading. The WebContents
2944 // should now have stopped loading.
2945 new_current_rfh->OnMessageReceived(
2946 FrameHostMsg_DidStopLoading(new_current_rfh->GetRoutingID()));
2947 EXPECT_EQ(contents()->GetMainFrame(), new_current_rfh);
2948 EXPECT_FALSE(contents()->IsLoading());
2949 }
2950
2951 TEST_F(WebContentsImplTest, MediaPowerSaveBlocking) { 2887 TEST_F(WebContentsImplTest, MediaPowerSaveBlocking) {
2952 // PlayerIDs are actually pointers cast to int64, so verify that both negative 2888 // PlayerIDs are actually pointers cast to int64, so verify that both negative
2953 // and positive player ids don't blow up. 2889 // and positive player ids don't blow up.
2954 const int kPlayerAudioVideoId = 15; 2890 const int kPlayerAudioVideoId = 15;
2955 const int kPlayerAudioOnlyId = -15; 2891 const int kPlayerAudioOnlyId = -15;
2956 const int kPlayerVideoOnlyId = 30; 2892 const int kPlayerVideoOnlyId = 30;
2957 const int kPlayerRemoteId = -30; 2893 const int kPlayerRemoteId = -30;
2958 2894
2959 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); 2895 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing());
2960 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); 2896 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing());
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
3105 frame->SendBeforeUnloadHandlersPresent(false); 3041 frame->SendBeforeUnloadHandlersPresent(false);
3106 EXPECT_FALSE(frame->SuddenTerminationAllowed()); 3042 EXPECT_FALSE(frame->SuddenTerminationAllowed());
3107 frame->SendBeforeUnloadHandlersPresent(true); 3043 frame->SendBeforeUnloadHandlersPresent(true);
3108 frame->SendUnloadHandlersPresent(false); 3044 frame->SendUnloadHandlersPresent(false);
3109 EXPECT_FALSE(frame->SuddenTerminationAllowed()); 3045 EXPECT_FALSE(frame->SuddenTerminationAllowed());
3110 frame->SendBeforeUnloadHandlersPresent(false); 3046 frame->SendBeforeUnloadHandlersPresent(false);
3111 EXPECT_TRUE(frame->SuddenTerminationAllowed()); 3047 EXPECT_TRUE(frame->SuddenTerminationAllowed());
3112 } 3048 }
3113 3049
3114 } // namespace content 3050 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_contents_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698