OLD | NEW |
| 1 |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 2 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 3 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 4 // found in the LICENSE file. |
4 | 5 |
5 #include "config.h" | 6 #include "config.h" |
6 | 7 |
7 #include "core/frame/PinchViewport.h" | 8 #include "core/frame/PinchViewport.h" |
8 | 9 |
9 #include "core/frame/FrameHost.h" | 10 #include "core/frame/FrameHost.h" |
10 #include "core/frame/LocalFrame.h" | 11 #include "core/frame/LocalFrame.h" |
11 #include "core/rendering/RenderView.h" | 12 #include "core/rendering/RenderView.h" |
12 #include "core/rendering/compositing/CompositedLayerMapping.h" | 13 #include "core/rendering/compositing/CompositedLayerMapping.h" |
13 #include "core/rendering/compositing/RenderLayerCompositor.h" | 14 #include "core/rendering/compositing/RenderLayerCompositor.h" |
14 #include "public/platform/Platform.h" | 15 #include "public/platform/Platform.h" |
15 #include "public/platform/WebLayerTreeView.h" | 16 #include "public/platform/WebLayerTreeView.h" |
16 #include "public/platform/WebUnitTestSupport.h" | 17 #include "public/platform/WebUnitTestSupport.h" |
17 #include "public/web/WebScriptSource.h" | 18 #include "public/web/WebScriptSource.h" |
18 #include "public/web/WebSettings.h" | 19 #include "public/web/WebSettings.h" |
19 #include "public/web/WebViewClient.h" | 20 #include "public/web/WebViewClient.h" |
20 #include "web/WebLocalFrameImpl.h" | 21 #include "web/WebLocalFrameImpl.h" |
21 #include "web/tests/FrameTestHelpers.h" | 22 #include "web/tests/FrameTestHelpers.h" |
22 #include "web/tests/URLTestHelpers.h" | 23 #include "web/tests/URLTestHelpers.h" |
23 #include <gmock/gmock.h> | 24 #include <gmock/gmock.h> |
24 #include <gtest/gtest.h> | 25 #include <gtest/gtest.h> |
25 | 26 |
| 27 #define EXPECT_POINT_EQ(expected, actual) \ |
| 28 do { \ |
| 29 EXPECT_EQ((expected).x(), (actual).x()); \ |
| 30 EXPECT_EQ((expected).y(), (actual).y()); \ |
| 31 } while (false) |
| 32 |
26 #define EXPECT_FLOAT_POINT_EQ(expected, actual) \ | 33 #define EXPECT_FLOAT_POINT_EQ(expected, actual) \ |
27 do { \ | 34 do { \ |
28 EXPECT_FLOAT_EQ((expected).x(), (actual).x()); \ | 35 EXPECT_FLOAT_EQ((expected).x(), (actual).x()); \ |
29 EXPECT_FLOAT_EQ((expected).y(), (actual).y()); \ | 36 EXPECT_FLOAT_EQ((expected).y(), (actual).y()); \ |
30 } while (false) | 37 } while (false) |
31 | 38 |
32 #define EXPECT_POINT_EQ(expected, actual) \ | 39 #define EXPECT_POINT_EQ(expected, actual) \ |
33 do { \ | 40 do { \ |
34 EXPECT_EQ((expected).x(), (actual).x()); \ | 41 EXPECT_EQ((expected).x(), (actual).x()); \ |
35 EXPECT_EQ((expected).y(), (actual).y()); \ | 42 EXPECT_EQ((expected).y(), (actual).y()); \ |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 expected.moveBy(-flooredIntPoint(pinchViewport.visibleRect().location())); | 478 expected.moveBy(-flooredIntPoint(pinchViewport.visibleRect().location())); |
472 expected.scale(pinchViewport.scale(), pinchViewport.scale()); | 479 expected.scale(pinchViewport.scale(), pinchViewport.scale()); |
473 | 480 |
474 EXPECT_POINT_EQ(expected, IntRect(anchor).location()); | 481 EXPECT_POINT_EQ(expected, IntRect(anchor).location()); |
475 EXPECT_POINT_EQ(expected, IntRect(focus).location()); | 482 EXPECT_POINT_EQ(expected, IntRect(focus).location()); |
476 | 483 |
477 // FIXME(bokan) - http://crbug.com/364154 - Figure out how to test text sele
ction | 484 // FIXME(bokan) - http://crbug.com/364154 - Figure out how to test text sele
ction |
478 // as well rather than just carret. | 485 // as well rather than just carret. |
479 } | 486 } |
480 | 487 |
| 488 // Test that the HistoryItem for the page stores the pinch viewport's offset and
scale. |
| 489 TEST_F(PinchViewportTest, TestSavedToHistoryItem) |
| 490 { |
| 491 initializeWithDesktopSettings(); |
| 492 webViewImpl()->resize(IntSize(200, 300)); |
| 493 webViewImpl()->layout(); |
| 494 |
| 495 registerMockedHttpURLLoad("200-by-300.html"); |
| 496 navigateTo(m_baseURL + "200-by-300.html"); |
| 497 |
| 498 EXPECT_FLOAT_POINT_EQ(FloatPoint(0, 0), |
| 499 webViewImpl()->page()->mainFrame()->loader().currentItem()->pinchViewpor
tScrollPoint()); |
| 500 |
| 501 PinchViewport& pinchViewport = frame()->page()->frameHost().pinchViewport(); |
| 502 pinchViewport.setScale(2); |
| 503 |
| 504 EXPECT_EQ(2, webViewImpl()->page()->mainFrame()->loader().currentItem()->pag
eScaleFactor()); |
| 505 |
| 506 pinchViewport.setLocation(FloatPoint(10, 20)); |
| 507 |
| 508 EXPECT_FLOAT_POINT_EQ(FloatPoint(10, 20), |
| 509 webViewImpl()->page()->mainFrame()->loader().currentItem()->pinchViewpor
tScrollPoint()); |
| 510 } |
| 511 |
| 512 // Test restoring a HistoryItem properly restores the pinch viewport's state. |
| 513 TEST_F(PinchViewportTest, TestRestoredFromHistoryItem) |
| 514 { |
| 515 initializeWithDesktopSettings(); |
| 516 webViewImpl()->resize(IntSize(200, 300)); |
| 517 |
| 518 registerMockedHttpURLLoad("200-by-300.html"); |
| 519 |
| 520 WebHistoryItem item; |
| 521 item.initialize(); |
| 522 WebURL destinationURL(blink::URLTestHelpers::toKURL(m_baseURL + "200-by-300.
html")); |
| 523 item.setURLString(destinationURL.string()); |
| 524 item.setPinchViewportScrollOffset(WebFloatPoint(100, 120)); |
| 525 item.setPageScaleFactor(2); |
| 526 |
| 527 webViewImpl()->mainFrame()->loadHistoryItem(item, WebHistoryDifferentDocumen
tLoad, WebURLRequest::UseProtocolCachePolicy); |
| 528 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); |
| 529 |
| 530 PinchViewport& pinchViewport = frame()->page()->frameHost().pinchViewport(); |
| 531 EXPECT_EQ(2, pinchViewport.scale()); |
| 532 |
| 533 EXPECT_FLOAT_POINT_EQ(FloatPoint(100, 120), pinchViewport.visibleRect().loca
tion()); |
| 534 } |
| 535 |
| 536 // Test restoring a HistoryItem without the pinch viewport offset falls back to
distributing |
| 537 // the scroll offset between the main frame and the pinch viewport. |
| 538 TEST_F(PinchViewportTest, TestRestoredFromLegacyHistoryItem) |
| 539 { |
| 540 initializeWithDesktopSettings(); |
| 541 webViewImpl()->resize(IntSize(100, 150)); |
| 542 |
| 543 registerMockedHttpURLLoad("200-by-300-viewport.html"); |
| 544 |
| 545 WebHistoryItem item; |
| 546 item.initialize(); |
| 547 WebURL destinationURL(blink::URLTestHelpers::toKURL(m_baseURL + "200-by-300-
viewport.html")); |
| 548 item.setURLString(destinationURL.string()); |
| 549 // (-1, -1) will be used if the HistoryItem is an older version prior to hav
ing |
| 550 // pinch viewport scroll offset. |
| 551 item.setPinchViewportScrollOffset(WebFloatPoint(-1, -1)); |
| 552 item.setScrollOffset(WebPoint(120, 180)); |
| 553 item.setPageScaleFactor(2); |
| 554 |
| 555 webViewImpl()->mainFrame()->loadHistoryItem(item, WebHistoryDifferentDocumen
tLoad, WebURLRequest::UseProtocolCachePolicy); |
| 556 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); |
| 557 |
| 558 PinchViewport& pinchViewport = frame()->page()->frameHost().pinchViewport(); |
| 559 EXPECT_EQ(2, pinchViewport.scale()); |
| 560 EXPECT_POINT_EQ(IntPoint(100, 150), frame()->view()->scrollPosition()); |
| 561 EXPECT_FLOAT_POINT_EQ(FloatPoint(20, 30), pinchViewport.visibleRect().locati
on()); |
| 562 } |
| 563 |
481 } // namespace | 564 } // namespace |
OLD | NEW |