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

Side by Side Diff: webrtc/sdk/android/instrumentationtests/src/org/webrtc/NetworkMonitorTest.java

Issue 2990693002: Fix issues with NetworkMonitor singleton when used by multiple clients. (Closed)
Patch Set: Created 3 years, 4 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
OLDNEW
1 /* 1 /*
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2015 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 23 matching lines...) Expand all
34 import android.support.test.filters.SmallTest; 34 import android.support.test.filters.SmallTest;
35 import android.support.test.rule.UiThreadTestRule; 35 import android.support.test.rule.UiThreadTestRule;
36 import org.chromium.base.test.BaseJUnit4ClassRunner; 36 import org.chromium.base.test.BaseJUnit4ClassRunner;
37 import org.junit.Before; 37 import org.junit.Before;
38 import org.junit.Rule; 38 import org.junit.Rule;
39 import org.junit.Test; 39 import org.junit.Test;
40 import org.junit.runner.RunWith; 40 import org.junit.runner.RunWith;
41 41
42 /** 42 /**
43 * Tests for org.webrtc.NetworkMonitor. 43 * Tests for org.webrtc.NetworkMonitor.
44 *
45 * TODO(deadbeef): These tests don't cover the interaction between
46 * NetworkManager.java and androidnetworkmonitor_jni.cc, which is how this
47 * class is used in practice in WebRTC.
44 */ 48 */
45 @SuppressLint("NewApi") 49 @SuppressLint("NewApi")
46 @RunWith(BaseJUnit4ClassRunner.class) 50 @RunWith(BaseJUnit4ClassRunner.class)
47 public class NetworkMonitorTest { 51 public class NetworkMonitorTest {
48 @Rule public UiThreadTestRule uiThreadTestRule = new UiThreadTestRule(); 52 @Rule public UiThreadTestRule uiThreadTestRule = new UiThreadTestRule();
49 53
50 /** 54 /**
51 * Listens for alerts fired by the NetworkMonitor when network status changes. 55 * Listens for alerts fired by the NetworkMonitor when network status changes.
52 */ 56 */
53 private static class NetworkMonitorTestObserver implements NetworkMonitor.Netw orkObserver { 57 private static class NetworkMonitorTestObserver implements NetworkMonitor.Netw orkObserver {
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 return uiThreadHandler; 159 return uiThreadHandler;
156 } 160 }
157 } 161 }
158 162
159 /** 163 /**
160 * Helper method to create a network monitor and delegates for testing. 164 * Helper method to create a network monitor and delegates for testing.
161 */ 165 */
162 private void createTestMonitor() { 166 private void createTestMonitor() {
163 Context context = InstrumentationRegistry.getTargetContext(); 167 Context context = InstrumentationRegistry.getTargetContext();
164 NetworkMonitor.resetInstanceForTests(); 168 NetworkMonitor.resetInstanceForTests();
165 NetworkMonitor.setAutoDetectConnectivityState(true); 169 NetworkMonitor.createAutoDetectorForTest();
166 receiver = NetworkMonitor.getAutoDetectorForTest(); 170 receiver = NetworkMonitor.getAutoDetectorForTest();
167 assertNotNull(receiver); 171 assertNotNull(receiver);
168 172
169 connectivityDelegate = new MockConnectivityManagerDelegate(); 173 connectivityDelegate = new MockConnectivityManagerDelegate();
170 connectivityDelegate.setActiveNetworkExists(true); 174 connectivityDelegate.setActiveNetworkExists(true);
171 receiver.setConnectivityManagerDelegateForTests(connectivityDelegate); 175 receiver.setConnectivityManagerDelegateForTests(connectivityDelegate);
172 176
173 wifiDelegate = new MockWifiManagerDelegate(); 177 wifiDelegate = new MockWifiManagerDelegate();
174 receiver.setWifiManagerDelegateForTests(wifiDelegate); 178 receiver.setWifiManagerDelegateForTests(wifiDelegate);
175 wifiDelegate.setWifiSSID("foo"); 179 wifiDelegate.setWifiSSID("foo");
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 @Test 282 @Test
279 @UiThreadTest 283 @UiThreadTest
280 @SmallTest 284 @SmallTest
281 public void testQueryableAPIsDoNotCrash() { 285 public void testQueryableAPIsDoNotCrash() {
282 NetworkMonitorAutoDetect.Observer observer = new TestNetworkMonitorAutoDetec tObserver(); 286 NetworkMonitorAutoDetect.Observer observer = new TestNetworkMonitorAutoDetec tObserver();
283 NetworkMonitorAutoDetect ncn = 287 NetworkMonitorAutoDetect ncn =
284 new NetworkMonitorAutoDetect(observer, InstrumentationRegistry.getTarget Context()); 288 new NetworkMonitorAutoDetect(observer, InstrumentationRegistry.getTarget Context());
285 ncn.getDefaultNetId(); 289 ncn.getDefaultNetId();
286 } 290 }
287 } 291 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698