Skip to content

Commit d834b32

Browse files
committedMay 25, 2014
fixing toJSON of chrome options where equal options become unequal.
1 parent 86fc110 commit d834b32

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed
 

Diff for: ‎java/client/src/org/openqa/selenium/chrome/ChromeOptions.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,12 @@ public Object getExperimentalOption(String name) {
202202
* JSON.
203203
*/
204204
public JSONObject toJson() throws IOException, JSONException {
205-
JSONObject options = new JSONObject(experimentalOptions);
205+
JSONObject options = new JSONObject();
206+
// copy experimental options, instead of passing to the JSONObject constructor
207+
// because the JSON library will mutate the map passed in.
208+
for (String key : experimentalOptions.keySet()) {
209+
options.put(key, experimentalOptions.get(key));
210+
}
206211

207212
if (binary != null) {
208213
options.put("binary", binary);

Diff for: ‎java/client/test/org/openqa/selenium/chrome/ChromeOptionsFunctionalTest.java

+19
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
package org.openqa.selenium.chrome;
1919

2020
import static org.junit.Assert.assertEquals;
21+
import static org.junit.Assert.assertTrue;
2122

2223
import org.junit.After;
24+
import org.junit.Before;
2325
import org.junit.Test;
2426
import org.openqa.selenium.testing.JUnit4TestBase;
2527
import org.openqa.selenium.testing.NeedsLocalEnvironment;
@@ -37,6 +39,12 @@ public void tearDown() throws Exception {
3739
}
3840
}
3941

42+
@Before
43+
@Override
44+
public void createDriver() throws Exception {
45+
// do nothing, don't want to have it create a driver for these tests
46+
}
47+
4048
@NeedsLocalEnvironment
4149
@Test
4250
public void canStartChromeWithCustomOptions() {
@@ -48,4 +56,15 @@ public void canStartChromeWithCustomOptions() {
4856
Object userAgent = driver.executeScript("return window.navigator.userAgent");
4957
assertEquals("foo;bar", userAgent);
5058
}
59+
60+
@NeedsLocalEnvironment
61+
@Test
62+
public void optionsStayEqualAfterSerialization() throws Exception {
63+
ChromeOptions options1 = new ChromeOptions();
64+
ChromeOptions options2 = new ChromeOptions();
65+
assertTrue("empty chrome options should be equal", options1.equals(options2));
66+
options1.toJson();
67+
assertTrue("empty chrome options after one is .toJson() should be equal",
68+
options1.equals(options2));
69+
}
5170
}

1 commit comments

Comments
 (1)

lukeis commented on May 25, 2014

@lukeis
MemberAuthor
Please sign in to comment.