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

Side by Side Diff: javatests/org/chromium/distiller/DomUtilTest.java

Issue 2638823002: Support <picture> in image extraction (Closed)
Patch Set: support lazy loading in <picture> Created 3 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 package org.chromium.distiller; 5 package org.chromium.distiller;
6 6
7 import org.chromium.distiller.webdocument.WebTable; 7 import org.chromium.distiller.webdocument.WebTable;
8 8
9 import com.google.gwt.core.client.JsArray; 9 import com.google.gwt.core.client.JsArray;
10 import com.google.gwt.dom.client.Document; 10 import com.google.gwt.dom.client.Document;
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 243
244 assertEquals(11, contentNodes.size()); 244 assertEquals(11, contentNodes.size());
245 } 245 }
246 246
247 public void testMakeAllLinksAbsolute() { 247 public void testMakeAllLinksAbsolute() {
248 final String html = 248 final String html =
249 "<a href=\"link\"></a>" + 249 "<a href=\"link\"></a>" +
250 "<img src=\"image\" srcset=\"image200 200w, image400 400w\">" + 250 "<img src=\"image\" srcset=\"image200 200w, image400 400w\">" +
251 "<img src=\"image2\">" + 251 "<img src=\"image2\">" +
252 "<video src=\"video\" poster=\"poster\">" + 252 "<video src=\"video\" poster=\"poster\">" +
253 "<source src=\"source\">" + 253 "<source src=\"source\" srcset=\"s2, s3\">" +
254 "<track src=\"track\">" + 254 "<track src=\"track\">" +
255 "</video>"; 255 "</video>";
256 256
257 final String expected = 257 final String expected =
258 "<a href=\"http://example.com/link\"></a>" + 258 "<a href=\"http://example.com/link\"></a>" +
259 "<img src=\"http://example.com/image\" " + 259 "<img src=\"http://example.com/image\" " +
260 "srcset=\"http://example.com/image200 200w, http://example.com/ima ge400 400w\">" + 260 "srcset=\"http://example.com/image200 200w, http://example.com/ima ge400 400w\">" +
261 "<img src=\"http://example.com/image2\">" + 261 "<img src=\"http://example.com/image2\">" +
262 "<video src=\"http://example.com/video\" poster=\"http://example.com /poster\">" + 262 "<video src=\"http://example.com/video\" poster=\"http://example.com /poster\">" +
263 "<source src=\"http://example.com/source\">" + 263 "<source src=\"http://example.com/source\" " +
264 "srcset=\"http://example.com/s2, http://example.com/s3\">" +
264 "<track src=\"http://example.com/track\">" + 265 "<track src=\"http://example.com/track\">" +
265 "</video>"; 266 "</video>";
266 267
267 mHead.setInnerHTML("<base href=\"http://example.com/\">"); 268 mHead.setInnerHTML("<base href=\"http://example.com/\">");
268 mBody.setInnerHTML(html); 269 mBody.setInnerHTML(html);
269 270
270 mBody.setInnerHTML(html); 271 mBody.setInnerHTML(html);
271 for (int i = 0; i < mBody.getChildCount(); i++) { 272 for (int i = 0; i < mBody.getChildCount(); i++) {
272 DomUtil.makeAllLinksAbsolute(mBody.getChild(i)); 273 DomUtil.makeAllLinksAbsolute(mBody.getChild(i));
273 } 274 }
274 assertEquals(expected, mBody.getInnerHTML()); 275 assertEquals(expected, mBody.getInnerHTML());
275 } 276 }
276 277
277 public void testGetSrcSetUrls() { 278 public void testGetSrcSetUrls() {
278 String html = 279 String html =
279 "<img src=\"http://example.com/image\" " + 280 "<img src=\"http://example.com/image\" " +
280 "srcset=\"http://example.com/image200 200w, http://example.com/ima ge400 400w\">"; 281 "srcset=\"http://example.com/image200 200w, http://example.com/ima ge400 400w\">";
281 282
282 mBody.setInnerHTML(html); 283 mBody.setInnerHTML(html);
283 List<String> list = DomUtil.getSrcSetUrls((ImageElement) mBody.getChild( 0)); 284 List<String> list = DomUtil.getSrcSetUrls((ImageElement) mBody.getChild( 0));
284 assertEquals(2, list.size()); 285 assertEquals(2, list.size());
285 assertEquals("http://example.com/image200", list.get(0)); 286 assertEquals("http://example.com/image200", list.get(0));
286 assertEquals("http://example.com/image400", list.get(1)); 287 assertEquals("http://example.com/image400", list.get(1));
287 } 288 }
288 289
290 public void testGetAllSrcSetUrls() {
291 String html =
292 "<picture>" +
293 "<source srcset=\"image200 200w, //example.org/image400 400w\">" +
294 "<source srcset=\"image100 100w, //example.org/image300 300w\">" +
295 "<img>" +
296 "</picture>";
297 Element container = Document.get().createDivElement();
298 container.setInnerHTML(html);
299 List<String> urls = DomUtil.getAllSrcSetUrls(container);
300 assertEquals(4, urls.size());
301 assertEquals("image200", urls.get(0));
302 assertEquals("//example.org/image400", urls.get(1));
303 assertEquals("image100", urls.get(2));
304 assertEquals("//example.org/image300", urls.get(3));
305 }
306
289 public void testStripTableBackgroundColorAttributes() { 307 public void testStripTableBackgroundColorAttributes() {
290 String tableWithBGColorHTML = 308 String tableWithBGColorHTML =
291 "<table bgcolor=\"red\">" + 309 "<table bgcolor=\"red\">" +
292 "<tbody>" + 310 "<tbody>" +
293 "<tr bgcolor=\"red\">" + 311 "<tr bgcolor=\"red\">" +
294 "<th bgcolor=\"red\">text</th>" + 312 "<th bgcolor=\"red\">text</th>" +
295 "<th bgcolor=\"red\">text</th>" + 313 "<th bgcolor=\"red\">text</th>" +
296 "</tr><tr bgcolor=\"red\">" + 314 "</tr><tr bgcolor=\"red\">" +
297 "<td bgcolor=\"red\">text</td>" + 315 "<td bgcolor=\"red\">text</td>" +
298 "<td bgcolor=\"red\">text</td>" + 316 "<td bgcolor=\"red\">text</td>" +
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 element = element.getNextSiblingElement(); 673 element = element.getNextSiblingElement();
656 assertEquals(300*200, DomUtil.getArea(element)); 674 assertEquals(300*200, DomUtil.getArea(element));
657 675
658 element = element.getNextSiblingElement(); 676 element = element.getNextSiblingElement();
659 assertEquals(400*100, DomUtil.getArea(element)); 677 assertEquals(400*100, DomUtil.getArea(element));
660 678
661 element = element.getFirstChildElement(); 679 element = element.getFirstChildElement();
662 assertEquals(400*100, DomUtil.getArea(element)); 680 assertEquals(400*100, DomUtil.getArea(element));
663 } 681 }
664 } 682 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698