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

File EditWYSIWYGTest.java

 
testUploadImageAfterPreview: Timed out after 10 seconds waiting for org.xwiki.test.ui....
testUndoRepeatedPaste: expected:<[qqq]> but was:<[]>
 

Code metrics

2
90
9
1
298
169
10
0.11
10
9
1.11

Classes

Class Line # Actions
EditWYSIWYGTest 42 90 0% 10 17
0.8316831683.2%
 

Contributing tests

This file is covered by 9 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.wysiwyg.test.ui;
21   
22    import java.net.URLDecoder;
23   
24    import org.junit.Assert;
25    import org.junit.Test;
26    import org.openqa.selenium.Keys;
27    import org.openqa.selenium.WebElement;
28    import org.xwiki.test.ui.browser.IgnoreBrowser;
29    import org.xwiki.test.ui.browser.IgnoreBrowsers;
30    import org.xwiki.test.ui.po.editor.wysiwyg.RichTextAreaElement;
31    import org.xwiki.wysiwyg.test.po.EditorElement;
32    import org.xwiki.wysiwyg.test.po.TableConfigPane;
33    import org.xwiki.wysiwyg.test.po.UploadImagePane;
34    import org.xwiki.wysiwyg.test.po.WYSIWYGEditPage;
35   
36    /**
37    * Test WYSIWYG content editing.
38    *
39    * @version $Id: 1ed8d88606de30df003ca80022637a70f5afeb54 $
40    * @since 3.0M2
41    */
 
