|
| 1 | +package org.openqa.selenium.firefox.internal; |
| 2 | + |
| 3 | +import static org.junit.Assert.assertEquals; |
| 4 | +import static org.junit.Assert.fail; |
| 5 | + |
| 6 | +import org.junit.Test; |
| 7 | +import org.openqa.selenium.WebDriverException; |
| 8 | +import org.openqa.selenium.firefox.FirefoxBinary; |
| 9 | +import org.openqa.selenium.firefox.FirefoxProfile; |
| 10 | +import org.openqa.selenium.internal.SocketLock; |
| 11 | + |
| 12 | +public class NewProfileExtensionConnectionTest { |
| 13 | + |
| 14 | + @Test |
| 15 | + public void canBeConstructed() throws Exception { |
| 16 | + new NewProfileExtensionConnection |
| 17 | + (makeLock(), new FirefoxBinary(), new FirefoxProfile(), "my-host"); |
| 18 | + } |
| 19 | + |
| 20 | + @Test |
| 21 | + public void shouldDefaultToPortSpecifiedInProfileWhenDeterminingNextFreePort() throws Exception { |
| 22 | + int expectedPort = 2400; |
| 23 | + |
| 24 | + FirefoxProfile profile = new FirefoxProfile(); |
| 25 | + profile.setPreference(FirefoxProfile.PORT_PREFERENCE, expectedPort); |
| 26 | + |
| 27 | + NewProfileExtensionConnection connection = new NewProfileExtensionConnection |
| 28 | + (makeLock(), new FirefoxBinary(), profile, "my-host"); |
| 29 | + |
| 30 | + try { |
| 31 | + |
| 32 | + connection.start(); |
| 33 | + |
| 34 | + fail("there was an unexpected server listening on " + expectedPort + "; expected connection to fail"); |
| 35 | + } catch (WebDriverException e) { |
| 36 | + int PORT_PREFERENCE_NOT_PROPAGATED = -1; |
| 37 | + assertEquals(expectedPort, |
| 38 | + profile.getIntegerPreference(FirefoxProfile.PORT_PREFERENCE, PORT_PREFERENCE_NOT_PROPAGATED)); |
| 39 | + } |
| 40 | + |
| 41 | + } |
| 42 | + |
| 43 | + private SocketLock makeLock() { |
| 44 | + return new SocketLock(4200); |
| 45 | + } |
| 46 | +} |
0 commit comments