Selenium/Firefox/Binary.pm

filter: Statementstmt 34.6% 18 / 52 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 44.4% 4 / 9 Podpod 100% 2 / 2 totaltotal 24.2% 24 / 99 CC 16 SCAR 29.9
CC
16
Cov
23%
_firefox_windows_path
30.0
_firefox_darwin_path
30.0
firefox_path
20.0
CRAP 19.8
↑ Summary Selenium/Remote/Driver.pm »
1 package Selenium::Firefox::Binary;
2 12 $Selenium::Firefox::Binary::VERSION = '1.50';
3 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # ABSTRACT: Subroutines for locating and properly initializing the Firefox Binary
7 12 ▶use File::Which qw/which/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 12 ▶use Selenium::Firefox::Profile;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 12 require Exporter;
11 12 our @ISA = qw/Exporter/;
12 12 our @EXPORT_OK = qw/firefox_path setup_firefox_binary_env/;
13  
14 0 ▶sub _firefox_windows_path {
Subroutine _firefox_windows_path: not called CC=5 SCAR=34.0
15  
16 # TODO: make this slightly less dumb
17 my @program_files = (
18 $ENV{PROGRAMFILES} // 'C:\Program Files',
19 0 ▶ $ENV{'PROGRAMFILES(X86)'} // 'C:\Program Files (x86)',
Condition0%0/4
$ENV{"PROGRAMFILES"} // "C:\\Program Files"
l!l
00
$ENV{"PROGRAMFILES(X86)"} // "C:\\Program Files (x86)"
l!l
00
MC/DC0%0/1
$ENV{"PROGRAMFILES"} // "C:\\Program Files"
$ENV{"PROGRAMFILES"}
MC/DC0%0/1
$ENV{"PROGRAMFILES(X86)"} // "C:\\Program Files (x86)"
$ENV{"PROGRAMFILES(X86)"}
Truth table0%0/2
A
A= $ENV{"PROGRAMFILES"}
Aresult
11
00
Truth table0%0/2
A
A= $ENV{"PROGRAMFILES(X86)"}
Aresult
11
00
20 );
21  
22 0 foreach (@program_files) {
23 0 my $binary_path = $_ . '\Mozilla Firefox\firefox.exe';
24 0 ▶ return $binary_path if -x $binary_path;
Branch: 1 branch
BranchTrueFalseTotal
if -x $binary_path 0 0 0
25 }
26  
27 # Fall back to a completely naive strategy
28 warn
29 0 q/We couldn't find a viable firefox.EXE; you may want to specify it via the binary attribute./;
30 0 return which('firefox');
31 }
32  
33 0 ▶sub _firefox_darwin_path {
Subroutine _firefox_darwin_path: not called CC=5 SCAR=34.0
34 0 my $default_firefox =
35 '/Applications/Firefox.app/Contents/MacOS/firefox';
36 0 my $default_firefox_bin =
37 '/Applications/Firefox.app/Contents/MacOS/firefox-bin';
38  
39 0 for my $path ( $default_firefox_bin, $default_firefox ) {
40 0 ▶ if ( -e $path && -x $path ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $path and -x $path) 0 0 0
Condition0%0/3
-e $path and -x $path
!ll&&!rl&&r
000
MC/DC0%0/2
-e $path and -x $path
-e $path -x $path
Truth table0%0/3
A and B
A= -e $pathB= -x $path
ABresult
0X0
100
111
41 0 return $path;
42 }
43 }
44 0 ▶ return which('firefox-bin') || which('firefox');
Condition0%0/3
which('firefox-bin') || which('firefox')
l!l&&r!l&&!r
000
MC/DC0%0/2
which('firefox-bin') || which('firefox')
which('firefox-bin') which('firefox')
Truth table0%0/3
A || B
A= which('firefox-bin')B= which('firefox')
ABresult
1X1
011
000
45 }
46  
47 0 ▶sub _firefox_unix_path {
Subroutine _firefox_unix_path: not called CC=2 SCAR=17.9
48  
49 # TODO: maybe which('firefox3'), which('firefox2') ?
50 0 ▶ return which('firefox') || '/usr/bin/firefox';
Condition0%0/2
which('firefox') || '/usr/bin/firefox'
l!l
00
MC/DC0%0/1
which('firefox') || '/usr/bin/firefox'
which('firefox')
Truth table0%0/2
A
A= which('firefox')
Aresult
11
00
51 }
52  
53  
54 0 ▶sub firefox_path {
Subroutine firefox_path: not called CC=4 SCAR=30.0
Pod documented
55 0 my $path;
56 0 ▶ if ( $^O eq 'MSWin32' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($^O eq 'MSWin32') { } 0 0 0
elsif ($^O eq 'darwin') { } 0 0 0
57 0 $path = _firefox_windows_path();
58 }
59 elsif ( $^O eq 'darwin' ) {
60 0 $path = _firefox_darwin_path();
61 }
62 else {
63 0 $path = _firefox_unix_path;
64 }
65  
66 0 ▶ if ( not -x $path ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-x $path) 0 0 0
67 0 die $path . ' is not an executable file.';
68 }
69  
70 0 return $path;
71 }
72  
73  
74 # We want the profile to persist to the end of the session, not just
75 # the end of this function.
76 12 my $profile;
77  
78 0 ▶sub setup_firefox_binary_env {
Subroutine setup_firefox_binary_env: not called CC=4 SCAR=30.0
Pod documented
79 0 my ( $port, $marionette_port, $caller_profile ) = @_;
80  
81 0 ▶ $profile = $caller_profile || Selenium::Firefox::Profile->new;
Condition0%0/3
$caller_profile || 'Selenium::Firefox::Profile'->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$caller_profile || 'Selenium::Firefox::Profile'->new
$caller_profile 'Selenium::Firefox::Profile'->new
Truth table0%0/3
A || B
A= $caller_profileB= 'Selenium::Firefox::Profile'->new
ABresult
1X1
011
000
82 0 $profile->add_webdriver( $port, $marionette_port );
83 0 $profile->add_marionette($marionette_port);
84  
85 # For non-geckodriver/marionette startup, we instruct Firefox to
86 # use the profile by specifying the appropriate environment
87 # variables for it to hook onto.
88 0 ▶ if ( !$marionette_port ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $marionette_port) { } 0 0 0
89 0 $ENV{'XRE_PROFILE_PATH'} = $profile->_layout_on_disk;
90 0 $ENV{'MOZ_NO_REMOTE'} = '1'; # able to launch multiple instances
91 0 $ENV{'MOZ_CRASHREPORTER_DISABLE'} = '1'; # disable breakpad
92 0 $ENV{'NO_EM_RESTART'} =
93 '1'; # prevent the binary from detaching from the console.log
94 }
95 else {
96 # In case the user created an old Firefox, which would've set
97 # those ENV variables, and then wanted to create a new Firefox
98 # afterwards, the env variables would still be around, and the
99 # new Firefox would respect the XRE_PROFILE_PATH and try to
100 # load it in the new geckodriver Firefox, which would cause an
101 # extension compatibility check
102 0 my @env_vars = qw/
103 XRE_PROFILE_PATH
104 MOZ_NO_REMOTE
105 MOZ_CRASHREPORTER_DISABLE
106 NO_EM_RESTART
107 /;
108  
109 0 foreach (@env_vars) {
110 0 delete $ENV{$_};
111 }
112 }
113  
114 0 return $profile;
115 }
116  
117 12 1;
118  
119 __END__
↑ Summary Selenium/Remote/Driver.pm »