For #22595 - Remove unused OnboardingAutomaticSignInViewHolder

upstream-sync
Gabriel Luong 3 years ago committed by mergify[bot]
parent e53845c7eb
commit 7c2d9bd8a8

@ -9,7 +9,6 @@ import mozilla.components.concept.sync.AccountObserver
import mozilla.components.concept.sync.AuthType
import mozilla.components.concept.sync.OAuthAccount
import mozilla.components.concept.sync.Profile
import mozilla.components.service.fxa.sharing.ShareableAccount
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
import org.mozilla.fenix.browser.browsingmode.BrowsingModeManager
import org.mozilla.fenix.ext.components
@ -37,8 +36,6 @@ sealed class Mode {
sealed class OnboardingState {
// Signed out, without an option to auto-login using a shared FxA account.
object SignedOutNoAutoSignIn : OnboardingState()
// Signed out, with an option to auto-login into a shared FxA account.
data class SignedOutCanAutoSignIn(val withAccount: ShareableAccount) : OnboardingState()
// Signed in.
object SignedIn : OnboardingState()
}
@ -60,9 +57,6 @@ class CurrentMode(
Mode.Onboarding(OnboardingState.SignedIn)
} else {
Mode.Onboarding(OnboardingState.SignedOutNoAutoSignIn)
// The following other state is effectively disabled - #6521
// Code still exists in app for when it will be used again - #15694
// Mode.Onboarding(OnboardingState.SignedOutCanAutoSignIn(accountManager.shareableAccounts(context)[0]))
}
}

@ -23,7 +23,6 @@ import org.mozilla.fenix.historymetadata.view.HistoryMetadataGroupViewHolder
import org.mozilla.fenix.historymetadata.view.HistoryMetadataHeaderViewHolder
import org.mozilla.fenix.home.HomeFragmentStore
import org.mozilla.fenix.home.TopPlaceholderViewHolder
import org.mozilla.fenix.home.OnboardingState
import org.mozilla.fenix.home.pocket.PocketStoriesViewHolder
import org.mozilla.fenix.home.recentbookmarks.view.RecentBookmarksHeaderViewHolder
import org.mozilla.fenix.home.recentbookmarks.view.RecentBookmarksViewHolder
@ -36,7 +35,6 @@ import org.mozilla.fenix.home.sessioncontrol.viewholders.NoCollectionsMessageVie
import org.mozilla.fenix.home.sessioncontrol.viewholders.PrivateBrowsingDescriptionViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.TabInCollectionViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding.ExperimentDefaultBrowserCardViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding.OnboardingAutomaticSignInViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding.OnboardingFinishViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding.OnboardingHeaderViewHolder
import org.mozilla.fenix.home.sessioncontrol.viewholders.onboarding.OnboardingManualSignInViewHolder
@ -144,9 +142,6 @@ sealed class AdapterItem(@LayoutRes val viewType: Int) {
}
object OnboardingManualSignIn : AdapterItem(OnboardingManualSignInViewHolder.LAYOUT_ID)
data class OnboardingAutomaticSignIn(
val state: OnboardingState.SignedOutCanAutoSignIn
) : AdapterItem(OnboardingAutomaticSignInViewHolder.LAYOUT_ID)
object ExperimentDefaultBrowserCard : AdapterItem(ExperimentDefaultBrowserCardViewHolder.LAYOUT_ID)
@ -263,9 +258,6 @@ class SessionControlAdapter(
)
OnboardingHeaderViewHolder.LAYOUT_ID -> OnboardingHeaderViewHolder(view)
OnboardingSectionHeaderViewHolder.LAYOUT_ID -> OnboardingSectionHeaderViewHolder(view)
OnboardingAutomaticSignInViewHolder.LAYOUT_ID -> OnboardingAutomaticSignInViewHolder(
view
)
OnboardingManualSignInViewHolder.LAYOUT_ID -> OnboardingManualSignInViewHolder(view)
OnboardingThemePickerViewHolder.LAYOUT_ID -> OnboardingThemePickerViewHolder(view)
OnboardingTrackingProtectionViewHolder.LAYOUT_ID -> OnboardingTrackingProtectionViewHolder(
@ -354,9 +346,6 @@ class SessionControlAdapter(
(item as AdapterItem.OnboardingSectionHeader).labelBuilder
)
is OnboardingManualSignInViewHolder -> holder.bind()
is OnboardingAutomaticSignInViewHolder -> holder.bind(
(item as AdapterItem.OnboardingAutomaticSignIn).state.withAccount
)
is HistoryMetadataGroupViewHolder,
is RecentBookmarksViewHolder,
is RecentTabViewHolder,

@ -133,11 +133,6 @@ private fun onboardingAdapterItems(onboardingState: OnboardingState): List<Adapt
AdapterItem.OnboardingManualSignIn
)
}
is OnboardingState.SignedOutCanAutoSignIn -> {
listOf(
AdapterItem.OnboardingAutomaticSignIn(onboardingState)
)
}
OnboardingState.SignedIn -> listOf()
}
)

