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

Side by Side Diff: net/android/javatests/src/org/chromium/net/NetworkChangeNotifierTest.java

Issue 1417973002: [Cronet] Switch from InstrumentationTest to junit (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address Helen's comments Created 5 years, 2 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 | « net/android/BUILD.gn ('k') | net/net.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.net; 5 package org.chromium.net;
6 6
7 import android.annotation.SuppressLint; 7 import android.annotation.SuppressLint;
8 import android.content.Context; 8 import android.content.Context;
9 import android.content.Intent; 9 import android.content.Intent;
10 import android.net.ConnectivityManager; 10 import android.net.ConnectivityManager;
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 if (activeNetIds.length >= 1) { 193 if (activeNetIds.length >= 1) {
194 mLastNetIdSeen = activeNetIds[0]; 194 mLastNetIdSeen = activeNetIds[0];
195 } else { 195 } else {
196 mLastNetIdSeen = NetId.INVALID; 196 mLastNetIdSeen = NetId.INVALID;
197 } 197 }
198 } 198 }
199 199
200 // Verify last notification was the expected one. 200 // Verify last notification was the expected one.
201 public void assertLastChange(ChangeType type, int netId) throws Exceptio n { 201 public void assertLastChange(ChangeType type, int netId) throws Exceptio n {
202 // Make sure notification processed. 202 // Make sure notification processed.
203 flushUiThreadTaskQueue(); 203 NetworkChangeNotifierTestUtil.flushUiThreadTaskQueue();
204 assertEquals(type, mLastChangeSeen); 204 assertEquals(type, mLastChangeSeen);
205 assertEquals(netId, mLastNetIdSeen); 205 assertEquals(netId, mLastNetIdSeen);
206 mLastChangeSeen = ChangeType.NONE; 206 mLastChangeSeen = ChangeType.NONE;
207 mLastNetIdSeen = NetId.INVALID; 207 mLastNetIdSeen = NetId.INVALID;
208 } 208 }
209 } 209 }
210 210
211 // Network.Network(int netId) pointer. 211 // Network.Network(int netId) pointer.
212 private Constructor<Network> mNetworkConstructor; 212 private Constructor<Network> mNetworkConstructor;
213 private NetworkChangeNotifierAutoDetect mReceiver; 213 private NetworkChangeNotifierAutoDetect mReceiver;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 final NetworkChangeNotifierAutoDetect.NetworkState networkState = 255 final NetworkChangeNotifierAutoDetect.NetworkState networkState =
256 mReceiver.getCurrentNetworkState(); 256 mReceiver.getCurrentNetworkState();
257 return mReceiver.getCurrentConnectionType(networkState); 257 return mReceiver.getCurrentConnectionType(networkState);
258 } 258 }
259 259
260 // Create Network object given a NetID. 260 // Create Network object given a NetID.
261 private Network netIdToNetwork(int netId) throws Exception { 261 private Network netIdToNetwork(int netId) throws Exception {
262 return mNetworkConstructor.newInstance(netId); 262 return mNetworkConstructor.newInstance(netId);
263 } 263 }
264 264
265 // Flush UI thread task queue.
266 private static void flushUiThreadTaskQueue() throws Exception {
267 FutureTask<Void> task = new FutureTask<Void>(new Runnable() {
268 public void run() {}
269 }, null);
270 ThreadUtils.postOnUiThread(task);
271 task.get();
272 }
273
274 @Override 265 @Override
275 protected void setUp() throws Exception { 266 protected void setUp() throws Exception {
276 super.setUp(); 267 super.setUp();
277 LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER) 268 LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER)
278 .ensureInitialized(getInstrumentation().getTargetContext()); 269 .ensureInitialized(getInstrumentation().getTargetContext());
279 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 270 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
280 // Find Network.Network(int netId) using reflection. 271 // Find Network.Network(int netId) using reflection.
281 mNetworkConstructor = Network.class.getConstructor(Integer.TYPE); 272 mNetworkConstructor = Network.class.getConstructor(Integer.TYPE);
282 } 273 }
283 ThreadUtils.postOnUiThread(new Runnable() { 274 ThreadUtils.postOnUiThread(new Runnable() {
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 // Simulate app backgrounding then foregrounding. 599 // Simulate app backgrounding then foregrounding.
609 assertTrue(ncn.isReceiverRegisteredForTesting()); 600 assertTrue(ncn.isReceiverRegisteredForTesting());
610 policy.onApplicationStateChange(ApplicationState.HAS_PAUSED_ACTIVITIES); 601 policy.onApplicationStateChange(ApplicationState.HAS_PAUSED_ACTIVITIES);
611 assertFalse(ncn.isReceiverRegisteredForTesting()); 602 assertFalse(ncn.isReceiverRegisteredForTesting());
612 policy.onApplicationStateChange(ApplicationState.HAS_RUNNING_ACTIVITIES) ; 603 policy.onApplicationStateChange(ApplicationState.HAS_RUNNING_ACTIVITIES) ;
613 assertTrue(ncn.isReceiverRegisteredForTesting()); 604 assertTrue(ncn.isReceiverRegisteredForTesting());
614 // Verify network list purged. 605 // Verify network list purged.
615 observer.assertLastChange(ChangeType.PURGE_LIST, NetId.INVALID); 606 observer.assertLastChange(ChangeType.PURGE_LIST, NetId.INVALID);
616 } 607 }
617 } 608 }
OLDNEW
« no previous file with comments | « net/android/BUILD.gn ('k') | net/net.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698