OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 EXPECT_EQ(expected.x(), actual.x()); \ | 145 EXPECT_EQ(expected.x(), actual.x()); \ |
146 EXPECT_EQ(expected.y(), actual.y()); \ | 146 EXPECT_EQ(expected.y(), actual.y()); \ |
147 } while (false) | 147 } while (false) |
148 | 148 |
149 #define EXPECT_FLOAT_POINT_EQ(expected, actual) \ | 149 #define EXPECT_FLOAT_POINT_EQ(expected, actual) \ |
150 do { \ | 150 do { \ |
151 EXPECT_FLOAT_EQ(expected.x(), actual.x()); \ | 151 EXPECT_FLOAT_EQ(expected.x(), actual.x()); \ |
152 EXPECT_FLOAT_EQ(expected.y(), actual.y()); \ | 152 EXPECT_FLOAT_EQ(expected.y(), actual.y()); \ |
153 } while (false) | 153 } while (false) |
154 | 154 |
| 155 #define EXPECT_WEB_FLOAT_SIZE_EQ(expected, actual) \ |
| 156 do { \ |
| 157 EXPECT_FLOAT_EQ(expected.width, actual.width); \ |
| 158 EXPECT_FLOAT_EQ(expected.height, actual.height); \ |
| 159 } while (false) |
| 160 |
155 class WebFrameTest : public ::testing::Test { | 161 class WebFrameTest : public ::testing::Test { |
156 protected: | 162 protected: |
157 WebFrameTest() | 163 WebFrameTest() |
158 : m_baseURL("http://internal.test/") | 164 : m_baseURL("http://internal.test/") |
159 , m_notBaseURL("http://external.test/") | 165 , m_notBaseURL("http://external.test/") |
160 , m_chromeURL("chrome://") | 166 , m_chromeURL("chrome://") |
161 { | 167 { |
162 } | 168 } |
163 | 169 |
164 virtual ~WebFrameTest() | 170 virtual ~WebFrameTest() |
(...skipping 7265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7430 EXPECT_EQ(fourthFrame, parent->lastChild()); | 7436 EXPECT_EQ(fourthFrame, parent->lastChild()); |
7431 | 7437 |
7432 EXPECT_EQ(parent, firstFrame->parent()); | 7438 EXPECT_EQ(parent, firstFrame->parent()); |
7433 EXPECT_EQ(parent, secondFrame->parent()); | 7439 EXPECT_EQ(parent, secondFrame->parent()); |
7434 EXPECT_EQ(parent, thirdFrame->parent()); | 7440 EXPECT_EQ(parent, thirdFrame->parent()); |
7435 EXPECT_EQ(parent, fourthFrame->parent()); | 7441 EXPECT_EQ(parent, fourthFrame->parent()); |
7436 | 7442 |
7437 view->close(); | 7443 view->close(); |
7438 } | 7444 } |
7439 | 7445 |
| 7446 class OverscrollWebViewClient : public FrameTestHelpers::TestWebViewClient { |
| 7447 public: |
| 7448 virtual void didOverscroll(const WebFloatSize& unusedDelta, const WebFloatSi
ze& accumulatedRootOverScroll, const WebFloatPoint& position, const WebFloatSize
& velocity) override |
| 7449 { |
| 7450 m_unusedDelta = unusedDelta; |
| 7451 m_accumulatedRootOverScroll = accumulatedRootOverScroll; |
| 7452 } |
| 7453 |
| 7454 WebFloatSize m_unusedDelta; |
| 7455 WebFloatSize m_accumulatedRootOverScroll; |
| 7456 }; |
| 7457 |
| 7458 class WebFrameOverscrollTest : public WebFrameTest { |
| 7459 protected: |
| 7460 WebGestureEvent generateEvent(WebInputEvent::Type type, int deltaX = 0, int
deltaY = 0) |
| 7461 { |
| 7462 WebGestureEvent event; |
| 7463 event.type = type; |
| 7464 event.x = 100; |
| 7465 event.y = 100; |
| 7466 if (type == WebInputEvent::GestureScrollUpdate) { |
| 7467 event.data.scrollUpdate.deltaX = deltaX; |
| 7468 event.data.scrollUpdate.deltaY = deltaY; |
| 7469 } |
| 7470 return event; |
| 7471 } |
| 7472 |
| 7473 void ScrollBegin(FrameTestHelpers::WebViewHelper* webViewHelper) |
| 7474 { |
| 7475 webViewHelper->webViewImpl()->handleInputEvent(generateEvent(WebInputEve
nt::GestureScrollBegin)); |
| 7476 } |
| 7477 |
| 7478 void ScrollUpdate(FrameTestHelpers::WebViewHelper* webViewHelper, float delt
aX, float deltaY) |
| 7479 { |
| 7480 webViewHelper->webViewImpl()->handleInputEvent(generateEvent(WebInputEve
nt::GestureScrollUpdate, deltaX, deltaY)); |
| 7481 } |
| 7482 |
| 7483 void ScrollEnd(FrameTestHelpers::WebViewHelper* webViewHelper) |
| 7484 { |
| 7485 webViewHelper->webViewImpl()->handleInputEvent(generateEvent(WebInputEve
nt::GestureScrollEnd)); |
| 7486 } |
| 7487 }; |
| 7488 |
| 7489 TEST_F(WebFrameOverscrollTest, AccumulatedRootOverscrollAndUnsedDeltaValuesOnOve
rscroll) |
| 7490 { |
| 7491 OverscrollWebViewClient client; |
| 7492 registerMockedHttpURLLoad("overscroll/overscroll.html"); |
| 7493 FrameTestHelpers::WebViewHelper webViewHelper; |
| 7494 WebViewImpl* webViewImpl = webViewHelper.initializeAndLoad(m_baseURL + "over
scroll/overscroll.html", true, 0, &client, configureAndroid); |
| 7495 webViewImpl->layout(); |
| 7496 |
| 7497 // Calculation of accumulatedRootOverscroll and unusedDelta on multiple scro
llUpdate. |
| 7498 ScrollBegin(&webViewHelper); |
| 7499 ScrollUpdate(&webViewHelper, -400, -400); |
| 7500 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_unusedDelta); |
| 7501 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_accumulatedRootOverScr
oll); |
| 7502 |
| 7503 ScrollUpdate(&webViewHelper, 0, -13); |
| 7504 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 13), client.m_unusedDelta); |
| 7505 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 13), client.m_accumulatedRootOverSc
roll); |
| 7506 |
| 7507 ScrollUpdate(&webViewHelper, -20, -13); |
| 7508 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(20, 13), client.m_unusedDelta); |
| 7509 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(20, 26), client.m_accumulatedRootOverS
croll); |
| 7510 |
| 7511 // Overscroll is not reported for the below scroll gestures, due to which Ov
erscrollWebViewClient |
| 7512 // retains last UnusedDelta and AccumulatedRootOverscroll values. |
| 7513 ScrollUpdate(&webViewHelper, 0, 1); |
| 7514 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(20, 13), client.m_unusedDelta); |
| 7515 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(20, 26), client.m_accumulatedRootOverS
croll); |
| 7516 |
| 7517 ScrollUpdate(&webViewHelper, 1, 0); |
| 7518 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(20, 13), client.m_unusedDelta); |
| 7519 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(20, 26), client.m_accumulatedRootOverS
croll); |
| 7520 |
| 7521 ScrollEnd(&webViewHelper); |
| 7522 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(20, 13), client.m_unusedDelta); |
| 7523 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(20, 26), client.m_accumulatedRootOverS
croll); |
| 7524 } |
| 7525 |
| 7526 TEST_F(WebFrameOverscrollTest, AccumulatedOverscrollAndUnusedDeltaValuesOnDiffer
entAxesOverscroll) |
| 7527 { |
| 7528 OverscrollWebViewClient client; |
| 7529 registerMockedHttpURLLoad("overscroll/div-overscroll.html"); |
| 7530 FrameTestHelpers::WebViewHelper webViewHelper; |
| 7531 WebViewImpl* webViewImpl = webViewHelper.initializeAndLoad(m_baseURL + "over
scroll/div-overscroll.html", true, 0, &client, configureAndroid); |
| 7532 webViewImpl->layout(); |
| 7533 |
| 7534 ScrollBegin(&webViewHelper); |
| 7535 |
| 7536 // Scroll the Div to the end. |
| 7537 ScrollUpdate(&webViewHelper, 0, -316); |
| 7538 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_unusedDelta); |
| 7539 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_accumulatedRootOverScr
oll); |
| 7540 |
| 7541 // Now On Scrolling DIV, scroll is bubbled and root layer is over-scrolled. |
| 7542 ScrollUpdate(&webViewHelper, 0, -50); |
| 7543 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 50), client.m_unusedDelta); |
| 7544 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 50), client.m_accumulatedRootOverSc
roll); |
| 7545 |
| 7546 // Overscroll is not reported, so client retains last UnusedDelta and Accumu
latedRootOverscroll values. |
| 7547 ScrollUpdate(&webViewHelper, 0, 1); |
| 7548 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 50), client.m_unusedDelta); |
| 7549 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 50), client.m_accumulatedRootOverSc
roll); |
| 7550 |
| 7551 ScrollUpdate(&webViewHelper, 0, -50); |
| 7552 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 50), client.m_unusedDelta); |
| 7553 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 50), client.m_accumulatedRootOverSc
roll); |
| 7554 |
| 7555 // Now On Scrolling DIV, scroll is bubbled and root layer is over-scrolled. |
| 7556 ScrollUpdate(&webViewHelper, 0, -100); |
| 7557 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 100), client.m_unusedDelta); |
| 7558 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 100), client.m_accumulatedRootOverS
croll); |
| 7559 |
| 7560 // Page scrolls vertically, but over-scrolls horizontally. |
| 7561 ScrollUpdate(&webViewHelper, 100, 50); |
| 7562 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(-100, 0), client.m_unusedDelta); |
| 7563 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(-100, 0), client.m_accumulatedRootOver
Scroll); |
| 7564 |
| 7565 // Scrolling up, Overscroll is not reported, so client retains last UnusedDe
lta and AccumulatedRootOverscroll values. |
| 7566 ScrollUpdate(&webViewHelper, 0, -50); |
| 7567 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(-100, 0), client.m_unusedDelta); |
| 7568 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(-100, 0), client.m_accumulatedRootOver
Scroll); |
| 7569 |
| 7570 // Page scrolls horizontally, but over-scrolls vertically. |
| 7571 ScrollUpdate(&webViewHelper, -100, -100); |
| 7572 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 100), client.m_unusedDelta); |
| 7573 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 100), client.m_accumulatedRootOverS
croll); |
| 7574 } |
| 7575 |
| 7576 TEST_F(WebFrameOverscrollTest, RootLayerOverscrolledOnInnerDivOverScroll) |
| 7577 { |
| 7578 OverscrollWebViewClient client; |
| 7579 registerMockedHttpURLLoad("overscroll/div-overscroll.html"); |
| 7580 FrameTestHelpers::WebViewHelper webViewHelper; |
| 7581 WebViewImpl* webViewImpl = webViewHelper.initializeAndLoad(m_baseURL + "over
scroll/div-overscroll.html", true, 0, &client, configureAndroid); |
| 7582 webViewImpl->layout(); |
| 7583 |
| 7584 ScrollBegin(&webViewHelper); |
| 7585 |
| 7586 // Scroll the Div to the end. |
| 7587 ScrollUpdate(&webViewHelper, 0, -316); |
| 7588 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_unusedDelta); |
| 7589 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_accumulatedRootOverScr
oll); |
| 7590 |
| 7591 // Now On Scrolling DIV, scroll is bubbled and root layer is over-scrolled. |
| 7592 ScrollUpdate(&webViewHelper, 0, -50); |
| 7593 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 50), client.m_unusedDelta); |
| 7594 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 50), client.m_accumulatedRootOverSc
roll); |
| 7595 } |
| 7596 |
| 7597 TEST_F(WebFrameOverscrollTest, RootLayerOverscrolledOnInnerIFrameOverScroll) |
| 7598 { |
| 7599 OverscrollWebViewClient client; |
| 7600 registerMockedHttpURLLoad("overscroll/iframe-overscroll.html"); |
| 7601 registerMockedHttpURLLoad("overscroll/scrollable-iframe.html"); |
| 7602 FrameTestHelpers::WebViewHelper webViewHelper; |
| 7603 WebViewImpl* webViewImpl = webViewHelper.initializeAndLoad(m_baseURL + "over
scroll/iframe-overscroll.html", true, 0, &client, configureAndroid); |
| 7604 webViewImpl->layout(); |
| 7605 |
| 7606 ScrollBegin(&webViewHelper); |
| 7607 |
| 7608 // Scroll the IFrame to the end. |
| 7609 ScrollUpdate(&webViewHelper, 0, -320); |
| 7610 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_unusedDelta); |
| 7611 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_accumulatedRootOverScr
oll); |
| 7612 |
| 7613 // Now On Scrolling IFrame, scroll is bubbled and root layer is over-scrolle
d. |
| 7614 ScrollUpdate(&webViewHelper, 0, -50); |
| 7615 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 50), client.m_unusedDelta); |
| 7616 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 50), client.m_accumulatedRootOverSc
roll); |
| 7617 } |
| 7618 |
| 7619 TEST_F(WebFrameOverscrollTest, NoOverscrollOnNonScrollableaxes) |
| 7620 { |
| 7621 OverscrollWebViewClient client; |
| 7622 registerMockedHttpURLLoad("overscroll/no-overscroll-on-nonscrollable-axes.ht
ml"); |
| 7623 FrameTestHelpers::WebViewHelper webViewHelper; |
| 7624 WebViewImpl* webViewImpl = webViewHelper.initializeAndLoad(m_baseURL + "over
scroll/no-overscroll-on-nonscrollable-axes.html", true, 0, &client, configureAnd
roid); |
| 7625 webViewImpl->layout(); |
| 7626 |
| 7627 // Overscroll is not reported in all the directions. |
| 7628 ScrollBegin(&webViewHelper); |
| 7629 ScrollUpdate(&webViewHelper, 0, -1); |
| 7630 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_unusedDelta); |
| 7631 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_accumulatedRootOverScr
oll); |
| 7632 |
| 7633 ScrollUpdate(&webViewHelper, 0, 1); |
| 7634 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_unusedDelta); |
| 7635 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_accumulatedRootOverScr
oll); |
| 7636 |
| 7637 ScrollUpdate(&webViewHelper, 1, 0); |
| 7638 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_unusedDelta); |
| 7639 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_accumulatedRootOverScr
oll); |
| 7640 |
| 7641 ScrollUpdate(&webViewHelper, -1, 0); |
| 7642 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_unusedDelta); |
| 7643 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_accumulatedRootOverScr
oll); |
| 7644 |
| 7645 ScrollUpdate(&webViewHelper, 1, 1); |
| 7646 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_unusedDelta); |
| 7647 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_accumulatedRootOverScr
oll); |
| 7648 |
| 7649 ScrollUpdate(&webViewHelper, -1, 1); |
| 7650 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_unusedDelta); |
| 7651 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_accumulatedRootOverScr
oll); |
| 7652 |
| 7653 ScrollUpdate(&webViewHelper, 1, -1); |
| 7654 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_unusedDelta); |
| 7655 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_accumulatedRootOverScr
oll); |
| 7656 |
| 7657 ScrollUpdate(&webViewHelper, -1, -1); |
| 7658 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_unusedDelta); |
| 7659 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_accumulatedRootOverScr
oll); |
| 7660 |
| 7661 ScrollEnd(&webViewHelper); |
| 7662 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_unusedDelta); |
| 7663 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_accumulatedRootOverScr
oll); |
| 7664 } |
| 7665 |
| 7666 TEST_F(WebFrameOverscrollTest, ScaledPageRootLayerOverscrolled) |
| 7667 { |
| 7668 OverscrollWebViewClient client; |
| 7669 registerMockedHttpURLLoad("overscroll/overscroll.html"); |
| 7670 FrameTestHelpers::WebViewHelper webViewHelper; |
| 7671 WebViewImpl* webViewImpl = webViewHelper.initializeAndLoad(m_baseURL + "over
scroll/overscroll.html", true, 0, &client, configureAndroid); |
| 7672 webViewImpl->setPageScaleFactor(3.f); |
| 7673 webViewImpl->layout(); |
| 7674 |
| 7675 // Calculation of accumulatedRootOverscroll and unusedDelta on scaled page. |
| 7676 ScrollBegin(&webViewHelper); |
| 7677 ScrollUpdate(&webViewHelper, 0, 30); |
| 7678 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, -10), client.m_unusedDelta); |
| 7679 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, -10), client.m_accumulatedRootOverS
croll); |
| 7680 |
| 7681 ScrollUpdate(&webViewHelper, 0, 30); |
| 7682 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, -10), client.m_unusedDelta); |
| 7683 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, -20), client.m_accumulatedRootOverS
croll); |
| 7684 |
| 7685 ScrollUpdate(&webViewHelper, 30, 30); |
| 7686 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(-10, -10), client.m_unusedDelta); |
| 7687 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(-10, -30), client.m_accumulatedRootOve
rScroll); |
| 7688 |
| 7689 ScrollUpdate(&webViewHelper, 30, 0); |
| 7690 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(-10, 0), client.m_unusedDelta); |
| 7691 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(-20, -30), client.m_accumulatedRootOve
rScroll); |
| 7692 |
| 7693 // Overscroll is not reported, so client retains last UnusedDelta and Accumu
latedRootOverscroll values. |
| 7694 ScrollEnd(&webViewHelper); |
| 7695 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(-10, 0), client.m_unusedDelta); |
| 7696 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(-20, -30), client.m_accumulatedRootOve
rScroll); |
| 7697 } |
| 7698 |
7440 } // namespace blink | 7699 } // namespace blink |
OLD | NEW |