@ -1,83 +0,0 @@
/* 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.home.sessioncontrol.viewholders.onboarding
import android.view.View
import android.widget.Button
import androidx.annotation.VisibleForTesting
import androidx.appcompat.content.res.AppCompatResources.getDrawable
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.snackbar.Snackbar
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch
import mozilla.components.service.fxa.manager.MigrationResult
import mozilla.components.service.fxa.sharing.ShareableAccount
import mozilla.components.support.ktx.android.view.putCompoundDrawablesRelativeWithIntrinsicBounds
import org.mozilla.fenix.R
import org.mozilla.fenix.components.FenixSnackbar
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.databinding.OnboardingAutomaticSigninBinding
import org.mozilla.fenix.ext.components
class OnboardingAutomaticSignInViewHolder(
view: View,
private val scope: CoroutineScope = MainScope()
) : RecyclerView.ViewHolder(view) {
private lateinit var shareableAccount: ShareableAccount
private val binding = OnboardingAutomaticSigninBinding.bind(view)
private val headerText = binding.headerText
init {
binding.fxaSignInButton.setOnClickListener {
scope.launch {
onClick(binding.fxaSignInButton)
}
}
}
fun bind(account: ShareableAccount) {
shareableAccount = account
headerText.text = itemView.context.getString(
R.string.onboarding_firefox_account_auto_signin_header_3, account.email
)
val icon = getDrawable(itemView.context, R.drawable.ic_onboarding_avatar_anonymous)
headerText.putCompoundDrawablesRelativeWithIntrinsicBounds(start = icon)
}
@VisibleForTesting
internal suspend fun onClick(button: Button) {
val context = button.context
context.components.analytics.metrics.track(Event.OnboardingAutoSignIn)
button.text = context.getString(R.string.onboarding_firefox_account_signing_in)
button.isEnabled = false
val accountManager = context.components.backgroundServices.accountManager
when (accountManager.migrateFromAccount(shareableAccount)) {
MigrationResult.WillRetry,
MigrationResult.Success -> {
// We consider both of these as a 'success'.
}
MigrationResult.Failure -> {
// Failed to sign-in (e.g. bad credentials). Allow to try again.
button.text = context.getString(R.string.onboarding_firefox_account_auto_signin_confirm)
button.isEnabled = true
FenixSnackbar.make(
view = button,
duration = Snackbar.LENGTH_SHORT,
isDisplayedWithBrowserToolbar = false
).setText(
context.getString(R.string.onboarding_firefox_account_automatic_signin_failed)
).show()
}
}
}
companion object {
const val LAYOUT_ID = R.layout.onboarding_automatic_signin
}
}

@ -1,16 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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/. -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M17.6655,14.2092C16.1843,12.4998 14.1333,14.8 11.9997,14.8C9.8675,14.8 7.8151,12.4998 6.3339,14.2092C5.9139,14.6936 5.8803,15.3992 6.2401,15.9284C7.4959,17.7764 9.5959,19 11.9997,19C14.4035,19 16.5035,17.7764 17.7593,15.9284C18.1205,15.3992 18.0855,14.6936 17.6655,14.2092M16.25,9.25C16.25,6.9026 14.3474,5 12,5C9.6526,5 7.75,6.9026 7.75,9.25C7.75,11.5974 9.6526,13.5 12,13.5C14.3474,13.5 16.25,11.5974 16.25,9.25Z" />
<path
android:fillColor="@android:color/white"
android:pathData="M12,22C6.4772,22 2,17.5228 2,12C2,6.4772 6.4772,2 12,2C17.5228,2 22,6.4772 22,12C21.9939,17.5203 17.5203,21.9939 12,22L12,22ZM12,4C7.5817,4 4,7.5817 4,12C4,16.4183 7.5817,20 12,20C16.4183,20 20,16.4183 20,12C19.995,7.5838 16.4162,4.005 12,4Z" />
</vector>

@ -2,7 +2,7 @@
- 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/. -->
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/onboarding_padded_background_color">
android:color="#1F000000">
<item
android:bottom="6dp"
android:top="6dp">

@ -1,42 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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/. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/onboarding_card"
style="@style/OnboardingCardDark"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/home_item_horizontal_margin"
android:orientation="vertical">
<TextView
android:id="@+id/header_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="14dp"
android:drawablePadding="12dp"
android:textAppearance="@style/Header16TextStyle"
android:textColor="@color/onboarding_card_primary_text_dark"
tools:text="@string/onboarding_firefox_account_auto_signin_header_3" />
<Button
android:id="@+id/fxa_sign_in_button"
style="@style/NeutralButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="@drawable/button_background"
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:padding="10dp"
android:text="@string/onboarding_firefox_account_auto_signin_confirm"
android:textAllCaps="false"
android:textColor="@color/onboarding_card_button_text_dark"
android:textSize="14sp"
android:textStyle="bold"
app:backgroundTint="@color/onboarding_card_button_background_dark" />
</LinearLayout>

@ -206,12 +206,6 @@
<color name="mozac_feature_readerview_text_color">@color/primary_text_light_theme</color>
<color name="mozac_feature_readerview_selected">@color/accent_high_contrast_dark_theme</color>
<!-- Onboarding colors -->
<color name="onboarding_padded_background_color">#1F000000</color>
<color name="onboarding_card_primary_text_dark">@color/photonWhite</color>
<color name="onboarding_card_button_background_dark">@color/photonLightGrey10</color>
<color name="onboarding_card_button_text_dark">@color/photonInk20</color>
<!-- Share UI -->
<color name="default_share_background">#E3E2E3</color>
<color name="device_type_desktop_background">#F091C3</color>

@ -1345,11 +1345,11 @@
<!-- text for the firefox account onboarding card header when we detect you're already signed in to
another Firefox browser. (The word `Firefox` should not be translated)
The first parameter is the email of the detected user's account -->
<string name="onboarding_firefox_account_auto_signin_header_3">You are signed in as %s on another Firefox browser on this device. Would you like to sign in with this account?</string>
<string name="onboarding_firefox_account_auto_signin_header_3" moz:removedIn="96" tools:ignore="UnusedResources">You are signed in as %s on another Firefox browser on this device. Would you like to sign in with this account?</string>
<!-- text for the button to confirm automatic sign-in -->
<string name="onboarding_firefox_account_auto_signin_confirm">Yes, sign me in</string>
<string name="onboarding_firefox_account_auto_signin_confirm" moz:removedIn="96" tools:ignore="UnusedResources">Yes, sign me in</string>
<!-- text for the automatic sign-in button while signing in is in process -->
<string name="onboarding_firefox_account_signing_in">Signing in&#8230;</string>
<string name="onboarding_firefox_account_signing_in" moz:removedIn="96" tools:ignore="UnusedResources">Signing in&#8230;</string>
<!-- text for the button to manually sign into Firefox account. -->
<string name="onboarding_firefox_account_sign_in_1">Sign up</string>
<!-- text for the button to stay signed out when presented with an option to automatically sign-in. -->
@ -1357,7 +1357,7 @@
<!-- text to display in the snackbar once account is signed-in -->
<string name="onboarding_firefox_account_sync_is_on">Sync is on</string>
<!-- text to display in the snackbar if automatic sign-in fails. user may try again -->
<string name="onboarding_firefox_account_automatic_signin_failed">Failed to sign-in</string>
<string name="onboarding_firefox_account_automatic_signin_failed" moz:removedIn="96" tools:ignore="UnusedResources">Failed to sign-in</string>
<!-- text for the tracking protection onboarding card header -->
<string name="onboarding_tracking_protection_header_3">Always-on privacy</string>
<!-- text for the tracking protection card description. 'Firefox' intentionally hardcoded here -->

@ -507,7 +507,7 @@
<item name="android:padding">16dp</item>
</style>
<style name="OnboardingCardDark" parent="OnboardingCardLightWithPadding">
<style name="OnboardingCardDark" parent="OnboardingCardLightWithPadding" tools:ignore="UnusedResources">
<item name="android:background">@drawable/onboarding_card_background_dark</item>
<item name="android:elevation">0dp</item>
</style>

@ -83,20 +83,6 @@ class ModeTest {
assertEquals(Mode.Onboarding(OnboardingState.SignedOutNoAutoSignIn), currentMode.getCurrentMode())
}
// Temporarily disabled. See #6521
// @Test
// fun `get current onboarding mode when can auto sign in`() {
// val shareableAccount: ShareableAccount = mockk()
// every { onboarding.userHasBeenOnboarded() } returns false
// every { accountManager.authenticatedAccount() } returns null
// every { accountManager.shareableAccounts(context) } returns listOf(shareableAccount)
//
// assertEquals(
// Mode.Onboarding(OnboardingState.SignedOutCanAutoSignIn(shareableAccount)),
// currentMode.getCurrentMode()
// )
// }
@Test
fun `emit mode change`() {
every { onboarding.userHasBeenOnboarded() } returns true

@ -1,120 +0,0 @@
/* 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.home.sessioncontrol.viewholders.onboarding
import android.view.LayoutInflater
import io.mockk.every
import io.mockk.coEvery
import io.mockk.mockk
import io.mockk.mockkObject
import io.mockk.verify
import io.mockk.unmockkObject
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.runBlockingTest
import mozilla.components.service.fxa.manager.MigrationResult
import mozilla.components.service.fxa.sharing.ShareableAccount
import mozilla.components.support.test.robolectric.testContext
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.components.BackgroundServices
import org.mozilla.fenix.components.FenixSnackbar
import org.mozilla.fenix.databinding.OnboardingAutomaticSigninBinding
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
@RunWith(FenixRobolectricTestRunner::class)
class OnboardingAutomaticSignInViewHolderTest {
private lateinit var backgroundServices: BackgroundServices
private lateinit var snackbar: FenixSnackbar
private lateinit var binding: OnboardingAutomaticSigninBinding
@Before
fun setup() {
binding = OnboardingAutomaticSigninBinding.inflate(LayoutInflater.from(testContext))
snackbar = mockk(relaxed = true)
mockkObject(FenixSnackbar.Companion)
backgroundServices = testContext.components.backgroundServices
every { FenixSnackbar.make(any(), any(), any(), any()) } returns snackbar
}
@After
fun teardown() {
unmockkObject(FenixSnackbar.Companion)
}
@Test
fun `bind updates header text`() {
val holder = OnboardingAutomaticSignInViewHolder(binding.root)
holder.bind(
mockk {
every { email } returns "email@example.com"
}
)
assertEquals(
"You are signed in as email@example.com on another Firefox browser on this device. Would you like to sign in with this account?",
binding.headerText.text
)
assertTrue(binding.fxaSignInButton.isEnabled)
}
@Test
fun `sign in on click - MigrationResult Success`() = runBlocking {
val account = mockk<ShareableAccount> {
every { email } returns "email@example.com"
}
coEvery {
backgroundServices.accountManager.migrateFromAccount(account)
} returns MigrationResult.Success
val holder = OnboardingAutomaticSignInViewHolder(binding.root, scope = this)
holder.bind(account)
holder.onClick(binding.fxaSignInButton)
assertEquals("Signing in…", binding.fxaSignInButton.text)
assertFalse(binding.fxaSignInButton.isEnabled)
}
@Test
fun `sign in on click - MigrationResult WillRetry treated the same as Success`() = runBlocking {
val account = mockk<ShareableAccount> {
every { email } returns "email@example.com"
}
coEvery {
backgroundServices.accountManager.migrateFromAccount(account)
} returns MigrationResult.WillRetry
val holder = OnboardingAutomaticSignInViewHolder(binding.root, scope = this)
holder.bind(account)
holder.onClick(binding.fxaSignInButton)
assertEquals("Signing in…", binding.fxaSignInButton.text)
assertFalse(binding.fxaSignInButton.isEnabled)
}
@Test
fun `show error if sign in fails`() = runBlockingTest {
val account = mockk<ShareableAccount> {
every { email } returns "email@example.com"
}
coEvery {
backgroundServices.accountManager.migrateFromAccount(account)
} returns MigrationResult.Failure
val holder = OnboardingAutomaticSignInViewHolder(binding.root, scope = this)
holder.bind(account)
holder.onClick(binding.fxaSignInButton)
assertEquals("Yes, sign me in", binding.fxaSignInButton.text)
assertTrue(binding.fxaSignInButton.isEnabled)
verify { snackbar.setText("Failed to sign-in") }
}
}
Loading…
Cancel
Save