mechanize 2.0.pre.2 → 2.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of mechanize might be problematic. Click here for more details.

Files changed (46) hide show
  1. data.tar.gz.sig +0 -0
  2. data/CHANGELOG.rdoc +22 -0
  3. data/Manifest.txt +11 -8
  4. data/Rakefile +2 -2
  5. data/examples/flickr_upload.rb +6 -7
  6. data/examples/mech-dump.rb +0 -2
  7. data/examples/proxy_req.rb +0 -2
  8. data/examples/rubyforge.rb +1 -3
  9. data/examples/spider.rb +2 -3
  10. data/lib/mechanize.rb +228 -680
  11. data/lib/mechanize/form/field.rb +1 -1
  12. data/lib/mechanize/history.rb +23 -5
  13. data/lib/mechanize/http.rb +3 -0
  14. data/lib/mechanize/http/agent.rb +738 -0
  15. data/lib/mechanize/inspect.rb +2 -2
  16. data/lib/mechanize/page.rb +101 -42
  17. data/lib/mechanize/page/frame.rb +24 -17
  18. data/lib/mechanize/page/link.rb +72 -54
  19. data/lib/mechanize/page/meta_refresh.rb +56 -0
  20. data/lib/mechanize/response_read_error.rb +27 -0
  21. data/test/htdocs/frame_referer_test.html +10 -0
  22. data/test/htdocs/tc_referer.html +4 -0
  23. data/test/test_frames.rb +9 -0
  24. data/test/test_history.rb +74 -98
  25. data/test/test_mechanize.rb +334 -812
  26. data/test/test_mechanize_form.rb +32 -3
  27. data/test/{test_textarea.rb → test_mechanize_form_textarea.rb} +1 -1
  28. data/test/test_mechanize_http_agent.rb +697 -0
  29. data/test/test_mechanize_link.rb +83 -0
  30. data/test/test_mechanize_page_encoding.rb +147 -0
  31. data/test/test_mechanize_page_link.rb +379 -0
  32. data/test/test_mechanize_page_meta_refresh.rb +115 -0
  33. data/test/test_pretty_print.rb +1 -1
  34. data/test/test_referer.rb +29 -5
  35. data/test/test_response_code.rb +21 -20
  36. data/test/test_robots.rb +13 -17
  37. data/test/test_scheme.rb +1 -1
  38. metadata +30 -31
  39. metadata.gz.sig +0 -0
  40. data/lib/mechanize/page/meta.rb +0 -48
  41. data/test/test_form_no_inputname.rb +0 -15
  42. data/test/test_links.rb +0 -146
  43. data/test/test_mechanize_page.rb +0 -224
  44. data/test/test_meta.rb +0 -67
  45. data/test/test_upload.rb +0 -109
  46. data/test/test_verbs.rb +0 -25
