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

Side by Side Diff: third_party/WebKit/Source/core/page/PrintContextTest.cpp

Issue 1592493002: Fix links in inline continuations in printed PDF (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/page/PrintContext.h" 5 #include "core/page/PrintContext.h"
6 6
7 #include "core/dom/Document.h" 7 #include "core/dom/Document.h"
8 8
9 #include "core/frame/FrameView.h" 9 #include "core/frame/FrameView.h"
10 #include "core/html/HTMLElement.h" 10 #include "core/html/HTMLElement.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 return ts.release(); 121 return ts.release();
122 } 122 }
123 123
124 static String htmlForAnchor(int x, int y, const char* name, const char* text Content) 124 static String htmlForAnchor(int x, int y, const char* name, const char* text Content)
125 { 125 {
126 TextStream ts; 126 TextStream ts;
127 ts << "<a name='" << name << "' style='position: absolute; left: " << x << "px; top: " << y << "px'>" << textContent << "</a>"; 127 ts << "<a name='" << name << "' style='position: absolute; left: " << x << "px; top: " << y << "px'>" << textContent << "</a>";
128 return ts.release(); 128 return ts.release();
129 } 129 }
130 130
131 void testBasicLinkTarget();
132
133 private: 131 private:
134 OwnPtr<DummyPageHolder> m_pageHolder; 132 OwnPtr<DummyPageHolder> m_pageHolder;
135 OwnPtrWillBePersistent<MockPrintContext> m_printContext; 133 OwnPtrWillBePersistent<MockPrintContext> m_printContext;
136 }; 134 };
137 135
138 class PrintContextFrameTest : public PrintContextTest { 136 class PrintContextFrameTest : public PrintContextTest {
139 public: 137 public:
140 PrintContextFrameTest() : PrintContextTest(SingleChildFrameLoaderClient::cre ate()) { } 138 PrintContextFrameTest() : PrintContextTest(SingleChildFrameLoaderClient::cre ate()) { }
141 }; 139 };
142 140
143 #define EXPECT_SKRECT_EQ(expectedX, expectedY, expectedWidth, expectedHeight, ac tualRect) \ 141 #define EXPECT_SKRECT_EQ(expectedX, expectedY, expectedWidth, expectedHeight, ac tualRect) \
144 EXPECT_EQ(expectedX, actualRect.x()); \ 142 EXPECT_EQ(expectedX, actualRect.x()); \
145 EXPECT_EQ(expectedY, actualRect.y()); \ 143 EXPECT_EQ(expectedY, actualRect.y()); \
146 EXPECT_EQ(expectedWidth, actualRect.width()); \ 144 EXPECT_EQ(expectedWidth, actualRect.width()); \
147 EXPECT_EQ(expectedHeight, actualRect.height()); 145 EXPECT_EQ(expectedHeight, actualRect.height());
148 146
149 void PrintContextTest::testBasicLinkTarget() 147 TEST_F(PrintContextTest, LinkTarget)
150 { 148 {
151 MockCanvas canvas; 149 MockCanvas canvas;
152 setBodyInnerHTML(absoluteBlockHtmlForLink(50, 60, 70, 80, "http://www.google .com") 150 setBodyInnerHTML(absoluteBlockHtmlForLink(50, 60, 70, 80, "http://www.google .com")
153 + absoluteBlockHtmlForLink(150, 160, 170, 180, "http://www.google.com#fr agment")); 151 + absoluteBlockHtmlForLink(150, 160, 170, 180, "http://www.google.com#fr agment"));
154 printSinglePage(canvas); 152 printSinglePage(canvas);
155 153
156 const Vector<MockCanvas::Operation>& operations = canvas.recordedOperations( ); 154 const Vector<MockCanvas::Operation>& operations = canvas.recordedOperations( );
157 ASSERT_EQ(2u, operations.size()); 155 ASSERT_EQ(2u, operations.size());
158 EXPECT_EQ(MockCanvas::DrawRect, operations[0].type); 156 EXPECT_EQ(MockCanvas::DrawRect, operations[0].type);
159 EXPECT_SKRECT_EQ(50, 60, 70, 80, operations[0].rect); 157 EXPECT_SKRECT_EQ(50, 60, 70, 80, operations[0].rect);
160 EXPECT_EQ(MockCanvas::DrawRect, operations[1].type); 158 EXPECT_EQ(MockCanvas::DrawRect, operations[1].type);
161 EXPECT_SKRECT_EQ(150, 160, 170, 180, operations[1].rect); 159 EXPECT_SKRECT_EQ(150, 160, 170, 180, operations[1].rect);
162 // We should also check if the annotation is correct but Skia doesn't export
163 // SkAnnotation API.
164 } 160 }
165 161
166 TEST_F(PrintContextTest, LinkTarget) 162 TEST_F(PrintContextTest, LinkTargetUnderAnonymousBlockBeforeBlock)
167 { 163 {
168 testBasicLinkTarget(); 164 MockCanvas canvas;
165 setBodyInnerHTML("<div style='padding-top: 50px'>"
166 + inlineHtmlForLink("http://www.google.com", "<img style='width: 111; he ight: 10'>")
167 + "<div> " + inlineHtmlForLink("http://www.google1.com", "<img style='wi dth: 122; height: 20'>") + "</div>"
168 + "</div>");
169 printSinglePage(canvas);
170 const Vector<MockCanvas::Operation>& operations = canvas.recordedOperations( );
171 ASSERT_EQ(2u, operations.size());
172 EXPECT_EQ(MockCanvas::DrawRect, operations[0].type);
173 EXPECT_SKRECT_EQ(0, 50, 111, 10, operations[0].rect);
174 EXPECT_EQ(MockCanvas::DrawRect, operations[1].type);
175 EXPECT_SKRECT_EQ(0, 60, 122, 20, operations[1].rect);
169 } 176 }
170 177
171 TEST_F(PrintContextTest, LinkTargetComplex) 178 TEST_F(PrintContextTest, LinkTargetContainingABlock)
172 { 179 {
173 MockCanvas canvas; 180 MockCanvas canvas;
174 setBodyInnerHTML("<div>" 181 setBodyInnerHTML("<div style='padding-top: 50px'>"
175 // Link in anonymous block before a block.
176 + inlineHtmlForLink("http://www.google.com", "<img style='width: 111; he ight: 10'>")
177 + "<div> " + inlineHtmlForLink("http://www.google1.com", "<img style='wi dth: 122; height: 20'>") + "</div>"
178 // Link in anonymous block after a block, containing another block
179 + inlineHtmlForLink("http://www.google2.com", "<div style='width:133; he ight: 30'>BLOCK</div>") 182 + inlineHtmlForLink("http://www.google2.com", "<div style='width:133; he ight: 30'>BLOCK</div>")
180 // Link embedded in inlines 183 + "</div>");
181 + "<span><b><i><img style='width: 40px; height: 40px'><br>" 184 printSinglePage(canvas);
185 const Vector<MockCanvas::Operation>& operations = canvas.recordedOperations( );
186 ASSERT_EQ(1u, operations.size());
187 EXPECT_EQ(MockCanvas::DrawRect, operations[0].type);
188 EXPECT_SKRECT_EQ(0, 50, 133, 30, operations[0].rect);
189 }
190
191 TEST_F(PrintContextTest, LinkTargetUnderInInlines)
192 {
193 MockCanvas canvas;
194 setBodyInnerHTML("<span><b><i><img style='width: 40px; height: 40px'><br>"
182 + inlineHtmlForLink("http://www.google3.com", "<img style='width: 144px; height: 40px'>") 195 + inlineHtmlForLink("http://www.google3.com", "<img style='width: 144px; height: 40px'>")
183 + "</i></b></span>" 196 + "</i></b></span>");
184 // Link embedded in relatively positioned inline 197 printSinglePage(canvas);
198 const Vector<MockCanvas::Operation>& operations = canvas.recordedOperations( );
199 ASSERT_EQ(1u, operations.size());
200 EXPECT_EQ(MockCanvas::DrawRect, operations[0].type);
201 EXPECT_SKRECT_EQ(0, 40, 144, 40, operations[0].rect);
202 }
203
204 TEST_F(PrintContextTest, LinkTargetUnderRelativelyPositionedInline)
205 {
206 MockCanvas canvas;
207 setBodyInnerHTML(
185 + "<span style='position: relative; top: 50px; left: 50px'><b><i><img st yle='width: 1px; height: 40px'><br>" 208 + "<span style='position: relative; top: 50px; left: 50px'><b><i><img st yle='width: 1px; height: 40px'><br>"
186 + inlineHtmlForLink("http://www.google3.com", "<img style='width: 155px; height: 50px'>") 209 + inlineHtmlForLink("http://www.google3.com", "<img style='width: 155px; height: 50px'>")
187 + "</i></b></span>" 210 + "</i></b></span>");
188 + "</div>");
189 printSinglePage(canvas); 211 printSinglePage(canvas);
190
191 const Vector<MockCanvas::Operation>& operations = canvas.recordedOperations( ); 212 const Vector<MockCanvas::Operation>& operations = canvas.recordedOperations( );
192 ASSERT_EQ(4u, operations.size()); 213 ASSERT_EQ(1u, operations.size());
193 EXPECT_EQ(MockCanvas::DrawRect, operations[0].type); 214 EXPECT_EQ(MockCanvas::DrawRect, operations[0].type);
194 EXPECT_SKRECT_EQ(0, 0, 111, 10, operations[0].rect); 215 EXPECT_SKRECT_EQ(50, 90, 155, 50, operations[0].rect);
195 EXPECT_EQ(MockCanvas::DrawRect, operations[1].type);
196 EXPECT_SKRECT_EQ(0, 10, 122, 20, operations[1].rect);
197 EXPECT_EQ(MockCanvas::DrawRect, operations[2].type);
198 EXPECT_SKRECT_EQ(0, 100, 144, 40, operations[2].rect);
199 EXPECT_EQ(MockCanvas::DrawRect, operations[3].type);
200 EXPECT_SKRECT_EQ(50, 190, 155, 50, operations[3].rect);
201 } 216 }
202 217
203 TEST_F(PrintContextTest, LinkTargetSvg) 218 TEST_F(PrintContextTest, LinkTargetSvg)
204 { 219 {
205 MockCanvas canvas; 220 MockCanvas canvas;
206 setBodyInnerHTML("<svg width='100' height='100'>" 221 setBodyInnerHTML("<svg width='100' height='100'>"
207 "<a xlink:href='http://www.w3.org'><rect x='20' y='20' width='50' height ='50'/></a>" 222 "<a xlink:href='http://www.w3.org'><rect x='20' y='20' width='50' height ='50'/></a>"
208 "<text x='10' y='90'><a xlink:href='http://www.google.com'><tspan>google </tspan></a></text>" 223 "<text x='10' y='90'><a xlink:href='http://www.google.com'><tspan>google </tspan></a></text>"
209 "</svg>"); 224 "</svg>");
210 printSinglePage(canvas); 225 printSinglePage(canvas);
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 ASSERT_EQ(3u, operations.size()); 323 ASSERT_EQ(3u, operations.size());
309 EXPECT_EQ(MockCanvas::DrawRect, operations[0].type); 324 EXPECT_EQ(MockCanvas::DrawRect, operations[0].type);
310 EXPECT_SKRECT_EQ(50, 60, 70, 80, operations[0].rect); // FIXME: the rect sho uld be clipped. 325 EXPECT_SKRECT_EQ(50, 60, 70, 80, operations[0].rect); // FIXME: the rect sho uld be clipped.
311 EXPECT_EQ(MockCanvas::DrawRect, operations[1].type); 326 EXPECT_EQ(MockCanvas::DrawRect, operations[1].type);
312 EXPECT_SKRECT_EQ(150, 160, 170, 180, operations[1].rect); 327 EXPECT_SKRECT_EQ(150, 160, 170, 180, operations[1].rect);
313 EXPECT_EQ(MockCanvas::DrawRect, operations[2].type); 328 EXPECT_EQ(MockCanvas::DrawRect, operations[2].type);
314 EXPECT_SKRECT_EQ(250, 260, 270, 280, operations[2].rect); 329 EXPECT_SKRECT_EQ(250, 260, 270, 280, operations[2].rect);
315 } 330 }
316 331
317 } // namespace blink 332 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698