tbb-testsuite 3.63 KB
Newer Older
1
2
3
4
5
6
7
8
#!/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;
boklm's avatar
boklm committed
9
use LWP::UserAgent;
10
11
12

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

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

boklm's avatar
boklm committed
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
sub get_tbbfile {
    my ($tbbfile) = @_;
    if ($tbbfile =~ m/^https?:\/\//) {
        print "Downloading $tbbfile\n";
        my (undef, undef, $file) = File::Spec->splitpath($tbbfile);
        my $output = "$options->{tbbinfos}{tmpdir}/$file";
        my $ua = LWP::UserAgent->new;
        my $resp = $ua->get($tbbfile, ':content_file' => $output);
        exit_error "Error downloading $tbbfile:\n" . $resp->status_line
                unless $resp->is_success;
        return $output;
    }
    exit_error "File $tbbfile does not exist" unless -f $tbbfile;
    return $tbbfile;
}

46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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;
}
66
67
68
69
70

sub extract_tbb {
    my ($tbbfile) = @_;
    exit_error "Can't open file $tbbfile" unless -f $tbbfile;
    $tbbfile = File::Spec->rel2abs($tbbfile);
boklm's avatar
boklm committed
71
    my $tmpdir = $options->{tbbinfos}{tmpdir};
72
73
    chdir $tmpdir;
    system('tar', 'xf', $tbbfile);
74
    return "$tmpdir/tor-browser_$options->{tbbinfos}{language}";
75
76
77
78
79
80
81
82
83
84
85
86
87
88
}

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 {
89
    return unless $options->{mozmill};
90
91
92
93
94
95
96
97
    my @tests = (
        'tbbScreenshot.js',
    );
    foreach my $test (@tests) {
        mozmill_run($test);
    }
}

boklm's avatar
boklm committed
98
sub selenium_tests {
99
    return unless $options->{selenium};
boklm's avatar
boklm committed
100
101
102
103
104
105
106
107
108
109
    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");
    }
}

110
111
112
sub test_tbb {
    my ($tbbfile) = @_;
    my $oldcwd = getcwd;
113
    $options->{tbbinfos} = tbb_filename_infos($tbbfile);
boklm's avatar
boklm committed
114
115
    $options->{tbbinfos}{tmpdir} = File::Temp::newdir;
    $tbbfile = get_tbbfile($tbbfile);
116
117
118
119
120
121
122
123
    $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;
}
124

125
126
127
foreach my $tbbfile (@{$options->{files}}) {
    test_tbb($tbbfile);
}