| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/web_contents/aura/overscroll_navigation_overlay.h" | 5 #include "content/browser/web_contents/aura/overscroll_navigation_overlay.h" |
| 6 | 6 |
| 7 #include "content/browser/frame_host/navigation_entry_impl.h" | 7 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 8 #include "content/browser/web_contents/aura/image_window_delegate.h" | 8 #include "content/browser/web_contents/aura/image_window_delegate.h" |
| 9 #include "content/browser/web_contents/web_contents_view.h" | 9 #include "content/browser/web_contents/web_contents_view.h" |
| 10 #include "content/common/view_messages.h" | 10 #include "content/common/view_messages.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 aura::test::CreateTestWindowWithDelegate( | 96 aura::test::CreateTestWindowWithDelegate( |
| 97 image_delegate, | 97 image_delegate, |
| 98 0, | 98 0, |
| 99 gfx::Rect(root_window()->bounds().size()), | 99 gfx::Rect(root_window()->bounds().size()), |
| 100 root_window())); | 100 root_window())); |
| 101 | 101 |
| 102 overlay_->SetOverlayWindow(overlay_window.Pass(), image_delegate); | 102 overlay_->SetOverlayWindow(overlay_window.Pass(), image_delegate); |
| 103 overlay_->StartObserving(); | 103 overlay_->StartObserving(); |
| 104 | 104 |
| 105 EXPECT_TRUE(overlay_->web_contents()); | 105 EXPECT_TRUE(overlay_->web_contents()); |
| 106 EXPECT_FALSE(overlay_->loading_complete_); | |
| 107 EXPECT_FALSE(overlay_->received_paint_update_); | 106 EXPECT_FALSE(overlay_->received_paint_update_); |
| 108 } | 107 } |
| 109 | 108 |
| 110 virtual void TearDown() OVERRIDE { | 109 virtual void TearDown() OVERRIDE { |
| 111 overlay_.reset(); | 110 overlay_.reset(); |
| 112 RenderViewHostImplTestHarness::TearDown(); | 111 RenderViewHostImplTestHarness::TearDown(); |
| 113 } | 112 } |
| 114 | 113 |
| 115 OverscrollNavigationOverlay* GetOverlay() { | 114 OverscrollNavigationOverlay* GetOverlay() { |
| 116 return overlay_.get(); | 115 return overlay_.get(); |
| 117 } | 116 } |
| 118 | 117 |
| 119 private: | 118 private: |
| 120 scoped_ptr<OverscrollNavigationOverlay> overlay_; | 119 scoped_ptr<OverscrollNavigationOverlay> overlay_; |
| 121 | 120 |
| 122 DISALLOW_COPY_AND_ASSIGN(OverscrollNavigationOverlayTest); | 121 DISALLOW_COPY_AND_ASSIGN(OverscrollNavigationOverlayTest); |
| 123 }; | 122 }; |
| 124 | 123 |
| 125 TEST_F(OverscrollNavigationOverlayTest, FirstVisuallyNonEmptyPaint_NoImage) { | 124 TEST_F(OverscrollNavigationOverlayTest, FirstVisuallyNonEmptyPaint_NoImage) { |
| 126 ReceivePaintUpdate(); | 125 ReceivePaintUpdate(); |
| 127 EXPECT_TRUE(GetOverlay()->received_paint_update_); | 126 EXPECT_TRUE(GetOverlay()->received_paint_update_); |
| 128 EXPECT_FALSE(GetOverlay()->loading_complete_); | |
| 129 | |
| 130 EXPECT_TRUE(GetOverlay()->received_paint_update_); | |
| 131 EXPECT_FALSE(GetOverlay()->loading_complete_); | |
| 132 // The paint update will hide the overlay. | 127 // The paint update will hide the overlay. |
| 133 EXPECT_FALSE(GetOverlay()->web_contents()); | 128 EXPECT_FALSE(GetOverlay()->web_contents()); |
| 134 } | 129 } |
| 135 | 130 |
| 136 TEST_F(OverscrollNavigationOverlayTest, FirstVisuallyNonEmptyPaint_WithImage) { | 131 TEST_F(OverscrollNavigationOverlayTest, FirstVisuallyNonEmptyPaint_WithImage) { |
| 137 GetOverlay()->image_delegate_->SetImage(CreateDummyScreenshot()); | 132 GetOverlay()->image_delegate_->SetImage(CreateDummyScreenshot()); |
| 138 | 133 |
| 139 ReceivePaintUpdate(); | 134 ReceivePaintUpdate(); |
| 140 EXPECT_TRUE(GetOverlay()->received_paint_update_); | 135 EXPECT_TRUE(GetOverlay()->received_paint_update_); |
| 141 EXPECT_FALSE(GetOverlay()->loading_complete_); | |
| 142 // The paint update will hide the overlay. | 136 // The paint update will hide the overlay. |
| 143 EXPECT_FALSE(GetOverlay()->web_contents()); | 137 EXPECT_FALSE(GetOverlay()->web_contents()); |
| 144 } | 138 } |
| 145 | 139 |
| 146 TEST_F(OverscrollNavigationOverlayTest, PaintUpdateWithoutNonEmptyPaint) { | 140 TEST_F(OverscrollNavigationOverlayTest, PaintUpdateWithoutNonEmptyPaint) { |
| 147 GetOverlay()->image_delegate_->SetImage(CreateDummyScreenshot()); | 141 GetOverlay()->image_delegate_->SetImage(CreateDummyScreenshot()); |
| 148 process()->sink().ClearMessages(); | 142 process()->sink().ClearMessages(); |
| 149 | 143 |
| 150 // The page load is complete, but the overlay should still be visible, because | 144 // The page load is complete, but the overlay should still be visible, because |
| 151 // there hasn't been any paint update. | 145 // there hasn't been any paint update. |
| 152 // This should also send a repaint request to the renderer, so that the | |
| 153 // renderer repaints the contents. | |
| 154 contents()->TestSetIsLoading(false); | 146 contents()->TestSetIsLoading(false); |
| 155 EXPECT_FALSE(GetOverlay()->received_paint_update_); | 147 EXPECT_FALSE(GetOverlay()->received_paint_update_); |
| 156 EXPECT_TRUE(GetOverlay()->loading_complete_); | |
| 157 EXPECT_TRUE(GetOverlay()->web_contents()); | 148 EXPECT_TRUE(GetOverlay()->web_contents()); |
| 158 EXPECT_TRUE(process()->sink().GetFirstMessageMatching(ViewMsg_Repaint::ID)); | |
| 159 | 149 |
| 160 // Receive a repaint ack update. This should hide the overlay. | 150 // Receive the paint update. This should hide the overlay. |
| 161 ViewHostMsg_UpdateRect_Params params; | 151 ReceivePaintUpdate(); |
| 162 memset(¶ms, 0, sizeof(params)); | |
| 163 params.view_size = gfx::Size(10, 10); | |
| 164 params.flags = ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK; | |
| 165 ViewHostMsg_UpdateRect rect(test_rvh()->GetRoutingID(), params); | |
| 166 RenderViewHostTester::TestOnMessageReceived(test_rvh(), rect); | |
| 167 EXPECT_TRUE(GetOverlay()->received_paint_update_); | 152 EXPECT_TRUE(GetOverlay()->received_paint_update_); |
| 168 EXPECT_FALSE(GetOverlay()->web_contents()); | 153 EXPECT_FALSE(GetOverlay()->web_contents()); |
| 169 } | 154 } |
| 170 | 155 |
| 171 TEST_F(OverscrollNavigationOverlayTest, MultiNavigation_PaintUpdate) { | 156 TEST_F(OverscrollNavigationOverlayTest, MultiNavigation_PaintUpdate) { |
| 172 GetOverlay()->image_delegate_->SetImage(CreateDummyScreenshot()); | 157 GetOverlay()->image_delegate_->SetImage(CreateDummyScreenshot()); |
| 173 SetDummyScreenshotOnNavEntry(controller().GetEntryAtOffset(-1)); | 158 SetDummyScreenshotOnNavEntry(controller().GetEntryAtOffset(-1)); |
| 174 | 159 |
| 175 PerformBackNavigationViaSliderCallbacks(); | 160 PerformBackNavigationViaSliderCallbacks(); |
| 176 // Screenshot was set on NavEntry at offset -1. | 161 // Screenshot was set on NavEntry at offset -1. |
| 177 EXPECT_TRUE(GetOverlay()->image_delegate_->has_image()); | 162 EXPECT_TRUE(GetOverlay()->image_delegate_->has_image()); |
| 178 EXPECT_FALSE(GetOverlay()->received_paint_update_); | 163 EXPECT_FALSE(GetOverlay()->received_paint_update_); |
| 179 | 164 |
| 180 ReceivePaintUpdate(); | 165 ReceivePaintUpdate(); |
| 181 // Paint updates until the navigation is committed represent updates | 166 // Paint updates until the navigation is committed represent updates |
| 182 // for the previous page, so they shouldn't affect the flag. | 167 // for the previous page, so they shouldn't affect the flag. |
| 183 EXPECT_FALSE(GetOverlay()->received_paint_update_); | 168 EXPECT_FALSE(GetOverlay()->received_paint_update_); |
| 184 | 169 |
| 185 contents()->CommitPendingNavigation(); | 170 contents()->CommitPendingNavigation(); |
| 186 ReceivePaintUpdate(); | 171 ReceivePaintUpdate(); |
| 187 // Navigation was committed and the paint update was received - the flag | 172 // Navigation was committed and the paint update was received - the flag |
| 188 // should now be updated. | 173 // should now be updated. |
| 189 EXPECT_TRUE(GetOverlay()->received_paint_update_); | 174 EXPECT_TRUE(GetOverlay()->received_paint_update_); |
| 190 | 175 |
| 191 EXPECT_FALSE(GetOverlay()->web_contents()); | 176 EXPECT_FALSE(GetOverlay()->web_contents()); |
| 192 } | 177 } |
| 193 | 178 |
| 194 TEST_F(OverscrollNavigationOverlayTest, MultiNavigation_LoadingUpdate) { | |
| 195 GetOverlay()->image_delegate_->SetImage(CreateDummyScreenshot()); | |
| 196 | |
| 197 contents()->TestSetIsLoading(false); | |
| 198 EXPECT_TRUE(GetOverlay()->loading_complete_); | |
| 199 | |
| 200 PerformBackNavigationViaSliderCallbacks(); | |
| 201 // No screenshot was set on NavEntry at offset -1. | |
| 202 EXPECT_FALSE(GetOverlay()->image_delegate_->has_image()); | |
| 203 // Navigation was started, so the loading status flag should be reset. | |
| 204 EXPECT_FALSE(GetOverlay()->loading_complete_); | |
| 205 | |
| 206 // Load updates until the navigation is committed represent updates for the | |
| 207 // previous page, so they shouldn't affect the flag. | |
| 208 contents()->TestSetIsLoading(true); | |
| 209 contents()->TestSetIsLoading(false); | |
| 210 EXPECT_FALSE(GetOverlay()->loading_complete_); | |
| 211 | |
| 212 contents()->CommitPendingNavigation(); | |
| 213 contents()->TestSetIsLoading(true); | |
| 214 contents()->TestSetIsLoading(false); | |
| 215 // Navigation was committed and the load update was received - the flag | |
| 216 // should now be updated. | |
| 217 EXPECT_TRUE(GetOverlay()->loading_complete_); | |
| 218 | |
| 219 EXPECT_TRUE(GetOverlay()->web_contents()); | |
| 220 ReceivePaintUpdate(); | |
| 221 EXPECT_FALSE(GetOverlay()->web_contents()); | |
| 222 } | |
| 223 | |
| 224 } // namespace content | 179 } // namespace content |
| OLD | NEW |