mechanize 2.14.0 → 2.14.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +27 -1
- data/README.md +7 -0
- data/SECURITY.md +11 -0
- data/lib/mechanize/directory_saver.rb +2 -1
- data/lib/mechanize/file_saver.rb +2 -0
- data/lib/mechanize/http/agent.rb +83 -29
- data/lib/mechanize/parser.rb +33 -3
- data/lib/mechanize/test_case.rb +2 -9
- data/lib/mechanize/version.rb +1 -1
- data/lib/mechanize.rb +12 -2
- data/test/htdocs/frame_test.html +8 -6
- data/test/htdocs/relative/tc_relative_links.html +1 -1
- metadata +7 -174
- data/.autotest +0 -6
- data/.github/dependabot.yml +0 -11
- data/.github/workflows/ci.yml +0 -43
- data/.github/workflows/upstream.yml +0 -51
- data/.gitignore +0 -15
- data/.yardopts +0 -8
- data/Gemfile +0 -12
- data/Rakefile +0 -56
- data/examples/flickr_upload.rb +0 -22
- data/examples/latest_user_agents.rb +0 -100
- data/examples/mech-dump.rb +0 -5
- data/examples/proxy_req.rb +0 -7
- data/examples/rubygems.rb +0 -23
- data/examples/spider.rb +0 -22
- data/examples/wikipedia_links_to_philosophy.rb +0 -158
- data/mechanize.gemspec +0 -74
- data/test/data/htpasswd +0 -1
- data/test/data/server.crt +0 -16
- data/test/data/server.csr +0 -12
- data/test/data/server.key +0 -15
- data/test/data/server.pem +0 -15
- data/test/test_mechanize.rb +0 -1382
- data/test/test_mechanize_cookie.rb +0 -559
- data/test/test_mechanize_cookie_jar.rb +0 -615
- data/test/test_mechanize_directory_saver.rb +0 -60
- data/test/test_mechanize_download.rb +0 -102
- data/test/test_mechanize_element_not_found_error.rb +0 -16
- data/test/test_mechanize_file.rb +0 -118
- data/test/test_mechanize_file_connection.rb +0 -40
- data/test/test_mechanize_file_request.rb +0 -26
- data/test/test_mechanize_file_response.rb +0 -48
- data/test/test_mechanize_file_saver.rb +0 -22
- data/test/test_mechanize_form.rb +0 -1025
- data/test/test_mechanize_form_check_box.rb +0 -49
- data/test/test_mechanize_form_encoding.rb +0 -110
- data/test/test_mechanize_form_field.rb +0 -78
- data/test/test_mechanize_form_file_upload.rb +0 -21
- data/test/test_mechanize_form_image_button.rb +0 -13
- data/test/test_mechanize_form_keygen.rb +0 -34
- data/test/test_mechanize_form_multi_select_list.rb +0 -98
- data/test/test_mechanize_form_option.rb +0 -60
- data/test/test_mechanize_form_radio_button.rb +0 -96
- data/test/test_mechanize_form_select_list.rb +0 -81
- data/test/test_mechanize_form_textarea.rb +0 -53
- data/test/test_mechanize_headers.rb +0 -36
- data/test/test_mechanize_history.rb +0 -104
- data/test/test_mechanize_http_agent.rb +0 -1915
- data/test/test_mechanize_http_auth_challenge.rb +0 -64
- data/test/test_mechanize_http_auth_realm.rb +0 -56
- data/test/test_mechanize_http_auth_store.rb +0 -233
- data/test/test_mechanize_http_content_disposition_parser.rb +0 -167
- data/test/test_mechanize_http_www_authenticate_parser.rb +0 -204
- data/test/test_mechanize_image.rb +0 -9
- data/test/test_mechanize_link.rb +0 -171
- data/test/test_mechanize_page.rb +0 -295
- data/test/test_mechanize_page_encoding.rb +0 -215
- data/test/test_mechanize_page_frame.rb +0 -17
- data/test/test_mechanize_page_image.rb +0 -191
- data/test/test_mechanize_page_link.rb +0 -377
- data/test/test_mechanize_page_meta_refresh.rb +0 -151
- data/test/test_mechanize_parser.rb +0 -316
- data/test/test_mechanize_pluggable_parser.rb +0 -68
- data/test/test_mechanize_redirect_limit_reached_error.rb +0 -25
- data/test/test_mechanize_redirect_not_get_or_head_error.rb +0 -15
- data/test/test_mechanize_response_read_error.rb +0 -29
- data/test/test_mechanize_subclass.rb +0 -23
- data/test/test_mechanize_util.rb +0 -144
- data/test/test_mechanize_xml_file.rb +0 -30
- data/test/test_multi_select.rb +0 -120
|
@@ -1,377 +0,0 @@
|
|
|
1
|
-
# coding: utf-8
|
|
2
|
-
# frozen_string_literal: true
|
|
3
|
-
|
|
4
|
-
require 'mechanize/test_case'
|
|
5
|
-
|
|
6
|
-
puts "Nokogiri::VERSION_INFO: #{Nokogiri::VERSION_INFO}"
|
|
7
|
-
|
|
8
|
-
class TestMechanizePageLink < Mechanize::TestCase
|
|
9
|
-
|
|
10
|
-
WINDOWS_1255 = <<-HTML
|
|
11
|
-
<meta http-equiv="content-type" content="text/html; charset=windows-1255">
|
|
12
|
-
<title>hi</title>
|
|
13
|
-
HTML
|
|
14
|
-
|
|
15
|
-
BAD = <<-HTML.dup
|
|
16
|
-
<meta http-equiv="content-type" content="text/html; charset=windows-1255">
|
|
17
|
-
<title>Bia\xB3ystok</title>
|
|
18
|
-
HTML
|
|
19
|
-
BAD.force_encoding Encoding::BINARY if defined? Encoding
|
|
20
|
-
|
|
21
|
-
SJIS_TITLE = "\x83\x65\x83\x58\x83\x67"
|
|
22
|
-
|
|
23
|
-
SJIS_AFTER_TITLE = <<-HTML.dup
|
|
24
|
-
<title>#{SJIS_TITLE}</title>
|
|
25
|
-
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
|
|
26
|
-
HTML
|
|
27
|
-
SJIS_AFTER_TITLE.force_encoding Encoding::BINARY if defined? Encoding
|
|
28
|
-
|
|
29
|
-
SJIS_BAD_AFTER_TITLE = <<-HTML.dup
|
|
30
|
-
<title>#{SJIS_TITLE}</title>
|
|
31
|
-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
|
32
|
-
HTML
|
|
33
|
-
SJIS_BAD_AFTER_TITLE.force_encoding Encoding::BINARY if defined? Encoding
|
|
34
|
-
|
|
35
|
-
UTF8_TITLE = 'テスト'
|
|
36
|
-
UTF8 = <<-HTML
|
|
37
|
-
<title>#{UTF8_TITLE}</title>
|
|
38
|
-
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
|
|
39
|
-
HTML
|
|
40
|
-
|
|
41
|
-
ENCODING_ERROR_CLASS = Nokogiri::XML::SyntaxError
|
|
42
|
-
|
|
43
|
-
def setup
|
|
44
|
-
super
|
|
45
|
-
|
|
46
|
-
@uri = URI('http://example')
|
|
47
|
-
@res = { 'content-type' => 'text/html' }
|
|
48
|
-
@body = +'<title>hi</title>'
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def util_page body = @body, res = @res
|
|
52
|
-
Mechanize::Page.new @uri, res, body && body.force_encoding(Encoding::BINARY), 200, @mech
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def skip_if_nkf_dependency
|
|
56
|
-
if RUBY_ENGINE == 'jruby'
|
|
57
|
-
meth = caller_locations(1,1).first.base_label
|
|
58
|
-
skip "#{meth}: skipped because this feature currently depends on NKF"
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def test_override_content_type
|
|
63
|
-
page = Mechanize::Page.new nil, {'content-type' => 'text/html'}, WINDOWS_1255
|
|
64
|
-
assert page
|
|
65
|
-
assert_equal 'text/html; charset=windows-1255', page.content_type
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def test_canonical_uri
|
|
69
|
-
page = @mech.get("http://localhost/canonical_uri.html")
|
|
70
|
-
assert_equal(URI("http://localhost/canonical_uri"), page.canonical_uri)
|
|
71
|
-
|
|
72
|
-
page = @mech.get("http://localhost/file_upload.html")
|
|
73
|
-
assert_nil page.canonical_uri
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def test_canonical_uri_unescaped
|
|
77
|
-
page = util_page(+<<-BODY)
|
|
78
|
-
<head>
|
|
79
|
-
<link rel="canonical" href="http://example/white space"/>
|
|
80
|
-
</head>
|
|
81
|
-
BODY
|
|
82
|
-
|
|
83
|
-
assert_equal @uri + '/white%20space', page.canonical_uri
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
def test_charset_from_content_type
|
|
87
|
-
charset = Mechanize::Page.__send__ :charset_from_content_type, 'text/html;charset=UTF-8'
|
|
88
|
-
|
|
89
|
-
assert_equal 'UTF-8', charset
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
def test_charset_from_bad_content_type
|
|
93
|
-
charset = Mechanize::Page.__send__ :charset_from_content_type, 'text/html'
|
|
94
|
-
|
|
95
|
-
assert_nil charset
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
def test_encoding
|
|
99
|
-
page = util_page WINDOWS_1255.dup
|
|
100
|
-
|
|
101
|
-
assert_equal 'windows-1255', page.encoding
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
def test_encoding_charset_after_title
|
|
105
|
-
page = util_page SJIS_AFTER_TITLE
|
|
106
|
-
|
|
107
|
-
assert_equal false, page.encoding_error?
|
|
108
|
-
|
|
109
|
-
assert_equal 'Shift_JIS', page.encoding
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
def test_encoding_charset_after_title_bad
|
|
113
|
-
skip_if_nkf_dependency
|
|
114
|
-
|
|
115
|
-
# https://gitlab.gnome.org/GNOME/libxml2/-/issues/543
|
|
116
|
-
skip if Nokogiri.uses_libxml?([">= 2.11.0", "< 2.12.0"])
|
|
117
|
-
|
|
118
|
-
page = util_page UTF8.dup
|
|
119
|
-
|
|
120
|
-
assert_equal false, page.encoding_error?
|
|
121
|
-
|
|
122
|
-
assert_equal "UTF-8", page.encoding
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
def test_encoding_charset_after_title_double_bad
|
|
126
|
-
skip_if_nkf_dependency
|
|
127
|
-
|
|
128
|
-
page = util_page SJIS_BAD_AFTER_TITLE
|
|
129
|
-
|
|
130
|
-
assert_equal false, page.encoding_error?
|
|
131
|
-
|
|
132
|
-
assert_equal 'SHIFT_JIS', page.encoding
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
def test_encoding_charset_bad
|
|
136
|
-
skip_if_nkf_dependency
|
|
137
|
-
|
|
138
|
-
# https://gitlab.gnome.org/GNOME/libxml2/-/issues/543
|
|
139
|
-
skip if Nokogiri.uses_libxml?([">= 2.11.0", "< 2.12.0"])
|
|
140
|
-
|
|
141
|
-
page = util_page(+"<title>#{UTF8_TITLE}</title>")
|
|
142
|
-
page.encodings.replace %w[
|
|
143
|
-
UTF-8
|
|
144
|
-
Shift_JIS
|
|
145
|
-
]
|
|
146
|
-
|
|
147
|
-
assert_equal false, page.encoding_error?
|
|
148
|
-
|
|
149
|
-
assert_equal 'UTF-8', page.encoding
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
def test_encoding_meta_charset
|
|
153
|
-
page = util_page(+"<meta charset='UTF-8'>")
|
|
154
|
-
|
|
155
|
-
assert_equal 'UTF-8', page.encoding
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
def test_encoding_equals
|
|
159
|
-
page = util_page
|
|
160
|
-
page.meta_refresh
|
|
161
|
-
assert page.instance_variable_get(:@meta_refresh)
|
|
162
|
-
|
|
163
|
-
page.encoding = 'UTF-8'
|
|
164
|
-
|
|
165
|
-
assert_nil page.instance_variable_get(:@meta_refresh)
|
|
166
|
-
|
|
167
|
-
assert_equal 'UTF-8', page.encoding
|
|
168
|
-
assert_equal 'UTF-8', page.parser.encoding
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
def test_page_encoding_error?
|
|
172
|
-
page = util_page
|
|
173
|
-
page.parser.errors.clear
|
|
174
|
-
assert_equal false, page.encoding_error?
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
def test_detect_libxml2error_indicate_encoding
|
|
178
|
-
page = util_page
|
|
179
|
-
page.parser.errors.clear
|
|
180
|
-
|
|
181
|
-
# error in libxml2-2.7.8/parser.c, HTMLparser.c or parserInternals.c
|
|
182
|
-
page.parser.errors = [ENCODING_ERROR_CLASS.new("Input is not proper UTF-8, indicate encoding !\n")]
|
|
183
|
-
assert_equal true, page.encoding_error?
|
|
184
|
-
end
|
|
185
|
-
|
|
186
|
-
def test_detect_libxml2error_invalid_char
|
|
187
|
-
page = util_page
|
|
188
|
-
page.parser.errors.clear
|
|
189
|
-
|
|
190
|
-
# error in libxml2-2.7.8/HTMLparser.c
|
|
191
|
-
page.parser.errors = [ENCODING_ERROR_CLASS.new("Invalid char in CDATA 0x%X\n")]
|
|
192
|
-
assert_equal true, page.encoding_error?
|
|
193
|
-
end
|
|
194
|
-
|
|
195
|
-
def test_detect_libxml2error_input_conversion_failed
|
|
196
|
-
page = util_page
|
|
197
|
-
page.parser.errors.clear
|
|
198
|
-
|
|
199
|
-
# error in libxml2-2.7.8/encoding.c
|
|
200
|
-
page.parser.errors = [ENCODING_ERROR_CLASS.new("input conversion failed due to input error\n")]
|
|
201
|
-
assert_equal true, page.encoding_error?
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
def test_detect_libxml2error_which_unsupported_by_mechanize
|
|
205
|
-
page = util_page
|
|
206
|
-
page.parser.errors.clear
|
|
207
|
-
|
|
208
|
-
# error in libxml2-2.7.8/HTMLparser.c
|
|
209
|
-
page.parser.errors = [ENCODING_ERROR_CLASS.new("encoder error\n")]
|
|
210
|
-
assert_equal false, page.encoding_error?
|
|
211
|
-
end
|
|
212
|
-
|
|
213
|
-
def test_encoding_equals_before_parser
|
|
214
|
-
# document has a bad encoding information - windows-1255
|
|
215
|
-
page = util_page BAD
|
|
216
|
-
|
|
217
|
-
# encoding is wrong, so user wants to force ISO-8859-2
|
|
218
|
-
page.encoding = 'ISO-8859-2'
|
|
219
|
-
|
|
220
|
-
assert_equal false, page.encoding_error?
|
|
221
|
-
assert_equal 'ISO-8859-2', page.encoding
|
|
222
|
-
assert_equal 'ISO-8859-2', page.parser.encoding
|
|
223
|
-
end
|
|
224
|
-
|
|
225
|
-
def test_encoding_equals_after_parser
|
|
226
|
-
# document has a bad encoding information - windows-1255
|
|
227
|
-
page = util_page BAD
|
|
228
|
-
page.parser
|
|
229
|
-
|
|
230
|
-
# autodetection sets encoding to windows-1255
|
|
231
|
-
assert_equal 'windows-1255', page.encoding
|
|
232
|
-
# believe in yourself, not machine
|
|
233
|
-
assert_equal false, page.encoding_error?
|
|
234
|
-
|
|
235
|
-
# encoding is wrong, so user wants to force ISO-8859-2
|
|
236
|
-
page.encoding = 'ISO-8859-2'
|
|
237
|
-
|
|
238
|
-
assert_equal false, page.encoding_error?
|
|
239
|
-
assert_equal 'ISO-8859-2', page.encoding
|
|
240
|
-
assert_equal 'ISO-8859-2', page.parser.encoding
|
|
241
|
-
end
|
|
242
|
-
|
|
243
|
-
def test_frames_with
|
|
244
|
-
page = @mech.get("http://localhost/frame_test.html")
|
|
245
|
-
assert_equal(3, page.frames.size)
|
|
246
|
-
|
|
247
|
-
find_orig = page.frames.find_all { |f| f.name == 'frame1' }
|
|
248
|
-
|
|
249
|
-
find1 = page.frames_with(:name => 'frame1')
|
|
250
|
-
|
|
251
|
-
find_orig.zip(find1).each { |a,b|
|
|
252
|
-
assert_equal(a, b)
|
|
253
|
-
}
|
|
254
|
-
end
|
|
255
|
-
|
|
256
|
-
def test_links_with_dom_id
|
|
257
|
-
page = @mech.get("http://localhost/tc_links.html")
|
|
258
|
-
link = page.links_with(:dom_id => 'bold_aaron_link')
|
|
259
|
-
link_by_id = page.links_with(:id => 'bold_aaron_link')
|
|
260
|
-
assert_equal(1, link.length)
|
|
261
|
-
assert_equal('Aaron Patterson', link.first.text)
|
|
262
|
-
assert_equal(link, link_by_id)
|
|
263
|
-
end
|
|
264
|
-
|
|
265
|
-
def test_links_with_dom_class
|
|
266
|
-
page = @mech.get("http://localhost/tc_links.html")
|
|
267
|
-
link = page.links_with(:dom_class => 'thing_link')
|
|
268
|
-
link_by_class = page.links_with(:class => 'thing_link')
|
|
269
|
-
assert_equal(1, link.length)
|
|
270
|
-
assert_equal(link, link_by_class)
|
|
271
|
-
end
|
|
272
|
-
|
|
273
|
-
def test_link_with_encoded_space
|
|
274
|
-
page = @mech.get("http://localhost/tc_links.html")
|
|
275
|
-
link = page.link_with(:text => 'encoded space')
|
|
276
|
-
page = @mech.click link
|
|
277
|
-
end
|
|
278
|
-
|
|
279
|
-
def test_link_with_space
|
|
280
|
-
page = @mech.get("http://localhost/tc_links.html")
|
|
281
|
-
link = page.link_with(:text => 'not encoded space')
|
|
282
|
-
page = @mech.click link
|
|
283
|
-
end
|
|
284
|
-
|
|
285
|
-
def test_link_with_unusual_characters
|
|
286
|
-
page = @mech.get("http://localhost/tc_links.html")
|
|
287
|
-
link = page.link_with(:text => 'unusual characters')
|
|
288
|
-
|
|
289
|
-
@mech.click link
|
|
290
|
-
|
|
291
|
-
# HACK no assertion
|
|
292
|
-
end
|
|
293
|
-
|
|
294
|
-
def test_links
|
|
295
|
-
page = @mech.get("http://localhost/find_link.html")
|
|
296
|
-
assert_equal(18, page.links.length)
|
|
297
|
-
end unless RUBY_ENGINE == 'jruby' # NekoHTML does not parse FRAME outside of FRAMESET
|
|
298
|
-
|
|
299
|
-
def test_links_with_bold
|
|
300
|
-
page = @mech.get("http://localhost/tc_links.html")
|
|
301
|
-
link = page.links_with(:text => /Bold Dude/)
|
|
302
|
-
assert_equal(1, link.length)
|
|
303
|
-
assert_equal('Bold Dude', link.first.text)
|
|
304
|
-
assert_equal [], link.first.rel
|
|
305
|
-
assert !link.first.rel?('me')
|
|
306
|
-
assert !link.first.rel?('nofollow')
|
|
307
|
-
|
|
308
|
-
link = page.links_with(:text => 'Aaron James Patterson')
|
|
309
|
-
assert_equal(1, link.length)
|
|
310
|
-
assert_equal('Aaron James Patterson', link.first.text)
|
|
311
|
-
assert_equal ['me'], link.first.rel
|
|
312
|
-
assert link.first.rel?('me')
|
|
313
|
-
assert !link.first.rel?('nofollow')
|
|
314
|
-
|
|
315
|
-
link = page.links_with(:text => 'Aaron Patterson')
|
|
316
|
-
assert_equal(1, link.length)
|
|
317
|
-
assert_equal('Aaron Patterson', link.first.text)
|
|
318
|
-
assert_equal ['me', 'nofollow'], link.first.rel
|
|
319
|
-
assert link.first.rel?('me')
|
|
320
|
-
assert link.first.rel?('nofollow')
|
|
321
|
-
|
|
322
|
-
link = page.links_with(:text => 'Ruby Rocks!')
|
|
323
|
-
assert_equal(1, link.length)
|
|
324
|
-
assert_equal('Ruby Rocks!', link.first.text)
|
|
325
|
-
end
|
|
326
|
-
|
|
327
|
-
def test_meta_refresh
|
|
328
|
-
page = @mech.get("http://localhost/find_link.html")
|
|
329
|
-
assert_equal(3, page.meta_refresh.length)
|
|
330
|
-
assert_equal(%w{
|
|
331
|
-
http://www.drphil.com/
|
|
332
|
-
http://www.upcase.com/
|
|
333
|
-
http://tenderlovemaking.com/ }.sort,
|
|
334
|
-
page.meta_refresh.map { |x| x.href.downcase }.sort)
|
|
335
|
-
end
|
|
336
|
-
|
|
337
|
-
def test_title
|
|
338
|
-
page = util_page
|
|
339
|
-
|
|
340
|
-
assert_equal('hi', page.title)
|
|
341
|
-
end
|
|
342
|
-
|
|
343
|
-
def test_title_none
|
|
344
|
-
page = util_page(+'') # invalid HTML
|
|
345
|
-
|
|
346
|
-
assert_nil(page.title)
|
|
347
|
-
end
|
|
348
|
-
|
|
349
|
-
def test_page_decoded_with_charset
|
|
350
|
-
page = util_page @body, 'content-type' => 'text/html; charset=EUC-JP'
|
|
351
|
-
|
|
352
|
-
assert_equal 'EUC-JP', page.encoding
|
|
353
|
-
assert_equal 'EUC-JP', page.parser.encoding
|
|
354
|
-
end
|
|
355
|
-
|
|
356
|
-
def test_form
|
|
357
|
-
page = @mech.get("http://localhost/tc_form_action.html")
|
|
358
|
-
|
|
359
|
-
form = page.form(:name => 'post_form1')
|
|
360
|
-
assert form
|
|
361
|
-
yielded = false
|
|
362
|
-
|
|
363
|
-
form = page.form(:name => 'post_form1') { |f|
|
|
364
|
-
yielded = true
|
|
365
|
-
assert f
|
|
366
|
-
assert_equal(form, f)
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
assert yielded
|
|
370
|
-
|
|
371
|
-
form_by_action = page.form(:action => '/form_post?a=b&b=c')
|
|
372
|
-
assert form_by_action
|
|
373
|
-
assert_equal(form, form_by_action)
|
|
374
|
-
end
|
|
375
|
-
|
|
376
|
-
end
|
|
377
|
-
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
require 'mechanize/test_case'
|
|
3
|
-
|
|
4
|
-
class TestMechanizePageMetaRefresh < Mechanize::TestCase
|
|
5
|
-
|
|
6
|
-
def setup
|
|
7
|
-
super
|
|
8
|
-
|
|
9
|
-
@MR = Mechanize::Page::MetaRefresh
|
|
10
|
-
|
|
11
|
-
@uri = URI 'http://example/here/'
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def util_page delay, uri
|
|
15
|
-
body = <<-BODY
|
|
16
|
-
<head><meta http-equiv="refresh" content="#{delay};url=#{uri}"></head>
|
|
17
|
-
BODY
|
|
18
|
-
|
|
19
|
-
Mechanize::Page.new(@uri, nil, body, 200, @mech)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def util_meta_refresh page
|
|
23
|
-
node = page.search('meta').first
|
|
24
|
-
@MR.from_node node, page
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def test_class_parse
|
|
28
|
-
delay, uri, link_self = @MR.parse "0; url=http://localhost:8080/path", @uri
|
|
29
|
-
assert_equal "0", delay
|
|
30
|
-
assert_equal "http://localhost:8080/path", uri.to_s
|
|
31
|
-
refute link_self
|
|
32
|
-
|
|
33
|
-
delay, uri, link_self =
|
|
34
|
-
@MR.parse "100.001; url=http://localhost:8080/path", @uri
|
|
35
|
-
assert_equal "100.001", delay
|
|
36
|
-
assert_equal "http://localhost:8080/path", uri.to_s
|
|
37
|
-
refute link_self
|
|
38
|
-
|
|
39
|
-
delay, uri, link_self =
|
|
40
|
-
@MR.parse "0; url='http://localhost:8080/path'", @uri
|
|
41
|
-
assert_equal "0", delay
|
|
42
|
-
assert_equal "http://localhost:8080/path", uri.to_s
|
|
43
|
-
refute link_self
|
|
44
|
-
|
|
45
|
-
delay, uri, link_self =
|
|
46
|
-
@MR.parse "0; url=\"http://localhost:8080/path\"", @uri
|
|
47
|
-
assert_equal "0", delay
|
|
48
|
-
assert_equal "http://localhost:8080/path", uri.to_s
|
|
49
|
-
refute link_self
|
|
50
|
-
|
|
51
|
-
delay, uri, link_self = @MR.parse "0; url=", @uri
|
|
52
|
-
assert_equal "0", delay
|
|
53
|
-
assert_equal "http://example/here/", uri.to_s
|
|
54
|
-
assert link_self
|
|
55
|
-
|
|
56
|
-
delay, uri, link_self = @MR.parse "0", @uri
|
|
57
|
-
assert_equal "0", delay
|
|
58
|
-
assert_equal "http://example/here/", uri.to_s
|
|
59
|
-
assert link_self
|
|
60
|
-
|
|
61
|
-
delay, uri, link_self = @MR.parse " 0; ", @uri
|
|
62
|
-
assert_equal "0", delay
|
|
63
|
-
assert_equal "http://example/here/", uri.to_s
|
|
64
|
-
assert link_self
|
|
65
|
-
|
|
66
|
-
delay, uri, link_self = @MR.parse " 0 ; ", @uri
|
|
67
|
-
assert_equal "0", delay
|
|
68
|
-
assert_equal "http://example/here/", uri.to_s
|
|
69
|
-
assert link_self
|
|
70
|
-
|
|
71
|
-
delay, uri, link_self = @MR.parse "0; UrL=http://localhost:8080/path", @uri
|
|
72
|
-
assert_equal "0", delay
|
|
73
|
-
assert_equal "http://localhost:8080/path", uri.to_s
|
|
74
|
-
refute link_self
|
|
75
|
-
|
|
76
|
-
delay, uri, link_self = @MR.parse "0 ; UrL = http://localhost:8080/path", @uri
|
|
77
|
-
assert_equal "0", delay
|
|
78
|
-
assert_equal "http://localhost:8080/path", uri.to_s
|
|
79
|
-
refute link_self
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
def test_class_parse_funky
|
|
83
|
-
delay, uri, link_self = @MR.parse "0; url=/funky?<b>Welcome<%2Fb>", @uri
|
|
84
|
-
|
|
85
|
-
assert_equal "0", delay
|
|
86
|
-
assert_equal "http://example/funky?%3Cb%3EWelcome%3C%2Fb%3E",
|
|
87
|
-
uri.to_s
|
|
88
|
-
|
|
89
|
-
refute link_self
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
def test_class_from_node
|
|
93
|
-
page = util_page 5, 'http://b.example'
|
|
94
|
-
link = util_meta_refresh page
|
|
95
|
-
assert_equal 5, link.delay
|
|
96
|
-
assert_equal 'http://b.example', link.href
|
|
97
|
-
|
|
98
|
-
page = util_page 5, 'http://example/a'
|
|
99
|
-
link = util_meta_refresh page
|
|
100
|
-
assert_equal 5, link.delay
|
|
101
|
-
assert_equal 'http://example/a', link.href
|
|
102
|
-
|
|
103
|
-
page = util_page 5, 'test'
|
|
104
|
-
link = util_meta_refresh page
|
|
105
|
-
assert_equal 5, link.delay
|
|
106
|
-
assert_equal 'test', link.href
|
|
107
|
-
|
|
108
|
-
page = util_page 5, '/test'
|
|
109
|
-
link = util_meta_refresh page
|
|
110
|
-
assert_equal 5, link.delay
|
|
111
|
-
assert_equal '/test', link.href
|
|
112
|
-
|
|
113
|
-
page = util_page 5, nil
|
|
114
|
-
link = util_meta_refresh page
|
|
115
|
-
assert_equal 5, link.delay
|
|
116
|
-
assert_nil link.href
|
|
117
|
-
|
|
118
|
-
page = util_page 5, @uri
|
|
119
|
-
link = util_meta_refresh page
|
|
120
|
-
assert_equal 5, link.delay
|
|
121
|
-
assert_equal 'http://example/here/', link.href
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
def test_class_from_node_no_content
|
|
125
|
-
body = <<-BODY
|
|
126
|
-
<head><meta http-equiv="refresh"></head>
|
|
127
|
-
BODY
|
|
128
|
-
|
|
129
|
-
page = Mechanize::Page.new(@uri, nil, body, 200, @mech)
|
|
130
|
-
|
|
131
|
-
assert_nil util_meta_refresh page
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
def test_class_from_node_not_refresh
|
|
135
|
-
body = <<-BODY
|
|
136
|
-
<head><meta http-equiv="other-thing" content="0;"></head>
|
|
137
|
-
BODY
|
|
138
|
-
|
|
139
|
-
page = Mechanize::Page.new(@uri, nil, body, 200, @mech)
|
|
140
|
-
|
|
141
|
-
assert_nil util_meta_refresh page
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
def test_meta_refresh_click_sends_no_referer
|
|
145
|
-
page = util_page 0, '/referer'
|
|
146
|
-
link = util_meta_refresh page
|
|
147
|
-
refreshed = link.click
|
|
148
|
-
assert_equal '', refreshed.body
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
|