зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
3315f2c93c
Коммит
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();
|
||||
|
|
Загрузка…
Ссылка в новой задаче