use of mozilla.components.utils.SafeIntent in project focus-android by mozilla-mobile.
the class SessionTest method testCustomTabConfiguration.
@Test
public void testCustomTabConfiguration() {
final CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
builder.setToolbarColor(Color.GREEN);
final Intent rawIntent = builder.build().intent;
rawIntent.putExtra(CustomTabConfig.EXTRA_CUSTOM_TAB_ID, UUID.randomUUID().toString());
final SafeIntent intent = new SafeIntent(rawIntent);
final CustomTabConfig customTabConfig = CustomTabConfig.parseCustomTabIntent(RuntimeEnvironment.application, intent);
final Session session = new Session(TEST_URL, customTabConfig);
assertTrue(session.isCustomTab());
assertNotNull(session.getCustomTabConfig());
assertNotNull(session.getCustomTabConfig().toolbarColor);
assertEquals(Color.GREEN, (int) session.getCustomTabConfig().toolbarColor);
}
use of mozilla.components.utils.SafeIntent in project focus-android by mozilla-mobile.
the class CustomTabConfigTest method isCustomTabIntent.
@Test
public void isCustomTabIntent() throws Exception {
final CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
final CustomTabsIntent customTabsIntent = builder.build();
assertTrue(CustomTabConfig.isCustomTabIntent(new SafeIntent(customTabsIntent.intent)));
}
use of mozilla.components.utils.SafeIntent in project focus-android by mozilla-mobile.
the class CustomTabConfigTest method malformedExtras.
@Test
public void malformedExtras() throws Exception {
final CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
final CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.intent.putExtra("garbage", new UnparcelableParcel());
// We write the extras into a parcel so that we can check what happens when unparcelling fails
final Parcel parcel = Parcel.obtain();
final Bundle extras = customTabsIntent.intent.getExtras();
extras.writeToParcel(parcel, 0);
extras.clear();
// Bundle is lazy and doesn't unparcel when calling readBundle()
parcel.setDataPosition(0);
final Bundle injectedBundle = parcel.readBundle();
parcel.recycle();
// We aren't usually allowed to overwrite an intent's extras:
final Field extrasField = Intent.class.getDeclaredField("mExtras");
extrasField.setAccessible(true);
extrasField.set(customTabsIntent.intent, injectedBundle);
extrasField.setAccessible(false);
// And we can't access any extras now because unparcelling fails:
assertFalse(CustomTabConfig.isCustomTabIntent(new SafeIntent(customTabsIntent.intent)));
customTabsIntent.intent.putExtra(CustomTabConfig.EXTRA_CUSTOM_TAB_ID, UUID.randomUUID().toString());
// Ensure we don't crash regardless
final CustomTabConfig c = CustomTabConfig.parseCustomTabIntent(RuntimeEnvironment.application, new SafeIntent(customTabsIntent.intent));
// And we don't have any data:
assertNull(c.actionButtonConfig);
}
use of mozilla.components.utils.SafeIntent in project focus-android by mozilla-mobile.
the class CustomTabConfigTest method closeButton.
// Tests that a small icon is correctly processed
@Test
public void closeButton() throws Exception {
final CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
{
final Bitmap bitmap = Bitmap.createBitmap(new int[] { Color.RED }, 1, 1, Bitmap.Config.ARGB_8888);
builder.setCloseButtonIcon(bitmap);
}
final CustomTabsIntent customTabsIntent = builder.build();
final Bitmap bitmap = CustomTabConfig.getCloseButtonIcon(RuntimeEnvironment.application, new SafeIntent(customTabsIntent.intent));
// An arbitrary 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 menuTest.
@Test
public void menuTest() throws Exception {
final CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
final PendingIntent pendingIntent = PendingIntent.getActivity(null, 0, null, 0);
builder.addMenuItem("menuitem1", pendingIntent);
builder.addMenuItem("menuitem2", pendingIntent);
// We can only handle menu items with an actual PendingIntent, other ones should be ignored:
builder.addMenuItem("menuitemIGNORED", null);
final CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.intent.putExtra(CustomTabConfig.EXTRA_CUSTOM_TAB_ID, UUID.randomUUID().toString());
final CustomTabConfig config = CustomTabConfig.parseCustomTabIntent(RuntimeEnvironment.application, new SafeIntent(customTabsIntent.intent));
assertEquals("Menu should contain 2 items", 2, config.menuItems.size());
final String s = config.menuItems.get(0).name;
assertEquals("Unexpected menu item", "menuitem1", config.menuItems.get(0).name);
assertEquals("Unexpected menu item", "menuitem2", config.menuItems.get(1).name);
}
Aggregations