001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Vadim L. Bogdanov
019: * @version $Revision$
020: */package javax.swing.text.html;
021:
022: import javax.swing.SwingTestCase;
023: import javax.swing.text.Element;
024: import javax.swing.text.StyleConstants;
025: import javax.swing.text.View;
026:
027: public class HTMLEditorKit_HTMLFactoryTest extends SwingTestCase {
028: private static class TestHTMLDocument extends HTMLDocument {
029: public void callWriteLock() {
030: writeLock();
031: }
032: }
033:
034: private TestHTMLDocument doc;
035: private HTMLEditorKit.HTMLFactory factory;
036:
037: public HTMLEditorKit_HTMLFactoryTest(final String name) {
038: super (name);
039: }
040:
041: protected void setUp() throws Exception {
042: super .setUp();
043:
044: setIgnoreNotImplemented(true);
045:
046: doc = new TestHTMLDocument();
047: factory = new HTMLEditorKit.HTMLFactory();
048: }
049:
050: protected void tearDown() throws Exception {
051: super .tearDown();
052: }
053:
054: public void testCreateForCONTENT() {
055: implTestCreateForTag(HTML.Tag.CONTENT,
056: "javax.swing.text.html.InlineView");
057: }
058:
059: public void testCreateForIMPLIED() {
060: implTestCreateForTag(HTML.Tag.IMPLIED,
061: "javax.swing.text.html.ParagraphView");
062: }
063:
064: public void testCreateForP() {
065: implTestCreateForTag(HTML.Tag.P,
066: "javax.swing.text.html.ParagraphView");
067: }
068:
069: public void testCreateForH1() {
070: implTestCreateForTag(HTML.Tag.H1,
071: "javax.swing.text.html.ParagraphView");
072: }
073:
074: public void testCreateForH2() {
075: implTestCreateForTag(HTML.Tag.H2,
076: "javax.swing.text.html.ParagraphView");
077: }
078:
079: public void testCreateForH3() {
080: implTestCreateForTag(HTML.Tag.H3,
081: "javax.swing.text.html.ParagraphView");
082: }
083:
084: public void testCreateForH4() {
085: implTestCreateForTag(HTML.Tag.H4,
086: "javax.swing.text.html.ParagraphView");
087: }
088:
089: public void testCreateForH5() {
090: implTestCreateForTag(HTML.Tag.H5,
091: "javax.swing.text.html.ParagraphView");
092: }
093:
094: public void testCreateForH6() {
095: implTestCreateForTag(HTML.Tag.H6,
096: "javax.swing.text.html.ParagraphView");
097: }
098:
099: public void testCreateForDT() {
100: implTestCreateForTag(HTML.Tag.DT,
101: "javax.swing.text.html.ParagraphView");
102: }
103:
104: public void testCreateForMENU() {
105: implTestCreateForTag(HTML.Tag.MENU,
106: "javax.swing.text.html.ListView");
107: }
108:
109: public void testCreateForDIR() {
110: implTestCreateForTag(HTML.Tag.DIR,
111: "javax.swing.text.html.ListView");
112: }
113:
114: public void testCreateForUL() {
115: implTestCreateForTag(HTML.Tag.UL,
116: "javax.swing.text.html.ListView");
117: }
118:
119: public void testCreateForOL() {
120: implTestCreateForTag(HTML.Tag.OL,
121: "javax.swing.text.html.ListView");
122: }
123:
124: public void testCreateForLI() {
125: View view = implTestCreateForTag(HTML.Tag.LI,
126: "javax.swing.text.html.BlockView");
127: assertEquals(View.Y_AXIS, ((BlockView) view).getAxis());
128: }
129:
130: public void testCreateForDL() {
131: View view = implTestCreateForTag(HTML.Tag.DL,
132: "javax.swing.text.html.BlockView");
133: assertEquals(View.Y_AXIS, ((BlockView) view).getAxis());
134: }
135:
136: public void testCreateForDD() {
137: View view = implTestCreateForTag(HTML.Tag.DD,
138: "javax.swing.text.html.BlockView");
139: assertEquals(View.Y_AXIS, ((BlockView) view).getAxis());
140: }
141:
142: public void testCreateForBODY() {
143: doc.callWriteLock();
144: Element elem = doc.getDefaultRootElement();
145: setTag(elem, HTML.Tag.BODY);
146: View view = factory.create(elem);
147: assertTrue(view instanceof BlockView);
148: assertEquals(View.Y_AXIS, ((BlockView) view).getAxis());
149: }
150:
151: public void testCreateForHTML() {
152: View view = implTestCreateForTag(HTML.Tag.HTML,
153: "javax.swing.text.html.BlockView");
154: assertEquals(View.Y_AXIS, ((BlockView) view).getAxis());
155: }
156:
157: public void testCreateForCENTER() {
158: View view = implTestCreateForTag(HTML.Tag.CENTER,
159: "javax.swing.text.html.BlockView");
160: assertEquals(View.Y_AXIS, ((BlockView) view).getAxis());
161: }
162:
163: public void testCreateForDIV() {
164: View view = implTestCreateForTag(HTML.Tag.DIV,
165: "javax.swing.text.html.BlockView");
166: assertEquals(View.Y_AXIS, ((BlockView) view).getAxis());
167: }
168:
169: public void testCreateForBLOCKQUOTE() {
170: View view = implTestCreateForTag(HTML.Tag.BLOCKQUOTE,
171: "javax.swing.text.html.BlockView");
172: assertEquals(View.Y_AXIS, ((BlockView) view).getAxis());
173: }
174:
175: public void testCreateForPRE() {
176: View view = implTestCreateForTag(HTML.Tag.PRE,
177: "javax.swing.text.html.BlockView");
178: assertEquals(View.Y_AXIS, ((BlockView) view).getAxis());
179: }
180:
181: public void testCreateForIMG() {
182: implTestCreateForTag(HTML.Tag.IMG,
183: "javax.swing.text.html.ImageView");
184: }
185:
186: public void testCreateForHR() {
187: if (isHarmony()) {
188: implTestCreateForTag(HTML.Tag.HR,
189: "javax.swing.text.html.HRuleTagView");
190: }
191: }
192:
193: public void testCreateForBR() {
194: implTestCreateForTag(HTML.Tag.BR,
195: "javax.swing.text.html.BRView");
196: }
197:
198: public void testCreateForTABLE() {
199: if (isHarmony()) {
200: implTestCreateForTag(HTML.Tag.TABLE,
201: "javax.swing.text.html.TableTagView");
202: }
203: }
204:
205: public void testCreateForINPUT() {
206: implTestCreateForTag(HTML.Tag.INPUT,
207: "javax.swing.text.html.FormView");
208: }
209:
210: public void testCreateForSELECT() {
211: implTestCreateForTag(HTML.Tag.SELECT,
212: "javax.swing.text.html.FormView");
213: }
214:
215: public void testCreateForTEXTAREA() {
216: implTestCreateForTag(HTML.Tag.TEXTAREA,
217: "javax.swing.text.html.FormView");
218: }
219:
220: public void testCreateForOBJECT() {
221: implTestCreateForTag(HTML.Tag.OBJECT,
222: "javax.swing.text.html.ObjectView");
223: }
224:
225: public void testCreateForFRAMESET() {
226: if (isHarmony()) {
227: implTestCreateForTag(HTML.Tag.FRAMESET,
228: "javax.swing.text.html.FrameSetTagView");
229: }
230: }
231:
232: public void testCreateForFRAME() {
233: if (isHarmony()) {
234: implTestCreateForTag(HTML.Tag.FRAME,
235: "javax.swing.text.html.FrameTagView");
236: }
237: }
238:
239: private View implTestCreateForTag(final HTML.Tag tag,
240: final String expected) {
241: doc.callWriteLock();
242: Element elem = doc.getDefaultRootElement();
243: ((HTMLDocument.BlockElement) elem).addAttribute(
244: HTML.Attribute.ROWS, "1");
245: setTag(elem, tag);
246: View result = factory.create(elem);
247: assertEquals(expected, result.getClass().getName());
248: return result;
249: }
250:
251: private void setTag(final Element elem, final HTML.Tag tag) {
252: ((HTMLDocument.BlockElement) elem).addAttribute(
253: StyleConstants.NameAttribute, tag);
254: }
255: }
|