Bug 1475325 - 2. Add tests for hiding selection action in different cases; r=jchen

Add some tests for hiding selection action during navigation, blurring,
or clearing delegate.
This commit is contained in:
Jim Chen 2018-09-18 15:20:03 -04:00
Родитель 2958ce4db3
Коммит 9d365405a5
1 изменённых файлов: 26 добавлений и 0 удалений

Просмотреть файл

@ -8,6 +8,7 @@ import org.mozilla.geckoview.GeckoResponse
import org.mozilla.geckoview.GeckoSession
import org.mozilla.geckoview.GeckoSession.SelectionActionDelegate.*
import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.AssertCalled
import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.NullDelegate
import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.WithDevToolsAPI
import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.WithDisplay
import org.mozilla.geckoview.test.util.Callbacks
@ -158,6 +159,31 @@ class SelectionActionDelegateTest : BaseSessionTest() {
hasSelectionAt(selectedContent.initialContent.length))
}
@Test fun pagehide() {
// Navigating to another page should hide selection action.
testThat(selectedContent, { mainSession.loadTestPath(HELLO_HTML_PATH) }, clearsSelection())
}
@Test fun deactivate() {
// Blurring the window should hide selection action.
testThat(selectedContent, { mainSession.setFocused(false) }, clearsSelection())
mainSession.setFocused(true)
}
@NullDelegate(GeckoSession.SelectionActionDelegate::class)
@Test fun clearDelegate() {
var counter = 0
mainSession.selectionActionDelegate = object : Callbacks.SelectionActionDelegate {
override fun onHideAction(session: GeckoSession, reason: Int) {
counter++
}
}
mainSession.selectionActionDelegate = null
assertThat("Hide action should be called when clearing delegate",
counter, equalTo(1))
}
/** Interface that defines behavior for a particular type of content */
private interface SelectedContent {