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

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

Issue 1507373003: Clean up attributes of image elements (Closed) Base URL: git@github.com:chromium/dom-distiller.git@master
Patch Set: add todos Created 5 years 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
« no previous file with comments | « javatests/org/chromium/distiller/ContentExtractorTest.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 241
242 assertEquals(11, contentNodes.size()); 242 assertEquals(11, contentNodes.size());
243 } 243 }
244 244
245 public void testMakeAllLinksAbsolute() { 245 public void testMakeAllLinksAbsolute() {
246 final String html = 246 final String html =
247 "<!DOCTYPE html>" + 247 "<!DOCTYPE html>" +
248 "<html><head><base href=\"http://example.com/\"></head><body>" + 248 "<html><head><base href=\"http://example.com/\"></head><body>" +
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 "<video src=\"video\" poster=\"poster\">" + 252 "<video src=\"video\" poster=\"poster\">" +
252 "<source src=\"source\">" + 253 "<source src=\"source\">" +
253 "<track src=\"track\"></track>" + 254 "<track src=\"track\"></track>" +
254 "</video>" + 255 "</video>" +
255 "</body></html>"; 256 "</body></html>";
256 257
257 final String expected = 258 final String expected =
258 "<a href=\"http://example.com/link\"></a>" + 259 "<a href=\"http://example.com/link\"></a>" +
259 "<img src=\"http://example.com/image\" " + 260 "<img src=\"http://example.com/image\" " +
260 "srcset=\"http://example.com/image200 200w, http://example.com/ima ge400 400w\">" + 261 "srcset=\"http://example.com/image200 200w, http://example.com/ima ge400 400w\">" +
262 "<img src=\"http://example.com/image2\">" +
261 "<video src=\"http://example.com/video\" poster=\"http://example.com /poster\">" + 263 "<video src=\"http://example.com/video\" poster=\"http://example.com /poster\">" +
262 "<source src=\"http://example.com/source\">" + 264 "<source src=\"http://example.com/source\">" +
263 "<track src=\"http://example.com/track\"></track>" + 265 "<track src=\"http://example.com/track\"></track>" +
264 "</video>"; 266 "</video>";
265 267
266 Document doc = DomUtil.createHTMLDocument(Document.get()); 268 Document doc = DomUtil.createHTMLDocument(Document.get());
267 Element root = doc.getDocumentElement(); 269 Element root = doc.getDocumentElement();
268 root.setInnerHTML(html); 270 root.setInnerHTML(html);
269 DomUtil.makeAllLinksAbsolute(root); 271 DomUtil.makeAllLinksAbsolute(root);
270 assertEquals(expected, doc.getBody().getInnerHTML()); 272 assertEquals(expected, doc.getBody().getInnerHTML());
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 "<td>text</td>" + 340 "<td>text</td>" +
339 "<td>text</td>" + 341 "<td>text</td>" +
340 "</tr>" + 342 "</tr>" +
341 "</tbody>" + 343 "</tbody>" +
342 "</table>"; 344 "</table>";
343 345
344 mBody.setInnerHTML(html); 346 mBody.setInnerHTML(html);
345 DomUtil.stripStyleAttributes(mBody); 347 DomUtil.stripStyleAttributes(mBody);
346 assertEquals(expected, mBody.getInnerHTML()); 348 assertEquals(expected, mBody.getInnerHTML());
347 } 349 }
350
351 public void testStripImageElements() {
352 String html =
353 "<img id=\"a\" alt=\"alt\" dir=\"rtl\" title=\"t\" style=\"typo\" al ign=\"left\"" +
354 "src=\"image\" class=\"a\" srcset=\"image200 200w\" data-dum my=\"a\">" +
355 "<img mulformed=\"nothing\" data-empty data-dup=\"1\" data-dup=\"2\" " +
356 "src=\"image\" src=\"second\">";
357
358 final String expected =
359 "<img alt=\"alt\" dir=\"rtl\" title=\"t\" src=\"image\" srcset=\"ima ge200 200w\">" +
360 "<img src=\"image\">";
361
362 mBody.setInnerHTML(html);
363 DomUtil.stripImageElements(Node.as(mBody));
364 assertEquals(expected, mBody.getInnerHTML());
365 }
348 } 366 }
OLDNEW
« no previous file with comments | « javatests/org/chromium/distiller/ContentExtractorTest.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698