Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: third_party/WebKit/Source/web/tests/TopControlsTest.cpp

Issue 1844013002: Fix main thread top controls scrolling to mirror CC. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@propertyTreesBoundsDelta
Patch Set: Build fix after rebase Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2015 Google Inc. All rights reserved. 2 * Copyright (C) 2015 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 #define MAYBE(test) DISABLED_##test 151 #define MAYBE(test) DISABLED_##test
152 #else 152 #else
153 #define MAYBE(test) test 153 #define MAYBE(test) test
154 #endif 154 #endif
155 155
156 // Scrolling down should hide top controls. 156 // Scrolling down should hide top controls.
157 TEST_F(TopControlsTest, MAYBE(HideOnScrollDown)) 157 TEST_F(TopControlsTest, MAYBE(HideOnScrollDown))
158 { 158 {
159 WebViewImpl* webView = initialize(); 159 WebViewImpl* webView = initialize();
160 // initialize top controls to be shown. 160 // initialize top controls to be shown.
161 webView->setTopControlsHeight(50.f, true); 161 webView->resizeWithTopControls(webView->size(), 50.f, true);
162 webView->topControls().setShownRatio(1); 162 webView->topControls().setShownRatio(1);
163 163
164 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin)); 164 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin));
165 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); 165 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset());
166 166
167 // Top controls should be scrolled partially and page should not scroll. 167 // Top controls should be scrolled partially and page should not scroll.
168 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, -25.f)); 168 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, -25.f));
169 EXPECT_FLOAT_EQ(25.f, webView->topControls().contentOffset()); 169 EXPECT_FLOAT_EQ(25.f, webView->topControls().contentOffset());
170 EXPECT_POINT_EQ(IntPoint(0, 0), frame()->view()->scrollPosition()); 170 EXPECT_POINT_EQ(IntPoint(0, 0), frame()->view()->scrollPosition());
171 171
172 // Top controls should consume 25px and become hidden. Excess scroll should be consumed by the page. 172 // Top controls should consume 25px and become hidden. Excess scroll should be consumed by the page.
173 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, -40.f)); 173 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, -40.f));
174 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); 174 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
175 EXPECT_POINT_EQ(IntPoint(0, 15), frame()->view()->scrollPosition()); 175 EXPECT_POINT_EQ(IntPoint(0, 15), frame()->view()->scrollPosition());
176 176
177 // Only page should consume scroll 177 // Only page should consume scroll
178 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, -20.f)); 178 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, -20.f));
179 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); 179 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
180 EXPECT_POINT_EQ(IntPoint(0, 35), frame()->view()->scrollPosition()); 180 EXPECT_POINT_EQ(IntPoint(0, 35), frame()->view()->scrollPosition());
181 } 181 }
182 182
183 // Scrolling up should show top controls. 183 // Scrolling up should show top controls.
184 TEST_F(TopControlsTest, MAYBE(ShowOnScrollUp)) 184 TEST_F(TopControlsTest, MAYBE(ShowOnScrollUp))
185 { 185 {
186 WebViewImpl* webView = initialize(); 186 WebViewImpl* webView = initialize();
187 // initialize top controls to be hidden. 187 // initialize top controls to be hidden.
188 webView->setTopControlsHeight(50.f, false); 188 webView->resizeWithTopControls(webView->size(), 50.f, false);
189 webView->topControls().setShownRatio(0); 189 webView->topControls().setShownRatio(0);
190 190
191 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin)); 191 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin));
192 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); 192 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
193 193
194 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, 10.f)); 194 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, 10.f));
195 EXPECT_FLOAT_EQ(10.f, webView->topControls().contentOffset()); 195 EXPECT_FLOAT_EQ(10.f, webView->topControls().contentOffset());
196 EXPECT_POINT_EQ(IntPoint(0, 0), frame()->view()->scrollPosition()); 196 EXPECT_POINT_EQ(IntPoint(0, 0), frame()->view()->scrollPosition());
197 197
198 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, 50.f)); 198 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, 50.f));
199 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); 199 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset());
200 EXPECT_POINT_EQ(IntPoint(0, 0), frame()->view()->scrollPosition()); 200 EXPECT_POINT_EQ(IntPoint(0, 0), frame()->view()->scrollPosition());
201 } 201 }
202 202
203 // Scrolling up after previous scroll downs should cause top controls to be 203 // Scrolling up after previous scroll downs should cause top controls to be
204 // shown only after all previously scrolled down amount is compensated. 204 // shown only after all previously scrolled down amount is compensated.
205 TEST_F(TopControlsTest, MAYBE(ScrollDownThenUp)) 205 TEST_F(TopControlsTest, MAYBE(ScrollDownThenUp))
206 { 206 {
207 WebViewImpl* webView = initialize(); 207 WebViewImpl* webView = initialize();
208 // initialize top controls to be shown and position page at 100px. 208 // initialize top controls to be shown and position page at 100px.
209 webView->setTopControlsHeight(50.f, true); 209 webView->resizeWithTopControls(webView->size(), 50.f, true);
210 webView->topControls().setShownRatio(1); 210 webView->topControls().setShownRatio(1);
211 frame()->view()->getScrollableArea()->setScrollPosition(IntPoint(0, 100), Pr ogrammaticScroll); 211 frame()->view()->getScrollableArea()->setScrollPosition(IntPoint(0, 100), Pr ogrammaticScroll);
212 212
213 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin)); 213 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin));
214 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); 214 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset());
215 215
216 // Scroll down to completely hide top controls. Excess deltaY (100px) should be consumed by the page. 216 // Scroll down to completely hide top controls. Excess deltaY (100px) should be consumed by the page.
217 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, -150.f)); 217 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, -150.f));
218 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); 218 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
219 EXPECT_POINT_EQ(IntPoint(0, 200), frame()->view()->scrollPosition()); 219 EXPECT_POINT_EQ(IntPoint(0, 200), frame()->view()->scrollPosition());
(...skipping 17 matching lines...) Expand all
237 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); 237 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset());
238 EXPECT_POINT_EQ(IntPoint(0, 50), frame()->view()->scrollPosition()); 238 EXPECT_POINT_EQ(IntPoint(0, 50), frame()->view()->scrollPosition());
239 } 239 }
240 240
241 // Scrolling down should always cause visible top controls to start hiding even 241 // Scrolling down should always cause visible top controls to start hiding even
242 // if we have been scrolling up previously. 242 // if we have been scrolling up previously.
243 TEST_F(TopControlsTest, MAYBE(ScrollUpThenDown)) 243 TEST_F(TopControlsTest, MAYBE(ScrollUpThenDown))
244 { 244 {
245 WebViewImpl* webView = initialize(); 245 WebViewImpl* webView = initialize();
246 // initialize top controls to be hidden and position page at 100px. 246 // initialize top controls to be hidden and position page at 100px.
247 webView->setTopControlsHeight(50.f, false); 247 webView->resizeWithTopControls(webView->size(), 50.f, false);
248 webView->topControls().setShownRatio(0); 248 webView->topControls().setShownRatio(0);
249 frame()->view()->getScrollableArea()->setScrollPosition(IntPoint(0, 100), Pr ogrammaticScroll); 249 frame()->view()->getScrollableArea()->setScrollPosition(IntPoint(0, 100), Pr ogrammaticScroll);
250 250
251 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin)); 251 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin));
252 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); 252 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
253 253
254 // Scroll up to completely show top controls. Excess deltaY (50px) should be consumed by the page. 254 // Scroll up to completely show top controls. Excess deltaY (50px) should be consumed by the page.
255 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, 100.f)); 255 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, 100.f));
256 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); 256 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset());
257 EXPECT_POINT_EQ(IntPoint(0, 50), frame()->view()->scrollPosition()); 257 EXPECT_POINT_EQ(IntPoint(0, 50), frame()->view()->scrollPosition());
258 258
259 // Scroll down and ensure only top controls is scrolled 259 // Scroll down and ensure only top controls is scrolled
260 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, -40.f)); 260 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, -40.f));
261 EXPECT_FLOAT_EQ(10.f, webView->topControls().contentOffset()); 261 EXPECT_FLOAT_EQ(10.f, webView->topControls().contentOffset());
262 EXPECT_POINT_EQ(IntPoint(0, 50), frame()->view()->scrollPosition()); 262 EXPECT_POINT_EQ(IntPoint(0, 50), frame()->view()->scrollPosition());
263 263
264 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, -60.f)); 264 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, -60.f));
265 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); 265 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
266 EXPECT_POINT_EQ(IntPoint(0, 100), frame()->view()->scrollPosition()); 266 EXPECT_POINT_EQ(IntPoint(0, 100), frame()->view()->scrollPosition());
267 } 267 }
268 268
269 // Top controls should not consume horizontal scroll. 269 // Top controls should not consume horizontal scroll.
270 TEST_F(TopControlsTest, MAYBE(HorizontalScroll)) 270 TEST_F(TopControlsTest, MAYBE(HorizontalScroll))
271 { 271 {
272 WebViewImpl* webView = initialize(); 272 WebViewImpl* webView = initialize();
273 // initialize top controls to be shown. 273 // initialize top controls to be shown.
274 webView->setTopControlsHeight(50.f, true); 274 webView->resizeWithTopControls(webView->size(), 50.f, true);
275 webView->topControls().setShownRatio(1); 275 webView->topControls().setShownRatio(1);
276 276
277 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin)); 277 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin));
278 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); 278 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset());
279 279
280 // Top controls should not consume horizontal scroll. 280 // Top controls should not consume horizontal scroll.
281 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, -110.f, -100.f)); 281 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, -110.f, -100.f));
282 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); 282 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
283 EXPECT_POINT_EQ(IntPoint(110, 50), frame()->view()->scrollPosition()); 283 EXPECT_POINT_EQ(IntPoint(110, 50), frame()->view()->scrollPosition());
284 284
285 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, -40.f, 0)); 285 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, -40.f, 0));
286 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); 286 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
287 EXPECT_POINT_EQ(IntPoint(150, 50), frame()->view()->scrollPosition()); 287 EXPECT_POINT_EQ(IntPoint(150, 50), frame()->view()->scrollPosition());
288 } 288 }
289 289
290 // Page scale should not impact top controls scrolling 290 // Page scale should not impact top controls scrolling
291 TEST_F(TopControlsTest, MAYBE(PageScaleHasNoImpact)) 291 TEST_F(TopControlsTest, MAYBE(PageScaleHasNoImpact))
292 { 292 {
293 WebViewImpl* webView = initialize(); 293 WebViewImpl* webView = initialize();
294 webViewImpl()->setDefaultPageScaleLimits(0.25f, 5); 294 webViewImpl()->setDefaultPageScaleLimits(0.25f, 5);
295 webView->setPageScaleFactor(2.0); 295 webView->setPageScaleFactor(2.0);
296 296
297 // Initialize top controls to be shown. 297 // Initialize top controls to be shown.
298 webView->setTopControlsHeight(50.f, true); 298 webView->resizeWithTopControls(webView->size(), 50.f, true);
299 webView->topControls().setShownRatio(1); 299 webView->topControls().setShownRatio(1);
300 300
301 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin)); 301 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollBegin));
302 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); 302 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset());
303 303
304 // Top controls should be scrolled partially and page should not scroll. 304 // Top controls should be scrolled partially and page should not scroll.
305 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, -20.f)); 305 webView->handleInputEvent(generateEvent(WebInputEvent::GestureScrollUpdate, 0, -20.f));
306 EXPECT_FLOAT_EQ(30.f, webView->topControls().contentOffset()); 306 EXPECT_FLOAT_EQ(30.f, webView->topControls().contentOffset());
307 EXPECT_POINT_EQ(IntPoint(0, 0), frame()->view()->getScrollableArea()->scroll PositionDouble()); 307 EXPECT_POINT_EQ(IntPoint(0, 0), frame()->view()->getScrollableArea()->scroll PositionDouble());
308 308
(...skipping 25 matching lines...) Expand all
334 // floating-point number. Make sure that if the top controls aren't fully 334 // floating-point number. Make sure that if the top controls aren't fully
335 // scrolled, scrollBy doesn't return any excess delta. i.e. There should be no 335 // scrolled, scrollBy doesn't return any excess delta. i.e. There should be no
336 // slippage between the content and top controls. 336 // slippage between the content and top controls.
337 TEST_F(TopControlsTest, MAYBE(FloatingPointSlippage)) 337 TEST_F(TopControlsTest, MAYBE(FloatingPointSlippage))
338 { 338 {
339 WebViewImpl* webView = initialize(); 339 WebViewImpl* webView = initialize();
340 webViewImpl()->setDefaultPageScaleLimits(0.25f, 5); 340 webViewImpl()->setDefaultPageScaleLimits(0.25f, 5);
341 webView->setPageScaleFactor(2.0); 341 webView->setPageScaleFactor(2.0);
342 342
343 // Initialize top controls to be shown. 343 // Initialize top controls to be shown.
344 webView->setTopControlsHeight(50.f, true); 344 webView->resizeWithTopControls(webView->size(), 50.f, true);
345 webView->topControls().setShownRatio(1); 345 webView->topControls().setShownRatio(1);
346 346
347 webView->topControls().scrollBegin(); 347 webView->topControls().scrollBegin();
348 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); 348 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset());
349 349
350 // This will result in a 20px scroll to the top controls so the show ratio 350 // This will result in a 20px scroll to the top controls so the show ratio
351 // will be 30/50 == 0.6 which is not representible in a float. Make sure 351 // will be 30/50 == 0.6 which is not representible in a float. Make sure
352 // that scroll still consumes the whole delta. 352 // that scroll still consumes the whole delta.
353 FloatSize remainingDelta = webView->topControls().scrollBy(FloatSize(0, 10)) ; 353 FloatSize remainingDelta = webView->topControls().scrollBy(FloatSize(0, 10)) ;
354 EXPECT_EQ(0, remainingDelta.height()); 354 EXPECT_EQ(0, remainingDelta.height());
355 } 355 }
356 356
357 // Scrollable subregions should scroll before top controls 357 // Scrollable subregions should scroll before top controls
358 TEST_F(TopControlsTest, MAYBE(ScrollableSubregionScrollFirst)) 358 TEST_F(TopControlsTest, MAYBE(ScrollableSubregionScrollFirst))
359 { 359 {
360 WebViewImpl* webView = initialize("overflow-scrolling.html"); 360 WebViewImpl* webView = initialize("overflow-scrolling.html");
361 webView->setTopControlsHeight(50.f, true); 361 webView->resizeWithTopControls(webView->size(), 50.f, true);
362 webView->topControls().setShownRatio(1); 362 webView->topControls().setShownRatio(1);
363 frame()->view()->getScrollableArea()->setScrollPosition(IntPoint(0, 50), Pro grammaticScroll); 363 frame()->view()->getScrollableArea()->setScrollPosition(IntPoint(0, 50), Pro grammaticScroll);
364 364
365 // Test scroll down 365 // Test scroll down
366 // Scroll down should scroll the overflow div first but top controls and mai n frame should not scroll. 366 // Scroll down should scroll the overflow div first but top controls and mai n frame should not scroll.
367 verticalScroll(-800.f); 367 verticalScroll(-800.f);
368 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); 368 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset());
369 EXPECT_POINT_EQ(IntPoint(0, 50), frame()->view()->scrollPosition()); 369 EXPECT_POINT_EQ(IntPoint(0, 50), frame()->view()->scrollPosition());
370 370
371 // Continued scroll down should start hiding top controls but main frame sho uld not scroll. 371 // Continued scroll down should start hiding top controls but main frame sho uld not scroll.
(...skipping 21 matching lines...) Expand all
393 verticalScroll(40.f); 393 verticalScroll(40.f);
394 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); 394 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset());
395 EXPECT_POINT_EQ(IntPoint(0, 50), frame()->view()->scrollPosition()); 395 EXPECT_POINT_EQ(IntPoint(0, 50), frame()->view()->scrollPosition());
396 } 396 }
397 397
398 398
399 // Scrollable iframes should scroll before top controls 399 // Scrollable iframes should scroll before top controls
400 TEST_F(TopControlsTest, MAYBE(ScrollableIframeScrollFirst)) 400 TEST_F(TopControlsTest, MAYBE(ScrollableIframeScrollFirst))
401 { 401 {
402 WebViewImpl* webView = initialize("iframe-scrolling.html"); 402 WebViewImpl* webView = initialize("iframe-scrolling.html");
403 webView->setTopControlsHeight(50.f, true); 403 webView->resizeWithTopControls(webView->size(), 50.f, true);
404 webView->topControls().setShownRatio(1); 404 webView->topControls().setShownRatio(1);
405 frame()->view()->getScrollableArea()->setScrollPosition(IntPoint(0, 50), Pro grammaticScroll); 405 frame()->view()->getScrollableArea()->setScrollPosition(IntPoint(0, 50), Pro grammaticScroll);
406 406
407 // Test scroll down 407 // Test scroll down
408 // Scroll down should scroll the iframe first but top controls and main fram e should not scroll. 408 // Scroll down should scroll the iframe first but top controls and main fram e should not scroll.
409 verticalScroll(-800.f); 409 verticalScroll(-800.f);
410 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); 410 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset());
411 EXPECT_POINT_EQ(IntPoint(0, 50), frame()->view()->scrollPosition()); 411 EXPECT_POINT_EQ(IntPoint(0, 50), frame()->view()->scrollPosition());
412 412
413 // Continued scroll down should start hiding top controls but main frame sho uld not scroll. 413 // Continued scroll down should start hiding top controls but main frame sho uld not scroll.
(...skipping 20 matching lines...) Expand all
434 // Continued scroll down up scroll up the main frame 434 // Continued scroll down up scroll up the main frame
435 verticalScroll(40.f); 435 verticalScroll(40.f);
436 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); 436 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset());
437 EXPECT_POINT_EQ(IntPoint(0, 50), frame()->view()->scrollPosition()); 437 EXPECT_POINT_EQ(IntPoint(0, 50), frame()->view()->scrollPosition());
438 } 438 }
439 439
440 // Top controls visibility should remain consistent when height is changed. 440 // Top controls visibility should remain consistent when height is changed.
441 TEST_F(TopControlsTest, MAYBE(HeightChangeMaintainsVisibility)) 441 TEST_F(TopControlsTest, MAYBE(HeightChangeMaintainsVisibility))
442 { 442 {
443 WebViewImpl* webView = initialize(); 443 WebViewImpl* webView = initialize();
444 webView->setTopControlsHeight(20.f, false); 444 webView->resizeWithTopControls(webView->size(), 20.f, false);
445 webView->topControls().setShownRatio(0); 445 webView->topControls().setShownRatio(0);
446 446
447 webView->setTopControlsHeight(20.f, false); 447 webView->resizeWithTopControls(webView->size(), 20.f, false);
448 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); 448 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
449 449
450 webView->setTopControlsHeight(40.f, false); 450 webView->resizeWithTopControls(webView->size(), 40.f, false);
451 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); 451 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
452 452
453 // Scroll up to show top controls. 453 // Scroll up to show top controls.
454 verticalScroll(40.f); 454 verticalScroll(40.f);
455 EXPECT_FLOAT_EQ(40.f, webView->topControls().contentOffset()); 455 EXPECT_FLOAT_EQ(40.f, webView->topControls().contentOffset());
456 456
457 // Changing height of a fully shown top controls should correctly adjust con tent offset 457 // Changing height of a fully shown top controls should correctly adjust con tent offset
458 webView->setTopControlsHeight(30.f, false); 458 webView->resizeWithTopControls(webView->size(), 30.f, false);
459 EXPECT_FLOAT_EQ(30.f, webView->topControls().contentOffset()); 459 EXPECT_FLOAT_EQ(30.f, webView->topControls().contentOffset());
460 } 460 }
461 461
462 // Zero delta should not have any effect on top controls. 462 // Zero delta should not have any effect on top controls.
463 TEST_F(TopControlsTest, MAYBE(ZeroHeightMeansNoEffect)) 463 TEST_F(TopControlsTest, MAYBE(ZeroHeightMeansNoEffect))
464 { 464 {
465 WebViewImpl* webView = initialize(); 465 WebViewImpl* webView = initialize();
466 webView->setTopControlsHeight(0, false); 466 webView->resizeWithTopControls(webView->size(), 0, false);
467 webView->topControls().setShownRatio(0); 467 webView->topControls().setShownRatio(0);
468 frame()->view()->getScrollableArea()->setScrollPosition(IntPoint(0, 100), Pr ogrammaticScroll); 468 frame()->view()->getScrollableArea()->setScrollPosition(IntPoint(0, 100), Pr ogrammaticScroll);
469 469
470 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); 470 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
471 471
472 verticalScroll(20.f); 472 verticalScroll(20.f);
473 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); 473 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
474 EXPECT_POINT_EQ(IntPoint(0, 80), frame()->view()->scrollPosition()); 474 EXPECT_POINT_EQ(IntPoint(0, 80), frame()->view()->scrollPosition());
475 475
476 verticalScroll(-30.f); 476 verticalScroll(-30.f);
477 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); 477 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
478 EXPECT_POINT_EQ(IntPoint(0, 110), frame()->view()->scrollPosition()); 478 EXPECT_POINT_EQ(IntPoint(0, 110), frame()->view()->scrollPosition());
479 479
480 webView->topControls().setShownRatio(1); 480 webView->topControls().setShownRatio(1);
481 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); 481 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
482 } 482 }
483 483
484 // Top controls should not hide when scrolling up past limit 484 // Top controls should not hide when scrolling up past limit
485 TEST_F(TopControlsTest, MAYBE(ScrollUpPastLimitDoesNotHide)) 485 TEST_F(TopControlsTest, MAYBE(ScrollUpPastLimitDoesNotHide))
486 { 486 {
487 WebViewImpl* webView = initialize(); 487 WebViewImpl* webView = initialize();
488 // Initialize top controls to be shown 488 // Initialize top controls to be shown
489 webView->setTopControlsHeight(50.f, true); 489 webView->resizeWithTopControls(webView->size(), 50.f, true);
490 webView->topControls().setShownRatio(1); 490 webView->topControls().setShownRatio(1);
491 // Use 2x scale so that both visual viewport and frameview are scrollable 491 // Use 2x scale so that both visual viewport and frameview are scrollable
492 webView->setPageScaleFactor(2.0); 492 webView->setPageScaleFactor(2.0);
493 493
494 // Fully scroll frameview but visualviewport remains scrollable 494 // Fully scroll frameview but visualviewport remains scrollable
495 webView->mainFrame()->setScrollOffset(WebSize(0, 10000)); 495 webView->mainFrame()->setScrollOffset(WebSize(0, 10000));
496 visualViewport().setLocation(FloatPoint(0, 0)); 496 visualViewport().setLocation(FloatPoint(0, 0));
497 verticalScroll(-10.f); 497 verticalScroll(-10.f);
498 EXPECT_FLOAT_EQ(40, webView->topControls().contentOffset()); 498 EXPECT_FLOAT_EQ(40, webView->topControls().contentOffset());
499 499
(...skipping 11 matching lines...) Expand all
511 verticalScroll(-30.f); 511 verticalScroll(-30.f);
512 // Top controls should not move because neither frameview nor visual viewpor t 512 // Top controls should not move because neither frameview nor visual viewpor t
513 // are scrollable 513 // are scrollable
514 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset()); 514 EXPECT_FLOAT_EQ(50.f, webView->topControls().contentOffset());
515 } 515 }
516 516
517 // Top controls should honor its constraints 517 // Top controls should honor its constraints
518 TEST_F(TopControlsTest, MAYBE(StateConstraints)) 518 TEST_F(TopControlsTest, MAYBE(StateConstraints))
519 { 519 {
520 WebViewImpl* webView = initialize(); 520 WebViewImpl* webView = initialize();
521 webView->setTopControlsHeight(50.f, false); 521 webView->resizeWithTopControls(webView->size(), 50.f, false);
522 frame()->view()->getScrollableArea()->setScrollPosition(IntPoint(0, 100), Pr ogrammaticScroll); 522 frame()->view()->getScrollableArea()->setScrollPosition(IntPoint(0, 100), Pr ogrammaticScroll);
523 523
524 // Setting permitted state should not change content offset 524 // Setting permitted state should not change content offset
525 webView->updateTopControlsState(WebTopControlsShown, WebTopControlsShown, fa lse); 525 webView->updateTopControlsState(WebTopControlsShown, WebTopControlsShown, fa lse);
526 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset()); 526 EXPECT_FLOAT_EQ(0.f, webView->topControls().contentOffset());
527 527
528 // Showing is permitted 528 // Showing is permitted
529 webView->topControls().setShownRatio(1); 529 webView->topControls().setShownRatio(1);
530 EXPECT_FLOAT_EQ(50, webView->topControls().contentOffset()); 530 EXPECT_FLOAT_EQ(50, webView->topControls().contentOffset());
531 531
(...skipping 28 matching lines...) Expand all
560 EXPECT_FLOAT_EQ(0, webView->topControls().contentOffset()); 560 EXPECT_FLOAT_EQ(0, webView->topControls().contentOffset());
561 EXPECT_POINT_EQ(IntPoint(0, 90), frame()->view()->scrollPosition()); 561 EXPECT_POINT_EQ(IntPoint(0, 90), frame()->view()->scrollPosition());
562 } 562 }
563 563
564 // Ensure that top controls do not affect the layout by showing and hiding 564 // Ensure that top controls do not affect the layout by showing and hiding
565 // except for position: fixed elements. 565 // except for position: fixed elements.
566 TEST_F(TopControlsTest, MAYBE(DontAffectLayoutHeight)) 566 TEST_F(TopControlsTest, MAYBE(DontAffectLayoutHeight))
567 { 567 {
568 // Initialize with the top controls showing. 568 // Initialize with the top controls showing.
569 WebViewImpl* webView = initialize("percent-height.html"); 569 WebViewImpl* webView = initialize("percent-height.html");
570 webView->setTopControlsHeight(100.f, true); 570 webView->resizeWithTopControls(WebSize(400, 300), 100.f, true);
571 webView->updateTopControlsState( 571 webView->updateTopControlsState(
572 WebTopControlsBoth, WebTopControlsShown, false); 572 WebTopControlsBoth, WebTopControlsShown, false);
573 webView->topControls().setShownRatio(1); 573 webView->topControls().setShownRatio(1);
574 webView->resize(WebSize(400, 300));
575 webView->updateAllLifecyclePhases(); 574 webView->updateAllLifecyclePhases();
576 575
577 ASSERT_EQ(100.f, webView->topControls().contentOffset()); 576 ASSERT_EQ(100.f, webView->topControls().contentOffset());
578 577
579 // When the top controls are showing, there's 300px for the layout height so 578 // When the top controls are showing, there's 300px for the layout height so
580 // 50% should result in both the position:fixed and position: absolute divs 579 // 50% should result in both the position:fixed and position: absolute divs
581 // having 150px of height. 580 // having 150px of height.
582 Element* absPos = 581 Element* absPos =
583 getElementById(WebString::fromUTF8("abs")); 582 getElementById(WebString::fromUTF8("abs"));
584 Element* fixedPos = 583 Element* fixedPos =
585 getElementById(WebString::fromUTF8("fixed")); 584 getElementById(WebString::fromUTF8("fixed"));
586 EXPECT_FLOAT_EQ(150.f, absPos->getBoundingClientRect()->height()); 585 EXPECT_FLOAT_EQ(150.f, absPos->getBoundingClientRect()->height());
587 EXPECT_FLOAT_EQ(150.f, fixedPos->getBoundingClientRect()->height()); 586 EXPECT_FLOAT_EQ(150.f, fixedPos->getBoundingClientRect()->height());
588 587
589 // The layout size on the FrameView should not include the top controls. 588 // The layout size on the FrameView should not include the top controls.
590 EXPECT_EQ(300, frame()->view()->layoutSize(IncludeScrollbars).height()); 589 EXPECT_EQ(300, frame()->view()->layoutSize(IncludeScrollbars).height());
591 590
592 // Hide the top controls. 591 // Hide the top controls.
593 verticalScroll(-100.f); 592 verticalScroll(-100.f);
594 webView->setTopControlsHeight(100.f, false); 593 webView->resizeWithTopControls(WebSize(400, 400), 100.f, false);
595 webView->resize(WebSize(400, 400));
596 webView->updateAllLifecyclePhases(); 594 webView->updateAllLifecyclePhases();
597 595
598 ASSERT_EQ(0.f, webView->topControls().contentOffset()); 596 ASSERT_EQ(0.f, webView->topControls().contentOffset());
599 597
600 // Hiding the top controls shouldn't change the height of the initial 598 // Hiding the top controls shouldn't change the height of the initial
601 // containing block for non-position: fixed. Position: fixed however should 599 // containing block for non-position: fixed. Position: fixed however should
602 // use the entire height of the viewport however. 600 // use the entire height of the viewport however.
603 EXPECT_FLOAT_EQ(150.f, absPos->getBoundingClientRect()->height()); 601 EXPECT_FLOAT_EQ(150.f, absPos->getBoundingClientRect()->height());
604 EXPECT_FLOAT_EQ(200.f, fixedPos->getBoundingClientRect()->height()); 602 EXPECT_FLOAT_EQ(200.f, fixedPos->getBoundingClientRect()->height());
605 603
606 // The layout size should not change as a result of top controls hiding. 604 // The layout size should not change as a result of top controls hiding.
607 EXPECT_EQ(300, frame()->view()->layoutSize(IncludeScrollbars).height()); 605 EXPECT_EQ(300, frame()->view()->layoutSize(IncludeScrollbars).height());
608 } 606 }
609 607
610 // Ensure that top controls do not affect vh units. 608 // Ensure that top controls do not affect vh units.
611 TEST_F(TopControlsTest, MAYBE(DontAffectVHUnits)) 609 TEST_F(TopControlsTest, MAYBE(DontAffectVHUnits))
612 { 610 {
613 // Initialize with the top controls showing. 611 // Initialize with the top controls showing.
614 WebViewImpl* webView = initialize("vh-height.html"); 612 WebViewImpl* webView = initialize("vh-height.html");
615 webView->setTopControlsHeight(100.f, true); 613 webView->resizeWithTopControls(WebSize(400, 300), 100.f, true);
616 webView->updateTopControlsState( 614 webView->updateTopControlsState(
617 WebTopControlsBoth, WebTopControlsShown, false); 615 WebTopControlsBoth, WebTopControlsShown, false);
618 webView->topControls().setShownRatio(1); 616 webView->topControls().setShownRatio(1);
619 webView->resize(WebSize(400, 300));
620 webView->updateAllLifecyclePhases(); 617 webView->updateAllLifecyclePhases();
621 618
622 ASSERT_EQ(100.f, webView->topControls().contentOffset()); 619 ASSERT_EQ(100.f, webView->topControls().contentOffset());
623 620
624 // 'vh' units should be based on the viewport when the top controls are 621 // 'vh' units should be based on the viewport when the top controls are
625 // hidden. 622 // hidden.
626 Element* absPos = 623 Element* absPos =
627 getElementById(WebString::fromUTF8("abs")); 624 getElementById(WebString::fromUTF8("abs"));
628 Element* fixedPos = 625 Element* fixedPos =
629 getElementById(WebString::fromUTF8("fixed")); 626 getElementById(WebString::fromUTF8("fixed"));
630 EXPECT_FLOAT_EQ(200.f, absPos->getBoundingClientRect()->height()); 627 EXPECT_FLOAT_EQ(200.f, absPos->getBoundingClientRect()->height());
631 EXPECT_FLOAT_EQ(200.f, fixedPos->getBoundingClientRect()->height()); 628 EXPECT_FLOAT_EQ(200.f, fixedPos->getBoundingClientRect()->height());
632 629
633 // The size used for viewport units should not be reduced by the top 630 // The size used for viewport units should not be reduced by the top
634 // controls. 631 // controls.
635 EXPECT_EQ(400, frame()->view()->viewportSizeForViewportUnits().height()); 632 EXPECT_EQ(400, frame()->view()->viewportSizeForViewportUnits().height());
636 633
637 // Hide the top controls. 634 // Hide the top controls.
638 verticalScroll(-100.f); 635 verticalScroll(-100.f);
639 webView->setTopControlsHeight(100.f, false); 636 webView->resizeWithTopControls(WebSize(400, 400), 100.f, false);
640 webView->resize(WebSize(400, 400));
641 webView->updateAllLifecyclePhases(); 637 webView->updateAllLifecyclePhases();
642 638
643 ASSERT_EQ(0.f, webView->topControls().contentOffset()); 639 ASSERT_EQ(0.f, webView->topControls().contentOffset());
644 640
645 // vh units should be static with respect to the top controls so neighter 641 // vh units should be static with respect to the top controls so neighter
646 // <div> should change size are a result of the top controls hiding. 642 // <div> should change size are a result of the top controls hiding.
647 EXPECT_FLOAT_EQ(200.f, absPos->getBoundingClientRect()->height()); 643 EXPECT_FLOAT_EQ(200.f, absPos->getBoundingClientRect()->height());
648 EXPECT_FLOAT_EQ(200.f, fixedPos->getBoundingClientRect()->height()); 644 EXPECT_FLOAT_EQ(200.f, fixedPos->getBoundingClientRect()->height());
649 645
650 // The viewport size used for vh units should not change as a result of top 646 // The viewport size used for vh units should not change as a result of top
651 // controls hiding. 647 // controls hiding.
652 EXPECT_EQ(400, frame()->view()->viewportSizeForViewportUnits().height()); 648 EXPECT_EQ(400, frame()->view()->viewportSizeForViewportUnits().height());
653 } 649 }
654 650
655 // Ensure that on a legacy page (there's a non-1 minimum scale) 100vh units fill 651 // Ensure that on a legacy page (there's a non-1 minimum scale) 100vh units fill
656 // the viewport, with top controls hidden, when the viewport encompasses the 652 // the viewport, with top controls hidden, when the viewport encompasses the
657 // layout width. 653 // layout width.
658 TEST_F(TopControlsTest, MAYBE(DontAffectVHUnitsWithScale)) 654 TEST_F(TopControlsTest, MAYBE(DontAffectVHUnitsWithScale))
659 { 655 {
660 // Initialize with the top controls showing. 656 // Initialize with the top controls showing.
661 WebViewImpl* webView = initialize("vh-height-width-800.html"); 657 WebViewImpl* webView = initialize("vh-height-width-800.html");
662 webView->setTopControlsHeight(100.f, true); 658 webView->resizeWithTopControls(WebSize(400, 300), 100.f, true);
663 webView->updateTopControlsState( 659 webView->updateTopControlsState(
664 WebTopControlsBoth, WebTopControlsShown, false); 660 WebTopControlsBoth, WebTopControlsShown, false);
665 webView->topControls().setShownRatio(1); 661 webView->topControls().setShownRatio(1);
666 webView->resize(WebSize(400, 300));
667 webView->updateAllLifecyclePhases(); 662 webView->updateAllLifecyclePhases();
668 663
669 ASSERT_EQ(100.f, webView->topControls().contentOffset()); 664 ASSERT_EQ(100.f, webView->topControls().contentOffset());
670 665
671 // Device viewport is 400px but the page is width=800 so minimum-scale 666 // Device viewport is 400px but the page is width=800 so minimum-scale
672 // should be 0.5. This is also the scale at which the viewport fills the 667 // should be 0.5. This is also the scale at which the viewport fills the
673 // layout width. 668 // layout width.
674 ASSERT_EQ(0.5f, webView->minimumPageScaleFactor()); 669 ASSERT_EQ(0.5f, webView->minimumPageScaleFactor());
675 670
676 // We should size vh units so that 100vh fills the viewport at min-scale so 671 // We should size vh units so that 100vh fills the viewport at min-scale so
677 // we have to account for the minimum page scale factor. Since both boxes 672 // we have to account for the minimum page scale factor. Since both boxes
678 // are 50vh, and layout scale = 0.5, we have a vh viewport of 400 / 0.5 = 80 0 673 // are 50vh, and layout scale = 0.5, we have a vh viewport of 400 / 0.5 = 80 0
679 // so we expect 50vh to be 400px. 674 // so we expect 50vh to be 400px.
680 Element* absPos = 675 Element* absPos =
681 getElementById(WebString::fromUTF8("abs")); 676 getElementById(WebString::fromUTF8("abs"));
682 Element* fixedPos = 677 Element* fixedPos =
683 getElementById(WebString::fromUTF8("fixed")); 678 getElementById(WebString::fromUTF8("fixed"));
684 EXPECT_FLOAT_EQ(400.f, absPos->getBoundingClientRect()->height()); 679 EXPECT_FLOAT_EQ(400.f, absPos->getBoundingClientRect()->height());
685 EXPECT_FLOAT_EQ(400.f, fixedPos->getBoundingClientRect()->height()); 680 EXPECT_FLOAT_EQ(400.f, fixedPos->getBoundingClientRect()->height());
686 681
687 // The size used for viewport units should not be reduced by the top 682 // The size used for viewport units should not be reduced by the top
688 // controls. 683 // controls.
689 EXPECT_EQ(800, frame()->view()->viewportSizeForViewportUnits().height()); 684 EXPECT_EQ(800, frame()->view()->viewportSizeForViewportUnits().height());
690 685
691 // Hide the top controls. 686 // Hide the top controls.
692 verticalScroll(-100.f); 687 verticalScroll(-100.f);
693 webView->setTopControlsHeight(100.f, false); 688 webView->resizeWithTopControls(WebSize(400, 400), 100.f, false);
694 webView->resize(WebSize(400, 400));
695 webView->updateAllLifecyclePhases(); 689 webView->updateAllLifecyclePhases();
696 690
697 ASSERT_EQ(0.f, webView->topControls().contentOffset()); 691 ASSERT_EQ(0.f, webView->topControls().contentOffset());
698 692
699 // vh units should be static with respect to the top controls so neighter 693 // vh units should be static with respect to the top controls so neighter
700 // <div> should change size are a result of the top controls hiding. 694 // <div> should change size are a result of the top controls hiding.
701 EXPECT_FLOAT_EQ(400.f, absPos->getBoundingClientRect()->height()); 695 EXPECT_FLOAT_EQ(400.f, absPos->getBoundingClientRect()->height());
702 EXPECT_FLOAT_EQ(400.f, fixedPos->getBoundingClientRect()->height()); 696 EXPECT_FLOAT_EQ(400.f, fixedPos->getBoundingClientRect()->height());
703 697
704 // The viewport size used for vh units should not change as a result of top 698 // The viewport size used for vh units should not change as a result of top
705 // controls hiding. 699 // controls hiding.
706 EXPECT_EQ(800, frame()->view()->viewportSizeForViewportUnits().height()); 700 EXPECT_EQ(800, frame()->view()->viewportSizeForViewportUnits().height());
707 } 701 }
708 702
709 // Ensure that on a legacy page (there's a non-1 minimum scale) whose viewport 703 // Ensure that on a legacy page (there's a non-1 minimum scale) whose viewport
710 // at minimum-scale is larger than the layout size, 100vh units fill the 704 // at minimum-scale is larger than the layout size, 100vh units fill the
711 // viewport, with top controls hidden, when the viewport is scaled such that 705 // viewport, with top controls hidden, when the viewport is scaled such that
712 // its width equals the layout width. 706 // its width equals the layout width.
713 TEST_F(TopControlsTest, MAYBE(DontAffectVHUnitsUseLayoutSize)) 707 TEST_F(TopControlsTest, MAYBE(DontAffectVHUnitsUseLayoutSize))
714 { 708 {
715 // Initialize with the top controls showing. 709 // Initialize with the top controls showing.
716 WebViewImpl* webView = initialize("vh-height-width-800-extra-wide.html"); 710 WebViewImpl* webView = initialize("vh-height-width-800-extra-wide.html");
717 webView->setTopControlsHeight(100.f, true); 711 webView->resizeWithTopControls(WebSize(400, 300), 100.f, true);
718 webView->updateTopControlsState( 712 webView->updateTopControlsState(
719 WebTopControlsBoth, WebTopControlsShown, false); 713 WebTopControlsBoth, WebTopControlsShown, false);
720 webView->topControls().setShownRatio(1); 714 webView->topControls().setShownRatio(1);
721 webView->resize(WebSize(400, 300));
722 webView->updateAllLifecyclePhases(); 715 webView->updateAllLifecyclePhases();
723 716
724 ASSERT_EQ(100.f, webView->topControls().contentOffset()); 717 ASSERT_EQ(100.f, webView->topControls().contentOffset());
725 718
726 // Device viewport is 400px and page is width=800 but there's an element 719 // Device viewport is 400px and page is width=800 but there's an element
727 // that's 1600px wide so the minimum scale is 0.25 to encompass that. 720 // that's 1600px wide so the minimum scale is 0.25 to encompass that.
728 ASSERT_EQ(0.25f, webView->minimumPageScaleFactor()); 721 ASSERT_EQ(0.25f, webView->minimumPageScaleFactor());
729 722
730 // The viewport will match the layout width at scale=0.5 so the height used 723 // The viewport will match the layout width at scale=0.5 so the height used
731 // for vh should be (300 / 0.5) for the layout height + (100 / 0.5) for top 724 // for vh should be (300 / 0.5) for the layout height + (100 / 0.5) for top
732 // controls = 800. 725 // controls = 800.
733 EXPECT_EQ(800, frame()->view()->viewportSizeForViewportUnits().height()); 726 EXPECT_EQ(800, frame()->view()->viewportSizeForViewportUnits().height());
734 } 727 }
735 728
729 // This tests that the viewport remains anchored when top controls are brought
730 // in while the document is fully scrolled. This normally causes clamping of the
731 // visual viewport to keep it bounded by the layout viewport so we're testing
732 // that the viewport anchoring logic is working to keep the view unchanged.
733 TEST_F(TopControlsTest, MAYBE(AnchorViewportDuringTopControlsAdjustment))
734 {
735 int contentHeight = 1016;
736 int layoutViewportHeight = 500;
737 int visualViewportHeight = 500;
738 int topControlsHeight = 100;
739 int pageScale = 2;
740 int minScale = 1;
741
742 // Initialize with the top controls showing.
743 WebViewImpl* webView = initialize("large-div.html");
744 webViewImpl()->setDefaultPageScaleLimits(minScale, 5);
745 webView->resizeWithTopControls(
746 WebSize(800, layoutViewportHeight),
747 topControlsHeight,
748 true);
749 webView->updateTopControlsState(
750 WebTopControlsBoth, WebTopControlsShown, false);
751 webView->topControls().setShownRatio(1);
752 webView->updateAllLifecyclePhases();
753
754 FrameView* view = frame()->view();
755 ScrollableArea* rootViewport = frame()->view()->getScrollableArea();
756
757 int expectedVisualOffset =
758 ((layoutViewportHeight + topControlsHeight / minScale) * pageScale
759 - (visualViewportHeight + topControlsHeight))
760 / pageScale;
761 int expectedLayoutOffset =
762 contentHeight - (layoutViewportHeight + topControlsHeight / minScale);
763 int expectedRootOffset = expectedVisualOffset + expectedLayoutOffset;
764
765 // Zoom in to 2X and fully scroll both viewports.
766 webView->setPageScaleFactor(pageScale);
767 {
768 webView->handleInputEvent(
769 generateEvent(WebInputEvent::GestureScrollBegin));
770 webView->handleInputEvent(
771 generateEvent(WebInputEvent::GestureScrollUpdate, 0, -10000));
772
773 ASSERT_EQ(0.f, webView->topControls().contentOffset());
774
775 EXPECT_EQ(expectedVisualOffset, visualViewport().location().y());
776 EXPECT_EQ(expectedLayoutOffset,
777 view->layoutViewportScrollableArea()->scrollPosition().y());
778 EXPECT_EQ(expectedRootOffset, rootViewport->scrollPosition().y());
779
780 webView->handleInputEvent(
781 generateEvent(WebInputEvent::GestureScrollEnd));
782 }
783
784 // Commit the top controls resize so that the top controls do not shrink the
785 // layout size. This should not have moved any of the viewports.
786 webView->resizeWithTopControls(
787 WebSize(800, layoutViewportHeight + topControlsHeight),
788 topControlsHeight,
789 false);
790 webView->updateAllLifecyclePhases();
791 ASSERT_EQ(expectedVisualOffset, visualViewport().location().y());
792 ASSERT_EQ(expectedLayoutOffset,
793 view->layoutViewportScrollableArea()->scrollPosition().y());
794 ASSERT_EQ(expectedRootOffset, rootViewport->scrollPosition().y());
795
796 // Now scroll back up just enough to show the top controls. The top controls
797 // should shrink both viewports but the layout viewport by a greater amount.
798 // This means the visual viewport's offset must be clamped to keep it within
799 // the layout viewport. Make sure we adjust the scroll position to account
800 // for this and keep the visual viewport at the same location relative to
801 // the document (i.e. the user shouldn't see a movement).
802 {
803 webView->handleInputEvent(
804 generateEvent(WebInputEvent::GestureScrollBegin));
805 webView->handleInputEvent(
806 generateEvent(WebInputEvent::GestureScrollUpdate, 0, 80));
807
808 visualViewport().clampToBoundaries();
809 view->setScrollPosition(view->scrollPosition(), ProgrammaticScroll);
810
811 ASSERT_EQ(80.f, webView->topControls().contentOffset());
812 EXPECT_EQ(expectedRootOffset, rootViewport->scrollPosition().y());
813
814 webView->handleInputEvent(
815 generateEvent(WebInputEvent::GestureScrollEnd));
816 }
817 }
818
736 } // namespace blink 819 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/WebViewImpl.cpp ('k') | third_party/WebKit/Source/web/tests/VisualViewportTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698