Bug 929654 - Part 4: Fail earlier for local testers who can't reach mochi.test. r=nalexander

This commit is contained in:
Mark Capella 2014-10-04 01:41:22 -04:00
Родитель a3fa12f6bc
Коммит 1973796470
3 изменённых файлов: 37 добавлений и 4 удалений

Просмотреть файл

@ -6,14 +6,18 @@ package org.mozilla.gecko.tests;
import java.util.Map;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.mozilla.gecko.AppConstants;
import org.mozilla.gecko.Assert;
import org.mozilla.gecko.FennecInstrumentationTestRunner;
import org.mozilla.gecko.FennecMochitestAssert;
import org.mozilla.gecko.FennecNativeDriver;
import org.mozilla.gecko.FennecTalosAssert;
import org.mozilla.gecko.AppConstants;
import android.app.Activity;
import android.content.Context;
import android.os.PowerManager;
@ -110,6 +114,33 @@ public abstract class BaseRobocopTest extends ActivityInstrumentationTestCase2<A
mAsserter.setTestName(getClass().getName());
}
/**
* Function to early abort if we can't reach the given HTTP server. Provides local testers
* with diagnostic information. Not currently available for TALOS tests, which are rarely run
* locally in any case.
*/
public void throwIfHttpGetFails() {
if (getTestType() == Type.TALOS) {
return;
}
// rawURL to test fetching from. This should be a raw (IP) URL, not an alias
// (like mochi.test). We can't (easily) test fetching from the aliases, since
// those are managed by Fennec's proxy settings.
final String rawUrl = ((String) mConfig.get("rawhost")).replaceAll("(/$)", "");
try {
final HttpClient httpclient = new DefaultHttpClient();
final HttpResponse response = httpclient.execute(new HttpGet(rawUrl));
final int statusCode = response.getStatusLine().getStatusCode();
if (200 != statusCode) {
throw new IllegalStateException("Status code: " + statusCode);
}
} catch (Exception e) {
mAsserter.ok(false, "Robocop tests on your device need network/wifi access to reach: [" + rawUrl + "].", e.toString());
}
}
/**
* Ensure that the screen on the test device is powered on during tests.
*/

Просмотреть файл

@ -122,7 +122,8 @@ abstract class BaseTest extends BaseRobocopTest {
mDevice = new Device();
mDatabaseHelper = new DatabaseHelper(mActivity, mAsserter);
// Ensure Robocop tests are run with Display powered on.
// Ensure Robocop tests have access to network, and are run with Display powered on.
throwIfHttpGetFails();
throwIfScreenNotOn();
}

Просмотреть файл

@ -75,7 +75,8 @@ abstract class UITest extends BaseRobocopTest
initComponents();
initHelpers();
// Ensure Robocop tests are run with Display powered on.
// Ensure Robocop tests have access to network, and are run with Display powered on.
throwIfHttpGetFails();
throwIfScreenNotOn();
}