Search in sources :

Example 6 with AppLink

use of bolts.AppLink in project facebook-android-sdk by facebook.

the class FacebookAppLinkResolverTests method testCachedAppLinkData.

@FlakyTest
public void testCachedAppLinkData() {
    String testUrlString = "https://fb.me/732873156764191";
    Uri testUrl = Uri.parse(testUrlString);
    Uri testWebUri = Uri.parse("http://www.facebook.com/");
    ArrayList<AppLink.Target> testTargets = new ArrayList<AppLink.Target>();
    testTargets.add(new AppLink.Target("com.myapp", null, Uri.parse("myapp://3"), "my app"));
    testTargets.add(new AppLink.Target("com.myapp-test", null, Uri.parse("myapp-test://4"), "my test app"));
    try {
        FacebookAppLinkResolver resolver = new FacebookAppLinkResolver();
        // This will prefetch the app link
        executeResolverOnBlockerThread(resolver, testUrl);
        getTestBlocker().waitForSignals(1);
        assertNotNull(resolveTask);
        // Now let's fetch it again. This should complete the task synchronously.
        Task<AppLink> cachedUrlResolveTask = resolver.getAppLinkFromUrlInBackground(testUrl);
        assertTrue(cachedUrlResolveTask.isCompleted() && !cachedUrlResolveTask.isCancelled() && !cachedUrlResolveTask.isFaulted());
        AppLink appLink = cachedUrlResolveTask.getResult();
        assertEquals(appLink.getSourceUrl(), testUrl);
        assertEquals(appLink.getWebUrl(), testWebUri);
        assertTrue(targetListsAreEqual(appLink.getTargets(), testTargets));
    } catch (Exception e) {
        // Forcing the test to fail with details
        assertNull(e);
    }
}
Also used : FacebookAppLinkResolver(com.facebook.applinks.FacebookAppLinkResolver) ArrayList(java.util.ArrayList) AppLink(bolts.AppLink) Uri(android.net.Uri) FlakyTest(android.test.FlakyTest)

Aggregations

Uri (android.net.Uri)6 AppLink (bolts.AppLink)6 Task (bolts.Task)5 Bundle (android.os.Bundle)3 FacebookAppLinkResolver (com.facebook.applinks.FacebookAppLinkResolver)3 ArrayList (java.util.ArrayList)3 JSONArray (org.json.JSONArray)3 JSONException (org.json.JSONException)3 JSONObject (org.json.JSONObject)3 GraphObject (com.facebook.model.GraphObject)2 FlakyTest (android.test.FlakyTest)1 FacebookRequestError (com.facebook.FacebookRequestError)1 GraphRequest (com.facebook.GraphRequest)1 GraphResponse (com.facebook.GraphResponse)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1