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

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 19 matching lines...) Expand all
30 #include "content/public/common/content_switches.h" 30 #include "content/public/common/content_switches.h"
31 #include "content/public/common/url_constants.h" 31 #include "content/public/common/url_constants.h"
32 #include "content/public/common/url_utils.h" 32 #include "content/public/common/url_utils.h"
33 #include "content/public/test/mock_render_process_host.h" 33 #include "content/public/test/mock_render_process_host.h"
34 #include "content/public/test/test_utils.h" 34 #include "content/public/test/test_utils.h"
35 #include "content/test/test_content_browser_client.h" 35 #include "content/test/test_content_browser_client.h"
36 #include "content/test/test_content_client.h" 36 #include "content/test/test_content_client.h"
37 #include "content/test/test_render_frame_host.h" 37 #include "content/test/test_render_frame_host.h"
38 #include "content/test/test_render_view_host.h" 38 #include "content/test/test_render_view_host.h"
39 #include "content/test/test_web_contents.h" 39 #include "content/test/test_web_contents.h"
40 #include "net/base/load_flags.h"
40 #include "testing/gtest/include/gtest/gtest.h" 41 #include "testing/gtest/include/gtest/gtest.h"
41 42
42 namespace content { 43 namespace content {
43 namespace { 44 namespace {
44 45
45 const char kTestWebUIUrl[] = "chrome://blah"; 46 const char kTestWebUIUrl[] = "chrome://blah";
46 47
47 class WebContentsImplTestWebUIControllerFactory 48 class WebContentsImplTestWebUIControllerFactory
48 : public WebUIControllerFactory { 49 : public WebUIControllerFactory {
49 public: 50 public:
(...skipping 2822 matching lines...) Expand 10 before | Expand all | Expand 10 after
2872 EXPECT_TRUE(observer.is_loading()); 2873 EXPECT_TRUE(observer.is_loading());
2873 2874
2874 // Send the DidStopLoading for the main frame and ensure it isn't loading 2875 // Send the DidStopLoading for the main frame and ensure it isn't loading
2875 // anymore. 2876 // anymore.
2876 orig_rfh->OnMessageReceived( 2877 orig_rfh->OnMessageReceived(
2877 FrameHostMsg_DidStopLoading(orig_rfh->GetRoutingID())); 2878 FrameHostMsg_DidStopLoading(orig_rfh->GetRoutingID()));
2878 EXPECT_FALSE(contents()->IsLoading()); 2879 EXPECT_FALSE(contents()->IsLoading());
2879 EXPECT_FALSE(observer.is_loading()); 2880 EXPECT_FALSE(observer.is_loading());
2880 } 2881 }
2881 2882
2883 // Ensure that WebContentsImpl does not stop loading too early when there still
2884 // is a pending renderer. This can happen if a same-process non user-initiated
2885 // navigation completes while there is an ongoing cross-process navigation.
2886 // TODO(fdegans): Rewrite the test for PlzNavigate when DidStartLoading and
2887 // DidStopLoading are properly called.
2888 TEST_F(WebContentsImplTest, NoEarlyStop) {
2889 const GURL kUrl1("http://www.chromium.org");
2890 const GURL kUrl2("http://www.google.com");
2891 const GURL kUrl3("http://www.wikipedia.org");
2892
2893 contents()->NavigateAndCommit(kUrl1);
2894
2895 TestRenderFrameHost* current_rfh = contents()->GetMainFrame();
2896
2897 // Start a browser-initiated cross-process navigation to |kUrl2|. There should
2898 // be a pending RenderFrameHost and the frame should be loading.
Charlie Reis 2015/03/03 06:32:23 The comment says "the frame should be loading" but
Fabrice (no longer in Chrome) 2015/03/03 13:12:17 We should not check the frame before the call to D
2899 controller().LoadURL(
2900 kUrl2, Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
2901 EXPECT_TRUE(contents()->cross_navigation_pending());
2902 TestRenderFrameHost* pending_rfh = contents()->GetPendingMainFrame();
2903 ASSERT_NE(pending_rfh, nullptr);
2904 EXPECT_TRUE(contents()->IsLoading());
2905
2906 // The current RenderFrameHost starts a non user-initiated render-initiated
2907 // navigation and sends a DidStartLoading IPC. The frame should still be
2908 // loading.
2909 current_rfh->OnMessageReceived(
2910 FrameHostMsg_DidStartLoading(current_rfh->GetRoutingID(), false));
2911 EXPECT_TRUE(contents()->IsLoading());
2912
2913 // Simulate the pending RenderFrameHost DidStartLoading. There should still be
2914 // a pending RenderFrameHost and the frame should still be loading.
2915 pending_rfh->PrepareForCommit(kUrl2);
2916 pending_rfh->OnMessageReceived(
2917 FrameHostMsg_DidStartLoading(pending_rfh->GetRoutingID(), false));
2918 EXPECT_EQ(contents()->GetPendingMainFrame(), pending_rfh);
2919 EXPECT_TRUE(contents()->IsLoading());
2920
2921 // Simulate the current RenderFrameHost DidStopLoading. There should still be
2922 // a pending RenderFrameHost and the frame should still be loading.
2923 current_rfh->SendNavigate(1, kUrl3);
2924 current_rfh->OnMessageReceived(
2925 FrameHostMsg_DidStopLoading(current_rfh->GetRoutingID()));
2926 EXPECT_EQ(contents()->GetPendingMainFrame(), pending_rfh);
2927 EXPECT_TRUE(contents()->IsLoading());
2928
2929 // Commit the navigation, the formerly pending RenderFrameHost should now be
2930 // the current RenderFrameHost and the frame should still be loading.
2931 contents()->TestDidNavigate(pending_rfh, 1, kUrl2,
2932 ui::PAGE_TRANSITION_TYPED);
2933 EXPECT_EQ(contents()->GetPendingMainFrame(), nullptr);
2934 TestRenderFrameHost* new_current_rfh = contents()->GetMainFrame();
2935 ASSERT_EQ(new_current_rfh, pending_rfh);
2936 EXPECT_TRUE(contents()->IsLoading());
2937
2938 // Simulate the new current RenderFrameHost DidStopLoading. The frame should
2939 // now have stopped loading.
2940 new_current_rfh->OnMessageReceived(
2941 FrameHostMsg_DidStopLoading(new_current_rfh->GetRoutingID()));
2942 EXPECT_EQ(contents()->GetMainFrame(), new_current_rfh);
2943 EXPECT_FALSE(contents()->IsLoading());
2944 }
2945
2882 TEST_F(WebContentsImplTest, MediaPowerSaveBlocking) { 2946 TEST_F(WebContentsImplTest, MediaPowerSaveBlocking) {
2883 // PlayerIDs are actually pointers cast to int64, so verify that both negative 2947 // PlayerIDs are actually pointers cast to int64, so verify that both negative
2884 // and positive player ids don't blow up. 2948 // and positive player ids don't blow up.
2885 const int kPlayerAudioVideoId = 15; 2949 const int kPlayerAudioVideoId = 15;
2886 const int kPlayerAudioOnlyId = -15; 2950 const int kPlayerAudioOnlyId = -15;
2887 const int kPlayerVideoOnlyId = 30; 2951 const int kPlayerVideoOnlyId = 30;
2888 const int kPlayerRemoteId = -30; 2952 const int kPlayerRemoteId = -30;
2889 2953
2890 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing()); 2954 EXPECT_FALSE(contents()->has_audio_power_save_blocker_for_testing());
2891 EXPECT_FALSE(contents()->has_video_power_save_blocker_for_testing()); 2955 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); 3100 frame->SendBeforeUnloadHandlersPresent(false);
3037 EXPECT_FALSE(frame->SuddenTerminationAllowed()); 3101 EXPECT_FALSE(frame->SuddenTerminationAllowed());
3038 frame->SendBeforeUnloadHandlersPresent(true); 3102 frame->SendBeforeUnloadHandlersPresent(true);
3039 frame->SendUnloadHandlersPresent(false); 3103 frame->SendUnloadHandlersPresent(false);
3040 EXPECT_FALSE(frame->SuddenTerminationAllowed()); 3104 EXPECT_FALSE(frame->SuddenTerminationAllowed());
3041 frame->SendBeforeUnloadHandlersPresent(false); 3105 frame->SendBeforeUnloadHandlersPresent(false);
3042 EXPECT_TRUE(frame->SuddenTerminationAllowed()); 3106 EXPECT_TRUE(frame->SuddenTerminationAllowed());
3043 } 3107 }
3044 3108
3045 } // namespace content 3109 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698