1 19 20 33 package org.htmlparser.tests.scannersTests; 34 import org.htmlparser.scanners.StyleScanner; 35 import org.htmlparser.tags.StyleTag; 36 import org.htmlparser.tests.ParserTestCase; 37 import org.htmlparser.util.ParserException; 38 39 public class StyleScannerTest extends ParserTestCase 40 { 41 42 public StyleScannerTest(String name) 43 { 44 super(name); 45 } 46 47 public void testEvaluate() 48 { 49 StyleScanner scanner = new StyleScanner("-s"); 50 boolean retVal = scanner.evaluate("style ", null); 51 assertEquals( 52 "Evaluation of STYLE tag", 53 new Boolean (true), 54 new Boolean (retVal)); 55 } 56 57 public void testScan() 58 { 59 createParser( 60 "<STYLE TYPE=\"text/css\"><!--\n\n" + "</STYLE>", 61 "http://www.yle.fi/"); 62 parser.addScanner(new StyleScanner("-s")); 63 try 64 { 65 parseAndAssertNodeCount(1); 66 assertTrue("Should've thrown exception", false); 67 } 68 catch (ParserException e) 69 { 70 71 } 72 } 73 74 public void testScanBug() throws ParserException 75 { 76 createParser( 77 "<html><head><title>Yahoo!</title><base HREF=http://www.yahoo.com/ target=_top><meta http-equiv=\"PICS-Label\" content='(PICS-1.1 \"http://www.icra.org/ratingsv02.html\" l r (cz 1 lz 1 nz 1 oz 1 vz 1) gen true for \"http://www.yahoo.com\" r (cz 1 lz 1 nz 1 oz 1 vz 1) \"http://www.rsac.org/ratingsv01.html\" l r (n 0 s 0 v 0 l 0) gen true for \"http://www.yahoo.com\" r (n 0 s 0 v 0 l 0))'><style>a.h{background-color:#ffee99}</style></head>", 78 "http://www.google.com/test/index.html"); 79 parser.registerScanners(); 80 parseAndAssertNodeCount(7); 81 assertTrue( 82 "Second last node should be a style tag", 83 node[5] instanceof StyleTag); 84 StyleTag styleTag = (StyleTag) node[5]; 85 assertEquals( 86 "Style Code", 87 "a.h{background-color:#ffee99}", 88 styleTag.getStyleCode()); 89 } 90 91 94 public void testScanBug2() throws ParserException 95 { 96 createParser( 97 "<STYLE TYPE=\"text/css\"><!--\n\n" 98 + "input{font-family: arial, helvetica, sans-serif; font-size:11px;}\n\n" 99 + "i {font-family: times; font-size:10pt; font-weight:normal;}\n\n" 100 + ".ruuhka {font-family: arial, helvetica, sans-serif; font-size:11px;}\n\n" 101 + ".paalinkit {font-family: arial, helvetica, sans-serif; font-size:12px;}\n\n" 102 + ".shortselect{font-family: arial, helvetica, sans-serif; font-size:12px; width:130;}\n\n" 103 + ".cityselect{font-family: arial, helvetica, sans-serif; font-size:11px; width:100;}\n\n" 104 + ".longselect{font-family: arial, helvetica, sans-serif; font-size:12px;}\n\n" 105 + "---></STYLE>", 106 "http://www.yle.fi/"); 107 parser.addScanner(new StyleScanner("-s")); 108 parseAndAssertNodeCount(1); 109 assertTrue(node[0] instanceof StyleTag); 110 } 111 112 115 public void testScanBug3() throws ParserException 116 { 117 createParser( 118 "<html><head><META HTTP-EQUIV=\"content-type\" CONTENT=\"text/html; charset=ISO-8859-1\"><title>Google</title><style><!--\n" 119 + "body,td,a,p,.h{font-family:arial,sans-serif;} .h{font-size: 20px;} .h{color:} .q{text-decoration:none; color:#0000cc;}\n" 120 + "//--></style>", 121 "http://www.yle.fi/"); 122 parser.registerScanners(); 123 parseAndAssertNodeCount(5); 124 assertTrue(node[4] instanceof StyleTag); 125 StyleTag styleTag = (StyleTag) node[4]; 126 String expectedCode = 127 "<!--\r\n" 128 + "body,td,a,p,.h{font-family:arial,sans-serif;} .h{font-size: 20px;} .h{color:} .q{text-decoration:none; color:#0000cc;}\r\n" 129 + "//-->"; 130 assertStringEquals( 131 "Expected Style Code", 132 expectedCode, 133 styleTag.getStyleCode()); 134 } 135 136 } 137 | Popular Tags |