spec/rack/jpmobile/emoticon_spec.rb in jpmobile-3.0.4 vs spec/rack/jpmobile/emoticon_spec.rb in jpmobile-3.0.5

- old
+ new

@@ -5,10 +5,12 @@ include Rack::Test::Methods include Jpmobile::RackHelper include Jpmobile::Util before(:each) do + Jpmobile.config.smart_phone_emoticon_compatibility = true + @docomo_cr = "&#xE63E;"; @docomo_utf8 = [0xe63e].pack("U") @docomo_docomopoint = "&#xE6D5;" @au_cr = "&#xE488;" @@ -97,10 +99,16 @@ it "softbank 絵文字コードが画像に変換されること" do response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@softbank_utf8))).call(@res)[2] response_body(response).should == "<img src=\"#{@path}/sun.gif\" alt=\"sun\" />" end + + it "Content-Type が変換できないものである場合には変換しないこと" do + @res = Rack::MockRequest.env_for("/", 'Content-Type' => 'image/jpeg') + response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@softbank_utf8))).call(@res)[2] + response_body(response).should == @softbank_utf8 + end end context "docomo のとき" do before(:each) do @res = Rack::MockRequest.env_for( @@ -267,8 +275,173 @@ 'Content-Type' => 'text/html; charset=utf-8') res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::ParamsFilter.new(Jpmobile::Rack::Filter.new(RenderParamApp.new))).call(res) req = Rack::Request.new(res[1]) req.params['q'].should == [0xf04a].pack("U") response_body(res).should == [0xe04a].pack('U') + end + end + + context 'for iPhone' do + context 'lower iOS 4' do + before(:each) do + @res = Rack::MockRequest.env_for( + "/", + 'HTTP_USER_AGENT' => "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0_1 like Mac OS X; ja-jp) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A306 Safari/6531.22.7", + 'Content-Type' => 'text/html; charset=utf-8') + end + + it 'should convert Softbank emoticon' do + response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@softbank_cr))).call(@res)[2] + response_body(response).should == [0xe04a].pack('U') + response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@softbank_utf8))).call(@res)[2] + response_body(response).should == [0xe04a].pack('U') + end + + it "converts query parameters" do + query_string = "q=" + URI.encode([0xe04A].pack("U")) + + res = Rack::MockRequest.env_for( + "/?#{query_string}", + "REQUEST_METHOD" => "GET", + 'HTTP_USER_AGENT' => "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0_1 like Mac OS X; ja-jp) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A306 Safari/6531.22.7", + 'Content-Type' => 'text/html; charset=utf-8') + res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::ParamsFilter.new(Jpmobile::Rack::Filter.new(RenderParamApp.new))).call(res) + req = Rack::Request.new(res[1]) + req.params['q'].should == [0xf04a].pack("U") + response_body(res).should == [0xe04a].pack('U') + end + + it 'should not convert 〓' do + response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new('〓'))).call(@res)[2] + response_body(response).should == '〓' + end + end + + context 'upper iOS 5' do + before(:each) do + @res = Rack::MockRequest.env_for( + "/", + 'HTTP_USER_AGENT' => "Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9A334 Safari/7534.48.3", + 'Content-Type' => 'text/html; charset=utf-8') + @unicode_single = "\342\230\200" + @unicode_multi = "\342\233\205" + end + + it "should convert Unicode emoticon" do + response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@unicode_single))).call(@res)[2] + response_body(response).should == [0x2600].pack('U*') + response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@unicode_multi))).call(@res)[2] + response_body(response).should == [0x26C5].pack('U*') + end + + it "converts query parameters" do + query_string = "q=" + URI.encode(@unicode_multi) + + res = Rack::MockRequest.env_for( + "/?#{query_string}", + "REQUEST_METHOD" => "GET", + 'HTTP_USER_AGENT' => "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0_1 like Mac OS X; ja-jp) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A306 Safari/6531.22.7", + 'Content-Type' => 'text/html; charset=utf-8') + res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::ParamsFilter.new(Jpmobile::Rack::Filter.new(RenderParamApp.new))).call(res) + req = Rack::Request.new(res[1]) + req.params['q'].should == [0x26C5].pack("U") + response_body(res).should == [0x26C5].pack('U') + end + + it 'should not convert 〓' do + response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new('〓'))).call(@res)[2] + response_body(response).should == '〓' + end + end + end + + context 'for Android' do + before(:each) do + @google_single = "\363\276\200\200" + @google_multi = "\363\276\200\217" + end + + context 'mobile' do + before(:each) do + @res = Rack::MockRequest.env_for( + "/", + 'HTTP_USER_AGENT' => 'Mozilla/5.0 (Linux; U; Android 1.6; ja-jp; SonyEriccsonSO-01B Build/R1EA018) AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1', + 'Content-Type' => 'text/html; charset=utf-8') + end + + it "should convert Google emoticon" do + response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@google_single))).call(@res)[2] + response_body(response).should == [0xFE000].pack('U*') + response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@google_multi))).call(@res)[2] + response_body(response).should == [0xFE00F].pack('U*') + end + + it "converts query parameters irreversibly" do + query_string = "q=" + URI.encode(@google_multi) + + res = Rack::MockRequest.env_for( + "/?#{query_string}", + "REQUEST_METHOD" => "GET", + 'HTTP_USER_AGENT' => 'Mozilla/5.0 (Linux; U; Android 1.6; ja-jp; SonyEriccsonSO-01B Build/R1EA018) AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1', + 'Content-Type' => 'text/html; charset=utf-8') + res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::ParamsFilter.new(Jpmobile::Rack::Filter.new(RenderParamApp.new))).call(res) + req = Rack::Request.new(res[1]) + req.params['q'].should == [0xe63e, 0xe63f].pack("U*") + response_body(res).should == [0xfe000, 0xfe001].pack("U*") + end + + it 'should not convert 〓' do + response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new('〓'))).call(@res)[2] + response_body(response).should == '〓' + end + end + + context 'tablet' do + before(:each) do + @res = Rack::MockRequest.env_for( + "/", + 'HTTP_USER_AGENT' => 'Mozilla/5.0 (Linux; U; Android 2.2; ja-jp; SC-01C Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1', + 'Content-Type' => 'text/html; charset=utf-8') + end + + it "should convert Google emoticon" do + response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@google_single))).call(@res)[2] + response_body(response).should == [0xFE000].pack('U*') + response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new(@google_multi))).call(@res)[2] + response_body(response).should == [0xFE00F].pack('U*') + end + + it "converts query parameters irreversibly" do + query_string = "q=" + URI.encode(@google_multi) + + res = Rack::MockRequest.env_for( + "/?#{query_string}", + "REQUEST_METHOD" => "GET", + 'HTTP_USER_AGENT' => 'Mozilla/5.0 (Linux; U; Android 2.2; ja-jp; SC-01C Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1', + 'Content-Type' => 'text/html; charset=utf-8') + res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::ParamsFilter.new(Jpmobile::Rack::Filter.new(RenderParamApp.new))).call(res) + req = Rack::Request.new(res[1]) + req.params['q'].should == [0xe63e, 0xe63f].pack("U*") + response_body(res).should == [0xfe000, 0xfe001].pack("U*") + end + + it 'should not convert 〓' do + response = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::Filter.new(UnitApplication.new('〓'))).call(@res)[2] + response_body(response).should == '〓' + end + + it 'should convert unsupported emoticon to "〓"' do + query_string = "q=" + URI.encode("\xF3\xBE\x93\xA4") + + res = Rack::MockRequest.env_for( + "/?#{query_string}", + "REQUEST_METHOD" => "GET", + 'HTTP_USER_AGENT' => 'Mozilla/5.0 (Linux; U; Android 2.2; ja-jp; SC-01C Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1', + 'Content-Type' => 'text/html; charset=utf-8') + res = Jpmobile::Rack::MobileCarrier.new(Jpmobile::Rack::ParamsFilter.new(Jpmobile::Rack::Filter.new(RenderParamApp.new))).call(res) + req = Rack::Request.new(res[1]) + req.params['q'].should == '〓' + response_body(res).should == '〓' + end end end end