use of mozilla.components.utils.SafeIntent in project focus-android by mozilla-mobile.
the class SessionManagerTest method testShareIntentWithTextViaNewIntent.
public void testShareIntentWithTextViaNewIntent() {
final SessionManager sessionManager = SessionManager.getInstance();
final Intent unsafeIntent = new Intent(Intent.ACTION_SEND);
unsafeIntent.putExtra(Intent.EXTRA_TEXT, "Hello World Focus");
sessionManager.handleNewIntent(RuntimeEnvironment.application, new SafeIntent(unsafeIntent));
final List<Session> sessions = sessionManager.getSessions().getValue();
assertNotNull(sessions);
assertEquals(1, sessions.size());
final Session session = sessions.get(0);
assertTrue(session.isSearch());
assertEquals("Hello World Focus", session.getSearchTerms());
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 testCustomTabIntent.
@Test
public void testCustomTabIntent() {
final SessionManager sessionManager = SessionManager.getInstance();
final SafeIntent intent = new SafeIntent(new CustomTabsIntent.Builder().setToolbarColor(Color.GREEN).addDefaultShareMenuItem().build().intent.setData(Uri.parse(TEST_URL)).putExtra(CustomTabConfig.EXTRA_CUSTOM_TAB_ID, UUID.randomUUID().toString()));
sessionManager.handleIntent(RuntimeEnvironment.application, intent, null);
final List<Session> sessions = sessionManager.getSessions().getValue();
assertNotNull(sessions);
assertEquals(0, sessions.size());
final List<Session> customTabSessions = sessionManager.getCustomTabSessions().getValue();
assertNotNull(customTabSessions);
assertEquals(1, customTabSessions.size());
final Session session = customTabSessions.get(0);
assertEquals(TEST_URL, session.getUrl().getValue());
assertTrue(session.isCustomTab());
assertNotNull(session.getCustomTabConfig());
final CustomTabConfig config = session.getCustomTabConfig();
assertNotNull(config.toolbarColor);
assertEquals(Color.GREEN, config.toolbarColor.intValue());
assertTrue(config.showShareMenuItem);
assertFalse(sessionManager.hasSession());
}
use of mozilla.components.utils.SafeIntent in project focus-android by mozilla-mobile.
the class TextActionActivity method onCreate.
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final SafeIntent intent = new SafeIntent(getIntent());
final CharSequence searchTextCharSequence = intent.getCharSequenceExtra(Intent.EXTRA_PROCESS_TEXT);
final String searchText;
if (searchTextCharSequence != null) {
searchText = searchTextCharSequence.toString();
} else {
searchText = "";
}
final String searchUrl = UrlUtils.createSearchUrl(this, searchText);
final Intent searchIntent = new Intent(this, MainActivity.class);
searchIntent.setAction(Intent.ACTION_VIEW);
searchIntent.putExtra(MainActivity.EXTRA_TEXT_SELECTION, true);
searchIntent.setData(Uri.parse(searchUrl));
startActivity(searchIntent);
finish();
}
use of mozilla.components.utils.SafeIntent in project focus-android by mozilla-mobile.
the class CustomTabConfigTest method malformedCloseButton.
// Tests that a non-Bitmap is ignored
@Test
public void malformedCloseButton() throws Exception {
final CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
final CustomTabsIntent customTabsIntent = builder.build();
// Intent is a parcelable but not a Bitmap
customTabsIntent.intent.putExtra(CustomTabsIntent.EXTRA_CLOSE_BUTTON_ICON, new Intent());
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 maxSizeCloseButton.
// Tests that a max-size bitmap is OK:
@Test
public void maxSizeCloseButton() 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 * maxSize], maxSize, maxSize, 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
assertNotNull(bitmap);
assertEquals(maxSize, bitmap.getWidth());
assertEquals(maxSize, bitmap.getHeight());
}
Aggregations