@Override protected void onStart() { super.onStart(); mCustomTabsDelegate.bindCustomTabsService(this); mKeyDelegate.attach(this); }
@Override protected void onStart() { super.onStart(); mCustomTabsDelegate.bindCustomTabsService(this); mKeyDelegate.attach(this); }
@Test public void testBindService() throws RemoteException { // no chrome installed should not bind service delegate.bindCustomTabsService(activity); assertThat(ShadowApplication.getInstance().getBoundServiceConnections()).isEmpty(); // bind service should create connection shadowOf(RuntimeEnvironment.application.getPackageManager()).addResolveInfoForIntent( new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com")), ShadowResolveInfo.newResolveInfo("label", "com.android.chrome", "DefaultActivity")); shadowOf(RuntimeEnvironment.application.getPackageManager()).addResolveInfoForIntent( new Intent("android.support.customtabs.action.CustomTabsService") .setPackage("com.android.chrome"), ShadowResolveInfo.newResolveInfo("label", "com.android.chrome", "DefaultActivity")); delegate.bindCustomTabsService(activity); List<ServiceConnection> connections = ShadowApplication.getInstance() .getBoundServiceConnections(); assertThat(connections).isNotEmpty(); // on service connected should create session and warm up client verify(service).warmup(anyLong()); assertNotNull(delegate.getSession()); verify(service).newSession(any(ICustomTabsCallback.class)); // may launch url should success when(service.mayLaunchUrl(any(), any(), any(), any())).thenReturn(true); assertTrue(delegate.mayLaunchUrl(Uri.parse("http://www.example.com"), null, null)); // on service disconnected should clear session delegate.unbindCustomTabsService(activity); assertNull(delegate.getSession()); }