Skip to content

Commit

Permalink
[java] Add preferences when retrieving from a file
Browse files Browse the repository at this point in the history
Fixes #10775
  • Loading branch information
pujagani committed Jun 17, 2022
1 parent 5713de4 commit 9fac7d5
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions java/src/org/openqa/selenium/firefox/FirefoxProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public FirefoxProfile(File profileDir) {
if (prefsInModel.exists()) {
StringReader reader = new StringReader("{\"frozen\": {}, \"mutable\": {}}");
Preferences existingPrefs = new Preferences(reader, prefsInModel);
existingPrefs.addTo(this.additionalPrefs);
acceptUntrustedCerts = getBooleanPreference(existingPrefs, ACCEPT_UNTRUSTED_CERTS_PREF, true);
untrustedCertIssuer = getBooleanPreference(existingPrefs, ASSUME_UNTRUSTED_ISSUER_PREF, true);
} else {
Expand Down
51 changes: 51 additions & 0 deletions java/test/org/openqa/selenium/firefox/FirefoxOptionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,57 @@ public void shouldThrowAnExceptionIfSystemPropertyProfileDoesNotExist() {
}
}

@Test
public void shouldGetStringPreferencesFromGetProfile() {
String key = "browser.startup.homepage";
String value = "about:robots";

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference(key, value);

FirefoxOptions options = new FirefoxOptions();
options.setProfile(profile);

assertThat(profile.getStringPreference(key, "-")).isEqualTo(value);

FirefoxProfile extractedProfile = options.getProfile();
assertThat(extractedProfile.getStringPreference(key, "-")).isEqualTo(value);
}

@Test
public void shouldGetIntegerPreferencesFromGetProfile() {
String key = "key";
int value = 5;

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference(key, value);

FirefoxOptions options = new FirefoxOptions();
options.setProfile(profile);

assertThat(profile.getIntegerPreference(key, 0)).isEqualTo(value);

FirefoxProfile extractedProfile = options.getProfile();
assertThat(extractedProfile.getIntegerPreference(key, 0)).isEqualTo(value);
}

@Test
public void shouldGetBooleanPreferencesFromGetProfile() {
String key = "key";
boolean value = true;

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference(key, value);

FirefoxOptions options = new FirefoxOptions();
options.setProfile(profile);

assertThat(profile.getBooleanPreference(key, false)).isEqualTo(value);

FirefoxProfile extractedProfile = options.getProfile();
assertThat(extractedProfile.getBooleanPreference(key, false)).isEqualTo(value);
}

@Test
public void callingToStringWhenTheBinaryDoesNotExistShouldNotCauseAnException() {
FirefoxOptions options =
Expand Down

0 comments on commit 9fac7d5

Please sign in to comment.