@@ -0,0 +1,83 @@
1
+ require "helper"
2
+
3
+ class TestMechanizeLink < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @agent = Mechanize.new
7
+ end
8
+
9
+ def test_click
10
+ page = @agent.get("http://localhost/frame_test.html")
11
+ link = page.link_with(:text => "Form Test")
12
+ assert_not_nil(link)
13
+ assert_equal('Form Test', link.text)
14
+ page = link.click
15
+ assert_equal("http://localhost/form_test.html",
16
+ @agent.history.last.uri.to_s)
17
+ end
18
+
19
+ def test_click_base
20
+ page = @agent.get("http://google.com/tc_base_link.html")
21
+ page = page.links.first.click
22
+ assert @agent.visited?("http://localhost/index.html")
23
+ end
24
+
25
+ def test_click_unsupported_scheme
26
+ page = @agent.get("http://google.com/tc_links.html")
27
+ link = page.link_with(:text => 'javascript link')
28
+ assert_raise(Mechanize::UnsupportedSchemeError) {
29
+ link.click
30
+ }
31
+
32
+ @agent.scheme_handlers['javascript'] = lambda { |my_link, my_page|
33
+ URI.parse('http://localhost/tc_links.html')
34
+ }
35
+ assert_nothing_raised {
36
+ link.click
37
+ }
38
+ end
39
+
40
+ def test_text_alt_text
41
+ page = @agent.get("http://localhost/alt_text.html")
42
+ assert_equal(5, page.links.length)
43
+ assert_equal(1, page.meta_refresh.length)
44
+
45
+ assert_equal '', page.meta_refresh.first.text
46
+ assert_equal 'alt text', page.link_with(:href => 'alt_text.html').text
47
+ assert_equal '', page.link_with(:href => 'no_alt_text.html').text
48
+ assert_equal 'no image', page.link_with(:href => 'no_image.html').text
49
+ assert_equal '', page.link_with(:href => 'no_text.html').text
50
+ assert_equal '', page.link_with(:href => 'nil_alt_text.html').text
51
+ end
52
+
53
+ def test_uri_escaped
54
+ doc = Nokogiri::HTML::Document.new
55
+
56
+ node = Nokogiri::XML::Node.new('foo', doc)
57
+ node['href'] = 'http://foo.bar/%20baz'
58
+
59
+ link = Mechanize::Page::Link.new(node, nil, nil)
60
+
61
+ assert_equal 'http://foo.bar/%20baz', link.uri.to_s
62
+ end
63
+
64
+ def test_uri_no_path
65
+ page = @agent.get("http://localhost/relative/tc_relative_links.html")
66
+ page = page.link_with(:text => 'just the query string').click
67
+ assert_equal('http://localhost/relative/tc_relative_links.html?a=b',
68
+ page.uri.to_s)
69
+ end
70
+
71
+ def test_uri_weird
72
+ doc = Nokogiri::HTML::Document.new
73
+
74
+ node = Nokogiri::XML::Node.new('foo', doc)
75
+ node['href'] = 'http://foo.bar/ baz'
76
+
77
+ link = Mechanize::Page::Link.new(node, nil, nil)
78
+
79
+ assert_equal 'http://foo.bar/%20baz', link.uri.to_s
80
+ end
81
+
82
+ end
83
+
@@ -0,0 +1,147 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'helper'
3
+ require 'cgi'
4
+
5
+ # tests for Page encoding and charset and parsing
6
+
7
+ class TestMechanizePageEncoding < Test::Unit::TestCase
8
+
9
+ MECH_ASCII_ENCODING = Mechanize::Util::NEW_RUBY_ENCODING ? 'US-ASCII' : 'ISO-8859-1'
10
+
11
+ def setup
12
+ @agent = Mechanize.new
13
+ @uri = URI('http://localhost/')
14
+ @response_headers = { 'content-type' => 'text/html' }
15
+ @body = '<title>hi</title>'
16
+ end
17
+
18
+ def util_page body = @body, headers = @response_headers
19
+ body.force_encoding Encoding::BINARY if body.respond_to? :force_encoding
20
+ Mechanize::Page.new @uri, headers, body, 200, @agent
21
+ end
22
+
23
+ def test_page_charset
24
+ charset = Mechanize::Page.charset 'text/html;charset=vAlue'
25
+ assert_equal 'vAlue', charset
26
+ end
27
+
28
+ def test_page_charset_upcase
29
+ charset = Mechanize::Page.charset 'TEXT/HTML;CHARSET=UTF-8'
30
+ assert_equal 'UTF-8', charset
31
+ end
32
+
33
+ def test_page_semicolon
34
+ charset = Mechanize::Page.charset 'text/html;charset=UTF-8;'
35
+ assert_equal 'UTF-8', charset
36
+ end
37
+
38
+ def test_page_charset_no_chaset_token
39
+ charset = Mechanize::Page.charset 'text/html'
40
+ assert_nil charset
41
+ end
42
+
43
+ def test_page_charset_returns_nil_when_charset_says_none
44
+ charset = Mechanize::Page.charset 'text/html;charset=none'
45
+
46
+ assert_nil charset
47
+ end
48
+
49
+ def test_page_charset_multiple
50
+ charset = Mechanize::Page.charset 'text/html;charset=111;charset=222'
51
+
52
+ assert_equal '111', charset
53
+ end
54
+
55
+ def test_page_response_header_charset
56
+ headers = {'content-type' => 'text/html;charset=HEADER'}
57
+ charsets = Mechanize::Page.response_header_charset(headers)
58
+
59
+ assert_equal ['HEADER'], charsets
60
+ end
61
+
62
+ def test_page_response_header_charset_no_token
63
+ headers = {'content-type' => 'text/html'}
64
+ charsets = Mechanize::Page.response_header_charset(headers)
65
+
66
+ assert_equal [], charsets
67
+
68
+ headers = {'X-My-Header' => 'hello'}
69
+ charsets = Mechanize::Page.response_header_charset(headers)
70
+
71
+ assert_equal [], charsets
72
+ end
73
+
74
+ def test_response_header_charset
75
+ page = util_page nil, {'content-type' => 'text/html;charset=HEADER'}
76
+
77
+ assert_equal ['HEADER'], page.response_header_charset
78
+ end
79
+
80
+ def test_page_meta_charset
81
+ body = '<meta http-equiv="content-type" content="text/html;charset=META">'
82
+ charsets = Mechanize::Page.meta_charset(body)
83
+
84
+ assert_equal ['META'], charsets
85
+ end
86
+
87
+ def test_page_meta_charset_is_empty_when_no_charset_meta
88
+ body = '<meta http-equiv="refresh" content="5; url=index.html">'
89
+ charsets = Mechanize::Page.meta_charset(body)
90
+ assert_equal [], charsets
91
+ end
92
+
93
+ def test_meta_charset
94
+ body = '<meta http-equiv="content-type" content="text/html;charset=META">'
95
+ page = util_page body
96
+
97
+ assert_equal ['META'], page.meta_charset
98
+ end
99
+
100
+ def test_detected_encoding
101
+ page = util_page
102
+
103
+ assert_equal MECH_ASCII_ENCODING, page.detected_encoding
104
+ end
105
+
106
+ def test_encodings
107
+ response = {'content-type' => 'text/html;charset=HEADER'}
108
+ body = '<meta http-equiv="content-type" content="text/html;charset=META">'
109
+ @agent.default_encoding = 'DEFAULT'
110
+ page = util_page body, response
111
+
112
+ assert_equal true, page.encodings.include?('HEADER')
113
+ assert_equal true, page.encodings.include?('META')
114
+ assert_equal true, page.encodings.include?(MECH_ASCII_ENCODING)
115
+ assert_equal true, page.encodings.include?('DEFAULT')
116
+ end
117
+
118
+ def test_parser_with_default_encoding
119
+ # pre test
120
+ assert_equal false, util_page.encodings.include?('Windows-1252')
121
+
122
+ @agent.default_encoding = 'Windows-1252'
123
+ page = util_page
124
+
125
+ assert_equal true, page.encodings.include?('Windows-1252')
126
+ end
127
+
128
+ def test_parser_force_default_encoding
129
+ @agent.default_encoding = 'Windows-1252'
130
+ @agent.force_default_encoding = true
131
+ page = util_page
132
+
133
+ assert page.encodings.include? 'Windows-1252'
134
+ end
135
+
136
+ def test_parser_encoding_equals_overwrites_force_default_encoding
137
+ @agent.default_encoding = 'Windows-1252'
138
+ @agent.force_default_encoding = true
139
+ page = util_page
140
+
141
+ assert_equal 'Windows-1252', page.encoding
142
+
143
+ page.encoding = 'ISO-8859-2'
144
+
145
+ assert_equal 'ISO-8859-2', page.encoding
146
+ end
147
+ end
@@ -0,0 +1,379 @@
1
+ # coding: utf-8
2
+
3
+ require 'helper'
4
+ require 'cgi'
5
+
6
+ class TestMechanizePage < Test::Unit::TestCase
7
+
8
+ WINDOWS_1255 = <<-HTML
9
+ <meta http-equiv="content-type" content="text/html; charset=windows-1255">
10
+ <title>hi</title>
11
+ HTML
12
+
13
+ BAD = <<-HTML
14
+ <meta http-equiv="content-type" content="text/html; charset=windows-1255">
15
+ <title>Bia\xB3ystok</title>
16
+ HTML
17
+ BAD.force_encoding Encoding::BINARY if defined? Encoding
18
+
19
+ SJIS_TITLE = "\x83\x65\x83\x58\x83\x67"
20
+
21
+ SJIS_AFTER_TITLE = <<-HTML
22
+ <title>#{SJIS_TITLE}</title>
23
+ <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
24
+ HTML
25
+
26
+ SJIS_AFTER_TITLE.force_encoding Encoding::BINARY if defined? Encoding
27
+
28
+ SJIS_BAD_AFTER_TITLE = <<-HTML
29
+ <title>#{SJIS_TITLE}</title>
30
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
31
+ HTML
32
+
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
+ @agent = Mechanize.new
45
+ @uri = URI('http://example')
46
+ @res = { 'content-type' => 'text/html' }
47
+ @body = '<title>hi</title>'
48
+ end
49
+
50
+ def util_page body = @body, res = @res
51
+ body.force_encoding Encoding::BINARY if body.respond_to? :force_encoding
52
+ Mechanize::Page.new @uri, res, body, 200, @agent
53
+ end
54
+
55
+ def test_initialize_supported_content_type
56
+ page = Mechanize::Page.new nil, 'content-type' => 'application/xhtml+xml'
57
+ assert page
58
+ assert_equal 'application/xhtml+xml', page.content_type
59
+
60
+ page = Mechanize::Page.new nil, 'content-type' => 'text/html'
61
+ assert page
62
+ assert_equal 'text/html', page.content_type
63
+
64
+ page = Mechanize::Page.new nil, 'content-type' => 'application/xhtml+xml;charset=utf-8'
65
+ assert page
66
+ assert_equal 'application/xhtml+xml;charset=utf-8', page.content_type
67
+
68
+ page = Mechanize::Page.new nil, 'content-type' => 'text/html;charset=utf-8'
69
+ assert page
70
+ assert_equal 'text/html;charset=utf-8', page.content_type
71
+ end
72
+
73
+ def test_initialize_unsupported_content_type
74
+ e = assert_raises Mechanize::ContentTypeError do
75
+ Mechanize::Page.new nil, 'content-type' => 'text/plain'
76
+ end
77
+
78
+ assert_equal 'text/plain', e.content_type
79
+
80
+ e = assert_raises Mechanize::ContentTypeError do
81
+ Mechanize::Page.new nil, 'content-type' => 'text/plain;charset=utf-8'
82
+ end
83
+
84
+ assert_equal 'text/plain;charset=utf-8', e.content_type
85
+ end
86
+
87
+ def test_override_content_type
88
+ page = Mechanize::Page.new nil, {'content-type' => 'text/html'}, WINDOWS_1255
89
+ assert page
90
+ assert_equal 'text/html; charset=windows-1255', page.content_type
91
+ end
92
+
93
+ def test_canonical_uri
94
+ page = @agent.get("http://localhost/canonical_uri.html")
95
+ assert_equal(URI("http://localhost/canonical_uri"), page.canonical_uri)
96
+
97
+ page = @agent.get("http://localhost/file_upload.html")
98
+ assert_equal(nil, page.canonical_uri)
99
+ end
100
+
101
+ def test_canonical_uri_unescaped
102
+ page = util_page <<-BODY
103
+ <head>
104
+ <link rel="canonical" href="http://example/white space"/>
105
+ </head>
106
+ BODY
107
+
108
+ assert_equal @uri + '/white%20space', page.canonical_uri
109
+ end
110
+
111
+ def test_charset_from_content_type
112
+ charset = Mechanize::Page.__send__ :charset_from_content_type, 'text/html;charset=UTF-8'
113
+
114
+ assert_equal 'UTF-8', charset
115
+ end
116
+
117
+ def test_charset_from_bad_content_type
118
+ charset = Mechanize::Page.__send__ :charset_from_content_type, 'text/html'
119
+
120
+ assert_nil charset
121
+ end
122
+
123
+ def test_encoding
124
+ page = util_page WINDOWS_1255
125
+
126
+ assert_equal 'windows-1255', page.encoding
127
+ end
128
+
129
+ def test_encoding_charset_after_title
130
+ page = util_page SJIS_AFTER_TITLE
131
+
132
+ assert_equal false, page.encoding_error?
133
+
134
+ assert_equal 'Shift_JIS', page.encoding
135
+ end
136
+
137
+ def test_encoding_charset_after_title_bad
138
+ page = util_page UTF8
139
+
140
+ assert_equal false, page.encoding_error?
141
+
142
+ assert_equal 'UTF-8', page.encoding
143
+ end
144
+
145
+ def test_encoding_charset_after_title_double_bad
146
+ page = util_page SJIS_BAD_AFTER_TITLE
147
+
148
+ assert_equal false, page.encoding_error?
149
+
150
+ assert_equal 'SHIFT_JIS', page.encoding
151
+ end
152
+
153
+ def test_encoding_charset_bad
154
+ page = util_page "<title>#{UTF8_TITLE}</title>"
155
+ page.encodings.replace %w[
156
+ UTF-8
157
+ Shift_JIS
158
+ ]
159
+
160
+ assert_equal false, page.encoding_error?
161
+
162
+ assert_equal 'UTF-8', page.encoding
163
+ end
164
+
165
+ def test_encoding_meta_charset
166
+ page = util_page "<meta charset='UTF-8'>"
167
+
168
+ assert_equal 'UTF-8', page.encoding
169
+ end
170
+
171
+ def test_encoding_equals
172
+ page = util_page
173
+ page.meta_refresh
174
+ assert page.instance_variable_get(:@meta_refresh)
175
+
176
+ page.encoding = 'UTF-8'
177
+
178
+ assert_nil page.instance_variable_get(:@meta_refresh)
179
+
180
+ assert_equal 'UTF-8', page.encoding
181
+ assert_equal 'UTF-8', page.parser.encoding
182
+ end
183
+
184
+ def test_page_encoding_error?
185
+ page = util_page
186
+ page.parser.errors.clear
187
+ assert_equal false, page.encoding_error?
188
+ end
189
+
190
+ def test_detect_libxml2error_indicate_encoding
191
+ page = util_page
192
+ page.parser.errors.clear
193
+
194
+ # error in libxml2-2.7.8/parser.c, HTMLparser.c or parserInternals.c
195
+ page.parser.errors = [ENCODING_ERROR_CLASS.new("Input is not proper UTF-8, indicate encoding !\n")]
196
+ assert_equal true, page.encoding_error?
197
+ end
198
+
199
+ def test_detect_libxml2error_invalid_char
200
+ page = util_page
201
+ page.parser.errors.clear
202
+
203
+ # error in libxml2-2.7.8/HTMLparser.c
204
+ page.parser.errors = [ENCODING_ERROR_CLASS.new("Invalid char in CDATA 0x%X\n")]
205
+ assert_equal true, page.encoding_error?
206
+ end
207
+
208
+ def test_detect_libxml2error_input_conversion_failed
209
+ page = util_page
210
+ page.parser.errors.clear
211
+
212
+ # error in libxml2-2.7.8/encoding.c
213
+ page.parser.errors = [ENCODING_ERROR_CLASS.new("input conversion failed due to input error\n")]
214
+ assert_equal true, page.encoding_error?
215
+ end
216
+
217
+ def test_detect_libxml2error_which_unsupported_by_mechanize
218
+ page = util_page
219
+ page.parser.errors.clear
220
+
221
+ # error in libxml2-2.7.8/HTMLparser.c
222
+ page.parser.errors = [ENCODING_ERROR_CLASS.new("encoder error\n")]
223
+ assert_equal false, page.encoding_error?
224
+ end
225
+
226
+ def test_encoding_equals_before_parser
227
+ # document has a bad encoding information - windows-1255
228
+ page = util_page BAD
229
+
230
+ # encoding is wrong, so user wants to force ISO-8859-2
231
+ page.encoding = 'ISO-8859-2'
232
+
233
+ assert_equal false, page.encoding_error?
234
+ assert_equal 'ISO-8859-2', page.encoding
235
+ assert_equal 'ISO-8859-2', page.parser.encoding
236
+ end
237
+
238
+ def test_encoding_equals_after_parser
239
+ # document has a bad encoding information - windows-1255
240
+ page = util_page BAD
241
+ page.parser
242
+
243
+ # autodetection sets encoding to windows-1255
244
+ assert_equal 'windows-1255', page.encoding
245
+ # believe in yourself, not machine
246
+ assert_equal false, page.encoding_error?
247
+
248
+ # encoding is wrong, so user wants to force ISO-8859-2
249
+ page.encoding = 'ISO-8859-2'
250
+
251
+ assert_equal false, page.encoding_error?
252
+ assert_equal 'ISO-8859-2', page.encoding
253
+ assert_equal 'ISO-8859-2', page.parser.encoding
254
+ end
255
+
256
+ def test_frames_with
257
+ page = @agent.get("http://localhost/frame_test.html")
258
+ assert_equal(3, page.frames.size)
259
+
260
+ find_orig = page.frames.find_all { |f| f.name == 'frame1' }
261
+
262
+ find1 = page.frames_with(:name => 'frame1')
263
+
264
+ find_orig.zip(find1).each { |a,b|
265
+ assert_equal(a, b)
266
+ }
267
+ end
268
+
269
+ def test_links_with_dom_id
270
+ page = @agent.get("http://localhost/tc_links.html")
271
+ link = page.links_with(:dom_id => 'bold_aaron_link')
272
+ link_by_id = page.links_with(:id => 'bold_aaron_link')
273
+ assert_equal(1, link.length)
274
+ assert_equal('Aaron Patterson', link.first.text)
275
+ assert_equal(link, link_by_id)
276
+ end
277
+
278
+ def test_link_with_encoded_space
279
+ page = @agent.get("http://localhost/tc_links.html")
280
+ link = page.link_with(:text => 'encoded space')
281
+ page = @agent.click link
282
+ end
283
+
284
+ def test_link_with_space
285
+ page = @agent.get("http://localhost/tc_links.html")
286
+ link = page.link_with(:text => 'not encoded space')
287
+ page = @agent.click link
288
+ end
289
+
290
+ def test_link_with_unusual_characters
291
+ page = @agent.get("http://localhost/tc_links.html")
292
+ link = page.link_with(:text => 'unusual characters')
293
+ assert_nothing_raised { @agent.click link }
294
+ end
295
+
296
+ def test_links
297
+ page = @agent.get("http://localhost/find_link.html")
298
+ assert_equal(18, page.links.length)
299
+ end
300
+
301
+ def test_links_with_bold
302
+ page = @agent.get("http://localhost/tc_links.html")
303
+ link = page.links_with(:text => /Bold Dude/)
304
+ assert_equal(1, link.length)
305
+ assert_equal('Bold Dude', link.first.text)
306
+ assert_equal [], link.first.rel
307
+ assert !link.first.rel?('me')
308
+ assert !link.first.rel?('nofollow')
309
+
310
+ link = page.links_with(:text => 'Aaron James Patterson')
311
+ assert_equal(1, link.length)
312
+ assert_equal('Aaron James Patterson', link.first.text)
313
+ assert_equal ['me'], link.first.rel
314
+ assert link.first.rel?('me')
315
+ assert !link.first.rel?('nofollow')
316
+
317
+ link = page.links_with(:text => 'Aaron Patterson')
318
+ assert_equal(1, link.length)
319
+ assert_equal('Aaron Patterson', link.first.text)
320
+ assert_equal ['me', 'nofollow'], link.first.rel
321
+ assert link.first.rel?('me')
322
+ assert link.first.rel?('nofollow')
323
+
324
+ link = page.links_with(:text => 'Ruby Rocks!')
325
+ assert_equal(1, link.length)
326
+ assert_equal('Ruby Rocks!', link.first.text)
327
+ end
328
+
329
+ def test_meta_refresh
330
+ page = @agent.get("http://localhost/find_link.html")
331
+ assert_equal(3, page.meta_refresh.length)
332
+ assert_equal(%w{
333
+ http://www.drphil.com/
334
+ http://www.upcase.com/
335
+ http://tenderlovemaking.com/ }.sort,
336
+ page.meta_refresh.map { |x| x.href.downcase }.sort)
337
+ end
338
+
339
+ def test_title
340
+ page = util_page
341
+
342
+ assert_equal('hi', page.title)
343
+ end
344
+
345
+ def test_title_none
346
+ page = util_page '' # invalid HTML
347
+
348
+ assert_equal(nil, page.title)
349
+ end
350
+
351
+ def test_page_decoded_with_charset
352
+ page = util_page @body, 'content-type' => 'text/html; charset=EUC-JP'
353
+
354
+ assert_equal 'EUC-JP', page.encoding
355
+ assert_equal 'EUC-JP', page.parser.encoding
356
+ end
357
+
358
+ def test_form
359
+ page = @agent.get("http://localhost/tc_form_action.html")
360
+
361
+ form = page.form(:name => 'post_form1')
362
+ assert form
363
+ yielded = false
364
+
365
+ form = page.form(:name => 'post_form1') { |f|
366
+ yielded = true
367
+ assert f
368
+ assert_equal(form, f)
369
+ }
370
+
371
+ assert yielded
372
+
373
+ form_by_action = page.form(:action => '/form_post?a=b&b=c')
374
+ assert form_by_action
375
+ assert_equal(form, form_by_action)
376
+ end
377
+
378
+ end
379
+