Skip to content

Commit

Permalink
For mozilla-mobile#11798: Allow sharing of reader view pages
Browse files Browse the repository at this point in the history
  • Loading branch information
csadilek committed Jun 25, 2020
1 parent 2d65faf commit 97e703c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
16 changes: 15 additions & 1 deletion app/src/main/java/org/mozilla/fenix/share/ShareController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import mozilla.components.concept.sync.Device
import mozilla.components.concept.sync.TabData
import mozilla.components.feature.accounts.push.SendTabUseCases
import mozilla.components.feature.share.RecentAppsStorage
import mozilla.components.support.ktx.kotlin.isExtensionUrl
import org.mozilla.fenix.R
import org.mozilla.fenix.components.FenixSnackbar
import org.mozilla.fenix.components.metrics.Event
Expand Down Expand Up @@ -172,7 +173,20 @@ class DefaultShareController(

@VisibleForTesting
fun getShareText() = shareData.joinToString("\n\n") { data ->
data.url.orEmpty()
val url = data.url.orEmpty()
if (url.isExtensionUrl()) {
// Sharing moz-extension:// URLs is not practical in general, as
// they will only work on the current device.

// We solve this for URLs from our reader extension as they contain
// the original URL as a query parameter. This is a workaround for
// now and needs a clean fix once we have a reader specific protocol
// e.g. ext+reader://
// https://github.com/mozilla-mobile/android-components/issues/2879
Uri.parse(url).getQueryParameter("url") ?: url
} else {
url
}
}

// Navigation between app fragments uses ShareTab as arguments. SendTabUseCases uses TabData.
Expand Down
16 changes: 16 additions & 0 deletions app/src/test/java/org/mozilla/fenix/share/ShareControllerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,22 @@ class ShareControllerTest {
assertEquals(textToShare, controller.getShareText())
}

@Test
fun `getShareText attempts to use original URL for reader pages`() {
val shareData = listOf(
ShareData(url = "moz-extension://eb8df45a-895b-4f3a-896a-c0c71ae4/page.html"),
ShareData(url = "moz-extension://eb8df45a-895b-4f3a-896a-c0c71ae5/page.html?url=url0"),
ShareData(url = "url1")
)
val controller = DefaultShareController(
context, shareData, sendTabUseCases, snackbar, navController,
recentAppStorage, testCoroutineScope, dismiss
)

val expectedShareText = "${shareData[0].url}\n\nurl0\n\n${shareData[2].url}"
assertEquals(expectedShareText, controller.getShareText())
}

@Test
fun `ShareTab#toTabData maps a list of ShareTab to a TabData list`() {
var tabData: List<TabData>
Expand Down

0 comments on commit 97e703c

Please sign in to comment.