Quantcast

[HtmlUnit] SVN: [13730] trunk/htmlunit/src

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[HtmlUnit] SVN: [13730] trunk/htmlunit/src

rbri
Revision: 13730
          http://sourceforge.net/p/htmlunit/code/13730
Author:   rbri
Date:     2017-03-15 17:44:15 +0000 (Wed, 15 Mar 2017)
Log Message:
-----------
 WebSocket onError processing was missing

Modified Paths:
--------------
    trunk/htmlunit/src/changes/changes.xml
    trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/WebSocket.java
    trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/WebSocketTest.java

Modified: trunk/htmlunit/src/changes/changes.xml
===================================================================
--- trunk/htmlunit/src/changes/changes.xml 2017-03-15 07:31:06 UTC (rev 13729)
+++ trunk/htmlunit/src/changes/changes.xml 2017-03-15 17:44:15 UTC (rev 13730)
@@ -8,6 +8,9 @@
 
     <body>
         <release version="2.26" date="???" description="Bugfixes">
+            <action type="fix" dev="rbri">
+                JavaScript: WebSocket onError processing was missing.
+            </action>
             <action type="fix" dev="asashour">
                 Fix detection of HtmlInput types (IE).
             </action>

Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/WebSocket.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/WebSocket.java 2017-03-15 07:31:06 UTC (rev 13729)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/WebSocket.java 2017-03-15 17:44:15 UTC (rev 13730)
@@ -437,5 +437,24 @@
             fire(msgEvent);
             callFunction(messageHandler_, new Object[] {msgEvent});
         }
+
+        @Override
+        public void onWebSocketError(final Throwable cause) {
+            super.onWebSocketError(cause);
+            readyState_ = CLOSED;
+            outgoingSession_ = null;
+
+            final Event errorEvent = new Event();
+            errorEvent.setType(Event.TYPE_ERROR);
+            fire(errorEvent);
+            callFunction(errorHandler_, new Object[] {errorEvent});
+
+            final CloseEvent closeEvent = new CloseEvent();
+            closeEvent.setCode(1006);
+            closeEvent.setReason(cause.getMessage());
+            closeEvent.setWasClean(false);
+            fire(closeEvent);
+            callFunction(closeHandler_, new Object[] {closeEvent});
+        }
     }
 }

Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/WebSocketTest.java
===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/WebSocketTest.java 2017-03-15 07:31:06 UTC (rev 13729)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/WebSocketTest.java 2017-03-15 17:44:15 UTC (rev 13730)
@@ -373,8 +373,35 @@
         while (text.length() > 0 && counter++ < 10);
 
         assertEquals(String.join("\n", getExpectedAlerts()), text);
+        stopWebServers();
     }
 
+    /**
+     * @throws Exception if the test fails
+     */
+    @Test
+    @Alerts({"onError[object Event]",
+                "onCloseListener code: 1006  wasClean: false",
+                "onClose code: 1006  wasClean: false"})
+    public void eventsNoSocketServer() throws Exception {
+        startWebServer("src/test/resources/com/gargoylesoftware/htmlunit/javascript/host",
+            null, null, null);
+        final WebDriver driver = getWebDriver();
+        driver.get("http://localhost:" + PORT + "/WebSocketTest_events.html");
+
+        final WebElement logElement = driver.findElement(By.id("log"));
+        int counter = 0;
+        String text;
+        do {
+            Thread.sleep(100);
+
+            text = logElement.getAttribute("value").trim().replaceAll("\r", "");
+        }
+        while (text.length() > 0 && counter++ < 10);
+
+        assertEquals(String.join("\n", getExpectedAlerts()), text);
+    }
+
     private static void assertVisible(final String domId, final WebDriver driver) throws Exception {
         final WebElement domE = driver.findElement(By.id(domId));
         int counter = 0;


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
HtmlUnit-develop mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/htmlunit-develop
Loading...