updated-packages
This commit is contained in:
68
vendor/php-webdriver/webdriver/lib/Firefox/FirefoxDriver.php
vendored
Normal file
68
vendor/php-webdriver/webdriver/lib/Firefox/FirefoxDriver.php
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace Facebook\WebDriver\Firefox;
|
||||
|
||||
use Facebook\WebDriver\Local\LocalWebDriver;
|
||||
use Facebook\WebDriver\Remote\DesiredCapabilities;
|
||||
use Facebook\WebDriver\Remote\Service\DriverCommandExecutor;
|
||||
use Facebook\WebDriver\Remote\WebDriverCommand;
|
||||
|
||||
class FirefoxDriver extends LocalWebDriver
|
||||
{
|
||||
/**
|
||||
* @deprecated Pass Firefox Profile using FirefoxOptions:
|
||||
* $firefoxOptions = new FirefoxOptions();
|
||||
* $firefoxOptions->setProfile($profile->encode());
|
||||
* $capabilities = DesiredCapabilities::firefox();
|
||||
* $capabilities->setCapability(FirefoxOptions::CAPABILITY, $firefoxOptions);
|
||||
*/
|
||||
const PROFILE = 'firefox_profile';
|
||||
|
||||
/**
|
||||
* Creates a new FirefoxDriver using default configuration.
|
||||
* This includes starting a new geckodriver process each time this method is called. However this may be
|
||||
* unnecessary overhead - instead, you can start the process once using FirefoxDriverService and pass
|
||||
* this instance to startUsingDriverService() method.
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function start(DesiredCapabilities $capabilities = null)
|
||||
{
|
||||
$service = FirefoxDriverService::createDefaultService();
|
||||
|
||||
return static::startUsingDriverService($service, $capabilities);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new FirefoxDriver using given FirefoxDriverService.
|
||||
* This is usable when you for example don't want to start new geckodriver process for each individual test
|
||||
* and want to reuse the already started geckodriver, which will lower the overhead associated with spinning up
|
||||
* a new process.
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function startUsingDriverService(
|
||||
FirefoxDriverService $service,
|
||||
DesiredCapabilities $capabilities = null
|
||||
) {
|
||||
if ($capabilities === null) {
|
||||
$capabilities = DesiredCapabilities::firefox();
|
||||
}
|
||||
|
||||
$executor = new DriverCommandExecutor($service);
|
||||
$newSessionCommand = WebDriverCommand::newSession(
|
||||
[
|
||||
'capabilities' => [
|
||||
'firstMatch' => [(object) $capabilities->toW3cCompatibleArray()],
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
$response = $executor->execute($newSessionCommand);
|
||||
|
||||
$returnedCapabilities = DesiredCapabilities::createFromW3cCapabilities($response->getValue()['capabilities']);
|
||||
$sessionId = $response->getSessionID();
|
||||
|
||||
return new static($executor, $sessionId, $returnedCapabilities, true);
|
||||
}
|
||||
}
|
34
vendor/php-webdriver/webdriver/lib/Firefox/FirefoxDriverService.php
vendored
Normal file
34
vendor/php-webdriver/webdriver/lib/Firefox/FirefoxDriverService.php
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Facebook\WebDriver\Firefox;
|
||||
|
||||
use Facebook\WebDriver\Remote\Service\DriverService;
|
||||
|
||||
class FirefoxDriverService extends DriverService
|
||||
{
|
||||
/**
|
||||
* @var string Name of the environment variable storing the path to the driver binary
|
||||
*/
|
||||
const WEBDRIVER_FIREFOX_DRIVER = 'WEBDRIVER_FIREFOX_DRIVER';
|
||||
/**
|
||||
* @var string Default executable used when no other is provided
|
||||
* @internal
|
||||
*/
|
||||
const DEFAULT_EXECUTABLE = 'geckodriver';
|
||||
|
||||
/**
|
||||
* @return static
|
||||
*/
|
||||
public static function createDefaultService()
|
||||
{
|
||||
$pathToExecutable = getenv(static::WEBDRIVER_FIREFOX_DRIVER);
|
||||
if ($pathToExecutable === false || $pathToExecutable === '') {
|
||||
$pathToExecutable = static::DEFAULT_EXECUTABLE;
|
||||
}
|
||||
|
||||
$port = 9515; // TODO: Get another free port if the default port is used.
|
||||
$args = ['-p=' . $port];
|
||||
|
||||
return new static($pathToExecutable, $port, $args);
|
||||
}
|
||||
}
|
133
vendor/php-webdriver/webdriver/lib/Firefox/FirefoxOptions.php
vendored
Normal file
133
vendor/php-webdriver/webdriver/lib/Firefox/FirefoxOptions.php
vendored
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
namespace Facebook\WebDriver\Firefox;
|
||||
|
||||
use ReturnTypeWillChange;
|
||||
|
||||
/**
|
||||
* Class to manage Firefox-specific capabilities
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/WebDriver/Capabilities/firefoxOptions
|
||||
*/
|
||||
class FirefoxOptions implements \JsonSerializable
|
||||
{
|
||||
/** @var string The key of FirefoxOptions in desired capabilities */
|
||||
const CAPABILITY = 'moz:firefoxOptions';
|
||||
/** @var string */
|
||||
const OPTION_ARGS = 'args';
|
||||
/** @var string */
|
||||
const OPTION_PREFS = 'prefs';
|
||||
/** @var string */
|
||||
const OPTION_PROFILE = 'profile';
|
||||
|
||||
/** @var array */
|
||||
private $options = [];
|
||||
/** @var array */
|
||||
private $arguments = [];
|
||||
/** @var array */
|
||||
private $preferences = [];
|
||||
/** @var FirefoxProfile */
|
||||
private $profile;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
// Set default preferences:
|
||||
// disable the "Reader View" help tooltip, which can hide elements in the window.document
|
||||
$this->setPreference(FirefoxPreferences::READER_PARSE_ON_LOAD_ENABLED, false);
|
||||
// disable JSON viewer and let JSON be rendered as raw data
|
||||
$this->setPreference(FirefoxPreferences::DEVTOOLS_JSONVIEW, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Directly set firefoxOptions.
|
||||
* Use `addArguments` to add command line arguments and `setPreference` to set Firefox about:config entry.
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
* @return self
|
||||
*/
|
||||
public function setOption($name, $value)
|
||||
{
|
||||
if ($name === self::OPTION_PREFS) {
|
||||
throw new \InvalidArgumentException('Use setPreference() method to set Firefox preferences');
|
||||
}
|
||||
if ($name === self::OPTION_ARGS) {
|
||||
throw new \InvalidArgumentException('Use addArguments() method to add Firefox arguments');
|
||||
}
|
||||
if ($name === self::OPTION_PROFILE) {
|
||||
throw new \InvalidArgumentException('Use setProfile() method to set Firefox profile');
|
||||
}
|
||||
|
||||
$this->options[$name] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Command line arguments to pass to the Firefox binary.
|
||||
* These must include the leading dash (-) where required, e.g. ['-headless'].
|
||||
*
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/WebDriver/Capabilities/firefoxOptions#args
|
||||
* @param string[] $arguments
|
||||
* @return self
|
||||
*/
|
||||
public function addArguments(array $arguments)
|
||||
{
|
||||
$this->arguments = array_merge($this->arguments, $arguments);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Firefox preference (about:config entry).
|
||||
*
|
||||
* @see http://kb.mozillazine.org/About:config_entries
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/WebDriver/Capabilities/firefoxOptions#prefs
|
||||
* @param string $name
|
||||
* @param string|bool|int $value
|
||||
* @return self
|
||||
*/
|
||||
public function setPreference($name, $value)
|
||||
{
|
||||
$this->preferences[$name] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://github.com/php-webdriver/php-webdriver/wiki/Firefox#firefox-profile
|
||||
* @param FirefoxProfile $profile
|
||||
* @return self
|
||||
*/
|
||||
public function setProfile(FirefoxProfile $profile)
|
||||
{
|
||||
$this->profile = $profile;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray()
|
||||
{
|
||||
$array = $this->options;
|
||||
if (!empty($this->arguments)) {
|
||||
$array[self::OPTION_ARGS] = $this->arguments;
|
||||
}
|
||||
if (!empty($this->preferences)) {
|
||||
$array[self::OPTION_PREFS] = $this->preferences;
|
||||
}
|
||||
if (!empty($this->profile)) {
|
||||
$array[self::OPTION_PROFILE] = $this->profile->encode();
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
#[ReturnTypeWillChange]
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return new \ArrayObject($this->toArray());
|
||||
}
|
||||
}
|
25
vendor/php-webdriver/webdriver/lib/Firefox/FirefoxPreferences.php
vendored
Normal file
25
vendor/php-webdriver/webdriver/lib/Firefox/FirefoxPreferences.php
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Facebook\WebDriver\Firefox;
|
||||
|
||||
/**
|
||||
* Constants of common Firefox profile preferences (about:config values).
|
||||
* @see http://kb.mozillazine.org/Firefox_:_FAQs_:_About:config_Entries
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
class FirefoxPreferences
|
||||
{
|
||||
/** @var string Port WebDriver uses to communicate with Firefox instance */
|
||||
const WEBDRIVER_FIREFOX_PORT = 'webdriver_firefox_port';
|
||||
/** @var string Should the reader view (FF 38+) be enabled? */
|
||||
const READER_PARSE_ON_LOAD_ENABLED = 'reader.parse-on-load.enabled';
|
||||
/** @var string Browser homepage */
|
||||
const BROWSER_STARTUP_HOMEPAGE = 'browser.startup.homepage';
|
||||
/** @var string Should the Devtools JSON view be enabled? */
|
||||
const DEVTOOLS_JSONVIEW = 'devtools.jsonview.enabled';
|
||||
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
}
|
308
vendor/php-webdriver/webdriver/lib/Firefox/FirefoxProfile.php
vendored
Normal file
308
vendor/php-webdriver/webdriver/lib/Firefox/FirefoxProfile.php
vendored
Normal file
@@ -0,0 +1,308 @@
|
||||
<?php
|
||||
|
||||
namespace Facebook\WebDriver\Firefox;
|
||||
|
||||
use Facebook\WebDriver\Exception\WebDriverException;
|
||||
use FilesystemIterator;
|
||||
use RecursiveDirectoryIterator;
|
||||
use RecursiveIteratorIterator;
|
||||
use ZipArchive;
|
||||
|
||||
class FirefoxProfile
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $preferences = [];
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $extensions = [];
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $extensions_datas = [];
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $rdf_file;
|
||||
|
||||
/**
|
||||
* @param string $extension The path to the xpi extension.
|
||||
* @return FirefoxProfile
|
||||
*/
|
||||
public function addExtension($extension)
|
||||
{
|
||||
$this->extensions[] = $extension;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $extension_datas The path to the folder containing the datas to add to the extension
|
||||
* @return FirefoxProfile
|
||||
*/
|
||||
public function addExtensionDatas($extension_datas)
|
||||
{
|
||||
if (!is_dir($extension_datas)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->extensions_datas[basename($extension_datas)] = $extension_datas;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $rdf_file The path to the rdf file
|
||||
* @return FirefoxProfile
|
||||
*/
|
||||
public function setRdfFile($rdf_file)
|
||||
{
|
||||
if (!is_file($rdf_file)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->rdf_file = $rdf_file;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param string|bool|int $value
|
||||
* @throws WebDriverException
|
||||
* @return FirefoxProfile
|
||||
*/
|
||||
public function setPreference($key, $value)
|
||||
{
|
||||
if (is_string($value)) {
|
||||
$value = sprintf('"%s"', $value);
|
||||
} else {
|
||||
if (is_int($value)) {
|
||||
$value = sprintf('%d', $value);
|
||||
} else {
|
||||
if (is_bool($value)) {
|
||||
$value = $value ? 'true' : 'false';
|
||||
} else {
|
||||
throw new WebDriverException(
|
||||
'The value of the preference should be either a string, int or bool.'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->preferences[$key] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPreference($key)
|
||||
{
|
||||
if (array_key_exists($key, $this->preferences)) {
|
||||
return $this->preferences[$key];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function encode()
|
||||
{
|
||||
$temp_dir = $this->createTempDirectory('WebDriverFirefoxProfile');
|
||||
|
||||
if (isset($this->rdf_file)) {
|
||||
copy($this->rdf_file, $temp_dir . DIRECTORY_SEPARATOR . 'mimeTypes.rdf');
|
||||
}
|
||||
|
||||
foreach ($this->extensions as $extension) {
|
||||
$this->installExtension($extension, $temp_dir);
|
||||
}
|
||||
|
||||
foreach ($this->extensions_datas as $dirname => $extension_datas) {
|
||||
mkdir($temp_dir . DIRECTORY_SEPARATOR . $dirname);
|
||||
$iterator = new RecursiveIteratorIterator(
|
||||
new RecursiveDirectoryIterator($extension_datas, RecursiveDirectoryIterator::SKIP_DOTS),
|
||||
RecursiveIteratorIterator::SELF_FIRST
|
||||
);
|
||||
foreach ($iterator as $item) {
|
||||
$target_dir = $temp_dir . DIRECTORY_SEPARATOR . $dirname . DIRECTORY_SEPARATOR
|
||||
. $iterator->getSubPathName();
|
||||
|
||||
if ($item->isDir()) {
|
||||
mkdir($target_dir);
|
||||
} else {
|
||||
copy($item, $target_dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$content = '';
|
||||
foreach ($this->preferences as $key => $value) {
|
||||
$content .= sprintf("user_pref(\"%s\", %s);\n", $key, $value);
|
||||
}
|
||||
file_put_contents($temp_dir . '/user.js', $content);
|
||||
|
||||
// Intentionally do not use `tempnam()`, as it creates empty file which zip extension may not handle.
|
||||
$temp_zip = sys_get_temp_dir() . '/' . uniqid('WebDriverFirefoxProfileZip', false);
|
||||
|
||||
$zip = new ZipArchive();
|
||||
$zip->open($temp_zip, ZipArchive::CREATE);
|
||||
|
||||
$dir = new RecursiveDirectoryIterator($temp_dir);
|
||||
$files = new RecursiveIteratorIterator($dir);
|
||||
|
||||
$dir_prefix = preg_replace(
|
||||
'#\\\\#',
|
||||
'\\\\\\\\',
|
||||
$temp_dir . DIRECTORY_SEPARATOR
|
||||
);
|
||||
|
||||
foreach ($files as $name => $object) {
|
||||
if (is_dir($name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$path = preg_replace("#^{$dir_prefix}#", '', $name);
|
||||
$zip->addFile($name, $path);
|
||||
}
|
||||
$zip->close();
|
||||
|
||||
$profile = base64_encode(file_get_contents($temp_zip));
|
||||
|
||||
// clean up
|
||||
$this->deleteDirectory($temp_dir);
|
||||
unlink($temp_zip);
|
||||
|
||||
return $profile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $extension The path to the extension.
|
||||
* @param string $profileDir The path to the profile directory.
|
||||
* @throws \Exception
|
||||
* @throws WebDriverException
|
||||
*/
|
||||
private function installExtension($extension, $profileDir)
|
||||
{
|
||||
$extensionCommonName = $this->parseExtensionName($extension);
|
||||
|
||||
// install extension to profile directory
|
||||
$extensionDir = $profileDir . '/extensions/';
|
||||
if (!is_dir($extensionDir) && !mkdir($extensionDir, 0777, true) && !is_dir($extensionDir)) {
|
||||
throw new WebDriverException('Cannot install Firefox extension - cannot create directory');
|
||||
}
|
||||
|
||||
if (!copy($extension, $extensionDir . $extensionCommonName . '.xpi')) {
|
||||
throw new WebDriverException('Cannot install Firefox extension - cannot copy file');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $prefix Prefix of the temp directory.
|
||||
*
|
||||
* @throws WebDriverException
|
||||
* @return string The path to the temp directory created.
|
||||
*/
|
||||
private function createTempDirectory($prefix = '')
|
||||
{
|
||||
$temp_dir = tempnam(sys_get_temp_dir(), $prefix);
|
||||
if (file_exists($temp_dir)) {
|
||||
unlink($temp_dir);
|
||||
mkdir($temp_dir);
|
||||
if (!is_dir($temp_dir)) {
|
||||
throw new WebDriverException('Cannot create firefox profile.');
|
||||
}
|
||||
}
|
||||
|
||||
return $temp_dir;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $directory The path to the directory.
|
||||
*/
|
||||
private function deleteDirectory($directory)
|
||||
{
|
||||
$dir = new RecursiveDirectoryIterator($directory, FilesystemIterator::SKIP_DOTS);
|
||||
$paths = new RecursiveIteratorIterator($dir, RecursiveIteratorIterator::CHILD_FIRST);
|
||||
|
||||
foreach ($paths as $path) {
|
||||
if ($path->isDir() && !$path->isLink()) {
|
||||
rmdir($path->getPathname());
|
||||
} else {
|
||||
unlink($path->getPathname());
|
||||
}
|
||||
}
|
||||
|
||||
rmdir($directory);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $xpi The path to the .xpi extension.
|
||||
* @param string $target_dir The path to the unzip directory.
|
||||
*
|
||||
* @throws \Exception
|
||||
* @return FirefoxProfile
|
||||
*/
|
||||
private function extractTo($xpi, $target_dir)
|
||||
{
|
||||
$zip = new ZipArchive();
|
||||
if (file_exists($xpi)) {
|
||||
if ($zip->open($xpi)) {
|
||||
$zip->extractTo($target_dir);
|
||||
$zip->close();
|
||||
} else {
|
||||
throw new \Exception("Failed to open the firefox extension. '$xpi'");
|
||||
}
|
||||
} else {
|
||||
throw new \Exception("Firefox extension doesn't exist. '$xpi'");
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function parseExtensionName($extensionPath)
|
||||
{
|
||||
$temp_dir = $this->createTempDirectory();
|
||||
|
||||
$this->extractTo($extensionPath, $temp_dir);
|
||||
|
||||
$mozillaRsaPath = $temp_dir . '/META-INF/mozilla.rsa';
|
||||
$mozillaRsaBinaryData = file_get_contents($mozillaRsaPath);
|
||||
$mozillaRsaHex = bin2hex($mozillaRsaBinaryData);
|
||||
|
||||
//We need to find the plugin id. This is the second occurrence of object identifier "2.5.4.3 commonName".
|
||||
|
||||
//That is marker "2.5.4.3 commonName" in hex:
|
||||
$objectIdentifierHexMarker = '0603550403';
|
||||
|
||||
$firstMarkerPosInHex = strpos($mozillaRsaHex, $objectIdentifierHexMarker); // phpcs:ignore
|
||||
|
||||
$secondMarkerPosInHexString =
|
||||
strpos($mozillaRsaHex, $objectIdentifierHexMarker, $firstMarkerPosInHex + 2); // phpcs:ignore
|
||||
|
||||
if ($secondMarkerPosInHexString === false) {
|
||||
throw new WebDriverException('Cannot install extension. Cannot fetch extension commonName');
|
||||
}
|
||||
|
||||
// phpcs:ignore
|
||||
$commonNameStringPositionInBinary = ($secondMarkerPosInHexString + strlen($objectIdentifierHexMarker)) / 2;
|
||||
|
||||
$commonNameStringLength = ord($mozillaRsaBinaryData[$commonNameStringPositionInBinary + 1]);
|
||||
// phpcs:ignore
|
||||
$extensionCommonName = substr(
|
||||
$mozillaRsaBinaryData,
|
||||
$commonNameStringPositionInBinary + 2,
|
||||
$commonNameStringLength
|
||||
);
|
||||
|
||||
$this->deleteDirectory($temp_dir);
|
||||
|
||||
return $extensionCommonName;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user