#!/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', mozmill => 1, selenium => 1, ); my $options = get_options(@ARGV); sub exit_error { print STDERR "Error: ", $_[0], "\n"; exit (exists $_[1] ? $_[1] : 1); } sub get_options { my @options = qw(os=s language=s mozmill! selenium!); my %res = %default_options; Getopt::Long::GetOptionsFromArray(\@_, \%res, @options) || exit 1; $res{files} = \@_; return \%res; } 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); return "$tmpdir/tor-browser_$options->{language}"; } 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 { return unless $options->{mozmill}; my @tests = ( 'tbbScreenshot.js', ); foreach my $test (@tests) { mozmill_run($test); } } sub selenium_tests { return unless $options->{selenium}; 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"); } } sub test_tbb { my ($tbbfile) = @_; my $oldcwd = getcwd; $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; } foreach my $tbbfile (@{$options->{files}}) { test_tbb($tbbfile); }