Skip to content

Commit

Permalink
Facebook Android SDK 4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
swiese committed Jun 25, 2015
1 parent a9a791d commit e813a0b
Show file tree
Hide file tree
Showing 87 changed files with 508 additions and 291 deletions.
8 changes: 6 additions & 2 deletions .buckconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
src_roots = /facebook/src/, /samples/HelloFacebookSample/src/

# We target gingerbread. Ensure that libraries target that.
source_level = 6
target_level = 6
source_level = 7
target_level = 7

[build]
build_dependencies = FIRST_ORDER_ONLY

[alias]
sdk = //facebook:android-sdk
hello-facebook = //samples/HelloFacebookSample:app
iconicus = //samples/Iconicus:app
rps = //samples/RPSSample:app
scrumptious = //samples/Scrumptious:app
switch-user = //samples/SwitchUserSample:app
2 changes: 1 addition & 1 deletion .buckversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
62a21e0436bc4b72db9aa7fc2237d9cdf162b29f
edff8b2b8818bb64982837158dd546a66b6ef6c2
8 changes: 4 additions & 4 deletions facebook/BUCK
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
build_config(
name = 'config-debug',
android_build_config(
name = 'build_config',
package = 'com.facebook',
debug = True,
)

android_resource(
Expand All @@ -14,8 +13,9 @@ android_resource(

android_library(
name = 'android-sdk',
srcs = glob(['src/**/*.java']) + [':config-debug'],
srcs = glob(['src/**/*.java']),
deps = [
':build_config',
':res',
'//libs:android-support-v4',
'//libs:bolts',
Expand Down
13 changes: 7 additions & 6 deletions facebook/junitTests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ apply plugin: 'com.android.application'
apply plugin: 'org.robolectric'

android {
// roboelectric doesn't support v21
compileSdkVersion 18
// roboelectric v21 is currently broken for some of our tests
compileSdkVersion 19
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION

defaultConfig {
applicationId "com.facebook.junittests"
minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)
// roboelectric doesn't support v21
targetSdkVersion 18
// roboelectric v21 is currently broken for some of our tests
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
Expand All @@ -39,11 +39,12 @@ dependencies {
def powerMockVersion = '1.6.1'

compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:18.+'
compile 'com.android.support:appcompat-v7:19.+'
compile project(':facebook')

testCompile 'junit:junit:4.12'
testCompile 'org.robolectric:robolectric:2.4'
testCompile 'org.robolectric:robolectric:3.0-rc3'
testCompile 'org.robolectric:shadows-support-v4:3.0-rc3'

// PowerMock brings in the mockito dependency
testCompile "org.powermock:powermock-module-junit4:$powerMockVersion"
Expand Down
6 changes: 3 additions & 3 deletions facebook/junitTests/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
android:label="junitTests"
android:theme="@style/Theme.AppCompat.Light.DarkActionBar" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
android:label="junitTests" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

package com.facebook.junittests;

import android.support.v4.app.FragmentActivity;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
Expand All @@ -28,7 +29,7 @@
import com.facebook.FacebookSdk;


public class MainActivity extends ActionBarActivity {
public class MainActivity extends FragmentActivity {
private static String APP_ID = "1234";
@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down
5 changes: 0 additions & 5 deletions facebook/junitTests/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,4 @@
-->

<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;

import java.util.Arrays;
import java.util.Date;
Expand Down Expand Up @@ -77,7 +78,7 @@ public class AccessTokenCacheTest extends FacebookPowerMockTestCase {
@Before
public void before() throws Exception {
mockStatic(FacebookSdk.class);
sharedPreferences = Robolectric.application.getSharedPreferences(
sharedPreferences = RuntimeEnvironment.application.getSharedPreferences(
AccessTokenManager.SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
sharedPreferences.edit().clear().commit();
cachingStrategyFactory = mock(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;

import java.util.Arrays;
import java.util.Date;
Expand Down Expand Up @@ -64,10 +65,10 @@ public class AccessTokenManagerTest extends FacebookPowerMockTestCase {
public void before() throws Exception {
mockStatic(FacebookSdk.class);
when(FacebookSdk.isInitialized()).thenReturn(true);
when(FacebookSdk.getApplicationContext()).thenReturn(Robolectric.application);
when(FacebookSdk.getApplicationContext()).thenReturn(RuntimeEnvironment.application);
suppress(method(Utility.class, "clearFacebookCookies"));

localBroadcastManager = LocalBroadcastManager.getInstance(Robolectric.application);
localBroadcastManager = LocalBroadcastManager.getInstance(RuntimeEnvironment.application);
accessTokenCache = mock(AccessTokenCache.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;

import java.io.IOException;
import java.util.Arrays;
Expand Down Expand Up @@ -185,7 +186,7 @@ public void testFromCacheWithMissingApplicationId() {
LegacyTokenHelper.putToken(bundle, token);
// no app id

FacebookSdk.sdkInitialize(Robolectric.application);
FacebookSdk.sdkInitialize(RuntimeEnvironment.application);
FacebookSdk.setApplicationId(applicationId);

AccessToken accessToken = AccessToken.createFromLegacyCache(bundle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.junit.Test;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;

import java.util.Arrays;
import java.util.Date;
Expand All @@ -52,9 +53,9 @@ public class AccessTokenTrackerTest extends FacebookPowerMockTestCase {
public void before() throws Exception {
mockStatic(FacebookSdk.class);
when(FacebookSdk.isInitialized()).thenReturn(true);
when(FacebookSdk.getApplicationContext()).thenReturn(Robolectric.application);
when(FacebookSdk.getApplicationContext()).thenReturn(RuntimeEnvironment.application);

localBroadcastManager = LocalBroadcastManager.getInstance(Robolectric.application);
localBroadcastManager = LocalBroadcastManager.getInstance(RuntimeEnvironment.application);
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.junit.Test;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;

import java.io.File;
import java.io.FileNotFoundException;
Expand Down Expand Up @@ -176,7 +177,7 @@ public static void addAttachment(UUID callId, String attachmentName) {
public static File openAttachment(UUID callId, String attachmentName)
throws FileNotFoundException {
if (attachments.contains(new Pair<>(callId, attachmentName))) {
File cacheDir = Robolectric.application.getCacheDir();
File cacheDir = RuntimeEnvironment.application.getCacheDir();
File dummyFile = new File(cacheDir, DUMMY_FILE_NAME);
if (!dummyFile.exists()) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Test;
import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;

import static org.junit.Assert.*;

Expand Down Expand Up @@ -166,6 +169,11 @@ public class FacebookGraphRequestErrorTest extends FacebookTestCase {
" }\n" +
"}";

@Before
public void before() throws Exception {
FacebookSdk.sdkInitialize(RuntimeEnvironment.application);
}

@Test
public void testClientException() {
final String errorMsg = "some error happened";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.reflect.Whitebox;
import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;

import java.util.concurrent.Executor;

Expand Down Expand Up @@ -156,10 +157,10 @@ public void testLoadDefaultsDoesNotOverwrite() throws Exception {

@Test
public void testRequestCodeOffsetAfterInit() throws Exception {
FacebookSdk.sdkInitialize(Robolectric.application);
FacebookSdk.sdkInitialize(RuntimeEnvironment.application);

try {
FacebookSdk.sdkInitialize(Robolectric.application, 1000);
FacebookSdk.sdkInitialize(RuntimeEnvironment.application, 1000);
fail();
} catch (FacebookException exception) {
assertEquals(FacebookSdk.CALLBACK_OFFSET_CHANGED_AFTER_INIT, exception.getMessage());
Expand All @@ -170,7 +171,7 @@ public void testRequestCodeOffsetAfterInit() throws Exception {
public void testRequestCodeOffsetNegative() throws Exception {
try {
// last bit set, so negative
FacebookSdk.sdkInitialize(Robolectric.application, 0xFACEB00C);
FacebookSdk.sdkInitialize(RuntimeEnvironment.application, 0xFACEB00C);
fail();
} catch (FacebookException exception) {
assertEquals(FacebookSdk.CALLBACK_OFFSET_NEGATIVE, exception.getMessage());
Expand All @@ -179,13 +180,13 @@ public void testRequestCodeOffsetNegative() throws Exception {

@Test
public void testRequestCodeOffset() throws Exception {
FacebookSdk.sdkInitialize(Robolectric.application, 1000);
FacebookSdk.sdkInitialize(RuntimeEnvironment.application, 1000);
assertEquals(1000, FacebookSdk.getCallbackRequestCodeOffset());
}

@Test
public void testRequestCodeRange() {
FacebookSdk.sdkInitialize(Robolectric.application, 1000);
FacebookSdk.sdkInitialize(RuntimeEnvironment.application, 1000);
assertTrue(FacebookSdk.isFacebookRequestCode(1000));
assertTrue(FacebookSdk.isFacebookRequestCode(1099));
assertFalse(FacebookSdk.isFacebookRequestCode(999));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;

import java.io.IOException;
import java.net.HttpURLConnection;
Expand Down Expand Up @@ -57,7 +58,7 @@ public void before() throws Exception {
mockStatic(FacebookSdk.class);
suppress(method(Utility.class, "clearFacebookCookies"));
when(FacebookSdk.isInitialized()).thenReturn(true);
when(FacebookSdk.getApplicationContext()).thenReturn(Robolectric.application);
when(FacebookSdk.getApplicationContext()).thenReturn(RuntimeEnvironment.application);
stub(method(AccessTokenCache.class, "save")).toReturn(null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;

import java.lang.reflect.Array;
import java.util.ArrayList;
Expand Down Expand Up @@ -71,7 +72,7 @@ public final class LegacyTokenCacheTest extends FacebookPowerMockTestCase {
public void setUp() {
super.setUp();

FacebookSdk.sdkInitialize(Robolectric.application);
FacebookSdk.sdkInitialize(RuntimeEnvironment.application);
}

@Before
Expand Down Expand Up @@ -106,10 +107,10 @@ public void testAllTypes() {

ensureApplicationContext();

LegacyTokenHelper cache = new LegacyTokenHelper(Robolectric.application);
LegacyTokenHelper cache = new LegacyTokenHelper(RuntimeEnvironment.application);
cache.save(originalBundle);

LegacyTokenHelper cache2 = new LegacyTokenHelper(Robolectric.application);
LegacyTokenHelper cache2 = new LegacyTokenHelper(RuntimeEnvironment.application);
Bundle cachedBundle = cache2.load();

assertEquals(originalBundle.getBoolean(BOOLEAN_KEY), cachedBundle.getBoolean(BOOLEAN_KEY));
Expand Down Expand Up @@ -146,16 +147,18 @@ public void testMultipleCaches() {

ensureApplicationContext();

LegacyTokenHelper cache1 = new LegacyTokenHelper(Robolectric.application);
LegacyTokenHelper cache2 = new LegacyTokenHelper(Robolectric.application, "CustomCache");
LegacyTokenHelper cache1 = new LegacyTokenHelper(RuntimeEnvironment.application);
LegacyTokenHelper cache2 = new LegacyTokenHelper(
RuntimeEnvironment.application,
"CustomCache");

cache1.save(bundle1);
cache2.save(bundle2);

// Get new references to make sure we are getting persisted data.
// Reverse the cache references for fun.
cache1 = new LegacyTokenHelper(Robolectric.application, "CustomCache");
cache2 = new LegacyTokenHelper(Robolectric.application);
cache1 = new LegacyTokenHelper(RuntimeEnvironment.application, "CustomCache");
cache2 = new LegacyTokenHelper(RuntimeEnvironment.application);

Bundle newBundle1 = cache1.load(), newBundle2 = cache2.load();

Expand All @@ -174,7 +177,7 @@ public void testCacheRoundtrip() {
String applicationId = "1234";

LegacyTokenHelper cache =
new LegacyTokenHelper(Robolectric.application);
new LegacyTokenHelper(RuntimeEnvironment.application);
cache.clear();

Bundle bundle = new Bundle();
Expand Down Expand Up @@ -367,7 +370,8 @@ private void ensureApplicationContext() {
long waitedFor = 0;
try {
// Don't hold up execution for too long.
while (Robolectric.application.getApplicationContext() == null && waitedFor <= 2000) {
while (RuntimeEnvironment.application.getApplicationContext() == null
&& waitedFor <= 2000) {
Thread.sleep(50);
waitedFor += 50;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@
import org.junit.Before;
import org.junit.Test;
import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;

import static org.junit.Assert.*;

public final class ProfileCacheTest extends FacebookTestCase {
@Before
public void before() throws Exception {
FacebookSdk.sdkInitialize(Robolectric.application);
Robolectric.application.getSharedPreferences(
FacebookSdk.sdkInitialize(RuntimeEnvironment.application);
RuntimeEnvironment.application.getSharedPreferences(
ProfileCache.SHARED_PREFERENCES_NAME,
Context.MODE_PRIVATE)
.edit().
Expand Down
Loading

0 comments on commit e813a0b

Please sign in to comment.