Bug 1456543 - 2. Add some @NullDelegate tests; r=snorp
authorJim Chen <nchen@mozilla.com>
Fri, 27 Apr 2018 11:57:13 -0400
changeset 416087 206d01e57d0dfefec680d0a0f29254f700f8cc83
parent 416086 429200bd5119b226cbede21ed258fefefe8b328e
child 416088 c3888fb8c222ee328da7f5fccf865c11785cf7c0
push id33916
push userapavel@mozilla.com
push dateSat, 28 Apr 2018 17:29:16 +0000
treeherdermozilla-central@807e94988d9a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1456543
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 1456543 - 2. Add some @NullDelegate tests; r=snorp Add some test for proper @NullDelegate behavior. MozReview-Commit-ID: L845TORdzem
mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/GeckoSessionTestRuleTest.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
@@ -3,16 +3,17 @@
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 package org.mozilla.geckoview.test
 
 import org.mozilla.geckoview.GeckoSession
 import org.mozilla.geckoview.GeckoSessionSettings
 import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.AssertCalled
 import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.ClosedSessionAtStart
+import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.NullDelegate
 import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.Setting
 import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.TimeoutException
 import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.TimeoutMillis
 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
@@ -71,16 +72,48 @@ class GeckoSessionTestRuleTest : BaseSes
             if (!ifce.isInterface || !ifce.simpleName.endsWith("Delegate")) {
                 continue
             }
             assertThat("Callbacks.All should include interface " + ifce.simpleName,
                        ifce.isInstance(Callbacks.Default), equalTo(true))
         }
     }
 
+    @NullDelegate.List(NullDelegate(GeckoSession.ContentDelegate::class),
+                       NullDelegate(Callbacks.NavigationDelegate::class))
+    @NullDelegate(Callbacks.ScrollDelegate::class)
+    @Test fun nullDelegate() {
+        assertThat("Content delegate should be null",
+                   sessionRule.session.contentDelegate, nullValue())
+        assertThat("Navigation delegate should be null",
+                   sessionRule.session.navigationDelegate, nullValue())
+        assertThat("Scroll delegate should be null",
+                   sessionRule.session.scrollDelegate, nullValue())
+
+        assertThat("Progress delegate should not be null",
+                   sessionRule.session.progressDelegate, notNullValue())
+    }
+
+    @NullDelegate(GeckoSession.ProgressDelegate::class)
+    @ClosedSessionAtStart
+    @Test fun nullDelegate_closed() {
+        assertThat("Progress delegate should be null",
+                   sessionRule.session.progressDelegate, nullValue())
+    }
+
+    @Test(expected = AssertionError::class)
+    @NullDelegate(GeckoSession.ProgressDelegate::class)
+    @ClosedSessionAtStart
+    fun nullDelegate_requireProgressOnOpen() {
+        assertThat("Progress delegate should be null",
+                   sessionRule.session.progressDelegate, nullValue())
+
+        sessionRule.session.open()
+    }
+
     @Test fun waitForPageStop() {
         sessionRule.session.loadTestPath(HELLO_HTML_PATH)
         sessionRule.waitForPageStop()
 
         var counter = 0
 
         sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressDelegate {
             override fun onPageStop(session: GeckoSession, success: Boolean) {
@@ -109,16 +142,25 @@ class GeckoSessionTestRuleTest : BaseSes
             override fun onPageStop(session: GeckoSession, success: Boolean) {
                 counter++
             }
         })
 
         assertThat("Callback count should be correct", counter, equalTo(2))
     }
 
