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

File CacheTest.java

 

Code metrics

0
52
4
1
148
75
4
0.08
13
4
1

Classes

Class Line # Actions
CacheTest 33 52 0% 4 0
1.0100%
 

Contributing tests

This file is covered by 4 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.xwiki.test.wysiwyg.framework.AbstractWysiwygTestCase;
24   
25    import static org.junit.Assert.*;
26   
27    /**
28    * Tests if the state of the WYSIWYG editor is preserved (cached) against the browser's Back button and the "soft" page
29    * refresh.
30    *
31    * @version $Id: 1ccdb0bb248b4967ce438dad9c7c06f0e757511d $
32    */
 
33    public class CacheTest extends AbstractWysiwygTestCase
34    {
35    /**
36    * Test that the content of the rich text area is preserved when the user leaves the editing without saving and then
37    * comes back.
38    */
 
39  1 toggle @Test
40    public void testPreserveUnsavedRichContentAgainstBackButton()
41    {
42    // Type text and cancel edition.
43  1 typeText("1");
44  1 clickEditCancelEdition();
45  1 getSelenium().goBack();
46  1 waitPage();
47  1 waitForEditorToLoad();
48   
49    // Type text and leave the editing by clicking on a link.
50  1 typeText("2");
51  1 getSelenium().click("//a[. = '" + getTestMethodName() + "']");
52  1 waitPage();
53  1 getSelenium().goBack();
54  1 waitPage();
55  1 waitForEditorToLoad();
56   
57    // Check the result.
58  1 typeText("3");
59  1 switchToSource();
60  1 assertSourceText("321");
61    }
62   
63    /**
64    * Test that the content of the source text area is preserved when the user leaves the editing without saving and
65    * then comes back.
66    */
 
67  1 toggle @Test
68    public void testPreserveUnsavedSourceAgainstBackButton()
69    {
70  1 switchToSource();
71   
72    // Type text and cancel edition.
73  1 getSourceTextArea().sendKeys("a");
74  1 clickEditCancelEdition();
75  1 getSelenium().goBack();
76  1 waitPage();
77  1 waitForEditorToLoad();
78   
79    // Type text and leave the editing by clicking on a link.
80  1 getSourceTextArea().sendKeys("b");
81  1 getSelenium().click("//a[. = '" + getTestMethodName() + "']");
82  1 waitPage();
83  1 getSelenium().goBack();
84  1 waitPage();
85  1 waitForEditorToLoad();
86   
87    // Check the result.
88  1 getSourceTextArea().sendKeys("c");
89  1 assertSourceText("abc");
90    }
91   
92    /**
93    * Tests that the currently active editor (WYSIWYG or Source) is preserved when the user leaves the editing without
94    * saving and then comes back.
95    */
 
96  1 toggle @Test
97    public void testPreserveSelectedEditorAgainstBackButton()
98    {
99    // The WYSIWYG editor should be initially active.
100  1 assertFalse(getSourceTextArea().isEnabled());
101   
102    // Switch to Source editor, cancel the edition and then come back.
103  1 switchToSource();
104  1 clickEditCancelEdition();
105  1 getSelenium().goBack();
106  1 waitPage();
107  1 waitForEditorToLoad();
108   
109    // The Source editor should be active now because it was selected before canceling the edition.
110  1 assertTrue(getSourceTextArea().isEnabled());
111   
112    // Switch to WYSIWYG editor, leave editing and then come back.
113  1 switchToWysiwyg();
114  1 getSelenium().click("//a[. = '" + getTestMethodName() + "']");
115  1 waitPage();
116  1 getSelenium().goBack();
117  1 waitPage();
118  1 waitForEditorToLoad();
119   
120    // The WYSIWYG editor should be active now because it was selected before we left the edit mode.
121  1 assertFalse(getSourceTextArea().isEnabled());
122    }
123   
124    /**
125    * @see XWIKI-4162: When in edit mode (all editors) back/forward looses the content you have changed
126    */
 
127  1 toggle @Test
128    public void testBackForwardCache()
129    {
130    // Make sure we can go back.
131  1 clickEditCancelEdition();
132  1 clickEditPageInWysiwyg();
133  1 waitForEditorToLoad();
134    // Write some text.
135  1 typeText("123");
136    // Go back.
137  1 getSelenium().goBack();
138  1 waitPage();
139    // Go forward.
140    // See http://jira.openqa.org/browse/SEL-543 (Simulate forward button in browser).
141  1 getSelenium().runScript("window.history.forward()");
142  1 waitPage();
143    // Make sure the rich text area is loaded.
144  1 waitForEditorToLoad();
145    // Assert the text content.
146  1 assertEquals("123", getRichTextArea().getText());
147    }
148    }