harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r427121 [18/29] - in /incubator/harmony/enhanced/classlib/trunk/modules/swing: make/ src/main/java/common/javax/swing/ src/main/java/common/javax/swing/text/ src/main/java/common/javax/swing/text/html/ src/main/java/common/javax/swing/text/...
Date Mon, 31 Jul 2006 14:08:55 GMT
Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/HTMLDocument_Reader_ActionsTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/HTMLDocument_Reader_ActionsTest.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/HTMLDocument_Reader_ActionsTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/HTMLDocument_Reader_ActionsTest.java Mon Jul 31 07:08:47 2006
@@ -0,0 +1,1181 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/**
+* @author Alexander T. Simbirtsev
+* @version $Revision$
+*/
+package javax.swing.text.html;
+
+import java.net.URL;
+import java.util.ArrayList;
+
+import javax.swing.text.AttributeSet;
+import javax.swing.text.MutableAttributeSet;
+import javax.swing.text.SimpleAttributeSet;
+import javax.swing.text.Style;
+import javax.swing.text.StyleConstants;
+import javax.swing.text.DefaultStyledDocument.ElementSpec;
+import javax.swing.text.html.HTML.Tag;
+import javax.swing.text.html.HTMLDocument.HTMLReader;
+import javax.swing.text.html.HTMLEditorKit.ParserCallback;
+
+public class HTMLDocument_Reader_ActionsTest extends HTMLDocumentTestCase {
+
+    protected HTMLDocument.HTMLReader reader;
+    protected HTMLDocument doc;
+    protected HTMLDocument.HTMLReader.TagAction action;
+    
+    protected void setUp() throws Exception {
+        super.setUp();
+        doc = new HTMLDocument();
+        reader = (HTMLDocument.HTMLReader)doc.getReader(0);
+    }
+
+    protected void tearDown() throws Exception {
+        action = null;
+        doc = null;
+        reader = null;
+        super.tearDown();
+    }
+
+    public void testHandleSimpleTag_Unknown() {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        
+        doc.setPreservesUnknownTags(true);
+        reader.handleStartTag(Tag.HTML, attr, 0);
+        reader.handleStartTag(Tag.BODY, attr, 0);
+        reader.handleStartTag(Tag.P, attr, 0);
+        assertEquals(3, reader.parseBuffer.size());
+        reader.handleSimpleTag(new Tag("fake"), attr, 0);
+        assertEquals(4, reader.parseBuffer.size());
+    }
+    
+    public void testBlockStart() {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        action = reader.new BlockAction();
+        
+        action.start(Tag.B, attr);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(1, reader.parseBuffer.size());
+        final ElementSpec spec = (ElementSpec)reader.parseBuffer.get(0);
+        final AttributeSet specAttr = spec.getAttributes();
+        assertEquals(2, specAttr.getAttributeCount());
+        checkAttributes(specAttr, StyleConstants.NameAttribute, Tag.B);
+        checkAttributes(specAttr, "aaaa", "bbbb");
+        assertSpec(spec, ElementSpec.StartTagType, ElementSpec.OriginateDirection, 0, null);
+    }
+
+    public void testBlockEnd() {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        action = reader.new BlockAction();
+        
+        action.end(Tag.B);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(1, reader.parseBuffer.size());
+        final ElementSpec spec = (ElementSpec)reader.parseBuffer.get(0);
+        checkEndTagSpec(spec);
+    }
+    
+    public void testCharacterStart() {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        action = reader.new CharacterAction();
+        
+        reader.charAttr.addAttribute("bbbb", "aaaa");
+        action.start(Tag.B, attr);
+        assertEquals(0, reader.parseBuffer.size());
+        assertEquals(2, reader.charAttr.getAttributeCount());
+        checkAttributes(reader.charAttr, "bbbb", "aaaa");
+        checkAttributes(reader.charAttr, Tag.B, attr);
+        reader.popCharacterStyle();
+        assertEquals(1, reader.charAttr.getAttributeCount());
+        checkAttributes(reader.charAttr, "bbbb", "aaaa");
+
+        assertNotSame(reader.charAttr.getAttribute(Tag.B), attr);
+    }
+
+    public void testFontStart() {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute(HTML.Attribute.COLOR, "black");
+        attr.addAttribute(HTML.Attribute.SIZE, isHarmony() ? "1pt" : "1");
+        attr.addAttribute(HTML.Attribute.FACE, "1111");
+        attr.addAttribute("aaaa", "bbbb");
+        
+        reader.charAttr.addAttribute("bbbb", "aaaa");
+        reader.handleStartTag(Tag.HTML, new SimpleAttributeSet(), 0);
+        reader.handleStartTag(Tag.BODY, new SimpleAttributeSet(), 0);
+        reader.handleStartTag(Tag.FONT, attr, 0);
+        assertEquals(5, reader.charAttr.getAttributeCount());
+        assertNotNull(reader.charAttr.getAttribute("bbbb"));
+        assertNotNull(reader.charAttr.getAttribute(Tag.FONT));
+        assertNotNull(reader.charAttr.getAttribute(CSS.Attribute.COLOR));
+        assertNotNull(reader.charAttr.getAttribute(CSS.Attribute.FONT_FAMILY));
+        assertNotNull(reader.charAttr.getAttribute(CSS.Attribute.FONT_SIZE));
+    }
+
+    public void testCharacterStart_vs_HandleStart() {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        action = reader.new CharacterAction();
+        
+        reader.charAttr.addAttribute("bbbb", "aaaa");
+        reader.handleStartTag(Tag.B, attr, 0);
+        assertEquals(0, reader.parseBuffer.size());
+        assertEquals(3, reader.charAttr.getAttributeCount());
+        checkAttributes(reader.charAttr, "bbbb", "aaaa");
+        checkAttributes(reader.charAttr, Tag.B, attr);
+        checkAttributes(reader.charAttr, CSS.Attribute.FONT_WEIGHT, "bold");
+        reader.popCharacterStyle();
+        assertEquals(1, reader.charAttr.getAttributeCount());
+        checkAttributes(reader.charAttr, "bbbb", "aaaa");
+    }
+
+    public void testCharacterEnd() {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        action = reader.new CharacterAction();
+        
+        reader.charAttr.addAttribute("bbbb", "aaaa");
+        reader.pushCharacterStyle();
+        reader.charAttr = null;
+        action.end(Tag.B);
+        assertEquals(0, reader.parseBuffer.size());
+        assertEquals(1, reader.charAttr.getAttributeCount());
+        checkAttributes(reader.charAttr, "bbbb", "aaaa");
+    }
+
+    public void testParagraphStart() {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        action = reader.new ParagraphAction();
+        
+        action.start(Tag.P, attr);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(1, reader.parseBuffer.size());
+        final ElementSpec spec = (ElementSpec)reader.parseBuffer.get(0);
+        final AttributeSet specAttr = spec.getAttributes();
+        assertEquals(2, specAttr.getAttributeCount());
+        checkAttributes(specAttr, StyleConstants.NameAttribute, Tag.P);
+        checkAttributes(specAttr, "aaaa", "bbbb");
+        assertSpec(spec, ElementSpec.StartTagType, ElementSpec.OriginateDirection, 0, null);
+    }
+
+    public void testParagraphEnd() {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        action = reader.new ParagraphAction();
+        
+        action.end(Tag.P);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(1, reader.parseBuffer.size());
+        final ElementSpec spec = (ElementSpec)reader.parseBuffer.get(0);
+        checkEndTagSpec(spec);
+    }
+
+    public void testSpecialStart() {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        action = reader.new SpecialAction();
+        
+        action.start(Tag.IMG, attr);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(2, reader.parseBuffer.size());
+        ElementSpec spec = (ElementSpec)reader.parseBuffer.get(0);
+        AttributeSet specAttr;
+        checkOpenImpliedSpec(spec);
+        spec = (ElementSpec)reader.parseBuffer.get(1);
+        specAttr = spec.getAttributes();
+        assertEquals(2, specAttr.getAttributeCount());
+        checkAttributes(specAttr, StyleConstants.NameAttribute, "img");
+        checkAttributes(specAttr, "aaaa", "bbbb");
+        checkImplicitContentSpec(spec);
+
+        assertEquals(2, attr.getAttributeCount());
+        checkAttributes(attr, StyleConstants.NameAttribute, "img");
+        checkAttributes(attr, "aaaa", "bbbb");
+    }
+
+    public void testAnchorStart() {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        reader.charAttr.addAttribute("bbbb", "aaaa");
+        reader.handleStartTag(Tag.A, attr, 0);
+        assertEquals(0, reader.parseBuffer.size());
+        assertEquals(2, reader.charAttr.getAttributeCount());
+        checkAttributes(reader.charAttr, "bbbb", "aaaa");
+        checkAttributes(reader.charAttr, Tag.A, attr);
+        reader.popCharacterStyle();
+        assertEquals(1, reader.charAttr.getAttributeCount());
+        checkAttributes(reader.charAttr, "bbbb", "aaaa");
+
+        assertNotSame(reader.charAttr.getAttribute(Tag.B), attr);
+    }
+
+    public void testAnchorEnd() {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        
+        reader.handleEndTag(Tag.A, 0);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(0, reader.parseBuffer.size());
+    }
+
+    public void testAnchorStartEnd() {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        final Tag tag = Tag.A;
+        reader.handleStartTag(tag, attr, 0);
+        assertEquals(1, reader.charAttr.getAttributeCount());
+        assertEquals(0, reader.parseBuffer.size());
+        reader.handleEndTag(tag, 0);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(2, reader.parseBuffer.size());
+        assertSpec((ElementSpec)reader.parseBuffer.get(0), ElementSpec.StartTagType, ElementSpec.OriginateDirection, 0, null);
+        checkImplicitContentSpec((ElementSpec)reader.parseBuffer.get(1));
+    }
+
+    public void testAnchorStartTextEnd() {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        attr.addAttribute(HTML.Attribute.HREF, "file:///index.html");
+        final Tag tag = Tag.A;
+        reader.handleStartTag(Tag.BODY, attr, 0);
+        reader.handleStartTag(tag, attr, 0);
+        assertEquals(1, reader.charAttr.getAttributeCount());
+        assertEquals(1, reader.parseBuffer.size());
+        reader.handleText("text".toCharArray(), 0);
+        assertEquals(2, reader.charAttr.getAttributeCount());
+        assertEquals(3, reader.parseBuffer.size());
+        reader.handleEndTag(tag, 0);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(3, reader.parseBuffer.size());
+    }
+
+    public void testSpecialStart_AfterSpecialStart() {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        reader = (HTMLReader)doc.getReader(0, 0, 0, Tag.I);
+        reader.new SpecialAction().start(Tag.I, new SimpleAttributeSet());
+        assertEquals(1, reader.parseBuffer.size());
+        
+        reader.new SpecialAction().start(Tag.IMG, attr);
+        assertEquals(2, reader.parseBuffer.size());
+        ElementSpec spec = (ElementSpec)reader.parseBuffer.get(1);
+        checkAttributes(spec.getAttributes(), StyleConstants.NameAttribute, Tag.IMG);
+        checkImplicitContentSpec(spec);
+    }
+
+    public void testSpecialStart_AfterCharacterStart1() {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        reader = (HTMLReader)doc.getReader(0, 0, 0, Tag.I);
+        reader.new CharacterAction().start(Tag.I, new SimpleAttributeSet());
+        assertEquals(0, reader.parseBuffer.size());
+        assertEquals(1, reader.charAttr.getAttributeCount());
+        
+        reader.new SpecialAction().start(Tag.IMG, attr);
+        assertEquals(1, reader.parseBuffer.size());
+        ElementSpec spec = (ElementSpec)reader.parseBuffer.get(0);
+        checkAttributes(spec.getAttributes(), StyleConstants.NameAttribute, Tag.IMG);
+        checkImplicitContentSpec(spec);
+    }
+
+    public void testSpecialStart_AfterCharacterStart2() {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        reader = (HTMLReader)doc.getReader(10, 10, 10, null);
+        reader.new CharacterAction().start(Tag.I, new SimpleAttributeSet());
+        assertEquals(0, reader.parseBuffer.size());
+        assertEquals(1, reader.charAttr.getAttributeCount());
+        
+        reader.new SpecialAction().start(Tag.IMG, attr);
+        assertEquals(2, reader.parseBuffer.size());
+    }
+
+    public void testFormStart_AfterImplied() {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        action = reader.new FormAction();
+        
+        reader.handleStartTag(Tag.BODY, new SimpleAttributeSet(), 0);
+        reader.handleText("text".toCharArray(), 0);
+        assertEquals(3, reader.parseBuffer.size());
+
+        reader.handleStartTag(Tag.FORM, attr, 0);
+        assertEquals(6, reader.parseBuffer.size());
+        
+        ElementSpec spec = (ElementSpec)reader.parseBuffer.get(3);
+        checkCRSpec(spec);
+        
+        spec = (ElementSpec)reader.parseBuffer.get(4);
+        checkEndTagSpec(spec);
+        
+        spec = (ElementSpec)reader.parseBuffer.get(5);
+        AttributeSet specAttr = spec.getAttributes();
+        assertEquals(2, specAttr.getAttributeCount());
+        checkAttributes(specAttr, StyleConstants.NameAttribute, Tag.FORM);
+        checkAttributes(specAttr, "aaaa", "bbbb");
+        assertSpec(spec, ElementSpec.StartTagType, ElementSpec.OriginateDirection, 0, null);
+
+        assertEquals(2, attr.getAttributeCount());
+        checkAttributes(attr, StyleConstants.NameAttribute, Tag.FORM);
+        checkAttributes(attr, "aaaa", "bbbb");
+    }
+
+    public void testSpecialEnd() {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        HTMLDocument.HTMLReader.TagAction action = reader.new SpecialAction();
+        
+        action.end(Tag.IMG);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(0, reader.parseBuffer.size());
+    }
+
+    public void testSpecialStart_Calls() {
+        final Marker specialMarker = new Marker();
+        doc = new HTMLDocument() {
+            public ParserCallback getReader(int pos) {
+                return new HTMLReader(0) {
+                    protected void addSpecialElement(final Tag tag, final MutableAttributeSet attr) {
+                        specialMarker.setOccurred();
+                        ArrayList callInfo = new ArrayList();
+                        callInfo.add(tag);
+                        callInfo.add(attr);
+                        specialMarker.setAuxiliary(callInfo);
+                    }
+                };
+            }
+        };
+        reader = (HTMLReader)doc.getReader(0);
+        String text = "precontent";
+        Tag tag = Tag.HTML;
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        reader.addSpecialElement(tag, attr);
+        assertTrue(specialMarker.isOccurred());
+        ArrayList callInfo = (ArrayList)specialMarker.getAuxiliary();
+        assertEquals(tag, callInfo.get(0));
+        assertEquals(attr, callInfo.get(1));
+    }
+    
+    public void testPreStart() {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        action = reader.new PreAction();
+        
+        action.start(Tag.PRE, attr);
+        assertEquals(2, reader.parseBuffer.size());
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        ElementSpec spec = (ElementSpec)reader.parseBuffer.get(0);
+        AttributeSet specAttr = spec.getAttributes();
+        assertEquals(2, specAttr.getAttributeCount());
+        checkAttributes(specAttr, StyleConstants.NameAttribute, Tag.PRE);
+        checkAttributes(specAttr, "aaaa", "bbbb");
+        assertSpec(spec, ElementSpec.StartTagType, ElementSpec.OriginateDirection, 0, null);
+
+        spec = (ElementSpec)reader.parseBuffer.get(1);
+        specAttr = spec.getAttributes();
+        assertEquals(3, specAttr.getAttributeCount());
+        checkAttributes(specAttr, StyleConstants.NameAttribute, Tag.IMPLIED);
+        checkAttributes(specAttr, CSS.Attribute.WHITE_SPACE, "pre");
+        checkAttributes(specAttr, "aaaa", "bbbb");
+        assertSpec(spec, ElementSpec.StartTagType, ElementSpec.OriginateDirection, 0, null);
+    }
+    
+    public void testPreStart_InParagraph() {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        action = reader.new PreAction();
+        
+        reader.handleStartTag(Tag.P, attr, 0);
+        assertEquals(1, reader.parseBuffer.size());
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        
+        action.start(Tag.PRE, attr);
+        assertEquals(3, reader.parseBuffer.size());
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        
+        ElementSpec spec = (ElementSpec)reader.parseBuffer.get(1);
+        AttributeSet specAttr = spec.getAttributes();
+        assertEquals(2, specAttr.getAttributeCount());
+        checkAttributes(specAttr, StyleConstants.NameAttribute, Tag.PRE);
+        checkAttributes(specAttr, "aaaa", "bbbb");
+        assertSpec(spec, ElementSpec.StartTagType, ElementSpec.OriginateDirection, 0, null);
+
+        spec = (ElementSpec)reader.parseBuffer.get(2);
+        specAttr = spec.getAttributes();
+        assertEquals(3, specAttr.getAttributeCount());
+        checkAttributes(specAttr, StyleConstants.NameAttribute, Tag.IMPLIED);
+        checkAttributes(specAttr, CSS.Attribute.WHITE_SPACE, "pre");
+        checkAttributes(specAttr, "aaaa", "bbbb");
+        assertSpec(spec, ElementSpec.StartTagType, ElementSpec.OriginateDirection, 0, null);
+    }
+    
+    public void testPreStartEnd_Specs() {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        action = reader.new PreAction();
+        
+        action.start(Tag.PRE, attr);
+        assertEquals(2, reader.parseBuffer.size());
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        action.end(Tag.PRE);
+        assertEquals(5, reader.parseBuffer.size());
+
+        checkCRSpec((ElementSpec)reader.parseBuffer.get(2));
+        checkEndTagSpec((ElementSpec)reader.parseBuffer.get(3));
+        checkEndTagSpec((ElementSpec)reader.parseBuffer.get(4));
+    }
+    
+    public void testPreStartEnd_BlockCalls() {
+        final Marker blockOpen = new Marker();
+        final Marker blockClose = new Marker();
+        doc = new HTMLDocument() {
+            public ParserCallback getReader(int pos) {
+                return new HTMLReader(0) {
+                    protected void blockOpen(Tag tag, MutableAttributeSet attr) {
+                        blockOpen.setOccurred();
+                        ArrayList callInfo = (blockOpen.getAuxiliary() == null)
+                                              ? new ArrayList() 
+                                              : (ArrayList)blockOpen.getAuxiliary();
+                        callInfo.add(tag);
+                        callInfo.add(attr.copyAttributes());
+                        blockOpen.setAuxiliary(callInfo);
+                        super.blockOpen(tag, attr);
+                    }
+
+                    protected void blockClose(Tag tag) {
+                        super.blockClose(tag);
+                        ArrayList callInfo = (blockClose.getAuxiliary() == null)
+                                              ? new ArrayList() 
+                                              : (ArrayList)blockClose.getAuxiliary();
+                        blockClose.setOccurred();
+                        callInfo.add(tag);
+                        blockClose.setAuxiliary(callInfo);
+                    }
+                };
+            }
+        };
+        reader = (HTMLReader)doc.getReader(0);
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        SimpleAttributeSet initial = (SimpleAttributeSet)attr.copyAttributes();
+        action = reader.new PreAction();
+        
+        action.start(Tag.PRE, attr);
+        assertTrue(blockOpen.isOccurred());
+        assertFalse(blockClose.isOccurred());
+        ArrayList callInfo = (ArrayList)blockOpen.getAuxiliary();
+        assertEquals(4, callInfo.size());
+        assertEquals(Tag.PRE, callInfo.get(0));
+        assertEquals(initial, callInfo.get(1));
+        assertEquals(Tag.IMPLIED, callInfo.get(2));
+        final AttributeSet attrs = (AttributeSet)callInfo.get(3);
+        checkAttributes(attrs, "aaaa", "bbbb");
+        checkAttributes(attrs, StyleConstants.NameAttribute, Tag.PRE);
+        checkAttributes(attrs, CSS.Attribute.WHITE_SPACE, "pre");
+        blockOpen.reset();
+        
+        action.end(Tag.PRE);
+        assertFalse(blockOpen.isOccurred());
+        assertTrue(blockClose.isOccurred());
+        callInfo = (ArrayList)blockClose.getAuxiliary();
+        assertEquals(2, callInfo.size());
+        assertEquals(Tag.IMPLIED, callInfo.get(0));
+        assertEquals(Tag.PRE, callInfo.get(1));
+    }
+    
+    public void testPreStartEnd_PreContentCalls() {
+        final Marker preContentMarker = new Marker();
+        doc = new HTMLDocument() {
+            public ParserCallback getReader(int pos) {
+                return new HTMLReader(0) {
+                    protected void preContent(char[] data) {
+                        preContentMarker.setOccurred();
+                        preContentMarker.setAuxiliary(data);
+                        super.preContent(data);
+                    }
+                };
+            }
+        };
+        reader = (HTMLReader)doc.getReader(0);
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        action = reader.new PreAction();
+        
+        action.start(Tag.PRE, attr);
+        String text = "data";
+        assertFalse(preContentMarker.isOccurred());
+        reader.handleText(text.toCharArray(), 0);
+        assertTrue(preContentMarker.isOccurred());
+        assertEquals(text, new String((char [])preContentMarker.getAuxiliary()));
+        action.end(Tag.PRE);
+        preContentMarker.reset();
+        reader.handleText(text.toCharArray(), 0);
+        assertFalse(preContentMarker.isOccurred());
+    }
+    
+    public void testPre_ContentWhitespaces1() {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        action = reader.new PreAction();
+        
+        action.start(Tag.PRE, attr);
+        String text = "data       \t \r \f  data";
+        assertEquals(2, reader.parseBuffer.size());
+        reader.handleText(text.toCharArray(), 0);
+        
+        assertEquals(3, reader.parseBuffer.size());
+        ElementSpec spec = (ElementSpec)reader.parseBuffer.get(2);
+        assertEquals(text.length(), spec.getLength());
+        assertEquals(text.length(), spec.getArray().length);
+    }
+    
+    public void testPre_ContentWhitespaces2() {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        action = reader.new PreAction();
+        
+        action.start(Tag.PRE, attr);
+        String text = "data       \t \r \f  data";
+        assertEquals(2, reader.parseBuffer.size());
+        reader.preContent(text.toCharArray());
+        
+        assertEquals(3, reader.parseBuffer.size());
+        ElementSpec spec = (ElementSpec)reader.parseBuffer.get(2);
+        assertEquals(text.length(), spec.getLength());
+        assertEquals(text.length(), spec.getArray().length);
+    }
+    
+    public void testTag_ContentWhitespaces() {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        action = reader.new PreAction();
+        
+        action.start(Tag.P, attr);
+        String text = "data       \t \r \f  data";
+        assertEquals(2, reader.parseBuffer.size());
+        reader.handleText(text.toCharArray(), 0);
+        
+        assertEquals(3, reader.parseBuffer.size());
+        ElementSpec spec = (ElementSpec)reader.parseBuffer.get(2);
+        assertEquals(text.length(), spec.getLength());
+        assertEquals(text.length(), spec.getArray().length);
+    }
+    
+    public void testPreEnd() {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        HTMLDocument.HTMLReader.TagAction action = reader.new PreAction();
+        
+        action.end(Tag.PRE);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(2, reader.parseBuffer.size());
+
+        ElementSpec spec = (ElementSpec)reader.parseBuffer.get(0);
+        checkEndTagSpec(spec);
+
+        spec = (ElementSpec)reader.parseBuffer.get(1);
+        checkEndTagSpec(spec);
+    }
+
+    public void testIsindexStart() {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        final String prompt = "text";
+        attr.addAttribute(HTML.Attribute.PROMPT, prompt);
+        action = reader.new IsindexAction();
+        
+        action.start(Tag.ISINDEX, attr);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(5, reader.parseBuffer.size());
+
+        ElementSpec spec = (ElementSpec)reader.parseBuffer.get(0);
+        checkOpenImpliedSpec(spec);
+        
+        spec = (ElementSpec)reader.parseBuffer.get(1);
+        checkOpenImpliedSpec(spec);
+
+        spec = (ElementSpec)reader.parseBuffer.get(2);
+        AttributeSet specAttr = spec.getAttributes();
+        assertEquals(3, specAttr.getAttributeCount());
+        checkAttributes(specAttr, StyleConstants.NameAttribute, Tag.ISINDEX);
+        checkAttributes(specAttr, "aaaa", "bbbb");
+        checkAttributes(specAttr, HTML.Attribute.PROMPT, prompt);
+        checkImplicitContentSpec(spec);
+        assertNotSame(specAttr, attr);
+
+        spec = (ElementSpec)reader.parseBuffer.get(3);
+        checkCRSpec(spec);
+
+        spec = (ElementSpec)reader.parseBuffer.get(4);
+        checkEndTagSpec(spec);
+    }
+
+    public void testIsindexStart_InParagraph() {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        final String prompt = "text";
+        attr.addAttribute(HTML.Attribute.PROMPT, prompt);
+        action = reader.new IsindexAction();
+        
+        reader.handleStartTag(Tag.P, new SimpleAttributeSet(), 0);
+        assertEquals(1, reader.parseBuffer.size());
+
+        action.start(Tag.ISINDEX, attr);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(5, reader.parseBuffer.size());
+
+        ElementSpec spec = (ElementSpec)reader.parseBuffer.get(0);
+        AttributeSet specAttr = spec.getAttributes();
+        assertEquals(1, specAttr.getAttributeCount());
+        checkAttributes(specAttr, StyleConstants.NameAttribute, Tag.P);
+        assertSpec(spec, ElementSpec.StartTagType, ElementSpec.OriginateDirection, 0, null);
+        
+        spec = (ElementSpec)reader.parseBuffer.get(1);
+        checkOpenImpliedSpec(spec);
+
+        spec = (ElementSpec)reader.parseBuffer.get(2);
+        specAttr = spec.getAttributes();
+        assertEquals(3, specAttr.getAttributeCount());
+        checkAttributes(specAttr, StyleConstants.NameAttribute, Tag.ISINDEX);
+        checkAttributes(specAttr, "aaaa", "bbbb");
+        checkAttributes(specAttr, HTML.Attribute.PROMPT, prompt);
+        checkImplicitContentSpec(spec);
+
+        spec = (ElementSpec)reader.parseBuffer.get(3);
+        checkCRSpec(spec);
+
+        spec = (ElementSpec)reader.parseBuffer.get(4);
+        checkEndTagSpec(spec);
+
+        reader.blockClose(Tag.IMPLIED);
+        int numSpecs = reader.parseBuffer.size();
+        reader.handleText("text".toCharArray(), 0);
+        assertEquals(numSpecs, reader.parseBuffer.size());
+    }
+    
+    public void testIsindex_Calls() {
+        final Marker blockOpenMarker = new Marker();
+        final Marker blockCloseMarker = new Marker();
+        final Marker contentMarker = new Marker();
+        doc = new HTMLDocument() {
+            public ParserCallback getReader(int pos) {
+                return new HTMLReader(0) {
+                    protected void blockOpen(Tag tag, MutableAttributeSet attr) {
+                        blockOpenMarker.setOccurred();
+                        ArrayList callInfo = (blockOpenMarker.getAuxiliary() == null)
+                                              ? new ArrayList() 
+                                              : (ArrayList)blockOpenMarker.getAuxiliary();
+                        callInfo.add(tag);
+                        callInfo.add(attr.copyAttributes());
+                        blockOpenMarker.setAuxiliary(callInfo);
+                        super.blockOpen(tag, attr);
+                    }
+
+                    protected void blockClose(Tag tag) {
+                        super.blockClose(tag);
+                        ArrayList callInfo = (blockCloseMarker.getAuxiliary() == null)
+                                              ? new ArrayList() 
+                                              : (ArrayList)blockCloseMarker.getAuxiliary();
+                        blockCloseMarker.setOccurred();
+                        callInfo.add(tag);
+                        blockCloseMarker.setAuxiliary(callInfo);
+                    }
+                    
+                   protected void addContent(char[] data, int offs, int length, boolean generateImpliedPIfNecessary) {
+                       ArrayList callInfo = (contentMarker.getAuxiliary() == null)
+                                            ? new ArrayList() 
+                                            : (ArrayList)contentMarker.getAuxiliary();
+                       contentMarker.setOccurred();
+                       callInfo.add(data);
+                       callInfo.add(new Integer(offs));
+                       callInfo.add(new Integer(length));
+                       callInfo.add(Boolean.valueOf(generateImpliedPIfNecessary));
+                       contentMarker.setAuxiliary(callInfo);
+                       super.addContent(data, offs, length, generateImpliedPIfNecessary);
+                   }
+                };
+            }
+        };
+        reader = (HTMLReader)doc.getReader(0);
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        action = reader.new IsindexAction();
+        
+        action.start(Tag.ISINDEX, attr);
+        assertTrue(blockOpenMarker.isOccurred());
+        
+        SimpleAttributeSet a = new SimpleAttributeSet();
+        ArrayList callInfo = (ArrayList)blockOpenMarker.getAuxiliary();
+        assertEquals(2, callInfo.size()/2);
+        assertEquals(Tag.IMPLIED, callInfo.get(0));
+        assertEquals(a, callInfo.get(1));
+        assertEquals(Tag.IMPLIED, callInfo.get(2));
+        assertEquals(a, callInfo.get(3));
+
+        assertTrue(blockCloseMarker.isOccurred());
+        callInfo = (ArrayList)blockCloseMarker.getAuxiliary();
+        assertEquals(1, callInfo.size());
+        assertEquals(Tag.IMPLIED, callInfo.get(0));
+
+        assertTrue(contentMarker.isOccurred());
+        callInfo = (ArrayList)contentMarker.getAuxiliary();
+        assertEquals(4, callInfo.size());
+        final char[] data = (char[])callInfo.get(0);
+        assertEquals(1, data.length);
+        assertEquals('\n', data[0]);
+        assertEquals(new Integer(0), callInfo.get(1));
+        assertEquals(new Integer(1), callInfo.get(2));
+        assertEquals(Boolean.TRUE, callInfo.get(3));
+        
+        
+    }
+    
+    public void testHiddenStart() {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        action = reader.new HiddenAction();
+
+        action.start(Tag.SCRIPT, attr);
+        assertEquals(2, reader.parseBuffer.size());
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        ElementSpec spec = (ElementSpec)reader.parseBuffer.get(0);
+        AttributeSet specAttr;
+        checkOpenImpliedSpec(spec);
+
+        spec = (ElementSpec)reader.parseBuffer.get(1);
+        specAttr = spec.getAttributes();
+        assertEquals(2, specAttr.getAttributeCount());
+        checkAttributes(specAttr, StyleConstants.NameAttribute, Tag.SCRIPT);
+        checkAttributes(specAttr, "aaaa", "bbbb");
+        checkImplicitContentSpec(spec);
+        
+        assertNotSame(specAttr, attr);
+    }
+    
+    public void testHiddenEnd() {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        action = reader.new HiddenAction();
+        
+        action.start(Tag.SCRIPT, attr);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(2, reader.parseBuffer.size());
+        action.end(Tag.SCRIPT);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(3, reader.parseBuffer.size());
+
+        ElementSpec spec = (ElementSpec)reader.parseBuffer.get(2);
+        AttributeSet specAttr = spec.getAttributes();
+        assertEquals(2, specAttr.getAttributeCount());
+        checkAttributes(specAttr, StyleConstants.NameAttribute, Tag.SCRIPT);
+        checkAttributes(specAttr, HTML.Attribute.ENDTAG, Boolean.TRUE);
+        checkImplicitContentSpec(spec);
+    }
+    
+    public void testBaseStart() throws Exception {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        final String url1 = "http://www.aaa.ru/aaa";
+        final String url2 = "http://www.bbb.ru";
+        final String tail1 = "/bbb#bbb";
+        final String tail2 = "dumb/dumm/#attr";
+        final String target = "target";
+        
+        attr.addAttribute(HTML.Attribute.HREF, tail2);
+        reader.handleSimpleTag(Tag.BASE, attr, 0);
+        assertNull(doc.getBase());
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(0, reader.parseBuffer.size());
+
+        doc.setBase(new URL(url2));
+
+        attr.addAttribute(HTML.Attribute.HREF, url1 + tail1);
+        reader.handleSimpleTag(Tag.BASE, attr, 0);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(0, reader.parseBuffer.size());
+        assertEquals(url1 + tail1, doc.getBase().toString());
+
+        attr.addAttribute(HTML.Attribute.HREF, tail2);
+        reader.handleSimpleTag(Tag.BASE, attr, 0);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(0, reader.parseBuffer.size());
+        assertEquals(url1 + "/" + tail2, doc.getBase().toString());
+    }
+    
+    public void testStyle_InHead() throws Exception {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        action = reader.new StyleAction();
+      
+        reader.handleStartTag(Tag.HEAD, new SimpleAttributeSet(), 0);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(1, reader.parseBuffer.size());
+        
+        action.start(Tag.STYLE, attr);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(1, reader.parseBuffer.size());
+        
+        final String text = "H1 { color: blue }";
+        reader.handleText(text.toCharArray(), 0);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(1, reader.parseBuffer.size());
+
+        assertEquals(0, doc.getStyleSheet().getRule("BODY").getAttributeCount());
+        action.end(Tag.STYLE);
+        Style rule = doc.getStyleSheet().getRule("h1");
+        assertEquals(0, rule.getAttributeCount());
+
+        reader.handleEndTag(Tag.HEAD, 0);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(5, reader.parseBuffer.size());
+        
+        rule = doc.getStyleSheet().getRule("h1");
+        assertEquals(2, rule.getAttributeCount());
+        assertEquals("h1", rule.getAttribute(StyleConstants.NameAttribute));
+        assertEquals("blue", rule.getAttribute(CSS.Attribute.COLOR).toString());
+    }
+
+    public void testStyle_InHead_Twice() throws Exception {
+        final String text1 = "H1 { color: blue }";
+        final String text2 = "H2 { color: red }";
+
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        action = reader.new StyleAction();
+      
+        reader.handleStartTag(Tag.HEAD, new SimpleAttributeSet(), 0);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(1, reader.parseBuffer.size());
+        
+        action.start(Tag.STYLE, attr);
+        assertEquals(1, reader.parseBuffer.size());
+        
+        reader.handleText(text1.toCharArray(), 0);
+        assertEquals(1, reader.parseBuffer.size());
+
+        assertEquals(0, doc.getStyleSheet().getRule("h1").getAttributeCount());
+        assertEquals(0, doc.getStyleSheet().getRule("h2").getAttributeCount());
+        action.end(Tag.STYLE);
+        assertEquals(0, doc.getStyleSheet().getRule("h1").getAttributeCount());
+        assertEquals(0, doc.getStyleSheet().getRule("h2").getAttributeCount());
+
+        action.start(Tag.STYLE, attr);
+        assertEquals(1, reader.parseBuffer.size());
+        
+        reader.handleText(text2.toCharArray(), 0);
+        assertEquals(1, reader.parseBuffer.size());
+
+        assertEquals(0, doc.getStyleSheet().getRule("h1").getAttributeCount());
+        assertEquals(0, doc.getStyleSheet().getRule("h2").getAttributeCount());
+        action.end(Tag.STYLE);
+        assertEquals(0, doc.getStyleSheet().getRule("h1").getAttributeCount());
+        assertEquals(0, doc.getStyleSheet().getRule("h2").getAttributeCount());
+
+        reader.handleEndTag(Tag.HEAD, 0);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(5, reader.parseBuffer.size());
+        
+        Style rule = doc.getStyleSheet().getRule("h1");
+        assertEquals(2, rule.getAttributeCount());
+        assertEquals("h1", rule.getAttribute(StyleConstants.NameAttribute));
+        assertEquals("blue", rule.getAttribute(CSS.Attribute.COLOR).toString());
+
+        rule = doc.getStyleSheet().getRule("h2");
+        assertEquals(2, rule.getAttributeCount());
+        assertEquals("h2", rule.getAttribute(StyleConstants.NameAttribute));
+        assertEquals("red", rule.getAttribute(CSS.Attribute.COLOR).toString());
+    }
+
+    public void testStyle() throws Exception {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        action = reader.new StyleAction();
+      
+        action.start(Tag.STYLE, attr);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(0, reader.parseBuffer.size());
+        
+        final String text = "H1 { color: blue }";
+        reader.handleText(text.toCharArray(), 0);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(0, reader.parseBuffer.size());
+
+        assertEquals(0, doc.getStyleSheet().getRule("BODY").getAttributeCount());
+        action.end(Tag.STYLE);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(0, reader.parseBuffer.size());
+        final Style rule = doc.getStyleSheet().getRule("h1");
+        assertEquals(0, rule.getAttributeCount());
+    }
+
+    public void testTitleStart() throws Exception {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        reader.handleStartTag(Tag.TITLE, attr, 0);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(2, reader.parseBuffer.size());
+        ElementSpec spec = (ElementSpec)reader.parseBuffer.get(0);
+        AttributeSet specAttr = spec.getAttributes();
+        assertEquals(1, specAttr.getAttributeCount());
+        checkOpenImpliedSpec(spec);
+        
+        spec = (ElementSpec)reader.parseBuffer.get(1);
+        specAttr = spec.getAttributes();
+        assertEquals(2, specAttr.getAttributeCount());
+        checkAttributes(specAttr, StyleConstants.NameAttribute, Tag.TITLE);
+        checkAttributes(specAttr, "aaaa", "bbbb");
+        checkImplicitContentSpec(spec);
+        assertNotSame(attr, specAttr);
+    }
+    
+    public void testTitleText() throws Exception {
+        final String title = "brand new title";
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        reader.handleStartTag(Tag.TITLE, attr, 0);
+
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(2, reader.parseBuffer.size());
+        reader.handleText(title.toCharArray(), 0);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(2, reader.parseBuffer.size());
+        
+        assertEquals(title, doc.getProperty(HTMLDocument.TitleProperty));
+    }
+    
+    public void testTitleEnd() throws Exception {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        reader.handleStartTag(Tag.TITLE, attr, 0);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(2, reader.parseBuffer.size());
+        reader.handleEndTag(Tag.TITLE, 0);
+        
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(3, reader.parseBuffer.size());
+        ElementSpec spec = (ElementSpec)reader.parseBuffer.get(2);
+        AttributeSet specAttr = spec.getAttributes();
+        assertEquals(2, specAttr.getAttributeCount());
+        checkAttributes(specAttr, StyleConstants.NameAttribute, Tag.TITLE);
+        checkAttributes(specAttr, HTML.Attribute.ENDTAG, Boolean.TRUE);
+        checkImplicitContentSpec(spec);
+    }
+    
+    public void testTitleEnd_Impied() throws Exception {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        reader.handleEndTag(Tag.TITLE, 0);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(2, reader.parseBuffer.size());
+        ElementSpec spec = (ElementSpec)reader.parseBuffer.get(0);
+        AttributeSet specAttr;
+        checkOpenImpliedSpec(spec);
+        spec = (ElementSpec)reader.parseBuffer.get(1);
+        specAttr = spec.getAttributes();
+        assertEquals(2, specAttr.getAttributeCount());
+        checkAttributes(specAttr, StyleConstants.NameAttribute, Tag.TITLE);
+        checkAttributes(specAttr, HTML.Attribute.ENDTAG, Boolean.TRUE);
+    }
+    
+    public void testLinkStart() throws Exception {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        
+        reader.handleStartTag(Tag.LINK, attr, 0);
+        assertEquals(2, reader.parseBuffer.size());
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        ElementSpec spec = (ElementSpec)reader.parseBuffer.get(0);
+        AttributeSet specAttr;
+        checkOpenImpliedSpec(spec);
+
+        spec = (ElementSpec)reader.parseBuffer.get(1);
+        specAttr = spec.getAttributes();
+        assertEquals(2, specAttr.getAttributeCount());
+        checkAttributes(specAttr, StyleConstants.NameAttribute, Tag.LINK);
+        checkAttributes(specAttr, "aaaa", "bbbb");
+        checkImplicitContentSpec(spec);
+    }
+    
+    public void testLinkStart_InTitle() throws Exception {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        
+        reader.handleStartTag(Tag.TITLE, attr, 0);
+        assertEquals(2, reader.parseBuffer.size());
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        
+        reader.handleStartTag(Tag.LINK, attr, 0);
+        assertEquals(3, reader.parseBuffer.size());
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        ElementSpec spec = (ElementSpec)reader.parseBuffer.get(2);
+        AttributeSet specAttr = spec.getAttributes();
+        assertEquals(2, specAttr.getAttributeCount());
+        checkAttributes(specAttr, StyleConstants.NameAttribute, Tag.LINK);
+        checkAttributes(specAttr, "aaaa", "bbbb");
+        checkImplicitContentSpec(spec);
+    }
+
+    public void testLinkEnd() throws Exception {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        reader.handleStartTag(Tag.LINK, attr, 0);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(2, reader.parseBuffer.size());
+        reader.handleEndTag(Tag.LINK, 0);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(2, reader.parseBuffer.size());
+    }
+    
+    public void testLinkEnd_InTitle() throws Exception {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        reader.handleStartTag(Tag.TITLE, attr, 0);
+        reader.handleStartTag(Tag.LINK, attr, 0);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(3, reader.parseBuffer.size());
+        reader.handleEndTag(Tag.LINK, 0);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(3, reader.parseBuffer.size());
+    }
+    
+    public void testLink_LoadCSS() throws Exception {
+        if (!isHarmony()) {
+            return;
+        }
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute(HTML.Attribute.TYPE, "text/css");
+        URL url = HTMLEditorKit.class.getResource(HTMLEditorKit.DEFAULT_CSS);
+        attr.addAttribute(HTML.Attribute.HREF, url.toString());
+        
+        assertEquals(0, new SimpleAttributeSet(doc.getStyleSheet().getRule("h3")).getAttributeCount());
+
+        reader.handleStartTag(Tag.TITLE, new SimpleAttributeSet(), 0);
+        assertEquals(2, reader.parseBuffer.size());
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        
+        reader.handleStartTag(Tag.LINK, attr, 0);
+        assertEquals(3, reader.parseBuffer.size());
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        
+        assertTrue(new SimpleAttributeSet(doc.getStyleSheet().getRule("h3")).getAttributeCount() > 0);
+    }
+
+    public void testAreaStart() throws Exception {
+        // TODO: implement
+    }
+    
+    public void testAreaEnd() throws Exception {
+        // TODO: implement
+    }
+    
+    public void testMetaStart() throws Exception {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        reader.handleStartTag(Tag.META, attr, 0);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(2, reader.parseBuffer.size());
+        ElementSpec spec = (ElementSpec)reader.parseBuffer.get(0);
+        AttributeSet specAttr;
+        checkOpenImpliedSpec(spec);
+        
+        spec = (ElementSpec)reader.parseBuffer.get(1);
+        specAttr = spec.getAttributes();
+        assertEquals(1, specAttr.getAttributeCount());
+        checkAttributes(specAttr, StyleConstants.NameAttribute, Tag.META);
+        assertSpec(spec, ElementSpec.ContentType, ElementSpec.OriginateDirection, 0, new char[]{' '});
+    }
+    
+    public void testMetaStart_InTitle() throws Exception {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        
+        reader.handleStartTag(Tag.TITLE, attr, 0);
+        assertEquals(2, reader.parseBuffer.size());
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        
+        reader.handleStartTag(Tag.META, attr, 0);
+        assertEquals(3, reader.parseBuffer.size());
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        ElementSpec spec = (ElementSpec)reader.parseBuffer.get(2);
+        AttributeSet specAttr = spec.getAttributes();
+        assertEquals(2, specAttr.getAttributeCount());
+        checkAttributes(specAttr, StyleConstants.NameAttribute, Tag.META);
+        checkAttributes(specAttr, "aaaa", "bbbb");
+        assertSpec(spec, ElementSpec.ContentType, ElementSpec.OriginateDirection, 0, new char[]{' '});
+    }
+    
+    public void testMetaEnd() throws Exception {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        reader.handleStartTag(Tag.META, attr, 0);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(2, reader.parseBuffer.size());
+        reader.handleEndTag(Tag.META, 0);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(2, reader.parseBuffer.size());
+    }
+    
+    public void testFormStart() {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        action = reader.new FormAction();
+        
+        action.start(Tag.FORM, attr);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(2, reader.parseBuffer.size());
+        ElementSpec spec = (ElementSpec)reader.parseBuffer.get(0);
+        AttributeSet specAttr;
+        checkOpenImpliedSpec(spec);
+        spec = (ElementSpec)reader.parseBuffer.get(1);
+        specAttr = spec.getAttributes();
+        assertEquals(2, specAttr.getAttributeCount());
+        checkAttributes(specAttr, StyleConstants.NameAttribute, Tag.FORM);
+        checkAttributes(specAttr, "aaaa", "bbbb");
+        checkImplicitContentSpec(spec);
+
+        assertEquals(2, attr.getAttributeCount());
+        checkAttributes(attr, StyleConstants.NameAttribute, Tag.FORM);
+        checkAttributes(attr, "aaaa", "bbbb");
+    }
+
+    public void testFormEnd() {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        action = reader.new FormAction();
+        
+        action.end(Tag.FORM);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(0, reader.parseBuffer.size());
+    }
+
+    public void testLabelStart() throws Exception {
+        // TODO: implement
+    }
+    
+    public void testLabelEnd() throws Exception {
+        // TODO: implement
+    }
+    
+    private void checkCRSpec(final ElementSpec spec) {
+        final AttributeSet specAttr = spec.getAttributes();
+        assertEquals(2, specAttr.getAttributeCount());
+        checkAttributes(specAttr, StyleConstants.NameAttribute, Tag.CONTENT);
+        checkAttributes(specAttr, "CR", Boolean.TRUE);
+        assertSpec(spec, ElementSpec.ContentType, ElementSpec.OriginateDirection, 0, new char[]{'\n'});
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/HTMLDocument_Reader_FormActionTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/HTMLDocument_Reader_FormActionTest.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/HTMLDocument_Reader_FormActionTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/HTMLDocument_Reader_FormActionTest.java Mon Jul 31 07:08:47 2006
@@ -0,0 +1,703 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/**
+* @author Alexander T. Simbirtsev
+* @version $Revision$
+*/
+package javax.swing.text.html;
+
+import javax.swing.DefaultButtonModel;
+import javax.swing.DefaultComboBoxModel;
+import javax.swing.DefaultListModel;
+import javax.swing.JToggleButton;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.PlainDocument;
+import javax.swing.text.SimpleAttributeSet;
+import javax.swing.text.StyleConstants;
+import javax.swing.text.DefaultStyledDocument.ElementSpec;
+import javax.swing.text.html.HTML.Tag;
+
+import org.apache.harmony.x.swing.text.html.form.FormFieldsetModel;
+import org.apache.harmony.x.swing.text.html.form.FormOption;
+
+public class HTMLDocument_Reader_FormActionTest extends HTMLDocumentTestCase {
+
+    protected HTMLDocument.HTMLReader reader;
+    protected HTMLDocument doc;
+    protected HTMLDocument.HTMLReader.TagAction action;
+    
+    protected void setUp() throws Exception {
+        super.setUp();
+        doc = new HTMLDocument();
+        reader = (HTMLDocument.HTMLReader)doc.getReader(0);
+    }
+
+    protected void tearDown() throws Exception {
+        action = null;
+        doc = null;
+        reader = null;
+        super.tearDown();
+    }
+
+    public void testFormStart_InputButton() throws Exception {
+        if (isHarmony()) {
+            checkStandardInputStart("button", DefaultButtonModel.class);
+        }
+    }
+    
+    public void testFormEnd_InputButton() throws Exception {
+        checkEmptyFormEnd(Tag.INPUT, "button");
+    }
+    
+    public void testFormStart_InputCheckBox() throws Exception {
+        checkStandardInputStart("checkbox", JToggleButton.ToggleButtonModel.class);
+    }
+    
+    public void testFormEnd_InputCheckBox() throws Exception {
+        checkEmptyFormEnd(Tag.INPUT, "checkbox");
+    }
+    
+    public void testFormStart_InputImage() throws Exception {
+        checkStandardInputStart("image", DefaultButtonModel.class);
+    }
+    
+    public void testFormEnd_InputImage() throws Exception {
+        checkEmptyFormEnd(Tag.INPUT, "image");
+    }
+    
+    public void testFormStart_InputRadio() throws Exception {
+        checkStandardInputStart("radio", JToggleButton.ToggleButtonModel.class);
+    }
+    
+    public void testFormEnd_InputRadio() throws Exception {
+        checkEmptyFormEnd(Tag.INPUT, "radio");
+    }
+    
+    public void testForm_InputRadioGroups() throws Exception {
+        String name1 = "name1";
+        String name2 = "name2";
+        String name3 = "";
+        action = reader.new FormAction();
+
+        reader.handleStartTag(Tag.FORM, new SimpleAttributeSet(), 0);
+        reader.handleStartTag(Tag.INPUT, createInputNamedAttributes(name1), 0);
+        reader.handleStartTag(Tag.INPUT, createInputNamedAttributes(name2), 0);
+        reader.handleStartTag(Tag.INPUT, createInputNamedAttributes(name3), 0);
+        reader.handleStartTag(Tag.INPUT, createInputNamedAttributes(name1), 0);
+        reader.handleStartTag(Tag.INPUT, createInputNamedAttributes(null), 0);
+        reader.handleStartTag(Tag.INPUT, createInputNamedAttributes(name2), 0);
+        reader.handleStartTag(Tag.INPUT, createInputNamedAttributes(name3), 0);
+        reader.handleStartTag(Tag.INPUT, createInputNamedAttributes(null), 0);
+        reader.handleEndTag(Tag.FORM, 0);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(13, reader.parseBuffer.size());
+
+        DefaultButtonModel model1 = (DefaultButtonModel)getModel((ElementSpec)reader.parseBuffer.get(2));
+        DefaultButtonModel model2 = (DefaultButtonModel)getModel((ElementSpec)reader.parseBuffer.get(3));
+        DefaultButtonModel model3 = (DefaultButtonModel)getModel((ElementSpec)reader.parseBuffer.get(4));
+        DefaultButtonModel model4 = (DefaultButtonModel)getModel((ElementSpec)reader.parseBuffer.get(5));
+        DefaultButtonModel model5 = (DefaultButtonModel)getModel((ElementSpec)reader.parseBuffer.get(6));
+        DefaultButtonModel model6 = (DefaultButtonModel)getModel((ElementSpec)reader.parseBuffer.get(7));
+        DefaultButtonModel model7 = (DefaultButtonModel)getModel((ElementSpec)reader.parseBuffer.get(8));
+        DefaultButtonModel model8 = (DefaultButtonModel)getModel((ElementSpec)reader.parseBuffer.get(9));
+        assertNotNull(model1.getGroup());
+        assertNotNull(model2.getGroup());
+        assertNotNull(model3.getGroup());
+        assertNotNull(model4.getGroup());
+        assertNotNull(model5.getGroup());
+        assertNotNull(model6.getGroup());
+        assertNotNull(model7.getGroup());
+        assertNotNull(model8.getGroup());
+        assertSame(model1.getGroup(), model4.getGroup());
+        assertSame(model2.getGroup(), model6.getGroup());
+        assertSame(model3.getGroup(), model7.getGroup());
+        assertSame(model5.getGroup(), model8.getGroup());
+        assertNotSame(model1.getGroup(), model2.getGroup());
+        assertNotSame(model3.getGroup(), model5.getGroup());
+
+        reader.handleStartTag(Tag.FORM, new SimpleAttributeSet(), 0);
+        reader.handleStartTag(Tag.INPUT, createInputNamedAttributes(name1), 0);
+        reader.handleStartTag(Tag.INPUT, createInputNamedAttributes(null), 0);
+        reader.handleStartTag(Tag.INPUT, createInputNamedAttributes(name1), 0);
+        assertEquals(18, reader.parseBuffer.size());
+        DefaultButtonModel model9 = (DefaultButtonModel)getModel((ElementSpec)reader.parseBuffer.get(15));
+        DefaultButtonModel model10 = (DefaultButtonModel)getModel((ElementSpec)reader.parseBuffer.get(16));
+        DefaultButtonModel model11 = (DefaultButtonModel)getModel((ElementSpec)reader.parseBuffer.get(17));
+        assertNotNull(model9.getGroup());
+        assertNotNull(model11.getGroup());
+        if (!isHarmony()) {
+            assertNotNull(model10.getGroup());
+        } else {
+            assertNull(model10.getGroup());
+        }
+        assertNotSame(model9.getGroup(), model1.getGroup());
+        assertNotSame(model11.getGroup(), model1.getGroup());
+        
+    }
+
+    private SimpleAttributeSet createInputNamedAttributes(String name) {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute(HTML.Attribute.TYPE, "radio");
+        if (name != null) {
+            attr.addAttribute(HTML.Attribute.NAME, name);
+        }
+        return attr;
+    }
+    
+    public void testFormStart_InputReset() throws Exception {
+        checkStandardInputStart("reset", DefaultButtonModel.class);
+    }
+    
+    public void testFormEnd_InputReset() throws Exception {
+        checkEmptyFormEnd(Tag.INPUT, "reset");
+    }
+    
+    public void testFormStart_InputSubmit() throws Exception {
+        checkStandardInputStart("submit", DefaultButtonModel.class);
+    }
+    
+    public void testFormEnd_InputSubmit() throws Exception {
+        checkEmptyFormEnd(Tag.INPUT, "submit");
+    }
+    
+    public void testFormStart_InputText() throws Exception {
+        checkStandardInputStart("text", PlainDocument.class);
+    }
+    
+    public void testFormEnd_InputText() throws Exception {
+        checkEmptyFormEnd(Tag.INPUT, "text");
+    }
+    
+    public void testFormStart_InputPassword() throws Exception {
+        checkStandardInputStart("password", PlainDocument.class);
+    }
+    
+    public void testFormEnd_InputPassword() throws Exception {
+        checkEmptyFormEnd(Tag.INPUT, "password");
+    }
+    
+    public void testFormStart_InputFile() throws Exception {
+        checkStandardInputStart("file", PlainDocument.class);
+    }
+    
+    public void testFormEnd_InputFile() throws Exception {
+        checkEmptyFormEnd(Tag.INPUT, "file");
+    }
+    
+    public void testFormStart_InputHidden() throws Exception {
+        checkStandardInputStart("hidden", null);
+    }
+    
+    public void testFormEnd_InputHidden() throws Exception {
+        checkEmptyFormEnd(Tag.INPUT, "hidden");
+    }
+    
+    public void testFormStart_InputNull() throws Exception {
+        checkStandardInputStart(null, PlainDocument.class);
+    }
+    
+    public void testFormEnd_InputNull() throws Exception {
+        checkEmptyFormEnd(Tag.INPUT, null);
+    }
+    
+    public void testFormStart_Button() throws Exception {
+        if (isHarmony()) {
+            checkStandardFormStart(Tag.BUTTON, DefaultButtonModel.class);
+        }
+    }
+    
+    public void testFormEnd_Button() throws Exception {
+        if (isHarmony()) {
+            checkEmptyFormEnd(Tag.BUTTON, null);
+        }
+    }
+    
+    public void testFormStart_SelectCombo1() throws Exception {
+        checkStandardFormStart(Tag.SELECT, DefaultComboBoxModel.class);
+    }
+    
+    public void testFormStart_SelectCombo2() throws Exception {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute(HTML.Attribute.SIZE, "1");
+        checkStandardFormStart(Tag.SELECT, DefaultComboBoxModel.class, attr);
+    }
+    
+    public void testFormStart_SelectList1() throws Exception {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute(HTML.Attribute.MULTIPLE, "multiple");
+        checkStandardFormStart(Tag.SELECT, DefaultListModel.class, attr);
+    }
+    
+    public void testFormStart_SelectList2() throws Exception {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute(HTML.Attribute.SIZE, "2");
+        checkStandardFormStart(Tag.SELECT, DefaultListModel.class, attr);
+    }
+    
+    public void testFormStart_SelectList3() throws Exception {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute(HTML.Attribute.MULTIPLE, "multiple");
+        attr.addAttribute(HTML.Attribute.SIZE, "1");
+        checkStandardFormStart(Tag.SELECT, DefaultListModel.class, attr);
+    }
+    
+    public void testFormStart_SelectList4() throws Exception {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute(HTML.Attribute.SIZE, "kva");
+        checkStandardFormStart(Tag.SELECT, DefaultComboBoxModel.class, attr);
+    }
+    
+    public void testFormEnd_Select() throws Exception {
+        checkEmptyFormEnd(Tag.SELECT, null);
+    }
+    
+    public void testFormStart_Option() throws Exception {
+        String text = "text";
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        action = reader.new FormAction();
+        action.start(Tag.OPTION, attr);
+        assertEquals(0, reader.parseBuffer.size());
+    }
+    
+    public void testForm_OptionCombo() throws Exception {
+        String text = "text";
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        action = reader.new FormAction();
+        action.start(Tag.SELECT, attr);
+        action.start(Tag.OPTION, attr);
+        
+        ElementSpec spec = (ElementSpec)reader.parseBuffer.get(1);
+        final AttributeSet specAttr = spec.getAttributes();
+        assertEquals(3, specAttr.getAttributeCount());
+        assertSpec(spec, ElementSpec.ContentType, ElementSpec.OriginateDirection, 0, new char[] {' '});
+        Object contentModel = specAttr.getAttribute(StyleConstants.ModelAttribute);
+        assertNotNull(contentModel);
+        assertTrue(contentModel instanceof DefaultComboBoxModel);
+        DefaultComboBoxModel model = (DefaultComboBoxModel)contentModel;
+        assertEquals(1, model.getSize());
+        assertNotNull(model.getElementAt(0));
+        reader.handleText(text.toCharArray(), 0);
+        assertEquals(1, model.getSize());
+        assertNotNull(model.getElementAt(0));
+        action.end(Tag.OPTION);
+
+        action.start(Tag.OPTION, attr);
+        assertEquals(2, model.getSize());
+        assertNotNull(model.getElementAt(1));
+        reader.handleText(text.toCharArray(), 0);
+        assertEquals(2, model.getSize());
+        assertNotNull(model.getElementAt(1));
+        action.end(Tag.OPTION);
+        action.end(Tag.SELECT);
+        assertEquals(3, specAttr.getAttributeCount());
+    }
+    
+    public void testForm_OptionList() throws Exception {
+        String text = "text";
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute(HTML.Attribute.MULTIPLE, "multiple");
+        attr.addAttribute("aaaa", "bbbb");
+        action = reader.new FormAction();
+        action.start(Tag.SELECT, attr);
+        action.start(Tag.OPTION, attr);
+        
+        ElementSpec spec = (ElementSpec)reader.parseBuffer.get(1);
+        final AttributeSet specAttr = spec.getAttributes();
+        assertEquals(4, specAttr.getAttributeCount());
+        assertSpec(spec, ElementSpec.ContentType, ElementSpec.OriginateDirection, 0, new char[] {' '});
+        Object contentModel = specAttr.getAttribute(StyleConstants.ModelAttribute);
+        assertNotNull(contentModel);
+        assertTrue(contentModel instanceof DefaultListModel);
+        DefaultListModel model = (DefaultListModel)contentModel;
+        assertEquals(1, model.getSize());
+        assertNotNull(model.getElementAt(0));
+        reader.handleText(text.toCharArray(), 0);
+        assertEquals(1, model.getSize());
+        assertNotNull(model.getElementAt(0));
+        action.end(Tag.OPTION);
+
+        action.start(Tag.OPTION, attr);
+        assertEquals(2, model.getSize());
+        assertNotNull(model.getElementAt(1));
+        reader.handleText(text.toCharArray(), 0);
+        assertEquals(2, model.getSize());
+        assertNotNull(model.getElementAt(1));
+        action.end(Tag.OPTION);
+        action.end(Tag.SELECT);
+        assertEquals(4, specAttr.getAttributeCount());
+    }
+    
+    public void testForm_SelectOption() throws Exception {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        action = reader.new FormAction();
+        action.start(Tag.SELECT, attr);
+        assertEquals(2, reader.parseBuffer.size());
+        action.start(Tag.OPTION, attr);
+        action.end(Tag.OPTION);
+        action.start(Tag.OPTION, attr);
+        action.end(Tag.OPTION);
+        action.end(Tag.SELECT);
+        assertEquals(2, reader.parseBuffer.size());
+    }
+    
+    public void testForm_Attributes() throws Exception {
+        String text = "text";
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        action = reader.new FormAction();
+        action.start(Tag.SELECT, attr);
+        ElementSpec spec = (ElementSpec)reader.parseBuffer.get(1);
+        final AttributeSet specAttr = spec.getAttributes();
+        assertNotSame(specAttr, attr);
+    }
+    
+    public void testForm_OptionAttributes() throws Exception {
+        String text = "text";
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        action = reader.new FormAction();
+        action.start(Tag.SELECT, attr);
+        ElementSpec spec = (ElementSpec)reader.parseBuffer.get(1);
+        final AttributeSet specAttr = spec.getAttributes();
+        assertEquals(3, specAttr.getAttributeCount());
+        assertSpec(spec, ElementSpec.ContentType, ElementSpec.OriginateDirection, 0, new char[] {' '});
+        Object contentModel = specAttr.getAttribute(StyleConstants.ModelAttribute);
+        assertNotNull(contentModel);
+        assertTrue(contentModel instanceof DefaultComboBoxModel);
+        DefaultComboBoxModel model = (DefaultComboBoxModel)contentModel;
+
+        action.start(Tag.OPTION, attr);
+        assertEquals(1, model.getSize());
+        assertNotNull(model.getElementAt(0));
+        Option option = (Option)model.getElementAt(0);
+        assertFalse(option.isSelected());
+        assertNull(option.getLabel());
+        assertNull(option.getValue());
+        reader.handleText(text.toCharArray(), 0);
+        assertEquals(1, model.getSize());
+        assertNotNull(model.getElementAt(0));
+        option = (Option)model.getElementAt(0);
+        assertFalse(option.isSelected());
+        assertEquals(text, option.getLabel());
+        assertEquals(text, option.getValue());
+        action.end(Tag.OPTION);
+
+        final String value = "value";
+        final String label = "label";
+        attr.addAttribute(HTML.Attribute.SELECTED, "true");
+        attr.addAttribute(HTML.Attribute.VALUE, value);
+        if (isHarmony()) {
+            attr.addAttribute(HTML.Attribute.LABEL, label);
+        } else {
+            attr.addAttribute("label", label);
+        }
+        action.start(Tag.OPTION, attr);
+        assertEquals(2, model.getSize());
+        assertNotNull(model.getElementAt(1));
+        option = (Option)model.getElementAt(1);
+        assertTrue(option.isSelected());
+        if (isHarmony()) {
+            assertEquals(label, option.getLabel());
+            assertEquals(0, ((FormOption)option).getDepth());
+        } else {
+            assertNull(option.getLabel());
+        }
+        assertEquals(value, option.getValue());
+        reader.handleText(text.toCharArray(), 0);
+        assertEquals(2, model.getSize());
+        assertNotNull(model.getElementAt(1));
+        option = (Option)model.getElementAt(1);
+        assertTrue(option.isSelected());
+        assertEquals(value, option.getValue());
+        if (isHarmony()) {
+            assertEquals(0, ((FormOption)option).getDepth());
+        }
+        assertEquals(text, option.getLabel());
+        action.end(Tag.OPTION);
+        action.end(Tag.SELECT);
+        assertEquals(3, specAttr.getAttributeCount());
+    }
+    
+    public void testForm_OptionGroupAttributes() throws Exception {
+        if (!isHarmony()) {
+            return;
+        }
+        String text = "text";
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        action = reader.new FormAction();
+        action.start(Tag.SELECT, attr);
+        ElementSpec spec = (ElementSpec)reader.parseBuffer.get(1);
+        final AttributeSet specAttr = spec.getAttributes();
+        assertEquals(3, specAttr.getAttributeCount());
+        assertSpec(spec, ElementSpec.ContentType, ElementSpec.OriginateDirection, 0, new char[] {' '});
+        Object contentModel = specAttr.getAttribute(StyleConstants.ModelAttribute);
+        assertNotNull(contentModel);
+        assertTrue(contentModel instanceof DefaultComboBoxModel);
+        DefaultComboBoxModel model = (DefaultComboBoxModel)contentModel;
+
+        final String value = "value";
+        final String label = "label";
+        attr.addAttribute(HTML.Attribute.SELECTED, "true");
+        attr.addAttribute(HTML.Attribute.LABEL, label);
+        action.start(Tag.OPTGROUP, attr);
+        assertEquals(1, model.getSize());
+        assertNotNull(model.getElementAt(0));
+        FormOption option = (FormOption)model.getElementAt(0);
+        assertFalse(option.isSelected());
+        assertEquals(label, option.getLabel());
+        assertNull(option.getValue());
+        reader.handleText(text.toCharArray(), 0);
+        assertEquals(1, model.getSize());
+        assertNotNull(model.getElementAt(0));
+        option = (FormOption)model.getElementAt(0);
+        assertFalse(option.isSelected());
+        assertEquals(label, option.getLabel());
+        assertNull(option.getValue());
+        assertEquals(0, option.getDepth());
+
+        attr.addAttribute(HTML.Attribute.SELECTED, "true");
+        attr.addAttribute(HTML.Attribute.VALUE, value);
+        attr.addAttribute(HTML.Attribute.LABEL, label);
+        action.start(Tag.OPTGROUP, attr);
+        assertEquals(2, model.getSize());
+        assertNotNull(model.getElementAt(1));
+        option = (FormOption)model.getElementAt(1);
+        assertFalse(option.isSelected());
+        assertEquals(label, option.getLabel());
+        assertNull(option.getValue());
+        reader.handleText(text.toCharArray(), 0);
+        assertEquals(2, model.getSize());
+        assertNotNull(model.getElementAt(1));
+        option = (FormOption)model.getElementAt(1);
+        assertFalse(option.isSelected());
+        assertEquals(label, option.getLabel());
+        assertNull(option.getValue());
+        assertEquals(1, option.getDepth());
+        action.end(Tag.OPTGROUP);
+        action.end(Tag.OPTGROUP);
+        action.end(Tag.SELECT);
+        assertEquals(3, specAttr.getAttributeCount());
+    }
+    
+    public void testFormEnd_Option() throws Exception {
+        checkEmptyFormEnd(Tag.OPTION, null);
+    }
+    
+    public void testFormEnd_Optgroup() throws Exception {
+        if (isHarmony()) {
+            checkEmptyFormEnd(Tag.OPTGROUP, null);
+        }
+    }
+    
+    public void testFormStart_TextArea() throws Exception {
+        checkStandardFormStart(Tag.TEXTAREA, PlainDocument.class);
+    }
+    
+    public void testFormEnd_TextArea() throws Exception {
+        checkEmptyFormEnd(Tag.TEXTAREA, null);
+    }
+    
+    public void testFormStart_FieldSet() throws Exception {
+        if (!isHarmony()) {
+            return;
+        }
+        String text = "text";
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        action = reader.new FormAction();
+        action.start(Tag.FIELDSET, attr);
+        ElementSpec spec = (ElementSpec)reader.parseBuffer.get(1);
+        final AttributeSet specAttr = spec.getAttributes();
+        assertEquals(3, specAttr.getAttributeCount());
+        assertSpec(spec, ElementSpec.ContentType, ElementSpec.OriginateDirection, 0, new char[] {' '});
+        Object contentModel = specAttr.getAttribute(StyleConstants.ModelAttribute);
+        assertNotNull(contentModel);
+        assertTrue(contentModel instanceof FormFieldsetModel);
+    }
+    
+    public void testFormEnd_FieldSet() throws Exception {
+        if (isHarmony()) {
+            checkEmptyFormEnd(Tag.FIELDSET, null);
+        }
+    }
+    
+    public void testFormStartEnd_Legend_InsideFieldSet() throws Exception {
+        if (!isHarmony()) {
+            return;
+        }
+        String text1 = "text1";
+        String text2 = "text2";
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        SimpleAttributeSet legendAttr1 = new SimpleAttributeSet();
+        legendAttr1.addAttribute("bbbb", "aaaa");
+        SimpleAttributeSet legendAttr2 = new SimpleAttributeSet();
+        legendAttr2.addAttribute("bb", "aa");
+        action = reader.new FormAction();
+        action.start(Tag.FIELDSET, attr);
+        ElementSpec spec = (ElementSpec)reader.parseBuffer.get(1);
+        final AttributeSet specAttr = spec.getAttributes();
+        assertEquals(3, specAttr.getAttributeCount());
+        assertSpec(spec, ElementSpec.ContentType, ElementSpec.OriginateDirection, 0, new char[] {' '});
+        Object contentModel = specAttr.getAttribute(StyleConstants.ModelAttribute);
+        assertNotNull(contentModel);
+        assertTrue(contentModel instanceof FormFieldsetModel);
+        FormFieldsetModel fieldSet = (FormFieldsetModel)contentModel;
+        assertNull(fieldSet.getLegend());
+        assertNull(fieldSet.getLegendAttributes());
+
+        action.start(Tag.LEGEND, legendAttr1);
+        reader.handleText(text1.toCharArray(), 0);
+        action.end(Tag.LEGEND);
+        assertEquals(text1, fieldSet.getLegend());
+        assertNotNull(fieldSet.getLegendAttributes());
+        assertEquals(2, fieldSet.getLegendAttributes().getAttributeCount());
+        checkAttributes(fieldSet.getLegendAttributes(), "bbbb", "aaaa");
+        checkAttributes(fieldSet.getLegendAttributes(), StyleConstants.NameAttribute, Tag.LEGEND);
+        assertNotSame(legendAttr1, fieldSet.getLegendAttributes());
+        
+        action.start(Tag.LEGEND, legendAttr2);
+        reader.handleText(text2.toCharArray(), 0);
+        action.end(Tag.LEGEND);
+        assertEquals(text1, fieldSet.getLegend());
+        assertNotNull(fieldSet.getLegendAttributes());
+        assertEquals(2, fieldSet.getLegendAttributes().getAttributeCount());
+        checkAttributes(fieldSet.getLegendAttributes(), StyleConstants.NameAttribute, Tag.LEGEND);
+        checkAttributes(fieldSet.getLegendAttributes(), "bbbb", "aaaa");
+    }
+    
+    public void testFormStartEnd_Legend_OutsideFieldSet() throws Exception {
+        if (!isHarmony()) {
+            return;
+        }
+        String text1 = "text1";
+        String text2 = "text2";
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        action = reader.new FormAction();
+        action.start(Tag.FIELDSET, attr);
+        ElementSpec spec = (ElementSpec)reader.parseBuffer.get(1);
+        final AttributeSet specAttr = spec.getAttributes();
+        assertEquals(3, specAttr.getAttributeCount());
+        assertSpec(spec, ElementSpec.ContentType, ElementSpec.OriginateDirection, 0, new char[] {' '});
+        Object contentModel = specAttr.getAttribute(StyleConstants.ModelAttribute);
+        assertNotNull(contentModel);
+        assertTrue(contentModel instanceof FormFieldsetModel);
+        FormFieldsetModel fieldSet = (FormFieldsetModel)contentModel;
+        assertNull(fieldSet.getLegend());
+        assertNull(fieldSet.getLegendAttributes());
+        action.end(Tag.FIELDSET);
+
+        action.start(Tag.LEGEND, attr);
+        reader.handleText(text1.toCharArray(), 0);
+        action.end(Tag.LEGEND);
+        assertNull(fieldSet.getLegend());
+        assertNull(fieldSet.getLegendAttributes());
+    }
+    
+    public void testFormEnd_Legend() throws Exception {
+        if (isHarmony()) {
+            checkEmptyFormEnd(Tag.LEGEND, null);
+        }
+    }
+
+    private void checkStandardInputStart(final String type, final Class modelClass) throws Exception {
+        checkStandardFormStart(Tag.INPUT, modelClass, type, null);
+    }
+    
+    private void checkStandardFormStart(final Tag tag, final Class modelClass) throws Exception {
+        checkStandardFormStart(tag, modelClass, null, null);
+    }
+    
+    private void checkStandardFormStart(final Tag tag, final Class modelClass, final AttributeSet attr) throws Exception {
+        checkStandardFormStart(tag, modelClass, null, attr);
+    }
+    
+    private void checkStandardFormStart(final Tag tag, final Class modelClass, final String type, final AttributeSet additionalAttr) throws Exception {
+        doFormStart(tag, type, additionalAttr);
+        
+        ElementSpec spec = (ElementSpec)reader.parseBuffer.get(0);
+        checkOpenImpliedSpec(spec);
+        
+        spec = (ElementSpec)reader.parseBuffer.get(1);
+        AttributeSet specAttr = spec.getAttributes();
+        
+        int addendum = additionalAttr != null ? additionalAttr.getAttributeCount() : 0;
+        int attrNum = 2;
+        if (modelClass != null) {
+            attrNum++;
+        }
+        if (Tag.INPUT.equals(tag)) {
+            attrNum++;
+        }
+        assertEquals(attrNum + addendum, specAttr.getAttributeCount());
+
+        if (additionalAttr != null) {
+            assertTrue(specAttr.containsAttributes(additionalAttr));
+        }
+        checkAttributes(specAttr, StyleConstants.NameAttribute, tag);
+        if (type != null) {
+            checkAttributes(specAttr, HTML.Attribute.TYPE, type);
+        }
+        checkAttributes(specAttr, "aaaa", "bbbb");
+        if (modelClass != null) {
+            assertSpec(spec, ElementSpec.ContentType, ElementSpec.OriginateDirection, 0, new char[] {' '});
+            Object contentModel = getModel(spec);
+            assertNotNull(contentModel);
+            assertTrue(modelClass.isAssignableFrom(contentModel.getClass()));
+        }
+    }
+
+    private Object getModel(final ElementSpec spec) {
+        return spec.getAttributes().getAttribute(StyleConstants.ModelAttribute);
+    }
+
+    private void doFormStart(final Tag tag, final String type, final AttributeSet additionalAttr) {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        if (additionalAttr != null) {
+            attr.addAttributes(additionalAttr);
+        }
+        if (type != null) {
+            attr.addAttribute(HTML.Attribute.TYPE, type);
+        }
+        attr.addAttribute("aaaa", "bbbb");
+        action = reader.new FormAction();
+        
+        action.start(tag, attr);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(2, reader.parseBuffer.size());
+    }
+    
+    private void checkEmptyFormEnd(final Tag tag, final String type) throws Exception {
+        SimpleAttributeSet attr = new SimpleAttributeSet();
+        attr.addAttribute("aaaa", "bbbb");
+        if (type != null) {
+            attr.addAttribute(HTML.Attribute.TYPE, type);
+        }
+
+        action = reader.new FormAction();
+        action.start(tag, attr);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        int numSpecs = reader.parseBuffer.size();
+        action.end(tag);
+        assertEquals(0, reader.charAttr.getAttributeCount());
+        assertEquals(numSpecs, reader.parseBuffer.size());
+    }
+}

Added: incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/HTMLDocument_RunElementTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/HTMLDocument_RunElementTest.java?rev=427121&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/HTMLDocument_RunElementTest.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/HTMLDocument_RunElementTest.java Mon Jul 31 07:08:47 2006
@@ -0,0 +1,103 @@
+/*
+ *  Copyright 2005 - 2006 The Apache Software Software Foundation or its licensors, as applicable.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+/**
+* @author Alexander T. Simbirtsev
+* @version $Revision$
+*/
+package javax.swing.text.html;
+
+import javax.swing.text.AbstractDocument_LeafElementTest;
+import javax.swing.text.StyleConstants;
+import javax.swing.text.AbstractDocument.AbstractElement;
+import javax.swing.text.AbstractDocument.BranchElement;
+import javax.swing.text.html.HTMLDocument.RunElement;
+import javax.swing.text.html.HTMLDocument_BlockElementTest.LockableHTMLDocument;
+
+public class HTMLDocument_RunElementTest extends
+        AbstractDocument_LeafElementTest {
+
+    protected LockableHTMLDocument htmlDoc;
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        htmlDoc = new LockableHTMLDocument();
+        doc = htmlDoc;
+
+        doc.insertString(0, "0123456789", as[0]);
+
+        htmlDoc.lockWrite();
+        BranchElement branch = doc.new BranchElement(null, as[1]);
+        leaf1 = doc.new LeafElement(null, as[2], 0, 3);
+        leaf2 = doc.new LeafElement(branch, as[2], 5, 8);
+        htmlDoc.unlockWrite();
+    }
+
+    protected void tearDown() throws Exception {
+        htmlDoc = null;
+        super.tearDown();
+    }
+
+    public void testGetName() {
+        AbstractElement run = htmlDoc.new RunElement(null, null, 0, 0);
+        assertEquals("content", run.getName());
+        htmlDoc.lockWrite();
+
+        final String name = "asddsa";
+        run = htmlDoc.new RunElement(null, null, 0, 0);
+        run.addAttribute(StyleConstants.NameAttribute, name);
+        assertEquals(name, run.getName());
+    }
+
+    public void testGetResolveParent() {
+        AbstractElement parent = htmlDoc.new RunElement(null, null, 0, 0);
+        AbstractElement block = htmlDoc.new RunElement(parent, null, 0, 0);
+        assertNull(parent.getResolveParent());
+        assertNull(block.getResolveParent());
+    }
+
+    public void testLeafElement() {
+    }
+
+    public void testRunElement() {
+        htmlDoc.lockWrite();
+
+        RunElement run = htmlDoc.new RunElement(leaf1, as[2],
+                3, 9);
+
+        assertSame(leaf1, run.getParent());
+        assertSame(leaf1, run.getParentElement());
+        assertSame(run, run.getAttributes());
+        assertEquals(as[2].getAttributeCount(), run.getAttributeCount());
+        assertEquals(3, run.getStartOffset());
+        assertEquals(9, run.getEndOffset());
+
+        int[] start    = {-1,  3,  3,  3}; // start offset
+        int[] expStart = {0,  3,  3,  3};  // expectations for start offset
+        int[] end      = {9, -1,  1, 20};  // end offset
+        int[] expEnd   = {9,  0,  1, 20};  // expectations for end offset
+        int[] intEnd   = {9,  3,  3, 20};  // expectations for DRL's end offset
+        for (int i = 0; i < start.length; i++) {
+            run = htmlDoc.new RunElement(null, null, start[i], end[i]);
+            assertEquals("Start (" + i + ")", expStart[i],
+                         run.getStartOffset());
+            assertEquals("End (" + i + ")",
+                         isHarmony() ? intEnd[i] : expEnd[i],
+                         run.getEndOffset());
+        }
+
+        htmlDoc.unlockWrite();
+    }
+}



Mime
View raw message