Firefox-Marionette
view release on metacpan or search on metacpan
lib/Firefox/Marionette.pm view on Meta::CPAN
$self->_wait_for_any_background_update_status();
foreach my $key (
qw(marionette_protocol application_type _firefox_pid last_message_id _child_error)
)
{
delete $self->{$key};
}
if ( my $ssh = $self->_ssh() ) {
delete $ssh->{ssh_local_tcp_socket};
}
delete $self->{_cached_per_instance};
$self->_reset_marionette_port();
$self->_get_version();
my @arguments =
$self->_setup_arguments( %{ $self->{_restart_parameters} } );
$self->_launch(@arguments);
my $socket = $self->_setup_local_connection_to_firefox(@arguments);
my $session_id;
( $session_id, $capabilities ) =
$self->_initial_socket_setup( $socket, $capabilities );
$self->_check_protocol_version_and_pid( $session_id, $capabilities );
$self->_post_launch_checks_and_setup($timeouts);
return $self;
}
sub _reset_marionette_port {
my ($self) = @_;
my $handle;
if ( $self->_ssh() ) {
$handle =
$self->_get_file_via_scp( {}, $self->{profile_path}, 'profile path' );
}
else {
$handle = FileHandle->new( $self->{profile_path}, Fcntl::O_RDONLY() )
or Firefox::Marionette::Exception->throw(
"Failed to open '$self->{profile_path}' for reading:$EXTENDED_OS_ERROR"
);
}
my $profile = Firefox::Marionette::Profile->parse_by_handle($handle);
close $handle
or Firefox::Marionette::Exception->throw(
"Failed to close '$self->{profile_path}':$EXTENDED_OS_ERROR");
if ( $self->_is_auto_listen_okay() ) {
$profile->set_value( 'marionette.port',
Firefox::Marionette::Profile::ANY_PORT() );
}
else {
my $port = $self->_get_empty_port();
$profile->set_value( 'marionette.defaultPrefs.port', $port );
$profile->set_value( 'marionette.port', $port );
}
if ( $self->_ssh() ) {
$self->_save_profile_via_ssh($profile);
}
else {
$profile->save( $self->{profile_path} );
}
return;
}
sub update {
my ( $self, $update_timeout ) = @_;
my $timeouts = $self->timeouts();
my $script_timeout = $timeouts->script();
my $update_timeouts = Firefox::Marionette::Timeouts->new(
script => ( $update_timeout || _DEFAULT_UPDATE_TIMEOUT() ) *
_MILLISECONDS_IN_ONE_SECOND(),
implicit => $timeouts->implicit(),
page_load => $timeouts->page_load()
);
$self->timeouts($update_timeouts);
my $old = $self->_context('chrome');
# toolkit/mozapps/update/nsIUpdateService.idl
my $update_parameters = $self->script(
$self->_compress_script(
$self->_prefs_interface_preamble() . <<'_JS_' ) );
let disabledForTesting = branch.getBoolPref("app.update.disabledForTesting");
branch.setBoolPref("app.update.disabledForTesting", false);
let updateManager = new Promise((resolve, reject) => {
var updateStatus = {};
if ("@mozilla.org/updates/update-manager;1" in Components.classes) {
let PREF_APP_UPDATE_CANCELATIONS_OSX = "app.update.cancelations.osx";
let PREF_APP_UPDATE_ELEVATE_NEVER = "app.update.elevate.never";
if (Services.prefs.prefHasUserValue(PREF_APP_UPDATE_CANCELATIONS_OSX)) {
Services.prefs.clearUserPref(PREF_APP_UPDATE_CANCELATIONS_OSX);
}
if (Services.prefs.prefHasUserValue(PREF_APP_UPDATE_ELEVATE_NEVER)) {
Services.prefs.clearUserPref(PREF_APP_UPDATE_ELEVATE_NEVER);
}
let updateService = Components.classes["@mozilla.org/updates/update-service;1"].getService(Components.interfaces.nsIApplicationUpdateService);
let latestUpdate = null;
if (!updateService.canCheckForUpdates) {
updateStatus["updateStatusCode"] = 'CANNOT_CHECK_FOR_UPDATES';
reject(updateStatus);
}
if (!updateService.canApplyUpdates) {
updateStatus["updateStatusCode"] = 'CANNOT_APPLY_UPDATES';
reject(updateStatus);
}
if (updateService.canUsuallyStageUpdates) {
if (!updateService.canStageUpdates) {
updateStatus["updateStatusCode"] = 'CANNOT_STAGE_UPDATES';
reject(updateStatus);
}
}
if ((updateService.isOtherInstanceHandlingUpdates) && (updateService.isOtherInstanceHandlingUpdates())) {
updateStatus["updateStatusCode"] = 'ANOTHER_INSTANCE_IS_HANDLING_UPDATES';
reject(updateStatus);
}
let updateChecker = Components.classes["@mozilla.org/updates/update-checker;1"].createInstance(Components.interfaces.nsIUpdateChecker);
if (updateChecker.stopCurrentCheck) {
updateChecker.stopCurrentCheck();
}
let updateServiceListener = {
onCheckComplete: (request, updates) => {
latestUpdate = updateService.selectUpdate(updates, true);
updateStatus["numberOfUpdates"] = updates.length;
if (latestUpdate === null) {
updateStatus["updateStatusCode"] = 'NO_UPDATES_AVAILABLE';
reject(updateStatus);
( run in 0.787 second using v1.01-cache-2.11-cpan-140bd7fdf52 )