Sha256: c408f3b47f413a710c4ed909abb4d18f3a73dee12ef2b7e26e0d7b9ba7b63a7e

Contents?: true

Size: 1.42 KB

Versions: 25

Compression:

Stored size: 1.42 KB

Contents

# Change this to the activity that will send the broadcast
activity Java::THE_PACKAGE.SampleActivity

# Change this to wait for the activity to be created
setup do |activity|
  start = Time.now
  loop do
    @text_view = activity.findViewById(42)
    break if @text_view || (Time.now - start > 60)
    sleep 1
  end
  assert @text_view
end

# Change this to trigger the sending of broadcast intents
# and assert that the receiver behaves correctly.
test('broadcast changes title', :ui => false) do |activity|
  begin
    @receiver = $package.SampleBroadcastReceiver.new
    action = '__THE_PACKAGE__.SampleBroadcastReceiver.action'
    filter = android.content.IntentFilter.new(action)
    receiver_ready = false
    Thread.start do
      begin
        android.os.Looper.prepare
        activity.registerReceiver(@receiver, filter, nil, android.os.Handler.new)
        receiver_ready = true
        android.os.Looper.loop
      rescue
        puts 'Exception starting receiver'
        puts $!.message
        puts $!.backtrace.join("\n")
      end
    end
    sleep 0.1 until receiver_ready
    intent = android.content.Intent.new
    intent.set_action action
    activity.send_broadcast(intent)
    bc_sent_at = Time.now

    message = 'Broadcast received!'
    sleep 0.1 until activity.title == message || (Time.now - bc_sent_at) > 10
    assert_equal message, activity.title
  ensure
    activity.unregister_receiver(@receiver) if @receiver
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
ruboto-1.6.1 assets/samples/sample_broadcast_receiver_test.rb
ruboto-1.6.0 assets/samples/sample_broadcast_receiver_test.rb
ruboto-1.5.0 assets/samples/sample_broadcast_receiver_test.rb
ruboto-1.4.1 assets/samples/sample_broadcast_receiver_test.rb
ruboto-1.4.0 assets/samples/sample_broadcast_receiver_test.rb
ruboto-1.3.1 assets/samples/sample_broadcast_receiver_test.rb
ruboto-1.3.0 assets/samples/sample_broadcast_receiver_test.rb
ruboto-1.2.0 assets/samples/sample_broadcast_receiver_test.rb
ruboto-1.1.2 assets/samples/sample_broadcast_receiver_test.rb
ruboto-1.1.1 assets/samples/sample_broadcast_receiver_test.rb
ruboto-1.1.0 assets/samples/sample_broadcast_receiver_test.rb
ruboto-1.0.3 assets/samples/sample_broadcast_receiver_test.rb
ruboto-1.0.2 assets/samples/sample_broadcast_receiver_test.rb
ruboto-1.0.1 assets/samples/sample_broadcast_receiver_test.rb
ruboto-1.0.0 assets/samples/sample_broadcast_receiver_test.rb
ruboto-0.16.0 assets/samples/sample_broadcast_receiver_test.rb
ruboto-0.15.0 assets/samples/sample_broadcast_receiver_test.rb
ruboto-0.14.0 assets/samples/sample_broadcast_receiver_test.rb
ruboto-0.13.0 assets/samples/sample_broadcast_receiver_test.rb
ruboto-0.12.0 assets/samples/sample_broadcast_receiver_test.rb