Echo the WebSocket close reason as well as the close code

When receiving a close frame with a code and reason both the code
and the reason are now added to the close frame send as response.
Before only the code was added

BUG=https://github.com/dart-lang/sdk/issues/23964
R=kustermann@google.com

Review URL: https://codereview.chromium.org//1273663002 .
diff --git a/sdk/lib/io/websocket_impl.dart b/sdk/lib/io/websocket_impl.dart
index 9693873..cc68544 100644
--- a/sdk/lib/io/websocket_impl.dart
+++ b/sdk/lib/io/websocket_impl.dart
@@ -888,7 +888,7 @@
           if (_readyState == WebSocket.OPEN) {
             _readyState = WebSocket.CLOSING;
             if (!_isReservedStatusCode(transformer.closeCode)) {
-              _close(transformer.closeCode);
+              _close(transformer.closeCode, transformer.closeReason);
             } else {
               _close();
             }
diff --git a/tests/standalone/io/web_socket_test.dart b/tests/standalone/io/web_socket_test.dart
index 9ae1758..ae38307 100644
--- a/tests/standalone/io/web_socket_test.dart
+++ b/tests/standalone/io/web_socket_test.dart
@@ -42,6 +42,13 @@
   Future<WebSocket> createClient(int port) =>
     WebSocket.connect('${secure ? "wss" : "ws"}://$HOST_NAME:$port/');
 
+  checkCloseStatus(webSocket, closeStatus, closeReason) {
+    Expect.equals(closeStatus == null ? WebSocketStatus.NO_STATUS_RECEIVED
+                                      : closeStatus, webSocket.closeCode);
+    Expect.equals(closeReason == null ? ""
+                                      : closeReason, webSocket.closeReason);
+  }
+
   void testRequestResponseClientCloses(int totalConnections,
                                        int closeStatus,
                                        String closeReason,
@@ -55,12 +62,7 @@
         webSocket.listen(
             webSocket.add,
             onDone: () {
-              Expect.equals(closeStatus == null
-                            ? WebSocketStatus.NO_STATUS_RECEIVED
-                            : closeStatus, webSocket.closeCode);
-              Expect.equals(
-                  closeReason == null ? ""
-                                      : closeReason, webSocket.closeReason);
+              checkCloseStatus(webSocket, closeStatus, closeReason);
               asyncEnd();
             });
         }, onDone: () {
@@ -85,10 +87,7 @@
                 }
               },
               onDone: () {
-                Expect.equals(closeStatus == null
-                              ? WebSocketStatus.NO_STATUS_RECEIVED
-                              : closeStatus, webSocket.closeCode);
-                Expect.equals("", webSocket.closeReason);
+                checkCloseStatus(webSocket, closeStatus, closeReason);
                 closeCount++;
                 if (closeCount == totalConnections) {
                   server.close();
@@ -119,10 +118,7 @@
               }
             },
             onDone: () {
-              Expect.equals(closeStatus == null
-                            ? WebSocketStatus.NO_STATUS_RECEIVED
-                            : closeStatus, webSocket.closeCode);
-              Expect.equals("", webSocket.closeReason);
+              checkCloseStatus(webSocket, closeStatus, closeReason);
               closeCount++;
               if (closeCount == totalConnections) {
                 server.close();
@@ -136,12 +132,7 @@
             webSocket.listen(
                 webSocket.add,
                 onDone: () {
-                  Expect.equals(closeStatus == null
-                                ? WebSocketStatus.NO_STATUS_RECEIVED
-                                : closeStatus, webSocket.closeCode);
-                  Expect.equals(closeReason == null
-                                ? ""
-                                : closeReason, webSocket.closeReason);
+                  checkCloseStatus(webSocket, closeStatus, closeReason);
                 });
             });
       }
@@ -363,8 +354,7 @@
               }
             },
             onDone: () {
-              Expect.equals(closeStatus, webSocket.closeCode);
-              Expect.equals("", webSocket.closeReason);
+              checkCloseStatus(webSocket, closeStatus, closeReason);
               closeCount++;
               if (closeCount == totalConnections) {
                 server.close();