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

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

Issue 925623002: Refactor the loading tracking logic in WebContentsImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments 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 (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 2861 matching lines...) Expand 10 before | Expand all | Expand 10 after
2872 EXPECT_TRUE(observer.is_loading()); 2872 EXPECT_TRUE(observer.is_loading());
2873 2873
2874 // Send the DidStopLoading for the main frame and ensure it isn't loading 2874 // Send the DidStopLoading for the main frame and ensure it isn't loading
2875 // anymore. 2875 // anymore.
2876 orig_rfh->OnMessageReceived( 2876 orig_rfh->OnMessageReceived(
2877 FrameHostMsg_DidStopLoading(orig_rfh->GetRoutingID())); 2877 FrameHostMsg_DidStopLoading(orig_rfh->GetRoutingID()));
2878 EXPECT_FALSE(contents()->IsLoading()); 2878 EXPECT_FALSE(contents()->IsLoading());
2879 EXPECT_FALSE(observer.is_loading()); 2879 EXPECT_FALSE(observer.is_loading());
2880 } 2880 }
2881 2881
2882 // Ensure that WebContentsImpl does not stop loading too early when there still
2883 // is a pending renderer. The sequence to reproduce the issue is as follows:
2884 // * Navigate and commit url1.
2885 // * Start a cross-site navigation to url2.
2886 // * Receive a DidStartLoading IPC from the pending RFH.
2887 // * Receive a DidStartLoading IPC from the current RFH.
2888 // * Receive a DidStopLoading IPC from the current RFH. At this point, the
2889 // WebContentsImpl should still be loading as there still is a pending frame.
2890 // Additionally, the now current RFH should be the previous loading RFH.
2891 // * Finally, receive a DidStopLoading IPC from the now current RFH.
2892 // WebContentsImpl should have stopped loading at this point.
clamy 2015/03/02 10:30:59 I think this is a bit too long as a comment. Inste
Fabrice (no longer in Chrome) 2015/03/02 18:01:40 Done.
2893 TEST_F(WebContentsImplTest, NoEarlyStop) {
2894 const GURL url1("http://www.chromium.org");
clamy 2015/03/02 10:30:59 Since these are const values, rename them kUrl1/kU
Fabrice (no longer in Chrome) 2015/03/02 18:01:40 Done.
2895 const GURL url2("http://www.google.com");
2896
2897 TestRenderFrameHost* current_rfh = contents()->GetMainFrame();
2898
2899 // Navigate the RenderFrameHost and commit. The frame should still be loading.
clamy 2015/03/02 10:30:59 You can replace all this below with contents()->Na
Fabrice (no longer in Chrome) 2015/03/02 18:01:40 Done.
2900 controller().LoadURL(
2901 url1, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
2902 contents()->TestDidNavigate(current_rfh, 1, url1, ui::PAGE_TRANSITION_TYPED);
2903 EXPECT_FALSE(contents()->cross_navigation_pending());
2904 EXPECT_EQ(current_rfh, contents()->GetMainFrame());
2905 EXPECT_TRUE(contents()->IsLoading());
2906
2907 // Navigate to new site and commit. The frame should still be loading.
clamy 2015/03/02 10:30:59 The comment should indicate that this is a browser
Fabrice (no longer in Chrome) 2015/03/02 18:01:40 Done.
2908 controller().LoadURL(
2909 url2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
2910 current_rfh->PrepareForCommit(url2);
clamy 2015/03/02 10:30:58 I don't think we should get to that step right now
Fabrice (no longer in Chrome) 2015/03/02 18:01:39 Done.
2911 EXPECT_TRUE(contents()->cross_navigation_pending());
2912 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame();
2913 ASSERT_NE(pending_rfh, nullptr);
2914 EXPECT_NE(current_rfh, pending_rfh);
2915 EXPECT_TRUE(contents()->IsLoading());
2916
2917 // Simulate the current RFH DidStartLoading. The frame should still be
2918 // loading.
clamy 2015/03/02 10:30:59 What you want to do here is simulate a renderer-in
Fabrice (no longer in Chrome) 2015/03/02 18:01:40 I suggest proceeding in another fashion, this test
2919 current_rfh->OnMessageReceived(
2920 FrameHostMsg_DidStartLoading(current_rfh->GetRoutingID(), false));
2921 EXPECT_TRUE(contents()->IsLoading());
2922
2923 // Simulate the pending RFH DidStartLoading. The frame should still be
2924 // loading.
2925 pending_rfh->OnMessageReceived(
2926 FrameHostMsg_DidStartLoading(pending_rfh->GetRoutingID(), false));
2927 contents()->TestDidNavigate(pending_rfh, 1, url2,
clamy 2015/03/02 10:30:59 The actual commit in the pending RFH should happen
Fabrice (no longer in Chrome) 2015/03/02 18:01:39 Done.
2928 ui::PAGE_TRANSITION_TYPED);
2929 EXPECT_TRUE(contents()->IsLoading());
2930
2931 // Simulate the original RFH DidStopLoading. The frame should still be
2932 // loading and the pending RFH should now be the current RFH.
clamy 2015/03/02 10:30:59 You should simulate the commit of the current RFH
Fabrice (no longer in Chrome) 2015/03/02 18:01:39 Done.
2933 current_rfh->OnMessageReceived(
2934 FrameHostMsg_DidStopLoading(current_rfh->GetRoutingID()));
2935 EXPECT_TRUE(contents()->IsLoading());
clamy 2015/03/02 10:30:59 Following this you should commit the navigation in
Fabrice (no longer in Chrome) 2015/03/02 18:01:39 Done.
2936 EXPECT_EQ(contents()->GetPendingMainFrame(), nullptr);
2937 TestRenderFrameHost *new_current_rfh = contents()->GetMainFrame();
2938 ASSERT_EQ(new_current_rfh, pending_rfh);
2939
2940 // Simulate the new current RFH DidStopLoading. The frame should now have
2941 // stopped loading.
2942 new_current_rfh->OnMessageReceived(
2943 FrameHostMsg_DidStopLoading(new_current_rfh->GetRoutingID()));
2944 EXPECT_FALSE(contents()->IsLoading());
2945 }
carlosk 2015/03/02 14:17:29 A couple general comments: * Replace RFH in your c
Fabrice (no longer in Chrome) 2015/03/02 18:01:39 Done.
2946
2882 TEST_F(WebContentsImplTest, MediaPowerSaveBlocking) { 2947 TEST_F(WebContentsImplTest, MediaPowerSaveBlocking) {
2883 // PlayerIDs are actually pointers cast to int64, so verify that both negative 2948 // PlayerIDs are actually pointers cast to int64, so verify that both negative
2884 // and positive player ids don't blow up. 2949 // and positive player ids don't blow up.
2885 const int kPlayerAudioVideoId = 15; 2950 const int kPlayerAudioVideoId = 15;
2886 const int kPlayerAudioOnlyId = -15; 2951 const int kPlayerAudioOnlyId = -15;
2887 const int kPlayerVideoOnlyId = 30; 2952 const int kPlayerVideoOnlyId = 30;
2888 const int kPlayerRemoteId = -30; 2953 const int kPlayerRemoteId = -30;
2889 2954
2890 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); 2955 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing());
2891 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); 2956 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing());
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
3036 frame->SendBeforeUnloadHandlersPresent(false); 3101 frame->SendBeforeUnloadHandlersPresent(false);
3037 EXPECT_FALSE(frame->SuddenTerminationAllowed()); 3102 EXPECT_FALSE(frame->SuddenTerminationAllowed());
3038 frame->SendBeforeUnloadHandlersPresent(true); 3103 frame->SendBeforeUnloadHandlersPresent(true);
3039 frame->SendUnloadHandlersPresent(false); 3104 frame->SendUnloadHandlersPresent(false);
3040 EXPECT_FALSE(frame->SuddenTerminationAllowed()); 3105 EXPECT_FALSE(frame->SuddenTerminationAllowed());
3041 frame->SendBeforeUnloadHandlersPresent(false); 3106 frame->SendBeforeUnloadHandlersPresent(false);
3042 EXPECT_TRUE(frame->SuddenTerminationAllowed()); 3107 EXPECT_TRUE(frame->SuddenTerminationAllowed());
3043 } 3108 }
3044 3109
3045 } // namespace content 3110 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698