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

For #8123: Fix history title crash #8174

Merged
merged 1 commit into from
Aug 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you leave a comment here why we are doing this and link to the GV bug that fixes the issue.

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