42    public class EditWYSIWYGTest extends AbstractWYSIWYGEditorTest
43    {
44    /**
45    * Tests that images are uploaded fine after a preview.
46    *
47    * @see <a href="http://jira.xwiki.org/jira/browse/XWIKI-5895">XWIKI-5895</a>: Adding an image in the WYSIWYG editor
48    * and previewing it without saving the page first makes the XWiki page corrupt.
49    **/
 
50  0 toggle @Test
51    @IgnoreBrowsers({
52    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
53    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
54    })
55    public void testUploadImageAfterPreview() throws Exception
56    {
57  0 this.editPage.clickPreview().clickBackToEdit();
58    // Recreate the page object because the page has been reloaded.
59  0 Test failure here this.editPage = new WYSIWYGEditPage().waitUntilPageIsLoaded();
60  0 UploadImagePane uploadImagePane = this.editPage.insertAttachedImage().selectFromCurrentPage().uploadImage();
61    // URL#getPath() returns the path URL-encoded and the file upload input doesn't expect this. Normally we
62    // shouldn't have special characters in the path but some CI jobs have spaces in their names
63    // (e.g. "xwiki-platform Quality Checks") which are encoded as %20. The file upload hangs if we pass the path
64    // with encoded spaces.
65  0 String path = URLDecoder.decode(this.getClass().getResource("/image.png").getPath(), "UTF-8");
66  0 uploadImagePane.setImageToUpload(path);
67    // Fails if the image configuration step doesn't load in a decent amount of time.
68  0 uploadImagePane.configureImage();
69    }
70   
71    /**
72    * @see "XWIKI:7028: Strange behaviour when pressing back and forward on a page that has 2 WYSIWYG editors
73    * displayed."
74    */
 
75  1 toggle @Test
76    @IgnoreBrowsers({
77    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
78    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
79    })
80    public void testBackForwardCache()
81    {
82  1 StringBuilder code = new StringBuilder();
83  1 code.append("; Description\n");
84  1 code.append(": {{html}}<textarea id=\"description\">f&gt;o**o**</textarea>{{/html}}\n");
85  1 code.append("; Summary\n");
86  1 code.append(": {{html}}<textarea id=\"summary\">b&lt;a//r//</textarea>{{/html}}\n\n");
87   
88  1 code.append("{{velocity}}\n");
89  1 code.append("{{html}}\n");
90  1 code.append("#wysiwyg_editProperty($tdoc 'description')\n");
91  1 code.append("#wysiwyg_editProperty($tdoc 'summary')\n");
92  1 code.append("{{/html}}\n");
93  1 code.append("{{/velocity}}");
94   
95    // Create a page with 2 WYSIWYG editors.
96  1 getUtil().createPage(getTestClassName(), getTestMethodName(), code.toString(), null);
97   
98  1 EditorElement descriptionEditor = new EditorElement("description").waitToLoad();
99  1 EditorElement summaryEditor = new EditorElement("summary").waitToLoad();
100   
101  1 String description = descriptionEditor.getRichTextArea().getText();
102  1 String summary = summaryEditor.getRichTextArea().getText();
103  1 getDriver().navigate().back();
104  1 getDriver().navigate().forward();
105   
106  1 descriptionEditor = new EditorElement("description").waitToLoad();
107  1 summaryEditor = new EditorElement("summary").waitToLoad();
108   
109  1 Assert.assertEquals(description, descriptionEditor.getRichTextArea().getText());
110  1 Assert.assertEquals(summary, summaryEditor.getRichTextArea().getText());
111    }
112   
113    /**
114    * Test that the content of the rich text area is preserved when the user refreshes the page.
115    */
 
116  1 toggle @Test
117    @IgnoreBrowsers({
118    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
119    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
120    })
121    public void testPreserveUnsavedRichContentAgainstRefresh()
122    {
123    // Type text and refresh the page.
124  1 this.editPage.getContentEditor().getRichTextArea().sendKeys("2");
125  1 this.editPage.sendKeys(Keys.F5);
126   
127  1 this.editPage = new WYSIWYGEditPage();
128  1 EditorElement editor = this.editPage.getContentEditor();
129  1 editor.waitToLoad();
130   
131    // Type more text and check the result.
132  1 RichTextAreaElement textArea = editor.getRichTextArea();
133  1 textArea.sendKeys("1");
134  1 Assert.assertEquals("12", textArea.getText());
135    }
136   
137    /**
138    * Test that the content of the source text area is preserved when the user refreshes the page.
139    */
 
140  1 toggle @Test
141    @IgnoreBrowsers({
142    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
143    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
144    })
145    public void testPreserveUnsavedSourceAgainstRefresh()
146    {
147  1 EditorElement editor = this.editPage.getContentEditor();
148  1 editor.switchToSource();
149   
150    // Type text and refresh the page.
151  1 editor.getSourceTextArea().sendKeys("1" + Keys.F5);
152   
153  1 this.editPage = new WYSIWYGEditPage();
154  1 editor = this.editPage.getContentEditor();
155  1 editor.waitToLoad();
156  1 editor.switchToSource();
157   
158    // Type more text and check the result.
159  1 editor.getSourceTextArea().sendKeys("2");
160  1 Assert.assertEquals("12", editor.getSourceTextArea().getAttribute("value"));
161    }
162   
163    /**
164    * Tests that the currently active editor (WYSIWYG or Source) is preserved when the user refreshes the page.
165    */
 
166  1 toggle @Test
167    @IgnoreBrowsers({
168    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
169    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
170    })
171    public void testPreserveSelectedEditorAgainstRefresh()
172    {
173    // The WYSIWYG editor should be initially active.
174  1 EditorElement editor = this.editPage.getContentEditor();
175  1 Assert.assertFalse(editor.getSourceTextArea().isEnabled());
176   
177    // Switch to Source editor and refresh the page.
178  1 editor.switchToSource();
179  1 editor.getSourceTextArea().sendKeys(Keys.F5);
180   
181  1 this.editPage = new WYSIWYGEditPage();
182  1 editor = this.editPage.getContentEditor();
183  1 editor.waitToLoad();
184   
185    // The Source editor should be active now because it was selected before the refresh.
186  1 Assert.assertTrue(editor.getSourceTextArea().isEnabled());
187   
188    // Switch to WYSIWYG editor and refresh the page again.
189  1 editor.switchToWysiwyg();
190  1 this.editPage.sendKeys(Keys.F5);
191   
192  1 this.editPage = new WYSIWYGEditPage();
193  1 editor = this.editPage.getContentEditor();
194  1 editor.waitToLoad();
195   
196    // The WYSIWYG editor should be active now because it was selected before the refresh.
197  1 Assert.assertFalse(editor.getSourceTextArea().isEnabled());
198    }
199   
200    /**
201    * Test if an undo step reverts only one paste operation from a sequence, and not all of them.
202    */
 
203  0 toggle @Test
204    @IgnoreBrowsers({
205    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146"),
206    @IgnoreBrowser(value = "internet.*", version = "9\\.*", reason="See http://jira.xwiki.org/browse/XE-1177")
207    })
208    public void testUndoRepeatedPaste()
209    {
210  0 EditorElement editor = this.editPage.getContentEditor();
211  0 RichTextAreaElement textArea = editor.getRichTextArea();
212    // Type text, select it (Shift+LeftArrow) and copy it (Control+C).
213    // NOTE: We don't use Control+A to select the text because it selects also the BR element.
214  0 textArea.sendKeys("q", Keys.chord(Keys.SHIFT, Keys.ARROW_LEFT), Keys.chord(Keys.CONTROL, "c"));
215    // Then paste it 4 times (Control+V).
216  0 for (int i = 0; i < 4; i++) {
217    // Release the key after each paste so that the history records an entry for each paste. In case the paste
218    // content is cleaned automatically, the editor cleans consecutive paste events (that happen one after
219    // another) together and so a single history entry is recorded for such a group of paste events.
220  0 textArea.sendKeys(Keys.chord(Keys.CONTROL, "v"));
221    }
222    // Undo the last paste.
223  0 editor.getToolBar().clickUndoButton();
224  0 Test failure here Assert.assertEquals("qqq", textArea.getText());
225    }
226   
227    /**
228    * @see "XWIKI-4230: 'Tab' doesn't work in the Table Dialog in FF 3.5.2"
229    */
 
230  1 toggle @Test
231    public void testTabInTableConfigDialog()
232    {
233  1 TableConfigPane tableConfig = this.editPage.insertTable();
234   
235    // Assert that the row count input has the focus.
236  1 Assert.assertEquals(tableConfig.getRowCountInput(), getDriver().switchTo().activeElement());
237  1 getDriver().switchTo().defaultContent();
238   
239    // Press Tab to move the focus to the next input.
240  1 tableConfig.getRowCountInput().sendKeys(Keys.TAB);
241   
242    // Assert that the column count input has the focus.
243  1 Assert.assertEquals(tableConfig.getColumnCountInput(), getDriver().switchTo().activeElement());
244  1 getDriver().switchTo().defaultContent();
245    }
246   
247    /**
248    * Test that hitting the . (dot) key at the end of a list item does not act as delete.
249    *
250    * @see <a href="http://jira.xwiki.org/jira/browse/XWIKI-3304">XWIKI-3304</a>
251    */
 
252  1 toggle @Test
253    @IgnoreBrowser(value = "internet.*", version = "8\\.*", reason="See http://jira.xwiki.org/browse/XE-1146")
254    public void testDotAtEndDoesNotDelete()
255    {
256  1 EditorElement editor = this.editPage.getContentEditor();
257   
258    // Create a list with two items.
259  1 editor.switchToSource();
260  1 WebElement sourceTextArea = editor.getSourceTextArea();
261  1 sourceTextArea.clear();
262  1 sourceTextArea.sendKeys("* foo\n* bar");
263  1 editor.switchToWysiwyg();
264   
265    // Place the caret at the end of the first item and type dot.
266  1 RichTextAreaElement textArea = editor.getRichTextArea();
267  1 textArea.sendKeys(Keys.ARROW_RIGHT, Keys.ARROW_RIGHT, Keys.ARROW_RIGHT, ".");
268   
269  1 Assert.assertEquals("foo.\nbar", textArea.getText());
270    }
271   
272    /**
273    * @see "XWIKI-3039: Changes are lost if an exception is thrown during saving"
274    * @see "XWIKI-9750: User Input in WYSIWYG Editor is lost after conversion error"
275    */
 
276  1 toggle @Test
277    public void testRecoverAfterConversionException()
278    {
279  1 EditorElement editor = this.editPage.getContentEditor();
280   
281    // We removed the startwikilink comment to force a parsing failure.
282  1 String html = "<span class=\"wikiexternallink\"><a href=\"mailto:x@y.z\">xyz</a></span><!--stopwikilink-->";
283  1 editor.getRichTextArea().setContent(html);
284   
285    // Test to see if the HTML was accepted by the rich text area.
286  1 Assert.assertEquals("xyz", editor.getRichTextArea().getText());
287   
288    // Save & Continue should notify us about the conversion error.
289  1 this.editPage.clickSaveAndContinue(false);
290  1 this.editPage.waitForNotificationErrorMessage("Failed to save the page. "
291    + "Reason: content: Exception while parsing HTML");
292   
293    // Save & View should redirect us back to the edit mode, but the unsaved changes shouldn't be lost.
294  1 this.editPage.clickSaveAndView();
295  1 this.editPage = new WYSIWYGEditPage().waitUntilPageIsLoaded();
296  1 Assert.assertEquals("xyz", this.editPage.getContentEditor().getRichTextArea().getText());
297    }
298    }