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 Alexey A. Ivanov
019: * @version $Revision$
020: */package javax.swing.text.html;
021:
022: import javax.swing.BasicSwingTestCase;
023: import javax.swing.text.MutableAttributeSet;
024: import javax.swing.text.SimpleAttributeSet;
025: import javax.swing.text.html.CSS.Attribute;
026:
027: public class StyleSheet_ConvertAttr_BackgroundTest extends
028: BasicSwingTestCase {
029: private StyleSheet ss;
030: private MutableAttributeSet simple;
031:
032: protected void setUp() throws Exception {
033: super .setUp();
034: ss = new StyleSheet();
035: simple = new SimpleAttributeSet();
036: }
037:
038: public void testBackground01() {
039: ss.addCSSAttribute(simple, Attribute.BACKGROUND,
040: "red no-repeat");
041:
042: assertAttributes("red", isHarmony() ? "none" : null,
043: "no-repeat", "scroll", isHarmony() ? "0% 0%" : null);
044: }
045:
046: public void testBackground02() {
047: ss.addCSSAttribute(simple, Attribute.BACKGROUND,
048: "no-repeat red");
049:
050: assertAttributes("red", isHarmony() ? "none" : null,
051: "no-repeat", "scroll", isHarmony() ? "0% 0%" : null);
052: }
053:
054: public void testBackground03() {
055: ss.addCSSAttribute(simple, Attribute.BACKGROUND,
056: "no-repeat red fixed url(bg.jpg)");
057:
058: assertAttributes("red", "url(bg.jpg)", "no-repeat", "fixed",
059: isHarmony() ? "0% 0%" : null);
060: }
061:
062: public void testBackground04() {
063: ss.addCSSAttribute(simple, Attribute.BACKGROUND,
064: "no-repeat red fixed url('bg.jpg') top");
065:
066: assertAttributes("red", "url('bg.jpg')", "no-repeat", "fixed",
067: "top");
068: }
069:
070: public void testBackground05() {
071: ss.addCSSAttribute(simple, Attribute.BACKGROUND,
072: "no-repeat red fixed url(\"bg.jpg\") top center");
073:
074: assertAttributes("red", "url(\"bg.jpg\")", "no-repeat",
075: "fixed", "top center");
076: }
077:
078: public void testBackground06() {
079: ss.addCSSAttribute(simple, Attribute.BACKGROUND,
080: "no-repeat red fixed url(\"bg.jpg\") top top");
081: if (isHarmony()) {
082: assertEquals(0, simple.getAttributeCount());
083: return;
084: }
085:
086: assertAttributes("red", "url(\"bg.jpg\")", "no-repeat",
087: "fixed", "top top");
088: }
089:
090: public void testBackground07() {
091: ss.addCSSAttribute(simple, Attribute.BACKGROUND,
092: "no-repeat red url(\"bg.jpg scroll");
093: if (isHarmony()) {
094: assertEquals(0, simple.getAttributeCount());
095: return;
096: }
097:
098: assertAttributes("red", null, "no-repeat", "scroll", null);
099: }
100:
101: public void testBackground08() {
102: ss.addCSSAttribute(simple, Attribute.BACKGROUND,
103: "repeat-x blue bg.jpg scroll");
104: if (isHarmony()) {
105: assertEquals(0, simple.getAttributeCount());
106: return;
107: }
108:
109: assertAttributes("blue", null, "repeat-x", "scroll", null);
110: }
111:
112: public void testBackground09() {
113: ss.addCSSAttribute(simple, Attribute.BACKGROUND,
114: "repeat-x #AABBCC fixed");
115:
116: assertAttributes("#AABBCC", isHarmony() ? "none" : null,
117: "repeat-x", "fixed", isHarmony() ? "0% 0%" : null);
118: }
119:
120: public void testBackground10() {
121: ss.addCSSAttribute(simple, Attribute.BACKGROUND,
122: "repeat-y none rgb(50%, 100%, 25%) fixed center");
123:
124: assertAttributes(isHarmony() ? "rgb(50%, 100%, 25%)"
125: : "rgb(50%,", isHarmony() ? "none" : null, "repeat-y",
126: "fixed", isHarmony() ? "center" : "100%, 25%)");
127: }
128:
129: public void testBackground11() {
130: ss.addCSSAttribute(simple, Attribute.BACKGROUND,
131: "repeat-y none green fixed center repeat");
132: if (isHarmony()) {
133: assertEquals(0, simple.getAttributeCount());
134: return;
135: }
136:
137: assertAttributes("green", null, "repeat-y", "fixed", "center");
138: }
139:
140: public void testBackground12() {
141: ss.addCSSAttribute(simple, Attribute.BACKGROUND, "none none");
142: if (!isHarmony()) {
143: return;
144: }
145: assertEquals(0, simple.getAttributeCount());
146: }
147:
148: public void testBackground13() {
149: ss.addCSSAttribute(simple, Attribute.BACKGROUND, "black white");
150: if (!isHarmony()) {
151: return;
152: }
153: assertEquals(0, simple.getAttributeCount());
154: }
155:
156: public void testBackground14() {
157: ss
158: .addCSSAttribute(simple, Attribute.BACKGROUND,
159: "fixed scroll");
160: if (!isHarmony()) {
161: return;
162: }
163: assertEquals(0, simple.getAttributeCount());
164: }
165:
166: public void testBackground15() {
167: ss.addCSSAttribute(simple, Attribute.BACKGROUND,
168: "50% blue url(bg.jpg) top");
169: if (!isHarmony()) {
170: return;
171: }
172: assertEquals(0, simple.getAttributeCount());
173: }
174:
175: public void testBackground16() {
176: ss.addCSSAttribute(simple, Attribute.BACKGROUND,
177: "50% fixed url(bg.jpg) 10px");
178: if (!isHarmony()) {
179: return;
180: }
181: assertAttributes("transparent", "url(bg.jpg)", "repeat",
182: "fixed", "50% 10px");
183: }
184:
185: public void testBackground17() {
186: ss.addCSSAttribute(simple, Attribute.BACKGROUND,
187: "url(bg.jpg) none");
188: if (!isHarmony()) {
189: return;
190: }
191: assertEquals(0, simple.getAttributeCount());
192: }
193:
194: public void testBackground18() {
195: ss.addCSSAttribute(simple, Attribute.BACKGROUND,
196: "fixed url(bg.jpg) left top transparent");
197: if (!isHarmony()) {
198: return;
199: }
200: assertAttributes("transparent", "url(bg.jpg)", "repeat",
201: "fixed", "left top");
202: }
203:
204: private void assertAttributes(final String color,
205: final String image, final String repeat,
206: final String attachment, final String position) {
207: // assertEquals("Attribute count",
208: // isHarmony() ? 5 : 4, simple.getAttributeCount());
209:
210: assertEquals("background-color", color,
211: getCSSAttribute(Attribute.BACKGROUND_COLOR));
212: assertEquals("background-image", image,
213: getCSSAttribute(Attribute.BACKGROUND_IMAGE));
214: assertEquals("background-repeat", repeat,
215: getCSSAttribute(Attribute.BACKGROUND_REPEAT));
216: assertEquals("background-attachment", attachment,
217: getCSSAttribute(Attribute.BACKGROUND_ATTACHMENT));
218: assertEquals("background-position", position,
219: getCSSAttribute(Attribute.BACKGROUND_POSITION));
220: }
221:
222: private String getCSSAttribute(final Attribute cssKey) {
223: final Object result = simple.getAttribute(cssKey);
224: return result != null ? result.toString() : null;
225: }
226:
227: }
|