Search in sources :

Example 16 with SafeIntent

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

the class CustomTabConfigTest method oversizedCloseButton.

// Tests that a close bitmap that's too large is ignored:
@Test
public void oversizedCloseButton() throws Exception {
    final int maxSize = RuntimeEnvironment.application.getResources().getDimensionPixelSize(R.dimen.customtabs_toolbar_icon_size);
    final CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
    {
        final Bitmap bitmap = Bitmap.createBitmap(new int[(maxSize + 1) * (maxSize + 1)], maxSize + 1, maxSize + 1, Bitmap.Config.ARGB_8888);
        builder.setCloseButtonIcon(bitmap);
    }
    final CustomTabsIntent customTabsIntent = builder.build();
    final Bitmap bitmap = CustomTabConfig.getCloseButtonIcon(RuntimeEnvironment.application, new SafeIntent(customTabsIntent.intent));
    assertNull(bitmap);
}
Also used : CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Bitmap(android.graphics.Bitmap) SafeIntent(mozilla.components.utils.SafeIntent) Test(org.junit.Test)

Example 17 with SafeIntent

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

the class CustomTabConfigTest method malformedActionButtonConfig.

@Test
public void malformedActionButtonConfig() throws Exception {
    final CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
    final CustomTabsIntent customTabsIntent = builder.build();
    final Bundle garbage = new Bundle();
    garbage.putParcelable("foobar", new UnparcelableParcel());
    customTabsIntent.intent.putExtra(CustomTabsIntent.EXTRA_ACTION_BUTTON_BUNDLE, garbage);
    // We should still detect that this is a custom tab
    assertTrue(CustomTabConfig.isCustomTabIntent(new SafeIntent(customTabsIntent.intent)));
    // And we still don't crash
    final CustomTabConfig.ActionButtonConfig actionButtonConfig = CustomTabConfig.getActionButtonConfig(RuntimeEnvironment.application, new SafeIntent(customTabsIntent.intent));
    // But we weren't able to read the action button data because of the unparcelable data
    assertNull(actionButtonConfig);
}
Also used : CustomTabsIntent(android.support.customtabs.CustomTabsIntent) Bundle(android.os.Bundle) SafeIntent(mozilla.components.utils.SafeIntent) Test(org.junit.Test)

Example 18 with SafeIntent

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

the class SessionManagerTest method testViewIntent.

@Test
public void testViewIntent() {
    final SessionManager sessionManager = SessionManager.getInstance();
    final SafeIntent intent = new SafeIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(TEST_URL)));
    sessionManager.handleIntent(RuntimeEnvironment.application, intent, null);
    final List<Session> sessions = sessionManager.getSessions().getValue();
    assertNotNull(sessions);
    assertEquals(1, sessions.size());
    final Session session = sessions.get(0);
    assertEquals(TEST_URL, session.getUrl().getValue());
    assertFalse(session.isCustomTab());
    assertNull(session.getCustomTabConfig());
    assertTrue(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 19 with SafeIntent

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

the class SessionManagerTest method testNoSessionIsCreatedIfWeAreRestoring.

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

Example 20 with SafeIntent

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

the class SessionManagerTest method testViewIntentWithNullURL.

/**
 * In production we see apps send VIEW intents without an URL. (#1373)
 */
@Test
public void testViewIntentWithNullURL() {
    final SessionManager sessionManager = SessionManager.getInstance();
    assertFalse(sessionManager.hasSession());
    final SafeIntent intent = new SafeIntent(new Intent(Intent.ACTION_VIEW, null));
    sessionManager.handleIntent(RuntimeEnvironment.application, intent, null);
    // We ignored the Intent and no session has been created.
    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)

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