Bug 1509110 - Add testing for onHistoryStateChange and gotoHistoryIndex. r=geckoview-reviewers,snorp
☠☠ backed out by 55c2f04c1751 ☠ ☠
authorDylan Roeh <droeh@mozilla.com>
Thu, 11 Apr 2019 16:47:12 +0000
changeset 469031 1bc29703a90ff8dc7d480cbae976cb02591be4a8
parent 469030 9ed5bb5e0cfcca516302496a3b29e69aac6b82c9
child 469032 87601ef1d4d4ec187b36f1b1f643d16f984e2fc6
push id35856
push usercsabou@mozilla.com
push dateFri, 12 Apr 2019 03:19:48 +0000
treeherdermozilla-central@940684cd1065 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgeckoview-reviewers, snorp
bugs1509110
milestone68.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 1509110 - Add testing for onHistoryStateChange and gotoHistoryIndex. r=geckoview-reviewers,snorp Differential Revision: https://phabricator.services.mozilla.com/D24532
mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/GeckoSessionTestRuleTest.kt
mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/HistoryDelegateTest.kt
--- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/GeckoSessionTestRuleTest.kt
+++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/GeckoSessionTestRuleTest.kt
@@ -61,21 +61,25 @@ class GeckoSessionTestRuleTest : BaseSes
                 equalTo(false))
     }
 
     @Test(expected = UiThreadUtils.TimeoutException::class)
     @TimeoutMillis(2000)
     fun noPendingCallbacks() {
         // Make sure we don't have unexpected pending callbacks at the start of a test.
         sessionRule.waitUntilCalled(object : Callbacks.All {
-            // There may be an extraneous onSessionStateChange call after a test,
-            // so ignore the first received.
+            // There may be extraneous onSessionStateChange and onHistoryStateChange calls
+            // after a test, so ignore the first received.
             @AssertCalled(count=2)
             override fun onSessionStateChange(session: GeckoSession, state: GeckoSession.SessionState) {
             }
+
+            @AssertCalled(count = 2)
+            override fun onHistoryStateChange(session: GeckoSession, historyList: GeckoSession.HistoryDelegate.HistoryList) {
+            }
         })
     }
 
     @Test fun includesAllCallbacks() {
         for (ifce in GeckoSession::class.java.classes) {
             if (!ifce.isInterface || !ifce.simpleName.endsWith("Delegate")) {
                 continue
             }
@@ -973,21 +977,25 @@ class GeckoSessionTestRuleTest : BaseSes
 
     @Test(expected = UiThreadUtils.TimeoutException::class)
     @TimeoutMillis(2000)
     @ClosedSessionAtStart
     fun noPendingCallbacks_withSpecificSession() {
         sessionRule.createOpenSession()
         // Make sure we don't have unexpected pending callbacks after opening a session.
         sessionRule.waitUntilCalled(object : Callbacks.All {
-            // There may be an extraneous onSessionStateChange call after a test,
-            // so ignore the first received.
+            // There may be extraneous onSessionStateChange and onHistoryStateChange calls
+            // after a test, so ignore the first received.
             @AssertCalled(count=2)
             override fun onSessionStateChange(session: GeckoSession, state: GeckoSession.SessionState) {
             }
+
+            @AssertCalled(count = 2)
+            override fun onHistoryStateChange(session: GeckoSession, historyList: GeckoSession.HistoryDelegate.HistoryList) {
+            }
         })
     }
 
     @Test fun waitForPageStop_withSpecificSession() {
         val newSession = sessionRule.createOpenSession()
         newSession.loadTestPath(HELLO_HTML_PATH)
         newSession.waitForPageStop()
     }
--- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/HistoryDelegateTest.kt
+++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/HistoryDelegateTest.kt
@@ -9,16 +9,17 @@ import org.mozilla.geckoview.GeckoSessio
 import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.AssertCalled
 import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.WithDevToolsAPI
 
 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
+import org.mozilla.geckoview.test.util.Callbacks
 
 @RunWith(AndroidJUnit4::class)
 @MediumTest
 class HistoryDelegateTest : BaseSessionTest() {
     companion object {
         // Keep in sync with the styles in `LINKS_HTML_PATH`.
         const val UNVISITED_COLOR = "rgb(0, 0, 255)"
         const val VISITED_COLOR = "rgb(255, 0, 0)"
@@ -124,9 +125,95 @@ class HistoryDelegateTest : BaseSessionT
         )
 
         assertThat(
             "Bugzilla should be unvisited",
             sessionRule.waitForChromeJS("getLinkColor('#bugzilla')") as String,
             equalTo(UNVISITED_COLOR)
         )
     }
+
+    @Test fun onHistoryStateChange() {
+        sessionRule.session.loadTestPath(HELLO_HTML_PATH)
+
+        sessionRule.waitUntilCalled(object : Callbacks.HistoryDelegate {
+            @AssertCalled(count = 1)
+            override fun onHistoryStateChange(session: GeckoSession, state: GeckoSession.HistoryDelegate.HistoryList) {
+                assertThat("History should have one entry", state.size,
+                        equalTo(1))
+                assertThat("URLs should match", state[state.currentIndex].uri,
+                        endsWith(HELLO_HTML_PATH))
+                assertThat("History index should be 0", state.currentIndex,
+                        equalTo(0))
+            }
+        })
+
+        sessionRule.session.loadTestPath(HELLO2_HTML_PATH)
+
+        sessionRule.waitUntilCalled(object : Callbacks.HistoryDelegate {
+            @AssertCalled(count = 1)
+            override fun onHistoryStateChange(session: GeckoSession, state: GeckoSession.HistoryDelegate.HistoryList) {
+                assertThat("History should have two entries", state.size,
+                        equalTo(2))
+                assertThat("URLs should match", state[state.currentIndex].uri,
+                        endsWith(HELLO2_HTML_PATH))
+                assertThat("History index should be 1", state.currentIndex,
+                        equalTo(1))
+            }
+        })
+
+        sessionRule.session.goBack()
+
+        sessionRule.waitUntilCalled(object : Callbacks.HistoryDelegate {
+            @AssertCalled(count = 1)
+            override fun onHistoryStateChange(session: GeckoSession, state: GeckoSession.HistoryDelegate.HistoryList) {
+                assertThat("History should have two entries", state.size,
+                        equalTo(2))
+                assertThat("URLs should match", state[state.currentIndex].uri,
+                        endsWith(HELLO_HTML_PATH))
+                assertThat("History index should be 0", state.currentIndex,
+                        equalTo(0))
+            }
+        })
+
+        sessionRule.session.goForward()
+
+        sessionRule.waitUntilCalled(object : Callbacks.HistoryDelegate {
+            @AssertCalled(count = 1)
+            override fun onHistoryStateChange(session: GeckoSession, state: GeckoSession.HistoryDelegate.HistoryList) {
+                assertThat("History should have two entries", state.size,
+                        equalTo(2))
+                assertThat("URLs should match", state[state.currentIndex].uri,
+                        endsWith(HELLO2_HTML_PATH))
+                assertThat("History index should be 1", state.currentIndex,
+                        equalTo(1))
+            }
+        })
+
+        sessionRule.session.gotoHistoryIndex(0)
+
+        sessionRule.waitUntilCalled(object : Callbacks.HistoryDelegate {
+            @AssertCalled(count = 1)
+            override fun onHistoryStateChange(session: GeckoSession, state: GeckoSession.HistoryDelegate.HistoryList) {
+                assertThat("History should have two entries", state.size,
+                        equalTo(2))
+                assertThat("URLs should match", state[state.currentIndex].uri,
+                        endsWith(HELLO_HTML_PATH))
+                assertThat("History index should be 1", state.currentIndex,
+                        equalTo(0))
+            }
+        })
+
+        sessionRule.session.gotoHistoryIndex(1)
+
+        sessionRule.waitUntilCalled(object : Callbacks.HistoryDelegate {
+            @AssertCalled(count = 1)
+            override fun onHistoryStateChange(session: GeckoSession, state: GeckoSession.HistoryDelegate.HistoryList) {
+                assertThat("History should have two entries", state.size,
+                        equalTo(2))
+                assertThat("URLs should match", state[state.currentIndex].uri,
+                        endsWith(HELLO2_HTML_PATH))
+                assertThat("History index should be 1", state.currentIndex,
+                        equalTo(1))
+            }
+        })
+    }
 }