diff --git a/components/browser/engine-gecko-beta/src/main/java/mozilla/components/browser/engine/gecko/GeckoEngineSession.kt b/components/browser/engine-gecko-beta/src/main/java/mozilla/components/browser/engine/gecko/GeckoEngineSession.kt index d99b7bf4469..b8343029d1d 100644 --- a/components/browser/engine-gecko-beta/src/main/java/mozilla/components/browser/engine/gecko/GeckoEngineSession.kt +++ b/components/browser/engine-gecko-beta/src/main/java/mozilla/components/browser/engine/gecko/GeckoEngineSession.kt @@ -680,7 +680,15 @@ class GeckoEngineSession( session: GeckoSession, historyList: GeckoSession.HistoryDelegate.HistoryList ) { - val items = historyList.map { HistoryItem(title = it.title, uri = it.uri) } + val items = historyList.map { + // title is sometimes null despite the @NotNull annotation + // https://bugzilla.mozilla.org/show_bug.cgi?id=1660286 + val title: String? = it.title + HistoryItem( + title = title ?: it.uri, + uri = it.uri + ) + } notifyObservers { onHistoryStateChanged(items, historyList.currentIndex) } } } diff --git a/components/browser/engine-gecko-beta/src/test/java/mozilla/components/browser/engine/gecko/GeckoEngineSessionTest.kt b/components/browser/engine-gecko-beta/src/test/java/mozilla/components/browser/engine/gecko/GeckoEngineSessionTest.kt index 50af81a5cef..67ebde5cdb1 100644 --- a/components/browser/engine-gecko-beta/src/test/java/mozilla/components/browser/engine/gecko/GeckoEngineSessionTest.kt +++ b/components/browser/engine-gecko-beta/src/test/java/mozilla/components/browser/engine/gecko/GeckoEngineSessionTest.kt @@ -15,10 +15,10 @@ import mozilla.components.browser.errorpages.ErrorType import mozilla.components.concept.engine.DefaultSettings import mozilla.components.concept.engine.EngineSession import mozilla.components.concept.engine.EngineSession.LoadUrlFlags +import mozilla.components.concept.engine.EngineSession.SafeBrowsingPolicy import mozilla.components.concept.engine.EngineSession.TrackingProtectionPolicy -import mozilla.components.concept.engine.EngineSession.TrackingProtectionPolicy.TrackingCategory import mozilla.components.concept.engine.EngineSession.TrackingProtectionPolicy.CookiePolicy -import mozilla.components.concept.engine.EngineSession.SafeBrowsingPolicy +import mozilla.components.concept.engine.EngineSession.TrackingProtectionPolicy.TrackingCategory import mozilla.components.concept.engine.HitResult import mozilla.components.concept.engine.UnsupportedSettingException import mozilla.components.concept.engine.content.blocking.Tracker @@ -944,7 +944,7 @@ class GeckoEngineSessionTest { override fun getCurrentIndex() = currentIndex } - fun mockHistoryItem(title: String, uri: String): GeckoSession.HistoryDelegate.HistoryItem { + fun mockHistoryItem(title: String?, uri: String): GeckoSession.HistoryDelegate.HistoryItem { val item = mock() whenever(item.title).thenReturn(title) whenever(item.uri).thenReturn(uri) @@ -956,11 +956,13 @@ class GeckoEngineSessionTest { historyDelegate.value.onHistoryStateChange(mock(), MockHistoryList(listOf( mockHistoryItem("Firefox", "https://firefox.com"), - mockHistoryItem("Mozilla", "http://mozilla.org") + mockHistoryItem("Mozilla", "http://mozilla.org"), + mockHistoryItem(null, "https://example.com") ), 1)) verify(observer).onHistoryStateChanged(listOf( HistoryItem("Firefox", "https://firefox.com"), - HistoryItem("Mozilla", "http://mozilla.org") + HistoryItem("Mozilla", "http://mozilla.org"), + HistoryItem("https://example.com", "https://example.com") ), 1) } diff --git a/components/browser/engine-gecko-nightly/src/main/java/mozilla/components/browser/engine/gecko/GeckoEngineSession.kt b/components/browser/engine-gecko-nightly/src/main/java/mozilla/components/browser/engine/gecko/GeckoEngineSession.kt index d99b7bf4469..b8343029d1d 100644 --- a/components/browser/engine-gecko-nightly/src/main/java/mozilla/components/browser/engine/gecko/GeckoEngineSession.kt +++ b/components/browser/engine-gecko-nightly/src/main/java/mozilla/components/browser/engine/gecko/GeckoEngineSession.kt @@ -680,7 +680,15 @@ class GeckoEngineSession( session: GeckoSession, historyList: GeckoSession.HistoryDelegate.HistoryList ) { - val items = historyList.map { HistoryItem(title = it.title, uri = it.uri) } + val items = historyList.map { + // title is sometimes null despite the @NotNull annotation + // https://bugzilla.mozilla.org/show_bug.cgi?id=1660286 + val title: String? = it.title + HistoryItem( + title = title ?: it.uri, + uri = it.uri + ) + } notifyObservers { onHistoryStateChanged(items, historyList.currentIndex) } } } diff --git a/components/browser/engine-gecko-nightly/src/test/java/mozilla/components/browser/engine/gecko/GeckoEngineSessionTest.kt b/components/browser/engine-gecko-nightly/src/test/java/mozilla/components/browser/engine/gecko/GeckoEngineSessionTest.kt index 1a47c63012e..9c0a7fd9507 100644 --- a/components/browser/engine-gecko-nightly/src/test/java/mozilla/components/browser/engine/gecko/GeckoEngineSessionTest.kt +++ b/components/browser/engine-gecko-nightly/src/test/java/mozilla/components/browser/engine/gecko/GeckoEngineSessionTest.kt @@ -15,10 +15,10 @@ import mozilla.components.browser.errorpages.ErrorType import mozilla.components.concept.engine.DefaultSettings import mozilla.components.concept.engine.EngineSession import mozilla.components.concept.engine.EngineSession.LoadUrlFlags +import mozilla.components.concept.engine.EngineSession.SafeBrowsingPolicy import mozilla.components.concept.engine.EngineSession.TrackingProtectionPolicy -import mozilla.components.concept.engine.EngineSession.TrackingProtectionPolicy.TrackingCategory import mozilla.components.concept.engine.EngineSession.TrackingProtectionPolicy.CookiePolicy -import mozilla.components.concept.engine.EngineSession.SafeBrowsingPolicy +import mozilla.components.concept.engine.EngineSession.TrackingProtectionPolicy.TrackingCategory import mozilla.components.concept.engine.HitResult import mozilla.components.concept.engine.UnsupportedSettingException import mozilla.components.concept.engine.content.blocking.Tracker @@ -945,7 +945,7 @@ class GeckoEngineSessionTest { override fun getCurrentIndex() = currentIndex } - fun mockHistoryItem(title: String, uri: String): GeckoSession.HistoryDelegate.HistoryItem { + fun mockHistoryItem(title: String?, uri: String): GeckoSession.HistoryDelegate.HistoryItem { val item = mock() whenever(item.title).thenReturn(title) whenever(item.uri).thenReturn(uri) @@ -957,11 +957,13 @@ class GeckoEngineSessionTest { historyDelegate.value.onHistoryStateChange(mock(), MockHistoryList(listOf( mockHistoryItem("Firefox", "https://firefox.com"), - mockHistoryItem("Mozilla", "http://mozilla.org") + mockHistoryItem("Mozilla", "http://mozilla.org"), + mockHistoryItem(null, "https://example.com") ), 1)) verify(observer).onHistoryStateChanged(listOf( HistoryItem("Firefox", "https://firefox.com"), - HistoryItem("Mozilla", "http://mozilla.org") + HistoryItem("Mozilla", "http://mozilla.org"), + HistoryItem("https://example.com", "https://example.com") ), 1) } diff --git a/components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/GeckoEngineSession.kt b/components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/GeckoEngineSession.kt index b0edb42e2fb..23ee899a5d7 100644 --- a/components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/GeckoEngineSession.kt +++ b/components/browser/engine-gecko/src/main/java/mozilla/components/browser/engine/gecko/GeckoEngineSession.kt @@ -652,7 +652,15 @@ class GeckoEngineSession( session: GeckoSession, historyList: GeckoSession.HistoryDelegate.HistoryList ) { - val items = historyList.map { HistoryItem(title = it.title, uri = it.uri) } + val items = historyList.map { + // title is sometimes null despite the @NotNull annotation + // https://bugzilla.mozilla.org/show_bug.cgi?id=1660286 + val title: String? = it.title + HistoryItem( + title = title ?: it.uri, + uri = it.uri + ) + } notifyObservers { onHistoryStateChanged(items, historyList.currentIndex) } } } diff --git a/components/browser/engine-gecko/src/test/java/mozilla/components/browser/engine/gecko/GeckoEngineSessionTest.kt b/components/browser/engine-gecko/src/test/java/mozilla/components/browser/engine/gecko/GeckoEngineSessionTest.kt index 0f9a8211a04..e65d2f54862 100644 --- a/components/browser/engine-gecko/src/test/java/mozilla/components/browser/engine/gecko/GeckoEngineSessionTest.kt +++ b/components/browser/engine-gecko/src/test/java/mozilla/components/browser/engine/gecko/GeckoEngineSessionTest.kt @@ -940,7 +940,7 @@ class GeckoEngineSessionTest { override fun getCurrentIndex() = currentIndex } - fun mockHistoryItem(title: String, uri: String): GeckoSession.HistoryDelegate.HistoryItem { + fun mockHistoryItem(title: String?, uri: String): GeckoSession.HistoryDelegate.HistoryItem { val item = mock() whenever(item.title).thenReturn(title) whenever(item.uri).thenReturn(uri) @@ -952,11 +952,13 @@ class GeckoEngineSessionTest { historyDelegate.value.onHistoryStateChange(mock(), MockHistoryList(listOf( mockHistoryItem("Firefox", "https://firefox.com"), - mockHistoryItem("Mozilla", "http://mozilla.org") + mockHistoryItem("Mozilla", "http://mozilla.org"), + mockHistoryItem(null, "https://example.com") ), 1)) verify(observer).onHistoryStateChanged(listOf( HistoryItem("Firefox", "https://firefox.com"), - HistoryItem("Mozilla", "http://mozilla.org") + HistoryItem("Mozilla", "http://mozilla.org"), + HistoryItem("https://example.com", "https://example.com") ), 1) }