Author: andrei_exadel
Date: 2008-11-26 06:11:49 -0500 (Wed, 26 Nov 2008)
New Revision: 11387
Added:
trunk/test-applications/seleniumTest/richfaces/src/main/resources/core/
trunk/test-applications/seleniumTest/richfaces/src/main/resources/core/scripts/
trunk/test-applications/seleniumTest/richfaces/src/main/resources/core/scripts/user-extensions.js
Modified:
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/DnDBean.java
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/DnDListener.java
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/dnd/dndTest.xhtml
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/template/dataTable.xhtml
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/template/modalPanel.xhtml
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/template/simple.xhtml
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/SeleniumTestBase.java
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/DnDTest.java
Log:
RF-5017, RF-5018
Modified:
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/DnDBean.java
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/DnDBean.java 2008-11-26
01:16:00 UTC (rev 11386)
+++
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/DnDBean.java 2008-11-26
11:11:49 UTC (rev 11387)
@@ -11,6 +11,11 @@
* copied from demo and tailored
*/
public class DnDBean {
+
+ public static final String DRAGLISTENER = "DragListener";
+
+ public static final String DROPLISTENER = "DropListener";
+
private List<Framework> containerPHP;
private List<Framework> containerCF;
@@ -18,10 +23,17 @@
private List<Framework> containerDNET;
private List<Framework> frameworks;
+
+ private String status = "";
+
+ private Object dropValue;
+
+ private Object dragValue;
public DnDBean() {
initList();
}
+
public List<Framework> getContainerPHP() {
return containerPHP;
@@ -56,6 +68,9 @@
}
public String reset() {
+ status = "";
+ dropValue = null;
+ dragValue = null;
initList();
return null;
}
@@ -83,10 +98,15 @@
public void processDropMethod(DropEvent event) {
Dropzone dropzone = (Dropzone) event.getComponent();
moveFramework(event.getDragValue(), dropzone.getDropValue());
+ status += getStatus() + DROPLISTENER;
}
public void processDragMethod(DragEvent event) {
- // TODO Auto-generated method stub
+ event.getAcceptedTypes();
+ status += getStatus() + DRAGLISTENER;
+ dragValue = event.getDragValue();
+ dropValue = event.getDropValue();
+
}
/**
@@ -119,4 +139,51 @@
this.name = name;
}
}
+
+ /**
+ * @return the status
+ */
+ public String getStatus() {
+ return status;
+ }
+
+ /**
+ * @param status the status to set
+ */
+ public void setStatus(String status) {
+ this.status = status;
+ }
+
+
+ /**
+ * @return the dropValue
+ */
+ public Object getDropValue() {
+ return dropValue;
+ }
+
+
+ /**
+ * @param dropValue the dropValue to set
+ */
+ public void setDropValue(Object dropValue) {
+ this.dropValue = dropValue;
+ }
+
+
+ /**
+ * @return the dragValue
+ */
+ public Object getDragValue() {
+ return dragValue;
+ }
+
+
+ /**
+ * @param dragValue the dragValue to set
+ */
+ public void setDragValue(Object dragValue) {
+ this.dragValue = dragValue;
+ }
+
}
Modified:
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/DnDListener.java
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/DnDListener.java 2008-11-26
01:16:00 UTC (rev 11386)
+++
trunk/test-applications/seleniumTest/richfaces/src/main/java/org/ajax4jsf/bean/DnDListener.java 2008-11-26
11:11:49 UTC (rev 11387)
@@ -25,7 +25,6 @@
// DropListener implementation
//
public void processDrag(DragEvent event) {
- // TODO Auto-generated method stub
}
//
Added:
trunk/test-applications/seleniumTest/richfaces/src/main/resources/core/scripts/user-extensions.js
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/main/resources/core/scripts/user-extensions.js
(rev 0)
+++
trunk/test-applications/seleniumTest/richfaces/src/main/resources/core/scripts/user-extensions.js 2008-11-26
11:11:49 UTC (rev 11387)
@@ -0,0 +1,151 @@
+/*
+ * Copyright 2004 ThoughtWorks, Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *
http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * User-extensions javascript for Selenium. Exadel. 2008
+ */
+
+IEBrowserBot.prototype._fireEventOnElement = function(eventType, element, clientX,
clientY) {
+ var win = this.getCurrentWindow();
+ triggerEvent(element, 'focus', false);
+
+ var wasChecked = element.checked;
+
+ // Set a flag that records if the page will unload - this isn't always accurate,
because
+ // <a href="javascript:alert('foo'):"> triggers the
onbeforeunload event, even thought the page won't unload
+ var pageUnloading = false;
+ var pageUnloadDetector = function() {
+ pageUnloading = true;
+ };
+ win.attachEvent("onbeforeunload", pageUnloadDetector);
+ this._modifyElementTarget(element);
+ if (element[eventType] && !this.controlKeyDown && !this.altKeyDown
&& !this.shiftKeyDown && !this.metaKeyDown) {
+ element[eventType]();
+ }
+ else {
+ this.browserbot.triggerMouseEvent(element, eventType, true, clientX, clientY);
+ }
+
+
+ // If the page is going to unload - still attempt to fire any subsequent events.
+ // However, we can't guarantee that the page won't unload half way through,
so we need to handle exceptions.
+ try {
+ win.detachEvent("onbeforeunload", pageUnloadDetector);
+
+ if (this._windowClosed(win)) {
+ return;
+ }
+
+ // Onchange event is not triggered automatically in IE.
+ if (isDefined(element.checked) && wasChecked != element.checked) {
+ triggerEvent(element, 'change', true);
+ }
+
+ }
+ catch (e) {
+ // If the page is unloading, we may get a "Permission denied" or
"Unspecified error".
+ // Just ignore it, because the document may have unloaded.
+ if (pageUnloading) {
+ LOG.logHook = function() {
+ };
+ LOG.warn("Caught exception when firing events on unloading page: "
+ e.message);
+ return;
+ }
+ throw e;
+ }
+};
+
+
+Selenium.prototype.doDragAndDropToObject = function(locatorOfObjectToBeDragged,
locatorOfDragDestinationObject) {
+/** Drags an element and drops it on another element
+ *
+ * @param locatorOfObjectToBeDragged an element to be dragged
+ * @param locatorOfDragDestinationObject an element whose location (i.e., whose
center-most pixel) will be the point where locatorOfObjectToBeDragged is dropped
+ */
+ var startX = this.getElementPositionLeft(locatorOfObjectToBeDragged);
+ var startY = this.getElementPositionTop(locatorOfObjectToBeDragged);
+
+ var destinationLeftX = this.getElementPositionLeft(locatorOfDragDestinationObject);
+ var destinationTopY = this.getElementPositionTop(locatorOfDragDestinationObject);
+ var destinationWidth = this.getElementWidth(locatorOfDragDestinationObject);
+ var destinationHeight = this.getElementHeight(locatorOfDragDestinationObject);
+
+ var endX = Math.round(destinationLeftX + (destinationWidth / 2));
+ var endY = Math.round(destinationTopY + (destinationHeight / 2));
+
+ var deltaX = endX - startX;
+ var deltaY = endY - startY;
+
+ var movementsString = "" + deltaX + "," + deltaY;
+
+ this.doDragAndDrop(locatorOfObjectToBeDragged, movementsString);
+ var objectToBeDragged = this.browserbot.findElement(locatorOfObjectToBeDragged);
+ var clientStartXY = getClientXY(objectToBeDragged)
+ var clientStartX = clientStartXY[0];
+ var clientStartY = clientStartXY[1];
+
+ var movements = movementsString.split(/,/);
+ var movementX = Number(movements[0]);
+ var movementY = Number(movements[1]);
+
+ var clientFinishX = ((clientStartX + movementX) < 0) ? 0 : (clientStartX +
movementX);
+ var clientFinishY = ((clientStartY + movementY) < 0) ? 0 : (clientStartY +
movementY);
+
+ // We should also fire event on DragDestinationObject.
+ var dragDestinationObject =
this.browserbot.findElement(locatorOfDragDestinationObject);
+ this.browserbot.triggerMouseEvent(dragDestinationObject, 'mouseover', true,
clientFinishX, clientFinishY);
+
+ this.browserbot.triggerMouseEvent(objectToBeDragged, 'mousemove', true,
clientFinishX, clientFinishY);
+ this.browserbot.triggerMouseEvent(objectToBeDragged, 'mouseup', true,
clientFinishX, clientFinishY);
+ this.browserbot.triggerMouseEvent(dragDestinationObject, 'mouseup', true,
clientFinishX, clientFinishY);
+
+};
+
+
+Selenium.prototype.doDragAndDrop = function(locator, movementsString) {
+ /** Drags an element a certain distance and then drops it
+ * @param locator an element locator
+ * @param movementsString offset in pixels from the current location to which the
element should be moved, e.g., "+70,-300"
+ */
+ var element = this.browserbot.findElement(locator);
+ var clientStartXY = getClientXY(element)
+ var clientStartX = clientStartXY[0];
+ var clientStartY = clientStartXY[1];
+
+ var movements = movementsString.split(/,/);
+ var movementX = Number(movements[0]);
+ var movementY = Number(movements[1]);
+
+ var clientFinishX = ((clientStartX + movementX) < 0) ? 0 : (clientStartX +
movementX);
+ var clientFinishY = ((clientStartY + movementY) < 0) ? 0 : (clientStartY +
movementY);
+
+ var mouseSpeed = this.mouseSpeed;
+ var move = function(current, dest) {
+ if (current == dest) return current;
+ if (Math.abs(current - dest) < mouseSpeed) return dest;
+ return (current < dest) ? current + mouseSpeed : current - mouseSpeed;
+ }
+
+ this.browserbot.triggerMouseEvent(element, 'mousedown', true, clientStartX,
clientStartY);
+ this.browserbot.triggerMouseEvent(element, 'mousemove', true, clientStartX,
clientStartY);
+ var clientX = clientStartX;
+ var clientY = clientStartY;
+
+ while ((clientX != clientFinishX) || (clientY != clientFinishY)) {
+ clientX = move(clientX, clientFinishX);
+ clientY = move(clientY, clientFinishY);
+ this.browserbot.triggerMouseEvent(element, 'mousemove', true, clientX,
clientY);
+ }
+
+};
Modified:
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/pages/dnd/dndTest.xhtml
===================================================================
(Binary files differ)
Modified:
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/template/dataTable.xhtml
===================================================================
(Binary files differ)
Modified:
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/template/modalPanel.xhtml
===================================================================
(Binary files differ)
Modified:
trunk/test-applications/seleniumTest/richfaces/src/main/webapp/template/simple.xhtml
===================================================================
(Binary files differ)
Modified:
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/SeleniumTestBase.java
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/SeleniumTestBase.java 2008-11-26
01:16:00 UTC (rev 11386)
+++
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/SeleniumTestBase.java 2008-11-26
11:11:49 UTC (rev 11387)
@@ -115,8 +115,10 @@
@BeforeSuite
public void startSeleniumServer() throws Exception {
RemoteControlConfiguration config = new RemoteControlConfiguration();
+ if (getFirefoxTemplate() != null) {
+ config.setFirefoxProfileTemplate(new File(getFirefoxTemplate()));
+ }
config.setMultiWindow(false);
- config.setUserExtensions(new
File(getClass().getClassLoader().getResource("script/selenium/user-extensions.js").toURI()));
seleniumServer = new SeleniumServer(false, config);
seleniumServer.start();
}
@@ -158,6 +160,10 @@
selenium = null;
}
}
+
+ protected String getFirefoxTemplate() {
+ return null;
+ }
protected void loadTemplates(String templateExpr) {
String[] array = new String[]{};
@@ -1290,4 +1296,5 @@
}
+
}
Modified:
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/DnDTest.java
===================================================================
---
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/DnDTest.java 2008-11-26
01:16:00 UTC (rev 11386)
+++
trunk/test-applications/seleniumTest/richfaces/src/test/java/org/richfaces/testng/DnDTest.java 2008-11-26
11:11:49 UTC (rev 11387)
@@ -2,14 +2,111 @@
import org.ajax4jsf.template.Template;
import org.richfaces.SeleniumTestBase;
+import org.testng.Assert;
import org.testng.annotations.Test;
public class DnDTest extends SeleniumTestBase {
+
+ static final String RESET_METHOD = "#{dndBean.reset}";
+
+ static final String FORMID = "_form:";
+ static final String DATAID = "src:";
+
+ String statusId;
+ String dragValueId;
+ String dropValueId;
+ String phpDropZoneId;
+ String dnetDropZoneId;
+ String cfDropZoneId;
+ String itemsHolderId;
+
+ void initIds(String parentId) {
+ statusId = parentId + FORMID + "status";
+ dragValueId = parentId + FORMID + "dragValue";
+ dropValueId = parentId + FORMID + "dropValue";
+ phpDropZoneId = parentId + FORMID + "PHP";
+ dnetDropZoneId = parentId + FORMID + "DNET";
+ cfDropZoneId = parentId + FORMID + "CF";
+ itemsHolderId = parentId + FORMID + DATAID;
+ }
+
+ @Override
+ protected String getFirefoxTemplate() {
+ return "c:/FFProfile";
+ }
@Test
- public void _testDnDComponents(Template template) {
- renderPage(template);
+ public void testDragValue(Template template) {
+ renderPage(template, RESET_METHOD);
+ initIds(getParentId());
+
+ DragAndDrop(0, phpDropZoneId);
+ waitForAjaxCompletion();
+ assertDragValue("Flexible Ajax", phpDropZoneId);
+
+ DragAndDrop(1, dnetDropZoneId);
+ waitForAjaxCompletion();
+ assertDragValue("AJAXEngine", dnetDropZoneId);
+
+ DragAndDrop(0, cfDropZoneId);
+ waitForAjaxCompletion();
+ assertDragValue("ajaxCFC", cfDropZoneId);
}
+
+
+ @Test
+ public void testDropValue(Template template) {
+ renderPage(template, RESET_METHOD);
+ initIds(getParentId());
+
+ DragAndDrop(0, phpDropZoneId);
+ waitForAjaxCompletion();
+ assertDropValue("PHP");
+ testDropData();
+
+ DragAndDrop(1, dnetDropZoneId);
+ waitForAjaxCompletion();
+ assertDropValue("DNET");
+ testDropData();
+
+ DragAndDrop(0, cfDropZoneId);
+ waitForAjaxCompletion();
+ assertDropValue("CF");
+ testDropData();
+ }
+
+
+
+ void DragAndDrop(int itemNumber, String dropZoneId) {
+ selenium.dragAndDropToObject("id=" + itemsHolderId + itemNumber +
":item", "id=" + dropZoneId + "_body");
+ }
+
+ void testDropData () {
+ String dragData = runScript("window._dropData");
+ if (dragData == null || !dragData.equals("dropData")) {
+ Assert.fail("Data attribute for dropSupport does not work.");
+ }
+ runScript("window._dropData = null;");
+ }
+
+ void assertDragValue(String dragLabel, String dropZoneId) {
+ String text = getTextById(dragValueId);
+ if (text == null || text.indexOf("org.ajax4jsf.bean.DnDBean$Framework") ==
-1) {
+ Assert.fail("Drag value ["+text+"] is incorrect. It's not
refferenced to org.ajax4jsf.bean.DnDBean$Framework class instance");
+ }
+ String dropZoneText = getTextById(dropZoneId);
+ if (dropZoneText == null || dropZoneText.indexOf(dragLabel) == -1) {
+ Assert.fail("Drag label is incorrect. Drop zone text
["+dropZoneText+"] does not contain label of dragged element");
+ }
+ }
+
+ void assertDropValue(String expectedValue) {
+ AssertTextEquals(dropValueId, expectedValue, "Drop Value is incorrect");
+ }
+
+ String getStatusValue() {
+ return getValueById(statusId);
+ }
@Override
public String getTestUrl() {