Search in sources :

Example 6 with LocalBroadcastManager

use of android.support.v4.content.LocalBroadcastManager in project facebook-android-sdk by facebook.

the class AppEventsLoggerTests method testExplicitCallWithNoAppSettings.

public void testExplicitCallWithNoAppSettings() throws InterruptedException {
    AppEventsLogger.setFlushBehavior(AppEventsLogger.FlushBehavior.EXPLICIT_ONLY);
    AccessToken accessToken1 = getFakeAccessToken();
    FacebookSdk.setApplicationId("234");
    AppEventsLogger logger1 = AppEventsLogger.newLogger(getActivity(), accessToken1);
    final WaitForBroadcastReceiver waitForBroadcastReceiver = new WaitForBroadcastReceiver();
    waitForBroadcastReceiver.incrementExpectCount();
    final LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(getActivity());
    try {
        // Need to get notifications on another thread so we can wait for them.
        runOnBlockerThread(new Runnable() {

            @Override
            public void run() {
                broadcastManager.registerReceiver(waitForBroadcastReceiver, new IntentFilter(AppEventsLogger.ACTION_APP_EVENTS_FLUSHED));
            }
        }, true);
        logger1.logEvent("an_event");
        logger1.flush();
        waitForBroadcastReceiver.waitForExpectedCalls();
        closeBlockerAndAssertSuccess();
    } finally {
        broadcastManager.unregisterReceiver(waitForBroadcastReceiver);
    }
}
Also used : IntentFilter(android.content.IntentFilter) WaitForBroadcastReceiver(com.facebook.WaitForBroadcastReceiver) AccessToken(com.facebook.AccessToken) AppEventsLogger(com.facebook.appevents.AppEventsLogger) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager)

Example 7 with LocalBroadcastManager

use of android.support.v4.content.LocalBroadcastManager in project facebook-android-sdk by facebook.

the class AppEventsLoggerTests method testSimpleCall.

public void testSimpleCall() throws InterruptedException {
    AppEventsLogger.setFlushBehavior(AppEventsLogger.FlushBehavior.EXPLICIT_ONLY);
    AccessToken accessToken1 = getAccessTokenForSharedUser();
    AccessToken accessToken2 = getAccessTokenForSharedUser(SECOND_TEST_USER_TAG);
    AppEventsLogger logger1 = AppEventsLogger.newLogger(getActivity(), accessToken1);
    AppEventsLogger logger2 = AppEventsLogger.newLogger(getActivity(), accessToken2);
    final WaitForBroadcastReceiver waitForBroadcastReceiver = new WaitForBroadcastReceiver();
    waitForBroadcastReceiver.incrementExpectCount();
    final LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(getActivity());
    try {
        // Need to get notifications on another thread so we can wait for them.
        runOnBlockerThread(new Runnable() {

            @Override
            public void run() {
                broadcastManager.registerReceiver(waitForBroadcastReceiver, new IntentFilter(AppEventsLogger.ACTION_APP_EVENTS_FLUSHED));
            }
        }, true);
        logger1.logEvent("an_event");
        logger2.logEvent("another_event");
        // test illegal event name and event key, should not crash in non-debug environment.
        logger1.logEvent("$illegal_event_name");
        Bundle params = new Bundle();
        params.putString("illegal%key", "good_value");
        logger1.logEvent("legal_event_name", params);
        char[] val = { 'b', 'a', 'd' };
        params.putCharArray("legal_key", val);
        logger1.logEvent("legal_event", params);
        logger1.flush();
        waitForBroadcastReceiver.waitForExpectedCalls();
        closeBlockerAndAssertSuccess();
    } finally {
        broadcastManager.unregisterReceiver(waitForBroadcastReceiver);
    }
}
Also used : IntentFilter(android.content.IntentFilter) WaitForBroadcastReceiver(com.facebook.WaitForBroadcastReceiver) AccessToken(com.facebook.AccessToken) Bundle(android.os.Bundle) AppEventsLogger(com.facebook.appevents.AppEventsLogger) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager)

