Merge "Improve error message when testing network factory"
This commit is contained in:
@@ -3624,51 +3624,55 @@ public class ConnectivityServiceTest {
|
|||||||
// Register the factory and expect it to start looking for a network.
|
// Register the factory and expect it to start looking for a network.
|
||||||
testFactory.expectAddRequestsWithScores(0); // Score 0 as the request is not served yet.
|
testFactory.expectAddRequestsWithScores(0); // Score 0 as the request is not served yet.
|
||||||
testFactory.register();
|
testFactory.register();
|
||||||
testFactory.waitForNetworkRequests(1);
|
|
||||||
assertTrue(testFactory.getMyStartRequested());
|
|
||||||
|
|
||||||
// Bring up wifi. The factory stops looking for a network.
|
try {
|
||||||
mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI);
|
testFactory.waitForNetworkRequests(1);
|
||||||
// Score 60 - 40 penalty for not validated yet, then 60 when it validates
|
assertTrue(testFactory.getMyStartRequested());
|
||||||
testFactory.expectAddRequestsWithScores(20, 60);
|
|
||||||
mWiFiNetworkAgent.connect(true);
|
|
||||||
testFactory.waitForRequests();
|
|
||||||
assertFalse(testFactory.getMyStartRequested());
|
|
||||||
|
|
||||||
ContentResolver cr = mServiceContext.getContentResolver();
|
// Bring up wifi. The factory stops looking for a network.
|
||||||
|
mWiFiNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_WIFI);
|
||||||
|
// Score 60 - 40 penalty for not validated yet, then 60 when it validates
|
||||||
|
testFactory.expectAddRequestsWithScores(20, 60);
|
||||||
|
mWiFiNetworkAgent.connect(true);
|
||||||
|
testFactory.waitForRequests();
|
||||||
|
assertFalse(testFactory.getMyStartRequested());
|
||||||
|
|
||||||
// Turn on mobile data always on. The factory starts looking again.
|
ContentResolver cr = mServiceContext.getContentResolver();
|
||||||
testFactory.expectAddRequestsWithScores(0); // Always on requests comes up with score 0
|
|
||||||
setAlwaysOnNetworks(true);
|
|
||||||
testFactory.waitForNetworkRequests(2);
|
|
||||||
assertTrue(testFactory.getMyStartRequested());
|
|
||||||
|
|
||||||
// Bring up cell data and check that the factory stops looking.
|
// Turn on mobile data always on. The factory starts looking again.
|
||||||
assertLength(1, mCm.getAllNetworks());
|
testFactory.expectAddRequestsWithScores(0); // Always on requests comes up with score 0
|
||||||
mCellNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_CELLULAR);
|
setAlwaysOnNetworks(true);
|
||||||
testFactory.expectAddRequestsWithScores(10, 50); // Unvalidated, then validated
|
testFactory.waitForNetworkRequests(2);
|
||||||
mCellNetworkAgent.connect(true);
|
assertTrue(testFactory.getMyStartRequested());
|
||||||
cellNetworkCallback.expectAvailableThenValidatedCallbacks(mCellNetworkAgent);
|
|
||||||
testFactory.waitForNetworkRequests(2);
|
|
||||||
assertFalse(testFactory.getMyStartRequested()); // Because the cell network outscores us.
|
|
||||||
|
|
||||||
// Check that cell data stays up.
|
// Bring up cell data and check that the factory stops looking.
|
||||||
waitForIdle();
|
assertLength(1, mCm.getAllNetworks());
|
||||||
verifyActiveNetwork(TRANSPORT_WIFI);
|
mCellNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_CELLULAR);
|
||||||
assertLength(2, mCm.getAllNetworks());
|
testFactory.expectAddRequestsWithScores(10, 50); // Unvalidated, then validated
|
||||||
|
mCellNetworkAgent.connect(true);
|
||||||
|
cellNetworkCallback.expectAvailableThenValidatedCallbacks(mCellNetworkAgent);
|
||||||
|
testFactory.waitForNetworkRequests(2);
|
||||||
|
assertFalse(
|
||||||
|
testFactory.getMyStartRequested()); // Because the cell network outscores us.
|
||||||
|
|
||||||
// Turn off mobile data always on and expect the request to disappear...
|
// Check that cell data stays up.
|
||||||
testFactory.expectRemoveRequests(1);
|
waitForIdle();
|
||||||
setAlwaysOnNetworks(false);
|
verifyActiveNetwork(TRANSPORT_WIFI);
|
||||||
testFactory.waitForNetworkRequests(1);
|
assertLength(2, mCm.getAllNetworks());
|
||||||
|
|
||||||
// ... and cell data to be torn down.
|
// Turn off mobile data always on and expect the request to disappear...
|
||||||
cellNetworkCallback.expectCallback(CallbackEntry.LOST, mCellNetworkAgent);
|
testFactory.expectRemoveRequests(1);
|
||||||
assertLength(1, mCm.getAllNetworks());
|
setAlwaysOnNetworks(false);
|
||||||
|
testFactory.waitForNetworkRequests(1);
|
||||||
|
|
||||||
testFactory.terminate();
|
// ... and cell data to be torn down.
|
||||||
mCm.unregisterNetworkCallback(cellNetworkCallback);
|
cellNetworkCallback.expectCallback(CallbackEntry.LOST, mCellNetworkAgent);
|
||||||
handlerThread.quit();
|
assertLength(1, mCm.getAllNetworks());
|
||||||
|
} finally {
|
||||||
|
testFactory.terminate();
|
||||||
|
mCm.unregisterNetworkCallback(cellNetworkCallback);
|
||||||
|
handlerThread.quit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user