Bug 1475324 - Add a test for synchronous saveState() r=droeh
authorJames Willcox <snorp@snorp.net>
Tue, 10 Jul 2018 10:48:43 -0500
changeset 426659 e3fad7250cc3fa18381852b49a6b937541fa50da
parent 426658 2b64e706396ab6e5e526829b0fdf4b709c372470
child 426660 4afbbc6154255f6f5dc1151a5a2cd1ea674e3915
push id34278
push useraciure@mozilla.com
push dateSun, 15 Jul 2018 09:53:15 +0000
treeherdermozilla-central@2a8f94a45fd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdroeh
bugs1475324
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1475324 - Add a test for synchronous saveState() r=droeh MozReview-Commit-ID: Bz6AK1Y1dUH
mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ContentDelegateTest.kt
mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/rule/GeckoSessionTestRule.java
--- 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) {