Example 8 with LocalBroadcastManager

use of android.support.v4.content.LocalBroadcastManager in project facebook-android-sdk by facebook.

the class ProfileManagerTest method testLoadCurrentProfileEmptyCache.

@Test
public void testLoadCurrentProfileEmptyCache() {
    ProfileCache profileCache = mock(ProfileCache.class);
    LocalBroadcastManager localBroadcastManager = mock(LocalBroadcastManager.class);
    ProfileManager profileManager = new ProfileManager(localBroadcastManager, profileCache);
    assertFalse(profileManager.loadCurrentProfile());
    verify(profileCache, times(1)).load();
}
Also used : LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 9 with LocalBroadcastManager

use of android.support.v4.content.LocalBroadcastManager in project facebook-android-sdk by facebook.

the class ProfileTrackerTest method testStartStopTrackingAndBroadcast.

@Test
public void testStartStopTrackingAndBroadcast() {
    FacebookSdk.sdkInitialize(RuntimeEnvironment.application);
    LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(RuntimeEnvironment.application);
    TestProfileTracker testProfileTracker = new TestProfileTracker();
    // Starts tracking
    assertTrue(testProfileTracker.isTracking());
    testProfileTracker.stopTracking();
    assertFalse(testProfileTracker.isTracking());
    sendBroadcast(localBroadcastManager, null, ProfileTest.createDefaultProfile());
    assertFalse(testProfileTracker.isCallbackCalled);
    testProfileTracker.startTracking();
    assertTrue(testProfileTracker.isTracking());
    Profile profile = ProfileTest.createDefaultProfile();
    sendBroadcast(localBroadcastManager, null, profile);
    assertNull(testProfileTracker.oldProfile);
    assertEquals(profile, testProfileTracker.currentProfile);
    assertTrue(testProfileTracker.isCallbackCalled);
    Profile profile1 = ProfileTest.createMostlyNullsProfile();
    Profile profile2 = ProfileTest.createDefaultProfile();
    sendBroadcast(localBroadcastManager, profile1, profile2);
    ProfileTest.assertMostlyNullsObjectGetters(testProfileTracker.oldProfile);
    ProfileTest.assertDefaultObjectGetters(testProfileTracker.currentProfile);
    assertEquals(profile1, testProfileTracker.oldProfile);
    assertEquals(profile2, testProfileTracker.currentProfile);
    testProfileTracker.stopTracking();
}
Also used : LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager) Test(org.junit.Test)

Example 10 with LocalBroadcastManager

use of android.support.v4.content.LocalBroadcastManager in project facebook-android-sdk by facebook.

the class LikeView method tearDownObjectAssociations.

private void tearDownObjectAssociations() {
    if (broadcastReceiver != null) {
        LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(getContext());
        localBroadcastManager.unregisterReceiver(broadcastReceiver);
        broadcastReceiver = null;
    }
    // register a broadcast receiver for it.
    if (creationCallback != null) {
        creationCallback.cancel();
        creationCallback = null;
    }
    likeActionController = null;
}
Also used : LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager)

Aggregations

LocalBroadcastManager (android.support.v4.content.LocalBroadcastManager)36 IntentFilter (android.content.IntentFilter)15 Intent (android.content.Intent)11 Test (org.junit.Test)10 Context (android.content.Context)9 BroadcastReceiver (android.content.BroadcastReceiver)7 Bundle (android.os.Bundle)3 AccessToken (com.facebook.AccessToken)2 WaitForBroadcastReceiver (com.facebook.WaitForBroadcastReceiver)2 AppEventsLogger (com.facebook.appevents.AppEventsLogger)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Uri (android.net.Uri)1 Parcel (android.os.Parcel)1 Parcelable (android.os.Parcelable)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 RecipeList (com.se491.chef_ly.model.RecipeList)1 IOException (java.io.IOException)1 Type (java.lang.reflect.Type)1