mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 15:23:51 +00:00
Bug 1622816 - Ensure network is always available in TestRunnerActivity r=geckoview-reviewers,agi
When running mochitests on real hardware, we sometimes lose the network, causing strange timeouts. It's better if we crash immediately in those situations to avoid confusion. Differential Revision: https://phabricator.services.mozilla.com/D67383 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
3315f2c93c
commit
4ccf12cecf
@ -19,8 +19,12 @@ import org.mozilla.geckoview.WebExtensionController;
|
||||
import org.mozilla.geckoview.WebRequestError;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.SurfaceTexture;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.Network;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
@ -257,12 +261,29 @@ public class TestRunnerActivity extends Activity {
|
||||
}
|
||||
}
|
||||
|
||||
private void ensureNetworkAvailable() {
|
||||
ConnectivityManager cm = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
cm.registerDefaultNetworkCallback(new ConnectivityManager.NetworkCallback() {
|
||||
@Override
|
||||
public void onLost(Network network) {
|
||||
throw new RuntimeException("Network has been lost");
|
||||
}
|
||||
});
|
||||
|
||||
NetworkInfo network = cm.getActiveNetworkInfo();
|
||||
if (network == null || !network.isConnected()) {
|
||||
throw new RuntimeException("No network available");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
final Intent intent = getIntent();
|
||||
|
||||
ensureNetworkAvailable();
|
||||
|
||||
if (sRuntime == null) {
|
||||
final GeckoRuntimeSettings.Builder runtimeSettingsBuilder =
|
||||
new GeckoRuntimeSettings.Builder();
|
||||
|
Loading…
Reference in New Issue
Block a user