Bug 1437701 - Add ContentDelegate test r=esawin
MozReview-Commit-ID: 7iMbtMlApaC
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