// Test distribution and preferences values stored in preferences.json private void checkPreferences() { String prefID = "distribution.id"; String prefAbout = "distribution.about"; String prefVersion = "distribution.version"; String prefTestBoolean = "distribution.test.boolean"; String prefTestString = "distribution.test.string"; String prefTestInt = "distribution.test.int"; try { final String[] prefNames = { prefID, prefAbout, prefVersion, prefTestBoolean, prefTestString, prefTestInt }; Actions.RepeatedEventExpecter eventExpecter = mActions.expectGoannaEvent("Preferences:Data"); mActions.sendPreferencesGetEvent(PREF_REQUEST_ID, prefNames); JSONObject data = null; int requestId = -1; // Wait until we get the correct "Preferences:Data" event while (requestId != PREF_REQUEST_ID) { data = new JSONObject(eventExpecter.blockForEventData()); requestId = data.getInt("requestId"); } eventExpecter.unregisterListener(); JSONArray preferences = data.getJSONArray("preferences"); for (int i = 0; i < preferences.length(); i++) { JSONObject pref = (JSONObject) preferences.get(i); String name = pref.getString("name"); if (name.equals(prefID)) { mAsserter.is(pref.getString("value"), "test-partner", "check " + prefID); } else if (name.equals(prefAbout)) { mAsserter.is(pref.getString("value"), "Test Partner", "check " + prefAbout); } else if (name.equals(prefVersion)) { mAsserter.is(pref.getInt("value"), 1, "check " + prefVersion); } else if (name.equals(prefTestBoolean)) { mAsserter.is(pref.getBoolean("value"), true, "check " + prefTestBoolean); } else if (name.equals(prefTestString)) { mAsserter.is(pref.getString("value"), "test", "check " + prefTestString); } else if (name.equals(prefTestInt)) { mAsserter.is(pref.getInt("value"), 5, "check " + prefTestInt); } } } catch (JSONException e) { mAsserter.ok(false, "exception getting preferences", e.toString()); } }
private void checkSearchPlugin() { Actions.RepeatedEventExpecter eventExpecter = mActions.expectGoannaEvent("SearchEngines:Data"); mActions.sendGoannaEvent("SearchEngines:GetVisible", null); try { JSONObject data = new JSONObject(eventExpecter.blockForEventData()); eventExpecter.unregisterListener(); JSONArray searchEngines = data.getJSONArray("searchEngines"); boolean foundEngine = false; for (int i = 0; i < searchEngines.length(); i++) { JSONObject engine = (JSONObject) searchEngines.get(i); String name = engine.getString("name"); if (name.equals("Test search engine")) { foundEngine = true; break; } } mAsserter.ok(foundEngine, "check search plugin", "found test search plugin"); } catch (JSONException e) { mAsserter.ok(false, "exception getting search plugins", e.toString()); } }
// Test localized distribution and preferences values stored in preferences.json private void checkLocalizedPreferences(String aLocale) { String prefAbout = "distribution.about"; String prefLocalizeable = "distribution.test.localizeable"; String prefLocalizeableOverride = "distribution.test.localizeable-override"; try { final String[] prefNames = {prefAbout, prefLocalizeable, prefLocalizeableOverride}; Actions.RepeatedEventExpecter eventExpecter = mActions.expectGoannaEvent("Preferences:Data"); mActions.sendPreferencesGetEvent(PREF_REQUEST_ID, prefNames); JSONObject data = null; int requestId = -1; // Wait until we get the correct "Preferences:Data" event while (requestId != PREF_REQUEST_ID) { data = new JSONObject(eventExpecter.blockForEventData()); requestId = data.getInt("requestId"); } eventExpecter.unregisterListener(); JSONArray preferences = data.getJSONArray("preferences"); for (int i = 0; i < preferences.length(); i++) { JSONObject pref = (JSONObject) preferences.get(i); String name = pref.getString("name"); if (name.equals(prefAbout)) { if (aLocale.equals("en-US")) { mAsserter.is(pref.getString("value"), "Test Partner", "check " + prefAbout); } else if (aLocale.equals("es-MX")) { mAsserter.is(pref.getString("value"), "Afiliado de Prueba", "check " + prefAbout); } } else if (name.equals(prefLocalizeable)) { if (aLocale.equals("en-US")) { mAsserter.is( pref.getString("value"), "http://test.org/en-US/en-US/", "check " + prefLocalizeable); } else if (aLocale.equals("es-MX")) { mAsserter.is( pref.getString("value"), "http://test.org/es-MX/es-MX/", "check " + prefLocalizeable); } } else if (name.equals(prefLocalizeableOverride)) { if (aLocale.equals("en-US")) { mAsserter.is( pref.getString("value"), "http://cheese.com", "check " + prefLocalizeableOverride); } else if (aLocale.equals("es-MX")) { mAsserter.is( pref.getString("value"), "http://test.org/es-MX/", "check " + prefLocalizeableOverride); } } } } catch (JSONException e) { mAsserter.ok(false, "exception getting preferences", e.toString()); } }