| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 RenderViewHostTester::TestOnMessageReceived(test_rvh(), msg); | 49 RenderViewHostTester::TestOnMessageReceived(test_rvh(), msg); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void PerformBackNavigationViaSliderCallbacks() { | 52 void PerformBackNavigationViaSliderCallbacks() { |
| 53 // Sets slide direction to SLIDE_BACK, sets screenshot from NavEntry at | 53 // Sets slide direction to SLIDE_BACK, sets screenshot from NavEntry at |
| 54 // offset -1 on layer_delegate_. | 54 // offset -1 on layer_delegate_. |
| 55 delete GetOverlay()->CreateBackLayer(); | 55 delete GetOverlay()->CreateBackLayer(); |
| 56 // Performs BACK navigation, sets image from layer_delegate_ on | 56 // Performs BACK navigation, sets image from layer_delegate_ on |
| 57 // image_delegate_. | 57 // image_delegate_. |
| 58 GetOverlay()->OnWindowSlideCompleting(); | 58 GetOverlay()->OnWindowSlideCompleting(); |
| 59 GetOverlay()->OnWindowSlideCompleted(); | 59 GetOverlay()->OnWindowSlideCompleted(scoped_ptr<ui::Layer>()); |
| 60 } | 60 } |
| 61 | 61 |
| 62 protected: | 62 protected: |
| 63 // RenderViewHostImplTestHarness: | 63 // RenderViewHostImplTestHarness: |
| 64 virtual void SetUp() OVERRIDE { | 64 virtual void SetUp() OVERRIDE { |
| 65 RenderViewHostImplTestHarness::SetUp(); | 65 RenderViewHostImplTestHarness::SetUp(); |
| 66 | 66 |
| 67 const GURL first("https://www.google.com"); | 67 const GURL first("https://www.google.com"); |
| 68 contents()->NavigateAndCommit(first); | 68 contents()->NavigateAndCommit(first); |
| 69 EXPECT_TRUE(controller().GetVisibleEntry()); | 69 EXPECT_TRUE(controller().GetVisibleEntry()); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 private: | 114 private: |
| 115 scoped_ptr<OverscrollNavigationOverlay> overlay_; | 115 scoped_ptr<OverscrollNavigationOverlay> overlay_; |
| 116 | 116 |
| 117 DISALLOW_COPY_AND_ASSIGN(OverscrollNavigationOverlayTest); | 117 DISALLOW_COPY_AND_ASSIGN(OverscrollNavigationOverlayTest); |
| 118 }; | 118 }; |
| 119 | 119 |
| 120 TEST_F(OverscrollNavigationOverlayTest, FirstVisuallyNonEmptyPaint_NoImage) { | 120 TEST_F(OverscrollNavigationOverlayTest, FirstVisuallyNonEmptyPaint_NoImage) { |
| 121 ReceivePaintUpdate(); | 121 ReceivePaintUpdate(); |
| 122 EXPECT_TRUE(GetOverlay()->received_paint_update_); | 122 EXPECT_TRUE(GetOverlay()->received_paint_update_); |
| 123 EXPECT_FALSE(GetOverlay()->loading_complete_); | 123 EXPECT_FALSE(GetOverlay()->loading_complete_); |
| 124 | |
| 125 EXPECT_TRUE(GetOverlay()->received_paint_update_); | |
| 126 EXPECT_FALSE(GetOverlay()->loading_complete_); | |
| 127 // The paint update will hide the overlay. | 124 // The paint update will hide the overlay. |
| 128 EXPECT_FALSE(GetOverlay()->web_contents()); | 125 EXPECT_FALSE(GetOverlay()->web_contents()); |
| 129 } | 126 } |
| 130 | 127 |
| 131 TEST_F(OverscrollNavigationOverlayTest, FirstVisuallyNonEmptyPaint_WithImage) { | 128 TEST_F(OverscrollNavigationOverlayTest, FirstVisuallyNonEmptyPaint_WithImage) { |
| 132 GetOverlay()->image_delegate_->SetImage(CreateDummyScreenshot()); | 129 GetOverlay()->image_delegate_->SetImage(CreateDummyScreenshot()); |
| 133 | 130 |
| 134 ReceivePaintUpdate(); | 131 ReceivePaintUpdate(); |
| 135 EXPECT_TRUE(GetOverlay()->received_paint_update_); | 132 EXPECT_TRUE(GetOverlay()->received_paint_update_); |
| 136 EXPECT_FALSE(GetOverlay()->loading_complete_); | 133 EXPECT_FALSE(GetOverlay()->loading_complete_); |
| 137 // The paint update will hide the overlay. | 134 // The paint update will hide the overlay. |
| 138 EXPECT_FALSE(GetOverlay()->web_contents()); | 135 EXPECT_FALSE(GetOverlay()->web_contents()); |
| 139 } | 136 } |
| 140 | 137 |
| 141 TEST_F(OverscrollNavigationOverlayTest, PaintUpdateWithoutNonEmptyPaint) { | 138 TEST_F(OverscrollNavigationOverlayTest, LoadUpdateWithoutNonEmptyPaint) { |
| 142 GetOverlay()->image_delegate_->SetImage(CreateDummyScreenshot()); | 139 GetOverlay()->image_delegate_->SetImage(CreateDummyScreenshot()); |
| 143 process()->sink().ClearMessages(); | 140 process()->sink().ClearMessages(); |
| 144 | 141 |
| 145 // The page load is complete, but the overlay should still be visible, because | |
| 146 // there hasn't been any paint update. | |
| 147 // This should also send a repaint request to the renderer, so that the | |
| 148 // renderer repaints the contents. | |
| 149 contents()->TestSetIsLoading(false); | 142 contents()->TestSetIsLoading(false); |
| 143 EXPECT_TRUE(GetOverlay()->loading_complete_); |
| 150 EXPECT_FALSE(GetOverlay()->received_paint_update_); | 144 EXPECT_FALSE(GetOverlay()->received_paint_update_); |
| 151 EXPECT_TRUE(GetOverlay()->loading_complete_); | 145 // The page load should hide the overlay. |
| 152 EXPECT_TRUE(GetOverlay()->web_contents()); | |
| 153 EXPECT_TRUE(process()->sink().GetFirstMessageMatching(ViewMsg_Repaint::ID)); | |
| 154 | |
| 155 // Receive a repaint ack update. This should hide the overlay. | |
| 156 ViewHostMsg_UpdateRect_Params params; | |
| 157 memset(¶ms, 0, sizeof(params)); | |
| 158 params.view_size = gfx::Size(10, 10); | |
| 159 params.flags = ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK; | |
| 160 ViewHostMsg_UpdateRect rect(test_rvh()->GetRoutingID(), params); | |
| 161 RenderViewHostTester::TestOnMessageReceived(test_rvh(), rect); | |
| 162 EXPECT_TRUE(GetOverlay()->received_paint_update_); | |
| 163 EXPECT_FALSE(GetOverlay()->web_contents()); | 146 EXPECT_FALSE(GetOverlay()->web_contents()); |
| 164 } | 147 } |
| 165 | 148 |
| 166 TEST_F(OverscrollNavigationOverlayTest, MultiNavigation_PaintUpdate) { | 149 TEST_F(OverscrollNavigationOverlayTest, MultiNavigation_PaintUpdate) { |
| 167 GetOverlay()->image_delegate_->SetImage(CreateDummyScreenshot()); | 150 GetOverlay()->image_delegate_->SetImage(CreateDummyScreenshot()); |
| 168 SetDummyScreenshotOnNavEntry(controller().GetEntryAtOffset(-1)); | 151 SetDummyScreenshotOnNavEntry(controller().GetEntryAtOffset(-1)); |
| 169 | 152 |
| 170 PerformBackNavigationViaSliderCallbacks(); | 153 PerformBackNavigationViaSliderCallbacks(); |
| 171 // Screenshot was set on NavEntry at offset -1. | 154 // Screenshot was set on NavEntry at offset -1. |
| 172 EXPECT_TRUE(GetOverlay()->image_delegate_->has_image()); | 155 EXPECT_TRUE(GetOverlay()->image_delegate_->has_image()); |
| 173 EXPECT_FALSE(GetOverlay()->received_paint_update_); | 156 EXPECT_FALSE(GetOverlay()->received_paint_update_); |
| 174 | 157 |
| 175 ReceivePaintUpdate(); | 158 ReceivePaintUpdate(); |
| 176 // Paint updates until the navigation is committed represent updates | 159 // Paint updates until the navigation is committed represent updates |
| 177 // for the previous page, so they shouldn't affect the flag. | 160 // for the previous page, so they shouldn't affect the flag. |
| 178 EXPECT_FALSE(GetOverlay()->received_paint_update_); | 161 EXPECT_FALSE(GetOverlay()->received_paint_update_); |
| 179 | 162 |
| 180 contents()->CommitPendingNavigation(); | 163 contents()->CommitPendingNavigation(); |
| 181 ReceivePaintUpdate(); | 164 ReceivePaintUpdate(); |
| 182 // Navigation was committed and the paint update was received - the flag | 165 // Navigation was committed and the paint update was received - the flag |
| 183 // should now be updated. | 166 // should now be updated. |
| 184 EXPECT_TRUE(GetOverlay()->received_paint_update_); | 167 EXPECT_TRUE(GetOverlay()->received_paint_update_); |
| 185 | 168 |
| 186 EXPECT_FALSE(GetOverlay()->web_contents()); | 169 EXPECT_FALSE(GetOverlay()->web_contents()); |
| 187 } | 170 } |
| 188 | 171 |
| 189 TEST_F(OverscrollNavigationOverlayTest, MultiNavigation_LoadingUpdate) { | 172 TEST_F(OverscrollNavigationOverlayTest, MultiNavigation_LoadingUpdate) { |
| 190 GetOverlay()->image_delegate_->SetImage(CreateDummyScreenshot()); | 173 GetOverlay()->image_delegate_->SetImage(CreateDummyScreenshot()); |
| 191 | 174 |
| 192 contents()->TestSetIsLoading(false); | |
| 193 EXPECT_TRUE(GetOverlay()->loading_complete_); | |
| 194 | |
| 195 PerformBackNavigationViaSliderCallbacks(); | 175 PerformBackNavigationViaSliderCallbacks(); |
| 196 // No screenshot was set on NavEntry at offset -1. | 176 // No screenshot was set on NavEntry at offset -1. |
| 197 EXPECT_FALSE(GetOverlay()->image_delegate_->has_image()); | 177 EXPECT_FALSE(GetOverlay()->image_delegate_->has_image()); |
| 198 // Navigation was started, so the loading status flag should be reset. | 178 // Navigation was started, so the loading status flag should be reset. |
| 199 EXPECT_FALSE(GetOverlay()->loading_complete_); | 179 EXPECT_FALSE(GetOverlay()->loading_complete_); |
| 200 | 180 |
| 201 // Load updates until the navigation is committed represent updates for the | 181 // Load updates until the navigation is committed represent updates for the |
| 202 // previous page, so they shouldn't affect the flag. | 182 // previous page, so they shouldn't affect the flag. |
| 203 contents()->TestSetIsLoading(true); | 183 contents()->TestSetIsLoading(true); |
| 204 contents()->TestSetIsLoading(false); | 184 contents()->TestSetIsLoading(false); |
| 205 EXPECT_FALSE(GetOverlay()->loading_complete_); | 185 EXPECT_FALSE(GetOverlay()->loading_complete_); |
| 206 | 186 |
| 207 contents()->CommitPendingNavigation(); | 187 contents()->CommitPendingNavigation(); |
| 208 contents()->TestSetIsLoading(true); | 188 contents()->TestSetIsLoading(true); |
| 209 contents()->TestSetIsLoading(false); | 189 contents()->TestSetIsLoading(false); |
| 210 // Navigation was committed and the load update was received - the flag | 190 // Navigation was committed and the load update was received - the flag |
| 211 // should now be updated. | 191 // should now be updated. |
| 212 EXPECT_TRUE(GetOverlay()->loading_complete_); | 192 EXPECT_TRUE(GetOverlay()->loading_complete_); |
| 213 | 193 |
| 214 EXPECT_TRUE(GetOverlay()->web_contents()); | |
| 215 ReceivePaintUpdate(); | |
| 216 EXPECT_FALSE(GetOverlay()->web_contents()); | 194 EXPECT_FALSE(GetOverlay()->web_contents()); |
| 217 } | 195 } |
| 218 | 196 |
| 219 } // namespace content | 197 } // namespace content |
| OLD | NEW |