Cookies-Roundtrip
view release on metacpan or search on metacpan
xt/live/750-firefoxmarionette-start-from-httpcookies.t view on Meta::CPAN
#!/usr/bin/env perl
###################################################################
#### NOTE env-var PERL_TEST_TEMPDIR_TINY_NOCLEANUP=1 will stop erasing tmp files
###################################################################
# this fails randomly in cmp cookies
# and this is due to the fact that @firefoxmarionettecookies
# has an order of cookies, fixed in source.
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 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
httpcookies2firefoxmarionettecookies
: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,
'addons' => 1,
#'profile_name' => 'marionette-insecure-do-not-use',
#'debug' => ($VERBOSITY>0) ? 'all:5' : undef,
);
# note: session cookies (i.e. expiry is undef) are not fetched from browser!
for my $c (@MY::CookieMaker::HTTPCookies_cases) {
# note: test-04: does not return the cookies! it returns empty, but test-02 gets them back
# even if expiry is undef for both.
# test-05: which has cookies for /acme and one for /acme/ammo fails
next if $c->{label} eq 'test-05';
next if $c->{label} eq 'test-08';
#next unless $c->{label} =~ /\-1[2345]$/;
diag "\n=====================\ntest " . $c->{label} . " (of ".scalar(@MY::CookieMaker::HTTPCookies_cases).")\n=====================\n";
my $httpcookies = $c->{getcookie}->();
ok(defined $httpcookies, "(label : ".$c->{'label'}.") : got the HTTP::Cookies object by running the test sub.") or BAIL_OUT;
my $httpcookies_count = count_cookies($httpcookies, $skip_discard, $VERBOSITY);
ok(defined($httpcookies_count), 'count_cookies()'." : (label '".$c->{label}."') : called and got good result.") or BAIL_OUT;
if( $VERBOSITY > 0 ){ diag "testing with this HTTP::Cookies object:\n".as_string_cookies($httpcookies); }
my $firefoxmarionettecookies = httpcookies2firefoxmarionettecookies($httpcookies, undef, $skip_discard, $VERBOSITY);
ok(defined($firefoxmarionettecookies), 'httpcookies2firefoxmarionettecookies()'." : (label '".$c->{label}."') : converted HTTP::Cookies (read from the test case) to firefoxmarionettecookies.") or BAIL_OUT(as_string_cookies($httpcookies)."\nno, it fa...
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;
# we can have empty cookie, so don't check
#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 $num_session_cookies = 0;
#for (@$firefoxmarionettecookies){ $num_session_cookies++ if ! exists($_->{expiry}) || ! defined($_->{expiry}) }
( run in 0.622 second using v1.01-cache-2.11-cpan-364913b4093 )