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

Side by Side Diff: third_party/WebKit/Source/core/layout/MapCoordinatesTest.cpp

Issue 2504573002: Don't call isURLAllowed() from layout. (Closed)
Patch Set: Fix everything Created 4 years, 1 month 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "core/layout/LayoutInline.h" 5 #include "core/layout/LayoutInline.h"
6 #include "core/layout/LayoutTestHelper.h" 6 #include "core/layout/LayoutTestHelper.h"
7 #include "core/layout/LayoutView.h" 7 #include "core/layout/LayoutView.h"
8 #include "platform/geometry/TransformState.h" 8 #include "platform/geometry/TransformState.h"
9 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h" 9 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 EXPECT_EQ(FloatPoint(), mappedPoint); 677 EXPECT_EQ(FloatPoint(), mappedPoint);
678 678
679 mappedPoint = mapLocalToAncestor(container, view, FloatPoint()); 679 mappedPoint = mapLocalToAncestor(container, view, FloatPoint());
680 EXPECT_EQ(adjustForFrameScroll(FloatPoint(0, 100)), mappedPoint); 680 EXPECT_EQ(adjustForFrameScroll(FloatPoint(0, 100)), mappedPoint);
681 mappedPoint = mapAncestorToLocal(container, view, mappedPoint); 681 mappedPoint = mapAncestorToLocal(container, view, mappedPoint);
682 EXPECT_EQ(FloatPoint(), mappedPoint); 682 EXPECT_EQ(FloatPoint(), mappedPoint);
683 } 683 }
684 684
685 // TODO(chrishtr): add more multi-frame tests. 685 // TODO(chrishtr): add more multi-frame tests.
686 TEST_P(MapCoordinatesTest, FixedPosInIFrameWhenMainFrameScrolled) { 686 TEST_P(MapCoordinatesTest, FixedPosInIFrameWhenMainFrameScrolled) {
687 setChildFrameHTML(
688 "<style>body { margin: 0; } #target { width: 200px; height: 200px; "
689 "position:fixed}</style><div id=target></div>");
690
687 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); 691 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com"));
688 setBodyInnerHTML( 692 setBodyInnerHTML(
689 "<style>body { margin: 0; }</style>" 693 "<style>body { margin: 0; }</style>"
690 "<div style='width: 200; height: 8000px'></div>" 694 "<div style='width: 200; height: 8000px'></div>"
691 "<iframe id=frame src='http://test.com' width='500' height='500' " 695 "<iframe src='http://test.com' width='500' height='500' "
692 "frameBorder='0'>" 696 "frameBorder='0'>"
693 "</iframe>"); 697 "</iframe>");
694 698
695 Document& frameDocument = setupChildIframe(
696 "frame",
697 "<style>body { margin: 0; } #target { width: 200px; height: 200px; "
698 "position:fixed}</style><div id=target></div>");
699
700 document().view()->layoutViewportScrollableArea()->setScrollOffset( 699 document().view()->layoutViewportScrollableArea()->setScrollOffset(
701 ScrollOffset(0.0, 1000), ProgrammaticScroll); 700 ScrollOffset(0.0, 1000), ProgrammaticScroll);
702 document().view()->updateAllLifecyclePhases(); 701 document().view()->updateAllLifecyclePhases();
703 702
704 Element* target = frameDocument.getElementById("target"); 703 Element* target = childDocument().getElementById("target");
705 ASSERT_TRUE(target); 704 ASSERT_TRUE(target);
706 FloatPoint mappedPoint = 705 FloatPoint mappedPoint =
707 mapAncestorToLocal(target->layoutObject(), nullptr, FloatPoint(10, 70), 706 mapAncestorToLocal(target->layoutObject(), nullptr, FloatPoint(10, 70),
708 TraverseDocumentBoundaries); 707 TraverseDocumentBoundaries);
709 708
710 // y = 70 - 8000, since the iframe is offset by 8000px from the main frame. 709 // y = 70 - 8000, since the iframe is offset by 8000px from the main frame.
711 // The scroll is not taken into account because the element is not fixed to 710 // The scroll is not taken into account because the element is not fixed to
712 // the root LayoutView, and the space of the root LayoutView does not include 711 // the root LayoutView, and the space of the root LayoutView does not include
713 // scroll. 712 // scroll.
714 EXPECT_EQ(FloatPoint(10, -7930), adjustForFrameScroll(mappedPoint)); 713 EXPECT_EQ(FloatPoint(10, -7930), adjustForFrameScroll(mappedPoint));
715 } 714 }
716 715
717 TEST_P(MapCoordinatesTest, IFrameTransformed) { 716 TEST_P(MapCoordinatesTest, IFrameTransformed) {
717 setChildFrameHTML(
718 "<style>body { margin: 0; } #target { width: 200px; "
719 "height: 8000px}</style><div id=target></div>");
720
718 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); 721 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com"));
719 setBodyInnerHTML( 722 setBodyInnerHTML(
720 "<style>body { margin: 0; }</style>" 723 "<style>body { margin: 0; }</style>"
721 "<iframe style='transform: scale(2)' id=frame src='http://test.com' " 724 "<iframe style='transform: scale(2)' src='http://test.com' "
722 "width='500' height='500' frameBorder='0'>" 725 "width='500' height='500' frameBorder='0'>"
723 "</iframe>"); 726 "</iframe>");
724 727
725 Document& frameDocument =
726 setupChildIframe("frame",
727 "<style>body { margin: 0; } #target { width: 200px; "
728 "height: 8000px}</style><div id=target></div>");
729
730 document().view()->updateAllLifecyclePhases(); 728 document().view()->updateAllLifecyclePhases();
731 729
732 frameDocument.view()->layoutViewportScrollableArea()->setScrollOffset( 730 childDocument().view()->layoutViewportScrollableArea()->setScrollOffset(
733 ScrollOffset(0.0, 1000), ProgrammaticScroll); 731 ScrollOffset(0.0, 1000), ProgrammaticScroll);
734 frameDocument.view()->updateAllLifecyclePhases(); 732 childDocument().view()->updateAllLifecyclePhases();
735 733
736 Element* target = frameDocument.getElementById("target"); 734 Element* target = childDocument().getElementById("target");
737 ASSERT_TRUE(target); 735 ASSERT_TRUE(target);
738 FloatPoint mappedPoint = 736 FloatPoint mappedPoint =
739 mapAncestorToLocal(target->layoutObject(), nullptr, FloatPoint(200, 200), 737 mapAncestorToLocal(target->layoutObject(), nullptr, FloatPoint(200, 200),
740 TraverseDocumentBoundaries | UseTransforms); 738 TraverseDocumentBoundaries | UseTransforms);
741 739
742 // Derivation: 740 // Derivation:
743 // (200, 200) -> (-50, -50) (Adjust for transform origin of scale, which is 741 // (200, 200) -> (-50, -50) (Adjust for transform origin of scale, which is
744 // at the center of the 500x500 iframe) 742 // at the center of the 500x500 iframe)
745 // (-50, -50) -> (-25, -25) (Divide by 2 to invert the scale) 743 // (-50, -50) -> (-25, -25) (Divide by 2 to invert the scale)
746 // (-25, -25) -> (225, 225) (Add the origin back in) 744 // (-25, -25) -> (225, 225) (Add the origin back in)
747 // (225, 225) -> (225, 1225) (Adjust by scroll offset of y=1000) 745 // (225, 225) -> (225, 1225) (Adjust by scroll offset of y=1000)
748 EXPECT_EQ(FloatPoint(225, 1225), mappedPoint); 746 EXPECT_EQ(FloatPoint(225, 1225), mappedPoint);
749 } 747 }
750 748
751 TEST_P(MapCoordinatesTest, FixedPosInScrolledIFrameWithTransform) { 749 TEST_P(MapCoordinatesTest, FixedPosInScrolledIFrameWithTransform) {
750 setChildFrameHTML(
751 "<style>* { margin: 0; } #target { width: 200px; height: 200px; "
752 "position:fixed}</style><div id=target></div>"
753 "<div style='width: 200; height: 8000px'></div>");
754
752 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); 755 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com"));
753 setBodyInnerHTML( 756 setBodyInnerHTML(
754 "<style>* { margin: 0; }</style>" 757 "<style>* { margin: 0; }</style>"
755 "<div style='position: absolute; left: 0px; top: 0px; width: 1024px; " 758 "<div style='position: absolute; left: 0px; top: 0px; width: 1024px; "
756 "height: 768px; transform-origin: 0 0; transform: scale(0.5, 0.5);'>" 759 "height: 768px; transform-origin: 0 0; transform: scale(0.5, 0.5);'>"
757 " <iframe id='frame' frameborder=0 src='http://test.com' " 760 " <iframe frameborder=0 src='http://test.com' "
758 "class='frame' sandbox='allow-same-origin' width='1024' " 761 "sandbox='allow-same-origin' width='1024' height='768'></iframe>"
759 "height='768'></iframe>"
760 "</div>"); 762 "</div>");
761 763
762 Document& frameDocument = setupChildIframe(
763 "frame",
764 "<style>* { margin: 0; } #target { width: 200px; height: 200px; "
765 "position:fixed}</style><div id=target></div>"
766 "<div style='width: 200; height: 8000px'></div>");
767
768 document().view()->updateAllLifecyclePhases(); 764 document().view()->updateAllLifecyclePhases();
769 frameDocument.view()->layoutViewportScrollableArea()->setScrollOffset( 765 childDocument().view()->layoutViewportScrollableArea()->setScrollOffset(
770 ScrollOffset(0.0, 1000), ProgrammaticScroll); 766 ScrollOffset(0.0, 1000), ProgrammaticScroll);
771 document().view()->updateAllLifecyclePhases(); 767 document().view()->updateAllLifecyclePhases();
772 768
773 Element* target = frameDocument.getElementById("target"); 769 Element* target = childDocument().getElementById("target");
774 ASSERT_TRUE(target); 770 ASSERT_TRUE(target);
775 FloatPoint mappedPoint = 771 FloatPoint mappedPoint =
776 mapAncestorToLocal(target->layoutObject(), nullptr, FloatPoint(0, 0), 772 mapAncestorToLocal(target->layoutObject(), nullptr, FloatPoint(0, 0),
777 UseTransforms | TraverseDocumentBoundaries); 773 UseTransforms | TraverseDocumentBoundaries);
778 774
779 EXPECT_EQ(FloatPoint(0, 0), mappedPoint); 775 EXPECT_EQ(FloatPoint(0, 0), mappedPoint);
780 } 776 }
781 777
782 TEST_P(MapCoordinatesTest, MulticolWithText) { 778 TEST_P(MapCoordinatesTest, MulticolWithText) {
783 setBodyInnerHTML( 779 setBodyInnerHTML(
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after
1559 LayoutUnit::epsilon()); 1555 LayoutUnit::epsilon());
1560 EXPECT_NEAR(50.0, matrix.projectPoint(FloatPoint(100.0, 50.0)).y(), 1556 EXPECT_NEAR(50.0, matrix.projectPoint(FloatPoint(100.0, 50.0)).y(),
1561 LayoutUnit::epsilon()); 1557 LayoutUnit::epsilon());
1562 EXPECT_NEAR(25.0, matrix.projectPoint(FloatPoint(50.0, 100.0)).x(), 1558 EXPECT_NEAR(25.0, matrix.projectPoint(FloatPoint(50.0, 100.0)).x(),
1563 LayoutUnit::epsilon()); 1559 LayoutUnit::epsilon());
1564 EXPECT_NEAR(100.0, matrix.projectPoint(FloatPoint(50.0, 100.0)).y(), 1560 EXPECT_NEAR(100.0, matrix.projectPoint(FloatPoint(50.0, 100.0)).y(),
1565 LayoutUnit::epsilon()); 1561 LayoutUnit::epsilon());
1566 } 1562 }
1567 1563
1568 } // namespace blink 1564 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698