mechanize-ntlm 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (171) hide show
  1. data/CHANGELOG.rdoc +480 -0
  2. data/EXAMPLES.rdoc +171 -0
  3. data/FAQ.rdoc +11 -0
  4. data/GUIDE.rdoc +122 -0
  5. data/LICENSE.rdoc +340 -0
  6. data/Manifest.txt +169 -0
  7. data/README.rdoc +60 -0
  8. data/Rakefile +44 -0
  9. data/examples/flickr_upload.rb +23 -0
  10. data/examples/mech-dump.rb +7 -0
  11. data/examples/proxy_req.rb +9 -0
  12. data/examples/rubyforge.rb +21 -0
  13. data/examples/spider.rb +11 -0
  14. data/lib/mechanize-ntlm.rb +7 -0
  15. data/lib/www/mechanize.rb +582 -0
  16. data/lib/www/mechanize/chain.rb +34 -0
  17. data/lib/www/mechanize/chain/auth_headers.rb +82 -0
  18. data/lib/www/mechanize/chain/body_decoding_handler.rb +43 -0
  19. data/lib/www/mechanize/chain/connection_resolver.rb +78 -0
  20. data/lib/www/mechanize/chain/custom_headers.rb +23 -0
  21. data/lib/www/mechanize/chain/handler.rb +9 -0
  22. data/lib/www/mechanize/chain/header_resolver.rb +48 -0
  23. data/lib/www/mechanize/chain/parameter_resolver.rb +23 -0
  24. data/lib/www/mechanize/chain/post_connect_hook.rb +0 -0
  25. data/lib/www/mechanize/chain/pre_connect_hook.rb +22 -0
  26. data/lib/www/mechanize/chain/request_resolver.rb +32 -0
  27. data/lib/www/mechanize/chain/response_body_parser.rb +40 -0
  28. data/lib/www/mechanize/chain/response_header_handler.rb +51 -0
  29. data/lib/www/mechanize/chain/response_reader.rb +41 -0
  30. data/lib/www/mechanize/chain/ssl_resolver.rb +36 -0
  31. data/lib/www/mechanize/chain/uri_resolver.rb +73 -0
  32. data/lib/www/mechanize/content_type_error.rb +16 -0
  33. data/lib/www/mechanize/cookie.rb +72 -0
  34. data/lib/www/mechanize/cookie_jar.rb +191 -0
  35. data/lib/www/mechanize/file.rb +73 -0
  36. data/lib/www/mechanize/file_response.rb +62 -0
  37. data/lib/www/mechanize/file_saver.rb +39 -0
  38. data/lib/www/mechanize/form.rb +359 -0
  39. data/lib/www/mechanize/form/button.rb +8 -0
  40. data/lib/www/mechanize/form/check_box.rb +13 -0
  41. data/lib/www/mechanize/form/field.rb +28 -0
  42. data/lib/www/mechanize/form/file_upload.rb +24 -0
  43. data/lib/www/mechanize/form/image_button.rb +23 -0
  44. data/lib/www/mechanize/form/multi_select_list.rb +69 -0
  45. data/lib/www/mechanize/form/option.rb +51 -0
  46. data/lib/www/mechanize/form/radio_button.rb +38 -0
  47. data/lib/www/mechanize/form/select_list.rb +45 -0
  48. data/lib/www/mechanize/headers.rb +12 -0
  49. data/lib/www/mechanize/history.rb +67 -0
  50. data/lib/www/mechanize/inspect.rb +90 -0
  51. data/lib/www/mechanize/monkey_patch.rb +37 -0
  52. data/lib/www/mechanize/page.rb +145 -0
  53. data/lib/www/mechanize/page/base.rb +10 -0
  54. data/lib/www/mechanize/page/frame.rb +22 -0
  55. data/lib/www/mechanize/page/link.rb +50 -0
  56. data/lib/www/mechanize/page/meta.rb +10 -0
  57. data/lib/www/mechanize/pluggable_parsers.rb +103 -0
  58. data/lib/www/mechanize/redirect_limit_reached_error.rb +18 -0
  59. data/lib/www/mechanize/redirect_not_get_or_head_error.rb +20 -0
  60. data/lib/www/mechanize/response_code_error.rb +25 -0
  61. data/lib/www/mechanize/unsupported_scheme_error.rb +10 -0
  62. data/lib/www/mechanize/util.rb +76 -0
  63. data/lib/www/ntlm-http/lib/net/ntlm_http.rb +854 -0
  64. data/mechanize.gemspec +24 -0
  65. data/test/chain/test_argument_validator.rb +14 -0
  66. data/test/chain/test_custom_headers.rb +18 -0
  67. data/test/chain/test_parameter_resolver.rb +35 -0
  68. data/test/chain/test_request_resolver.rb +29 -0
  69. data/test/chain/test_response_reader.rb +24 -0
  70. data/test/data/htpasswd +1 -0
  71. data/test/data/server.crt +16 -0
  72. data/test/data/server.csr +12 -0
  73. data/test/data/server.key +15 -0
  74. data/test/data/server.pem +15 -0
  75. data/test/helper.rb +127 -0
  76. data/test/htdocs/alt_text.html +10 -0
  77. data/test/htdocs/bad_form_test.html +9 -0
  78. data/test/htdocs/button.jpg +0 -0
  79. data/test/htdocs/empty_form.html +6 -0
  80. data/test/htdocs/file_upload.html +26 -0
  81. data/test/htdocs/find_link.html +41 -0
  82. data/test/htdocs/form_multi_select.html +16 -0
  83. data/test/htdocs/form_multival.html +37 -0
  84. data/test/htdocs/form_no_action.html +18 -0
  85. data/test/htdocs/form_no_input_name.html +16 -0
  86. data/test/htdocs/form_select.html +16 -0
  87. data/test/htdocs/form_select_all.html +16 -0
  88. data/test/htdocs/form_select_none.html +17 -0
  89. data/test/htdocs/form_select_noopts.html +10 -0
  90. data/test/htdocs/form_set_fields.html +14 -0
  91. data/test/htdocs/form_test.html +188 -0
  92. data/test/htdocs/frame_test.html +30 -0
  93. data/test/htdocs/google.html +13 -0
  94. data/test/htdocs/iframe_test.html +16 -0
  95. data/test/htdocs/index.html +6 -0
  96. data/test/htdocs/link with space.html +5 -0
  97. data/test/htdocs/meta_cookie.html +11 -0
  98. data/test/htdocs/no_title_test.html +6 -0
  99. data/test/htdocs/relative/tc_relative_links.html +21 -0
  100. data/test/htdocs/tc_bad_links.html +5 -0
  101. data/test/htdocs/tc_base_link.html +8 -0
  102. data/test/htdocs/tc_blank_form.html +11 -0
  103. data/test/htdocs/tc_checkboxes.html +19 -0
  104. data/test/htdocs/tc_encoded_links.html +5 -0
  105. data/test/htdocs/tc_follow_meta.html +8 -0
  106. data/test/htdocs/tc_form_action.html +48 -0
  107. data/test/htdocs/tc_links.html +18 -0
  108. data/test/htdocs/tc_no_attributes.html +16 -0
  109. data/test/htdocs/tc_pretty_print.html +17 -0
  110. data/test/htdocs/tc_radiobuttons.html +17 -0
  111. data/test/htdocs/tc_referer.html +10 -0
  112. data/test/htdocs/tc_relative_links.html +19 -0
  113. data/test/htdocs/tc_textarea.html +23 -0
  114. data/test/htdocs/unusual______.html +5 -0
  115. data/test/servlets.rb +339 -0
  116. data/test/ssl_server.rb +48 -0
  117. data/test/test_authenticate.rb +71 -0
  118. data/test/test_bad_links.rb +25 -0
  119. data/test/test_blank_form.rb +16 -0
  120. data/test/test_checkboxes.rb +61 -0
  121. data/test/test_content_type.rb +13 -0
  122. data/test/test_cookie_class.rb +338 -0
  123. data/test/test_cookie_jar.rb +343 -0
  124. data/test/test_cookies.rb +123 -0
  125. data/test/test_encoded_links.rb +20 -0
  126. data/test/test_errors.rb +49 -0
  127. data/test/test_follow_meta.rb +69 -0
  128. data/test/test_form_action.rb +44 -0
  129. data/test/test_form_as_hash.rb +61 -0
  130. data/test/test_form_button.rb +38 -0
  131. data/test/test_form_no_inputname.rb +15 -0
  132. data/test/test_forms.rb +575 -0
  133. data/test/test_frames.rb +25 -0
  134. data/test/test_get_headers.rb +52 -0
  135. data/test/test_gzipping.rb +22 -0
  136. data/test/test_hash_api.rb +45 -0
  137. data/test/test_history.rb +142 -0
  138. data/test/test_history_added.rb +16 -0
  139. data/test/test_html_unscape_forms.rb +39 -0
  140. data/test/test_if_modified_since.rb +20 -0
  141. data/test/test_keep_alive.rb +31 -0
  142. data/test/test_links.rb +120 -0
  143. data/test/test_mech.rb +259 -0
  144. data/test/test_mechanize_file.rb +47 -0
  145. data/test/test_multi_select.rb +106 -0
  146. data/test/test_no_attributes.rb +13 -0
  147. data/test/test_option.rb +18 -0
  148. data/test/test_page.rb +67 -0
  149. data/test/test_pluggable_parser.rb +145 -0
  150. data/test/test_post_form.rb +34 -0
  151. data/test/test_pretty_print.rb +22 -0
  152. data/test/test_radiobutton.rb +75 -0
  153. data/test/test_redirect_limit_reached.rb +41 -0
  154. data/test/test_redirect_verb_handling.rb +45 -0
  155. data/test/test_referer.rb +39 -0
  156. data/test/test_relative_links.rb +40 -0
  157. data/test/test_request.rb +13 -0
  158. data/test/test_response_code.rb +52 -0
  159. data/test/test_save_file.rb +48 -0
  160. data/test/test_scheme.rb +48 -0
  161. data/test/test_select.rb +106 -0
  162. data/test/test_select_all.rb +15 -0
  163. data/test/test_select_none.rb +15 -0
  164. data/test/test_select_noopts.rb +16 -0
  165. data/test/test_set_fields.rb +44 -0
  166. data/test/test_ssl_server.rb +20 -0
  167. data/test/test_subclass.rb +14 -0
  168. data/test/test_textarea.rb +45 -0
  169. data/test/test_upload.rb +109 -0
  170. data/test/test_verbs.rb +25 -0
  171. metadata +284 -0
@@ -0,0 +1,13 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
2
+
3
+ class RequestTest < Test::Unit::TestCase
4
+ def setup
5
+ @agent = WWW::Mechanize.new
6
+ end
7
+
8
+ def test_uri_is_not_polluted
9
+ uri = URI.parse('http://localhost/')
10
+ @agent.get(uri, {'q' => 'Ruby'})
11
+ assert_equal 'http://localhost/', uri.to_s
12
+ end
13
+ end
@@ -0,0 +1,52 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
2
+
3
+ class ResponseCodeMechTest < Test::Unit::TestCase
4
+ def setup
5
+ @agent = WWW::Mechanize.new
6
+ end
7
+
8
+ def test_eof_error_loop
9
+ assert_raises(EOFError) {
10
+ @agent.get("http://localhost/http_headers?Content-Length=300")
11
+ }
12
+ end
13
+
14
+ def test_redirect
15
+ @agent.get("http://localhost/response_code?code=300")
16
+ assert_equal("http://localhost/index.html",
17
+ @agent.current_page.uri.to_s)
18
+
19
+ @agent.get("http://localhost/response_code?code=301")
20
+ assert_equal("http://localhost/index.html",
21
+ @agent.current_page.uri.to_s)
22
+
23
+ @agent.get("http://localhost/response_code?code=302")
24
+ assert_equal("http://localhost/index.html",
25
+ @agent.current_page.uri.to_s)
26
+
27
+ @agent.get("http://localhost/response_code?code=303")
28
+ assert_equal("http://localhost/index.html",
29
+ @agent.current_page.uri.to_s)
30
+
31
+ @agent.get("http://localhost/response_code?code=307")
32
+ assert_equal("http://localhost/index.html",
33
+ @agent.current_page.uri.to_s)
34
+ end
35
+
36
+ def test_do_not_follow_redirect
37
+ @agent.redirect_ok = false
38
+
39
+ @agent.get("http://localhost/response_code?code=302")
40
+ assert_equal("http://localhost/response_code?code=302",
41
+ @agent.current_page.uri.to_s)
42
+ end
43
+
44
+ def test_error
45
+ @agent = WWW::Mechanize.new
46
+ begin
47
+ @agent.get("http://localhost/response_code?code=500")
48
+ rescue WWW::Mechanize::ResponseCodeError => err
49
+ assert_equal("500", err.response_code)
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,48 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
2
+
3
+ class TestSaveFile < Test::Unit::TestCase
4
+ def setup
5
+ @agent = WWW::Mechanize.new
6
+ end
7
+
8
+ def test_save_file
9
+ page = @agent.get('http://localhost:2000/form_no_action.html')
10
+ length = page.response['Content-Length']
11
+ page.save_as("test.html")
12
+ file_length = nil
13
+ File.open("test.html", "r") { |f| file_length = f.read.length }
14
+ FileUtils.rm("test.html")
15
+ assert_equal(length.to_i, file_length)
16
+ end
17
+
18
+ def test_save_file_default
19
+ page = WWW::Mechanize::File.new(
20
+ URI.parse('http://localhost/test.html'),
21
+ {},
22
+ "hello"
23
+ )
24
+ page.save
25
+ assert(File.exists?('test.html'))
26
+ page.save
27
+ assert(File.exists?('test.html.1'))
28
+ page.save
29
+ assert(File.exists?('test.html.2'))
30
+ FileUtils.rm("test.html")
31
+ FileUtils.rm("test.html.1")
32
+ FileUtils.rm("test.html.2")
33
+ end
34
+
35
+ def test_save_file_default_with_dots
36
+ page = WWW::Mechanize::File.new(
37
+ URI.parse('http://localhost/../test.html'),
38
+ {},
39
+ "hello"
40
+ )
41
+ page.save
42
+ assert(File.exists?('test.html'))
43
+ page.save
44
+ assert(File.exists?('test.html.1'))
45
+ FileUtils.rm("test.html")
46
+ FileUtils.rm("test.html.1")
47
+ end
48
+ end
@@ -0,0 +1,48 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
2
+
3
+ class SchemeTest < Test::Unit::TestCase
4
+ def setup
5
+ @agent = WWW::Mechanize.new
6
+ @agent.log = Class.new(Object) do
7
+ def method_missing(*args)
8
+ end
9
+ end.new
10
+ end
11
+
12
+ def test_file_scheme
13
+ f = File.expand_path(__FILE__)
14
+ page = @agent.get("file://#{f}")
15
+ assert_equal(File.read(f), page.body)
16
+ end
17
+
18
+ def test_file_scheme_parses_html
19
+ f = File.expand_path(
20
+ File.join(File.dirname(__FILE__), "htdocs", 'google.html'))
21
+ page = @agent.get("file://#{f}")
22
+ assert_equal(File.read(f), page.body)
23
+ assert_kind_of(WWW::Mechanize::Page, page)
24
+ end
25
+
26
+ def test_file_scheme_supports_directories
27
+ f = File.expand_path(File.join(File.dirname(__FILE__), "htdocs"))
28
+ page = @agent.get("file://#{f}")
29
+ assert_equal(Dir[File.join(f, '*')].length, page.links.length)
30
+ assert_kind_of(WWW::Mechanize::Page, page)
31
+ end
32
+
33
+ def test_click_file_link
34
+ f = File.expand_path(File.join(File.dirname(__FILE__), "htdocs"))
35
+ page = @agent.get("file://#{f}")
36
+ link = page.links.find { |l| l.text =~ /tc_follow_meta/ }
37
+ assert_not_nil(link)
38
+ path = URI.parse(link.href).path
39
+
40
+ page = link.click
41
+ assert_equal(File.read(path), page.body)
42
+
43
+ link = page.meta.first
44
+ assert_not_nil(link)
45
+ page = @agent.click(link)
46
+ assert_equal("http://localhost/index.html", @agent.history.last.uri.to_s)
47
+ end
48
+ end
@@ -0,0 +1,106 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
2
+
3
+ class SelectTest < Test::Unit::TestCase
4
+ def setup
5
+ @agent = WWW::Mechanize.new
6
+ @page = @agent.get("http://localhost/form_select.html")
7
+ @form = @page.forms.first
8
+ end
9
+
10
+ def test_select_none
11
+ @form.fields_with(:name => 'list').first.select_none
12
+ assert_equal('1', @form.list)
13
+ end
14
+
15
+ def test_select_all
16
+ @form.fields_with(:name => 'list').first.select_all
17
+ assert_equal('6', @form.list)
18
+ end
19
+
20
+ def test_correct_class
21
+ assert_instance_of(WWW::Mechanize::Form::SelectList,
22
+ @form.field_with(:name => 'list'))
23
+ end
24
+
25
+ def test_click_all
26
+ @form.field_with(:name => 'list').options.each { |o| o.click }
27
+ option_list = @form.field_with(:name => 'list').options
28
+ assert_not_nil(option_list)
29
+ assert_equal(6, option_list.length)
30
+ assert_equal(option_list.last.value, @form.list)
31
+ page = @agent.submit(@form)
32
+ assert_equal(1, page.links.length)
33
+ assert_equal(1, page.links_with(:text => "list:#{option_list.last}").length)
34
+ end
35
+
36
+ def test_select_default
37
+ assert_equal("2", @form.list)
38
+ page = @agent.submit(@form)
39
+ assert_equal(1, page.links.length)
40
+ assert_equal(1, page.links_with(:text => 'list:2').length)
41
+ end
42
+
43
+ def test_select_one
44
+ @form.list = 'Aaron'
45
+ assert_equal('Aaron', @form.list)
46
+ page = @agent.submit(@form)
47
+ assert_equal(1, page.links.length)
48
+ assert_equal('list:Aaron', page.links.first.text)
49
+ end
50
+
51
+ def test_select_two
52
+ @form.list = ['1', 'Aaron']
53
+ assert_equal('1', @form.list)
54
+ page = @agent.submit(@form)
55
+ assert_equal(1, page.links.length)
56
+ assert_equal(1, page.links_with(:text => 'list:1').length)
57
+ end
58
+
59
+ def test_select_three
60
+ @form.list = ['1', '2', '3']
61
+ assert_equal('1', @form.list)
62
+ page = @agent.submit(@form)
63
+ assert_equal(1, page.links.length)
64
+ assert_equal(1, page.links_with(:text => 'list:1').length)
65
+ end
66
+
67
+ def test_select_three_twice
68
+ @form.list = ['1', '2', '3']
69
+ @form.list = ['1', '2', '3']
70
+ assert_equal('1', @form.list)
71
+ page = @agent.submit(@form)
72
+ assert_equal(1, page.links.length)
73
+ assert_equal(1, page.links_with(:text => 'list:1').length)
74
+ end
75
+
76
+ def test_select_with_empty_value
77
+ list = @form.field_with(:name => 'list')
78
+ list.options.last.instance_variable_set(:@value, '')
79
+ list.options.last.tick
80
+ page = @agent.submit(@form)
81
+ assert_equal(1, page.links.length)
82
+ assert_equal(1, page.links_with(:text => 'list:').length)
83
+ end
84
+
85
+ def test_select_with_click
86
+ @form.list = ['1', 'Aaron']
87
+ @form.field_with(:name => 'list').options[3].tick
88
+ assert_equal('4', @form.list)
89
+ page = @agent.submit(@form)
90
+ assert_equal(1, page.links.length)
91
+ assert_equal(1, page.links_with(:text => 'list:4').length)
92
+ end
93
+
94
+ def test_click_twice
95
+ list = @form.field_with(:name => 'list')
96
+ list.options[0].click
97
+ assert_equal('1', @form.list)
98
+ list.options[1].click
99
+ assert_equal('2', @form.list)
100
+ list.options.last.click
101
+ assert_equal('6', @form.list)
102
+ assert_equal(1, list.selected_options.length)
103
+ list.select_all
104
+ assert_equal(1, list.selected_options.length)
105
+ end
106
+ end
@@ -0,0 +1,15 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
2
+ class SelectAllTest < Test::Unit::TestCase
3
+ def setup
4
+ @agent = WWW::Mechanize.new
5
+ @page = @agent.get("http://localhost/form_select_all.html")
6
+ @form = @page.forms.first
7
+ end
8
+
9
+ def test_select_default
10
+ assert_equal("6", @form.list)
11
+ page = @agent.submit(@form)
12
+ assert_equal(1, page.links.length)
13
+ assert_equal(1, page.links_with(:text => 'list:6').length)
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
2
+ class SelectNoneTest < Test::Unit::TestCase
3
+ def setup
4
+ @agent = WWW::Mechanize.new
5
+ @page = @agent.get("http://localhost/form_select_none.html")
6
+ @form = @page.forms.first
7
+ end
8
+
9
+ def test_select_default
10
+ assert_equal("1", @form.list)
11
+ page = @agent.submit(@form)
12
+ assert_equal(1, page.links.length)
13
+ assert_equal(1, page.links_with(:text => 'list:1').length)
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
2
+
3
+ class SelectNoOptionsTest < Test::Unit::TestCase
4
+ def setup
5
+ @agent = WWW::Mechanize.new
6
+ @page = @agent.get("http://localhost/form_select_noopts.html")
7
+ @form = @page.forms.first
8
+ end
9
+
10
+ def test_select_default
11
+ assert_not_nil(@form.field('list'))
12
+ assert_nil(@form.list)
13
+ page = @agent.submit(@form)
14
+ assert_equal(0, page.links.length)
15
+ end
16
+ end
@@ -0,0 +1,44 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
2
+
3
+ class TestSetFields < Test::Unit::TestCase
4
+ def setup
5
+ @agent = WWW::Mechanize.new
6
+ @page = @agent.get("http://localhost/form_set_fields.html")
7
+ @form = @page.forms.first
8
+ end
9
+
10
+ def test_set_no_fields
11
+ before = {}
12
+ @form.fields.each { |f| before[f.name] = f.value }
13
+ @form.set_fields
14
+ before.each { |k,v| assert_equal(v, @form.send(k)) }
15
+ end
16
+
17
+ def test_set_one_field
18
+ @form.set_fields( :gender => 'male' )
19
+ assert_equal('male', @form.gender)
20
+ end
21
+
22
+ def test_set_many_fields
23
+ @form.set_fields( :gender => 'male',
24
+ :first_name => 'Aaron',
25
+ 'green[eggs]' => 'Ham'
26
+ )
27
+ assert_equal('male', @form.gender)
28
+ assert_equal('Aaron', @form.first_name)
29
+ assert_equal('Ham', @form.fields_with(:name => 'green[eggs]').first.value)
30
+ end
31
+
32
+ def test_set_multiple_duplicate_fields
33
+ page = @agent.get("http://localhost/form_multival.html")
34
+ form = page.form('post_form')
35
+ form.set_fields( :first => { 0 => 'a', 1 => 'b' } )
36
+ assert_equal('a', form.fields_with(:name => 'first')[0].value)
37
+ assert_equal('b', form.fields_with(:name => 'first')[1].value)
38
+ end
39
+
40
+ def test_set_second_field
41
+ @form.set_fields( :first_name => ['Aaron', 1] )
42
+ assert_equal('Aaron', @form.fields_with(:name => 'first_name')[1].value)
43
+ end
44
+ end
@@ -0,0 +1,20 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
2
+
3
+ class SSLServerTest < Test::Unit::TestCase
4
+ def setup
5
+ @agent = WWW::Mechanize.new
6
+ end
7
+
8
+ def test_ssl_request
9
+ non_ssl_page = @agent.get("http://localhost/form_test.html")
10
+ ssl_page = @agent.get("https://localhost/form_test.html")
11
+ assert_equal(non_ssl_page.body.length, ssl_page.body.length)
12
+ end
13
+
14
+ def test_ssl_request_verify
15
+ non_ssl_page = @agent.get("http://localhost/form_test.html")
16
+ @agent.ca_file = 'data/server.crt'
17
+ ssl_page = @agent.get("https://localhost/form_test.html")
18
+ assert_equal(non_ssl_page.body.length, ssl_page.body.length)
19
+ end
20
+ end
@@ -0,0 +1,14 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
2
+
3
+ class TestSubclass < Test::Unit::TestCase
4
+ def setup
5
+ @agent = WWW::Mechanize.new
6
+ end
7
+
8
+ def test_send_cookie
9
+ page = @agent.get( :url => "http://localhost/send_cookies",
10
+ :headers => {'Cookie' => 'name=Aaron'} )
11
+ assert_equal(1, page.links.length)
12
+ assert_not_nil(page.links.find { |l| l.text == "name:Aaron" })
13
+ end
14
+ end
@@ -0,0 +1,45 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
2
+
3
+ class TestTextArea < Test::Unit::TestCase
4
+ def setup
5
+ @agent = WWW::Mechanize.new
6
+ @page = @agent.get("http://localhost/tc_textarea.html")
7
+ end
8
+
9
+ def test_empty_text_area
10
+ form = @page.forms_with(:name => 'form1').first
11
+ assert_equal('', form.field_with(:name => 'text1').value)
12
+ form.text1 = 'Hello World'
13
+ assert_equal('Hello World', form.field_with(:name => 'text1').value)
14
+ page = @agent.submit(form)
15
+ assert_equal(1, page.links.length)
16
+ assert_equal('text1:Hello World', page.links[0].text)
17
+ end
18
+
19
+ def test_non_empty_textfield
20
+ form = @page.forms_with(:name => 'form2').first
21
+ assert_equal('sample text', form.field_with(:name => 'text1').value)
22
+ page = @agent.submit(form)
23
+ assert_equal(1, page.links.length)
24
+ assert_equal('text1:sample text', page.links[0].text)
25
+ end
26
+
27
+ def test_multi_textfield
28
+ form = @page.form_with(:name => 'form3')
29
+ assert_equal(2, form.fields_with(:name => 'text1').length)
30
+ assert_equal('', form.fields_with(:name => 'text1')[0].value)
31
+ assert_equal('sample text', form.fields_with(:name => 'text1')[1].value)
32
+ form.text1 = 'Hello World'
33
+ assert_equal('Hello World', form.fields_with(:name => 'text1')[0].value)
34
+ assert_equal('sample text', form.fields_with(:name => 'text1')[1].value)
35
+ page = @agent.submit(form)
36
+ assert_equal(2, page.links.length)
37
+ link = page.links_with(:text => 'text1:sample text')
38
+ assert_not_nil(link)
39
+ assert_equal(1, link.length)
40
+
41
+ link = page.links_with(:text => 'text1:Hello World')
42
+ assert_not_nil(link)
43
+ assert_equal(1, link.length)
44
+ end
45
+ end