Bug 1437701 - Add ContentDelegate test r=esawin
authorJames Willcox <snorp@snorp.net>
Thu, 22 Mar 2018 16:16:26 -0500
changeset 410807 698a2f48d8b68cde5e9685417cad06a4f119c7ca
parent 410806 fbcb35097910b0520521316da5f1219faf8aced7
child 410808 7de2ec5e9b047e2e0b27a650a4903f5b98a9284a
push id33740
push usernbeleuzu@mozilla.com
push dateFri, 30 Mar 2018 21:49:44 +0000
treeherdermozilla-central@f4fcdaef6168 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersesawin
bugs1437701
milestone61.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 1437701 - Add ContentDelegate test r=esawin MozReview-Commit-ID: 7iMbtMlApaC
mobile/android/geckoview/src/androidTest/assets/www/titleChange.html
mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/BaseSessionTest.kt
mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ContentDelegateTest.kt
new file mode 100644
--- /dev/null
+++ b/mobile/android/geckoview/src/androidTest/assets/www/titleChange.html
@@ -0,0 +1,12 @@
+<html>
+<header><title>Title1</title></header>
+    <body>
+        <script>
+            addEventListener("load", function() {
+                setTimeout(function() {
+                    document.title = "Title2";
+                }, 100);
+            });
+        </script>
+    </body>
+</html>
\ No newline at end of file
--- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/BaseSessionTest.kt
+++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/BaseSessionTest.kt
@@ -22,18 +22,19 @@ import kotlin.reflect.KClass
  * providing the test rule and other utilities.
  */
 open class BaseSessionTest(noErrorCollector: Boolean = false) {
     companion object {
         const val INVALID_URI = "http://www.test.invalid/"
         const val HELLO_HTML_PATH = "/assets/www/hello.html"
         const val HELLO2_HTML_PATH = "/assets/www/hello2.html"
         const val NEW_SESSION_HTML_PATH = "/assets/www/newSession.html";
-        const val NEW_SESSION_CHILD_HTML_PATH = "/assets/www/newSession_child.html";
-        const val CLICK_TO_RELOAD_HTML_PATH = "/assets/www/clickToReload.html";
+        const val NEW_SESSION_CHILD_HTML_PATH = "/assets/www/newSession_child.html"
+        const val CLICK_TO_RELOAD_HTML_PATH = "/assets/www/clickToReload.html"
+        const val TITLE_CHANGE_HTML_PATH = "/assets/www/titleChange.html"
     }
 
     @get:Rule val sessionRule = GeckoSessionTestRule()
 
     @get:Rule val errors = ErrorCollector()
     fun <T> assertThat(reason: String, v: T, m: Matcher<T>) = sessionRule.assertThat(reason, v, m)
 
     init {
new file mode 100644
--- /dev/null
+++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/ContentDelegateTest.kt
@@ -0,0 +1,37 @@
+/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+package org.mozilla.geckoview.test
+
+import android.support.test.InstrumentationRegistry
+import org.mozilla.geckoview.GeckoSession
+import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.AssertCalled
+import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.WithDisplay
+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
+
+@RunWith(AndroidJUnit4::class)
+@MediumTest
+class ContentDelegateTest : BaseSessionTest() {
+
+    @Test fun titleChange() {
+        sessionRule.session.loadTestPath(TITLE_CHANGE_HTML_PATH)
+
+        val titles = mutableListOf("Title1", "Title2")
+        sessionRule.waitUntilCalled(object : Callbacks.ContentDelegate {
+            @AssertCalled(count = 2)
+            override fun onTitleChange(session: GeckoSession, title: String) {
+                assertThat("Title should match", title,
+                           equalTo(titles.removeAt(0)))
+            }
+        })
+    }
+
+}
\ No newline at end of file