| 1 |
#!/usr/bin/perl -w |
| 2 |
use strict; |
| 3 |
use Test::HTTP::LocalServer; |
| 4 |
use Test::More; |
| 5 |
use lib './inc'; |
| 6 |
use IO::Catch; |
| 7 |
|
| 8 |
# pre-5.8.0's warns aren't caught by a tied STDERR. |
| 9 |
tie *STDOUT, 'IO::Catch', '_STDOUT_' or die $!; |
| 10 |
|
| 11 |
our %tests = ( |
| 12 |
back => { count => 3, commands => ['get %s','click submit','back']}, |
| 13 |
browse => { count => 2, commands => [ 'get %s', 'browse' ] }, |
| 14 |
get => { count => 1, commands => ['get %s']} , |
| 15 |
open => { count => 2, commands => ['get %s','open 1'] }, |
| 16 |
submit => { count => 2, commands => ['get %s','submit']}, |
| 17 |
click => { count => 2, commands => ['get %s','click submit']}, |
| 18 |
reload => { count => 2, commands => ['get %s','reload'] }, |
| 19 |
); |
| 20 |
plan tests => scalar (keys %tests); |
| 21 |
|
| 22 |
BEGIN { |
| 23 |
# Disable all ReadLine functionality |
| 24 |
$ENV{PERL_RL} = 0; |
| 25 |
}; |
| 26 |
use WWW::Mechanize::Shell; |
| 27 |
|
| 28 |
delete @ENV{qw(HTTP_PROXY http_proxy CGI_HTTP_PROXY)}; |
| 29 |
|
| 30 |
my $browser_synced; |
| 31 |
{ no warnings 'redefine'; |
| 32 |
*WWW::Mechanize::Shell::sync_browser = sub { |
| 33 |
$browser_synced++; |
| 34 |
}; |
| 35 |
}; |
| 36 |
|
| 37 |
my $server = Test::HTTP::LocalServer->spawn(); |
| 38 |
|
| 39 |
sub sync_ok { |
| 40 |
my %args = @_; |
| 41 |
my $name = $args{name}; |
| 42 |
my $count = $args{count}; |
| 43 |
my (@commands) = @{$args{commands}}; |
| 44 |
|
| 45 |
my $s = WWW::Mechanize::Shell->new( 'test', rcfile => undef, warnings => undef ); |
| 46 |
$s->option('autosync', 1); |
| 47 |
$browser_synced = 0; |
| 48 |
|
| 49 |
for my $cmd (@commands) { |
| 50 |
no warnings; |
| 51 |
$cmd = sprintf $cmd, $server->url; |
| 52 |
$s->cmd($cmd); |
| 53 |
}; |
| 54 |
is($browser_synced,$count,"'$name' synchronizes $count times") |
| 55 |
or diag join "\n", @commands; |
| 56 |
}; |
| 57 |
|
| 58 |
for my $cmd (sort keys %tests) { |
| 59 |
sync_ok( name => $cmd, %{$tests{$cmd}} ); |
| 60 |
}; |
| 61 |
|
| 62 |
$server->stop; |