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(); | |
bokan
2015/06/04 14:45:44
Nit: I don't think you need these layout calls.
MuVen
2015/06/04 17:58:56
Done.
| |
7496 | |
7497 // Calculation of accumulatedRootOverscroll and unusedDelta on multiple scro llUpdate. | |
7498 ScrollBegin(&webViewHelper); | |
7499 ScrollUpdate(&webViewHelper, -308, -316); | |
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); | |
bokan
2015/06/04 14:45:44
Shouldn't these be non-0 now that the unusedDelta
MuVen
2015/06/04 17:58:56
Done.
| |
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 due to which OverscrollWebViewClient retains l ast | |
7512 // UnusedDelta and AccumulatedRootOverscroll values. | |
bokan
2015/06/04 14:45:44
We should use the GMock in these tests, it'll make
MuVen
2015/06/04 17:58:56
Done.
| |
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 | |
bokan
2015/06/04 14:45:44
I would add another overscroll here to make sure t
MuVen
2015/06/04 17:58:56
Done.
| |
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); | |
bokan
2015/06/04 14:45:44
This is tested in the below test. You should keep
MuVen
2015/06/04 17:58:56
Done.
| |
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 // Overscroll is reported. | |
7552 ScrollUpdate(&webViewHelper, 0, -2); | |
7553 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 1), client.m_unusedDelta); | |
7554 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 1), client.m_accumulatedRootOverScr oll); | |
7555 | |
7556 // Now On Scrolling DIV, scroll is bubbled and root layer is over-scrolled. | |
7557 ScrollUpdate(&webViewHelper, 0, -100); | |
7558 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 100), client.m_unusedDelta); | |
7559 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 101), client.m_accumulatedRootOverS croll); | |
7560 | |
7561 // Page scrolls vertically, but over-scrolls horizontally. | |
7562 ScrollUpdate(&webViewHelper, 100, 50); | |
7563 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(-100, 0), client.m_unusedDelta); | |
7564 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(-100, 0), client.m_accumulatedRootOver Scroll); | |
7565 | |
7566 // Scrolling up, Overscroll is not reported, so client retains last UnusedDe lta and AccumulatedRootOverscroll values. | |
7567 ScrollUpdate(&webViewHelper, 0, -50); | |
7568 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(-100, 0), client.m_unusedDelta); | |
7569 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(-100, 0), client.m_accumulatedRootOver Scroll); | |
7570 | |
7571 // Page scrolls horizontally, but over-scrolls vertically. | |
7572 ScrollUpdate(&webViewHelper, -100, -100); | |
7573 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 100), client.m_unusedDelta); | |
7574 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 100), client.m_accumulatedRootOverS croll); | |
7575 } | |
7576 | |
7577 TEST_F(WebFrameOverscrollTest, RootLayerOverscrolledOnInnerDivOverScroll) | |
7578 { | |
7579 OverscrollWebViewClient client; | |
7580 registerMockedHttpURLLoad("overscroll/div-overscroll.html"); | |
7581 FrameTestHelpers::WebViewHelper webViewHelper; | |
7582 WebViewImpl* webViewImpl = webViewHelper.initializeAndLoad(m_baseURL + "over scroll/div-overscroll.html", true, 0, &client, configureAndroid); | |
7583 webViewImpl->layout(); | |
7584 | |
7585 ScrollBegin(&webViewHelper); | |
7586 | |
7587 // Scroll the Div to the end. | |
7588 ScrollUpdate(&webViewHelper, 0, -316); | |
7589 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_unusedDelta); | |
7590 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_accumulatedRootOverScr oll); | |
7591 | |
7592 // Now On Scrolling DIV, scroll is bubbled and root layer is over-scrolled. | |
7593 ScrollUpdate(&webViewHelper, 0, -50); | |
7594 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 50), client.m_unusedDelta); | |
7595 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 50), client.m_accumulatedRootOverSc roll); | |
7596 } | |
7597 | |
7598 TEST_F(WebFrameOverscrollTest, RootLayerOverscrolledOnInnerIFrameOverScroll) | |
7599 { | |
7600 OverscrollWebViewClient client; | |
7601 registerMockedHttpURLLoad("overscroll/iframe-overscroll.html"); | |
7602 registerMockedHttpURLLoad("overscroll/scrollable-iframe.html"); | |
7603 FrameTestHelpers::WebViewHelper webViewHelper; | |
7604 WebViewImpl* webViewImpl = webViewHelper.initializeAndLoad(m_baseURL + "over scroll/iframe-overscroll.html", true, 0, &client, configureAndroid); | |
7605 webViewImpl->layout(); | |
7606 | |
7607 ScrollBegin(&webViewHelper); | |
7608 | |
7609 // Scroll the IFrame to the end. | |
7610 ScrollUpdate(&webViewHelper, 0, -320); | |
7611 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_unusedDelta); | |
7612 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_accumulatedRootOverScr oll); | |
7613 | |
7614 // Now On Scrolling IFrame, scroll is bubbled and root layer is over-scrolle d. | |
7615 ScrollUpdate(&webViewHelper, 0, -50); | |
7616 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 50), client.m_unusedDelta); | |
7617 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 50), client.m_accumulatedRootOverSc roll); | |
7618 } | |
7619 | |
7620 TEST_F(WebFrameOverscrollTest, NoOverscrollOnNonScrollableaxes) | |
7621 { | |
7622 OverscrollWebViewClient client; | |
7623 registerMockedHttpURLLoad("overscroll/no-overscroll-on-nonscrollable-axes.ht ml"); | |
7624 FrameTestHelpers::WebViewHelper webViewHelper; | |
7625 WebViewImpl* webViewImpl = webViewHelper.initializeAndLoad(m_baseURL + "over scroll/no-overscroll-on-nonscrollable-axes.html", true, 0, &client, configureAnd roid); | |
7626 webViewImpl->layout(); | |
7627 | |
7628 // Overscroll is not reported in all the directions. | |
7629 ScrollBegin(&webViewHelper); | |
7630 ScrollUpdate(&webViewHelper, 0, -1); | |
7631 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_unusedDelta); | |
7632 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_accumulatedRootOverScr oll); | |
7633 | |
7634 ScrollUpdate(&webViewHelper, 0, 1); | |
7635 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_unusedDelta); | |
7636 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_accumulatedRootOverScr oll); | |
7637 | |
7638 ScrollUpdate(&webViewHelper, 1, 0); | |
7639 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_unusedDelta); | |
7640 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_accumulatedRootOverScr oll); | |
7641 | |
7642 ScrollUpdate(&webViewHelper, -1, 0); | |
7643 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_unusedDelta); | |
7644 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_accumulatedRootOverScr oll); | |
7645 | |
7646 ScrollUpdate(&webViewHelper, 1, 1); | |
7647 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_unusedDelta); | |
7648 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_accumulatedRootOverScr oll); | |
7649 | |
7650 ScrollUpdate(&webViewHelper, -1, 1); | |
7651 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_unusedDelta); | |
7652 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_accumulatedRootOverScr oll); | |
7653 | |
7654 ScrollUpdate(&webViewHelper, 1, -1); | |
7655 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_unusedDelta); | |
7656 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_accumulatedRootOverScr oll); | |
7657 | |
7658 ScrollUpdate(&webViewHelper, -1, -1); | |
7659 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_unusedDelta); | |
7660 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_accumulatedRootOverScr oll); | |
7661 | |
7662 ScrollEnd(&webViewHelper); | |
7663 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_unusedDelta); | |
7664 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, 0), client.m_accumulatedRootOverScr oll); | |
7665 } | |
7666 | |
7667 TEST_F(WebFrameOverscrollTest, ScaledPageRootLayerOverscrolled) | |
bokan
2015/06/04 14:45:43
Awesome, thanks for testing under page scale :)
MuVen
2015/06/04 17:58:56
Thanks to majidvp :)
| |
7668 { | |
7669 OverscrollWebViewClient client; | |
7670 registerMockedHttpURLLoad("overscroll/overscroll.html"); | |
7671 FrameTestHelpers::WebViewHelper webViewHelper; | |
7672 WebViewImpl* webViewImpl = webViewHelper.initializeAndLoad(m_baseURL + "over scroll/overscroll.html", true, 0, &client, configureAndroid); | |
7673 webViewImpl->setPageScaleFactor(3.f); | |
7674 webViewImpl->layout(); | |
7675 | |
7676 // Calculation of accumulatedRootOverscroll and unusedDelta on scaled page. | |
7677 ScrollBegin(&webViewHelper); | |
7678 ScrollUpdate(&webViewHelper, 0, 30); | |
7679 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, -10), client.m_unusedDelta); | |
7680 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, -10), client.m_accumulatedRootOverS croll); | |
7681 | |
7682 ScrollUpdate(&webViewHelper, 0, 30); | |
7683 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, -10), client.m_unusedDelta); | |
7684 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(0, -20), client.m_accumulatedRootOverS croll); | |
7685 | |
7686 ScrollUpdate(&webViewHelper, 30, 30); | |
7687 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(-10, -10), client.m_unusedDelta); | |
7688 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(-10, -30), client.m_accumulatedRootOve rScroll); | |
7689 | |
7690 ScrollUpdate(&webViewHelper, 30, 0); | |
7691 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(-10, 0), client.m_unusedDelta); | |
7692 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(-20, -30), client.m_accumulatedRootOve rScroll); | |
7693 | |
7694 // Overscroll is not reported, so client retains last UnusedDelta and Accumu latedRootOverscroll values. | |
7695 ScrollEnd(&webViewHelper); | |
7696 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(-10, 0), client.m_unusedDelta); | |
7697 EXPECT_WEB_FLOAT_SIZE_EQ(WebFloatSize(-20, -30), client.m_accumulatedRootOve rScroll); | |
7698 } | |
7699 | |
7440 } // namespace blink | 7700 } // namespace blink |
OLD | NEW |