Search in sources :

Example 16 with AccessToken

use of com.facebook.AccessToken in project facebook-android-sdk by facebook.

the class WebViewLoginMethodHandlerTest method testFromDialog.

@Test
public void testFromDialog() {
    List<String> permissions = Utility.arrayList("stream_publish", "go_outside_and_play");
    String token = "AnImaginaryTokenValue";
    String userId = "1000";
    Bundle bundle = new Bundle();
    bundle.putString("access_token", token);
    bundle.putString("expires_in", "60");
    bundle.putString("signed_request", SIGNED_REQUEST_STR);
    AccessToken accessToken = LoginMethodHandler.createAccessTokenFromWebBundle(permissions, bundle, AccessTokenSource.WEB_VIEW, "1234");
    TestUtils.assertSamePermissions(permissions, accessToken);
    assertEquals(token, accessToken.getToken());
    assertEquals(AccessTokenSource.WEB_VIEW, accessToken.getSource());
    assertTrue(!accessToken.isExpired());
}
Also used : Bundle(android.os.Bundle) AccessToken(com.facebook.AccessToken) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 17 with AccessToken

use of com.facebook.AccessToken in project facebook-android-sdk by facebook.

the class WebViewLoginMethodHandlerTest method testWebViewHandlesSuccess.

@Test
public void testWebViewHandlesSuccess() {
    Bundle bundle = new Bundle();
    bundle.putString("access_token", ACCESS_TOKEN);
    bundle.putString("expires_in", String.format("%d", EXPIRES_IN_DELTA));
    bundle.putString("code", "Something else");
    bundle.putString("signed_request", SIGNED_REQUEST_STR);
    WebViewLoginMethodHandler handler = new WebViewLoginMethodHandler(mockLoginClient);
    LoginClient.Request request = createRequest();
    handler.onWebDialogComplete(request, bundle, null);
    ArgumentCaptor<LoginClient.Result> resultArgumentCaptor = ArgumentCaptor.forClass(LoginClient.Result.class);
    verify(mockLoginClient, times(1)).completeAndValidate(resultArgumentCaptor.capture());
    LoginClient.Result result = resultArgumentCaptor.getValue();
    assertNotNull(result);
    assertEquals(LoginClient.Result.Code.SUCCESS, result.code);
    AccessToken token = result.token;
    assertNotNull(token);
    assertEquals(ACCESS_TOKEN, token.getToken());
    assertDateDiffersWithinDelta(new Date(), token.getExpires(), EXPIRES_IN_DELTA * 1000, 1000);
    TestUtils.assertSamePermissions(PERMISSIONS, token.getPermissions());
}
Also used : Bundle(android.os.Bundle) AccessToken(com.facebook.AccessToken) Date(java.util.Date) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 18 with AccessToken

use of com.facebook.AccessToken in project facebook-android-sdk by facebook.

the class WebViewLoginMethodHandlerTest method testFromSSOWithExpiresLong.

@Test
public void testFromSSOWithExpiresLong() {
    List<String> permissions = Utility.arrayList("stream_publish", "go_outside_and_play");
    String token = "AnImaginaryTokenValue";
    Intent intent = new Intent();
    intent.putExtra("access_token", token);
    intent.putExtra("expires_in", 60L);
    intent.putExtra("extra_extra", "Something unrelated");
    intent.putExtra("signed_request", SIGNED_REQUEST_STR);
    AccessToken accessToken = LoginMethodHandler.createAccessTokenFromWebBundle(permissions, intent.getExtras(), AccessTokenSource.FACEBOOK_APPLICATION_WEB, "1234");
    TestUtils.assertSamePermissions(permissions, accessToken);
    assertEquals(token, accessToken.getToken());
    assertEquals(AccessTokenSource.FACEBOOK_APPLICATION_WEB, accessToken.getSource());
    assertTrue(!accessToken.isExpired());
}
Also used : AccessToken(com.facebook.AccessToken) Intent(android.content.Intent) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 19 with AccessToken

use of com.facebook.AccessToken in project facebook-android-sdk by facebook.

the class LoginClientTest method testReauthorizationWithSameFbidSucceeds.

@Test
public void testReauthorizationWithSameFbidSucceeds() throws Exception {
    FacebookSdk.sdkInitialize(RuntimeEnvironment.application);
    LoginClient.Request request = createRequest(ACCESS_TOKEN);
    AccessToken token = new AccessToken(ACCESS_TOKEN, APP_ID, USER_ID, PERMISSIONS, null, null, null, null);
    LoginClient.Result result = LoginClient.Result.createTokenResult(request, token);
    LoginClient.OnCompletedListener listener = mock(LoginClient.OnCompletedListener.class);
    LoginClient client = new LoginClient(mockFragment);
    client.setOnCompletedListener(listener);
    client.completeAndValidate(result);
    ArgumentCaptor<LoginClient.Result> resultArgumentCaptor = ArgumentCaptor.forClass(LoginClient.Result.class);
    verify(listener).onCompleted(resultArgumentCaptor.capture());
    result = resultArgumentCaptor.getValue();
    assertNotNull(result);
    assertEquals(LoginClient.Result.Code.SUCCESS, result.code);
    AccessToken resultToken = result.token;
    assertNotNull(resultToken);
    assertEquals(ACCESS_TOKEN, resultToken.getToken());
    // We don't care about ordering.
    assertEquals(PERMISSIONS, resultToken.getPermissions());
}
Also used : AccessToken(com.facebook.AccessToken) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 20 with AccessToken

use of com.facebook.AccessToken in project facebook-android-sdk by facebook.

the class LoginManagerTest method testLogInWithPublishAndAccessTokenCreatesReauthRequest.

@Test
public void testLogInWithPublishAndAccessTokenCreatesReauthRequest() {
    AccessToken accessToken = createAccessToken();
    stub(method(AccessToken.class, "getCurrentAccessToken")).toReturn(accessToken);
    LoginManager loginManager = new LoginManager();
    loginManager.logInWithPublishPermissions(mockActivity, Arrays.asList("publish_actions", "publish_stream"));
    int loginRequestCode = CallbackManagerImpl.RequestCodeOffset.Login.toRequestCode();
    verify(mockActivity, times(1)).startActivityForResult(any(Intent.class), eq(loginRequestCode));
}
Also used : AccessToken(com.facebook.AccessToken) Intent(android.content.Intent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

AccessToken (com.facebook.AccessToken)49 Test (org.junit.Test)16 Bundle (android.os.Bundle)14 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)13 Date (java.util.Date)9 Intent (android.content.Intent)8 AccessTokenTracker (com.facebook.AccessTokenTracker)7 FacebookException (com.facebook.FacebookException)7 GraphRequest (com.facebook.GraphRequest)5 GraphResponse (com.facebook.GraphResponse)4 JSONObject (org.json.JSONObject)4 JSONException (org.json.JSONException)3 IntentFilter (android.content.IntentFilter)2 LocalBroadcastManager (android.support.v4.content.LocalBroadcastManager)2 LargeTest (android.test.suitebuilder.annotation.LargeTest)2 Profile (com.facebook.Profile)2 ProfileTracker (com.facebook.ProfileTracker)2 TestBlocker (com.facebook.TestBlocker)2 WaitForBroadcastReceiver (com.facebook.WaitForBroadcastReceiver)2 AppEventsLogger (com.facebook.appevents.AppEventsLogger)2