Bug 1509110 - Add testing for onHistoryStateChange and gotoHistoryIndex. r=geckoview-reviewers,snorp
☠☠ backed out by 15f3d68875c0 ☠ ☠
authorDylan Roeh <droeh@mozilla.com>
Thu, 11 Apr 2019 12:51:32 +0000
changeset 468999 81253689d39c5a08134cf122dcc0e092e38db643
parent 468998 f3338782b169fc54390232c411a50e5615cf5b27
child 469000 a7adb4cb7f66a2b98f8a674458b43f10a4d7bf14
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/HistoryDelegateTest.kt
--- 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))
+            }
+        })
+    }
 }