+    @Test(expected = AssertionError::class)
+    @NullDelegate(GeckoSession.ProgressDelegate::class)
+    @ClosedSessionAtStart
+    fun waitForPageStops_throwOnNullDelegate() {
+        sessionRule.session.open(sessionRule.runtime) // Avoid waiting for initial load
+        sessionRule.session.reload()
+        sessionRule.session.waitForPageStops(2)
+    }
+
     @Test fun waitUntilCalled_anyInterfaceMethod() {
         sessionRule.session.loadTestPath(HELLO_HTML_PATH)
         sessionRule.waitUntilCalled(GeckoSession.ProgressDelegate::class)
 
         var counter = 0
 
         sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressDelegate {
             override fun onPageStart(session: GeckoSession, url: String) {
@@ -164,16 +206,29 @@ class GeckoSessionTestRuleTest : BaseSes
         sessionRule.waitUntilCalled(CharSequence::class)
     }
 
     fun waitUntilCalled_notThrowOnCallbackInterface() {
         sessionRule.session.loadTestPath(HELLO_HTML_PATH)
         sessionRule.waitUntilCalled(Callbacks.ProgressDelegate::class)
     }
 
+    @Test(expected = AssertionError::class)
+    @NullDelegate(GeckoSession.ScrollDelegate::class)
+    fun waitUntilCalled_throwOnNullDelegateInterface() {
+        sessionRule.session.reload()
+        sessionRule.session.waitUntilCalled(Callbacks.All::class)
+    }
+
+    @NullDelegate(GeckoSession.ScrollDelegate::class)
+    @Test fun waitUntilCalled_notThrowOnNonNullDelegateMethod() {
+        sessionRule.session.reload()
+        sessionRule.session.waitUntilCalled(Callbacks.All::class, "onPageStop")
+    }
+
     @Test fun waitUntilCalled_anyObjectMethod() {
         sessionRule.session.loadTestPath(HELLO_HTML_PATH)
 
         var counter = 0
 
         sessionRule.waitUntilCalled(object : Callbacks.ProgressDelegate {
             override fun onPageStart(session: GeckoSession, url: String) {
                 counter++
@@ -207,16 +262,37 @@ class GeckoSessionTestRuleTest : BaseSes
             override fun onPageStop(session: GeckoSession, success: Boolean) {
                 counter++
             }
         })
 
         assertThat("Callback count should be correct", counter, equalTo(2))
     }
 
+    @Test(expected = AssertionError::class)
+    @NullDelegate(GeckoSession.ScrollDelegate::class)
+    fun waitUntilCalled_throwOnNullDelegateObject() {
+        sessionRule.session.reload()
+        sessionRule.session.waitUntilCalled(object : Callbacks.All {
+            @AssertCalled
+            override fun onScrollChanged(session: GeckoSession, scrollX: Int, scrollY: Int) {
+            }
+        })
+    }
+
+    @NullDelegate(GeckoSession.ScrollDelegate::class)
+    @Test fun waitUntilCalled_notThrowOnNonNullDelegateObject() {
+        sessionRule.session.reload()
+        sessionRule.session.waitUntilCalled(object : Callbacks.All {
+            @AssertCalled
+            override fun onPageStop(session: GeckoSession, success: Boolean) {
+            }
+        })
+    }
+
     @Test fun waitUntilCalled_multipleCount() {
         sessionRule.session.loadTestPath(HELLO_HTML_PATH)
         sessionRule.session.reload()
 
         var counter = 0
 
         sessionRule.waitUntilCalled(object : Callbacks.ProgressDelegate {
             @AssertCalled(count = 2)
@@ -540,16 +616,50 @@ class GeckoSessionTestRuleTest : BaseSes
             @AssertCalled
             override fun onPageStop(session: GeckoSession, success: Boolean) {
                 throw IllegalStateException()
             }
         })
     }
 
     @Test(expected = AssertionError::class)
+    @NullDelegate(GeckoSession.ScrollDelegate::class)
+    fun forCallbacksDuringWait_throwOnAnyNullDelegate() {
+        sessionRule.session.reload()
+        sessionRule.session.waitForPageStop()
+
+        sessionRule.session.forCallbacksDuringWait(object : Callbacks.All {})
+    }
+
+    @Test(expected = AssertionError::class)
+    @NullDelegate(GeckoSession.ScrollDelegate::class)
+    fun forCallbacksDuringWait_throwOnSpecificNullDelegate() {
+        sessionRule.session.reload()
+        sessionRule.session.waitForPageStop()
+
+        sessionRule.session.forCallbacksDuringWait(object : Callbacks.All {
+            @AssertCalled
+            override fun onScrollChanged(session: GeckoSession, scrollX: Int, scrollY: Int) {
+            }
+        })
+    }
+
+    @NullDelegate(GeckoSession.ScrollDelegate::class)
+    @Test fun forCallbacksDuringWait_notThrowOnNonNullDelegate() {
+        sessionRule.session.reload()
+        sessionRule.session.waitForPageStop()
+
+        sessionRule.session.forCallbacksDuringWait(object : Callbacks.All {
+            @AssertCalled
+            override fun onPageStop(session: GeckoSession, success: Boolean) {
+            }
+        })
+    }
+
+    @Test(expected = AssertionError::class)
     fun getCurrentCall_throwOnNoCurrentCall() {
         sessionRule.currentCall
     }
 
     @Test fun delegateUntilTestEnd() {
         var counter = 0
 
         sessionRule.delegateUntilTestEnd(object : Callbacks.ProgressDelegate {
@@ -729,16 +839,25 @@ class GeckoSessionTestRuleTest : BaseSes
                 throw IllegalStateException()
             }
         })
 
         sessionRule.session.loadTestPath(HELLO_HTML_PATH)
         sessionRule.waitForPageStop()
     }
 
+    @Test(expected = AssertionError::class)
+    @NullDelegate(GeckoSession.NavigationDelegate::class)
+    fun delegateDuringNextWait_throwOnNullDelegate() {
+        sessionRule.session.delegateDuringNextWait(object : Callbacks.NavigationDelegate {
+            override fun onLocationChange(session: GeckoSession, url: String) {
+            }
+        })
+    }
+
     @Test fun wrapSession() {
         val session = sessionRule.wrapSession(
           GeckoSession(sessionRule.session.settings))
         sessionRule.openSession(session)
         session.reload()
         session.waitForPageStop()
     }