seleniumを使ってブラウザの位置情報を偽装する方法(Firefox)

seleniumを使ってFirefoxの位置情報を偽装するためには、以下の設定を使用すれば良い。

import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.firefox.FirefoxProfile;

double latitude = 35.0;
double longitude = 139.0;

FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("geo.prompt.testing", true);
firefoxProfile.setPreference("geo.prompt.testing.allow", true);
firefoxProfile.setPreference("geo.enabled", true);
firefoxProfile.setPreference("geo.wifi.uri", String.format("data:application/json,{\"location\": {\"lat\": %f, \"lng\": %f}, \"accuracy\": 100.0, \"status\": \"OK\"}", latitude, longitude));
}
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setProfile(firefoxProfile);
FirefoxDriver webDriver = new FirefoxDriver(firefoxOptions);