use of android.support.v4.content.LocalBroadcastManager in project Bolts-Android by BoltsFramework.
the class AppLinkTest method testAppLinkNavInEventBroadcast.
public void testAppLinkNavInEventBroadcast() throws Exception {
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com"));
Bundle appLinkData = new Bundle();
appLinkData.putString("target_url", "http://www.example2.com");
Bundle appLinkRefererData = new Bundle();
appLinkRefererData.putString("url", "referer://");
appLinkRefererData.putString("app_name", "Referrer App");
appLinkRefererData.putString("package", "com.bolts.referrer");
appLinkData.putBundle("referer_app_link", appLinkRefererData);
Bundle applinkExtras = new Bundle();
applinkExtras.putString("token", "a_token");
appLinkData.putBundle("extras", applinkExtras);
i.putExtra("al_applink_data", appLinkData);
final CountDownLatch lock = new CountDownLatch(1);
final String[] receivedStrings = new String[7];
LocalBroadcastManager manager = LocalBroadcastManager.getInstance(getInstrumentation().getTargetContext());
manager.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String eventName = intent.getStringExtra("event_name");
Bundle eventArgs = intent.getBundleExtra("event_args");
receivedStrings[0] = eventName;
receivedStrings[1] = eventArgs.getString("targetURL");
receivedStrings[2] = eventArgs.getString("inputURL");
receivedStrings[3] = eventArgs.getString("refererURL");
receivedStrings[4] = eventArgs.getString("refererAppName");
receivedStrings[5] = eventArgs.getString("extras/token");
receivedStrings[6] = eventArgs.getString("sourceApplication");
lock.countDown();
}
}, new IntentFilter("com.parse.bolts.measurement_event"));
Uri targetUrl = AppLinks.getTargetUrlFromInboundIntent(getInstrumentation().getTargetContext(), i);
lock.await(2000, TimeUnit.MILLISECONDS);
assertEquals("al_nav_in", receivedStrings[0]);
assertEquals("http://www.example2.com", receivedStrings[1]);
assertEquals("http://www.example.com", receivedStrings[2]);
assertEquals("referer://", receivedStrings[3]);
assertEquals("Referrer App", receivedStrings[4]);
assertEquals("a_token", receivedStrings[5]);
assertEquals("com.bolts.referrer", receivedStrings[6]);
}
use of android.support.v4.content.LocalBroadcastManager in project robolectric by robolectric.
the class ShadowLocalBroadcastManagerTest method shouldSendBroadcastsWithDataScheme.
@Test
public void shouldSendBroadcastsWithDataScheme() throws Exception {
LocalBroadcastManager instance = LocalBroadcastManager.getInstance(RuntimeEnvironment.application);
final boolean[] called = new boolean[1];
final BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
called[0] = true;
}
};
IntentFilter intentFilter = new IntentFilter("com.foo");
intentFilter.addDataScheme("http");
instance.registerReceiver(receiver, intentFilter);
instance.sendBroadcast(new Intent("com.foo", Uri.parse("ftp://robolectric.org")));
assertFalse(called[0]);
instance.sendBroadcast(new Intent("com.foo", Uri.parse("http://robolectric.org")));
assertTrue(called[0]);
}
use of android.support.v4.content.LocalBroadcastManager in project robolectric by robolectric.
the class ShadowLocalBroadcastManagerTest method shouldUnregisterReceiver.
@Test
public void shouldUnregisterReceiver() throws Exception {
LocalBroadcastManager instance = LocalBroadcastManager.getInstance(RuntimeEnvironment.application);
final boolean[] called = new boolean[1];
final BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
called[0] = true;
}
};
instance.registerReceiver(receiver, new IntentFilter("com.foo"));
instance.unregisterReceiver(receiver);
instance.sendBroadcast(new Intent("com.foo"));
assertFalse(called[0]);
}
use of android.support.v4.content.LocalBroadcastManager in project robolectric by robolectric.
the class ShadowLocalBroadcastManagerTest method testGetSentBroadcastIntents.
@Test
public void testGetSentBroadcastIntents() throws Exception {
LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(RuntimeEnvironment.application);
ShadowLocalBroadcastManager shadowLocalBroadcastManager = shadowOf(broadcastManager);
assertEquals(0, shadowLocalBroadcastManager.getSentBroadcastIntents().size());
Intent broadcastIntent = new Intent("foo");
broadcastManager.sendBroadcast(broadcastIntent);
assertEquals(1, shadowLocalBroadcastManager.getSentBroadcastIntents().size());
assertEquals(broadcastIntent, shadowLocalBroadcastManager.getSentBroadcastIntents().get(0));
}
use of android.support.v4.content.LocalBroadcastManager in project robolectric by robolectric.
the class ShadowLocalBroadcastManagerTest method testGetBroadcastIntents.
@Test
public void testGetBroadcastIntents() throws Exception {
LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(RuntimeEnvironment.application);
broadcastManager.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
transcript.add("got intent " + intent.getAction());
}
}, IntentFilter.create("foo", "application/blatz"));
Intent intent1 = new Intent("foo").setType("application/blatz");
broadcastManager.sendBroadcast(intent1);
Intent intent2 = new Intent("bar").setType("application/blatz");
broadcastManager.sendBroadcast(intent2);
assertThat(transcript).containsExactly("got intent foo");
}
Aggregations