| OLD | NEW |
| 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; |
| 11 import com.google.gwt.dom.client.Element; | 11 import com.google.gwt.dom.client.Element; |
| 12 import com.google.gwt.dom.client.Node; | 12 import com.google.gwt.dom.client.Node; |
| 13 | 13 |
| 14 import java.util.ArrayList; |
| 14 import java.util.Map; | 15 import java.util.Map; |
| 15 import java.util.List; | 16 import java.util.List; |
| 16 | 17 |
| 17 public class DomUtilTest extends DomDistillerJsTestCase { | 18 public class DomUtilTest extends DomDistillerJsTestCase { |
| 18 public void testGetAttributes() { | 19 public void testGetAttributes() { |
| 19 Element e = Document.get().createDivElement(); | 20 Element e = Document.get().createDivElement(); |
| 20 e.setInnerHTML("<div style=\"width:50px; height:100px\" id=\"f\" class=\
"sdf\"></div>"); | 21 e.setInnerHTML("<div style=\"width:50px; height:100px\" id=\"f\" class=\
"sdf\"></div>"); |
| 21 e = Element.as(e.getChildNodes().getItem(0)); | 22 e = Element.as(e.getChildNodes().getItem(0)); |
| 22 JsArray<Node> jsAttrs = DomUtil.getAttributes(e); | 23 JsArray<Node> jsAttrs = DomUtil.getAttributes(e); |
| 23 assertEquals(3, jsAttrs.length()); | 24 assertEquals(3, jsAttrs.length()); |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 mBody.setInnerHTML(html); | 371 mBody.setInnerHTML(html); |
| 371 for (int i = 0; i < mBody.getChildCount(); i++) { | 372 for (int i = 0; i < mBody.getChildCount(); i++) { |
| 372 DomUtil.stripImageElements(mBody.getChild(i)); | 373 DomUtil.stripImageElements(mBody.getChild(i)); |
| 373 } | 374 } |
| 374 assertEquals(expected, mBody.getInnerHTML()); | 375 assertEquals(expected, mBody.getInnerHTML()); |
| 375 | 376 |
| 376 mBody.setInnerHTML(html); | 377 mBody.setInnerHTML(html); |
| 377 DomUtil.stripImageElements(mBody); | 378 DomUtil.stripImageElements(mBody); |
| 378 assertEquals(expected, mBody.getInnerHTML()); | 379 assertEquals(expected, mBody.getInnerHTML()); |
| 379 } | 380 } |
| 381 |
| 382 public void testJoin() { |
| 383 List<String> wordsToJoin = new ArrayList<String>(); |
| 384 wordsToJoin.add("some"); |
| 385 wordsToJoin.add("words"); |
| 386 wordsToJoin.add("to"); |
| 387 wordsToJoin.add("join"); |
| 388 String result = DomUtil.join(wordsToJoin.toArray(), " - "); |
| 389 String expected = "some - words - to - join"; |
| 390 assertEquals(expected, result); |
| 391 } |
| 392 |
| 393 public void testFormatDuration() { |
| 394 String result = DomUtil.formatDuration("P3Y6M4DT12H30M5S"); |
| 395 String expected = "3 year(s) 6 month(s) 4 day(s) " + |
| 396 "12 hour(s) 30 minute(s) 5 second(s)"; |
| 397 assertEquals(expected,result); |
| 398 |
| 399 result = DomUtil.formatDuration("P23DT23H"); |
| 400 expected = "23 day(s) 23 hour(s)"; |
| 401 assertEquals(expected, result); |
| 402 |
| 403 result = DomUtil.formatDuration("P4Y"); |
| 404 expected = "4 year(s)"; |
| 405 assertEquals(expected, result); |
| 406 |
| 407 result = DomUtil.formatDuration("PT36H"); |
| 408 expected = "36 hour(s)"; |
| 409 assertEquals(expected, result); |
| 410 |
| 411 result = DomUtil.formatDuration("PT15M"); |
| 412 expected = "15 minute(s)"; |
| 413 assertEquals(expected, result); |
| 414 |
| 415 result = DomUtil.formatDuration("P23T23M"); |
| 416 expected = ""; |
| 417 assertEquals(expected,result); |
| 418 |
| 419 result = DomUtil.formatDuration("PT15"); |
| 420 expected = ""; |
| 421 assertEquals(expected, result); |
| 422 |
| 423 result = DomUtil.formatDuration("20M"); |
| 424 expected = ""; |
| 425 assertEquals(expected, result); |
| 426 } |
| 427 |
| 428 |
| 380 } | 429 } |
| OLD | NEW |