This repository has been archived by the owner on Nov 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 473
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #282: Process CustomTab intents
- Loading branch information
Showing
25 changed files
with
352 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...browser/session/src/main/java/mozilla/components/browser/session/tab/CustomTabsService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package mozilla.components.browser.session.tab | ||
|
||
import android.app.Service | ||
import android.content.Intent | ||
import android.net.Uri | ||
import android.os.Bundle | ||
import android.os.IBinder | ||
import android.support.customtabs.ICustomTabsCallback | ||
import android.support.customtabs.ICustomTabsService | ||
|
||
class CustomTabsService : Service() { | ||
override fun onBind(intent: Intent): IBinder? { | ||
return object : ICustomTabsService.Stub() { | ||
override fun warmup(flags: Long): Boolean = true | ||
override fun newSession(cb: ICustomTabsCallback) = true | ||
override fun mayLaunchUrl(cb: ICustomTabsCallback, url: Uri, extras: Bundle, bundles: List<Bundle>) = true | ||
override fun extraCommand(s: String, bundle: Bundle): Bundle? = null | ||
override fun updateVisuals(cb: ICustomTabsCallback, bundle: Bundle) = false | ||
override fun requestPostMessageChannel(cb: ICustomTabsCallback, uri: Uri): Boolean = false | ||
override fun postMessage(cb: ICustomTabsCallback, s: String, bundle: Bundle): Int = 0 | ||
override fun validateRelationship(cb: ICustomTabsCallback, i: Int, uri: Uri, bundle: Bundle) = false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...ser/session/src/test/java/mozilla/components/browser/session/tab/CustomTabsServiceTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package mozilla.components.browser.session.tab | ||
|
||
import android.content.Intent | ||
import android.net.Uri | ||
import android.os.Bundle | ||
import android.support.customtabs.ICustomTabsCallback | ||
import android.support.customtabs.ICustomTabsService | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Assert.assertFalse | ||
import org.junit.Assert.assertNotNull | ||
import org.junit.Assert.assertNull | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.mockito.Mockito.mock | ||
import org.robolectric.RobolectricTestRunner | ||
|
||
@RunWith(RobolectricTestRunner::class) | ||
class CustomTabsServiceTest { | ||
|
||
@Test | ||
fun testCustomTabService() { | ||
val customTabsService = CustomTabsService() | ||
val customTabsServiceStub = customTabsService.onBind(mock(Intent::class.java)) | ||
assertNotNull(customTabsServiceStub) | ||
|
||
val stub = customTabsServiceStub as ICustomTabsService.Stub | ||
assertTrue(stub.warmup(123)) | ||
assertTrue(stub.newSession(mock(ICustomTabsCallback::class.java))) | ||
assertNull(stub.extraCommand("", mock(Bundle::class.java))) | ||
assertFalse(stub.updateVisuals(mock(ICustomTabsCallback::class.java), mock(Bundle::class.java))) | ||
assertFalse(stub.requestPostMessageChannel(mock(ICustomTabsCallback::class.java), mock(Uri::class.java))) | ||
assertEquals(0, stub.postMessage(mock(ICustomTabsCallback::class.java), "", mock(Bundle::class.java))) | ||
assertFalse(stub.validateRelationship( | ||
mock(ICustomTabsCallback::class.java), | ||
0, | ||
mock(Uri::class.java), | ||
mock(Bundle::class.java))) | ||
assertTrue(stub.mayLaunchUrl( | ||
mock(ICustomTabsCallback::class.java), | ||
mock(Uri::class.java), | ||
mock(Bundle::class.java), emptyList<Bundle>())) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.