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