OLD | NEW |
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/child/web_url_loader_impl.h" | 10 #include "content/child/web_url_loader_impl.h" |
11 #include "content/common/frame_messages.h" | 11 #include "content/common/frame_messages.h" |
12 #include "content/common/frame_owner_properties.h" | 12 #include "content/common/frame_owner_properties.h" |
13 #include "content/common/renderer.mojom.h" | 13 #include "content/common/renderer.mojom.h" |
14 #include "content/common/view_messages.h" | 14 #include "content/common/view_messages.h" |
| 15 #include "content/public/common/previews_state.h" |
15 #include "content/public/renderer/document_state.h" | 16 #include "content/public/renderer/document_state.h" |
16 #include "content/public/test/frame_load_waiter.h" | 17 #include "content/public/test/frame_load_waiter.h" |
17 #include "content/public/test/render_view_test.h" | 18 #include "content/public/test/render_view_test.h" |
18 #include "content/public/test/test_utils.h" | 19 #include "content/public/test/test_utils.h" |
19 #include "content/renderer/navigation_state_impl.h" | 20 #include "content/renderer/navigation_state_impl.h" |
20 #include "content/renderer/render_frame_impl.h" | 21 #include "content/renderer/render_frame_impl.h" |
21 #include "content/renderer/render_view_impl.h" | 22 #include "content/renderer/render_view_impl.h" |
22 #include "content/test/fake_compositor_dependencies.h" | 23 #include "content/test/fake_compositor_dependencies.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
24 #include "third_party/WebKit/public/platform/WebEffectiveConnectionType.h" | 25 #include "third_party/WebKit/public/platform/WebEffectiveConnectionType.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 | 77 |
77 void TearDown() override { | 78 void TearDown() override { |
78 #if defined(LEAK_SANITIZER) | 79 #if defined(LEAK_SANITIZER) |
79 // Do this before shutting down V8 in RenderViewTest::TearDown(). | 80 // Do this before shutting down V8 in RenderViewTest::TearDown(). |
80 // http://crbug.com/328552 | 81 // http://crbug.com/328552 |
81 __lsan_do_leak_check(); | 82 __lsan_do_leak_check(); |
82 #endif | 83 #endif |
83 RenderViewTest::TearDown(); | 84 RenderViewTest::TearDown(); |
84 } | 85 } |
85 | 86 |
86 void SetIsUsingLoFi(RenderFrameImpl* frame, bool is_using_lofi) { | 87 void SetPreviewsState(RenderFrameImpl* frame, PreviewsState previews_state) { |
87 frame->is_using_lofi_ = is_using_lofi; | 88 frame->previews_state_ = previews_state; |
88 } | 89 } |
89 | 90 |
90 void SetEffectionConnectionType(RenderFrameImpl* frame, | 91 void SetEffectionConnectionType(RenderFrameImpl* frame, |
91 blink::WebEffectiveConnectionType type) { | 92 blink::WebEffectiveConnectionType type) { |
92 frame->effective_connection_type_ = type; | 93 frame->effective_connection_type_ = type; |
93 } | 94 } |
94 | 95 |
95 RenderFrameImpl* GetMainRenderFrame() { | 96 RenderFrameImpl* GetMainRenderFrame() { |
96 return static_cast<RenderFrameImpl*>(view_->GetMainRenderFrame()); | 97 return static_cast<RenderFrameImpl*>(view_->GetMainRenderFrame()); |
97 } | 98 } |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 static_cast<RenderViewImpl*>(view_)->OnMessageReceived(was_shown_message); | 174 static_cast<RenderViewImpl*>(view_)->OnMessageReceived(was_shown_message); |
174 | 175 |
175 // This test is primarily checking that this case does not crash, but | 176 // This test is primarily checking that this case does not crash, but |
176 // observers should still be notified. | 177 // observers should still be notified. |
177 EXPECT_TRUE(observer.visible()); | 178 EXPECT_TRUE(observer.visible()); |
178 } | 179 } |
179 | 180 |
180 // Test that LoFi state only updates for new main frame documents. Subframes | 181 // Test that LoFi state only updates for new main frame documents. Subframes |
181 // inherit from the main frame and should not change at commit time. | 182 // inherit from the main frame and should not change at commit time. |
182 TEST_F(RenderFrameImplTest, LoFiNotUpdatedOnSubframeCommits) { | 183 TEST_F(RenderFrameImplTest, LoFiNotUpdatedOnSubframeCommits) { |
183 SetIsUsingLoFi(GetMainRenderFrame(), true); | 184 SetPreviewsState(GetMainRenderFrame(), SERVER_LOFI_ON); |
184 SetIsUsingLoFi(frame(), true); | 185 SetPreviewsState(frame(), SERVER_LOFI_ON); |
185 EXPECT_TRUE(GetMainRenderFrame()->IsUsingLoFi()); | 186 EXPECT_EQ(SERVER_LOFI_ON, GetMainRenderFrame()->GetPreviewsState()); |
186 EXPECT_TRUE(frame()->IsUsingLoFi()); | 187 EXPECT_EQ(SERVER_LOFI_ON, frame()->GetPreviewsState()); |
187 | 188 |
188 blink::WebHistoryItem item; | 189 blink::WebHistoryItem item; |
189 item.initialize(); | 190 item.initialize(); |
190 | 191 |
191 // The main frame's and subframe's LoFi states should stay the same on | 192 // The main frame's and subframe's LoFi states should stay the same on |
192 // navigations within the page. | 193 // navigations within the page. |
193 frame()->didNavigateWithinPage(frame()->GetWebFrame(), item, | 194 frame()->didNavigateWithinPage(frame()->GetWebFrame(), item, |
194 blink::WebStandardCommit, true); | 195 blink::WebStandardCommit, true); |
195 EXPECT_TRUE(frame()->IsUsingLoFi()); | 196 EXPECT_EQ(SERVER_LOFI_ON, frame()->GetPreviewsState()); |
196 GetMainRenderFrame()->didNavigateWithinPage( | 197 GetMainRenderFrame()->didNavigateWithinPage( |
197 GetMainRenderFrame()->GetWebFrame(), item, blink::WebStandardCommit, | 198 GetMainRenderFrame()->GetWebFrame(), item, blink::WebStandardCommit, |
198 true); | 199 true); |
199 EXPECT_TRUE(GetMainRenderFrame()->IsUsingLoFi()); | 200 EXPECT_EQ(SERVER_LOFI_ON, GetMainRenderFrame()->GetPreviewsState()); |
200 | 201 |
201 // The subframe's LoFi state should not be reset on commit. | 202 // The subframe's LoFi state should not be reset on commit. |
202 DocumentState* document_state = | 203 DocumentState* document_state = |
203 DocumentState::FromDataSource(frame()->GetWebFrame()->dataSource()); | 204 DocumentState::FromDataSource(frame()->GetWebFrame()->dataSource()); |
204 static_cast<NavigationStateImpl*>(document_state->navigation_state()) | 205 static_cast<NavigationStateImpl*>(document_state->navigation_state()) |
205 ->set_was_within_same_page(false); | 206 ->set_was_within_same_page(false); |
206 | 207 |
207 frame()->didCommitProvisionalLoad(frame()->GetWebFrame(), item, | 208 frame()->didCommitProvisionalLoad(frame()->GetWebFrame(), item, |
208 blink::WebStandardCommit); | 209 blink::WebStandardCommit); |
209 EXPECT_TRUE(frame()->IsUsingLoFi()); | 210 EXPECT_EQ(SERVER_LOFI_ON, frame()->GetPreviewsState()); |
210 | 211 |
211 // The main frame's LoFi state should be reset to off on commit. | 212 // The main frame's LoFi state should be reset to off on commit. |
212 document_state = DocumentState::FromDataSource( | 213 document_state = DocumentState::FromDataSource( |
213 GetMainRenderFrame()->GetWebFrame()->dataSource()); | 214 GetMainRenderFrame()->GetWebFrame()->dataSource()); |
214 static_cast<NavigationStateImpl*>(document_state->navigation_state()) | 215 static_cast<NavigationStateImpl*>(document_state->navigation_state()) |
215 ->set_was_within_same_page(false); | 216 ->set_was_within_same_page(false); |
216 | 217 |
217 // Calling didCommitProvisionalLoad is not representative of a full navigation | 218 // Calling didCommitProvisionalLoad is not representative of a full navigation |
218 // but serves the purpose of testing the LoFi state logic. | 219 // but serves the purpose of testing the LoFi state logic. |
219 GetMainRenderFrame()->didCommitProvisionalLoad( | 220 GetMainRenderFrame()->didCommitProvisionalLoad( |
220 GetMainRenderFrame()->GetWebFrame(), item, blink::WebStandardCommit); | 221 GetMainRenderFrame()->GetWebFrame(), item, blink::WebStandardCommit); |
221 EXPECT_FALSE(GetMainRenderFrame()->IsUsingLoFi()); | 222 EXPECT_EQ(PREVIEWS_OFF, GetMainRenderFrame()->GetPreviewsState()); |
222 // The subframe would be deleted here after a cross-document navigation. It | 223 // The subframe would be deleted here after a cross-document navigation. It |
223 // happens to be left around in this test because this does not simulate the | 224 // happens to be left around in this test because this does not simulate the |
224 // frame detach. | 225 // frame detach. |
225 } | 226 } |
226 | 227 |
227 // Test that effective connection type only updates for new main frame | 228 // Test that effective connection type only updates for new main frame |
228 // documents. | 229 // documents. |
229 TEST_F(RenderFrameImplTest, EffectiveConnectionType) { | 230 TEST_F(RenderFrameImplTest, EffectiveConnectionType) { |
230 EXPECT_EQ(blink::WebEffectiveConnectionType::TypeUnknown, | 231 EXPECT_EQ(blink::WebEffectiveConnectionType::TypeUnknown, |
231 frame()->getEffectiveConnectionType()); | 232 frame()->getEffectiveConnectionType()); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 common_params.url = GURL("data:text/html,max_zoomlimit_test"); | 355 common_params.url = GURL("data:text/html,max_zoomlimit_test"); |
355 GetMainRenderFrame()->SetHostZoomLevel(common_params.url, kMaxZoomLevel); | 356 GetMainRenderFrame()->SetHostZoomLevel(common_params.url, kMaxZoomLevel); |
356 GetMainRenderFrame()->NavigateInternal( | 357 GetMainRenderFrame()->NavigateInternal( |
357 common_params, StartNavigationParams(), RequestNavigationParams(), | 358 common_params, StartNavigationParams(), RequestNavigationParams(), |
358 std::unique_ptr<StreamOverrideParameters>()); | 359 std::unique_ptr<StreamOverrideParameters>()); |
359 ProcessPendingMessages(); | 360 ProcessPendingMessages(); |
360 EXPECT_DOUBLE_EQ(kMaxZoomLevel, view_->GetWebView()->zoomLevel()); | 361 EXPECT_DOUBLE_EQ(kMaxZoomLevel, view_->GetWebView()->zoomLevel()); |
361 } | 362 } |
362 | 363 |
363 } // namespace | 364 } // namespace |
OLD | NEW |