зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1771793 - Add imageUrl tests to WebNotificationTest r=geckoview-reviewers,calu
Follow-up unit tests for bug 1768574. Differential Revision: https://phabricator.services.mozilla.com/D147685
This commit is contained in:
Родитель
b22258d4fa
Коммит
5f5204b519
|
@ -4,6 +4,8 @@ import android.os.Parcel
|
|||
import androidx.test.filters.MediumTest
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import org.hamcrest.Matchers.*
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
@ -14,6 +16,8 @@ import org.mozilla.geckoview.WebNotification
|
|||
import org.mozilla.geckoview.WebNotificationDelegate
|
||||
import org.mozilla.geckoview.test.rule.GeckoSessionTestRule
|
||||
|
||||
const val VERY_LONG_IMAGE_URL = "https://example.com/this/is/a/very/long/address/that/is/meant/to/be/longer/than/is/one/hundred/and/fifth/characters/long/for/testing/imageurl/length.ico"
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
@MediumTest
|
||||
class WebNotificationTest : BaseSessionTest() {
|
||||
|
@ -214,4 +218,77 @@ class WebNotificationTest : BaseSessionTest() {
|
|||
|
||||
assertThat("Promise should have been resolved", promiseResult.value as Double, equalTo(1.0))
|
||||
}
|
||||
|
||||
@Test fun writeToParcel() {
|
||||
val notificationResult = GeckoResult<WebNotification>()
|
||||
|
||||
sessionRule.delegateDuringNextWait(object : WebNotificationDelegate {
|
||||
@GeckoSessionTestRule.AssertCalled
|
||||
override fun onShowNotification(notification: WebNotification) {
|
||||
notificationResult.complete(notification)
|
||||
}
|
||||
})
|
||||
|
||||
val promiseResult = mainSession.evaluatePromiseJS("""
|
||||
new Promise(resolve => {
|
||||
const notification = new Notification('The Title', { body: 'The Text' });
|
||||
notification.onclose = function() {
|
||||
resolve(1);
|
||||
}
|
||||
});
|
||||
""".trimIndent())
|
||||
|
||||
val notification = sessionRule.waitForResult(notificationResult)
|
||||
notification.dismiss()
|
||||
|
||||
// Ensure we always have a non-null URL from js.
|
||||
assertNotNull(notification.imageUrl)
|
||||
|
||||
// Test that we can serialize a notification
|
||||
val parcel = Parcel.obtain()
|
||||
notification.writeToParcel(parcel, /* ignored */ -1)
|
||||
|
||||
assertThat("Promise should have been resolved.", promiseResult.value as Double, equalTo(1.0))
|
||||
}
|
||||
|
||||
@Test fun writeToParcelLongImageUrl() {
|
||||
val notificationResult = GeckoResult<WebNotification>()
|
||||
|
||||
sessionRule.delegateDuringNextWait(object : WebNotificationDelegate {
|
||||
@GeckoSessionTestRule.AssertCalled
|
||||
override fun onShowNotification(notification: WebNotification) {
|
||||
notificationResult.complete(notification)
|
||||
}
|
||||
})
|
||||
|
||||
val promiseResult = mainSession.evaluatePromiseJS("""
|
||||
new Promise(resolve => {
|
||||
const notification = new Notification('The Title',
|
||||
{
|
||||
body: 'The Text',
|
||||
icon: '$VERY_LONG_IMAGE_URL'
|
||||
});
|
||||
notification.onclose = function() {
|
||||
resolve(1);
|
||||
}
|
||||
});
|
||||
""".trimIndent())
|
||||
|
||||
val notification = sessionRule.waitForResult(notificationResult)
|
||||
notification.dismiss()
|
||||
|
||||
// Ensure we have an imageUrl longer than our max to start with.
|
||||
assertNotNull(notification.imageUrl)
|
||||
assertTrue(notification.imageUrl!!.length > 150)
|
||||
|
||||
// Test that we can serialize a notification with an imageUrl.length >= 150
|
||||
val parcel = Parcel.obtain()
|
||||
notification.writeToParcel(parcel, /* ignored */ -1)
|
||||
parcel.setDataPosition(0)
|
||||
|
||||
val serializedNotification = WebNotification.CREATOR.createFromParcel(parcel)
|
||||
assertTrue(serializedNotification.imageUrl!!.isBlank())
|
||||
|
||||
assertThat("Promise should have been resolved.", promiseResult.value as Double, equalTo(1.0))
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче