jpmobile 0.0.8 → 0.1.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. data/.gitignore +0 -3
  2. data/{spec/spec.opts → .rspec} +1 -2
  3. data/README.rdoc +122 -128
  4. data/Rakefile +23 -101
  5. data/VERSION.yml +4 -3
  6. data/jpmobile.gemspec +130 -182
  7. data/lib/jpmobile.rb +37 -24
  8. data/lib/jpmobile/docomo_guid.rb +2 -1
  9. data/lib/jpmobile/email.rb +3 -4
  10. data/lib/jpmobile/emoticon.rb +2 -6
  11. data/lib/jpmobile/encoding.rb +29 -0
  12. data/lib/jpmobile/filter.rb +42 -134
  13. data/lib/jpmobile/helpers.rb +5 -18
  14. data/lib/jpmobile/hook_action_controller.rb +24 -16
  15. data/lib/jpmobile/hook_action_view.rb +28 -89
  16. data/lib/jpmobile/mobile/abstract_mobile.rb +21 -4
  17. data/lib/jpmobile/mobile/android.rb +10 -0
  18. data/lib/jpmobile/mobile/au.rb +28 -3
  19. data/lib/jpmobile/mobile/ddipocket.rb +12 -0
  20. data/lib/jpmobile/mobile/display.rb +29 -26
  21. data/lib/jpmobile/mobile/docomo.rb +38 -12
  22. data/lib/jpmobile/mobile/iphone.rb +26 -0
  23. data/lib/jpmobile/mobile/smart_phone.rb +21 -0
  24. data/lib/jpmobile/mobile/softbank.rb +16 -41
  25. data/lib/jpmobile/mobile/vodafone.rb +17 -0
  26. data/lib/jpmobile/mobile/willcom.rb +1 -10
  27. data/lib/jpmobile/mobile/windows_phone.rb +10 -0
  28. data/lib/jpmobile/position.rb +4 -3
  29. data/lib/jpmobile/rack.rb +43 -0
  30. data/lib/jpmobile/rack/filter.rb +51 -0
  31. data/lib/jpmobile/rack/mobile_carrier.rb +33 -0
  32. data/lib/jpmobile/rack/params_filter.rb +47 -0
  33. data/lib/jpmobile/rails.rb +22 -0
  34. data/lib/jpmobile/request_with_mobile.rb +8 -12
  35. data/lib/jpmobile/trans_sid.rb +44 -26
  36. data/lib/jpmobile/util.rb +68 -0
  37. data/{tasks → lib/tasks}/jpmobile_tasks.rake +32 -13
  38. data/spec/rack/jpmobile/android_spec.rb +20 -0
  39. data/spec/rack/jpmobile/au_spec.rb +206 -0
  40. data/spec/rack/jpmobile/docomo_spec.rb +237 -0
  41. data/spec/rack/jpmobile/emoticon_spec.rb +215 -0
  42. data/spec/rack/jpmobile/filter_spec.rb +181 -0
  43. data/spec/rack/jpmobile/iphone_spec.rb +32 -0
  44. data/spec/rack/jpmobile/mobile_by_ua_spec.rb +39 -0
  45. data/spec/rack/jpmobile/params_filter_spec.rb +193 -0
  46. data/spec/rack/jpmobile/softbank_spec.rb +123 -0
  47. data/spec/rack/jpmobile/willcom_spec.rb +67 -0
  48. data/spec/rack/jpmobile/windows_phone.rb +20 -0
  49. data/spec/rack_helper.rb +86 -0
  50. data/spec/spec_helper.rb +3 -2
  51. data/spec/unit/detect_by_email_spec.rb +21 -27
  52. data/spec/unit/is_carrier_spec.rb +56 -84
  53. data/spec/unit/spec_helper.rb +1 -2
  54. data/spec/unit/util_spec.rb +2 -2
  55. data/spec/unit/valid_ip_spec.rb +43 -52
  56. data/test/legacy/autoload_test.rb +1 -3
  57. data/test/legacy/emoticon_test.rb +5 -6
  58. data/test/legacy/helper.rb +0 -71
  59. data/test/rails/overrides/.rspec +5 -0
  60. data/test/rails/overrides/Gemfile +32 -0
  61. data/test/rails/overrides/app/controllers/docomo_guid_always_controller.rb +3 -0
  62. data/test/rails/overrides/app/controllers/docomo_guid_base_controller.rb +5 -0
  63. data/test/rails/overrides/app/controllers/docomo_guid_docomo_controller.rb +3 -0
  64. data/test/rails/overrides/app/controllers/filter_controller.rb +0 -34
  65. data/test/rails/overrides/app/controllers/filter_controller_base.rb +19 -0
  66. data/test/rails/overrides/app/controllers/hankaku_filter_controller.rb +3 -0
  67. data/test/rails/overrides/app/controllers/links_controller.rb +28 -0
  68. data/test/rails/overrides/app/controllers/mobile_spec_controller.rb +1 -1
  69. data/test/rails/overrides/app/controllers/template_path_controller.rb +3 -0
  70. data/test/rails/overrides/app/controllers/trans_sid_always_and_session_off_controller.rb +4 -0
  71. data/test/rails/overrides/app/controllers/trans_sid_always_controller.rb +3 -0
  72. data/test/rails/overrides/app/controllers/trans_sid_base_controller.rb +18 -0
  73. data/test/rails/overrides/app/controllers/trans_sid_mobile_controller.rb +3 -0
  74. data/test/rails/overrides/app/controllers/trans_sid_none_controller.rb +3 -0
  75. data/test/rails/overrides/app/views/links/au_gps.html.erb +1 -0
  76. data/test/rails/overrides/app/views/links/au_location.html.erb +1 -0
  77. data/test/rails/overrides/app/views/links/docomo_foma_gps.html.erb +1 -0
  78. data/test/rails/overrides/app/views/links/docomo_openiarea.html.erb +1 -0
  79. data/test/rails/overrides/app/views/links/docomo_utn.html.erb +1 -0
  80. data/test/rails/overrides/app/views/links/link.html.erb +1 -0
  81. data/test/rails/overrides/app/views/links/show_all.html.erb +1 -0
  82. data/test/rails/overrides/app/views/links/softbank_location.html.erb +1 -0
  83. data/test/rails/overrides/app/views/links/willcom_location.html.erb +1 -0
  84. data/test/rails/overrides/app/views/template_path/_partial_smart_phone.html.erb +1 -0
  85. data/test/rails/overrides/app/views/template_path/_partial_smart_phone_iphone.html.erb +1 -0
  86. data/test/rails/overrides/app/views/template_path/index_smart_phone.html.erb +1 -0
  87. data/test/rails/overrides/app/views/template_path/index_smart_phone_iphone.html.erb +1 -0
  88. data/test/rails/overrides/app/views/template_path/show_mobile.html.erb +1 -0
  89. data/test/rails/overrides/app/views/template_path/show_mobile_docomo.html.erb +1 -0
  90. data/test/rails/overrides/autotest/discover.rb +2 -0
  91. data/test/rails/overrides/config/initializers/jpmobile_generator.rb +1 -0
  92. data/test/rails/overrides/config/routes.rb +58 -0
  93. data/test/rails/overrides/db/migrate/001_add_sessions_table.rb +16 -0
  94. data/test/rails/overrides/spec/helpers/helpers_spec.rb +2 -2
  95. data/test/rails/overrides/spec/{controllers → requests}/docomo_guid_spec.rb +37 -14
  96. data/test/rails/overrides/spec/{controllers → requests}/docomo_spec.rb +11 -8
  97. data/test/rails/overrides/spec/{controllers → requests}/emobile_spec.rb +24 -8
  98. data/test/rails/overrides/spec/requests/filter_spec.rb +171 -0
  99. data/test/rails/overrides/spec/requests/helpers_spec.rb +187 -0
  100. data/test/rails/overrides/spec/requests/pc_spec.rb +22 -0
  101. data/test/rails/overrides/spec/requests/softbank_emulator_spec.rb +21 -0
  102. data/test/rails/overrides/spec/requests/template_path_spec.rb +234 -0
  103. data/test/rails/overrides/spec/requests/trans_sid_spec.rb +142 -0
  104. data/test/rails/overrides/spec/spec_helper.rb +17 -48
  105. data/test/sinatra/guestbook.rb +40 -0
  106. data/test/sinatra/test/filter_test.rb +39 -0
  107. metadata +185 -312
  108. data/lib/jpmobile/hook_request.rb +0 -5
  109. data/lib/jpmobile/rack/auth.rb +0 -55
  110. data/lib/jpmobile/rack/combined_logger.rb +0 -54
  111. data/lib/jpmobile/rack/request.rb +0 -7
  112. data/lib/jpmobile/rack/trans_sid.rb +0 -14
  113. data/lib/jpmobile/version.rb +0 -9
  114. data/spec/unit/detect_by_ua_spec.rb +0 -40
  115. data/test/legacy/au_test.rb +0 -173
  116. data/test/legacy/docomo_test.rb +0 -187
  117. data/test/legacy/emoticon_functional_test.rb +0 -195
  118. data/test/legacy/filter_test.rb +0 -34
  119. data/test/legacy/helpers_test.rb +0 -217
  120. data/test/legacy/softbank_test.rb +0 -183
  121. data/test/legacy/willcom_test.rb +0 -56
  122. data/test/rails/2.3.2/spec/controllers/trans_sid_spec.rb +0 -99
  123. data/test/rails/overrides/app/controllers/docomo_guid_controller.rb +0 -13
  124. data/test/rails/overrides/app/controllers/trans_sid_controller.rb +0 -28
  125. data/test/rails/overrides/lib/tasks/rspec.rake +0 -165
  126. data/test/rails/overrides/spec/controllers/filter_spec.rb +0 -159
  127. data/test/rails/overrides/spec/controllers/pc_spec.rb +0 -13
  128. data/test/rails/overrides/spec/controllers/softbank_emulator_spec.rb +0 -42
  129. data/test/rails/overrides/spec/controllers/template_path_spec.rb +0 -117
  130. data/test/rails/overrides/spec/controllers/trans_sid_spec.rb +0 -117
  131. data/test/rails/overrides/spec/rspec.rake +0 -165
  132. data/test/rails/overrides/spec/spec.opts +0 -4
