Skip to content

Commit

Permalink
Issue mozilla-mobile#2805: Add MockWebBackForwardList.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcomella committed Sep 25, 2019
1 parent 6ffe27b commit 428a405
Showing 1 changed file with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* 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.helpers

import android.graphics.Bitmap
import android.webkit.WebBackForwardList
import android.webkit.WebHistoryItem

/**
* An implementation of the [WebBackForwardList] abstract class for testing.
*/
class MockWebBackForwardList(
private val backingList: List<WebHistoryItem>,
private val mockCurrentIndex: Int = 0
) : WebBackForwardList() {

override fun getSize(): Int = backingList.size
override fun getItemAtIndex(index: Int): WebHistoryItem = backingList[index]

override fun getCurrentIndex(): Int = mockCurrentIndex
override fun getCurrentItem(): WebHistoryItem? = backingList[mockCurrentIndex]

override fun clone(): WebBackForwardList {
TODO("not implemented: not needed yet")
}
}

/**
* An implementation of the [WebHistoryItem] abstract class for testing.
*/
class MockWebHistoryItem(
private val mockOriginalUrl: String? = null
) : WebHistoryItem() {

override fun getOriginalUrl(): String? = mockOriginalUrl

override fun getUrl(): String? {
TODO("not implemented: not needed yet")
}

override fun getFavicon(): Bitmap? {
TODO("not implemented: not needed yet")
}

override fun getTitle(): String? {
TODO("not implemented: not needed yet")
}

override fun clone(): WebHistoryItem {
TODO("not implemented: not needed yet")
}
}

fun List<WebHistoryItem>.toMockWebBackForwardList(): MockWebBackForwardList {
return MockWebBackForwardList(this)
}

0 comments on commit 428a405

Please sign in to comment.