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/common/view_messages.h" | 9 #include "content/common/view_messages.h" |
10 #include "content/public/browser/web_contents_view.h" | 10 #include "content/public/browser/web_contents_view.h" |
11 #include "content/public/test/mock_render_process_host.h" | 11 #include "content/public/test/mock_render_process_host.h" |
12 #include "content/test/test_render_view_host.h" | 12 #include "content/test/test_render_view_host.h" |
13 #include "content/test/test_web_contents.h" | 13 #include "content/test/test_web_contents.h" |
14 #include "ui/aura/test/test_windows.h" | 14 #include "ui/aura/test/test_windows.h" |
15 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
| 16 #include "ui/gfx/codec/png_codec.h" |
16 | 17 |
17 namespace content { | 18 namespace content { |
18 | 19 |
19 class OverscrollNavigationOverlayTest : public RenderViewHostImplTestHarness { | 20 class OverscrollNavigationOverlayTest : public RenderViewHostImplTestHarness { |
20 public: | 21 public: |
21 OverscrollNavigationOverlayTest() {} | 22 OverscrollNavigationOverlayTest() {} |
22 virtual ~OverscrollNavigationOverlayTest() {} | 23 virtual ~OverscrollNavigationOverlayTest() {} |
23 | 24 |
24 gfx::Image CreateDummyScreenshot() { | 25 gfx::Image CreateDummyScreenshot() { |
25 SkBitmap bitmap; | 26 SkBitmap bitmap; |
26 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1); | 27 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1); |
27 bitmap.allocPixels(); | 28 bitmap.allocPixels(); |
28 bitmap.eraseColor(SK_ColorWHITE); | 29 bitmap.eraseColor(SK_ColorWHITE); |
29 return gfx::Image::CreateFrom1xBitmap(bitmap); | 30 return gfx::Image::CreateFrom1xBitmap(bitmap); |
30 } | 31 } |
31 | 32 |
32 void SetDummyScreenshotOnNavEntry(NavigationEntry* entry) { | 33 void SetDummyScreenshotOnNavEntry(NavigationEntry* entry) { |
33 const unsigned char* raw_data = | 34 SkBitmap bitmap; |
34 reinterpret_cast<const unsigned char*>("garbage"); | 35 bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1); |
35 const int length = 5; | 36 bitmap.allocPixels(); |
36 std::vector<unsigned char> data_vector(raw_data, raw_data+length); | 37 bitmap.eraseColor(SK_ColorWHITE); |
| 38 std::vector<unsigned char> png_data; |
| 39 gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, true, &png_data); |
37 scoped_refptr<base::RefCountedBytes> png_bytes = | 40 scoped_refptr<base::RefCountedBytes> png_bytes = |
38 base::RefCountedBytes::TakeVector(&data_vector); | 41 base::RefCountedBytes::TakeVector(&png_data); |
39 NavigationEntryImpl* entry_impl = | 42 NavigationEntryImpl* entry_impl = |
40 NavigationEntryImpl::FromNavigationEntry(entry); | 43 NavigationEntryImpl::FromNavigationEntry(entry); |
41 entry_impl->SetScreenshotPNGData(png_bytes); | 44 entry_impl->SetScreenshotPNGData(png_bytes); |
42 } | 45 } |
43 | 46 |
44 void ReceivePaintUpdate() { | 47 void ReceivePaintUpdate() { |
45 ViewHostMsg_DidFirstVisuallyNonEmptyPaint msg( | 48 ViewHostMsg_DidFirstVisuallyNonEmptyPaint msg( |
46 test_rvh()->GetRoutingID(), 0); | 49 test_rvh()->GetRoutingID(), 0); |
47 RenderViewHostTester::TestOnMessageReceived(test_rvh(), msg); | 50 RenderViewHostTester::TestOnMessageReceived(test_rvh(), msg); |
48 } | 51 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 scoped_ptr<OverscrollNavigationOverlay> overlay_; | 124 scoped_ptr<OverscrollNavigationOverlay> overlay_; |
122 | 125 |
123 DISALLOW_COPY_AND_ASSIGN(OverscrollNavigationOverlayTest); | 126 DISALLOW_COPY_AND_ASSIGN(OverscrollNavigationOverlayTest); |
124 }; | 127 }; |
125 | 128 |
126 TEST_F(OverscrollNavigationOverlayTest, FirstVisuallyNonEmptyPaint_NoImage) { | 129 TEST_F(OverscrollNavigationOverlayTest, FirstVisuallyNonEmptyPaint_NoImage) { |
127 ReceivePaintUpdate(); | 130 ReceivePaintUpdate(); |
128 EXPECT_TRUE(GetOverlay()->received_paint_update_); | 131 EXPECT_TRUE(GetOverlay()->received_paint_update_); |
129 EXPECT_FALSE(GetOverlay()->loading_complete_); | 132 EXPECT_FALSE(GetOverlay()->loading_complete_); |
130 | 133 |
131 // The paint update will hide the overlay, although the page hasn't completely | 134 EXPECT_TRUE(GetOverlay()->received_paint_update_); |
132 // loaded yet. This is because the image-delegate doesn't have an image set. | 135 EXPECT_FALSE(GetOverlay()->loading_complete_); |
| 136 // The paint update will hide the overlay. |
133 EXPECT_FALSE(GetOverlay()->web_contents()); | 137 EXPECT_FALSE(GetOverlay()->web_contents()); |
134 } | 138 } |
135 | 139 |
136 TEST_F(OverscrollNavigationOverlayTest, FirstVisuallyNonEmptyPaint_WithImage) { | 140 TEST_F(OverscrollNavigationOverlayTest, FirstVisuallyNonEmptyPaint_WithImage) { |
137 GetOverlay()->image_delegate_->SetImage(CreateDummyScreenshot()); | 141 GetOverlay()->image_delegate_->SetImage(CreateDummyScreenshot()); |
138 | 142 |
139 ReceivePaintUpdate(); | 143 ReceivePaintUpdate(); |
140 EXPECT_TRUE(GetOverlay()->received_paint_update_); | 144 EXPECT_TRUE(GetOverlay()->received_paint_update_); |
141 EXPECT_FALSE(GetOverlay()->loading_complete_); | 145 EXPECT_FALSE(GetOverlay()->loading_complete_); |
142 EXPECT_TRUE(GetOverlay()->web_contents()); | 146 // The paint update will hide the overlay. |
143 | |
144 contents()->TestSetIsLoading(false); | |
145 EXPECT_TRUE(GetOverlay()->loading_complete_); | |
146 EXPECT_FALSE(GetOverlay()->web_contents()); | 147 EXPECT_FALSE(GetOverlay()->web_contents()); |
147 } | 148 } |
148 | 149 |
149 TEST_F(OverscrollNavigationOverlayTest, PaintUpdateWithoutNonEmptyPaint) { | 150 TEST_F(OverscrollNavigationOverlayTest, PaintUpdateWithoutNonEmptyPaint) { |
150 GetOverlay()->image_delegate_->SetImage(CreateDummyScreenshot()); | 151 GetOverlay()->image_delegate_->SetImage(CreateDummyScreenshot()); |
151 process()->sink().ClearMessages(); | 152 process()->sink().ClearMessages(); |
152 | 153 |
153 // The page load is complete, but the overlay should still be visible, because | 154 // The page load is complete, but the overlay should still be visible, because |
154 // there hasn't been any paint update. | 155 // there hasn't been any paint update. |
155 // This should also send a repaint request to the renderer, so that the | 156 // This should also send a repaint request to the renderer, so that the |
(...skipping 15 matching lines...) Expand all Loading... |
171 ViewHostMsg_UpdateRect rect(test_rvh()->GetRoutingID(), params); | 172 ViewHostMsg_UpdateRect rect(test_rvh()->GetRoutingID(), params); |
172 RenderViewHostTester::TestOnMessageReceived(test_rvh(), rect); | 173 RenderViewHostTester::TestOnMessageReceived(test_rvh(), rect); |
173 EXPECT_TRUE(GetOverlay()->received_paint_update_); | 174 EXPECT_TRUE(GetOverlay()->received_paint_update_); |
174 EXPECT_FALSE(GetOverlay()->web_contents()); | 175 EXPECT_FALSE(GetOverlay()->web_contents()); |
175 } | 176 } |
176 | 177 |
177 TEST_F(OverscrollNavigationOverlayTest, MultiNavigation_PaintUpdate) { | 178 TEST_F(OverscrollNavigationOverlayTest, MultiNavigation_PaintUpdate) { |
178 GetOverlay()->image_delegate_->SetImage(CreateDummyScreenshot()); | 179 GetOverlay()->image_delegate_->SetImage(CreateDummyScreenshot()); |
179 SetDummyScreenshotOnNavEntry(controller().GetEntryAtOffset(-1)); | 180 SetDummyScreenshotOnNavEntry(controller().GetEntryAtOffset(-1)); |
180 | 181 |
181 ReceivePaintUpdate(); | |
182 EXPECT_TRUE(GetOverlay()->received_paint_update_); | |
183 | |
184 PerformBackNavigationViaSliderCallbacks(); | 182 PerformBackNavigationViaSliderCallbacks(); |
185 // Screenshot was set on NavEntry at offset -1. | 183 // Screenshot was set on NavEntry at offset -1. |
186 EXPECT_TRUE(GetOverlay()->image_delegate_->has_image()); | 184 EXPECT_TRUE(GetOverlay()->image_delegate_->has_image()); |
187 // Navigation was started, so the paint update flag should be reset. | |
188 EXPECT_FALSE(GetOverlay()->received_paint_update_); | 185 EXPECT_FALSE(GetOverlay()->received_paint_update_); |
189 | 186 |
190 ReceivePaintUpdate(); | 187 ReceivePaintUpdate(); |
191 // Paint updates until the navigation is committed represent updates | 188 // Paint updates until the navigation is committed represent updates |
192 // for the previous page, so they shouldn't affect the flag. | 189 // for the previous page, so they shouldn't affect the flag. |
193 EXPECT_FALSE(GetOverlay()->received_paint_update_); | 190 EXPECT_FALSE(GetOverlay()->received_paint_update_); |
194 | 191 |
195 contents()->CommitPendingNavigation(); | 192 contents()->CommitPendingNavigation(); |
196 ReceivePaintUpdate(); | 193 ReceivePaintUpdate(); |
197 // Navigation was committed and the paint update was received - the flag | 194 // Navigation was committed and the paint update was received - the flag |
198 // should now be updated. | 195 // should now be updated. |
199 EXPECT_TRUE(GetOverlay()->received_paint_update_); | 196 EXPECT_TRUE(GetOverlay()->received_paint_update_); |
200 | 197 |
201 EXPECT_TRUE(GetOverlay()->web_contents()); | |
202 contents()->TestSetIsLoading(true); | |
203 contents()->TestSetIsLoading(false); | |
204 EXPECT_FALSE(GetOverlay()->web_contents()); | 198 EXPECT_FALSE(GetOverlay()->web_contents()); |
205 } | 199 } |
206 | 200 |
207 TEST_F(OverscrollNavigationOverlayTest, MultiNavigation_LoadingUpdate) { | 201 TEST_F(OverscrollNavigationOverlayTest, MultiNavigation_LoadingUpdate) { |
208 GetOverlay()->image_delegate_->SetImage(CreateDummyScreenshot()); | 202 GetOverlay()->image_delegate_->SetImage(CreateDummyScreenshot()); |
209 | 203 |
210 contents()->TestSetIsLoading(false); | 204 contents()->TestSetIsLoading(false); |
211 EXPECT_TRUE(GetOverlay()->loading_complete_); | 205 EXPECT_TRUE(GetOverlay()->loading_complete_); |
212 | 206 |
213 PerformBackNavigationViaSliderCallbacks(); | 207 PerformBackNavigationViaSliderCallbacks(); |
(...skipping 14 matching lines...) Expand all Loading... |
228 // Navigation was committed and the load update was received - the flag | 222 // Navigation was committed and the load update was received - the flag |
229 // should now be updated. | 223 // should now be updated. |
230 EXPECT_TRUE(GetOverlay()->loading_complete_); | 224 EXPECT_TRUE(GetOverlay()->loading_complete_); |
231 | 225 |
232 EXPECT_TRUE(GetOverlay()->web_contents()); | 226 EXPECT_TRUE(GetOverlay()->web_contents()); |
233 ReceivePaintUpdate(); | 227 ReceivePaintUpdate(); |
234 EXPECT_FALSE(GetOverlay()->web_contents()); | 228 EXPECT_FALSE(GetOverlay()->web_contents()); |
235 } | 229 } |
236 | 230 |
237 } // namespace content | 231 } // namespace content |
OLD | NEW |