SeleniumHQ/selenium — pull request #87 by Rob--W (2013-06-16 21:31:01+00:00)
Title: [SafariDriver] [Java] Support custom extensions for Safari

Solves https://code.google.com/p/selenium/issues/detail?id=4852

I've created a new capability and class (`SafariExtensions`) which allows one to add one or more custom extensions. I've based the API on `ChromeOptions` from the Chrome WebDriver, to make it easier for developers to use it. The API supports local and remote sessions.

### Example

```java
DesiredCapabilities capabilities = DesiredCapabilities.safari();
File extensionFile = new File("path/to/extension.safariextz");
SafariExtensions extensions = new SafariExtensions();
extensions.addExtensions(extensionFile);
capabilities.setCapability(SafariExtensions.CAPABILITY, extensions);

// Local
WebDriver driver = new SafariDriver(capabilities);

// Remote
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
```

### Tests
Three tests have been added:

- Verify that not using the new capability does not change old behavior
- Verify that an extension is installed, if specified.
- Verify that an extension is removed when the browser quits.

I've also patched the implementation of the `DriverCommand.QUIT` method, by closing the Web Socket connection in Java instead of sending QUIT to the Safari extension (the Safari extension silently ignores the command).
Before this fix, invoking `safariDriver.quit()` would always cause an IOException to be thrown: "An existing connection was forcibly closed by the remote host".

### Ideas for future improvements
My current objective was to automate the tests of a Safari extension. Others might actually want to preserve the existing set of installed extensions, instead of adding new ones. In order to achieve this, use a third-party library (such as https://code.google.com/p/plist/) to parse `Extensions.plist`, and add the WebDriver Safari extension by appending values to Extensions.plist instead of overwriting it.

*I've signed the [SFC Individual Contributor License Agreement](https://spreadsheets.google.com/spreadsheet/viewform?hl=en_US&formkey=dFFjXzBzM1VwekFlOWFWMjFFRjJMRFE6MQ)*