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

Side by Side Diff: Source/web/tests/PinchViewportTest.cpp

Issue 263853008: Added pinch viewport offset to history item. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Feedback addressed + small fix for broken unit test Created 6 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 // 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"
11 #include "core/rendering/RenderView.h" 11 #include "core/rendering/RenderView.h"
12 #include "core/rendering/compositing/CompositedLayerMapping.h" 12 #include "core/rendering/compositing/CompositedLayerMapping.h"
13 #include "core/rendering/compositing/RenderLayerCompositor.h" 13 #include "core/rendering/compositing/RenderLayerCompositor.h"
14 #include "public/platform/Platform.h" 14 #include "public/platform/Platform.h"
15 #include "public/platform/WebLayerTreeView.h" 15 #include "public/platform/WebLayerTreeView.h"
16 #include "public/platform/WebUnitTestSupport.h" 16 #include "public/platform/WebUnitTestSupport.h"
17 #include "public/web/WebSettings.h" 17 #include "public/web/WebSettings.h"
18 #include "public/web/WebViewClient.h" 18 #include "public/web/WebViewClient.h"
19 #include "web/WebLocalFrameImpl.h" 19 #include "web/WebLocalFrameImpl.h"
20 #include "web/tests/FrameTestHelpers.h" 20 #include "web/tests/FrameTestHelpers.h"
21 #include "web/tests/URLTestHelpers.h" 21 #include "web/tests/URLTestHelpers.h"
22 #include <gmock/gmock.h> 22 #include <gmock/gmock.h>
23 #include <gtest/gtest.h> 23 #include <gtest/gtest.h>
24 24
25 #define EXPECT_POINT_EQ(expected, actual) \
26 do { \
27 EXPECT_EQ((expected).x(), (actual).x()); \
28 EXPECT_EQ((expected).y(), (actual).y()); \
29 } while (false)
30
25 #define EXPECT_FLOAT_POINT_EQ(expected, actual) \ 31 #define EXPECT_FLOAT_POINT_EQ(expected, actual) \
26 do { \ 32 do { \
27 EXPECT_FLOAT_EQ((expected).x(), (actual).x()); \ 33 EXPECT_FLOAT_EQ((expected).x(), (actual).x()); \
28 EXPECT_FLOAT_EQ((expected).y(), (actual).y()); \ 34 EXPECT_FLOAT_EQ((expected).y(), (actual).y()); \
29 } while (false) 35 } while (false)
30 36
31 #define EXPECT_SIZE_EQ(expected, actual) \ 37 #define EXPECT_SIZE_EQ(expected, actual) \
32 do { \ 38 do { \
33 EXPECT_EQ((expected).width(), (actual).width()); \ 39 EXPECT_EQ((expected).width(), (actual).width()); \
34 EXPECT_EQ((expected).height(), (actual).height()); \ 40 EXPECT_EQ((expected).height(), (actual).height()); \
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 EXPECT_SIZE_EQ(IntSize(0, 0), frame()->page()->frameHost().pinchViewport().s ize()); 429 EXPECT_SIZE_EQ(IntSize(0, 0), frame()->page()->frameHost().pinchViewport().s ize());
424 430
425 webViewImpl()->enableAutoResizeMode(WebSize(10, 10), WebSize(1000, 1000)); 431 webViewImpl()->enableAutoResizeMode(WebSize(10, 10), WebSize(1000, 1000));
426 432
427 registerMockedHttpURLLoad("200-by-300.html"); 433 registerMockedHttpURLLoad("200-by-300.html");
428 navigateTo(m_baseURL + "200-by-300.html"); 434 navigateTo(m_baseURL + "200-by-300.html");
429 435
430 EXPECT_SIZE_EQ(IntSize(200, 300), frame()->page()->frameHost().pinchViewport ().size()); 436 EXPECT_SIZE_EQ(IntSize(200, 300), frame()->page()->frameHost().pinchViewport ().size());
431 } 437 }
432 438
439 // Test that the HistoryItem for the page stores the pinch viewport's offset and scale.
440 TEST_F(PinchViewportTest, TestSavedToHistoryItem)
441 {
442 initializeWithDesktopSettings();
443 webViewImpl()->resize(IntSize(200, 300));
444 webViewImpl()->layout();
445
446 registerMockedHttpURLLoad("200-by-300.html");
447 navigateTo(m_baseURL + "200-by-300.html");
448
449 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0),
450 webViewImpl()->page()->mainFrame()->loader().currentItem()->pinchViewpor tScrollPoint());
451
452 PinchViewport& pinchViewport = frame()->page()->frameHost().pinchViewport();
453 pinchViewport.setScale(2);
454
455 EXPECT_EQ(2, webViewImpl()->page()->mainFrame()->loader().currentItem()->pag eScaleFactor());
456
457 pinchViewport.setLocation(FloatPoint(10, 20));
458
459 EXPECT_FLOAT_POINT_EQ(FloatPoint(10, 20),
460 webViewImpl()->page()->mainFrame()->loader().currentItem()->pinchViewpor tScrollPoint());
461 }
462
463 // Test restoring a HistoryItem properly restores the pinch viewport's state.
464 TEST_F(PinchViewportTest, TestRestoredFromHistoryItem)
465 {
466 initializeWithDesktopSettings();
467 webViewImpl()->resize(IntSize(200, 300));
468
469 registerMockedHttpURLLoad("200-by-300.html");
470
471 WebHistoryItem item;
472 item.initialize();
473 WebURL destinationURL(blink::URLTestHelpers::toKURL(m_baseURL + "200-by-300. html"));
474 item.setURLString(destinationURL.string());
475 item.setPinchViewportScrollOffset(WebFloatPoint(100, 120));
476 item.setPageScaleFactor(2);
477
478 webViewImpl()->mainFrame()->loadHistoryItem(item, WebHistoryDifferentDocumen tLoad, WebURLRequest::UseProtocolCachePolicy);
479 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
480
481 PinchViewport& pinchViewport = frame()->page()->frameHost().pinchViewport();
482 EXPECT_EQ(2, pinchViewport.scale());
483
484 EXPECT_FLOAT_POINT_EQ(FloatPoint(100, 120), pinchViewport.visibleRect().loca tion());
485 }
486
487 // Test restoring a HistoryItem without the pinch viewport offset falls back to distributing
488 // the scroll offset between the main frame and the pinch viewport.
489 TEST_F(PinchViewportTest, TestRestoredFromLegacyHistoryItem)
490 {
491 initializeWithDesktopSettings();
492 webViewImpl()->resize(IntSize(100, 150));
493
494 registerMockedHttpURLLoad("200-by-300-viewport.html");
495
496 WebHistoryItem item;
497 item.initialize();
498 WebURL destinationURL(blink::URLTestHelpers::toKURL(m_baseURL + "200-by-300- viewport.html"));
499 item.setURLString(destinationURL.string());
500 // (-1, -1) will be used if the HistoryItem is an older version prior to hav ing
501 // pinch viewport scroll offset.
502 item.setPinchViewportScrollOffset(WebFloatPoint(-1, -1));
503 item.setScrollOffset(WebPoint(120, 180));
504 item.setPageScaleFactor(2);
505
506 webViewImpl()->mainFrame()->loadHistoryItem(item, WebHistoryDifferentDocumen tLoad, WebURLRequest::UseProtocolCachePolicy);
507 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
508
509 PinchViewport& pinchViewport = frame()->page()->frameHost().pinchViewport();
510 EXPECT_EQ(2, pinchViewport.scale());
511 EXPECT_POINT_EQ(IntPoint(100, 150), frame()->view()->scrollPosition());
512 EXPECT_FLOAT_POINT_EQ(FloatPoint(20, 30), pinchViewport.visibleRect().locati on());
513 }
514
433 } // namespace 515 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698