| OLD | NEW |
| 1 | 1 |
| 2 // Copyright 2014 The Chromium Authors. All rights reserved. | 2 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 // 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 |
| 4 // found in the LICENSE file. | 4 // found in the LICENSE file. |
| 5 | 5 |
| 6 #include "config.h" | 6 #include "config.h" |
| 7 | 7 |
| 8 #include "core/frame/PinchViewport.h" | 8 #include "core/frame/PinchViewport.h" |
| 9 | 9 |
| 10 #include "core/frame/FrameHost.h" | 10 #include "core/frame/FrameHost.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 do { \ | 52 do { \ |
| 53 EXPECT_FLOAT_EQ((expected).x(), (actual).x()); \ | 53 EXPECT_FLOAT_EQ((expected).x(), (actual).x()); \ |
| 54 EXPECT_FLOAT_EQ((expected).y(), (actual).y()); \ | 54 EXPECT_FLOAT_EQ((expected).y(), (actual).y()); \ |
| 55 EXPECT_FLOAT_EQ((expected).width(), (actual).width()); \ | 55 EXPECT_FLOAT_EQ((expected).width(), (actual).width()); \ |
| 56 EXPECT_FLOAT_EQ((expected).height(), (actual).height()); \ | 56 EXPECT_FLOAT_EQ((expected).height(), (actual).height()); \ |
| 57 } while (false) | 57 } while (false) |
| 58 | 58 |
| 59 | 59 |
| 60 using namespace WebCore; | 60 using namespace WebCore; |
| 61 using namespace blink; | 61 using namespace blink; |
| 62 using blink::FrameTestHelpers::runPendingTasks; | |
| 63 | 62 |
| 64 namespace { | 63 namespace { |
| 65 | 64 |
| 66 class PinchViewportTest : public testing::Test { | 65 class PinchViewportTest : public testing::Test { |
| 67 public: | 66 public: |
| 68 PinchViewportTest() | 67 PinchViewportTest() |
| 69 : m_baseURL("http://www.test.com/") | 68 : m_baseURL("http://www.test.com/") |
| 70 { | 69 { |
| 71 } | 70 } |
| 72 | 71 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 83 } | 82 } |
| 84 | 83 |
| 85 virtual ~PinchViewportTest() | 84 virtual ~PinchViewportTest() |
| 86 { | 85 { |
| 87 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); | 86 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); |
| 88 } | 87 } |
| 89 | 88 |
| 90 void navigateTo(const std::string& url) | 89 void navigateTo(const std::string& url) |
| 91 { | 90 { |
| 92 FrameTestHelpers::loadFrame(webViewImpl()->mainFrame(), url); | 91 FrameTestHelpers::loadFrame(webViewImpl()->mainFrame(), url); |
| 93 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(
); | |
| 94 } | 92 } |
| 95 | 93 |
| 96 void forceFullCompositingUpdate() | 94 void forceFullCompositingUpdate() |
| 97 { | 95 { |
| 98 webViewImpl()->layout(); | 96 webViewImpl()->layout(); |
| 99 } | 97 } |
| 100 | 98 |
| 101 void registerMockedHttpURLLoad(const std::string& fileName) | 99 void registerMockedHttpURLLoad(const std::string& fileName) |
| 102 { | 100 { |
| 103 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseU
RL.c_str()), WebString::fromUTF8(fileName.c_str())); | 101 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseU
RL.c_str()), WebString::fromUTF8(fileName.c_str())); |
| 104 } | 102 } |
| 105 | 103 |
| 106 void executeScript(const WebString& code) | |
| 107 { | |
| 108 webViewImpl()->mainFrame()->executeScript(WebScriptSource(code)); | |
| 109 runPendingTasks(); | |
| 110 } | |
| 111 | |
| 112 WebLayer* getRootScrollLayer() | 104 WebLayer* getRootScrollLayer() |
| 113 { | 105 { |
| 114 RenderLayerCompositor* compositor = frame()->contentRenderer()->composit
or(); | 106 RenderLayerCompositor* compositor = frame()->contentRenderer()->composit
or(); |
| 115 ASSERT(compositor); | 107 ASSERT(compositor); |
| 116 ASSERT(compositor->scrollLayer()); | 108 ASSERT(compositor->scrollLayer()); |
| 117 | 109 |
| 118 WebLayer* webScrollLayer = compositor->scrollLayer()->platformLayer(); | 110 WebLayer* webScrollLayer = compositor->scrollLayer()->platformLayer(); |
| 119 return webScrollLayer; | 111 return webScrollLayer; |
| 120 } | 112 } |
| 121 | 113 |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 | 509 |
| 518 registerMockedHttpURLLoad("200-by-300.html"); | 510 registerMockedHttpURLLoad("200-by-300.html"); |
| 519 | 511 |
| 520 WebHistoryItem item; | 512 WebHistoryItem item; |
| 521 item.initialize(); | 513 item.initialize(); |
| 522 WebURL destinationURL(blink::URLTestHelpers::toKURL(m_baseURL + "200-by-300.
html")); | 514 WebURL destinationURL(blink::URLTestHelpers::toKURL(m_baseURL + "200-by-300.
html")); |
| 523 item.setURLString(destinationURL.string()); | 515 item.setURLString(destinationURL.string()); |
| 524 item.setPinchViewportScrollOffset(WebFloatPoint(100, 120)); | 516 item.setPinchViewportScrollOffset(WebFloatPoint(100, 120)); |
| 525 item.setPageScaleFactor(2); | 517 item.setPageScaleFactor(2); |
| 526 | 518 |
| 527 webViewImpl()->mainFrame()->loadHistoryItem(item, WebHistoryDifferentDocumen
tLoad, WebURLRequest::UseProtocolCachePolicy); | 519 FrameTestHelpers::loadHistoryItem(webViewImpl()->mainFrame(), item, WebHisto
ryDifferentDocumentLoad, WebURLRequest::UseProtocolCachePolicy); |
| 528 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); | |
| 529 | 520 |
| 530 PinchViewport& pinchViewport = frame()->page()->frameHost().pinchViewport(); | 521 PinchViewport& pinchViewport = frame()->page()->frameHost().pinchViewport(); |
| 531 EXPECT_EQ(2, pinchViewport.scale()); | 522 EXPECT_EQ(2, pinchViewport.scale()); |
| 532 | 523 |
| 533 EXPECT_FLOAT_POINT_EQ(FloatPoint(100, 120), pinchViewport.visibleRect().loca
tion()); | 524 EXPECT_FLOAT_POINT_EQ(FloatPoint(100, 120), pinchViewport.visibleRect().loca
tion()); |
| 534 } | 525 } |
| 535 | 526 |
| 536 // Test restoring a HistoryItem without the pinch viewport offset falls back to
distributing | 527 // 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. | 528 // the scroll offset between the main frame and the pinch viewport. |
| 538 TEST_F(PinchViewportTest, TestRestoredFromLegacyHistoryItem) | 529 TEST_F(PinchViewportTest, TestRestoredFromLegacyHistoryItem) |
| 539 { | 530 { |
| 540 initializeWithDesktopSettings(); | 531 initializeWithDesktopSettings(); |
| 541 webViewImpl()->resize(IntSize(100, 150)); | 532 webViewImpl()->resize(IntSize(100, 150)); |
| 542 | 533 |
| 543 registerMockedHttpURLLoad("200-by-300-viewport.html"); | 534 registerMockedHttpURLLoad("200-by-300-viewport.html"); |
| 544 | 535 |
| 545 WebHistoryItem item; | 536 WebHistoryItem item; |
| 546 item.initialize(); | 537 item.initialize(); |
| 547 WebURL destinationURL(blink::URLTestHelpers::toKURL(m_baseURL + "200-by-300-
viewport.html")); | 538 WebURL destinationURL(blink::URLTestHelpers::toKURL(m_baseURL + "200-by-300-
viewport.html")); |
| 548 item.setURLString(destinationURL.string()); | 539 item.setURLString(destinationURL.string()); |
| 549 // (-1, -1) will be used if the HistoryItem is an older version prior to hav
ing | 540 // (-1, -1) will be used if the HistoryItem is an older version prior to hav
ing |
| 550 // pinch viewport scroll offset. | 541 // pinch viewport scroll offset. |
| 551 item.setPinchViewportScrollOffset(WebFloatPoint(-1, -1)); | 542 item.setPinchViewportScrollOffset(WebFloatPoint(-1, -1)); |
| 552 item.setScrollOffset(WebPoint(120, 180)); | 543 item.setScrollOffset(WebPoint(120, 180)); |
| 553 item.setPageScaleFactor(2); | 544 item.setPageScaleFactor(2); |
| 554 | 545 |
| 555 webViewImpl()->mainFrame()->loadHistoryItem(item, WebHistoryDifferentDocumen
tLoad, WebURLRequest::UseProtocolCachePolicy); | 546 FrameTestHelpers::loadHistoryItem(webViewImpl()->mainFrame(), item, WebHisto
ryDifferentDocumentLoad, WebURLRequest::UseProtocolCachePolicy); |
| 556 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(); | |
| 557 | 547 |
| 558 PinchViewport& pinchViewport = frame()->page()->frameHost().pinchViewport(); | 548 PinchViewport& pinchViewport = frame()->page()->frameHost().pinchViewport(); |
| 559 EXPECT_EQ(2, pinchViewport.scale()); | 549 EXPECT_EQ(2, pinchViewport.scale()); |
| 560 EXPECT_POINT_EQ(IntPoint(100, 150), frame()->view()->scrollPosition()); | 550 EXPECT_POINT_EQ(IntPoint(100, 150), frame()->view()->scrollPosition()); |
| 561 EXPECT_FLOAT_POINT_EQ(FloatPoint(20, 30), pinchViewport.visibleRect().locati
on()); | 551 EXPECT_FLOAT_POINT_EQ(FloatPoint(20, 30), pinchViewport.visibleRect().locati
on()); |
| 562 } | 552 } |
| 563 | 553 |
| 564 } // namespace | 554 } // namespace |
| OLD | NEW |