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);
}
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);
}
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());
}
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());
}
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());
}
Aggregations