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

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

Issue 2175603004: Fix tests calling methods on the wrong thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/android/javatests/src/org/chromium/chrome/browser/ChromeBackupIntegrationTest.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/android/javatests/src/org/chromium/net/NetworkChangeNotifierTest.java
diff --git a/net/android/javatests/src/org/chromium/net/NetworkChangeNotifierTest.java b/net/android/javatests/src/org/chromium/net/NetworkChangeNotifierTest.java
index 8d6aa8e9fe9d736c4c5690e949264937f4ac98ff..a95b6f2a2d25702b0eb7cae56aab8f3c73099c04 100644
--- a/net/android/javatests/src/org/chromium/net/NetworkChangeNotifierTest.java
+++ b/net/android/javatests/src/org/chromium/net/NetworkChangeNotifierTest.java
@@ -105,6 +105,16 @@ public class NetworkChangeNotifierTest extends InstrumentationTestCase {
}
}
+ private static void triggerApplicationStateChange(
+ final RegistrationPolicyApplicationStatus policy, final int applicationState) {
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ policy.onApplicationStateChange(applicationState);
+ }
+ });
+ }
+
/**
* Mocks out calls to the ConnectivityManager.
*/
@@ -462,13 +472,13 @@ public class NetworkChangeNotifierTest extends InstrumentationTestCase {
public void testNetworkChangeNotifierRegistersForIntents() throws InterruptedException {
RegistrationPolicyApplicationStatus policy =
(RegistrationPolicyApplicationStatus) mReceiver.getRegistrationPolicy();
- policy.onApplicationStateChange(ApplicationState.HAS_RUNNING_ACTIVITIES);
+ triggerApplicationStateChange(policy, ApplicationState.HAS_RUNNING_ACTIVITIES);
assertTrue(mReceiver.isReceiverRegisteredForTesting());
- policy.onApplicationStateChange(ApplicationState.HAS_PAUSED_ACTIVITIES);
+ triggerApplicationStateChange(policy, ApplicationState.HAS_PAUSED_ACTIVITIES);
assertFalse(mReceiver.isReceiverRegisteredForTesting());
- policy.onApplicationStateChange(ApplicationState.HAS_RUNNING_ACTIVITIES);
+ triggerApplicationStateChange(policy, ApplicationState.HAS_RUNNING_ACTIVITIES);
assertTrue(mReceiver.isReceiverRegisteredForTesting());
}
@@ -606,14 +616,14 @@ public class NetworkChangeNotifierTest extends InstrumentationTestCase {
// Pretend we got moved to the background.
final RegistrationPolicyApplicationStatus policy =
(RegistrationPolicyApplicationStatus) mReceiver.getRegistrationPolicy();
- policy.onApplicationStateChange(ApplicationState.HAS_PAUSED_ACTIVITIES);
+ triggerApplicationStateChange(policy, ApplicationState.HAS_PAUSED_ACTIVITIES);
// Change the state.
mConnectivityDelegate.setActiveNetworkExists(true);
mConnectivityDelegate.setNetworkType(ConnectivityManager.TYPE_WIFI);
// The NetworkChangeNotifierAutoDetect doesn't receive any notification while we are in the
// background, but when we get back to the foreground the state changed should be detected
// and a notification sent.
- policy.onApplicationStateChange(ApplicationState.HAS_RUNNING_ACTIVITIES);
+ triggerApplicationStateChange(policy, ApplicationState.HAS_RUNNING_ACTIVITIES);
assertTrue(observer.hasReceivedNotification());
}
@@ -840,7 +850,7 @@ public class NetworkChangeNotifierTest extends InstrumentationTestCase {
RegistrationPolicyApplicationStatus policy =
(RegistrationPolicyApplicationStatus) ncn.getRegistrationPolicy();
- policy.onApplicationStateChange(ApplicationState.HAS_RUNNING_ACTIVITIES);
+ triggerApplicationStateChange(policy, ApplicationState.HAS_RUNNING_ACTIVITIES);
assertTrue(ncn.isReceiverRegisteredForTesting());
// Find NetworkChangeNotifierAutoDetect's NetworkCallback, which should have been registered
@@ -865,9 +875,9 @@ public class NetworkChangeNotifierTest extends InstrumentationTestCase {
// Simulate app backgrounding then foregrounding.
assertTrue(ncn.isReceiverRegisteredForTesting());
- policy.onApplicationStateChange(ApplicationState.HAS_PAUSED_ACTIVITIES);
+ triggerApplicationStateChange(policy, ApplicationState.HAS_PAUSED_ACTIVITIES);
assertFalse(ncn.isReceiverRegisteredForTesting());
- policy.onApplicationStateChange(ApplicationState.HAS_RUNNING_ACTIVITIES);
+ triggerApplicationStateChange(policy, ApplicationState.HAS_RUNNING_ACTIVITIES);
assertTrue(ncn.isReceiverRegisteredForTesting());
// Verify network list purged.
observer.assertLastChange(ChangeType.PURGE_LIST, NetId.INVALID);
« no previous file with comments | « chrome/android/javatests/src/org/chromium/chrome/browser/ChromeBackupIntegrationTest.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698