| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 clientEvents = mock(AppRTCClient.SignalingEvents.class); | 55 clientEvents = mock(AppRTCClient.SignalingEvents.class); |
| 56 serverEvents = mock(AppRTCClient.SignalingEvents.class); | 56 serverEvents = mock(AppRTCClient.SignalingEvents.class); |
| 57 | 57 |
| 58 client = new DirectRTCClient(clientEvents); | 58 client = new DirectRTCClient(clientEvents); |
| 59 server = new DirectRTCClient(serverEvents); | 59 server = new DirectRTCClient(serverEvents); |
| 60 } | 60 } |
| 61 | 61 |
| 62 @Test | 62 @Test |
| 63 public void testValidIpPattern() { | 63 public void testValidIpPattern() { |
| 64 // Strings that should match the pattern. | 64 // Strings that should match the pattern. |
| 65 // clang-format off |
| 65 final String[] ipAddresses = new String[] { | 66 final String[] ipAddresses = new String[] { |
| 66 "0.0.0.0", | 67 "0.0.0.0", |
| 67 "127.0.0.1", | 68 "127.0.0.1", |
| 68 "192.168.0.1", | 69 "192.168.0.1", |
| 69 "0.0.0.0:8888", | 70 "0.0.0.0:8888", |
| 70 "127.0.0.1:8888", | 71 "127.0.0.1:8888", |
| 71 "192.168.0.1:8888", | 72 "192.168.0.1:8888", |
| 72 "::", | 73 "::", |
| 73 "::1", | 74 "::1", |
| 74 "2001:0db8:85a3:0000:0000:8a2e:0370:7946", | 75 "2001:0db8:85a3:0000:0000:8a2e:0370:7946", |
| 75 "[::]", | 76 "[::]", |
| 76 "[::1]", | 77 "[::1]", |
| 77 "[2001:0db8:85a3:0000:0000:8a2e:0370:7946]", | 78 "[2001:0db8:85a3:0000:0000:8a2e:0370:7946]", |
| 78 "[::]:8888", | 79 "[::]:8888", |
| 79 "[::1]:8888", | 80 "[::1]:8888", |
| 80 "[2001:0db8:85a3:0000:0000:8a2e:0370:7946]:8888" | 81 "[2001:0db8:85a3:0000:0000:8a2e:0370:7946]:8888" |
| 81 }; | 82 }; |
| 83 // clang-format on |
| 82 | 84 |
| 83 for (String ip : ipAddresses) { | 85 for (String ip : ipAddresses) { |
| 84 assertTrue(ip + " didn't match IP_PATTERN even though it should.", | 86 assertTrue(ip + " didn't match IP_PATTERN even though it should.", |
| 85 DirectRTCClient.IP_PATTERN.matcher(ip).matches()); | 87 DirectRTCClient.IP_PATTERN.matcher(ip).matches()); |
| 86 } | 88 } |
| 87 } | 89 } |
| 88 | 90 |
| 89 @Test | 91 @Test |
| 90 public void testInvalidIpPattern() { | 92 public void testInvalidIpPattern() { |
| 91 // Strings that shouldn't match the pattern. | 93 // Strings that shouldn't match the pattern. |
| 94 // clang-format off |
| 92 final String[] invalidIpAddresses = new String[] { | 95 final String[] invalidIpAddresses = new String[] { |
| 93 "Hello, World!", | 96 "Hello, World!", |
| 94 "aaaa", | 97 "aaaa", |
| 95 "1111", | 98 "1111", |
| 96 "[hello world]", | 99 "[hello world]", |
| 97 "hello:world" | 100 "hello:world" |
| 98 }; | 101 }; |
| 102 // clang-format on |
| 99 | 103 |
| 100 for (String invalidIp : invalidIpAddresses) { | 104 for (String invalidIp : invalidIpAddresses) { |
| 101 assertFalse(invalidIp + " matched IP_PATTERN even though it shouldn't.", | 105 assertFalse(invalidIp + " matched IP_PATTERN even though it shouldn't.", |
| 102 DirectRTCClient.IP_PATTERN.matcher(invalidIp).matches()); | 106 DirectRTCClient.IP_PATTERN.matcher(invalidIp).matches()); |
| 103 } | 107 } |
| 104 } | 108 } |
| 105 | 109 |
| 106 @Test | 110 @Test |
| 107 public void testDirectRTCClient() { | 111 public void testDirectRTCClient() { |
| 108 server.connectToRoom(new AppRTCClient.RoomConnectionParameters(ROOM_URL, "0.
0.0.0", LOOPBACK)); | 112 server.connectToRoom(new AppRTCClient.RoomConnectionParameters(ROOM_URL, "0.
0.0.0", LOOPBACK)); |
| 109 try { | 113 try { |
| 110 Thread.sleep(SERVER_WAIT); | 114 Thread.sleep(SERVER_WAIT); |
| 111 } catch (InterruptedException e) { | 115 } catch (InterruptedException e) { |
| 112 fail(e.getMessage()); | 116 fail(e.getMessage()); |
| 113 } | 117 } |
| 114 client.connectToRoom( | 118 client.connectToRoom( |
| 115 new AppRTCClient.RoomConnectionParameters(ROOM_URL, "127.0.0.1", LOOPBAC
K)); | 119 new AppRTCClient.RoomConnectionParameters(ROOM_URL, "127.0.0.1", LOOPBAC
K)); |
| 116 verify(serverEvents, timeout(NETWORK_TIMEOUT)) | 120 verify(serverEvents, timeout(NETWORK_TIMEOUT)) |
| 117 .onConnectedToRoom(any(AppRTCClient.SignalingParameters.class)); | 121 .onConnectedToRoom(any(AppRTCClient.SignalingParameters.class)); |
| 118 | 122 |
| 119 SessionDescription offerSdp = new SessionDescription(SessionDescription.Type
.OFFER, DUMMY_SDP); | 123 SessionDescription offerSdp = new SessionDescription(SessionDescription.Type
.OFFER, DUMMY_SDP); |
| 120 server.sendOfferSdp(offerSdp); | 124 server.sendOfferSdp(offerSdp); |
| 121 verify(clientEvents, timeout(NETWORK_TIMEOUT)) | 125 verify(clientEvents, timeout(NETWORK_TIMEOUT)) |
| 122 .onConnectedToRoom(any(AppRTCClient.SignalingParameters.class)); | 126 .onConnectedToRoom(any(AppRTCClient.SignalingParameters.class)); |
| 123 | 127 |
| 124 SessionDescription answerSdp | 128 SessionDescription answerSdp = |
| 125 = new SessionDescription(SessionDescription.Type.ANSWER, DUMMY_SDP); | 129 new SessionDescription(SessionDescription.Type.ANSWER, DUMMY_SDP); |
| 126 client.sendAnswerSdp(answerSdp); | 130 client.sendAnswerSdp(answerSdp); |
| 127 verify(serverEvents, timeout(NETWORK_TIMEOUT)) | 131 verify(serverEvents, timeout(NETWORK_TIMEOUT)) |
| 128 .onRemoteDescription(isNotNull(SessionDescription.class)); | 132 .onRemoteDescription(isNotNull(SessionDescription.class)); |
| 129 | 133 |
| 130 IceCandidate candidate = new IceCandidate(DUMMY_SDP_MID, 0, DUMMY_SDP); | 134 IceCandidate candidate = new IceCandidate(DUMMY_SDP_MID, 0, DUMMY_SDP); |
| 131 server.sendLocalIceCandidate(candidate); | 135 server.sendLocalIceCandidate(candidate); |
| 132 verify(clientEvents, timeout(NETWORK_TIMEOUT)) | 136 verify(clientEvents, timeout(NETWORK_TIMEOUT)) |
| 133 .onRemoteIceCandidate(isNotNull(IceCandidate.class)); | 137 .onRemoteIceCandidate(isNotNull(IceCandidate.class)); |
| 134 | 138 |
| 135 client.sendLocalIceCandidate(candidate); | 139 client.sendLocalIceCandidate(candidate); |
| 136 verify(serverEvents, timeout(NETWORK_TIMEOUT)) | 140 verify(serverEvents, timeout(NETWORK_TIMEOUT)) |
| 137 .onRemoteIceCandidate(isNotNull(IceCandidate.class)); | 141 .onRemoteIceCandidate(isNotNull(IceCandidate.class)); |
| 138 | 142 |
| 139 client.disconnectFromRoom(); | 143 client.disconnectFromRoom(); |
| 140 verify(clientEvents, timeout(NETWORK_TIMEOUT)).onChannelClose(); | 144 verify(clientEvents, timeout(NETWORK_TIMEOUT)).onChannelClose(); |
| 141 verify(serverEvents, timeout(NETWORK_TIMEOUT)).onChannelClose(); | 145 verify(serverEvents, timeout(NETWORK_TIMEOUT)).onChannelClose(); |
| 142 | 146 |
| 143 verifyNoMoreInteractions(clientEvents); | 147 verifyNoMoreInteractions(clientEvents); |
| 144 verifyNoMoreInteractions(serverEvents); | 148 verifyNoMoreInteractions(serverEvents); |
| 145 } | 149 } |
| 146 } | 150 } |
| OLD | NEW |