# vi:filetype= use strict; use warnings; use File::Slurp qw( write_file ); use Test::Base; use Cwd 'cwd'; use IPC::Run (); my $tmp_file = cwd() . '/t/vdom.html'; plan tests => 2 * blocks(); run { my $block = shift; my $name = $block->name; my $html = $block->html; my $expected_vdom = $block->vdom; my $expected_core_vdom = $block->core_vdom; write_file $tmp_file, $html; #warn "Tmpfile: $tmp_file\n"; my @cmd = ("./start.sh", "vdom"); my $stdin = "file://$tmp_file"; IPC::Run::run(\@cmd, \$stdin, \(my $vdom), \(my $err)); is $?, 0, "$name - qt-webkit exited with 0 status code"; if (defined $expected_vdom) { $expected_vdom =~ s/^ +//gm; $vdom =~ s{(location="file:///).*?/(t/vdom.html")}{$1$2}; is $vdom, $expected_vdom, "$name - vdom ok"; } elsif (defined $expected_core_vdom) { $expected_core_vdom =~ s/^ +//gm; (my $core_vdom = $vdom) =~ s/^(?:[^\n]*\n){3}//s; #warn "Count: $count\n"; $core_vdom =~ s/(?:\n}$){3}$//sm; is $core_vdom, $expected_core_vdom, "$name - core vdom ok"; } else { die "$name - neither --- vdom nor --- core_vdom are specified.\n"; } } __DATA__ === TEST 1: empty html --- html --- vdom window location="file:///t/vdom.html" innerHeight=768 innerWidth=1024 outerHeight=0 outerWidth=0 { document width=1024 height=768 { BODY offsetX=0 offsetY=0 offsetWidth=1008 offsetHeight=752 fontFamily="Arial" fontSize="14px" fontStyle="normal" fontWeight="normal" color="rgb(0, 0, 0)" backgroundColor="rgba(0, 0, 0, 0)" { "\n " "\n" "\n" } } } === TEST 2: A tags --- html foo bar --- core_vdom "\n" A id="b" name="hello" offsetX=8 offsetY=8 offsetWidth=17 offsetHeight=15 { "foo" } "\n" A href="file:///abc.html" target="_blank" offsetX=29 offsetY=8 offsetWidth=18 offsetHeight=15 color="rgb(0, 0, 238)" { "bar" } "\n" "\n" === TEST 3: attribute inheritance (first child) --- html
hi
boy
--- core_vdom "\n " DIV id="divA" offsetX=8 offsetY=8 offsetHeight=32 color="rgb(255, 0, 0)" { "\n " DIV id="divB" offsetHeight=16 { "hi" } "\n " DIV id="divC" offsetY=24 offsetHeight=16 color="rgb(0, 128, 0)" { "boy" } "\n " } "\n " "\n" "\n" === TEST 4: attribute inheritance (second child) --- html
hi
boy
--- core_vdom "\n " DIV id="divA" offsetX=8 offsetY=8 offsetHeight=32 color="rgb(0, 128, 0)" { "\n " DIV id="divB" offsetHeight=16 color="rgb(255, 0, 0)" { "hi" } "\n " DIV id="divC" offsetY=24 offsetHeight=16 { "boy" } "\n " } "\n " "\n" "\n" === TEST 5: attribute inheritance (neither className nor id inheritance) --- html --- core_vdom SPAN id="foo" className="bar" offsetX=8 offsetY=8 offsetWidth=0 offsetHeight=0 { "\n " SPAN id="foo" className="bar" { } "\n" } "\n" === TEST 6: attribute inheritance (grandson should inherit attrs as well) --- html A B --- core_vdom SPAN offsetX=8 offsetY=8 offsetWidth=22 offsetHeight=15 { "\n " SPAN offsetWidth=13 { "\n " SPAN offsetWidth=9 { "A" } "\n " } "\n " SPAN offsetX=21 offsetWidth=9 color="rgb(255, 0, 0)" { "\n " SPAN color="rgb(0, 0, 0)" { "B" } "\n " } "\n" } "\n" === TEST 7: hidden tags --- html Hello,

yes!

world! --- core_vdom "Hello,\n" "\nworld!\n" === TEST 8: ignored tags --- html Hello, world ! -- agentzh --- core_vdom "\n Hello,\n " "\n world\n " "\n !\n " INPUT offsetX=29 offsetY=16 offsetWidth=48 offsetHeight=10 { } "\n " TEXTAREA offsetX=78 offsetY=12 offsetWidth=63 offsetHeight=10 { } "\n --\n " SELECT offsetX=145 offsetY=8 offsetWidth=75 offsetHeight=24 backgroundColor="rgb(255, 255, 255)" { } "\n " "\n agentzh\n" "\n"