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

File EditRightsPane.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart6.png
69% of files have more coverage

Code metrics

8
41
14
3
202
128
18
0.44
2.93
4.67
1.29

Classes

Class Line # Actions
EditRightsPane 33 34 0% 13 24
0.5252%
EditRightsPane.Right 36 1 0% 1 0
1.0100%
EditRightsPane.State 53 6 0% 4 1
0.9090909490.9%
 

Contributing tests

This file is covered by 1 test. .

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.ui.po;
21   
22    import org.openqa.selenium.By;
23    import org.openqa.selenium.WebElement;
24    import org.openqa.selenium.support.FindBy;
25   
26    /**
27    * Class that holds the types of Rights and the types of States of a check-box
28    *
29    * @version $Id: b005867466c23022cddee513cba85a7e48d485df $
30    * @since 3.2M3
31    */
32   
 
33    public class EditRightsPane extends BaseElement
34    {
35    /** The known access rights. */
 
36    public enum Right
37    {
38    VIEW,
39    COMMENT,
40    EDIT,
41    DELETE,
42    ADMIN,
43    REGISTER,
44    PROGRAM;
45   
 
46  3 toggle int getColumnIndex()
47    {
48  3 return this.ordinal() + 2;
49    }
50    }
51   
52    /** The possible states of an access right box. */
 
53    public enum State
54    {
55    NONE("/xwiki/resources/js/xwiki/usersandgroups/img/none.png"),
56    ALLOW("/xwiki/resources/js/xwiki/usersandgroups/img/allow.png"),
57    DENY("/xwiki/resources/js/xwiki/usersandgroups/img/deny1.png");
58   
59    String imageURL;
60   
 
61  3 toggle State(String imageURL)
62    {
63  3 this.imageURL = imageURL;
64    }
65   
 
66  1 toggle State getNextState()
67    {
68  1 return values()[(ordinal() + 1) % values().length];
69    }
70   
 
71  3 toggle static State getButtonState(WebElement button)
72    {
73  3 for (State s : values()) {
74  4 if ((button.getAttribute("src").endsWith(s.imageURL))) {
75  3 return s;
76    }
77    }
78  0 return NONE;
79    }
80    }
81   
82    private LiveTableElement rightsTable;
83   
84    @FindBy(id = "uorgu")
85    private WebElement showUsersField;
86   
87    @FindBy(id = "uorgg")
88    private WebElement showGroupsField;
89   
 
90  1 toggle public void switchToUsers()
91    {
92  1 this.showUsersField.click();
93  1 getRightsTable().waitUntilReady();
94    }
95   
 
96  0 toggle public void switchToGroups()
97    {
98  0 this.showGroupsField.click();
99  0 getRightsTable().waitUntilReady();
100    }
101   
 
102  0 toggle public State getGuestRight(Right right)
103    {
104  0 final By iconLocator = By.xpath("//tr[@id='unregistered']/td[" + right.getColumnIndex() + "]/img");
105  0 final WebElement icon = getDriver().findElement(iconLocator);
106  0 return State.getButtonState(icon);
107    }
108   
 
109  2 toggle public State getRight(String entityName, Right right)
110    {
111  2 final By iconLocator =
112    By.xpath("//*[@id='usersandgroupstable-display']//td[@class='username']/a[contains(@href, '" + entityName
113    + "')]/../../td[" + right.getColumnIndex() + "]/img");
114  2 final WebElement icon = getDriver().findElement(iconLocator);
115  2 return State.getButtonState(icon);
116    }
117   
 
118  0 toggle public void clickGuestRight(Right right)
119    {
120  0 try {
121  0 getDriver().executeJavascript(
122    "window.__oldConfirm = window.confirm; window.confirm = function() { return true; };");
123  0 final By buttonLocator = By.xpath("*//tr[@id='unregistered']/td[" + right.getColumnIndex() + "]/img");
124  0 final WebElement button = getDriver().findElement(buttonLocator);
125  0 State currentState = State.getButtonState(button);
126  0 button.click();
127    // Note: Selenium 2.0a4 returns a relative URL when calling getAttribute("src") but since we moved to
128    // Selenium 2.0a7 it returns a *full* URL even though the DOM has a relative URL as in:
129    // <img src="/xwiki/resources/js/xwiki/usersandgroups/img/allow.png">
130  0 getDriver().waitUntilElementEndsWithAttributeValue(buttonLocator, "src",
131    currentState.getNextState().imageURL);
132    } finally {
133  0 getDriver().executeJavascript("window.confirm = window.__oldConfirm;");
134    }
135    }
136   
137    /**
138    * Click once on a right button, waiting for the next state to appear.
139    *
140    * @param entityName the target user or group name
141    * @param right the target right
142    */
 
143  1 toggle public void clickRight(String entityName, Right right)
144    {
145  1 try {
146  1 getDriver().executeJavascript(
147    "window.__oldConfirm = window.confirm; window.confirm = function() { return true; };");
148  1 final By buttonLocator =
149    By.xpath("//*[@id='usersandgroupstable-display']//td[@class='username']/a[contains(@href, '"
150    + entityName + "')]/../../td[" + right.getColumnIndex() + "]/img");
151  1 final WebElement button = getDriver().findElement(buttonLocator);
152  1 State currentState = State.getButtonState(button).getNextState();
153  1 button.click();
154    // Note: Selenium 2.0a4 returns a relative URL when calling getAttribute("src") but since we moved to
155    // Selenium 2.0a7 it returns a *full* URL even though the DOM has a relative URL as in:
156    // <img src="/xwiki/resources/js/xwiki/usersandgroups/img/allow.png">
157  1 getDriver().waitUntilElementEndsWithAttributeValue(buttonLocator, "src", currentState.imageURL);
158    } finally {
159  1 getDriver().executeJavascript("window.confirm = window.__oldConfirm;");
160    }
161    }
162   
163    /**
164    * Click on a right button until it gets in the wanted state.
165    *
166    * @param entityName the target user or group name
167    * @param right the target right
168    * @param wantedState the wanted state for the right
169    */
 
170  1 toggle public void setRight(String entityName, Right right, State wantedState)
171    {
172  2 while (getRight(entityName, right) != wantedState) {
173  1 clickRight(entityName, right);
174    }
175    }
176   
177    /**
178    * Click on a right button until it gets in the wanted state.
179    *
180    * @param right the target right
181    * @param wantedState the wanted state for the right
182    */
 
183  0 toggle public void setGuestRight(Right right, State wantedState)
184    {
185  0 while (getGuestRight(right) != wantedState) {
186  0 clickGuestRight(right);
187    }
188    }
189   
 
190  0 toggle public String getURL(String space, String page)
191    {
192  0 return getUtil().getURL(space, page, "edit", "editor=rights");
193    }
194   
 
195  1 toggle public LiveTableElement getRightsTable()
196    {
197  1 if (this.rightsTable == null) {
198  1 this.rightsTable = new LiveTableElement("usersandgroupstable");
199    }
200  1 return this.rightsTable;
201    }
202    }