From ef4ceb4404385840e53bc7440d9b3a67667d5d4c Mon Sep 17 00:00:00 2001 From: Alexandru2909 Date: Fri, 29 Sep 2023 16:42:54 +0300 Subject: [PATCH] Bug 1855939 - Fix crash when tapping the shopping CFR action after rotation --- .../toolbar/BrowserToolbarCFRPresenter.kt | 6 ++-- .../toolbar/BrowserToolbarCFRPresenterTest.kt | 30 +++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarCFRPresenter.kt b/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarCFRPresenter.kt index 0f101ee53..17f8a7a76 100644 --- a/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarCFRPresenter.kt +++ b/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarCFRPresenter.kt @@ -99,7 +99,7 @@ class BrowserToolbarCFRPresenter( .transformWhile { progress -> emit(progress) progress != 100 - }.filter { it == 100 }.collect { + }.filter { popup == null && it == 100 }.collect { scope?.cancel() showTcpCfr() } @@ -112,7 +112,7 @@ class BrowserToolbarCFRPresenter( .filter { it.isProductUrl && it.content.progress == 100 && !it.content.loading } .distinctUntilChanged() .map { toolbar.findViewById(R.id.mozac_browser_toolbar_page_actions).isVisible } - .filter { it } + .filter { popup == null && it } .firstOrNull() if (shouldShowCfr == true) { @@ -134,7 +134,7 @@ class BrowserToolbarCFRPresenter( emit(progress) progress != 100 } - .filter { it == 100 } + .filter { popup == null && it == 100 } .collect { scope?.cancel() showEraseCfr() diff --git a/app/src/test/java/org/mozilla/fenix/components/toolbar/BrowserToolbarCFRPresenterTest.kt b/app/src/test/java/org/mozilla/fenix/components/toolbar/BrowserToolbarCFRPresenterTest.kt index 9ccc68a1d..31dc41fc9 100644 --- a/app/src/test/java/org/mozilla/fenix/components/toolbar/BrowserToolbarCFRPresenterTest.kt +++ b/app/src/test/java/org/mozilla/fenix/components/toolbar/BrowserToolbarCFRPresenterTest.kt @@ -255,6 +255,36 @@ class BrowserToolbarCFRPresenterTest { verify { presenter.showShoppingCFR(eq(false)) } } + @Test + fun `GIVEN the current tab is showing a product page WHEN the tab is not loading AND another CFR is shown THEN the shopping CFR is not shown`() { + val tab = createTab(url = "") + val browserStore = createBrowserStore( + tab = tab, + selectedTabId = tab.id, + ) + val presenter = createPresenter( + browserStore = browserStore, + settings = mockk { + every { shouldShowTotalCookieProtectionCFR } returns false + every { shouldShowReviewQualityCheckCFR } returns true + every { reviewQualityCheckOptInTimeInMillis } returns System.currentTimeMillis() + every { shouldShowEraseActionCFR } returns false + }, + ) + every { presenter.popup } returns mockk() + every { presenter.showShoppingCFR(any()) } just Runs + + presenter.start() + + assertNotNull(presenter.scope) + + browserStore.dispatch(ShoppingProductAction.UpdateProductUrlStatusAction(tab.id, true)).joinBlocking() + verify(exactly = 0) { presenter.showShoppingCFR(eq(false)) } + + browserStore.dispatch(ContentAction.UpdateProgressAction(tab.id, 100)).joinBlocking() + verify(exactly = 0) { presenter.showShoppingCFR(eq(false)) } + } + @Test fun `GIVEN the user opted in the shopping feature AND the opted in shopping CFR should be shown WHEN the tab finishes loading THEN the CFR is shown`() { val tab = createTab(url = "")