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

Side by Side Diff: content/renderer/render_frame_impl_browsertest.cc

Issue 1624583003: Reload Lo-Fi images inline instead of reloading the whole page (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added comment and test Created 4 years, 10 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/debug/leak_annotations.h" 8 #include "base/debug/leak_annotations.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "content/common/frame_messages.h" 10 #include "content/common/frame_messages.h"
11 #include "content/common/view_messages.h" 11 #include "content/common/view_messages.h"
12 #include "content/public/renderer/document_state.h"
12 #include "content/public/test/frame_load_waiter.h" 13 #include "content/public/test/frame_load_waiter.h"
13 #include "content/public/test/render_view_test.h" 14 #include "content/public/test/render_view_test.h"
14 #include "content/public/test/test_utils.h" 15 #include "content/public/test/test_utils.h"
16 #include "content/renderer/navigation_state_impl.h"
15 #include "content/renderer/render_frame_impl.h" 17 #include "content/renderer/render_frame_impl.h"
16 #include "content/renderer/render_view_impl.h" 18 #include "content/renderer/render_view_impl.h"
17 #include "content/test/fake_compositor_dependencies.h" 19 #include "content/test/fake_compositor_dependencies.h"
18 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
19 #include "third_party/WebKit/public/platform/WebURLRequest.h" 21 #include "third_party/WebKit/public/platform/WebURLRequest.h"
20 #include "third_party/WebKit/public/web/WebFrameOwnerProperties.h" 22 #include "third_party/WebKit/public/web/WebFrameOwnerProperties.h"
23 #include "third_party/WebKit/public/web/WebHistoryItem.h"
21 #include "third_party/WebKit/public/web/WebLocalFrame.h" 24 #include "third_party/WebKit/public/web/WebLocalFrame.h"
22 25
23 namespace { 26 namespace {
24 const int32_t kSubframeRouteId = 20; 27 const int32_t kSubframeRouteId = 20;
25 const int32_t kSubframeWidgetRouteId = 21; 28 const int32_t kSubframeWidgetRouteId = 21;
26 const int32_t kFrameProxyRouteId = 22; 29 const int32_t kFrameProxyRouteId = 22;
27 } // namespace 30 } // namespace
28 31
29 namespace content { 32 namespace content {
30 33
31 // RenderFrameImplTest creates a RenderFrameImpl that is a child of the 34 // RenderFrameImplTest creates a RenderFrameImpl that is a child of the
32 // main frame, and has its own RenderWidget. This behaves like an out 35 // main frame, and has its own RenderWidget. This behaves like an out
33 // of process frame even though it is in the same process as its parent. 36 // of process frame even though it is in the same process as its parent.
34 class RenderFrameImplTest : public RenderViewTest { 37 class RenderFrameImplTest : public RenderViewTest {
35 public: 38 public:
36 ~RenderFrameImplTest() override {} 39 ~RenderFrameImplTest() override {}
37 40
38 void SetUp() override { 41 void SetUp() override {
39 RenderViewTest::SetUp(); 42 RenderViewTest::SetUp();
40 EXPECT_TRUE(static_cast<RenderFrameImpl*>(view_->GetMainRenderFrame()) 43 EXPECT_TRUE(static_cast<RenderFrameImpl*>(view_->GetMainRenderFrame())
Charlie Reis 2016/02/04 19:30:30 nit: Let's use the new helper here.
megjablon 2016/02/04 20:02:31 Done.
41 ->is_main_frame_); 44 ->is_main_frame_);
42 45
43 FrameMsg_NewFrame_WidgetParams widget_params; 46 FrameMsg_NewFrame_WidgetParams widget_params;
44 widget_params.routing_id = kSubframeWidgetRouteId; 47 widget_params.routing_id = kSubframeWidgetRouteId;
45 widget_params.hidden = false; 48 widget_params.hidden = false;
46 49
47 IsolateAllSitesForTesting(base::CommandLine::ForCurrentProcess()); 50 IsolateAllSitesForTesting(base::CommandLine::ForCurrentProcess());
48 51
49 LoadHTML("Parent frame <iframe name='frame'></iframe>"); 52 LoadHTML("Parent frame <iframe name='frame'></iframe>");
50 53
(...skipping 13 matching lines...) Expand all
64 67
65 void TearDown() override { 68 void TearDown() override {
66 #if defined(LEAK_SANITIZER) 69 #if defined(LEAK_SANITIZER)
67 // Do this before shutting down V8 in RenderViewTest::TearDown(). 70 // Do this before shutting down V8 in RenderViewTest::TearDown().
68 // http://crbug.com/328552 71 // http://crbug.com/328552
69 __lsan_do_leak_check(); 72 __lsan_do_leak_check();
70 #endif 73 #endif
71 RenderViewTest::TearDown(); 74 RenderViewTest::TearDown();
72 } 75 }
73 76
77 void SetIsUsingLoFi(RenderFrameImpl* frame, bool is_using_lofi) {
78 frame->is_using_lofi_ = is_using_lofi;
79 }
80
81 RenderFrameImpl* main_frame() {
Charlie Reis 2016/02/04 19:30:30 Style nit: GetMainRenderFrame() (hacker_case is f
megjablon 2016/02/04 20:02:31 Done.
82 return static_cast<RenderFrameImpl*>(view_->GetMainRenderFrame());
83 }
84
74 RenderFrameImpl* frame() { return frame_; } 85 RenderFrameImpl* frame() { return frame_; }
75 86
76 content::RenderWidget* frame_widget() const { 87 content::RenderWidget* frame_widget() const {
77 return frame_->render_widget_.get(); 88 return frame_->render_widget_.get();
78 } 89 }
79 90
80 private: 91 private:
81 RenderFrameImpl* frame_; 92 RenderFrameImpl* frame_;
82 FakeCompositorDependencies compositor_deps_; 93 FakeCompositorDependencies compositor_deps_;
83 }; 94 };
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 frame_widget()->OnMessageReceived(close_message); 181 frame_widget()->OnMessageReceived(close_message);
171 182
172 ViewMsg_WasShown was_shown_message(0, true, ui::LatencyInfo()); 183 ViewMsg_WasShown was_shown_message(0, true, ui::LatencyInfo());
173 static_cast<RenderViewImpl*>(view_)->OnMessageReceived(was_shown_message); 184 static_cast<RenderViewImpl*>(view_)->OnMessageReceived(was_shown_message);
174 185
175 // This test is primarily checking that this case does not crash, but 186 // This test is primarily checking that this case does not crash, but
176 // observers should still be notified. 187 // observers should still be notified.
177 EXPECT_TRUE(observer.visible()); 188 EXPECT_TRUE(observer.visible());
178 } 189 }
179 190
191 // Test that LoFi state only updates for new main frame documents. Subframes
192 // inherit from the main frame and should not change at commit time.
193 TEST_F(RenderFrameImplTest, LoFiNotUpdatedOnSubframeCommits) {
194 SetIsUsingLoFi(main_frame(), true);
195 SetIsUsingLoFi(frame(), true);
196 EXPECT_TRUE(main_frame()->IsUsingLoFi());
197 EXPECT_TRUE(frame()->IsUsingLoFi());
198
199 blink::WebHistoryItem item;
200 item.initialize();
201
202 // The main frame's and subframe's LoFi states should stay the same on
203 // navigations within the page.
204 frame()->didNavigateWithinPage(frame()->GetWebFrame(), item,
205 blink::WebStandardCommit);
206 EXPECT_TRUE(frame()->IsUsingLoFi());
207 main_frame()->didNavigateWithinPage(main_frame()->GetWebFrame(), item,
208 blink::WebStandardCommit);
209 EXPECT_TRUE(main_frame()->IsUsingLoFi());
Charlie Reis 2016/02/04 19:30:30 Can you add a test for the subframe doing a didCom
megjablon 2016/02/04 20:02:31 Done.
210
211 // The main frame's LoFi state should be reset to off on commit.
212 DocumentState* document_state =
213 DocumentState::FromDataSource(main_frame()->GetWebFrame()->dataSource());
214 static_cast<NavigationStateImpl*>(document_state->navigation_state())
215 ->set_was_within_same_page(false);
216
217 main_frame()->didCommitProvisionalLoad(main_frame()->GetWebFrame(), item,
Charlie Reis 2016/02/04 19:30:30 It's a little surprising to me that these work wit
megjablon 2016/02/04 20:02:31 Done. Comment added as discussed offline.
218 blink::WebStandardCommit);
219 EXPECT_FALSE(main_frame()->IsUsingLoFi());
220 }
221
180 } // namespace 222 } // namespace
OLDNEW
« no previous file with comments | « content/renderer/render_frame_impl.cc ('k') | third_party/WebKit/Source/core/fetch/ImageResource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698