Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Side by Side Diff: webrtc/examples/androidjunit/src/org/appspot/apprtc/DirectRTCClientTest.java

Issue 2009493002: Improve IP_PATTERN in DirectRTCClient in Android AppRTC Demo (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/examples/androidapp/src/org/appspot/apprtc/DirectRTCClient.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 package org.appspot.apprtc; 11 package org.appspot.apprtc;
12 12
13 import org.junit.Before; 13 import org.junit.Before;
14 import org.junit.Test; 14 import org.junit.Test;
15 import org.junit.runner.RunWith; 15 import org.junit.runner.RunWith;
16 import org.robolectric.RobolectricTestRunner; 16 import org.robolectric.RobolectricTestRunner;
17 import org.robolectric.annotation.Config; 17 import org.robolectric.annotation.Config;
18 import org.webrtc.IceCandidate; 18 import org.webrtc.IceCandidate;
19 import org.webrtc.SessionDescription; 19 import org.webrtc.SessionDescription;
20 20
21 import java.util.regex.Matcher;
22
21 import static org.junit.Assert.fail; 23 import static org.junit.Assert.fail;
22 import static org.mockito.Matchers.any; 24 import static org.mockito.Matchers.any;
23 import static org.mockito.Matchers.isNotNull; 25 import static org.mockito.Matchers.isNotNull;
24 import static org.mockito.Mockito.mock; 26 import static org.mockito.Mockito.mock;
25 import static org.mockito.Mockito.timeout; 27 import static org.mockito.Mockito.timeout;
26 import static org.mockito.Mockito.verify; 28 import static org.mockito.Mockito.verify;
27 import static org.mockito.Mockito.verifyNoMoreInteractions; 29 import static org.mockito.Mockito.verifyNoMoreInteractions;
28 30
29 /** 31 /**
30 * Test for DirectRTCClient. Test is very simple and only tests the overall sani ty of the class 32 * Test for DirectRTCClient. Test is very simple and only tests the overall sani ty of the class
(...skipping 20 matching lines...) Expand all
51 @Before 53 @Before
52 public void setUp() { 54 public void setUp() {
53 clientEvents = mock(AppRTCClient.SignalingEvents.class); 55 clientEvents = mock(AppRTCClient.SignalingEvents.class);
54 serverEvents = mock(AppRTCClient.SignalingEvents.class); 56 serverEvents = mock(AppRTCClient.SignalingEvents.class);
55 57
56 client = new DirectRTCClient(clientEvents); 58 client = new DirectRTCClient(clientEvents);
57 server = new DirectRTCClient(serverEvents); 59 server = new DirectRTCClient(serverEvents);
58 } 60 }
59 61
60 @Test 62 @Test
63 public void testIpPattern() {
magjed_webrtc 2016/05/24 14:08:23 Split up in two tests testValidIpPattern()/testInv
sakal 2016/05/24 14:17:48 Done.
64 // Strings that should match the pattern.
65 final String[] ipAddresses = new String[] {
66 "0.0.0.0",
67 "127.0.0.1",
68 "192.168.0.1",
69 "0.0.0.0:8888",
70 "127.0.0.1:8888",
71 "192.168.0.1:8888",
72 "::",
73 "::1",
74 "2001:0db8:85a3:0000:0000:8a2e:0370:7946",
75 "[::]",
76 "[::1]",
77 "[2001:0db8:85a3:0000:0000:8a2e:0370:7946]",
78 "[::]:8888",
79 "[::1]:8888",
80 "[2001:0db8:85a3:0000:0000:8a2e:0370:7946]:8888"
81 };
82 // Strings that shouldn't match the pattern.
83 final String[] fakeIpAddresses = new String[] {
84 "Hello, World!",
85 "aaaa",
86 "1111",
87 "[hello world]",
88 "hello:world"
89 };
90
91 for (String ip : ipAddresses) {
92 if (!DirectRTCClient.IP_PATTERN.matcher(ip).matches()) {
93 fail(ip + " didn't match IP_PATTERN even though it should.");
94 }
95 }
96
97 for (String fakeIp : fakeIpAddresses) {
98 if (DirectRTCClient.IP_PATTERN.matcher(fakeIp).matches()) {
99 fail(fakeIp + " matched IP_PATTERN even though it shouldn't.");
100 }
101 }
102 }
103
104 @Test
61 public void testDirectRTCClient() { 105 public void testDirectRTCClient() {
62 server.connectToRoom(new AppRTCClient.RoomConnectionParameters(ROOM_URL, "0. 0.0.0", LOOPBACK)); 106 server.connectToRoom(new AppRTCClient.RoomConnectionParameters(ROOM_URL, "0. 0.0.0", LOOPBACK));
63 try { 107 try {
64 Thread.sleep(SERVER_WAIT); 108 Thread.sleep(SERVER_WAIT);
65 } catch (InterruptedException e) { 109 } catch (InterruptedException e) {
66 fail(e.getMessage()); 110 fail(e.getMessage());
67 } 111 }
68 client.connectToRoom( 112 client.connectToRoom(
69 new AppRTCClient.RoomConnectionParameters(ROOM_URL, "127.0.0.1", LOOPBAC K)); 113 new AppRTCClient.RoomConnectionParameters(ROOM_URL, "127.0.0.1", LOOPBAC K));
70 verify(serverEvents, timeout(NETWORK_TIMEOUT)) 114 verify(serverEvents, timeout(NETWORK_TIMEOUT))
(...skipping 20 matching lines...) Expand all
91 .onRemoteIceCandidate(isNotNull(IceCandidate.class)); 135 .onRemoteIceCandidate(isNotNull(IceCandidate.class));
92 136
93 client.disconnectFromRoom(); 137 client.disconnectFromRoom();
94 verify(clientEvents, timeout(NETWORK_TIMEOUT)).onChannelClose(); 138 verify(clientEvents, timeout(NETWORK_TIMEOUT)).onChannelClose();
95 verify(serverEvents, timeout(NETWORK_TIMEOUT)).onChannelClose(); 139 verify(serverEvents, timeout(NETWORK_TIMEOUT)).onChannelClose();
96 140
97 verifyNoMoreInteractions(clientEvents); 141 verifyNoMoreInteractions(clientEvents);
98 verifyNoMoreInteractions(serverEvents); 142 verifyNoMoreInteractions(serverEvents);
99 } 143 }
100 } 144 }
OLDNEW
« no previous file with comments | « webrtc/examples/androidapp/src/org/appspot/apprtc/DirectRTCClient.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698