Bug 1475324 - Add a test for synchronous saveState() r=droeh
MozReview-Commit-ID: Bz6AK1Y1dUH
--- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ContentDelegateTest.kt
+++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ContentDelegateTest.kt
@@ -7,24 +7,28 @@ package org.mozilla.geckoview.test
import org.mozilla.geckoview.GeckoResult
import org.mozilla.geckoview.GeckoSession
import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.AssertCalled
import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.IgnoreCrash
import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.ReuseSession
import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.WithDevToolsAPI
import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.WithDisplay
import org.mozilla.geckoview.test.util.Callbacks
+import org.mozilla.geckoview.test.util.UiThreadUtils
+import android.os.Looper
import android.support.test.filters.MediumTest
import android.support.test.runner.AndroidJUnit4
import org.hamcrest.Matchers.*
import org.junit.Assume.assumeThat
import org.junit.Test
import org.junit.runner.RunWith
+import kotlin.concurrent.thread
+
@RunWith(AndroidJUnit4::class)
@MediumTest
class ContentDelegateTest : BaseSessionTest() {
@Test fun titleChange() {
sessionRule.session.loadTestPath(TITLE_CHANGE_HTML_PATH)
sessionRule.waitUntilCalled(object : Callbacks.ContentDelegate {
@@ -150,9 +154,34 @@ class ContentDelegateTest : BaseSessionT
assertThat("'name' field should match",
mainSession.evaluateJS("$('#name').value").toString(),
equalTo("the name"))
assertThat("Scroll position should match",
mainSession.evaluateJS("window.scrollY") as Double,
closeTo(100.0, .5))
}
+
+ @Test fun saveStateSync() {
+ val startUri = createTestUrl(SAVE_STATE_PATH)
+ mainSession.loadUri(startUri)
+ sessionRule.waitForPageStop()
+
+ var worker = thread {
+ Looper.prepare()
+
+ var thread = Thread.currentThread()
+ mainSession.saveState().then<Void> { _: GeckoSession.SessionState? ->
+ assertThat("We should be on the worker thread", Thread.currentThread(),
+ equalTo(thread))
+ Looper.myLooper().quit()
+ null
+ }
+
+ Looper.loop()
+ }
+
+ worker.join(sessionRule.timeoutMillis)
+ if (worker.isAlive) {
+ throw UiThreadUtils.TimeoutException("Timed out")
+ }
+ }
}
--- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/rule/GeckoSessionTestRule.java
+++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/rule/GeckoSessionTestRule.java
@@ -920,16 +920,25 @@ public class GeckoSessionTestRule extend
*
* @return ErrorCollector or null.
*/
public @Nullable ErrorCollector getErrorCollector() {
return mErrorCollector;
}
/**
+ * Get the current timeout value in milliseconds.
+ *
+ * @return The current timeout value in milliseconds.
+ */
+ public long getTimeoutMillis() {
+ return mTimeoutMillis;
+ }
+
+ /**
* Assert a condition with junit.Assert or an error collector.
*
* @param reason Reason string
* @param value Value to check
* @param matcher Matcher for checking the value
*/
public <T> void checkThat(final String reason, final T value, final Matcher<? super T> matcher) {
if (mErrorCollector != null) {