Bug 1511211 Re-enable addon test in testDistribution.java r=nalexander

This test formerly used a bootstrapped extension.  Converting it to a
webextension is straightforward, except for the fact that webextensions
are started asynchronously, so the test has to wait for a message from
the addon instead of just assuming it is started synchronously during
distribution handling.

Differential Revision: https://phabricator.services.mozilla.com/D13635

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andrew Swan 2018-12-14 20:41:19 +00:00
Родитель 45814e9ae8
Коммит a616b3883c
2 изменённых файлов: 37 добавлений и 10 удалений

Двоичный файл не отображается.

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

@ -22,6 +22,7 @@ import org.json.JSONObject;
import org.mozilla.gecko.Actions;
import org.mozilla.gecko.AppConstants;
import org.mozilla.gecko.BrowserLocaleManager;
import org.mozilla.gecko.EventDispatcher;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.GeckoSharedPrefs;
import org.mozilla.gecko.db.BrowserContract;
@ -30,6 +31,8 @@ import org.mozilla.gecko.distribution.ReferrerDescriptor;
import org.mozilla.gecko.distribution.ReferrerReceiver;
import org.mozilla.gecko.preferences.DistroSharedPrefsImport;
import org.mozilla.gecko.preferences.GeckoPreferences;
import org.mozilla.gecko.util.BundleEventListener;
import org.mozilla.gecko.util.EventCallback;
import org.mozilla.gecko.util.GeckoBundle;
import org.mozilla.gecko.util.ThreadUtils;
@ -59,12 +62,16 @@ import android.util.Log;
* extensions/
* distribution.test@mozilla.org.xpi
*/
public class testDistribution extends ContentProviderTest {
public class testDistribution extends ContentProviderTest implements BundleEventListener {
private static final String CLASS_REFERRER_RECEIVER = "org.mozilla.gecko.distribution.ReferrerReceiver";
private static final String ACTION_INSTALL_REFERRER = "com.android.vending.INSTALL_REFERRER";
private static final int WAIT_TIMEOUT_MSEC = 10000;
public static final String LOGTAG = "GeckoTestDistribution";
public static final String ADDON_MESSAGE = "Distribution:AddonEnabled";
private boolean mAddonEnabled;
private Object mAddonSignal;
public static class TestableDistribution extends Distribution {
@Override
protected JarInputStream fetchDistribution(URI uri,
@ -127,6 +134,17 @@ public class testDistribution extends ContentProviderTest {
mAsserter.dumpLog("Background task completed. Proceeding.");
}
@Override // BundleEventListener
public void handleMessage(final String event, final GeckoBundle message,
final EventCallback callback) {
if (ADDON_MESSAGE.equals(event)) {
mAddonEnabled = true;
synchronized (mAddonSignal) {
mAddonSignal.notify();
}
}
}
public void testDistribution() throws Exception {
mActivity = getActivity();
@ -140,6 +158,13 @@ public class testDistribution extends ContentProviderTest {
clearDistributionPref();
clearDistributionFromDataData();
// The extension contained in the distribution starts up
// asynchronously. Set up a listener for the message it broadcasts
// early so we don't miss it.
mAddonEnabled = false;
mAddonSignal = new Object();
EventDispatcher.getInstance().registerGeckoThreadListener(this, ADDON_MESSAGE);
setTestLocale("en-US");
try {
initDistribution(mockPackagePath);
@ -385,16 +410,18 @@ public class testDistribution extends ContentProviderTest {
}
private void checkAddon() {
/* Bug 1511211
try {
final String[] prefNames = { "distribution.test.addonEnabled" };
final JSONArray preferences = getPrefs(prefNames);
final JSONObject pref = (JSONObject) preferences.get(0);
mAsserter.is(pref.getBoolean("value"), true, "check distribution add-on is enabled");
} catch (JSONException e) {
mAsserter.ok(false, "exception getting preferences", e.toString());
if (!mAddonEnabled) {
mAsserter.dumpLog("Waiting for AddonEnabled event");
synchronized (mAddonSignal) {
try {
mAddonSignal.wait();
} catch (InterruptedException e) {
mAsserter.ok(false, "InterruptedException waiting for AddonEnabled event", e.toString());
}
}
}
*/
mAsserter.ok(mAddonEnabled, "Not enabled.",
"Distribution extension is not enabled");
}
private JSONArray getPrefs(String[] prefNames) throws JSONException {