Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
For #8123: Fix history title crash
Browse files Browse the repository at this point in the history
  • Loading branch information
NotWoods committed Aug 21, 2020
1 parent a363a46 commit 0b385bd
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<GeckoSession.HistoryDelegate.HistoryItem>()
whenever(item.title).thenReturn(title)
whenever(item.uri).thenReturn(uri)
Expand All @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<GeckoSession.HistoryDelegate.HistoryItem>()
whenever(item.title).thenReturn(title)
whenever(item.uri).thenReturn(uri)
Expand All @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<GeckoSession.HistoryDelegate.HistoryItem>()
whenever(item.title).thenReturn(title)
whenever(item.uri).thenReturn(uri)
Expand All @@ -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)
}

Expand Down

0 comments on commit 0b385bd

Please sign in to comment.