tbb-testsuite 2.99 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
#!/usr/bin/perl -w
use strict;
use Getopt::Long;
use Cwd qw(getcwd);
use File::Spec;
use File::Temp;
use Data::Dump qw/dd/;
use FindBin;

my %default_options = (
    language => 'en-US',
12
13
    mozmill  => 1,
    selenium => 1,
14
15
16
17
18
19
20
21
);
my $options = get_options(@ARGV);
sub exit_error {
    print STDERR "Error: ", $_[0], "\n";
    exit (exists $_[1] ? $_[1] : 1);
}

sub get_options {
22
    my @options = qw(mozmill! selenium!);
23
24
    my %res = %default_options;
    Getopt::Long::GetOptionsFromArray(\@_, \%res, @options) || exit 1;
25
    $res{files} = \@_;
26
27
28
    return \%res;
}

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
sub tbb_filename_infos {
    my ($tbbfile) = @_;
    my (undef, undef, $file) = File::Spec->splitpath($tbbfile);
    my %res;
    if ($file =~ m/^tor-browser-linux(..)-([^_]+)_(.+)\.tar\.xz$/) {
        @res{qw(type os version language)} = ('tbbfile', 'Linux', $2, $3);
        $res{arch} = $1 eq '64' ? 'x86_64' : 'x86';
    } elsif ($file =~ m/^torbrowser-install-([^_]+)_(.+)\.exe$/) {
        @res{qw(type os arch version language)} =
                ('tbbfile', 'Windows', 'x86', $1, $2);
    } elsif ($file =~ m/^TorBrowserBundle-(.+)-osx32_(.+)\.zip$/) {
        @res{qw(type os arch version language)} =
                ('tbbfile', 'MacOSX', 'x86', $1, $2);
    } elsif ($file eq 'sha256sums.txt') {
        $res{type} = 'sha256sum';
    } else {
        $res{type} = 'Unknown';
    }
    return \%res;
}
49
50
51
52
53
54
55
56
57

sub extract_tbb {
    my ($tbbfile) = @_;
    exit_error "Can't open file $tbbfile" unless -f $tbbfile;
    $tbbfile = File::Spec->rel2abs($tbbfile);
    my $oldcwd = getcwd;
    my $tmpdir = File::Temp::newdir('tbbXXXXX', CLEANUP => 0);
    chdir $tmpdir;
    system('tar', 'xf', $tbbfile);
58
    return "$tmpdir/tor-browser_$options->{tbbinfos}{language}";
59
60
61
62
63
64
65
66
67
68
69
70
71
72
}

sub setup_tbb {
    unlink 'Data/Browser/profile.default/extensions/tor-launcher@torproject.org.xpi';
}

sub mozmill_run {
    my ($test_path) = @_;
    system('mozmill', '-b', "$options->{tbbdir}/Browser/firefox", '-p',
        "$options->{tbbdir}/Data/Browser/profile.default", '-t',
        "$FindBin::Bin/mozmill-tests/tbb-tests/$test_path");
}

sub mozmill_tests {
73
    return unless $options->{mozmill};
74
75
76
77
78
79
80
81
    my @tests = (
        'tbbScreenshot.js',
    );
    foreach my $test (@tests) {
        mozmill_run($test);
    }
}

boklm's avatar
boklm committed
82
sub selenium_tests {
83
    return unless $options->{selenium};
boklm's avatar
boklm committed
84
85
86
87
88
89
90
91
92
93
    my @tests = (
        'test_check.tpo.py',
    );
    $ENV{TBB_BIN} = "$options->{tbbdir}/Browser/firefox";
    $ENV{TBB_PROFILE} = "$options->{tbbdir}/Data/Browser/profile.default";
    foreach my $test (@tests) {
        system("$FindBin::Bin/selenium-tests/$test");
    }
}

94
95
96
sub test_tbb {
    my ($tbbfile) = @_;
    my $oldcwd = getcwd;
97
    $options->{tbbinfos} = tbb_filename_infos($tbbfile);
98
99
100
101
102
103
104
105
    $options->{tbbdir} = extract_tbb($tbbfile);
    chdir $options->{tbbdir} || exit_error "Can't enter directory $options->{tbbdir}";
    setup_tbb;
    print "tbbdir: $options->{tbbdir}\n";
    mozmill_tests;
    selenium_tests;
    chdir $oldcwd;
}
106

107
108
109
foreach my $tbbfile (@{$options->{files}}) {
    test_tbb($tbbfile);
}