Skip to content

Commit

Permalink
Issue mozilla-mobile#2805: Add WebBackForwardList.toList.
Browse files Browse the repository at this point in the history
This code is adapted from Severin's WIP:
severinrudie@0f4f432
  • Loading branch information
mcomella committed Sep 25, 2019
1 parent 428a405 commit f0efd07
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app/src/main/java/org/mozilla/tv/firefox/ext/WebBackForwardList.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.tv.firefox.ext

import android.webkit.WebBackForwardList
import android.webkit.WebHistoryItem

fun WebBackForwardList.toList(): List<WebHistoryItem> {
val size = this.size
val outputList = mutableListOf<WebHistoryItem>()
for (i in 0 until size) {
outputList.add(getItemAtIndex(i))
}
return outputList
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.tv.firefox.ext

import org.junit.Assert.assertEquals
import org.junit.Test
import org.mozilla.tv.firefox.helpers.MockWebHistoryItem
import org.mozilla.tv.firefox.helpers.toMockWebBackForwardList

class WebBackForwardListKtTest {

@Test
fun `WHEN a WebBackForwardList is converted to a List THEN the original URLs are all in order and unmodified`() {
val expected = listOf(
"https://google.com",
"https://mozilla.org",
"https://facebook.com"
)

// This test relies on our MockWeb* impls having no bugs but we can't do any better.
val webBackForwardList = expected.map { MockWebHistoryItem(mockOriginalUrl = it) }
.toMockWebBackForwardList()

val actual = webBackForwardList.toList()
.map { it.originalUrl }
assertEquals(expected, actual)
}
}

0 comments on commit f0efd07

Please sign in to comment.