1
0
Fork 0

For #12353: URL copied to clipboard should not be extension/reader URL

master
Christian Sadilek 2020-07-08 15:22:16 -04:00 committed by Emily Kager
parent 9ae1aa6f16
commit 216396d979
2 changed files with 57 additions and 8 deletions

View File

@ -13,6 +13,7 @@ import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.PopupWindow
import androidx.annotation.LayoutRes
import androidx.annotation.VisibleForTesting
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
@ -29,6 +30,8 @@ import kotlinx.android.synthetic.main.component_browser_top_toolbar.*
import kotlinx.android.synthetic.main.component_browser_top_toolbar.view.*
import mozilla.components.browser.domains.autocomplete.ShippedDomainsProvider
import mozilla.components.browser.session.Session
import mozilla.components.browser.state.selector.selectedTab
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.browser.toolbar.BrowserToolbar
import mozilla.components.browser.toolbar.behavior.BrowserToolbarBottomBehavior
import mozilla.components.browser.toolbar.display.DisplayToolbar
@ -94,9 +97,6 @@ class BrowserToolbarView(
view.context.resources.getDimensionPixelSize(R.dimen.context_menu_height),
true
)
val selectedSession = container.context.components.core.sessionManager.selectedSession
popupWindow.elevation =
view.context.resources.getDimension(R.dimen.mozac_browser_menu_elevation)
@ -110,11 +110,7 @@ class BrowserToolbarView(
customView.copy.setOnClickListener {
popupWindow.dismiss()
if (isCustomTabSession) {
clipboard.text = customTabSession?.url
} else {
clipboard.text = selectedSession?.url
}
clipboard.text = getUrlForClipboard(it.context.components.core.store, customTabSession)
FenixSnackbar.make(
view = view,
@ -300,5 +296,15 @@ class BrowserToolbarView(
companion object {
private const val TOOLBAR_ELEVATION = 16
@VisibleForTesting
internal fun getUrlForClipboard(store: BrowserStore, customTabSession: Session? = null): String? {
return if (customTabSession != null) {
customTabSession.url
} else {
val selectedTab = store.state.selectedTab
selectedTab?.readerState?.activeUrl ?: selectedTab?.content?.url
}
}
}
}

View File

@ -0,0 +1,43 @@
/* 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 org.mozilla.fenix.components.toolbar
import io.mockk.every
import io.mockk.mockk
import mozilla.components.browser.session.Session
import mozilla.components.browser.state.state.BrowserState
import mozilla.components.browser.state.state.ReaderState
import mozilla.components.browser.state.state.createTab
import mozilla.components.browser.state.store.BrowserStore
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.components.toolbar.BrowserToolbarView.Companion.getUrlForClipboard
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
@RunWith(FenixRobolectricTestRunner::class)
class BrowserToolbarViewTest {
@Test
fun getUrlForClipboard() {
val customTabSession: Session = mockk()
every { customTabSession.url } returns "https://mozilla.org"
// Custom tab
assertEquals("https://mozilla.org", getUrlForClipboard(mockk(), customTabSession))
// Regular tab
val regularTab = createTab(url = "http://firefox.com")
var store = BrowserStore(BrowserState(tabs = listOf(regularTab), selectedTabId = regularTab.id))
assertEquals(regularTab.content.url, getUrlForClipboard(store))
// Reader Tab
val readerTab = createTab(url = "moz-extension://1234",
readerState = ReaderState(active = true, activeUrl = "https://blog.mozilla.org/123")
)
store = BrowserStore(BrowserState(tabs = listOf(readerTab), selectedTabId = readerTab.id))
assertEquals(readerTab.readerState.activeUrl, getUrlForClipboard(store))
}
}