Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Issue #1303: Move CustomTabService to new feature component: feature-…
Browse files Browse the repository at this point in the history
…customtabs.
  • Loading branch information
pocmo committed Nov 13, 2018
1 parent ae0b2d9 commit 188c140
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 36 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -97,6 +97,8 @@ _Combined components to implement feature-specific use cases._

*[**Awesomebar**](components/feature/awesomebar/README.md) - A component that connects a [concept-awesomebar](components/concept/awesomebar/README.md) implementation to a [concept-toolbar](components/concept/toolbar/README.md) implementation and provides implementations of various suggestion providers.

* 🔴 [**Custom Tabs**](components/feature/customtabs/README.md) - A component for providing [Custom Tabs](https://developer.chrome.com/multidevice/android/customtabs) functionality in browsers.

*[**Downloads**](components/feature/downloads/README.md) - A component to perform downloads using the [Android downloads manager](https://developer.android.com/reference/android/app/DownloadManager).

* 🔴 [**Intent**](components/feature/intent/README.md) - A component that provides intent processing functionality by combining various other feature modules.
Expand Down

This file was deleted.

19 changes: 19 additions & 0 deletions components/feature/customtabs/README.md
@@ -0,0 +1,19 @@
# [Android Components](../../../README.md) > Feature > Custom Tabs

A component for providing [Custom Tabs](https://developer.chrome.com/multidevice/android/customtabs) functionality in browsers.

## Usage

### Setting up the dependency

Use Gradle to download the library from [maven.mozilla.org](https://maven.mozilla.org/) ([Setup repository](../../../README.md#maven-repository)):

```Groovy
implementation "org.mozilla.components:feature-customtabs:{latest-version}"
```

## License

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/
37 changes: 37 additions & 0 deletions components/feature/customtabs/build.gradle
@@ -0,0 +1,37 @@
/* 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/. */

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion Config.compileSdkVersion

defaultConfig {
minSdkVersion Config.minSdkVersion
targetSdkVersion Config.targetSdkVersion
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation Deps.kotlin_stdlib

implementation Deps.support_customtabs

testImplementation project(':support-test')

testImplementation Deps.testing_junit
testImplementation Deps.testing_robolectric
testImplementation Deps.testing_mockito
}

apply from: '../../../publish.gradle'
ext.configurePublish(Config.componentsGroupId, archivesBaseName, gradle.componentDescriptions[archivesBaseName])
21 changes: 21 additions & 0 deletions components/feature/customtabs/proguard-rules.pro
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
5 changes: 5 additions & 0 deletions components/feature/customtabs/src/main/AndroidManifest.xml
@@ -0,0 +1,5 @@
<!-- 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/. -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mozilla.components.feature.customtabs" />
@@ -0,0 +1,57 @@
/* 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.feature.customtabs

import android.app.Service
import android.net.Uri
import android.os.Bundle
import android.support.customtabs.CustomTabsSessionToken

/**
* [Service] providing Custom Tabs related functionality.
*/
class CustomTabsService : android.support.customtabs.CustomTabsService() {
override fun warmup(flags: Long): Boolean {
return true
}

override fun requestPostMessageChannel(sessionToken: CustomTabsSessionToken?, postMessageOrigin: Uri?): Boolean {
return false
}

override fun newSession(sessionToken: CustomTabsSessionToken?): Boolean {
return true
}

override fun extraCommand(commandName: String?, args: Bundle?): Bundle? {
return null
}

override fun mayLaunchUrl(
sessionToken: CustomTabsSessionToken?,
url: Uri?,
extras: Bundle?,
otherLikelyBundles: MutableList<Bundle>?
): Boolean {
return true
}

override fun postMessage(sessionToken: CustomTabsSessionToken?, message: String?, extras: Bundle?): Int {
return 0
}

override fun validateRelationship(
sessionToken: CustomTabsSessionToken?,
relation: Int,
origin: Uri?,
extras: Bundle?
): Boolean {
return false
}

override fun updateVisuals(sessionToken: CustomTabsSessionToken?, bundle: Bundle?): Boolean {
return false
}
}
Expand Up @@ -7,15 +7,19 @@ package mozilla.components.browser.session.tab
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
import mozilla.components.feature.customtabs.CustomTabsService
import mozilla.components.support.test.mock
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.doReturn
import org.mockito.Mockito.mock
import org.robolectric.RobolectricTestRunner

Expand All @@ -29,20 +33,24 @@ class CustomTabsServiceTest {
assertNotNull(customTabsServiceStub)

val stub = customTabsServiceStub as ICustomTabsService.Stub

val callback = mock(ICustomTabsCallback::class.java)
doReturn(mock<IBinder>()).`when`(callback).asBinder()

assertTrue(stub.warmup(123))
assertTrue(stub.newSession(mock(ICustomTabsCallback::class.java)))
assertTrue(stub.newSession(callback))
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)))
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>()))
mock(ICustomTabsCallback::class.java),
mock(Uri::class.java),
mock(Bundle::class.java), emptyList<Bundle>()))
}
}
1 change: 1 addition & 0 deletions settings.gradle
Expand Up @@ -40,6 +40,7 @@ setupProject(':concept-storage', 'components/concept/storage', 'An abstract defi
////////////////////////////////////////////////////////////////////////////////////////////////////

setupProject(':feature-awesomebar', 'components/feature/awesomebar', 'Component connecting a concept-toolbar with a concept-awesomebar.')
setupProject(':feature-customtabs', 'components/feature/customtabs', 'Component for providing custom tabs functionality.')
setupProject(':feature-intent', 'components/feature/intent', 'Combining various feature components for intent processing.')
setupProject(':feature-search', 'components/feature/search', 'Feature implementation connecting an engine implementation with the search module.')
setupProject(':feature-session', 'components/feature/session', 'Feature implementation connecting an engine implementation with the session module.')
Expand Down

0 comments on commit 188c140

Please sign in to comment.