Cookies-Roundtrip
view release on metacpan or search on metacpan
xt/live/700-firefoxmarionette-start-from-firefoxmarionettecookies.t view on Meta::CPAN
#!/usr/bin/env perl
###################################################################
#### NOTE env-var PERL_TEST_TEMPDIR_TINY_NOCLEANUP=1 will stop erasing tmp files
###################################################################
use strict;
use warnings;
our $VERSION = '0.01';
use Test::More;
use Test::More::UTF8;
use Test::Deep '!blessed';
use FindBin;
use Test::TempDir::Tiny;
use HTTP::CookieJar;
use URI;
use Firefox::Marionette;
use Data::Roundtrip qw/perl2dump no-unicode-escape-permanently/;
use lib ($FindBin::Bin, 'blib/lib');
use Cookies::Roundtrip qw/:count :as_string :equal
httpcookiejar2httpcookies httpcookies2httpcookiejar
:firefoxmarionettecookies2
:firefoxmarionette
/;
my $VERBOSITY = 4; # we need verbosity of 10 (max), so this is not used
my $curdir = $FindBin::Bin;
require(File::Spec->catfile($curdir, '..', '..', 't', 'MY', 'CookieMaker.pm'));
#ok(@MY::CookieMaker::HTTPCookieJar_cases, "Library 'CookieMaker.pm' loaed OK/1.") or BAIL_OUT;
#ok(@MY::CookieMaker::HTTPCookies_cases, "Library 'CookieMaker.pm' loaed OK/2.") or BAIL_OUT;
ok(@MY::CookieMaker::FirefoxMarionetteCookies_cases, "Library 'CookieMaker.pm' loaed OK/3.") or BAIL_OUT;
# if for debug you change this make sure that it has path in it e.g. ./xyz
my $tmpdir = tempdir(); # will be erased unless a BAIL_OUT or env var set
ok(-d $tmpdir, "tmpdir exists $tmpdir") or BAIL_OUT;
my $skip_discard = 0;
my %ffmar_constructor_params = (
'visible' => 0,
#'debug' => ($VERBOSITY>0) ? 5 : 0,
);
for my $c (@MY::CookieMaker::FirefoxMarionetteCookies_cases) {
diag "\n==================\ntest " . $c->{label} . "\n==================\n";
my $firefoxmarionettecookies = $c->{getcookie}->($c->{'constructor-params'});
my $firefoxmarionettecookies_count = count_cookies($firefoxmarionettecookies, $skip_discard, $VERBOSITY);
ok(defined($firefoxmarionettecookies_count), 'count_cookies()'." : (label '".$c->{label}."') : called and got good result.") or BAIL_OUT;
ok($firefoxmarionettecookies_count > 0, 'count_cookies()'." : (label '".$c->{label}."') : at least one cookie to test with.") or BAIL_OUT(as_string_cookies($firefoxmarionettecookies)."\nno, see above cookies.");
my $ffmarobj1 = Firefox::Marionette->new(%ffmar_constructor_params);
ok(defined($ffmarobj1), 'Firefox::Marionette->new()'." : (label '".$c->{label}."') : called and got good result/1.") or BAIL_OUT;
# you need to load the url of the cookie domain before you add the cookie
# because adding cookies to no document says 'cookie-averse' document
# you also CAN NOT add cookies for different domains!!!! only same domain
# cookies to the document you visited.
# visit another domain and you can add cookies for that domain
# that's why we pass '' (meaning go to the domain url) to below sub:
my $ret = firefoxmarionette_load_cookies($ffmarobj1, $firefoxmarionettecookies, '', $skip_discard, $VERBOSITY);
ok(defined($ret), 'firefoxmarionette_load_cookies()'." : (label '".$c->{label}."') : called and got good result.") or BAIL_OUT;
my $firefoxmarionettecookies2 = firefoxmarionette_get_cookies($ffmarobj1, $VERBOSITY);
ok(defined($firefoxmarionettecookies2), 'firefoxmarionette_get_cookies()'." : (label '".$c->{label}."') : called and got good result.") or BAIL_OUT;
if( $VERBOSITY > 0 ){ diag "Cookies from Firefox Marionette browser:\n".as_string_cookies($firefoxmarionettecookies2); }
my $firefoxmarionettecookies2_count = count_cookies($firefoxmarionettecookies2, $skip_discard, $VERBOSITY);
ok(defined($firefoxmarionettecookies2_count), 'count_cookies()'." : (label '".$c->{label}."') : called and got good result.") or BAIL_OUT;
is($firefoxmarionettecookies2_count, $firefoxmarionettecookies2_count, 'firefoxmarionette_load_cookies()'." : (label '".$c->{label}."') : the number of loaded cookies (${firefoxmarionettecookies_count}) is the same as the number of extracted cookies...
my $httpcookies = firefoxmarionettecookies2httpcookies($firefoxmarionettecookies2, undef, $skip_discard, $VERBOSITY);
ok(defined $httpcookies, 'firefoxmarionettecookies2httpcookies()'." (label '".$c->{label}."') : called and got good result.") or BAIL_OUT;
my $httpcookies_count = count_cookies($httpcookies, $skip_discard, $VERBOSITY);
( run in 3.245 seconds using v1.01-cache-2.11-cpan-364913b4093 )