Bug 1456543 - 3. Add test for updating module state during transfer; r?esawin
Add a test for correctly updating module states after transferring, so
that, for example, if we transfer a session with a null delegate to
another session with a non-null delegate, the corresponding module will
be automatically enabled.
MozReview-Commit-ID: IHskWAJ584i
--- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/SessionLifecycleTest.kt
+++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/SessionLifecycleTest.kt
@@ -1,16 +1,19 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
package org.mozilla.geckoview.test
import org.mozilla.geckoview.GeckoSession
import org.mozilla.geckoview.GeckoSessionSettings
+import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.ClosedSessionAtStart
+import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.NullDelegate
+import org.mozilla.geckoview.test.util.Callbacks
import android.support.test.filters.MediumTest
import android.support.test.runner.AndroidJUnit4
import org.hamcrest.Matchers.*
import org.junit.Test
import org.junit.runner.RunWith
@@ -185,16 +188,46 @@ class SessionLifecycleTest : BaseSession
session2.toParcel { parcel ->
session3.readFromParcel(parcel)
}
session3.reload()
session3.waitForPageStop()
}
+ @NullDelegate(GeckoSession.NavigationDelegate::class)
+ @ClosedSessionAtStart
+ @Test fun readFromParcel_moduleUpdated() {
+ val session = sessionRule.createOpenSession()
+
+ // Disable navigation notifications on the old, open session.
+ assertThat("Old session navigation delegate should be null",
+ session.navigationDelegate, nullValue())
+
+ // Enable navigation notifications on the new, closed session.
+ var onLocationCount = 0
+ sessionRule.session.navigationDelegate = object : Callbacks.NavigationDelegate {
+ override fun onLocationChange(session: GeckoSession, url: String) {
+ onLocationCount++
+ }
+ }
+
+ // Transferring the old session to the new session should
+ // automatically re-enable navigation notifications.
+ session.toParcel { parcel ->
+ sessionRule.session.readFromParcel(parcel)
+ }
+
+ sessionRule.session.reload()
+ sessionRule.session.waitForPageStop()
+
+ assertThat("New session should receive navigation notifications",
+ onLocationCount, equalTo(1))
+ }
+
@Test fun createFromParcel() {
val session = sessionRule.createOpenSession()
session.toParcel { parcel ->
val newSession = sessionRule.wrapSession(
GeckoSession.CREATOR.createFromParcel(parcel))
assertThat("New session has same settings",