1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.test.wysiwyg

File FontTest.java

 

Code metrics

0
60
12
1
209
114
12
0.2
5
12
1

Classes

Class Line # Actions
FontTest 31 60 0% 12 0
1.0100%
 

Contributing tests

This file is covered by 8 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.test.wysiwyg;
21   
22    import org.junit.Test;
23    import org.openqa.selenium.By;
24    import org.xwiki.test.wysiwyg.framework.AbstractWysiwygTestCase;
25   
26    /**
27    * Functional tests for font support inside the WYSIWYG editor.
28    *
29    * @version $Id: ded3897c0374149094a888a3116b94e605f4f91a $
30    */
 
31    public class FontTest extends AbstractWysiwygTestCase
32    {
33    /**
34    * The XPath selector used to access the font size list box.
35    */
36    private static final String FONT_SIZE_SELECTOR = "//select[@title=\"Font Size\"]";
37   
38    /**
39    * The XPath selector used to access the font name list box.
40    */
41    private static final String FONT_NAME_SELECTOR = "//select[@title=\"Font Name\"]";
42   
43    /**
44    * Selects a plain text and applies a specific font size.
45    *
46    * @see XWIKI-3295: Font size are not handled properly
47    */
 
48  1 toggle @Test
49    public void testSetFontSizeOnAPlainTextSelection()
50    {
51  1 typeText("abc");
52  1 select("document.body.firstChild", 1, "document.body.firstChild", 2);
53  1 applyFontSize("24px");
54  1 switchToSource();
55  1 assertSourceText("a(% style=\"font-size: 24px;\" %)b(%%)c");
56    }
57   
58    /**
59    * Selects a plain text and applies a specific font name.
60    */
 
61  1 toggle @Test
62    public void testSetFontNameOnAPlainTextSelection()
63    {
64  1 typeText("abc");
65  1 select("document.body.firstChild", 1, "document.body.firstChild", 2);
66  1 applyFontName("Georgia");
67  1 switchToSource();
68  1 assertSourceText("a(% style=\"font-family: Georgia;\" %)b(%%)c");
69    }
70   
71    /**
72    * Selects a plain text and applies a specific font name and font size.
73    */
 
74  1 toggle @Test
75    public void testSetFontNameAndSizeOnAPlainTextSelection()
76    {
77  1 typeText("abc");
78  1 select("document.body.firstChild", 1, "document.body.firstChild", 2);
79  1 applyFontName("Arial");
80  1 applyFontSize("18px");
81  1 switchToSource();
82  1 assertSourceText("a(% style=\"font-family: Arial; font-size: 18px;\" %)b(%%)c");
83    }
84   
85    /**
86    * Test if the font size and font name are detected correctly.
87    */
 
88  1 toggle @Test
89    public void testDetectFont()
90    {
91  1 switchToSource();
92  1 setSourceText("(% style=\"font-size: 24px; font-family: foo,verdana,sans-serif\" %)\nabc");
93  1 switchToWysiwyg();
94  1 selectAllContent();
95  1 waitForDetectedFontSize("24px");
96  1 waitForDetectedFontName("Verdana");
97    }
98   
99    /**
100    * Test if a known font name (contained in the list box) that is not supported by the current browser is correctly
101    * detected.
102    */
 
103  1 toggle @Test
104    public void testDetectKnownUnsupportedFontName()
105    {
106  1 switchToSource();
107  1 setSourceText("(% style=\"font-family: wingdings\" %)\nabc");
108  1 switchToWysiwyg();
109  1 selectAllContent();
110  1 waitForDetectedFontName("Wingdings");
111   
112  1 switchToSource();
113  1 setSourceText("(% style=\"font-family: wingdings,arial\" %)\nabc");
114  1 switchToWysiwyg();
115  1 selectAllContent();
116  1 waitForDetectedFontName("Arial");
117    }
118   
119    /**
120    * Tests if an unknown font name if detected.
121    */
 
122  1 toggle @Test
123    public void testDetectUnknownFontName()
124    {
125  1 switchToSource();
126  1 setSourceText("(% style=\"font-family: unknown\" %)\nabc");
127  1 switchToWysiwyg();
128  1 selectAllContent();
129  1 waitForDetectedFontName("unknown");
130   
131  1 switchToSource();
132  1 setSourceText("(% style=\"font-family: unknown,arial\" %)\nabc");
133  1 switchToWysiwyg();
134  1 selectAllContent();
135  1 waitForDetectedFontName("Arial");
136    }
137   
138    /**
139    * Detect a font size that is not listed.
140    */
 
141  1 toggle @Test
142    public void testDetectUnlistedFontSize()
143    {
144  1 switchToSource();
145  1 setSourceText("(% style=\"font-size: 21px\" %)\nabc");
146  1 switchToWysiwyg();
147  1 selectAllContent();
148  1 waitForDetectedFontSize("21px");
149    }
150   
151    /**
152    * Test if the font name for a cross paragraph selection is correctly detected.
153    */
 
154  1 toggle @Test
155    public void testDetectFontNameOnCrossParagraphSelection()
156    {
157  1 switchToSource();
158  1 setSourceText("(% style=\"font-family: courier new\" %)\nabc\n\n(% style=\"font-family: times new roman\" %)\nxyz");
159  1 switchToWysiwyg();
160  1 moveCaret("document.body.getElementsByTagName('p')[0].firstChild", 1);
161  1 waitForDetectedFontName("Courier New");
162  1 moveCaret("document.body.getElementsByTagName('p')[1].firstChild", 1);
163  1 waitForDetectedFontName("Times New Roman");
164  1 select("document.body.getElementsByTagName('p')[0].firstChild", 1,
165    "document.body.getElementsByTagName('p')[1].firstChild", 1);
166  1 waitForDetectedFontName("");
167    }
168   
169    /**
170    * Selects a font size from the list box.
171    *
172    * @param fontSize the font size to select from the list box
173    */
 
174  2 toggle protected void applyFontSize(String fontSize)
175    {
176  2 getSelenium().select(FONT_SIZE_SELECTOR, fontSize);
177    }
178   
179    /**
180    * Selects a font name from the list box.
181    *
182    * @param fontName the font name to select from the list box
183    */
 
184  2 toggle protected void applyFontName(String fontName)
185    {
186  2 getSelenium().select(FONT_NAME_SELECTOR, fontName);
187    }
188   
189    /**
190    * Waits for the editor to detect the font size of the current selection and asserts if the detected font size
191    * equals the expected font size.
192    *
193    * @param expectedFontSize the expected font size
194    */
 
195  2 toggle protected void waitForDetectedFontSize(final String expectedFontSize)
196    {
197  2 getDriver().waitUntilElementHasAttributeValue(By.xpath(FONT_SIZE_SELECTOR), "value", expectedFontSize);
198    }
199   
200    /**
201    * Asserts if the detected font name equals the expected font name.
202    *
203    * @param expectedFontName the expected font name
204    */
 
205  8 toggle protected void waitForDetectedFontName(final String expectedFontName)
206    {
207  8 getDriver().waitUntilElementHasAttributeValue(By.xpath(FONT_NAME_SELECTOR), "value", expectedFontName);
208    }
209    }