diff --git a/app/src/main/java/org/mozilla/fenix/historymetadata/HistoryMetadataMiddleware.kt b/app/src/main/java/org/mozilla/fenix/historymetadata/HistoryMetadataMiddleware.kt index c1c2a8cbd8..f24d576e06 100644 --- a/app/src/main/java/org/mozilla/fenix/historymetadata/HistoryMetadataMiddleware.kt +++ b/app/src/main/java/org/mozilla/fenix/historymetadata/HistoryMetadataMiddleware.kt @@ -89,7 +89,8 @@ class HistoryMetadataMiddleware( } } } - is EngineAction.LoadUrlAction -> { + is EngineAction.LoadUrlAction, + is EngineAction.OptimizedLoadUrlTriggeredAction -> { // This isn't an ideal fix as we shouldn't have to hold any state in the middleware: // https://github.com/mozilla-mobile/android-components/issues/11034 directLoadTriggered = true diff --git a/app/src/test/java/org/mozilla/fenix/historymetadata/HistoryMetadataMiddlewareTest.kt b/app/src/test/java/org/mozilla/fenix/historymetadata/HistoryMetadataMiddlewareTest.kt index 2fe95d63eb..ece8c760d1 100644 --- a/app/src/test/java/org/mozilla/fenix/historymetadata/HistoryMetadataMiddlewareTest.kt +++ b/app/src/test/java/org/mozilla/fenix/historymetadata/HistoryMetadataMiddlewareTest.kt @@ -242,6 +242,62 @@ class HistoryMetadataMiddlewareTest { } } + @Test + fun `GIVEN tab with search terms WHEN subsequent optimized direct load occurs THEN search terms are not retained`() { + service = TestingMetadataService() + middleware = HistoryMetadataMiddleware(service) + store = BrowserStore( + middleware = listOf(middleware) + EngineMiddleware.create(engine = mockk()), + initialState = BrowserState() + ) + setupGoogleSearchEngine() + + val parentTab = createTab("https://google.com?q=mozilla+website", searchTerms = "mozilla website") + val tab = createTab("https://google.com?url=https://mozilla.org", parent = parentTab) + store.dispatch(TabListAction.AddTabAction(parentTab, select = true)).joinBlocking() + store.dispatch(TabListAction.AddTabAction(tab)).joinBlocking() + + with((service as TestingMetadataService).createdMetadata) { + assertEquals(2, this.count()) + assertEquals("https://google.com?q=mozilla+website", this[0].url) + assertNull(this[0].searchTerm) + assertNull(this[0].referrerUrl) + + assertEquals("https://google.com?url=https://mozilla.org", this[1].url) + assertEquals("mozilla website", this[1].searchTerm) + assertEquals("https://google.com?q=mozilla+website", this[1].referrerUrl) + } + + // Both tabs load. + store.dispatch(ContentAction.UpdateHistoryStateAction(parentTab.id, listOf(HistoryItem("Google - mozilla website", "https://google.com?q=mozilla+website")), 0)).joinBlocking() + store.dispatch(ContentAction.UpdateHistoryStateAction(tab.id, listOf(HistoryItem("", "https://google.com?url=mozilla+website")), currentIndex = 0)).joinBlocking() + with((service as TestingMetadataService).createdMetadata) { + assertEquals(2, this.count()) + } + + // Direct load occurs on child tab. Search terms should be cleared. + store.dispatch(EngineAction.OptimizedLoadUrlTriggeredAction(tab.id, "https://firefox.com")).joinBlocking() + store.dispatch(ContentAction.UpdateUrlAction(tab.id, "https://firefox.com")).joinBlocking() + store.dispatch(ContentAction.UpdateHistoryStateAction(tab.id, listOf(HistoryItem("", "https://google.com?url=mozilla+website"), HistoryItem("Firefox", "https://firefox.com")), 1)).joinBlocking() + with((service as TestingMetadataService).createdMetadata) { + assertEquals(3, this.count()) + assertEquals("https://firefox.com", this[2].url) + assertNull(this[2].searchTerm) + assertNull(this[2].referrerUrl) + } + + // Direct load occurs on parent tab. Search terms should be cleared. + store.dispatch(EngineAction.OptimizedLoadUrlTriggeredAction(parentTab.id, "https://firefox.com")).joinBlocking() + store.dispatch(ContentAction.UpdateUrlAction(parentTab.id, "https://firefox.com")).joinBlocking() + store.dispatch(ContentAction.UpdateHistoryStateAction(parentTab.id, listOf(HistoryItem("Google - mozilla website", "https://google.com?q=mozilla+website"), HistoryItem("Firefox", "https://firefox.com")), 1)).joinBlocking() + with((service as TestingMetadataService).createdMetadata) { + assertEquals(4, this.count()) + assertEquals("https://firefox.com", this[3].url) + assertNull(this[3].searchTerm) + assertNull(this[3].referrerUrl) + } + } + @Test fun `GIVEN normal tab has parent WHEN url is the same THEN nothing happens`() { val parentTab = createTab("https://mozilla.org", searchTerms = "mozilla website") diff --git a/buildSrc/src/main/java/AndroidComponents.kt b/buildSrc/src/main/java/AndroidComponents.kt index dfa6afba0a..691e74729a 100644 --- a/buildSrc/src/main/java/AndroidComponents.kt +++ b/buildSrc/src/main/java/AndroidComponents.kt @@ -3,5 +3,5 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ object AndroidComponents { - const val VERSION = "95.0.20211013143158" + const val VERSION = "95.0.20211013154351" }