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

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

Issue 2504573002: Don't call isURLAllowed() from layout. (Closed)
Patch Set: Fix bad formatting that caused clang-format-diff to get confused. 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/LayoutTestHelper.h" 5 #include "core/layout/LayoutTestHelper.h"
6 #include "core/layout/LayoutView.h" 6 #include "core/layout/LayoutView.h"
7 #include "core/layout/PaintInvalidationState.h" 7 #include "core/layout/PaintInvalidationState.h"
8 #include "core/paint/PaintLayer.h" 8 #include "core/paint/PaintLayer.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 leaf->mapToVisualRectInAncestorSpace(container, rect, EdgeInclusive)); 117 leaf->mapToVisualRectInAncestorSpace(container, rect, EdgeInclusive));
118 rect.move(-container->scrolledContentOffset()); 118 rect.move(-container->scrolledContentOffset());
119 EXPECT_EQ(rect, LayoutRect(0, 10, 80, 0)); 119 EXPECT_EQ(rect, LayoutRect(0, 10, 80, 0));
120 } 120 }
121 121
122 TEST_F(VisualRectMappingTest, LayoutView) { 122 TEST_F(VisualRectMappingTest, LayoutView) {
123 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); 123 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com"));
124 setBodyInnerHTML( 124 setBodyInnerHTML(
125 "<style>body { margin: 0; }</style>" 125 "<style>body { margin: 0; }</style>"
126 "<div id=frameContainer>" 126 "<div id=frameContainer>"
127 " <iframe id=frame src='http://test.com' width='50' height='50' " 127 " <iframe src='http://test.com' width='50' height='50' "
128 "frameBorder='0'></iframe>" 128 "frameBorder='0'></iframe>"
129 "</div>"); 129 "</div>");
130 130 setChildFrameHTML(
131 Document& frameDocument = setupChildIframe(
132 "frame",
133 "<style>body { margin: 0; }</style><span><img style='width: 20px; " 131 "<style>body { margin: 0; }</style><span><img style='width: 20px; "
134 "height: 100px'></span>text text text"); 132 "height: 100px'></span>text text text");
133
135 document().view()->updateAllLifecyclePhases(); 134 document().view()->updateAllLifecyclePhases();
136 135
137 LayoutBlock* frameContainer = 136 LayoutBlock* frameContainer =
138 toLayoutBlock(getLayoutObjectByElementId("frameContainer")); 137 toLayoutBlock(getLayoutObjectByElementId("frameContainer"));
139 LayoutBlock* frameBody = toLayoutBlock(frameDocument.body()->layoutObject()); 138 LayoutBlock* frameBody =
139 toLayoutBlock(childDocument().body()->layoutObject());
140 LayoutText* frameText = toLayoutText(frameBody->lastChild()); 140 LayoutText* frameText = toLayoutText(frameBody->lastChild());
141 141
142 // This case involves clipping: frame height is 50, y-coordinate of result 142 // This case involves clipping: frame height is 50, y-coordinate of result
143 // rect is 13, so height should be clipped to (50 - 13) == 37. 143 // rect is 13, so height should be clipped to (50 - 13) == 37.
144 frameDocument.view()->setScrollOffset(ScrollOffset(0, 47), 144 childDocument().view()->setScrollOffset(ScrollOffset(0, 47),
145 ProgrammaticScroll); 145 ProgrammaticScroll);
146 LayoutRect originalRect(4, 60, 20, 80); 146 LayoutRect originalRect(4, 60, 20, 80);
147 LayoutRect rect = originalRect; 147 LayoutRect rect = originalRect;
148 EXPECT_TRUE(frameText->mapToVisualRectInAncestorSpace(frameContainer, rect)); 148 EXPECT_TRUE(frameText->mapToVisualRectInAncestorSpace(frameContainer, rect));
149 EXPECT_EQ(rect, LayoutRect(4, 13, 20, 37)); 149 EXPECT_EQ(rect, LayoutRect(4, 13, 20, 37));
150 150
151 rect = originalRect; 151 rect = originalRect;
152 EXPECT_TRUE(frameText->mapToVisualRectInAncestorSpace(&layoutView(), rect)); 152 EXPECT_TRUE(frameText->mapToVisualRectInAncestorSpace(&layoutView(), rect));
153 EXPECT_EQ(rect, LayoutRect(4, 13, 20, 37)); 153 EXPECT_EQ(rect, LayoutRect(4, 13, 20, 37));
154 checkPaintInvalidationStateRectMapping(rect, originalRect, *frameText, 154 checkPaintInvalidationStateRectMapping(rect, originalRect, *frameText,
155 layoutView(), layoutView()); 155 layoutView(), layoutView());
156 156
157 rect = LayoutRect(4, 60, 0, 80); 157 rect = LayoutRect(4, 60, 0, 80);
158 EXPECT_TRUE(frameText->mapToVisualRectInAncestorSpace(frameContainer, rect, 158 EXPECT_TRUE(frameText->mapToVisualRectInAncestorSpace(frameContainer, rect,
159 EdgeInclusive)); 159 EdgeInclusive));
160 EXPECT_EQ(rect, LayoutRect(4, 13, 0, 37)); 160 EXPECT_EQ(rect, LayoutRect(4, 13, 0, 37));
161 } 161 }
162 162
163 TEST_F(VisualRectMappingTest, LayoutViewSubpixelRounding) { 163 TEST_F(VisualRectMappingTest, LayoutViewSubpixelRounding) {
164 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); 164 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com"));
165 setBodyInnerHTML( 165 setBodyInnerHTML(
166 "<style>body { margin: 0; }</style>" 166 "<style>body { margin: 0; }</style>"
167 "<div id=frameContainer style='position: relative; left: 0.5px'>" 167 "<div id=frameContainer style='position: relative; left: 0.5px'>"
168 " <iframe id=frame style='position: relative; left: 0.5px' " 168 " <iframe style='position: relative; left: 0.5px' "
169 "src='http://test.com' width='200' height='200' frameBorder='0'></iframe>" 169 "src='http://test.com' width='200' height='200' frameBorder='0'></iframe>"
170 "</div>"); 170 "</div>");
171 171 setChildFrameHTML(
172 Document& frameDocument = setupChildIframe(
173 "frame",
174 "<style>body { margin: 0; }</style><div id='target' style='position: " 172 "<style>body { margin: 0; }</style><div id='target' style='position: "
175 "relative; width: 100px; height: 100px; left: 0.5px'>"); 173 "relative; width: 100px; height: 100px; left: 0.5px'>");
174
176 document().view()->updateAllLifecyclePhases(); 175 document().view()->updateAllLifecyclePhases();
177 176
178 LayoutBlock* frameContainer = 177 LayoutBlock* frameContainer =
179 toLayoutBlock(getLayoutObjectByElementId("frameContainer")); 178 toLayoutBlock(getLayoutObjectByElementId("frameContainer"));
180 LayoutObject* target = frameDocument.getElementById("target")->layoutObject(); 179 LayoutObject* target =
180 childDocument().getElementById("target")->layoutObject();
181 LayoutRect rect(0, 0, 100, 100); 181 LayoutRect rect(0, 0, 100, 100);
182 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(frameContainer, rect)); 182 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(frameContainer, rect));
183 // When passing from the iframe to the parent frame, the rect of (0.5, 0, 100, 183 // When passing from the iframe to the parent frame, the rect of (0.5, 0, 100,
184 // 100) is expanded to (0, 0, 100, 100), and then offset by the 0.5 offset of 184 // 100) is expanded to (0, 0, 100, 100), and then offset by the 0.5 offset of
185 // frameContainer. 185 // frameContainer.
186 EXPECT_EQ(LayoutRect(LayoutPoint(DoublePoint(0.5, 0)), LayoutSize(101, 100)), 186 EXPECT_EQ(LayoutRect(LayoutPoint(DoublePoint(0.5, 0)), LayoutSize(101, 100)),
187 rect); 187 rect);
188 } 188 }
189 189
190 TEST_F(VisualRectMappingTest, LayoutViewDisplayNone) { 190 TEST_F(VisualRectMappingTest, LayoutViewDisplayNone) {
191 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); 191 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com"));
192 setBodyInnerHTML( 192 setBodyInnerHTML(
193 "<style>body { margin: 0; }</style>" 193 "<style>body { margin: 0; }</style>"
194 "<div id=frameContainer>" 194 "<div id=frameContainer>"
195 " <iframe id=frame src='http://test.com' width='50' height='50' " 195 " <iframe id='frame' src='http://test.com' width='50' height='50' "
196 "frameBorder='0'></iframe>" 196 "frameBorder='0'></iframe>"
197 "</div>"); 197 "</div>");
198 setChildFrameHTML(
199 "<style>body { margin: 0; }</style><div "
200 "style='width:100px;height:100px;'></div>");
198 201
199 Document& frameDocument =
200 setupChildIframe("frame",
201 "<style>body { margin: 0; }</style><div "
202 "style='width:100px;height:100px;'></div>");
203 document().view()->updateAllLifecyclePhases(); 202 document().view()->updateAllLifecyclePhases();
204 203
205 LayoutBlock* frameContainer = 204 LayoutBlock* frameContainer =
206 toLayoutBlock(getLayoutObjectByElementId("frameContainer")); 205 toLayoutBlock(getLayoutObjectByElementId("frameContainer"));
207 LayoutBlock* frameBody = toLayoutBlock(frameDocument.body()->layoutObject()); 206 LayoutBlock* frameBody =
207 toLayoutBlock(childDocument().body()->layoutObject());
208 LayoutBlock* frameDiv = toLayoutBlock(frameBody->lastChild()); 208 LayoutBlock* frameDiv = toLayoutBlock(frameBody->lastChild());
209 209
210 // This part is copied from the LayoutView test, just to ensure that the 210 // This part is copied from the LayoutView test, just to ensure that the
211 // mapped rect is valid before display:none is set on the iframe. 211 // mapped rect is valid before display:none is set on the iframe.
212 frameDocument.view()->setScrollOffset(ScrollOffset(0, 47), 212 childDocument().view()->setScrollOffset(ScrollOffset(0, 47),
213 ProgrammaticScroll); 213 ProgrammaticScroll);
214 LayoutRect originalRect(4, 60, 20, 80); 214 LayoutRect originalRect(4, 60, 20, 80);
215 LayoutRect rect = originalRect; 215 LayoutRect rect = originalRect;
216 EXPECT_TRUE(frameDiv->mapToVisualRectInAncestorSpace(frameContainer, rect)); 216 EXPECT_TRUE(frameDiv->mapToVisualRectInAncestorSpace(frameContainer, rect));
217 EXPECT_EQ(rect, LayoutRect(4, 13, 20, 37)); 217 EXPECT_EQ(rect, LayoutRect(4, 13, 20, 37));
218 218
219 Element* frameElement = document().getElementById("frame"); 219 Element* frameElement = document().getElementById("frame");
220 frameElement->setInlineStyleProperty(CSSPropertyDisplay, "none"); 220 frameElement->setInlineStyleProperty(CSSPropertyDisplay, "none");
221 document().view()->updateAllLifecyclePhases(); 221 document().view()->updateAllLifecyclePhases();
222 222
223 rect = originalRect; 223 rect = originalRect;
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 LayoutRect targetVisualRect = target->localVisualRect(); 691 LayoutRect targetVisualRect = target->localVisualRect();
692 EXPECT_EQ(LayoutRect(0, 0, 400, 400), targetVisualRect); 692 EXPECT_EQ(LayoutRect(0, 0, 400, 400), targetVisualRect);
693 LayoutRect rect = targetVisualRect; 693 LayoutRect rect = targetVisualRect;
694 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); 694 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect));
695 EXPECT_EQ(LayoutRect(0, 0, 200, 200), rect); 695 EXPECT_EQ(LayoutRect(0, 0, 200, 200), rect);
696 checkPaintInvalidationStateRectMapping(rect, targetVisualRect, *target, 696 checkPaintInvalidationStateRectMapping(rect, targetVisualRect, *target,
697 layoutView(), layoutView()); 697 layoutView(), layoutView());
698 } 698 }
699 699
700 } // namespace blink 700 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698