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 "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "core/frame/PinchViewport.h" | 7 #include "core/frame/PinchViewport.h" |
8 | 8 |
9 #include "core/frame/FrameHost.h" | 9 #include "core/frame/FrameHost.h" |
10 #include "core/frame/LocalFrame.h" | 10 #include "core/frame/LocalFrame.h" |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
148 } | 148 } |
149 | 149 |
150 static void configureAndroidSettings(WebSettings* settings) | 150 static void configureAndroidSettings(WebSettings* settings) |
151 { | 151 { |
152 configureSettings(settings); | 152 configureSettings(settings); |
153 settings->setViewportEnabled(true); | 153 settings->setViewportEnabled(true); |
154 settings->setViewportMetaEnabled(true); | 154 settings->setViewportMetaEnabled(true); |
155 settings->setShrinksViewportContentToFit(true); | 155 settings->setShrinksViewportContentToFit(true); |
156 } | 156 } |
157 | 157 |
158 static void resizesAreOrientationChanges(WebSettings* settings) | |
159 { | |
160 configureSettings(settings); | |
161 settings->setViewportEnabled(true); | |
162 settings->setMainFrameResizesAreOrientationChanges(true); | |
bokan
2014/09/16 19:46:48
Does anything break if you just add setMainFrameRe
timav
2014/09/16 21:44:51
Nothing breaks in the existing tests, but for my o
bokan
2014/09/16 22:03:19
Hmm...you shouldn't need that. What was the proble
| |
163 } | |
164 | |
158 protected: | 165 protected: |
159 std::string m_baseURL; | 166 std::string m_baseURL; |
160 FrameTestHelpers::TestWebViewClient m_mockWebViewClient; | 167 FrameTestHelpers::TestWebViewClient m_mockWebViewClient; |
161 | 168 |
162 private: | 169 private: |
163 FrameTestHelpers::WebViewHelper m_helper; | 170 FrameTestHelpers::WebViewHelper m_helper; |
164 }; | 171 }; |
165 | 172 |
166 // Test that resizing the PinchViewport works as expected and that resizing the | 173 // Test that resizing the PinchViewport works as expected and that resizing the |
167 // WebView resizes the PinchViewport. | 174 // WebView resizes the PinchViewport. |
(...skipping 18 matching lines...) Expand all Loading... | |
186 EXPECT_SIZE_EQ(webViewSize, IntSize(webViewImpl()->size())); | 193 EXPECT_SIZE_EQ(webViewSize, IntSize(webViewImpl()->size())); |
187 EXPECT_SIZE_EQ(webViewSize, pinchViewport.size()); | 194 EXPECT_SIZE_EQ(webViewSize, pinchViewport.size()); |
188 | 195 |
189 // Resizing the pinch viewport shouldn't affect the WebView. | 196 // Resizing the pinch viewport shouldn't affect the WebView. |
190 IntSize newViewportSize = IntSize(320, 200); | 197 IntSize newViewportSize = IntSize(320, 200); |
191 pinchViewport.setSize(newViewportSize); | 198 pinchViewport.setSize(newViewportSize); |
192 EXPECT_SIZE_EQ(webViewSize, IntSize(webViewImpl()->size())); | 199 EXPECT_SIZE_EQ(webViewSize, IntSize(webViewImpl()->size())); |
193 EXPECT_SIZE_EQ(newViewportSize, pinchViewport.size()); | 200 EXPECT_SIZE_EQ(newViewportSize, pinchViewport.size()); |
194 } | 201 } |
195 | 202 |
203 // Test that the PinchViewport works as expected in case of a scaled | |
204 // and scrolled viewport - scroll down. | |
205 TEST_F(PinchViewportTest, TestResizeAfterVerticalScroll) | |
206 { | |
207 /* | |
208 200 200 | |
209 --------------------- --------------------- | |
210 | | | | | |
211 | | | | | |
212 | | | | | |
213 |150 | | | | |
214 | | | | | |
215 | | |175 | | |
216 | | | | | |
217 |---------- |300 | |300 | |
218 | | | -------> | | | |
219 |75 | | |-------------- | | |
220 | | | |50 | | | |
221 o---- |150 | o----- |100 | | |
222 | |60 | | | |40 | | | |
223 | | | | |____| | | | |
224 |---- | | |-------------- | | |
225 --------------------- --------------------- | |
bokan
2014/09/16 19:46:48
ASCII art is super helpful, nice! The anchor shoul
timav
2014/09/16 21:44:52
Right, and I keep forgetting about that.
I can mo
| |
226 | |
227 */ | |
228 | |
229 initializeWithDesktopSettings(resizesAreOrientationChanges); | |
bokan
2014/09/16 19:46:48
use initializeWithAndroidSettings() and move the m
timav
2014/09/16 21:44:51
Done.
| |
230 | |
231 registerMockedHttpURLLoad("200-by-300-viewport.html"); | |
232 navigateTo(m_baseURL + "200-by-300-viewport.html"); | |
233 | |
234 webViewImpl()->resize(IntSize(100, 150)); | |
235 webViewImpl()->layout(); | |
236 | |
237 // Scroll main frame to the bottom of the document | |
238 webViewImpl()->setMainFrameScrollOffset(WebPoint(0, 150)); | |
239 | |
240 webViewImpl()->setPageScaleFactor(2.5); | |
241 | |
242 PinchViewport& pinchViewport = frame()->page()->frameHost().pinchViewport(); | |
243 pinchViewport.setLocation(FloatPoint(0, 75)); | |
244 | |
245 // Verify the initial size of the pinch viewport in the CSS pixels | |
246 EXPECT_FLOAT_SIZE_EQ(FloatSize(40, 60), pinchViewport.visibleRect().size()); | |
247 | |
248 webViewImpl()->resize(IntSize(150, 100)); | |
249 webViewImpl()->layout(); | |
250 | |
251 EXPECT_FLOAT_SIZE_EQ(FloatSize(60, 40), pinchViewport.visibleRect().size()); | |
252 EXPECT_POINT_EQ(IntPoint(0, 175), frame()->view()->scrollPosition()); | |
253 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 50), pinchViewport.location()); | |
254 } | |
255 | |
256 // Test that the PinchViewport works as expected in case if a scaled | |
257 // and scrolled viewport - scroll right. | |
258 TEST_F(PinchViewportTest, TestResizeAfterHorizontalScroll) | |
259 { | |
260 /* | |
261 200 200 | |
262 ---------------o----- ---------------o----- | |
263 | | | || | | | | | |
264 | | 50 |40 || | | |_____| | |
265 | | -----| | | 90 60 | | |
266 | | | | | | | |
267 | | | | ---------------| | |
268 | 100 | 100 | | 50 150 | | |
269 | | | | | | |
270 | ----------| | | | |
271 | | -------> | | | |
272 | | | | | |
273 | |
274 */ | |
275 | |
276 initializeWithDesktopSettings(resizesAreOrientationChanges); | |
277 | |
278 registerMockedHttpURLLoad("200-by-300-viewport.html"); | |
279 navigateTo(m_baseURL + "200-by-300-viewport.html"); | |
280 | |
281 webViewImpl()->resize(IntSize(100, 150)); | |
282 webViewImpl()->layout(); | |
bokan
2014/09/16 19:46:48
you shouldn't need this layout (there's a layout c
timav
2014/09/16 21:44:51
Done.
| |
283 | |
284 // Scroll main frame to the right of the document | |
285 webViewImpl()->setMainFrameScrollOffset(WebPoint(100, 0)); | |
286 | |
287 webViewImpl()->setPageScaleFactor(2.5); | |
288 | |
289 PinchViewport& pinchViewport = frame()->page()->frameHost().pinchViewport(); | |
290 pinchViewport.setLocation(FloatPoint(50, 0)); | |
291 | |
292 // Verify the initial size of the pinch viewport in the CSS pixels | |
293 EXPECT_FLOAT_SIZE_EQ(FloatSize(40, 60), pinchViewport.visibleRect().size()); | |
294 | |
295 webViewImpl()->resize(IntSize(150, 100)); | |
296 webViewImpl()->layout(); | |
297 | |
298 EXPECT_FLOAT_SIZE_EQ(FloatSize(60, 40), pinchViewport.visibleRect().size()); | |
299 EXPECT_POINT_EQ(IntPoint(50, 0), frame()->view()->scrollPosition()); | |
300 EXPECT_FLOAT_POINT_EQ(FloatPoint(90, 0), pinchViewport.location()); | |
301 } | |
302 | |
196 static void disableAcceleratedCompositing(WebSettings* settings) | 303 static void disableAcceleratedCompositing(WebSettings* settings) |
197 { | 304 { |
198 PinchViewportTest::configureSettings(settings); | 305 PinchViewportTest::configureSettings(settings); |
199 // FIXME: This setting is being removed, so this test needs to be rewritten to | 306 // FIXME: This setting is being removed, so this test needs to be rewritten to |
200 // do something else. crbug.com/173949 | 307 // do something else. crbug.com/173949 |
201 settings->setAcceleratedCompositingEnabled(false); | 308 settings->setAcceleratedCompositingEnabled(false); |
202 } | 309 } |
203 | 310 |
204 // Test that the container layer gets sized properly if the WebView is resized | 311 // Test that the container layer gets sized properly if the WebView is resized |
205 // prior to the PinchViewport being attached to the layer tree. | 312 // prior to the PinchViewport being attached to the layer tree. |
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
793 pinchViewport.scrollIntoView(FloatRect(50, 75, 50, 75)); | 900 pinchViewport.scrollIntoView(FloatRect(50, 75, 50, 75)); |
794 EXPECT_POINT_EQ(IntPoint(50, 75), frame()->view()->scrollPosition()); | 901 EXPECT_POINT_EQ(IntPoint(50, 75), frame()->view()->scrollPosition()); |
795 EXPECT_FLOAT_POINT_EQ(FloatPoint(), pinchViewport.visibleRect().location()); | 902 EXPECT_FLOAT_POINT_EQ(FloatPoint(), pinchViewport.visibleRect().location()); |
796 | 903 |
797 pinchViewport.scrollIntoView(FloatRect(190, 290, 10, 10)); | 904 pinchViewport.scrollIntoView(FloatRect(190, 290, 10, 10)); |
798 EXPECT_POINT_EQ(IntPoint(100, 150), frame()->view()->scrollPosition()); | 905 EXPECT_POINT_EQ(IntPoint(100, 150), frame()->view()->scrollPosition()); |
799 EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 75), pinchViewport.visibleRect().locati on()); | 906 EXPECT_FLOAT_POINT_EQ(FloatPoint(50, 75), pinchViewport.visibleRect().locati on()); |
800 } | 907 } |
801 | 908 |
802 } // namespace | 909 } // namespace |
OLD | NEW |