mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-28 12:45:27 +00:00
Bug 1440111 - 4. Add ProgressListenerTest; r=snorp
Add headless test for ProgressListener. MozReview-Commit-ID: KLwLhoCQsW8 --HG-- extra : rebase_source : e3fc1087cf13e57af6fa154d46c0ec93ab625b7a
This commit is contained in:
parent
7927af085a
commit
ca0fcfcdbd
@ -0,0 +1,232 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
package org.mozilla.geckoview.test
|
||||
|
||||
import org.mozilla.geckoview.GeckoSession
|
||||
import org.mozilla.geckoview.test.rule.GeckoSessionTestRule
|
||||
import org.mozilla.geckoview.test.rule.GeckoSessionTestRule.AssertCalled
|
||||
import org.mozilla.geckoview.test.util.Callbacks
|
||||
|
||||
import android.support.test.filters.MediumTest
|
||||
import android.support.test.filters.LargeTest
|
||||
import android.support.test.runner.AndroidJUnit4
|
||||
|
||||
import org.hamcrest.Matcher
|
||||
import org.hamcrest.Matchers.*
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.ErrorCollector
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
@MediumTest
|
||||
class ProgressListenerTest {
|
||||
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";
|
||||
}
|
||||
|
||||
@get:Rule val sessionRule = GeckoSessionTestRule()
|
||||
|
||||
@get:Rule val errors = ErrorCollector()
|
||||
fun <T> assertThat(reason: String, v: T, m: Matcher<T>) = errors.checkThat(reason, v, m)
|
||||
|
||||
@Before fun setUp() {
|
||||
sessionRule.errorCollector = errors
|
||||
}
|
||||
|
||||
@Test fun load() {
|
||||
sessionRule.session.loadTestPath(HELLO_HTML_PATH)
|
||||
sessionRule.waitForPageStop()
|
||||
|
||||
sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressListener {
|
||||
@AssertCalled(count = 1, order = intArrayOf(1))
|
||||
override fun onPageStart(session: GeckoSession, url: String) {
|
||||
assertThat("Session should not be null", session, notNullValue())
|
||||
assertThat("URL should not be null", url, notNullValue())
|
||||
assertThat("URL should match", url, endsWith(HELLO_HTML_PATH))
|
||||
}
|
||||
|
||||
@AssertCalled(count = 1, order = intArrayOf(2))
|
||||
override fun onSecurityChange(session: GeckoSession,
|
||||
securityInfo: GeckoSession.ProgressListener.SecurityInformation) {
|
||||
assertThat("Session should not be null", session, notNullValue())
|
||||
assertThat("Security info should not be null", securityInfo, notNullValue())
|
||||
|
||||
assertThat("Should not be secure", securityInfo.isSecure, equalTo(false))
|
||||
assertThat("Tracking mode should match",
|
||||
securityInfo.trackingMode,
|
||||
equalTo(GeckoSession.ProgressListener.SecurityInformation.CONTENT_UNKNOWN))
|
||||
}
|
||||
|
||||
@AssertCalled(count = 1, order = intArrayOf(3))
|
||||
override fun onPageStop(session: GeckoSession, success: Boolean) {
|
||||
assertThat("Session should not be null", session, notNullValue())
|
||||
assertThat("Load should succeed", success, equalTo(true))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@Test fun multipleLoads() {
|
||||
sessionRule.session.loadUri(INVALID_URI)
|
||||
sessionRule.session.loadTestPath(HELLO_HTML_PATH)
|
||||
sessionRule.waitForPageStops(2)
|
||||
|
||||
sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressListener {
|
||||
@AssertCalled(count = 2, order = intArrayOf(1, 3))
|
||||
override fun onPageStart(session: GeckoSession, url: String) {
|
||||
assertThat("URL should match", url,
|
||||
endsWith(if (sessionRule.currentCall.counter == 1)
|
||||
INVALID_URI else HELLO_HTML_PATH))
|
||||
}
|
||||
|
||||
@AssertCalled(count = 2, order = intArrayOf(2, 4))
|
||||
override fun onPageStop(session: GeckoSession, success: Boolean) {
|
||||
// The first load is certain to fail because of interruption by the second load
|
||||
// or by invalid domain name, whereas the second load is certain to succeed.
|
||||
assertThat("Success flag should match", success,
|
||||
equalTo(sessionRule.currentCall.counter != 1))
|
||||
};
|
||||
})
|
||||
}
|
||||
|
||||
@Test fun reload() {
|
||||
sessionRule.session.loadTestPath(HELLO_HTML_PATH)
|
||||
sessionRule.waitForPageStop()
|
||||
|
||||
sessionRule.session.reload()
|
||||
sessionRule.waitForPageStop()
|
||||
|
||||
sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressListener {
|
||||
@AssertCalled(count = 1, order = intArrayOf(1))
|
||||
override fun onPageStart(session: GeckoSession, url: String) {
|
||||
assertThat("URL should match", url, endsWith(HELLO_HTML_PATH))
|
||||
}
|
||||
|
||||
@AssertCalled(count = 1, order = intArrayOf(2))
|
||||
override fun onSecurityChange(session: GeckoSession,
|
||||
securityInfo: GeckoSession.ProgressListener.SecurityInformation) {
|
||||
}
|
||||
|
||||
@AssertCalled(count = 1, order = intArrayOf(3))
|
||||
override fun onPageStop(session: GeckoSession, success: Boolean) {
|
||||
assertThat("Load should succeed", success, equalTo(true))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@Test fun goBackAndForward() {
|
||||
sessionRule.session.loadTestPath(HELLO_HTML_PATH)
|
||||
sessionRule.waitForPageStop()
|
||||
sessionRule.session.loadTestPath(HELLO2_HTML_PATH)
|
||||
sessionRule.waitForPageStop()
|
||||
|
||||
sessionRule.session.goBack()
|
||||
sessionRule.waitForPageStop()
|
||||
|
||||
sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressListener {
|
||||
@AssertCalled(count = 1, order = intArrayOf(1))
|
||||
override fun onPageStart(session: GeckoSession, url: String) {
|
||||
assertThat("URL should match", url, endsWith(HELLO_HTML_PATH))
|
||||
}
|
||||
|
||||
@AssertCalled(count = 1, order = intArrayOf(2))
|
||||
override fun onSecurityChange(session: GeckoSession,
|
||||
securityInfo: GeckoSession.ProgressListener.SecurityInformation) {
|
||||
}
|
||||
|
||||
@AssertCalled(count = 1, order = intArrayOf(3))
|
||||
override fun onPageStop(session: GeckoSession, success: Boolean) {
|
||||
assertThat("Load should succeed", success, equalTo(true))
|
||||
}
|
||||
})
|
||||
|
||||
sessionRule.session.goForward()
|
||||
sessionRule.waitForPageStop()
|
||||
|
||||
sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressListener {
|
||||
@AssertCalled(count = 1, order = intArrayOf(1))
|
||||
override fun onPageStart(session: GeckoSession, url: String) {
|
||||
assertThat("URL should match", url, endsWith(HELLO2_HTML_PATH))
|
||||
}
|
||||
|
||||
@AssertCalled(count = 1, order = intArrayOf(2))
|
||||
override fun onSecurityChange(session: GeckoSession,
|
||||
securityInfo: GeckoSession.ProgressListener.SecurityInformation) {
|
||||
}
|
||||
|
||||
@AssertCalled(count = 1, order = intArrayOf(3))
|
||||
override fun onPageStop(session: GeckoSession, success: Boolean) {
|
||||
assertThat("Load should succeed", success, equalTo(true))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@LargeTest
|
||||
@Test fun correctSecurityInfoForValidTLS() {
|
||||
sessionRule.session.loadUri("https://mozilla-modern.badssl.com")
|
||||
sessionRule.waitForPageStop()
|
||||
|
||||
sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressListener {
|
||||
@AssertCalled(count = 1)
|
||||
override fun onSecurityChange(session: GeckoSession,
|
||||
securityInfo: GeckoSession.ProgressListener.SecurityInformation) {
|
||||
assertThat("Should be secure",
|
||||
securityInfo.isSecure, equalTo(true))
|
||||
assertThat("Should not be exception",
|
||||
securityInfo.isException, equalTo(false))
|
||||
assertThat("Origin should match",
|
||||
securityInfo.origin,
|
||||
equalTo("https://mozilla-modern.badssl.com"))
|
||||
assertThat("Host should match",
|
||||
securityInfo.host,
|
||||
equalTo("mozilla-modern.badssl.com"))
|
||||
assertThat("Organization should match",
|
||||
securityInfo.organization,
|
||||
equalTo("Lucas Garron"))
|
||||
assertThat("Subject name should match",
|
||||
securityInfo.subjectName,
|
||||
equalTo("CN=*.badssl.com,O=Lucas Garron,L=Walnut Creek,ST=California,C=US"))
|
||||
assertThat("Issuer common name should match",
|
||||
securityInfo.issuerCommonName,
|
||||
equalTo("DigiCert SHA2 Secure Server CA"))
|
||||
assertThat("Issuer organization should match",
|
||||
securityInfo.issuerOrganization,
|
||||
equalTo("DigiCert Inc"))
|
||||
assertThat("Security mode should match",
|
||||
securityInfo.securityMode,
|
||||
equalTo(GeckoSession.ProgressListener.SecurityInformation.SECURITY_MODE_IDENTIFIED))
|
||||
assertThat("Active mixed mode should match",
|
||||
securityInfo.mixedModeActive,
|
||||
equalTo(GeckoSession.ProgressListener.SecurityInformation.CONTENT_UNKNOWN))
|
||||
assertThat("Passive mixed mode should match",
|
||||
securityInfo.mixedModePassive,
|
||||
equalTo(GeckoSession.ProgressListener.SecurityInformation.CONTENT_UNKNOWN))
|
||||
assertThat("Tracking mode should match",
|
||||
securityInfo.trackingMode,
|
||||
equalTo(GeckoSession.ProgressListener.SecurityInformation.CONTENT_UNKNOWN))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@LargeTest
|
||||
@Test fun noSecurityInfoForExpiredTLS() {
|
||||
sessionRule.session.loadUri("https://expired.badssl.com")
|
||||
sessionRule.waitForPageStop()
|
||||
|
||||
sessionRule.forCallbacksDuringWait(object : Callbacks.ProgressListener {
|
||||
@AssertCalled(count = 1)
|
||||
override fun onPageStop(session: GeckoSession, success: Boolean) {
|
||||
assertThat("Load should fail", success, equalTo(false))
|
||||
}
|
||||
|
||||
@AssertCalled(false)
|
||||
override fun onSecurityChange(session: GeckoSession,
|
||||
securityInfo: GeckoSession.ProgressListener.SecurityInformation) {
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user