Bug 906088 - part 6 - update tests to use the new API; r=kats

Fixed testPrefsObserver to use the correct requestId for unregistering observers.
Changed all tests to use th same hexadecimal constant, per Kats's feedback.  Asking
for actual review now.  Local robocop testing shows the failing tests on try now pass
locally, so I'm assuming I have fixed the issues...
This commit is contained in:
Nathan Froyd 2013-09-04 09:58:32 -04:00
parent 53844a7710
commit de359b548a
8 changed files with 117 additions and 79 deletions

View File

@ -48,6 +48,29 @@ public interface Actions {
*/
void sendGeckoEvent(String geckoEvent, String data);
/**
* Sends a preferences get event to Gecko.
*
* @param requestId The id of this request.
* @param prefNames The preferences being requested.
*/
void sendPreferencesGetEvent(int requestId, String[] prefNames);
/**
* Sends a preferences observe event to Gecko.
*
* @param requestId The id of this request.
* @param prefNames The preferences being requested.
*/
void sendPreferencesObserveEvent(int requestId, String[] prefNames);
/**
* Sends a preferences remove observers event to Gecko.
*
* @param requestId The id of this request.
*/
void sendPreferencesRemoveObserversEvent(int requestid);
/**
* Listens for a gecko event to be sent from the Gecko instance.
* The returned object can be used to test if the event has been

View File

@ -44,6 +44,9 @@ public class FennecNativeActions implements Actions {
private Method mRegisterEventListener;
private Method mUnregisterEventListener;
private Method mBroadcastEvent;
private Method mPreferencesGetEvent;
private Method mPreferencesObserveEvent;
private Method mPreferencesRemoveObserversEvent;
private Method mSetDrawListener;
private Method mQuerySql;
private Object mRobocopApi;
@ -66,6 +69,9 @@ public class FennecNativeActions implements Actions {
mRegisterEventListener = mApiClass.getMethod("registerEventListener", String.class, mEventListenerClass);
mUnregisterEventListener = mApiClass.getMethod("unregisterEventListener", String.class, mEventListenerClass);
mBroadcastEvent = mApiClass.getMethod("broadcastEvent", String.class, String.class);
mPreferencesGetEvent = mApiClass.getMethod("preferencesGetEvent", Integer.TYPE, String[].class);
mPreferencesObserveEvent = mApiClass.getMethod("preferencesObserveEvent", Integer.TYPE, String[].class);
mPreferencesRemoveObserversEvent = mApiClass.getMethod("preferencesRemoveObserversEvent", Integer.TYPE);
mSetDrawListener = mApiClass.getMethod("setDrawListener", mDrawListenerClass);
mQuerySql = mApiClass.getMethod("querySql", String.class, String.class);
@ -265,6 +271,34 @@ public class FennecNativeActions implements Actions {
}
}
private void sendPreferencesEvent(Method method, int requestId, String[] prefNames) {
try {
method.invoke(mRobocopApi, requestId, prefNames);
} catch (IllegalAccessException e) {
FennecNativeDriver.log(LogLevel.ERROR, e);
} catch (InvocationTargetException e) {
FennecNativeDriver.log(LogLevel.ERROR, e);
}
}
public void sendPreferencesGetEvent(int requestId, String[] prefNames) {
sendPreferencesEvent(mPreferencesGetEvent, requestId, prefNames);
}
public void sendPreferencesObserveEvent(int requestId, String[] prefNames) {
sendPreferencesEvent(mPreferencesObserveEvent, requestId, prefNames);
}
public void sendPreferencesRemoveObserversEvent(int requestId) {
try {
mPreferencesRemoveObserversEvent.invoke(mRobocopApi, requestId);
} catch (IllegalAccessException e) {
FennecNativeDriver.log(LogLevel.ERROR, e);
} catch (InvocationTargetException e) {
FennecNativeDriver.log(LogLevel.ERROR, e);
}
}
class DrawListenerProxy implements InvocationHandler {
private final PaintExpecter mPaintExpecter;

View File

@ -35,6 +35,18 @@ public class RobocopAPI {
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent(subject, data));
}
public void preferencesGetEvent(int requestId, String[] prefNames) {
GeckoAppShell.sendEventToGecko(GeckoEvent.createPreferencesGetEvent(requestId, prefNames));
}
public void preferencesObserveEvent(int requestId, String[] prefNames) {
GeckoAppShell.sendEventToGecko(GeckoEvent.createPreferencesObserveEvent(requestId, prefNames));
}
public void preferencesRemoveObserversEvent(int requestId) {
GeckoAppShell.sendEventToGecko(GeckoEvent.createPreferencesRemoveObserversEvent(requestId));
}
public void setDrawListener(GeckoLayerClient.DrawListener listener) {
GeckoAppShell.getLayerView().getLayerClient().setDrawListener(listener);
}

View File

@ -59,21 +59,18 @@ public class testAddonManager extends PixelTest {
mActions.sendGeckoEvent("Preferences:Set", jsonPref.toString());
// Wait for confirmation of the pref change before proceeding with the test.
JSONArray getPrefData = new JSONArray();
getPrefData.put("extensions.getAddons.browseAddons");
JSONObject message = new JSONObject();
message.put("requestId", "testAddonManager");
message.put("preferences", getPrefData);
final String[] prefNames = { "extensions.getAddons.browseAddons" };
final int ourRequestId = 0x7357;
Actions.RepeatedEventExpecter eventExpecter = mActions.expectGeckoEvent("Preferences:Data");
mActions.sendGeckoEvent("Preferences:Get", message.toString());
mActions.sendPreferencesGetEvent(ourRequestId, prefNames);
JSONObject data = null;
String requestId = "";
int requestId = -1;
// Wait until we get the correct "Preferences:Data" event
while (!requestId.equals("testAddonManager")) {
while (requestId != ourRequestId) {
data = new JSONObject(eventExpecter.blockForEventData());
requestId = data.getString("requestId");
requestId = data.getInt("requestId");
}
eventExpecter.unregisterListener();

View File

@ -29,7 +29,7 @@ import org.json.JSONObject;
*/
public class testDistribution extends ContentProviderTest {
private static final String MOCK_PACKAGE = "mock-package.zip";
private static final String PREF_REQUEST_ID = "testDistribution";
private static final int PREF_REQUEST_ID = 0x7357;
private Activity mActivity;
@ -86,28 +86,23 @@ public class testDistribution extends ContentProviderTest {
String prefTestInt = "distribution.test.int";
try {
JSONArray getPrefData = new JSONArray();
getPrefData.put(prefID);
getPrefData.put(prefAbout);
getPrefData.put(prefVersion);
getPrefData.put(prefTestBoolean);
getPrefData.put(prefTestString);
getPrefData.put(prefTestInt);
JSONObject message = new JSONObject();
message.put("requestId", PREF_REQUEST_ID);
message.put("preferences", getPrefData);
final String[] prefNames = { prefID,
prefAbout,
prefVersion,
prefTestBoolean,
prefTestString,
prefTestInt };
Actions.RepeatedEventExpecter eventExpecter = mActions.expectGeckoEvent("Preferences:Data");
mActions.sendGeckoEvent("Preferences:Get", message.toString());
mActions.sendPreferencesGetEvent(PREF_REQUEST_ID, prefNames);
JSONObject data = null;
String requestId = "";
int requestId = -1;
// Wait until we get the correct "Preferences:Data" event
while (!requestId.equals(PREF_REQUEST_ID)) {
while (requestId != PREF_REQUEST_ID) {
data = new JSONObject(eventExpecter.blockForEventData());
requestId = data.getString("requestId");
requestId = data.getInt("requestId");
}
eventExpecter.unregisterListener();
@ -172,23 +167,18 @@ public class testDistribution extends ContentProviderTest {
mActions.sendGeckoEvent("Preferences:Set", jsonPref.toString());
// Wait for confirmation of the pref change.
JSONArray getPrefData = new JSONArray();
getPrefData.put(prefUseragentLocale);
JSONObject message = new JSONObject();
message.put("requestId", PREF_REQUEST_ID);
message.put("preferences", getPrefData);
final String[] prefNames = { prefUseragentLocale };
Actions.RepeatedEventExpecter eventExpecter = mActions.expectGeckoEvent("Preferences:Data");
mActions.sendGeckoEvent("Preferences:Get", message.toString());
mActions.sendPreferencesGetEvent(PREF_REQUEST_ID, prefNames);
JSONObject data = null;
String requestId = "";
int requestId = -1;
// Wait until we get the correct "Preferences:Data" event
while (!requestId.equals(PREF_REQUEST_ID)) {
while (requestId != PREF_REQUEST_ID) {
data = new JSONObject(eventExpecter.blockForEventData());
requestId = data.getString("requestId");
requestId = data.getInt("requestId");
}
eventExpecter.unregisterListener();
@ -204,25 +194,18 @@ public class testDistribution extends ContentProviderTest {
String prefLocalizeableOverride = "distribution.test.localizeable-override";
try {
JSONArray getPrefData = new JSONArray();
getPrefData.put(prefAbout);
getPrefData.put(prefLocalizeable);
getPrefData.put(prefLocalizeableOverride);
JSONObject message = new JSONObject();
message.put("requestId", PREF_REQUEST_ID);
message.put("preferences", getPrefData);
final String[] prefNames = { prefAbout, prefLocalizeable, prefLocalizeableOverride };
Actions.RepeatedEventExpecter eventExpecter = mActions.expectGeckoEvent("Preferences:Data");
mActions.sendGeckoEvent("Preferences:Get", message.toString());
mActions.sendPreferencesGetEvent(PREF_REQUEST_ID, prefNames);
JSONObject data = null;
String requestId = "";
int requestId = -1;
// Wait until we get the correct "Preferences:Data" event
while (!requestId.equals(PREF_REQUEST_ID)) {
while (requestId != PREF_REQUEST_ID) {
data = new JSONObject(eventExpecter.blockForEventData());
requestId = data.getString("requestId");
requestId = data.getInt("requestId");
}
eventExpecter.unregisterListener();

View File

@ -81,22 +81,19 @@ public class testDoorHanger extends BaseTest {
boolean offlineAllowedByDefault = true;
try {
// Save offline-allow-by-default preferences first
JSONArray getPrefData = new JSONArray();
getPrefData.put("offline-apps.allow_by_default");
JSONObject message = new JSONObject();
message.put("requestId", "testDoorHanger");
message.put("preferences", getPrefData);
final String[] prefNames = { "offline-apps.allow_by_default" };
final int ourRequestId = 0x7357;
Actions.RepeatedEventExpecter eventExpecter = mActions.expectGeckoEvent("Preferences:Data");
mActions.sendGeckoEvent("Preferences:Get", message.toString());
mActions.sendPreferencesGetEvent(ourRequestId, prefNames);
JSONObject data = null;
String requestId = "";
int requestId = -1;
// Wait until we get the correct "Preferences:Data" event
while (!requestId.equals("testDoorHanger")) {
while (requestId != ourRequestId) {
data = new JSONObject(eventExpecter.blockForEventData());
requestId = data.getString("requestId");
requestId = data.getInt("requestId");
}
eventExpecter.unregisterListener();

View File

@ -126,21 +126,18 @@ public class testPasswordEncrypt extends BaseTest {
mActions.sendGeckoEvent("Preferences:Set", jsonPref.toString());
// Wait for confirmation of the pref change before proceeding with the test.
JSONArray getPrefData = new JSONArray();
getPrefData.put("privacy.masterpassword.enabled");
JSONObject message = new JSONObject();
message.put("requestId", "testPasswordEncrypt");
message.put("preferences", getPrefData);
final String[] prefNames = { "privacy.masterpassword.enabled" };
final int ourRequestId = 0x73577;
Actions.RepeatedEventExpecter eventExpecter = mActions.expectGeckoEvent("Preferences:Data");
mActions.sendGeckoEvent("Preferences:Get", message.toString());
mActions.sendPreferencesGetEvent(ourRequestId, prefNames);
JSONObject data = null;
String requestId = "";
int requestId = -1;
// Wait until we get the correct "Preferences:Data" event
while (!requestId.equals("testPasswordEncrypt")) {
while (requestId != ourRequestId) {
data = new JSONObject(eventExpecter.blockForEventData());
requestId = data.getString("requestId");
requestId = data.getInt("requestId");
}
} catch (Exception ex) {
mAsserter.ok(false, "exception in toggleMasterPassword", ex.toString());

View File

@ -16,7 +16,7 @@ import org.json.JSONObject;
*/
public class testPrefsObserver extends BaseTest {
private static final String PREF_TEST_PREF = "robocop.tests.dummy";
private static final String PREF_REQUEST_ID = "testPrefsObserver";
private static final int PREF_OBSERVE_REQUEST_ID = 0x7357;
private static final long PREF_TIMEOUT = 10000;
private Actions.RepeatedEventExpecter mExpecter;
@ -40,15 +40,15 @@ public class testPrefsObserver extends BaseTest {
mAsserter.dumpLog("Waiting to check pref");
JSONObject data = null;
String requestId = "";
int requestId = -1;
while (!requestId.equals(PREF_REQUEST_ID)) {
while (requestId != PREF_OBSERVE_REQUEST_ID) {
data = new JSONObject(mExpecter.blockForEventData());
if (!mExpecter.eventReceived()) {
mAsserter.ok(false, "Checking pref is correct value", "Didn't receive pref");
return;
}
requestId = data.getString("requestId");
requestId = data.getInt("requestId");
}
JSONObject pref = data.getJSONArray("preferences").getJSONObject(0);
@ -61,16 +61,16 @@ public class testPrefsObserver extends BaseTest {
mAsserter.dumpLog("Checking pref observer is removed");
JSONObject pref = null;
String requestId = "";
int requestId = -1;
while (!requestId.equals(PREF_REQUEST_ID)) {
while (requestId != PREF_OBSERVE_REQUEST_ID) {
String data = mExpecter.blockForEventDataWithTimeout(PREF_TIMEOUT);
if (data == null) {
mAsserter.ok(true, "Verifying pref is unobserved", "Didn't get unobserved pref");
return;
}
pref = new JSONObject(data);
requestId = pref.getString("requestId");
requestId = pref.getInt("requestId");
}
mAsserter.ok(false, "Received unobserved pref change", "");
@ -80,19 +80,14 @@ public class testPrefsObserver extends BaseTest {
mAsserter.dumpLog("Setting up pref observer");
// Setup the pref observer
JSONArray getPrefData = new JSONArray();
getPrefData.put(PREF_TEST_PREF);
JSONObject message = new JSONObject();
message.put("requestId", PREF_REQUEST_ID);
message.put("preferences", getPrefData);
mExpecter = mActions.expectGeckoEvent("Preferences:Data");
mActions.sendGeckoEvent("Preferences:Observe", message.toString());
mActions.sendPreferencesObserveEvent(PREF_OBSERVE_REQUEST_ID, new String[] { PREF_TEST_PREF });
}
public void removePrefObserver() {
mAsserter.dumpLog("Removing pref observer");
mActions.sendGeckoEvent("Preferences:RemoveObservers", PREF_REQUEST_ID);
mActions.sendPreferencesRemoveObserversEvent(PREF_OBSERVE_REQUEST_ID);
}
public void testPrefsObserver() {