1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
require 'mechanize/test_case'
class TestMechanizePageMetaRefresh < Mechanize::TestCase
def setup
super
@MR = Mechanize::Page::MetaRefresh
@uri = URI 'http://example/here/'
end
def util_page delay, uri
body = <<-BODY
<head><meta http-equiv="refresh" content="#{delay};url=#{uri}"></head>
BODY
Mechanize::Page.new(@uri, nil, body, 200, @mech)
end
def util_meta_refresh page
node = page.search('meta').first
@MR.from_node node, page
end
def test_class_parse
delay, uri, link_self = @MR.parse "0; url=http://localhost:8080/path", @uri
assert_equal "0", delay
assert_equal "http://localhost:8080/path", uri.to_s
refute link_self
delay, uri, link_self =
@MR.parse "100.001; url=http://localhost:8080/path", @uri
assert_equal "100.001", delay
assert_equal "http://localhost:8080/path", uri.to_s
refute link_self
delay, uri, link_self =
@MR.parse "0; url='http://localhost:8080/path'", @uri
assert_equal "0", delay
assert_equal "http://localhost:8080/path", uri.to_s
refute link_self
delay, uri, link_self =
@MR.parse "0; url=\"http://localhost:8080/path\"", @uri
assert_equal "0", delay
assert_equal "http://localhost:8080/path", uri.to_s
refute link_self
delay, uri, link_self = @MR.parse "0; url=", @uri
assert_equal "0", delay
assert_equal "http://example/here/", uri.to_s
assert link_self
delay, uri, link_self = @MR.parse "0", @uri
assert_equal "0", delay
assert_equal "http://example/here/", uri.to_s
assert link_self
delay, uri, link_self = @MR.parse " 0; ", @uri
assert_equal "0", delay
assert_equal "http://example/here/", uri.to_s
assert link_self
delay, uri, link_self = @MR.parse " 0 ; ", @uri
assert_equal "0", delay
assert_equal "http://example/here/", uri.to_s
assert link_self
delay, uri, link_self = @MR.parse "0; UrL=http://localhost:8080/path", @uri
assert_equal "0", delay
assert_equal "http://localhost:8080/path", uri.to_s
refute link_self
delay, uri, link_self = @MR.parse "0 ; UrL = http://localhost:8080/path", @uri
assert_equal "0", delay
assert_equal "http://localhost:8080/path", uri.to_s
refute link_self
end
def test_class_parse_funky
delay, uri, link_self = @MR.parse "0; url=/funky?<b>Welcome<%2Fb>", @uri
assert_equal "0", delay
assert_equal "http://example/funky?%3Cb%3EWelcome%3C%2Fb%3E",
uri.to_s
refute link_self
end
def test_class_from_node
page = util_page 5, 'http://b.example'
link = util_meta_refresh page
assert_equal 5, link.delay
assert_equal 'http://b.example', link.href
page = util_page 5, 'http://example/a'
link = util_meta_refresh page
assert_equal 5, link.delay
assert_equal 'http://example/a', link.href
page = util_page 5, 'test'
link = util_meta_refresh page
assert_equal 5, link.delay
assert_equal 'test', link.href
page = util_page 5, '/test'
link = util_meta_refresh page
assert_equal 5, link.delay
assert_equal '/test', link.href
page = util_page 5, nil
link = util_meta_refresh page
assert_equal 5, link.delay
assert_nil link.href
page = util_page 5, @uri
link = util_meta_refresh page
assert_equal 5, link.delay
assert_equal 'http://example/here/', link.href
end
def test_class_from_node_no_content
body = <<-BODY
<head><meta http-equiv="refresh"></head>
BODY
page = Mechanize::Page.new(@uri, nil, body, 200, @mech)
assert_nil util_meta_refresh page
end
def test_class_from_node_not_refresh
body = <<-BODY
<head><meta http-equiv="other-thing" content="0;"></head>
BODY
page = Mechanize::Page.new(@uri, nil, body, 200, @mech)
assert_nil util_meta_refresh page
end
def test_meta_refresh_click_sends_no_referer
page = util_page 0, '/referer'
link = util_meta_refresh page
refreshed = link.click
assert_equal '', refreshed.body
end
end
|