Bug 1437701 - Add ContentDelegate test r=esawin draft
authorJames Willcox <snorp@snorp.net>
Thu, 22 Mar 2018 16:16:26 -0500
changeset 774436 d8368cd1423a2e985d7efd086ed22ecbcc818f26
parent 773858 ddb6326f78508998274724898e1b21144845e75a
child 774437 6a76caab52b3680dbf4c7ca431ec315ae60ddb86
push id104401
push userbmo:snorp@snorp.net
push dateWed, 28 Mar 2018 22:12:07 +0000
reviewersesawin
bugs1437701
milestone61.0a1
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