-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathruntests.pl
90 lines (80 loc) · 2.52 KB
/
runtests.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!perl
use strict;
use warnings;
use lib '.';
use t::helper;
use WWW::Mechanize::Firefox;
use File::Glob qw( bsd_glob );
use Config;
use Getopt::Long;
GetOptions(
't|test:s' => \my $tests,
'c|continue' => \my $continue,
);
my @tests;
if( $tests ) {
@tests= bsd_glob( $tests );
};
=head1 NAME
runtests.pl - runs the test suite across several instances of Firefox
=cut
my @instances = @ARGV
? map { bsd_glob $_ } @ARGV
: t::helper::firefox_instances;
my $port = 4243;
# Later, we could even parallelize the test suite
# if I find out how to make the mozrepl port dynamic
for my $instance (@instances) {
# Launch firefox
my $vis_instance = $instance ? $instance : "local instance";
warn $vis_instance;
my @launch = $instance
? (launch => [$instance,'-repl', $port, 'about:blank'])
: ()
;
if( $instance ) {
$ENV{TEST_WWW_MECHANIZE_FIREFOX_VERSIONS} = $instance;
$ENV{MOZREPL}= "localhost:$port";
} else {
$ENV{TEST_WWW_MECHANIZE_FIREFOX_VERSIONS} = "don't test other instances";
delete $ENV{MOZREPL}; # my local setup ...
};
my $retries = 3;
my $ff;
while( $retries-- and !$ff) {
$ff= eval {
Firefox::Application->new(
@launch,
);
};
};
die "Couldn't launch Firefox instance from $instance"
unless $ff;
if( @tests ) {
for my $test (@tests) {
system(qq{perl -Ilib -w "$test"}) == 0
or ($continue and warn "Error while testing $vis_instance: $!/$?")
or die "Error while testing $vis_instance: $!/$?";
};
} else { # run all tests
system("$Config{ make } test") == 0
or ($continue and warn "Error while testing $vis_instance: $!/$?")
or die "Error while testing $vis_instance";
};
if( $instance ) {
# Close firefox again
# Quit in 500ms, so we have time to shut our socket down
$ff->repl->expr(<<'JS');
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var win = wm.getMostRecentWindow('navigator:browser');
win.setTimeout(function() {
Components.classes["@mozilla.org/toolkit/app-startup;1"]
.getService(Components.interfaces.nsIAppStartup).quit(0x02);
}, 500);
JS
};
undef $ff;
# Safe wait until shutdown
sleep 5;
};