test/activity/ssl_activity.rb in ruboto-1.0.3 vs test/activity/ssl_activity.rb in ruboto-1.1.0

- old
+ new

@@ -6,26 +6,43 @@ class SslActivity def onCreate(bundle) super puts 'start thread' @thread = Thread.with_large_stack { require 'net/https' } + @open_uri_thread = Thread.with_large_stack { require 'open-uri' } puts 'thread started' set_title File.basename(__FILE__).chomp('_activity.rb').split('_').map { |s| "#{s[0..0].upcase}#{s[1..-1]}" }.join(' ') self.content_view = linear_layout :orientation => LinearLayout::VERTICAL, :gravity => android.view.Gravity::CENTER do - @text_view = text_view :id => 42, :text => 'net/https loading...', - :text_size => 48.0, :gravity => android.view.Gravity::CENTER + @text_view = text_view text: 'net/https loading...', + text_size: 48.0, gravity: :center, id: 42 + @response_view = text_view text: 'net/https loading...', + text_size: 48.0, gravity: :center, id: 43 end end def onResume super - puts 'on resume my lord' - Thread.start do - puts 'joining thread' - @thread.join - puts 'thread joined' - run_on_ui_thread{@text_view.text = 'net/https loaded OK!'} - puts 'text updated' + Thread.with_large_stack do + begin + @thread.join + run_on_ui_thread { @text_view.text = 'net/https loaded OK!' } + @open_uri_thread.join + run_on_ui_thread { @response_view.text = 'open-uri loaded OK!' } + puts 'before open' + ENV['TMPDIR'] = files_dir.absolute_path + open('https://google.com/', ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE) do |f| + puts 'inside open' + body = f.read + puts 'body' + puts body + heading = body[%r{<title>.*?</title>}] + puts heading.inspect + run_on_ui_thread { @response_view.text = heading } + end + rescue Exception + puts "Exception resdum: #{$!.class} #{$!.message}" + run_on_ui_thread { @response_view.text = $!.to_s } + end end end end