forked from mozilla-mobile/firefox-tv
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue mozilla-mobile#2805: Add WebBackForwardList.toList.
This code is adapted from Severin's WIP: severinrudie@0f4f432
- Loading branch information
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
app/src/main/java/org/mozilla/tv/firefox/ext/WebBackForwardList.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
30 changes: 30 additions & 0 deletions
30
app/src/testSystem/java/org/mozilla/tv/firefox/ext/WebBackForwardListKtTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |