Author: lfryc(a)redhat.com
Date: 2010-09-09 07:17:48 -0400 (Thu, 09 Sep 2010)
New Revision: 19143
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/cheiron/halt/XHRHalter.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/cheiron/halt/XHRState.java
modules/tests/metamer/trunk/ftest-source/src/main/resources/javascript/cheiron/XHRHalter.js
Removed:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/cheiron/halt/SendHalt.java
modules/tests/metamer/trunk/ftest-source/src/main/resources/javascript/cheiron/SendHalt.js
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jStatus/AbstracStatusTest.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jStatus/TestInstantAttributes.java
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jStatus/TestReferencedUsage.java
Log:
SendHalt replaced by more general implementation XHRHalter (able to step all the states of
XHR request) - used in a4j:status tests
Deleted:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/cheiron/halt/SendHalt.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/cheiron/halt/SendHalt.java 2010-09-09
11:03:11 UTC (rev 19142)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/cheiron/halt/SendHalt.java 2010-09-09
11:17:48 UTC (rev 19143)
@@ -1,78 +0,0 @@
-/*******************************************************************************
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- *******************************************************************************/
-package org.jboss.cheiron.halt;
-
-import static org.jboss.test.selenium.encapsulated.JavaScript.js;
-
-import org.jboss.test.selenium.encapsulated.JavaScript;
-import org.jboss.test.selenium.framework.AjaxSelenium;
-import org.jboss.test.selenium.framework.AjaxSeleniumProxy;
-
-/**
- * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
- * @version $Revision$
- */
-public class SendHalt {
-
- private static JavaScript isHaltAvailable =
js("selenium.browserbot.getCurrentWindow().SendHalt.isHaltAvailable()");
- private static JavaScript getHalt =
js("selenium.browserbot.getCurrentWindow().SendHalt.getHalt()");
- private static JavaScript unhalt =
js("selenium.browserbot.getCurrentWindow().SendHalt.unhalt({0})");
- private static JavaScript setEnabled =
js("selenium.browserbot.getCurrentWindow().SendHalt.setEnabled({0})");
-
- private static final AbstractPageExtensions sendHaltExtensions = new
AbstractPageExtensions() {
- {
- loadFromResource("javascript/cheiron/SendHalt.js");
- }
-
- public JavaScript isExtensionInstalledScript() {
- return js("selenium.browserbot.getCurrentWindow().SendHalt !=
undefined");
- }
- };
-
- int handle;
-
- private SendHalt(int handle) {
- this.handle = handle;
- }
-
- static AjaxSelenium selenium = AjaxSeleniumProxy.getInstance();
-
- public static void enable() {
- selenium.getPageExtensions().install();
- sendHaltExtensions.install();
- selenium.getEval(setEnabled.parametrize(true));
- }
-
- public static void disable() {
- selenium.getEval(setEnabled.parametrize(false));
- }
-
- public static SendHalt getHalt() {
- selenium.waitForCondition(isHaltAvailable);
- return new SendHalt(Integer.valueOf(selenium.getEval(getHalt)));
- }
-
- public void unhalt() {
- selenium.getEval(unhalt.parametrize(handle));
- }
-
-}
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/cheiron/halt/XHRHalter.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/cheiron/halt/XHRHalter.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/cheiron/halt/XHRHalter.java 2010-09-09
11:17:48 UTC (rev 19143)
@@ -0,0 +1,140 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ *******************************************************************************/
+package org.jboss.cheiron.halt;
+
+import static org.jboss.cheiron.halt.XHRState.*;
+import static org.jboss.test.selenium.encapsulated.JavaScript.js;
+
+import org.apache.commons.lang.Validate;
+import org.jboss.test.selenium.encapsulated.JavaScript;
+import org.jboss.test.selenium.framework.AjaxSelenium;
+import org.jboss.test.selenium.framework.AjaxSeleniumProxy;
+
+/**
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ */
+public class XHRHalter {
+
+ private static JavaScript isHandleAvailable =
js("selenium.browserbot.getCurrentWindow().XHRHalter.isHandleAvailable()");
+ private static JavaScript isWaitingForSend =
js("selenium.browserbot.getCurrentWindow().XHRHalter.isWaitingForSend({0})");
+ private static JavaScript getHandle =
js("selenium.browserbot.getCurrentWindow().XHRHalter.getHandle()");
+ private static JavaScript continueTo =
js("selenium.browserbot.getCurrentWindow().XHRHalter.continueTo({0},
selenium.browserbot.getCurrentWindow().XHRHalter.STATE_{1})");
+ private static JavaScript setEnabled =
js("selenium.browserbot.getCurrentWindow().XHRHalter.setEnabled({0})");
+
+ private static final AbstractPageExtensions halterExtensions = new
AbstractPageExtensions() {
+ {
+ loadFromResource("javascript/cheiron/XHRHalter.js");
+ }
+
+ public JavaScript isExtensionInstalledScript() {
+ return js("selenium.browserbot.getCurrentWindow().XHRHalter !=
undefined");
+ }
+ };
+
+ int handle;
+
+ private XHRHalter(int handle) {
+ this.handle = handle;
+ }
+
+ static AjaxSelenium selenium = AjaxSeleniumProxy.getInstance();
+
+ public static void enable() {
+ selenium.getPageExtensions().install();
+ halterExtensions.install();
+ selenium.getEval(setEnabled.parametrize(true));
+ }
+
+ public static void disable() {
+ selenium.getEval(setEnabled.parametrize(false));
+ }
+
+ public static boolean isHandleAvailable() {
+ return Boolean.valueOf(selenium.getEval(isHandleAvailable));
+ }
+
+ public static void waitForHandleAvailable() {
+ selenium.waitForCondition(isHandleAvailable);
+ }
+
+ public static XHRHalter getHandle() {
+ int handle = Integer.valueOf(selenium.getEval(getHandle));
+ if (handle < 0) {
+ throw new IllegalStateException("Handle is not available");
+ }
+ return new XHRHalter(handle);
+ }
+
+ public static XHRHalter getHandleBlocking() {
+ waitForHandleAvailable();
+ return getHandle();
+ }
+
+ public void continueBefore(XHRState phase) {
+ Validate.notNull(phase);
+ XHRState phaseToContinueAfter = XHRState.values()[phase.ordinal() - 1];
+ continueAfter(phaseToContinueAfter);
+ }
+
+ public void continueAfter(XHRState phase) {
+ Validate.notNull(phase);
+ selenium.getEval(continueTo.parametrize(handle, phase.toString()));
+ }
+
+ public boolean isWaitingForSend() {
+ return Boolean.valueOf(selenium.getEval(isWaitingForSend.parametrize(handle)));
+ }
+
+ public void waitForOpen() {
+ selenium.waitForCondition(isWaitingForSend.parametrize(handle));
+ }
+
+ public void send() {
+ continueAfter(SEND);
+ }
+
+ public void initialize() {
+ continueAfter(UNITIALIZED);
+ }
+
+ public void loading() {
+ continueAfter(LOADING);
+ }
+
+ public void loaded() {
+ continueAfter(LOADED);
+ }
+
+ public void interactive() {
+ continueAfter(INTERACTIVE);
+ }
+
+ public void complete() {
+ continueAfter(COMPLETE);
+ }
+
+ @Override
+ public String toString() {
+ return this.getClass().getName() + ": handle " + handle;
+ }
+}
Added:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/cheiron/halt/XHRState.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/cheiron/halt/XHRState.java
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/jboss/cheiron/halt/XHRState.java 2010-09-09
11:17:48 UTC (rev 19143)
@@ -0,0 +1,5 @@
+package org.jboss.cheiron.halt;
+
+public enum XHRState {
+ SEND, UNITIALIZED, LOADING, LOADED, INTERACTIVE, COMPLETE;
+}
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jStatus/AbstracStatusTest.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jStatus/AbstracStatusTest.java 2010-09-09
11:03:11 UTC (rev 19142)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jStatus/AbstracStatusTest.java 2010-09-09
11:17:48 UTC (rev 19143)
@@ -23,11 +23,13 @@
import static org.testng.Assert.assertEquals;
-import org.jboss.cheiron.halt.SendHalt;
+import org.jboss.cheiron.halt.XHRHalter;
import org.jboss.test.selenium.locator.ElementLocator;
import org.jboss.test.selenium.locator.JQueryLocator;
import org.jboss.test.selenium.waiting.retrievers.TextRetriever;
import org.richfaces.tests.metamer.ftest.AbstractMetamerTest;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
/**
* @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
@@ -43,14 +45,30 @@
TextRetriever retrieveStatus = retrieveText.locator(status);
+ XHRHalter haltHandler;
+
+ @BeforeMethod
+ public void cleanXHRHalter() {
+ haltHandler = null;
+ }
+
+ protected XHRHalter getCurrentXHRHalter() {
+ if (haltHandler == null) {
+ haltHandler = XHRHalter.getHandleBlocking();
+ } else {
+ haltHandler.waitForOpen();
+ }
+ return haltHandler;
+ }
+
void testRequestButton(ElementLocator<?> button, String startStatusText, String
stopStatusText) {
- SendHalt.enable();
+ XHRHalter.enable();
selenium.click(button);
- SendHalt halt = SendHalt.getHalt();
+ XHRHalter halt = getCurrentXHRHalter();
assertEquals(retrieveStatus.retrieve(), startStatusText);
- halt.unhalt();
+ halt.complete();
waitAjax.waitForChange(startStatusText, retrieveStatus);
assertEquals(retrieveStatus.retrieve(), stopStatusText);
- SendHalt.disable();
+ XHRHalter.disable();
}
}
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jStatus/TestInstantAttributes.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jStatus/TestInstantAttributes.java 2010-09-09
11:03:11 UTC (rev 19142)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jStatus/TestInstantAttributes.java 2010-09-09
11:17:48 UTC (rev 19143)
@@ -28,7 +28,7 @@
import java.net.URL;
-import org.jboss.cheiron.halt.SendHalt;
+import org.jboss.cheiron.halt.XHRHalter;
import org.jboss.test.selenium.encapsulated.JavaScript;
import org.jboss.test.selenium.locator.ElementLocator;
import org.richfaces.tests.metamer.ftest.annotations.IssueTracking;
@@ -59,12 +59,12 @@
for (int i = 0; i < 2; i++) {
attributes.setOnStart(alert.parametrize("start" + 1));
- SendHalt.enable();
+ XHRHalter.enable();
selenium.click(button1);
selenium.waitForCondition(js("selenium.isAlertPresent()"));
assertEquals(selenium.getAlert(), "start" + 1);
- SendHalt.getHalt().unhalt();
- SendHalt.disable();
+ getCurrentXHRHalter().complete();
+ XHRHalter.disable();
}
}
Modified:
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jStatus/TestReferencedUsage.java
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jStatus/TestReferencedUsage.java 2010-09-09
11:03:11 UTC (rev 19142)
+++
modules/tests/metamer/trunk/ftest-source/src/main/java/org/richfaces/tests/metamer/ftest/a4jStatus/TestReferencedUsage.java 2010-09-09
11:17:48 UTC (rev 19143)
@@ -26,7 +26,7 @@
import java.net.URL;
-import org.jboss.cheiron.halt.SendHalt;
+import org.jboss.cheiron.halt.XHRHalter;
import org.jboss.test.selenium.locator.JQueryLocator;
import org.jboss.test.selenium.waiting.retrievers.TextRetriever;
import org.testng.annotations.Test;
@@ -50,82 +50,82 @@
@Test
public void testClickBothButtonsInSequence() {
- SendHalt.enable();
+ XHRHalter.enable();
selenium.click(button1);
- SendHalt halt = SendHalt.getHalt();
+ XHRHalter halt = getCurrentXHRHalter();
assertEquals(retrieveStatus1.retrieve(), "START");
assertEquals(retrieveStatus2.retrieve(), "STOP");
- halt.unhalt();
+ halt.complete();
waitAjax.waitForChange("START", retrieveStatus1);
selenium.click(button2);
- halt = SendHalt.getHalt();
+ halt = getCurrentXHRHalter();
assertEquals(retrieveStatus1.retrieve(), "STOP");
assertEquals(retrieveStatus2.retrieve(), "START");
- halt.unhalt();
+ halt.complete();
waitAjax.waitForChange("START", retrieveStatus2);
assertEquals(retrieveStatus1.retrieve(), "STOP");
assertEquals(retrieveStatus2.retrieve(), "STOP");
- SendHalt.disable();
+ XHRHalter.disable();
}
@Test
public void testClickBothButtonsImmediately() {
- SendHalt.enable();
+ XHRHalter.enable();
selenium.click(button1);
selenium.click(button2);
- SendHalt halt = SendHalt.getHalt();
+ XHRHalter halt = getCurrentXHRHalter();
assertEquals(retrieveStatus1.retrieve(), "START");
assertEquals(retrieveStatus2.retrieve(), "STOP");
- halt.unhalt();
- halt = SendHalt.getHalt();
+ halt.complete();
+ halt.waitForOpen();
assertEquals(retrieveStatus1.retrieve(), "STOP");
assertEquals(retrieveStatus2.retrieve(), "START");
- halt.unhalt();
+ halt.complete();
waitAjax.waitForChange("START", retrieveStatus2);
assertEquals(retrieveStatus1.retrieve(), "STOP");
assertEquals(retrieveStatus2.retrieve(), "STOP");
- SendHalt.disable();
+ XHRHalter.disable();
}
/**
* @Test TODO: selenium is causing 3 requests, but manually we triggers 2 requests
(use Firebug to reproduce)
*/
public void testClickFirstButtonThenSecondButtonThenAgainFirstButtonImmediately() {
- SendHalt.enable();
+ XHRHalter.enable();
selenium.click(button1);
selenium.click(button2);
selenium.click(button1);
- SendHalt halt = SendHalt.getHalt();
+ XHRHalter halt = XHRHalter.getHandleBlocking();
assertEquals(retrieveStatus1.retrieve(), "START");
assertEquals(retrieveStatus2.retrieve(), "STOP");
- halt.unhalt();
- halt = SendHalt.getHalt();
+ halt.complete();
+ halt.waitForOpen();
assertEquals(retrieveStatus1.retrieve(), "START");
assertEquals(retrieveStatus2.retrieve(), "STOP");
- halt.unhalt();
+ halt.complete();
waitAjax.waitForChange("START", retrieveStatus1);
assertEquals(retrieveStatus1.retrieve(), "STOP");
assertEquals(retrieveStatus2.retrieve(), "STOP");
- SendHalt.disable();
+ XHRHalter.disable();
}
@Test
public void testDoubleClick() {
- SendHalt.enable();
+ XHRHalter.enable();
selenium.click(button1);
- SendHalt halt = SendHalt.getHalt();
+ XHRHalter halt = getCurrentXHRHalter();
assertEquals(retrieveStatus1.retrieve(), "START");
assertEquals(retrieveStatus2.retrieve(), "STOP");
- halt.unhalt();
+ halt.complete();
selenium.click(button1);
- halt = SendHalt.getHalt();
+ halt.waitForOpen();
assertEquals(retrieveStatus1.retrieve(), "START");
assertEquals(retrieveStatus2.retrieve(), "STOP");
- halt.unhalt();
+ halt.complete();
waitAjax.waitForChange("START", retrieveStatus1);
assertEquals(retrieveStatus1.retrieve(), "STOP");
assertEquals(retrieveStatus2.retrieve(), "STOP");
- SendHalt.disable();
+ XHRHalter.disable();
}
}
Deleted:
modules/tests/metamer/trunk/ftest-source/src/main/resources/javascript/cheiron/SendHalt.js
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/resources/javascript/cheiron/SendHalt.js 2010-09-09
11:03:11 UTC (rev 19142)
+++
modules/tests/metamer/trunk/ftest-source/src/main/resources/javascript/cheiron/SendHalt.js 2010-09-09
11:17:48 UTC (rev 19143)
@@ -1,90 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright ${year}, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-var SendHalt = function(xhr, content, callback) {
- SendHalt._instances.push(this);
- this.halt = true;
- this.xhr = xhr;
- this.content = content;
- this.callback = callback;
- this.id = SendHalt._instances.length - 1;
-}
-
-SendHalt._instances = new Array();
-SendHalt._haltCounter = 0;
-SendHalt._enabled = false;
-
-SendHalt.setEnabled = function(enabled) {
- SendHalt._enabled = enabled;
-}
-
-SendHalt.isEnabled = function(enabled) {
- return SendHalt._enabled;
-}
-
-SendHalt.getLastId = function() {
- return SendHalt._instances.length - 1;
-}
-
-SendHalt.getHalt = function() {
- if (SendHalt.isHaltAvailable()) {
- SendHalt._haltCounter += 1;
- return SendHalt.getLastId();
- }
- return -1;
-}
-
-SendHalt.XHRWrapperInjection = {
- send : RichFacesSelenium.XHRWrapper.prototype.send
-}
-
-SendHalt._repeatWait = function(id) {
- var halt = SendHalt._instances[id];
- if (halt.halt) {
- setTimeout("SendHalt._repeatWait(" + id + ")", 100);
- } else {
- halt.callback(halt.xhr, halt.content);
- }
-}
-
-SendHalt.prototype.wait = function() {
- SendHalt._repeatWait(this.id);
-}
-
-SendHalt.unhalt = function(id) {
- var halt = SendHalt._instances[id];
- halt.halt = false;
-}
-
-SendHalt.isHaltAvailable = function() {
- return SendHalt.getLastId() == SendHalt._haltCounter;
-}
-
-RichFacesSelenium.XHRWrapper.prototype.send = function(content) {
- if (SendHalt.isEnabled()) {
- var metamerHalt = new SendHalt(this, content, function(xhr, content1) {
- SendHalt.XHRWrapperInjection.send.call(xhr, content1);
- });
- metamerHalt.wait();
- } else {
- SendHalt.XHRWrapperInjection.send.call(this, content);
- }
-};
\ No newline at end of file
Added:
modules/tests/metamer/trunk/ftest-source/src/main/resources/javascript/cheiron/XHRHalter.js
===================================================================
---
modules/tests/metamer/trunk/ftest-source/src/main/resources/javascript/cheiron/XHRHalter.js
(rev 0)
+++
modules/tests/metamer/trunk/ftest-source/src/main/resources/javascript/cheiron/XHRHalter.js 2010-09-09
11:17:48 UTC (rev 19143)
@@ -0,0 +1,182 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+var XHRHalter = function(xhr) {
+ XHRHalter._associations[xhr] = this;
+ if (this.id == undefined) {
+ XHRHalter._instances.push(this);
+ this.id = XHRHalter._instances.length - 1;
+ }
+ this.currentState = XHRHalter.STATE_OPEN;
+ this.availableStates = new Array();
+ this.continueToState = XHRHalter.STATE_OPEN;
+ this.xhr = xhr;
+ this.sendParams = {};
+ this.xhrParams = new Array();
+ this.saveXhrParams();
+ this.callback = function(xhr) {
+ XHRHalter.XHRWrapperInjection.onreadystatechangeCallback.call(xhr);
+ };
+};
+
+XHRHalter.STATE_OPEN = -2;
+XHRHalter.STATE_SEND = -1;
+XHRHalter.STATE_UNITIALIZED = 0;
+XHRHalter.STATE_LOADING = 1;
+XHRHalter.STATE_LOADED = 2;
+XHRHalter.STATE_INTERACTIVE = 3;
+XHRHalter.STATE_COMPLETE = 4;
+
+XHRHalter._instances = new Array();
+XHRHalter._associations = {};
+XHRHalter._haltCounter = 0;
+XHRHalter._enabled = true;
+
+XHRHalter.setEnabled = function(enabled) {
+ XHRHalter._enabled = enabled;
+};
+
+XHRHalter.isEnabled = function(enabled) {
+ return XHRHalter._enabled;
+};
+
+XHRHalter.getHandle = function() {
+ if (XHRHalter.isHandleAvailable()) {
+ return XHRHalter._haltCounter++;
+ }
+ return -1;
+};
+
+XHRHalter.XHRWrapperInjection = {
+ onreadystatechangeCallback :
RichFacesSelenium.XHRWrapper.prototype.onreadystatechangeCallback,
+ open : RichFacesSelenium.XHRWrapper.prototype.open,
+ send : RichFacesSelenium.XHRWrapper.prototype.send
+};
+
+XHRHalter._repeatWait = function(id) {
+ var halter = XHRHalter._instances[id];
+ halter.tryProcessStates();
+ if (!halter.isXhrCompleted()) {
+ setTimeout("XHRHalter._repeatWait(" + id + ")", 100);
+ }
+};
+
+XHRHalter.prototype.isXhrCompleted = function() {
+ return this.currentState == XHRHalter.STATE_COMPLETE;
+};
+
+XHRHalter.prototype.getLastAvailableState = function() {
+ return this.availableStates.length - 1;
+};
+
+XHRHalter.continueTo = function(id, state) {
+ var halter = XHRHalter._instances[id];
+ if (state < halter.continueToState) {
+ throw new Error("cannot continue to state (" + state + ") before the
actual state (" + halter.continueToState + ")");
+ }
+ halter.continueToState = state;
+};
+
+XHRHalter.isWaitingForSend = function(id) {
+ var halter = XHRHalter._instances[id];
+ return halter.currentState == XHRHalter.STATE_OPEN && halter.continueToState ==
XHRHalter.STATE_OPEN;
+};
+
+XHRHalter.prototype.tryProcessStates = function() {
+ while (this.currentState < this.continueToState && this.currentState <
this.getLastAvailableState()) {
+ this.currentState += 1;
+ this.processState(this.currentState);
+ }
+};
+
+XHRHalter.prototype.processState = function(state) {
+ this.loadXhrParams(state);
+ switch (state) {
+ case XHRHalter.STATE_SEND :
+ XHRHalter.XHRWrapperInjection.send.call(this.xhr,
this.sendParams['content']);
+ break;
+ default :
+ this.callback(this.xhr);
+ }
+};
+
+XHRHalter.prototype.loadXhrParams = function(state) {
+ state = Math.max(state, XHRHalter.STATE_UNITIALIZED);
+ var holder = this.availableStates[state];
+ this.xhr.readyState = state;
+ this.xhr.responseText = holder.responseText;
+ this.xhr.responseXML = holder.responseXML;
+ this.xhr.status = holder.status;
+ this.xhr.statusText = holder.statusText;
+ this.xhr.onreadystatechange = holder.onreadystatechange;
+};
+
+XHRHalter.prototype.saveXhrParams = function() {
+ this.availableStates[this.xhr.readyState] = {};
+ var holder = this.availableStates[this.xhr.readyState];
+ holder.responseText = this.xhr.responseText;
+ holder.responseXML = this.xhr.responseXML;
+ holder.status = this.xhr.status;
+ holder.statusText = this.xhr.statusText;
+ holder.onreadystatechange = this.xhr.onreadystatechange;
+};
+
+XHRHalter.prototype.wait = function() {
+ XHRHalter._repeatWait(this.id);
+};
+
+XHRHalter.isHandleAvailable = function() {
+ return XHRHalter._instances.length - 1 >= XHRHalter._haltCounter;
+};
+
+RichFacesSelenium.XHRWrapper.prototype.onreadystatechangeCallback = function() {
+ if (XHRHalter.isEnabled()) {
+ var halter = XHRHalter._associations[this];
+ halter.saveXhrParams();
+ halter.loadXhrParams(halter.currentState);
+ } else {
+ XHRHalter.XHRWrapperInjection.onreadystatechangeCallback.call(this);
+ }
+};
+
+RichFacesSelenium.XHRWrapper.prototype.open = function(method, url, asyncFlag, userName,
password) {
+ if (XHRHalter.isEnabled()) {
+ var halter = XHRHalter._associations[this];
+ if (halter === undefined) {
+ halter = new XHRHalter(this);
+ } else {
+ XHRHalter.call(halter, this);
+ }
+ halter.wait();
+ }
+ asyncFlag = (asyncFlag !== false);
+ return XHRHalter.XHRWrapperInjection.open.call(this, method, url, asyncFlag, userName,
password);
+};
+
+
+RichFacesSelenium.XHRWrapper.prototype.send = function(content) {
+ if (XHRHalter.isEnabled()) {
+ var halter = XHRHalter._associations[this];
+ halter.sendParams['content'] = content;
+ } else {
+ return XHRHalter.XHRWrapperInjection.send.call(this, content);
+ }
+};