| 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/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(GetMainRenderFrame()->is_main_frame_); |
| 41 ->is_main_frame_); | |
| 42 | 44 |
| 43 FrameMsg_NewFrame_WidgetParams widget_params; | 45 FrameMsg_NewFrame_WidgetParams widget_params; |
| 44 widget_params.routing_id = kSubframeWidgetRouteId; | 46 widget_params.routing_id = kSubframeWidgetRouteId; |
| 45 widget_params.hidden = false; | 47 widget_params.hidden = false; |
| 46 | 48 |
| 47 IsolateAllSitesForTesting(base::CommandLine::ForCurrentProcess()); | 49 IsolateAllSitesForTesting(base::CommandLine::ForCurrentProcess()); |
| 48 | 50 |
| 49 LoadHTML("Parent frame <iframe name='frame'></iframe>"); | 51 LoadHTML("Parent frame <iframe name='frame'></iframe>"); |
| 50 | 52 |
| 51 RenderFrameImpl::FromWebFrame( | 53 RenderFrameImpl::FromWebFrame( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 64 | 66 |
| 65 void TearDown() override { | 67 void TearDown() override { |
| 66 #if defined(LEAK_SANITIZER) | 68 #if defined(LEAK_SANITIZER) |
| 67 // Do this before shutting down V8 in RenderViewTest::TearDown(). | 69 // Do this before shutting down V8 in RenderViewTest::TearDown(). |
| 68 // http://crbug.com/328552 | 70 // http://crbug.com/328552 |
| 69 __lsan_do_leak_check(); | 71 __lsan_do_leak_check(); |
| 70 #endif | 72 #endif |
| 71 RenderViewTest::TearDown(); | 73 RenderViewTest::TearDown(); |
| 72 } | 74 } |
| 73 | 75 |
| 76 void SetIsUsingLoFi(RenderFrameImpl* frame, bool is_using_lofi) { |
| 77 frame->is_using_lofi_ = is_using_lofi; |
| 78 } |
| 79 |
| 80 RenderFrameImpl* GetMainRenderFrame() { |
| 81 return static_cast<RenderFrameImpl*>(view_->GetMainRenderFrame()); |
| 82 } |
| 83 |
| 74 RenderFrameImpl* frame() { return frame_; } | 84 RenderFrameImpl* frame() { return frame_; } |
| 75 | 85 |
| 76 content::RenderWidget* frame_widget() const { | 86 content::RenderWidget* frame_widget() const { |
| 77 return frame_->render_widget_.get(); | 87 return frame_->render_widget_.get(); |
| 78 } | 88 } |
| 79 | 89 |
| 80 private: | 90 private: |
| 81 RenderFrameImpl* frame_; | 91 RenderFrameImpl* frame_; |
| 82 FakeCompositorDependencies compositor_deps_; | 92 FakeCompositorDependencies compositor_deps_; |
| 83 }; | 93 }; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 frame_widget()->OnMessageReceived(close_message); | 180 frame_widget()->OnMessageReceived(close_message); |
| 171 | 181 |
| 172 ViewMsg_WasShown was_shown_message(0, true, ui::LatencyInfo()); | 182 ViewMsg_WasShown was_shown_message(0, true, ui::LatencyInfo()); |
| 173 static_cast<RenderViewImpl*>(view_)->OnMessageReceived(was_shown_message); | 183 static_cast<RenderViewImpl*>(view_)->OnMessageReceived(was_shown_message); |
| 174 | 184 |
| 175 // This test is primarily checking that this case does not crash, but | 185 // This test is primarily checking that this case does not crash, but |
| 176 // observers should still be notified. | 186 // observers should still be notified. |
| 177 EXPECT_TRUE(observer.visible()); | 187 EXPECT_TRUE(observer.visible()); |
| 178 } | 188 } |
| 179 | 189 |
| 190 // Test that LoFi state only updates for new main frame documents. Subframes |
| 191 // inherit from the main frame and should not change at commit time. |
| 192 TEST_F(RenderFrameImplTest, LoFiNotUpdatedOnSubframeCommits) { |
| 193 SetIsUsingLoFi(GetMainRenderFrame(), true); |
| 194 SetIsUsingLoFi(frame(), true); |
| 195 EXPECT_TRUE(GetMainRenderFrame()->IsUsingLoFi()); |
| 196 EXPECT_TRUE(frame()->IsUsingLoFi()); |
| 197 |
| 198 blink::WebHistoryItem item; |
| 199 item.initialize(); |
| 200 |
| 201 // The main frame's and subframe's LoFi states should stay the same on |
| 202 // navigations within the page. |
| 203 frame()->didNavigateWithinPage(frame()->GetWebFrame(), item, |
| 204 blink::WebStandardCommit); |
| 205 EXPECT_TRUE(frame()->IsUsingLoFi()); |
| 206 GetMainRenderFrame()->didNavigateWithinPage( |
| 207 GetMainRenderFrame()->GetWebFrame(), item, blink::WebStandardCommit); |
| 208 EXPECT_TRUE(GetMainRenderFrame()->IsUsingLoFi()); |
| 209 |
| 210 // The subframe's LoFi state should not be reset on commit. |
| 211 DocumentState* document_state = |
| 212 DocumentState::FromDataSource(frame()->GetWebFrame()->dataSource()); |
| 213 static_cast<NavigationStateImpl*>(document_state->navigation_state()) |
| 214 ->set_was_within_same_page(false); |
| 215 |
| 216 frame()->didCommitProvisionalLoad(frame()->GetWebFrame(), item, |
| 217 blink::WebStandardCommit); |
| 218 EXPECT_TRUE(frame()->IsUsingLoFi()); |
| 219 |
| 220 // The main frame's LoFi state should be reset to off on commit. |
| 221 document_state = DocumentState::FromDataSource( |
| 222 GetMainRenderFrame()->GetWebFrame()->dataSource()); |
| 223 static_cast<NavigationStateImpl*>(document_state->navigation_state()) |
| 224 ->set_was_within_same_page(false); |
| 225 |
| 226 // Calling didCommitProvisionalLoad is not representative of a full navigation |
| 227 // but serves the purpose of testing the LoFi state logic. |
| 228 GetMainRenderFrame()->didCommitProvisionalLoad( |
| 229 GetMainRenderFrame()->GetWebFrame(), item, blink::WebStandardCommit); |
| 230 EXPECT_FALSE(GetMainRenderFrame()->IsUsingLoFi()); |
| 231 // The subframe would be deleted here after a cross-document navigation. It |
| 232 // happens to be left around in this test because this does not simulate the |
| 233 // frame detach. |
| 234 } |
| 235 |
| 180 } // namespace | 236 } // namespace |
| OLD | NEW |