@@ -1,195 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- require File.dirname(__FILE__)+'/helper'
4
-
5
- class EmoticonTestController < ActionController::Base
6
- mobile_filter
7
- def docomo_cr
8
- render :text=>"&#xE63E;"
9
- end
10
- def docomo_utf8
11
- render :text=>[0xe63e].pack("U")
12
- end
13
- def docomo_docomopoint
14
- render :text=>"&#xE6D5;"
15
- end
16
- def au_cr
17
- render :text=>"&#xE488;"
18
- end
19
- def au_utf8
20
- render :text=>[0xe488].pack("U")
21
- end
22
- def softbank_cr
23
- render :text=>"&#xF04A;"
24
- end
25
- def softbank_utf8
26
- render :text=>[0xf04a].pack("U")
27
- end
28
- def query
29
- @q = params[:q]
30
- render :text=>@q
31
- end
32
- end
33
-
34
- class EmoticonFunctionalTest < ActionController::TestCase
35
- def setup
36
- init EmoticonTestController
37
- end
38
-
39
- def test_docomo_from_pc
40
- # PC
41
- get :docomo_cr
42
- assert_equal "&#xE63E;", @response.body
43
- get :docomo_utf8
44
- assert_equal "\xee\x98\xbe", @response.body
45
- end
46
-
47
- def test_docomo_from_docomo
48
- # DoCoMo携帯
49
- user_agent "DoCoMo/2.0 SH902i(c100;TB;W24H12)"
50
- get :docomo_cr
51
- assert_equal sjis("\xf8\x9f"), @response.body
52
- get :docomo_utf8
53
- assert_equal sjis("\xf8\x9f"), @response.body
54
- get :query, :q=>sjis("\xf8\x9f")
55
- assert_equal "\xee\x98\xbe", assigns["q"]
56
- assert_equal sjis("\xf8\x9f"), @response.body
57
-
58
- get :docomo_docomopoint
59
- assert_equal sjis("\xf9\x79"), @response.body
60
- end
61
-
62
- def test_docomo_from_au
63
- # Au携帯電話での閲覧
64
- user_agent "KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0"
65
- get :docomo_cr
66
- assert_equal sjis("\xf6\x60"), @response.body
67
- get :docomo_utf8
68
- assert_equal sjis("\xf6\x60"), @response.body
69
- get :docomo_docomopoint
70
- assert_equal to_sjis("[ドコモポイント]"), @response.body
71
- end
72
-
73
- def test_docomo_from_softbank
74
- # SoftBank携帯電話での閲覧
75
- user_agent "SoftBank/1.0/910T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1"
76
- get :docomo_cr
77
- assert_equal "\e$Gj\x0f", @response.body
78
- get :docomo_utf8
79
- assert_equal "\e$Gj\x0f", @response.body
80
- get :docomo_docomopoint
81
- assert_equal "[ドコモポイント]", @response.body
82
- end
83
-
84
- def test_docomo_from_jphone
85
- # J-PHONE携帯電話での閲覧
86
- user_agent "J-PHONE/3.0/V301D"
87
- get :docomo_cr
88
- assert_equal "\e$Gj\x0f", @response.body
89
- get :docomo_utf8
90
- assert_equal "\e$Gj\x0f", @response.body
91
- get :docomo_docomopoint
92
- assert_equal "Shift_JIS", @response.charset
93
- assert_equal to_sjis("[ドコモポイント]"), @response.body
94
- end
95
-
96
- def test_au_from_pc
97
- # PC
98
- get :au_cr
99
- assert_equal "&#xE488;", @response.body
100
- get :au_utf8
101
- assert_equal [0xe488].pack("U"), @response.body
102
- end
103
-
104
- def test_au_from_au
105
- # Au
106
- user_agent "KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0"
107
- get :au_cr
108
- assert_equal sjis("\xf6\x60"), @response.body
109
- get :au_utf8
110
- assert_equal sjis("\xf6\x60"), @response.body
111
- get :query, :q=>sjis("\xf6\x60")
112
- assert_equal [0xe488].pack("U"), assigns["q"]
113
- assert_equal sjis("\xf6\x60"), @response.body
114
- end
115
-
116
- def test_au_from_docomo
117
- # DoCoMo携帯電話での閲覧
118
- user_agent "DoCoMo/2.0 SH902i(c100;TB;W24H12)"
119
- get :au_cr
120
- assert_equal sjis("\xf8\x9f"), @response.body
121
- get :au_utf8
122
- assert_equal sjis("\xf8\x9f"), @response.body
123
- end
124
-
125
- def test_au_from_softbank
126
- # SoftBank携帯電話での閲覧
127
- user_agent "SoftBank/1.0/910T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1"
128
- get :au_cr
129
- assert_equal "\e$Gj\x0f", @response.body
130
- get :au_utf8
131
- assert_equal "\e$Gj\x0f", @response.body
132
- end
133
-
134
- def test_softbank_from_pc
135
- # PCから
136
- get :softbank_cr
137
- assert_equal "&#xF04A;", @response.body
138
- get :softbank_utf8
139
- assert_equal [0xf04a].pack("U"), @response.body
140
- end
141
-
142
- def test_softbank_from_softbank
143
- # SoftBank携帯電話から
144
- user_agent "SoftBank/1.0/910T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1"
145
- get :softbank_cr
146
- assert_equal "\e$Gj\x0f", @response.body
147
- get :softbank_utf8
148
- assert_equal "\e$Gj\x0f", @response.body
149
- get :query, :q=>[0xe04A].pack("U") # 3G端末はUTF-8で絵文字を送ってくる
150
- assert_equal [0xf04a].pack("U"), assigns["q"]
151
- assert_equal "\e$Gj\x0f", @response.body
152
- end
153
-
154
- def test_softbank_from_vodafone3g
155
- # Vodafone3G携帯電話から
156
- user_agent "Vodafone/1.0/V705SH/SHJ001/SN000000000000000 Browser/VF-NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1"
157
- get :softbank_cr
158
- assert_equal "\e$Gj\x0f", @response.body
159
- get :softbank_utf8
160
- assert_equal "\e$Gj\x0f", @response.body
161
- get :query, :q=>[0xe04A].pack("U") # 3G端末はUTF-8で絵文字を送ってくる
162
- assert_equal [0xf04a].pack("U"), assigns["q"]
163
- assert_equal "\e$Gj\x0f", @response.body
164
- end
165
-
166
- def test_softbank_from_jphone
167
- # J-PHONE携帯電話から
168
- user_agent "J-PHONE/3.0/V301D"
169
- get :softbank_cr
170
- assert_equal "\e$Gj\x0f", @response.body
171
- get :softbank_utf8
172
- assert_equal "\e$Gj\x0f", @response.body
173
- get :query, :q=>"\e$Gj\x0f" # J-PHONE端末はWebcodeで絵文字を送ってくる
174
- assert_equal [0xf04a].pack("U"), assigns["q"]
175
- assert_equal "\e$Gj\x0f", @response.body
176
- end
177
-
178
- def test_softbank_from_docomo
179
- # DoCoMo携帯電話での閲覧
180
- user_agent "DoCoMo/2.0 SH902i(c100;TB;W24H12)"
181
- get :softbank_cr
182
- assert_equal sjis("\xf8\x9f"), @response.body
183
- get :softbank_utf8
184
- assert_equal sjis("\xf8\x9f"), @response.body
185
- end
186
-
187
- def test_softbank_from_au
188
- # Au携帯電話での閲覧
189
- user_agent "KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0"
190
- get :softbank_cr
191
- assert_equal sjis("\xf6\x60"), @response.body
192
- get :softbank_utf8
193
- assert_equal sjis("\xf6\x60"), @response.body
194
- end
195
- end
@@ -1,34 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- require File.dirname(__FILE__)+'/helper'
4
-
5
- class FilterTest < Test::Unit::TestCase
6
- def setup
7
- @aiu_sjis = sjis("\202\240\202\242\202\244") # あいう
8
- @aiu_utf8 = utf8("\343\201\202\343\201\204\343\201\206") # あいう
9
-
10
- @aiu_zhz = utf8("\343\201\202\357\275\262\343\202\246") # あイウ (イ半角), UTF-8
11
- @aiu_zzz = utf8("\343\201\202\343\202\244\343\202\246") # あイウ, UTF-8
12
- @aiu_zhh = utf8("\343\201\202\357\275\262\357\275\263") # あイウ (イウ半角), UTF-8
13
-
14
- @abracadabra_z_utf8 = utf8("\343\202\242\343\203\226\343\203\251\343\202\253\343\203\200\343\203\226\343\203\251") # アブラカダブラ, UTF-8
15
- @abracadabra_h_utf8 = utf8("\357\275\261\357\276\214\357\276\236\357\276\227\357\275\266\357\276\200\357\276\236\357\276\214\357\276\236\357\276\227") # アブラカダブラ(半角), UTF-8
16
- @abracadabra_z_sjis = sjis("\203A\203u\203\211\203J\203_\203u\203\211") # アブラカダブラ, Shift_JIS
17
- end
18
- def test_filter_sjis
19
- filter = Jpmobile::Filter::Sjis.new
20
- assert_equal(@aiu_sjis, filter.to_external(@aiu_utf8, nil))
21
- assert_equal(@aiu_utf8, filter.to_internal(@aiu_sjis, nil))
22
- end
23
- def test_filter_hankaku
24
- filter = Jpmobile::Filter::HankakuKana.new
25
-
26
- assert_equal(@aiu_zzz, filter.to_internal(@aiu_zhz, nil))
27
- assert_equal(@aiu_zzz, filter.to_internal(@aiu_zzz, nil))
28
- assert_equal(@aiu_zhh, filter.to_external(@aiu_zhz, nil))
29
- assert_equal(@aiu_zhh, filter.to_external(@aiu_zzz, nil))
30
-
31
- assert_equal(@abracadabra_z_utf8, filter.to_internal(@abracadabra_h_utf8, nil))
32
- assert_equal(@abracadabra_h_utf8, filter.to_external(@abracadabra_z_utf8, nil))
33
- end
34
- end
@@ -1,217 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- require File.dirname(__FILE__)+'/helper'
3
- require 'hpricot'
4
-
5
- class FakeView
6
- include Jpmobile::Helpers
7
- def initialize
8
- @requiest = nil
9
- end
10
- def url_for(options={})
11
- return "http://example.jp"
12
- end
13
- attr_accessor :request
14
- end
15
-
16
- class HelpersTest < Test::Unit::TestCase
17
- def setup
18
- @view = FakeView.new
19
- end
20
-
21
- # get_position_link_to_がエラー無く終わるか。
22
- def test_get_position_link_to_show_all
23
- assert_nothing_raised {
24
- @view.get_position_link_to(:show_all=>true)
25
- }
26
- end
27
-
28
- # get_position_link_to(自動判別), DoCoMo
29
- def test_get_position_link_to_docomo
30
- @view.request = request_with_ua("DoCoMo/2.0 SH903i(c100;TB;W24H16)").first
31
- links = get_href_and_texts(@view.get_position_link_to("STRING"))
32
- assert_equal(1, links.size)
33
- text,attrs,path,params = links.first
34
- assert_equal("STRING", text)
35
- assert_equal("http://example.jp", path)
36
- assert(attrs.to_hash.include?("lcs"))
37
- end
38
-
39
- # get_position_link_to(自動判別), TUKA
40
- def test_get_position_link_to_tuka
41
- @view.request = request_with_ua("UP.Browser/3.04-KCTA UP.Link/3.4.5.9").first
42
- links = get_href_and_texts(@view.get_position_link_to("STRING"))
43
- assert(links.empty?)
44
- end
45
-
46
- # get_position_link_to(自動判別), au, location only
47
- def test_get_position_link_to_au_location_only
48
- @view.request = request_with_ua("KDDI-SN26 UP.Browser/6.2.0.6.2 (GUI) MMP/2.0").first
49
- links = get_href_and_texts(@view.get_position_link_to("STRING"))
50
- assert_equal(1, links.size)
51
- text,attrs,path,params = links.first
52
- assert_equal("STRING", text)
53
- assert_equal("device:location", path)
54
- assert_equal("http://example.jp", params["url"])
55
- end
56
-
57
- # get_position_link_to(自動判別), au, gps
58
- def test_get_position_link_to_au_gps
59
- @view.request = request_with_ua("KDDI-CA32 UP.Browser/6.2.0.7.3.129 (GUI) MMP/2.0").first
60
- links = get_href_and_texts(@view.get_position_link_to("STRING"))
61
- assert_equal(1, links.size)
62
- text,attrs,path,params = links.first
63
- assert_equal("STRING", text)
64
- assert_equal("device:gpsone", path)
65
- assert_equal("http://example.jp", params["url"])
66
- assert_equal("0", params["number"])
67
- assert_equal("0", params["acry"])
68
- assert_equal("1", params["ver"])
69
- assert_equal("0", params["unit"])
70
- assert_equal("0", params["datum"])
71
- end
72
-
73
- # get_position_link_to(自動判別), J-PHONE
74
- def test_get_position_link_to_jphone
75
- @view.request = request_with_ua("J-PHONE/4.3/V603SH/SNXXXX0000000 SH/0007aa Profile/MIDP-1.0 Configuration/CLDC-1.0 Ext-Profile/JSCL-1.3.2").first
76
- links = get_href_and_texts(@view.get_position_link_to("STRING"))
77
- assert_equal(1, links.size)
78
- text,attrs,path,params = links.first
79
- assert_equal("STRING", text)
80
- assert_equal("http://example.jp", path)
81
- assert(attrs.to_hash.include?("z"))
82
- end
83
-
84
- # get_position_link_to(自動判別), Vodafone
85
- def test_get_position_link_to_vodafone
86
- @view.request = request_with_ua("Vodafone/1.0/V903T/TJ001 Browser/VF-Browser/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 Ext-J-Profile/JSCL-1.2.2 Ext-V-Profile/VSCL-2.0.0").first
87
- links = get_href_and_texts(@view.get_position_link_to("STRING"))
88
- assert_equal(1, links.size)
89
- text,attrs,path,params = links.first
90
- assert_equal("STRING", text)
91
- assert_equal("location:auto", path)
92
- end
93
-
94
- # get_position_link_to(自動判別), Softbank
95
- def test_get_position_link_to_softbank
96
- @view.request = request_with_ua("SoftBank/1.0/910T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1").first
97
- links = get_href_and_texts(@view.get_position_link_to("STRING"))
98
- assert_equal(1, links.size)
99
- text,attrs,path,params = links.first
100
- assert_equal("STRING", text)
101
- assert_equal("location:auto", path)
102
- end
103
-
104
- # get_position_link_to(自動判別), Willcom
105
- def test_get_position_link_to_willcom
106
- @view.request = request_with_ua("Mozilla/3.0(WILLCOM;KYOCERA/WX310K/2;1.2.2.16.000000/0.1/C100) Opera 7.0").first
107
- links = get_href_and_texts(@view.get_position_link_to("STRING"))
108
- assert_equal(1, links.size)
109
- text,attrs,path,params = links.first
110
- assert_equal("STRING", text)
111
- assert_equal("http://location.request/dummy.cgi", path)
112
- assert_equal("http://example.jp", params["my"])
113
- assert_equal("$location", params["pos"])
114
- end
115
-
116
- # DoCoMo 端末情報取得用のリンクが正しく出力されるか。
117
- def test_docomo_utn_link_to
118
- links = get_href_and_texts(@view.docomo_utn_link_to("STRING"))
119
- assert_equal(1, links.size)
120
- text,attrs,path,params = links.first
121
- assert_equal("STRING", text)
122
- assert_equal("http://example.jp", path)
123
- assert(attrs.to_hash.include?("utn"))
124
- end
125
-
126
- # DoCoMo オープンiエリア取得用のリンクが正しく出力されるか。
127
- def test_docomo_openiarea_link_to
128
- links = get_href_and_texts(@view.docomo_openiarea_link_to("STRING"))
129
- assert_equal(1, links.size)
130
- text,attrs,path,params = links.first
131
- assert_equal("STRING", text)
132
- assert_equal("http://w1m.docomo.ne.jp/cp/iarea", path)
133
- assert_equal("OPENAREACODE", params["ecode"])
134
- assert_equal("OPENAREAKEY", params["msn"])
135
- assert_equal("1", params["posinfo"])
136
- assert_equal("http://example.jp", params["nl"])
137
- end
138
-
139
- # DoCoMo GPS取得用のリンクが正しく出力されるか。
140
- def test_docomo_foma_gps_link_to
141
- links = get_href_and_texts(@view.docomo_foma_gps_link_to("STRING"))
142
- assert_equal(1, links.size)
143
- text,attrs,path,params = links.first
144
- assert_equal("STRING", text)
145
- assert_equal("http://example.jp", path)
146
- assert(attrs.to_hash.include?("lcs"))
147
- end
148
-
149
- # au簡易位置情報取得用のリンクが正しく出力されるか。
150
- def test_au_location_link_to
151
- links = get_href_and_texts(@view.au_location_link_to("STRING"))
152
- assert_equal(1, links.size)
153
- text,attrs,path,params = links.first
154
- assert_equal("STRING", text)
155
- assert_equal("device:location", path)
156
- assert_equal("http://example.jp", params["url"])
157
- end
158
-
159
- # au GPS位置情報取得用のリンクが正しく出力されるか。
160
- def test_au_gps_link_to
161
- links = get_href_and_texts(@view.au_gps_link_to("STRING"))
162
- assert_equal(1, links.size)
163
- text,attrs,path,params = links.first
164
- assert_equal("STRING", text)
165
- assert_equal("device:gpsone", path)
166
- assert_equal("http://example.jp", params["url"])
167
- assert_equal("0", params["number"])
168
- assert_equal("0", params["acry"])
169
- assert_equal("1", params["ver"])
170
- assert_equal("0", params["unit"])
171
- assert_equal("0", params["datum"])
172
- end
173
-
174
- # J-PHONE 位置情報取得用のリンクが正しく出力されるか。
175
- def test_jphone_location_link_to
176
- links = get_href_and_texts(@view.jphone_location_link_to("STRING"))
177
- assert_equal(1, links.size)
178
- text,attrs,path,params = links.first
179
- assert_equal("STRING", text)
180
- assert_equal("http://example.jp", path)
181
- assert(attrs.to_hash.include?("z"))
182
- end
183
-
184
- # Softbank 3G 位置情報取得用のリンクが正しく出力されるか。
185
- def test_softbank_location_link_to
186
- links = get_href_and_texts(@view.softbank_location_link_to("STRING"))
187
- assert_equal(1, links.size)
188
- text,attrs,path,params = links.first
189
- assert_equal("STRING", text)
190
- assert_equal("location:auto", path)
191
- end
192
-
193
- # Willcom 位置情報取得用のリンクが正しく出力されるか。
194
- def test_willcom_location_link_to
195
- links = get_href_and_texts(@view.willcom_location_link_to("STRING"))
196
- assert_equal(1, links.size)
197
- text,attrs,path,params = links.first
198
- assert_equal("STRING", text)
199
- assert_equal("http://location.request/dummy.cgi", path)
200
- assert_equal("http://example.jp", params["my"])
201
- assert_equal("$location", params["pos"])
202
- end
203
-
204
- private
205
- # 文字列 +str+ 中に含まれるリンクについて、
206
- # リンクテキスト、属性のHash、URLのqueryをのぞいた部分、ueryをHashにしたもの
207
- # の3要素からなる配列の配列で返す。
208
- def get_href_and_texts(str)
209
- results = []
210
- (Hpricot(str)/:a).each do |link|
211
- path, query = link["href"].split(/\?/, 2)
212
- params = query.nil? ? nil : Rack::Utils.parse_query(query)
213
- results << [link.inner_html, link.attributes, path, params]
214
- end
215
- return results
216
- end
217
- end
@@ -1,183 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- require File.dirname(__FILE__)+'/helper'
4
-
5
- class SoftbankTest < Test::Unit::TestCase
6
- # SoftBank, 端末種別の識別
7
- def test_softbank_910t
8
- reqs = request_with_ua("SoftBank/1.0/910T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1")
9
- reqs.each do |req|
10
- assert_equal(true, req.mobile?)
11
- assert_instance_of(Jpmobile::Mobile::Softbank, req.mobile)
12
- assert_kind_of(Jpmobile::Mobile::Softbank, req.mobile)
13
- assert_equal(nil, req.mobile.position)
14
- assert_equal("000000000000000", req.mobile.serial_number)
15
- assert_equal("000000000000000", req.mobile.ident)
16
- assert_equal("000000000000000", req.mobile.ident_device)
17
- assert_equal(nil, req.mobile.ident_subscriber)
18
- assert(req.mobile.supports_cookie?)
19
- end
20
- end
21
-
22
- # SoftBank, X_JPHONE_UID付き
23
- def test_softbank_910t_x_jphone_uid
24
- reqs = request_with_ua("SoftBank/1.0/910T/TJ001/SN000000000000000 Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1", "HTTP_X_JPHONE_UID"=>"aaaaaaaaaaaaaaaa")
25
- reqs.each do |req|
26
- assert_equal("000000000000000", req.mobile.serial_number)
27
- assert_equal("aaaaaaaaaaaaaaaa", req.mobile.x_jphone_uid)
28
- assert_equal("aaaaaaaaaaaaaaaa", req.mobile.ident)
29
- assert_equal("000000000000000", req.mobile.ident_device)
30
- assert_equal("aaaaaaaaaaaaaaaa", req.mobile.ident_subscriber)
31
- assert(req.mobile.supports_cookie?)
32
- end
33
- end
34
-
35
- # Vodafone, 端末種別の識別
36
- def test_vodafone_v903t
37
- reqs = request_with_ua("Vodafone/1.0/V903T/TJ001 Browser/VF-Browser/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 Ext-J-Profile/JSCL-1.2.2 Ext-V-Profile/VSCL-2.0.0")
38
- reqs.each do |req|
39
- assert_equal(true, req.mobile?)
40
- assert_instance_of(Jpmobile::Mobile::Vodafone, req.mobile)
41
- assert_kind_of(Jpmobile::Mobile::Softbank, req.mobile)
42
- assert_equal(nil, req.mobile.position)
43
- assert_equal(nil, req.mobile.ident)
44
- assert(req.mobile.supports_cookie?)
45
- end
46
- end
47
-
48
- # Vodafone, 端末種別の識別
49
- def test_vodafone_v903sh
50
- reqs = request_with_ua("Vodafone/1.0/V903SH/SHJ001/SN000000000000000 Browser/UP.Browser/7.0.2.1 Profile/MIDP-2.0 Configuration/CLDC-1.1 Ext-J-Profile/JSCL-1.2.2 Ext-V-Profile/VSCL-2.0.0")
51
- reqs.each do |req|
52
- assert_equal(true, req.mobile?)
53
- assert_instance_of(Jpmobile::Mobile::Vodafone, req.mobile)
54
- assert_kind_of(Jpmobile::Mobile::Softbank, req.mobile)
55
- assert_equal("000000000000000", req.mobile.serial_number)
56
- assert_equal("000000000000000", req.mobile.ident)
57
- assert_equal("000000000000000", req.mobile.ident_device)
58
- assert_equal(nil, req.mobile.ident_subscriber)
59
- assert_equal(nil, req.mobile.position)
60
- assert(req.mobile.supports_cookie?)
61
- end
62
- end
63
-
64
- # J-PHONE, 端末種別の識別
65
- def test_jphone_v603sh
66
- reqs = request_with_ua("J-PHONE/4.3/V603SH/SNXXXX0000000 SH/0007aa Profile/MIDP-1.0 Configuration/CLDC-1.0 Ext-Profile/JSCL-1.3.2")
67
- reqs.each do |req|
68
- assert_equal(true, req.mobile?)
69
- assert_instance_of(Jpmobile::Mobile::Jphone, req.mobile)
70
- assert_kind_of(Jpmobile::Mobile::Softbank, req.mobile)
71
- assert_equal("XXXX0000000", req.mobile.serial_number)
72
- assert_equal("XXXX0000000", req.mobile.ident)
73
- assert_equal("XXXX0000000", req.mobile.ident_device)
74
- assert_equal(nil, req.mobile.ident_subscriber)
75
- assert_equal(nil, req.mobile.position)
76
- assert(!req.mobile.supports_cookie?)
77
- end
78
- end
79
-
80
- # J-PHONE, 端末種別の識別
81
- def test_jphone_v301d
82
- reqs = request_with_ua("J-PHONE/3.0/V301D")
83
- reqs.each do |req|
84
- assert_equal(true, req.mobile?)
85
- assert_instance_of(Jpmobile::Mobile::Jphone, req.mobile)
86
- assert_kind_of(Jpmobile::Mobile::Softbank, req.mobile)
87
- assert_equal(nil, req.mobile.serial_number)
88
- assert_equal(nil, req.mobile.position)
89
- assert(!req.mobile.supports_cookie?)
90
- end
91
- end
92
-
93
- # J-PHONE
94
- # http://kokogiko.net/wiki.cgi?page=vodafone%A4%C7%A4%CE%B0%CC%C3%D6%BC%E8%C6%C0%CA%FD%CB%A1
95
- def test_jphone_antenna
96
- reqs = request_with_ua("J-PHONE/3.0/V301D",
97
- "HTTP_X_JPHONE_GEOCODE"=>"353840%1A1394440%1A%93%8C%8B%9E%93s%8D%60%8B%E6%8E%C5%82T%92%9A%96%DA")
98
- reqs.each do |req|
99
- assert_in_delta(35.64768482, req.mobile.position.lat, 1e-4)
100
- assert_in_delta(139.7412141, req.mobile.position.lon, 1e-4)
101
- assert_equal("東京都港区芝5丁目", req.mobile.position.options["address"])
102
- end
103
- end
104
-
105
- # J-PHONE 位置情報なし
106
- def test_jphone_antenna_empty
107
- reqs = request_with_ua("J-PHONE/3.0/V301D",
108
- "HTTP_X_JPHONE_GEOCODE"=>"0000000%1A0000000%1A%88%CA%92%75%8F%EE%95%F1%82%C8%82%B5")
109
- reqs.each do |req|
110
- assert_equal(nil, req.mobile.position)
111
- end
112
- end
113
-
114
- # Vodafone 3G, wgs84, gps
115
- def test_vodafone_gps
116
- reqs = request_with_ua("Vodafone/1.0/V903T/TJ001 Browser/VF-Browser/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 Ext-J-Profile/JSCL-1.2.2 Ext-V-Profile/VSCL-2.0.0",
117
- {"QUERY_STRING"=>"pos=N43.3.18.42E141.21.1.88&geo=wgs84&x-acr=1"})
118
- reqs.each do |req|
119
- assert_in_delta(43.05511667, req.mobile.position.lat, 1e-7)
120
- assert_in_delta(141.3505222, req.mobile.position.lon, 1e-7)
121
- assert_equal("N43.3.18.42E141.21.1.88", req.mobile.position.options["pos"])
122
- assert_equal("wgs84", req.mobile.position.options["geo"])
123
- assert_equal("1", req.mobile.position.options["x-acr"])
124
- end
125
- end
126
-
127
- # 正しいIPアドレス空間からのアクセスを判断できるか。
128
- def test_softbank_valid_ip_address
129
- reqs = request_with_ua("Vodafone/1.0/V903T/TJ001 Browser/VF-Browser/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 Ext-J-Profile/JSCL-1.2.2 Ext-V-Profile/VSCL-2.0.0",
130
- {"REMOTE_ADDR"=>"202.179.204.1"})
131
- reqs.each do |req|
132
- assert_equal(true, req.mobile.valid_ip?)
133
- end
134
- end
135
-
136
- # 正しいIPアドレス空間からのアクセスを判断できるか。
137
- def test_jphone_valid_ip_address
138
- reqs = request_with_ua("J-PHONE/3.0/V301D",
139
- {"REMOTE_ADDR"=>"202.179.204.1"})
140
- reqs.each do |req|
141
- assert_equal(true, req.mobile.valid_ip?)
142
- end
143
- end
144
-
145
- # 正しくないIPアドレス空間からのアクセスを判断できるか。
146
- def test_softbank_ip_address
147
- reqs = request_with_ua("Vodafone/1.0/V903T/TJ001 Browser/VF-Browser/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 Ext-J-Profile/JSCL-1.2.2 Ext-V-Profile/VSCL-2.0.0",
148
- {"REMOTE_ADDR"=>"127.0.0.1"})
149
- reqs.each do |req|
150
- assert_equal(false, req.mobile.valid_ip?)
151
- end
152
- end
153
-
154
- # 端末の画面サイズを正しく取得できるか。
155
- def test_softbank_v903t_display
156
- reqs = request_with_ua("Vodafone/1.0/V903T/TJ001 Browser/VF-Browser/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 Ext-J-Profile/JSCL-1.2.2 Ext-V-Profile/VSCL-2.0.0",
157
- "HTTP_X_JPHONE_DISPLAY"=>"240*320",
158
- "HTTP_X_JPHONE_COLOR"=>"C262144" )
159
- reqs.each do |req|
160
- assert_equal(240, req.mobile.display.width)
161
- assert_equal(320, req.mobile.display.height)
162
- assert_equal(240, req.mobile.display.physical_width)
163
- assert_equal(320, req.mobile.display.physical_height)
164
- assert_equal(true, req.mobile.display.color?)
165
- assert_equal(262144, req.mobile.display.colors)
166
- end
167
- end
168
-
169
- # 端末の画面情報が渡ってない場合に正しく動作するか。
170
- def test_softbank_v903t_display_information_omitted
171
- reqs = request_with_ua("Vodafone/1.0/V903T/TJ001 Browser/VF-Browser/1.0 Profile/MIDP-2.0 Configuration/CLDC-1.1 Ext-J-Profile/JSCL-1.2.2 Ext-V-Profile/VSCL-2.0.0")
172
- reqs.each do |req|
173
- assert_equal(nil, req.mobile.display.width)
174
- assert_equal(nil, req.mobile.display.height)
175
- assert_equal(nil, req.mobile.display.browser_width)
176
- assert_equal(nil, req.mobile.display.browser_height)
177
- assert_equal(nil, req.mobile.display.physical_width)
178
- assert_equal(nil, req.mobile.display.physical_height)
179
- assert_equal(nil, req.mobile.display.color?)
180
- assert_equal(nil, req.mobile.display.colors)
181
- end
182
- end
183
- end