Kaynağa Gözat

Begin restoring <FF47 binary startup functionality

Daniel Gempesaw 9 yıl önce
ebeveyn
işleme
29d7190005

+ 34 - 18
lib/Selenium/CanStartBinary.pm

@@ -276,23 +276,7 @@ sub _build_binary_mode {
     my $port = $self->port + 0;
     return if $port == 4444;
 
-    if ($self->isa('Selenium::Firefox')) {
-        my $marionette_port = $self->marionette_enabled
-          ? $self->marionette_port
-          : 0;
-
-        my @args = ($port, $marionette_port);
-
-        if ($self->has_firefox_profile) {
-            push @args, $self->firefox_profile;
-        }
-
-        my $profile = setup_firefox_binary_env(@args);
-        # For geckodriver, setting env variable XRE_PROFILE_PATH does
-        # not seem to work anymore. Instead, geckodriver accepts an
-        # encoded firefox profile, so we need to set it on the Driver.
-        $self->firefox_profile($profile);
-    }
+    $self->_handle_firefox_setup;
 
     my $command = $self->_construct_command;
     system($command);
@@ -306,6 +290,38 @@ sub _build_binary_mode {
     }
 }
 
+sub _handle_firefox_setup {
+    # This is a no-op for other browsers
+    return unless $self->isa('Selenium::Firefox');
+
+    my $marionette_port = $self->marionette_enabled
+      ? $self->marionette_port
+      : 0;
+
+    my $user_profile = $self->has_firefox_profile
+      ? $self->firefox_profile
+      : 0;
+
+    my $profile = setup_firefox_binary_env(
+        $port,
+        $self->marionette_port,
+        $user_profile
+    );
+
+    if ($self->marionette_enabled) {
+        # For geckodriver/marionette, we keep the enhanced profile around because
+        # we need to send it to geckodriver as a zipped b64-encoded
+        # directory.
+        $self->firefox_profile($profile);
+    }
+    else {
+        # For non-geckodriver/non-marionette, we want to get rid of
+        # the profile so that we don't accidentally zip it and encode
+        # it down the line while Firefox is trying to read from it.
+        $self->clear_firefox_profile;
+    }
+}
+
 sub shutdown_binary {
     my ($self) = @_;
 
@@ -355,7 +371,7 @@ sub DEMOLISH {
     # if we're in global destruction, all bets are off.
     return if $in_gd;
     $self->shutdown_binary;
-};
+}
 
 sub _construct_command {
     my ($self) = @_;

+ 10 - 0
lib/Selenium/Firefox/Binary.pm

@@ -70,6 +70,16 @@ sub setup_firefox_binary_env {
     $profile->add_webdriver($port);
     $profile->add_marionette($marionette_port);
 
+    # For non-geckodriver/marionette startup, we instruct Firefox to
+    # use the profile by specifying the appropriate environment
+    # variables for it to hook onto.
+    if (! $marionette_port) {
+        $ENV{'XRE_PROFILE_PATH'} = $profile->_layout_on_disk;
+        $ENV{'MOZ_NO_REMOTE'} = '1'; # able to launch multiple instances
+        $ENV{'MOZ_CRASHREPORTER_DISABLE'} = '1'; # disable breakpad
+        $ENV{'NO_EM_RESTART'} = '1'; # prevent the binary from detaching from the console.log
+    }
+
     return $profile;
 }
 

+ 2 - 1
lib/Selenium/Remote/Driver.pm

@@ -486,7 +486,8 @@ has 'firefox_profile' => (
 
         return $profile;
     },
-    predicate => 'has_firefox_profile'
+    predicate => 'has_firefox_profile',
+    clearer => 1
 );
 
 has 'desired_capabilities' => (