Skip to content

Commit

Permalink
merge preferences to one hashmap #192
Browse files Browse the repository at this point in the history
  • Loading branch information
oomelianchuk committed Apr 2, 2024
1 parent 6896967 commit 291a139
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,18 +253,20 @@ else if (firefoxBrowsers.contains(browserName))
FirefoxProfile profile = new FirefoxProfile();

// differentiate types of preference values to avoid misunderstanding
if (config.getPreferencesBoolean() != null && config.getPreferencesBoolean().isEmpty())
{
config.getPreferencesBoolean().forEach((key, val) -> profile.setPreference(key, val));
}
if (config.getPreferencesInteger() != null && config.getPreferencesInteger().isEmpty())
{
config.getPreferencesInteger().forEach((key, val) -> profile.setPreference(key, val));
}
if (config.getPreferencesString() != null && config.getPreferencesString().isEmpty())
{
config.getPreferencesString().forEach((key, val) -> profile.setPreference(key, val));
}
config.getPreferences().forEach((key, val) -> {
if (val.equals("true") | val.equals("false"))
{
profile.setPreference(key, Boolean.parseBoolean(val.toString()));
}
else if (StringUtils.isNumeric(val.toString()))
{
profile.setPreference(key, Integer.parseInt(val.toString()));
}
else
{
profile.setPreference(key, val.toString());
}
});
options.setProfile(profile);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ public class BrowserConfiguration

private List<String> arguments;

private Map<String, Boolean> preferencesBoolean;

private Map<String, Integer> preferencesInteger;

private Map<String, String> preferencesString;
private Map<String, Object> preferences;

public String getConfigTag()
{
Expand Down Expand Up @@ -117,61 +113,15 @@ public void setArguments(List<String> arguments)

public Map<String, Object> getPreferences()
{
Map<String, Object> allPreferences = new HashMap<>();
if (preferencesBoolean != null)
{
allPreferences.putAll(preferencesBoolean);
}
if (preferencesInteger != null)
{
allPreferences.putAll(preferencesInteger);
}
if (preferencesString != null)
{
allPreferences.putAll(preferencesString);
}
return allPreferences;
}

public Map<String, Boolean> getPreferencesBoolean()
{
return preferencesBoolean;
}

public Map<String, Integer> getPreferencesInteger()
{
return preferencesInteger;
}

public Map<String, String> getPreferencesString()
{
return preferencesString;
}

public void addPreference(String key, boolean val)
{
if (this.preferencesBoolean == null)
{
this.preferencesBoolean = new HashMap<>();
}
this.preferencesBoolean.put(key, val);
}

public void addPreference(String key, int val)
{
if (this.preferencesInteger == null)
{
this.preferencesInteger = new HashMap<>();
}
this.preferencesInteger.put(key, val);
return preferences;
}

public void addPreference(String key, String val)
public void addPreference(String key, Object val)
{
if (this.preferencesString == null)
if (this.preferences == null)
{
this.preferencesString = new HashMap<>();
this.preferences = new HashMap<String, Object>();
}
this.preferencesString.put(key, val);
this.preferences.put(key, val);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -333,18 +333,12 @@ private void checkChrome(BrowserConfiguration config)
LinkedList<String> list = new LinkedList<>();
list.add("headless");
Assert.assertEquals(list, config.getArguments());

HashMap<String, Boolean> prefsBoolean = new HashMap<>();
prefsBoolean.put("geolocation.enabled", true);
Assert.assertEquals(prefsBoolean, config.getPreferencesBoolean());

HashMap<String, Integer> prefsInteger = new HashMap<>();
prefsInteger.put("renderer.memory_cache.size", 120000);
Assert.assertEquals(prefsInteger, config.getPreferencesInteger());

HashMap<String, String> prefsString = new HashMap<>();
prefsString.put("homepage", "https://www.xceptance.com");
Assert.assertEquals(prefsString, config.getPreferencesString());

HashMap<String, Object> prefs = new HashMap<>();
prefs.put("geolocation.enabled", true);
prefs.put("renderer.memory_cache.size", 120000);
prefs.put("homepage", "https://www.xceptance.com");
Assert.assertEquals(prefs, config.getPreferences());
}

private void checkMultiChrome(BrowserConfiguration config)
Expand Down Expand Up @@ -372,18 +366,12 @@ private void checkFirefox(BrowserConfiguration config)
LinkedList<String> list = new LinkedList<>();
list.add("headless");
Assert.assertEquals(list, config.getArguments());

HashMap<String, Boolean> prefsBoolean = new HashMap<>();
prefsBoolean.put("media.navigator.permission.disabled", true);
Assert.assertEquals(prefsBoolean, config.getPreferencesBoolean());

HashMap<String, Integer> prefsInteger = new HashMap<>();
prefsInteger.put("app.update.backgroundMaxErrors", 1);
Assert.assertEquals(prefsInteger, config.getPreferencesInteger());

HashMap<String, String> prefsString = new HashMap<>();
prefsString.put("browser.startup.homepage", "https://www.xceptance.com");
Assert.assertEquals(prefsString, config.getPreferencesString());

HashMap<String, Object> prefs = new HashMap<>();
prefs.put("media.navigator.permission.disabled", true);
prefs.put("app.update.backgroundMaxErrors", 1);
prefs.put("browser.startup.homepage", "https://www.xceptance.com");
Assert.assertEquals(prefs, config.getPreferences());
}

private void checkMultiFirefox(BrowserConfiguration config)
Expand Down

0 comments on commit 291a139

Please sign in to comment.