test/activity/navigation_activity_test.rb in ruboto-0.10.0 vs test/activity/navigation_activity_test.rb in ruboto-0.10.1
- old
+ new
@@ -10,138 +10,39 @@
assert @text_view
end
test('Java backed activity is reloaded if source already loaded', :ui => false) do |activity|
require 'navigation_target_activity'
- #::NavigationTargetActivity = ::RubyFileActivity
- #Object.const_set(:NavigationTargetActivity, RubyFileActivity)
- #Kernel.const_set(:NavigationTargetActivity, RubyFileActivity)
button_activity_text 43, activity, 42, 'This is the navigation target activity.',
'org.ruboto.test_app.NavigationTargetActivity'
end
test('button starts Java activity', :ui => false) do |activity|
- monitor = add_monitor('org.ruboto.test_app.NavigationTargetActivity', nil, false)
- begin
- activity.run_on_ui_thread { activity.find_view_by_id(43).perform_click }
- current_activity = wait_for_monitor_with_timeout(monitor, 5000)
- assert current_activity
- current_activity.run_on_ui_thread { current_activity.finish }
- # FIXME(uwe): Replace sleep with proper monitor
- sleep 3
- ensure
- puts "Removing monitor"
- removeMonitor(monitor)
- end
+ button_activity_text 43, activity, 42, 'This is the navigation target activity.',
+ 'org.ruboto.test_app.NavigationTargetActivity'
end
test('button starts Ruby activity', :ui => false) do |activity|
- monitor = add_monitor('org.ruboto.RubotoActivity', nil, false)
- begin
- activity.run_on_ui_thread { activity.find_view_by_id(44).perform_click }
- current_activity = wait_for_monitor_with_timeout(monitor, 5000)
- assert current_activity
- current_activity.run_on_ui_thread { current_activity.finish }
- # FIXME(uwe): Replace sleep with proper monitor
- sleep 3
- ensure
- puts "Removing monitor"
- removeMonitor(monitor)
- end
+ button_activity_text 44, activity, 42, 'This is the navigation target activity.'
end
test('button starts activity by script name', :ui => false) do |activity|
- monitor = add_monitor('org.ruboto.RubotoActivity', nil, false)
- begin
- activity.run_on_ui_thread { activity.find_view_by_id(45).perform_click }
- current_activity = wait_for_monitor_with_timeout(monitor, 5000)
- assert current_activity
- current_activity.run_on_ui_thread { current_activity.finish }
- # FIXME(uwe): Replace sleep with proper monitor
- sleep 3
- ensure
- puts "Removing monitor"
- removeMonitor(monitor)
- end
+ button_activity_text 45, activity, 42, 'This is the navigation target activity.'
end
test('button starts inline activity', :ui => false) do |activity|
- monitor = add_monitor('org.ruboto.RubotoActivity', nil, false)
- begin
- activity.run_on_ui_thread { activity.find_view_by_id(46).perform_click }
- current_activity = wait_for_monitor_with_timeout(monitor, 5000)
- assert current_activity
- current_activity.run_on_ui_thread { current_activity.finish }
- # FIXME(uwe): Replace sleep with proper monitor
- sleep 3
- ensure
- puts "Removing monitor"
- removeMonitor(monitor)
- end
-
- start = Time.now
- loop do
- @text_view = current_activity.find_view_by_id(42)
- break if (@text_view && @text_view.text == 'This is an inline activity.') || (Time.now - start > 10)
- puts 'wait for text'
- sleep 0.5
- end
- assert @text_view
- assert_equal 'This is an inline activity.', @text_view.text
+ button_activity_text 46, activity, 42, 'This is an inline activity.'
end
test('button starts inline activity with options', :ui => false) do |activity|
- monitor = add_monitor('org.ruboto.RubotoActivity', nil, false)
- begin
- activity.run_on_ui_thread { activity.find_view_by_id(47).perform_click }
- current_activity = wait_for_monitor_with_timeout(monitor, 5000)
- assert current_activity
- current_activity.run_on_ui_thread { current_activity.finish }
- # FIXME(uwe): Replace sleep with proper monitor
- sleep 3
- ensure
- puts "Removing monitor"
- removeMonitor(monitor)
- end
-
- start = Time.now
- loop do
- @text_view = current_activity.find_view_by_id(42)
- break if (@text_view && @text_view.text == 'This is an inline activity.') || (Time.now - start > 10)
- puts 'wait for text'
- sleep 0.5
- end
- assert @text_view
- assert_equal 'This is an inline activity.', @text_view.text
+ button_activity_text 47, activity, 42, 'This is an inline activity.'
end
test('button starts infile class activity', :ui => false) do |activity|
- monitor = add_monitor('org.ruboto.RubotoActivity', nil, false)
- begin
- activity.run_on_ui_thread { activity.find_view_by_id(48).perform_click }
- current_activity = wait_for_monitor_with_timeout(monitor, 5000)
- ensure
- removeMonitor(monitor)
- end
- puts "new activity: #{current_activity.inspect}"
- assert current_activity
- assert current_activity.is_a? Java::OrgRuboto::RubotoActivity
- start = Time.now
- loop do
- @text_view = current_activity.find_view_by_id(42)
- break if @text_view || (Time.now - start > 10)
- puts 'wait for text'
- sleep 1
- end
- assert @text_view
- assert_equal 'This is an infile activity.', @text_view.text
- current_activity.run_on_ui_thread { current_activity.finish }
- # FIXME(uwe): Replace sleep with proper monitor
- sleep 3
+ button_activity_text 48, activity, 42, 'This is an infile activity.'
end
-
test("infile activity starts again", :ui => false) do |activity|
button_activity_text 48, activity, 42, 'This is an infile activity.'
end
test("start ruby file activity", :ui => false) do |activity|
@@ -150,21 +51,35 @@
test("start ruby file activity again", :ui => false) do |activity|
button_activity_text 49, activity, 42, 'This is a Ruby file activity.'
end
-def button_activity_text button_id, activity, expected_text_id, expected_text_string,
- activity_class_name = 'org.ruboto.RubotoActivity'
+test("start ruboto activity without config", :ui => false) do |activity|
+ a = start_activity_by_button activity, 50
+ assert_equal 'Ruboto Test App', a.title
+end
+
+def start_activity_by_button(activity, button_id, activity_class_name = 'org.ruboto.RubotoActivity')
monitor = add_monitor(activity_class_name, nil, false)
begin
- activity.run_on_ui_thread { activity.find_view_by_id(button_id).perform_click }
+ activity.run_on_ui_thread do
+ btn = activity.find_view_by_id(button_id)
+ btn.request_focus
+ btn.perform_click
+ end
current_activity = wait_for_monitor_with_timeout(monitor, 5000)
ensure
removeMonitor(monitor)
end
puts "new activity: #{current_activity.inspect}"
assert current_activity.is_a? Java::OrgRuboto::RubotoActivity
+ current_activity
+end
+
+def button_activity_text button_id, activity, expected_text_id, expected_text_string,
+ activity_class_name = 'org.ruboto.RubotoActivity'
+ current_activity = start_activity_by_button(activity, button_id, activity_class_name)
start = Time.now
loop do
@text_view = current_activity.find_view_by_id(expected_text_id)
break if @text_view || (Time.now - start > 10)
puts 'wait for text'
@@ -172,10 +87,15 @@
end
assert @text_view
assert_equal expected_text_string, @text_view.text
ensure
if current_activity
- current_activity.run_on_ui_thread { current_activity.finish }
- # FIXME(uwe): Replace sleep with proper monitor
- sleep 3
+ finish_at = Time.now
+ finished = false
+ current_activity.run_on_ui_thread { current_activity.finish ; finished = true }
+ loop do
+ break if finished || (Time.now - finish_at > 10)
+ puts 'wait for finish'
+ sleep 0.1
+ end
end
end