2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-11 13:11:01 +00:00

For #4155: Adds tests for browser toolbar popup menu

This commit is contained in:
Sawyer Blatz 2019-09-05 08:44:40 -07:00
parent fdd2b59fb8
commit 52fd327bc0
5 changed files with 76 additions and 157 deletions

View File

@ -46,7 +46,6 @@ class BrowserToolbarView(
val toolbarIntegration: ToolbarIntegration
init {
view.setOnUrlLongClickListener {
val popup = PopupMenu(view.context, view)
popup.menuInflater.inflate(R.menu.browser_toolbar_popup_menu, popup.menu)

View File

@ -872,12 +872,4 @@
<string name="add_to_homescreen_cancel">Cancel</string>
<!-- Add button text for the Add to Homescreen dialog -->
<string name="add_to_homescreen_add">Add</string>
<!-- Browser long press popup menu -->
<!-- Copy the current url -->
<string name="browser_toolbar_long_press_popup_copy">Copy</string>
<!-- Paste & go the text in the clipboard. '&amp;' is replaced with the ampersand symbol: & -->
<string name="browser_toolbar_long_press_popup_paste_and_go">Paste &amp; Go</string>
<!-- Paste the text in the clipboard -->
<string name="browser_toolbar_long_press_popup_paste">Paste</string>
</resources>

View File

@ -15,6 +15,7 @@
<item name="android:colorAccent">@color/primary_text_normal_theme</item>
<item name="android:textColorPrimary">@color/primary_text_normal_theme</item>
<item name="android:textColorSecondary">@color/secondary_text_normal_theme</item>
<item name="android:popupMenuStyle">@style/PopupMenu</item>
<item name="alertDialogStyle">@style/DialogStyleNormal</item>
<item name="alertDialogTheme">@style/DialogStyleNormal</item>
@ -98,6 +99,7 @@
<item name="android:colorControlActivated">@color/accent_high_contrast_private_theme</item>
<item name="android:textColorPrimary">@color/primary_text_private_theme</item>
<item name="android:textColorSecondary">@color/secondary_text_private_theme</item>
<item name="android:popupMenuStyle">@style/PopupMenu</item>
<item name="alertDialogStyle">@style/DialogStyleDark</item>
<item name="alertDialogTheme">@style/DialogStyleDark</item>
@ -136,7 +138,6 @@
<item name="privateBrowsingButtonBackground">@color/primary_text_private_theme</item>
<item name="privateBrowsingButtonAccent">@color/above_private_theme</item>
<item name="shieldLottieFile">@raw/shield_json_dark</item>
</style>
<style name="Mozac.Browser.Menu" parent="" tools:ignore="UnusedResources">
@ -300,6 +301,11 @@
<item name="android:background">@drawable/onboarding_card_background_dark</item>
</style>
<style name="PopupMenu" parent="@android:style/Widget.PopupMenu">
<item name="android:dropDownHorizontalOffset">16dp</item>
<item name="android:popupBackground">@drawable/rounded_all_corners</item>
</style>
<style name="CreateCollectionDialogStyle" parent="DialogStyleBase"/>
<style name="FirefoxAccountsDialogStyle" parent="DialogStyleBase">
<item name="android:windowBackground">@drawable/scrim_background</item>

View File

@ -7,6 +7,7 @@ import io.mockk.just
import io.mockk.mockk
import io.mockk.verify
import mozilla.components.browser.session.Session
import org.junit.Before
import org.junit.Test
import org.mozilla.fenix.browser.readermode.ReaderModeController
@ -18,20 +19,46 @@ import org.mozilla.fenix.quickactionsheet.QuickActionSheetController
class BrowserInteractorTest {
val metrics: MetricController = mockk()
val context: Context = mockk()
val browserStore: BrowserFragmentStore = mockk(relaxed = true)
val browserToolbarController: BrowserToolbarController = mockk(relaxed = true)
val quickActionSheetController: QuickActionSheetController = mockk(relaxed = true)
val readerModeController: ReaderModeController = mockk(relaxed = true)
val session: Session = mockk()
val interactor = BrowserInteractor(
context,
browserStore,
browserToolbarController,
quickActionSheetController,
readerModeController,
session
)
@Before
fun setup() {
every { context.metrics } returns metrics
every { context.components.core.sessionManager.selectedSession } returns session
}
@Test
fun onBrowserToolbarPaste() {
val pastedText = "Mozilla"
interactor.onBrowserToolbarPaste(pastedText)
verify { browserToolbarController.handleToolbarPaste(pastedText) }
}
@Test
fun onBrowserToolbarPasteAndGo() {
val pastedText = "Mozilla"
interactor.onBrowserToolbarPasteAndGo(pastedText)
verify { browserToolbarController.handleToolbarPasteAndGo(pastedText) }
}
@Test
fun onBrowserToolbarClicked() {
val context: Context = mockk()
val browserToolbarController: BrowserToolbarController = mockk(relaxed = true)
val interactor = BrowserInteractor(
context,
mockk(),
browserToolbarController,
mockk(),
mockk(),
mockk()
)
interactor.onBrowserToolbarClicked()
verify { browserToolbarController.handleToolbarClick() }
@ -39,19 +66,8 @@ class BrowserInteractorTest {
@Test
fun onBrowserToolbarMenuItemTapped() {
val context: Context = mockk()
val browserToolbarController: BrowserToolbarController = mockk(relaxed = true)
val item: ToolbarMenu.Item = mockk()
val interactor = BrowserInteractor(
context,
mockk(),
browserToolbarController,
mockk(),
mockk(),
mockk()
)
interactor.onBrowserToolbarMenuItemTapped(item)
verify { browserToolbarController.handleToolbarItemInteraction(item) }
@ -59,18 +75,6 @@ class BrowserInteractorTest {
@Test
fun onQuickActionSheetOpened() {
val context: Context = mockk()
val metrics: MetricController = mockk()
val interactor = BrowserInteractor(
context,
mockk(),
mockk(),
mockk(),
mockk(),
mockk()
)
every { context.metrics } returns metrics
every { metrics.track(Event.QuickActionSheetOpened) } just Runs
interactor.onQuickActionSheetOpened()
@ -80,18 +84,6 @@ class BrowserInteractorTest {
@Test
fun onQuickActionSheetClosed() {
val context: Context = mockk()
val metrics: MetricController = mockk()
val interactor = BrowserInteractor(
context,
mockk(),
mockk(),
mockk(),
mockk(),
mockk()
)
every { context.metrics } returns metrics
every { metrics.track(Event.QuickActionSheetClosed) } just Runs
interactor.onQuickActionSheetClosed()
@ -101,19 +93,6 @@ class BrowserInteractorTest {
@Test
fun onQuickActionSheetSharePressed() {
val context: Context = mockk()
val session: Session = mockk()
val quickActionSheetController: QuickActionSheetController = mockk(relaxed = true)
val interactor = BrowserInteractor(
context,
mockk(),
mockk(),
quickActionSheetController,
mockk(),
session
)
interactor.onQuickActionSheetSharePressed()
verify { quickActionSheetController.handleShare() }
@ -121,20 +100,6 @@ class BrowserInteractorTest {
@Test
fun onQuickActionSheetDownloadPressed() {
val context: Context = mockk()
val metrics: MetricController = mockk()
val quickActionSheetController: QuickActionSheetController = mockk(relaxed = true)
val interactor = BrowserInteractor(
context,
mockk(),
mockk(),
quickActionSheetController,
mockk(),
mockk()
)
every { context.metrics } returns metrics
every { metrics.track(Event.QuickActionSheetDownloadTapped) } just Runs
interactor.onQuickActionSheetDownloadPressed()
@ -144,19 +109,6 @@ class BrowserInteractorTest {
@Test
fun onQuickActionSheetBookmarkPressed() {
val context: Context = mockk()
val session: Session = mockk()
val quickActionSheetController: QuickActionSheetController = mockk(relaxed = true)
val interactor = BrowserInteractor(
context,
mockk(),
mockk(),
quickActionSheetController,
mockk(),
session
)
interactor.onQuickActionSheetBookmarkPressed()
verify { quickActionSheetController.handleBookmark() }
@ -164,22 +116,6 @@ class BrowserInteractorTest {
@Test
fun onQuickActionSheetReadPressed() {
val context: Context = mockk()
val metrics: MetricController = mockk()
val session: Session = mockk()
val readerModeController: ReaderModeController = mockk(relaxed = true)
val browserStore: BrowserFragmentStore = mockk(relaxed = true)
val interactor = BrowserInteractor(
context,
browserStore,
mockk(),
mockk(),
readerModeController,
session
)
every { context.metrics } returns metrics
every { context.components.core.sessionManager.selectedSession } returns session
every { session.readerMode } returns false
every { metrics.track(Event.QuickActionSheetOpened) } just Runs
@ -191,23 +127,6 @@ class BrowserInteractorTest {
@Test
fun onQuickActionSheetReadPressedWithActiveReaderMode() {
val context: Context = mockk()
val metrics: MetricController = mockk()
val session: Session = mockk()
val readerModeController: ReaderModeController = mockk(relaxed = true)
val browserStore: BrowserFragmentStore = mockk(relaxed = true)
val interactor = BrowserInteractor(
context,
browserStore,
mockk(),
mockk(),
readerModeController,
session
)
every { context.metrics } returns metrics
every { context.components.core.sessionManager.selectedSession } returns session
every { session.readerMode } returns true
every { metrics.track(Event.QuickActionSheetClosed) } just Runs
@ -219,19 +138,6 @@ class BrowserInteractorTest {
@Test
fun onQuickActionSheetOpenLinkPressed() {
val context: Context = mockk()
val session: Session = mockk()
val quickActionSheetController: QuickActionSheetController = mockk(relaxed = true)
val interactor = BrowserInteractor(
context,
mockk(),
mockk(),
quickActionSheetController,
mockk(),
session
)
interactor.onQuickActionSheetOpenLinkPressed()
verify { quickActionSheetController.handleOpenLink() }
@ -239,22 +145,8 @@ class BrowserInteractorTest {
@Test
fun onQuickActionSheetAppearancePressed() {
val context: Context = mockk()
val metrics: MetricController = mockk()
val readerModeController: ReaderModeController = mockk(relaxed = true)
every { context.metrics } returns metrics
every { metrics.track(Event.ReaderModeAppearanceOpened) } just Runs
val interactor = BrowserInteractor(
context,
mockk(),
mockk(),
mockk(),
readerModeController,
mockk()
)
interactor.onQuickActionSheetAppearancePressed()
verify {

View File

@ -13,6 +13,7 @@ import io.mockk.just
import io.mockk.mockk
import io.mockk.mockkStatic
import io.mockk.verify
import io.mockk.verifyOrder
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.ObsoleteCoroutinesApi
import mozilla.components.browser.session.Session
@ -87,6 +88,35 @@ class DefaultBrowserToolbarControllerTest {
every { context.components.core.sessionManager.selectedSession } returns currentSession
}
@Test
fun handleBrowserToolbarPaste() {
every { currentSession.id } returns "1"
val pastedText = "Mozilla"
controller.handleToolbarPaste(pastedText)
verify {
navController.nav(
R.id.browserFragment,
BrowserFragmentDirections.actionBrowserFragmentToSearchFragment(
sessionId = currentSession.id,
pastedText = pastedText
)
)
}
}
@Test
fun handleBrowserToolbarPasteAndGo() {
val pastedText = "Mozilla"
controller.handleToolbarPasteAndGo(pastedText)
verifyOrder {
currentSession.searchTerms = ""
sessionUseCases.loadUrl(pastedText)
}
}
@Test
fun handleToolbarClick() {
every { currentSession.id } returns "1"