Search in sources :

Example 6 with SafeIntent

use of mozilla.components.utils.SafeIntent in project focus-android by mozilla-mobile.

the class CustomTabConfigTest method actionButtonConfig.

@Test
public void actionButtonConfig() throws Exception {
    final CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
    final String description = "description";
    final String intentAction = "ACTION";
    {
        final Bitmap bitmap = Bitmap.createBitmap(new int[] { Color.RED }, 1, 1, Bitmap.Config.ARGB_8888);
        final PendingIntent intent = PendingIntent.getActivity(RuntimeEnvironment.application, 0, new Intent(intentAction), 0);
        builder.setActionButton(bitmap, description, intent);
    }
    final CustomTabsIntent customTabsIntent = builder.build();
    final CustomTabConfig.ActionButtonConfig actionButtonConfig = CustomTabConfig.getActionButtonConfig(RuntimeEnvironment.application, new SafeIntent(customTabsIntent.intent));
    assertEquals(description, actionButtonConfig.description);
    assertNotNull(actionButtonConfig.pendingIntent);
    final Bitmap bitmap = actionButtonConfig.icon;
    assertEquals(1, bitmap.getWidth());
    assertEquals(1, bitmap.getHeight());
    assertEquals(Color.RED, bitmap.getPixel(0, 0));
}
Also used : CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Bitmap(android.graphics.Bitmap) SafeIntent(mozilla.components.utils.SafeIntent) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) SafeIntent(mozilla.components.utils.SafeIntent) PendingIntent(android.app.PendingIntent) Test(org.junit.Test)

Example 7 with SafeIntent

use of mozilla.components.utils.SafeIntent in project focus-android by mozilla-mobile.

the class CustomTabConfigTest method idIsRequired.

// Test that parser throws an exception if no ID is in the intent
@Test(expected = IllegalArgumentException.class)
public void idIsRequired() {
    final CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
    final CustomTabsIntent customTabsIntent = builder.build();
    CustomTabConfig.parseCustomTabIntent(RuntimeEnvironment.application, new SafeIntent(customTabsIntent.intent));
}
Also used : CustomTabsIntent(android.support.customtabs.CustomTabsIntent) SafeIntent(mozilla.components.utils.SafeIntent) Test(org.junit.Test)

Example 8 with SafeIntent

use of mozilla.components.utils.SafeIntent in project focus-android by mozilla-mobile.

the class SessionManagerTest method testTransformingCustomTabIntoRegularSession.

@Test
public void testTransformingCustomTabIntoRegularSession() {
    final String customTabId = "342d6440-760a-43ba-86c4-fe896eb20a29";
    final SessionManager sessionManager = SessionManager.getInstance();
    assertFalse(sessionManager.hasSession());
    assertEquals(0, sessionManager.getCustomTabSessions().getValue().size());
    assertEquals(0, sessionManager.getSessions().getValue().size());
    final SafeIntent intent = new SafeIntent(new CustomTabsIntent.Builder().build().intent.setData(Uri.parse(TEST_URL)).putExtra(CustomTabConfig.EXTRA_CUSTOM_TAB_ID, customTabId));
    sessionManager.handleIntent(RuntimeEnvironment.application, intent, null);
    assertFalse(sessionManager.hasSession());
    assertEquals(1, sessionManager.getCustomTabSessions().getValue().size());
    assertEquals(0, sessionManager.getSessions().getValue().size());
    final Session session = sessionManager.getCustomTabSessionByCustomTabId(customTabId);
    assertNotNull(session);
    assertTrue(session.isCustomTab());
    assertEquals(Source.CUSTOM_TAB, session.getSource());
    assertNotNull(session.getCustomTabConfig());
    sessionManager.moveCustomTabToRegularSessions(session);
    assertTrue(sessionManager.hasSession());
    assertEquals(0, sessionManager.getCustomTabSessions().getValue().size());
    assertEquals(1, sessionManager.getSessions().getValue().size());
    assertFalse(session.isCustomTab());
    assertEquals(Source.NONE, session.getSource());
    assertNull(session.getCustomTabConfig());
}
Also used : CustomTabsIntent(android.support.customtabs.CustomTabsIntent) SafeIntent(mozilla.components.utils.SafeIntent) Test(org.junit.Test)

Example 9 with SafeIntent

use of mozilla.components.utils.SafeIntent in project focus-android by mozilla-mobile.

the class SessionManagerTest method testViewIntentFromHistoryIsIgnored.

@Test
public void testViewIntentFromHistoryIsIgnored() {
    final SessionManager sessionManager = SessionManager.getInstance();
    final Intent unsafeIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(TEST_URL));
    unsafeIntent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);
    final SafeIntent intent = new SafeIntent(unsafeIntent);
    sessionManager.handleIntent(RuntimeEnvironment.application, intent, null);
    final List<Session> sessions = sessionManager.getSessions().getValue();
    assertNotNull(sessions);
    assertEquals(0, sessions.size());
    assertFalse(sessionManager.hasSession());
}
Also used : SafeIntent(mozilla.components.utils.SafeIntent) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Intent(android.content.Intent) SafeIntent(mozilla.components.utils.SafeIntent) Test(org.junit.Test)

Example 10 with SafeIntent

use of mozilla.components.utils.SafeIntent in project focus-android by mozilla-mobile.

the class SessionManagerTest method testSeparateCustomTabSessions.

@Test
public void testSeparateCustomTabSessions() {
    final String customTabId = "342d6440-760a-43ba-86c4-fe896eb20a29";
    final SessionManager sessionManager = SessionManager.getInstance();
    assertFalse(sessionManager.hasSession());
    assertEquals(0, sessionManager.getCustomTabSessions().getValue().size());
    final SafeIntent intent = new SafeIntent(new CustomTabsIntent.Builder().build().intent.setData(Uri.parse(TEST_URL)).putExtra(CustomTabConfig.EXTRA_CUSTOM_TAB_ID, customTabId));
    sessionManager.handleIntent(RuntimeEnvironment.application, intent, null);
    assertFalse(sessionManager.hasSession());
    assertEquals(1, sessionManager.getCustomTabSessions().getValue().size());
    assertNotNull(sessionManager.getCustomTabSessionByCustomTabId(customTabId));
}
Also used : CustomTabsIntent(android.support.customtabs.CustomTabsIntent) SafeIntent(mozilla.components.utils.SafeIntent) Test(org.junit.Test)

Aggregations

SafeIntent (mozilla.components.utils.SafeIntent)23 CustomTabsIntent (android.support.customtabs.CustomTabsIntent)20 Test (org.junit.Test)19 Intent (android.content.Intent)10 Bitmap (android.graphics.Bitmap)5 PendingIntent (android.app.PendingIntent)3 Bundle (android.os.Bundle)3 CustomTabConfig (org.mozilla.focus.customtabs.CustomTabConfig)2 Parcel (android.os.Parcel)1 RequiresApi (android.support.annotation.RequiresApi)1 Field (java.lang.reflect.Field)1