Cleanup tests

This commit is contained in:
Benoit Marty 2020-01-07 18:46:05 +01:00
parent 3ceac70536
commit f3fb07079e
4 changed files with 371 additions and 446 deletions

View File

@ -18,6 +18,7 @@ package im.vector.matrix.android.account
import im.vector.matrix.android.InstrumentedTest import im.vector.matrix.android.InstrumentedTest
import im.vector.matrix.android.common.CommonTestHelper import im.vector.matrix.android.common.CommonTestHelper
import im.vector.matrix.android.common.CryptoTestHelper
import im.vector.matrix.android.common.SessionTestParams import im.vector.matrix.android.common.SessionTestParams
import im.vector.matrix.android.common.TestConstants import im.vector.matrix.android.common.TestConstants
import org.junit.FixMethodOrder import org.junit.FixMethodOrder
@ -31,6 +32,7 @@ import org.junit.runners.MethodSorters
class AccountCreationTest : InstrumentedTest { class AccountCreationTest : InstrumentedTest {
private val commonTestHelper = CommonTestHelper(context()) private val commonTestHelper = CommonTestHelper(context())
private val cryptoTestHelper = CryptoTestHelper(commonTestHelper)
@Test @Test
fun createAccountTest() { fun createAccountTest() {
@ -51,4 +53,11 @@ class AccountCreationTest : InstrumentedTest {
session.close() session.close()
session2.close() session2.close()
} }
@Test
fun simpleE2eTest() {
val res = cryptoTestHelper.doE2ETestWithAliceInARoom()
res.close()
}
} }

View File

@ -25,8 +25,12 @@ import im.vector.matrix.android.api.auth.data.HomeServerConnectionConfig
import im.vector.matrix.android.api.auth.data.LoginFlowResult import im.vector.matrix.android.api.auth.data.LoginFlowResult
import im.vector.matrix.android.api.auth.registration.RegistrationResult import im.vector.matrix.android.api.auth.registration.RegistrationResult
import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.session.Session
import org.junit.Assert.assertNotNull import im.vector.matrix.android.api.session.events.model.EventType
import org.junit.Assert.assertTrue import im.vector.matrix.android.api.session.room.Room
import im.vector.matrix.android.api.session.room.timeline.Timeline
import im.vector.matrix.android.api.session.room.timeline.TimelineEvent
import im.vector.matrix.android.api.session.room.timeline.TimelineSettings
import org.junit.Assert.*
import java.util.* import java.util.*
import java.util.concurrent.CountDownLatch import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
@ -88,50 +92,43 @@ class CommonTestHelper(context: Context) {
//session.syncState().removeObserver(observer) //session.syncState().removeObserver(observer)
} }
// /** /**
// * Sends text messages in a room * Sends text messages in a room
// * *
// * @param room the room where to send the messages * @param room the room where to send the messages
// * @param message the message to send * @param message the message to send
// * @param nbOfMessages the number of time the message will be sent * @param nbOfMessages the number of time the message will be sent
// * @throws Exception */
// */ fun sendTextMessage(room: Room, message: String, nbOfMessages: Int): List<TimelineEvent> {
// @Throws(Exception::class) val sentEvents = ArrayList<TimelineEvent>(nbOfMessages)
// fun sendTextMessage(room: Room, message: String, nbOfMessages: Int): List<Event> { val latch = CountDownLatch(nbOfMessages)
// val sentEvents = ArrayList<Event>(nbOfMessages) val onEventSentListener = object : Timeline.Listener {
// val latch = CountDownLatch(nbOfMessages) override fun onTimelineFailure(throwable: Throwable) {
// val onEventSentListener = object : MXEventListener() { }
// fun onEventSent(event: Event, prevEventId: String) {
// latch.countDown() override fun onTimelineUpdated(snapshot: List<TimelineEvent>) {
// } // TODO Count only new messages?
// } if (snapshot.count { it.root.type == EventType.MESSAGE } == nbOfMessages) {
// room.addEventListener(onEventSentListener) sentEvents.addAll(snapshot.filter { it.root.type == EventType.MESSAGE })
// for (i in 0 until nbOfMessages) { latch.countDown()
// room.sendTextMessage(message + " #" + (i + 1), null, Message.FORMAT_MATRIX_HTML, object : RoomMediaMessage.EventCreationListener() { }
// fun onEventCreated(roomMediaMessage: RoomMediaMessage) { }
// val sentEvent = roomMediaMessage.getEvent() }
// sentEvents.add(sentEvent) val timeline = room.createTimeline(null, TimelineSettings(10))
// } timeline.addListener(onEventSentListener)
// for (i in 0 until nbOfMessages) {
// fun onEventCreationFailed(roomMediaMessage: RoomMediaMessage, errorMessage: String) { room.sendTextMessage(message + " #" + (i + 1))
// }
// } await(latch)
// timeline.removeListener(onEventSentListener)
// fun onEncryptionFailed(roomMediaMessage: RoomMediaMessage) {
// // Check that all events has been created
// } assertEquals(nbOfMessages.toLong(), sentEvents.size.toLong())
// })
// } return sentEvents
// await(latch) }
// room.removeEventListener(onEventSentListener)
//
// // Check that all events has been created
// Assert.assertEquals(nbOfMessages.toLong(), sentEvents.size.toLong())
//
// return sentEvents
// }
//
//
// PRIVATE METHODS ***************************************************************************** // PRIVATE METHODS *****************************************************************************
/** /**
@ -277,60 +274,4 @@ class CommonTestHelper(context: Context) {
session.signOut(true, object : TestMatrixCallback<Unit>(lock) {}) session.signOut(true, object : TestMatrixCallback<Unit>(lock) {})
await(lock) await(lock)
} }
// /**
// * Clone a session.
// * It simulate that the user launches again the application with the same Credentials, contrary to login which will create a new DeviceId
// *
// * @param from the session to clone
// * @return the duplicated session
// */
// @Throws(InterruptedException::class)
// fun createNewSession(from: Session, sessionTestParams: SessionTestParams): Session {
// val context = InstrumentationRegistry.getContext()
//
// val credentials = from.sessionParams.credentials
// val hs = createHomeServerConfig(credentials)
// val store = MXFileStore(hs, false, context)
// val dataHandler = MXDataHandler(store, credentials)
// dataHandler.setLazyLoadingEnabled(sessionTestParams.withLazyLoading)
// store.setDataHandler(dataHandler)
// val session2 = Session.Builder(hs, dataHandler, context)
// .withLegacyCryptoStore(sessionTestParams.withLegacyCryptoStore)
// .build()
//
// val results = HashMap<String, Any>()
//
// val lock = CountDownLatch(1)
// val listener = object : MXStoreListener() {
// fun postProcess(accountId: String) {
// results["postProcess"] = "postProcess $accountId"
// }
//
// fun onStoreReady(accountId: String) {
// results["onStoreReady"] = "onStoreReady"
// lock.countDown()
// }
//
// fun onStoreCorrupted(accountId: String, description: String) {
// results["onStoreCorrupted"] = description
// lock.countDown()
// }
//
// fun onStoreOOM(accountId: String, description: String) {
// results["onStoreOOM"] = "onStoreOOM"
// lock.countDown()
// }
// }
//
// store.addMXStoreListener(listener)
// store.open()
//
// await(lock)
//
// Assert.assertTrue(results.toString(), results.containsKey("onStoreReady"))
//
// return session2
// }
} }

View File

@ -16,102 +16,75 @@
package im.vector.matrix.android.common package im.vector.matrix.android.common
// import android.os.SystemClock import android.os.SystemClock
// import android.text.TextUtils import android.text.TextUtils
// import im.vector.matrix.android.api.session.Session import im.vector.matrix.android.api.session.Session
// import im.vector.matrix.android.api.session.events.model.Event import im.vector.matrix.android.api.session.events.model.Event
// import im.vector.matrix.android.api.session.events.model.EventType import im.vector.matrix.android.api.session.events.model.EventType
// import im.vector.matrix.android.api.session.events.model.toContent import im.vector.matrix.android.api.session.events.model.toContent
// import im.vector.matrix.android.api.session.room.model.create.CreateRoomParams import im.vector.matrix.android.api.session.room.model.create.CreateRoomParams
// import im.vector.matrix.android.api.session.room.model.message.MessageTextContent import im.vector.matrix.android.api.session.room.timeline.Timeline
// import im.vector.matrix.android.api.session.room.model.message.MessageType import im.vector.matrix.android.api.session.room.timeline.TimelineEvent
// import im.vector.matrix.android.internal.crypto.MXCRYPTO_ALGORITHM_MEGOLM import im.vector.matrix.android.api.session.room.timeline.TimelineSettings
// import im.vector.matrix.android.internal.crypto.MXCRYPTO_ALGORITHM_MEGOLM_BACKUP import im.vector.matrix.android.internal.crypto.MXCRYPTO_ALGORITHM_MEGOLM
// import im.vector.matrix.android.internal.crypto.keysbackup.model.MegolmBackupAuthData import im.vector.matrix.android.internal.crypto.MXCRYPTO_ALGORITHM_MEGOLM_BACKUP
// import im.vector.matrix.android.internal.crypto.keysbackup.model.MegolmBackupCreationInfo import im.vector.matrix.android.internal.crypto.keysbackup.model.MegolmBackupAuthData
// import org.junit.Assert.* import im.vector.matrix.android.internal.crypto.keysbackup.model.MegolmBackupCreationInfo
// import java.util.* import org.junit.Assert.*
// import java.util.concurrent.CountDownLatch import java.util.*
// import java.util.concurrent.CountDownLatch
// class CryptoTestHelper(val mTestHelper: CommonTestHelper) {
// class CryptoTestHelper(val mTestHelper: CommonTestHelper) {
// val messagesFromAlice: List<String> = Arrays.asList("0 - Hello I'm Alice!", "4 - Go!")
// val messagesFromBob: List<String> = Arrays.asList("1 - Hello I'm Bob!", "2 - Isn't life grand?", "3 - Let's go to the opera.") val messagesFromAlice: List<String> = Arrays.asList("0 - Hello I'm Alice!", "4 - Go!")
// val messagesFromBob: List<String> = Arrays.asList("1 - Hello I'm Bob!", "2 - Isn't life grand?", "3 - Let's go to the opera.")
// // Set this value to false to test the new Realm store and to true to test legacy Filestore
// val USE_LEGACY_CRYPTO_STORE = false val defaultSessionParams = SessionTestParams(true)
//
// // Lazy loading is on by default now /**
// private val LAZY_LOADING_ENABLED = true * @return alice session
// */
// val defaultSessionParams = SessionTestParams(true, false, LAZY_LOADING_ENABLED, USE_LEGACY_CRYPTO_STORE) fun doE2ETestWithAliceInARoom(): CryptoTestData {
// val encryptedSessionParams = SessionTestParams(true, true, LAZY_LOADING_ENABLED, USE_LEGACY_CRYPTO_STORE) val aliceSession = mTestHelper.createAccount(TestConstants.USER_ALICE, defaultSessionParams)
//
// fun buildTextEvent(text: String, session: Session, roomId: String): Event { var roomId: String? = null
// val message = MessageTextContent( val lock1 = CountDownLatch(1)
// MessageType.MSGTYPE_TEXT,
// text aliceSession.createRoom(CreateRoomParams().apply { name = "MyRoom" }, object : TestMatrixCallback<String>(lock1) {
// ) override fun onSuccess(data: String) {
// roomId = data
// return Event( super.onSuccess(data)
// type = EventType.MESSAGE, }
// content = message.toContent(), })
// senderId = session.myUserId,
// roomId = roomId) mTestHelper.await(lock1)
// } assertNotNull(roomId)
//
// /** val room = aliceSession.getRoom(roomId!!)!!
// * @return alice session
// */ val lock2 = CountDownLatch(1)
// fun doE2ETestWithAliceInARoom(): CryptoTestData { room.enableEncryptionWithAlgorithm(MXCRYPTO_ALGORITHM_MEGOLM, object : TestMatrixCallback<Unit>(lock2) {})
// val results = HashMap<String, Any>() mTestHelper.await(lock2)
// val aliceSession = mTestHelper.createAccount(TestConstants.USER_ALICE, defaultSessionParams)
// return CryptoTestData(aliceSession, roomId!!)
// var roomId: String? = null }
// val lock1 = CountDownLatch(1)
// /**
// aliceSession.createRoom(CreateRoomParams().apply { name = "MyRoom" }, object : TestMatrixCallback<String>(lock1) { * @return alice and bob sessions
// override fun onSuccess(data: String) { */
// roomId = data fun doE2ETestWithAliceAndBobInARoom(): CryptoTestData {
// super.onSuccess(data) val statuses = HashMap<String, String>()
// }
// }) val cryptoTestData = doE2ETestWithAliceInARoom()
// val aliceSession = cryptoTestData.firstSession
// mTestHelper.await(lock1) val aliceRoomId = cryptoTestData.roomId
// assertNotNull(roomId)
// val room = aliceSession.getRoom(aliceRoomId)!!
// val room = aliceSession.getRoom(roomId!!)
// val bobSession = mTestHelper.createAccount(TestConstants.USER_BOB, defaultSessionParams)
// val lock2 = CountDownLatch(1)
// room.enableEncryptionWithAlgorithm(MXCRYPTO_ALGORITHM_MEGOLM, object : TestMatrixCallback<Void?>(lock2) { val lock1 = CountDownLatch(2)
// override fun onSuccess(data: Void?) {
// results["enableEncryptionWithAlgorithm"] = "enableEncryptionWithAlgorithm"
// super.onSuccess(data)
// }
// })
// mTestHelper.await(lock2)
// assertTrue(results.containsKey("enableEncryptionWithAlgorithm"))
//
// return CryptoTestData(aliceSession, roomId!!)
// }
//
// /**
// * @param cryptedBob
// * @return alice and bob sessions
// */
// fun doE2ETestWithAliceAndBobInARoom(cryptedBob: Boolean = true): CryptoTestData {
// val statuses = HashMap<String, String>()
//
// val cryptoTestData = doE2ETestWithAliceInARoom()
// val aliceSession = cryptoTestData.firstSession
// val aliceRoomId = cryptoTestData.roomId
//
// val room = aliceSession.getRoom(aliceRoomId)!!
//
// val bobSession = mTestHelper.createAccount(TestConstants.USER_BOB, defaultSessionParams)
//
// val lock1 = CountDownLatch(2)
//
// val bobEventListener = object : MXEventListener() { // val bobEventListener = object : MXEventListener() {
// override fun onNewRoom(roomId: String) { // override fun onNewRoom(roomId: String) {
// if (TextUtils.equals(roomId, aliceRoomId)) { // if (TextUtils.equals(roomId, aliceRoomId)) {
@ -124,24 +97,24 @@ package im.vector.matrix.android.common
// } // }
// //
// bobSession.dataHandler.addListener(bobEventListener) // bobSession.dataHandler.addListener(bobEventListener)
//
// room.invite(bobSession.myUserId, callback = object : TestMatrixCallback<Unit>(lock1) { room.invite(bobSession.myUserId, callback = object : TestMatrixCallback<Unit>(lock1) {
// override fun onSuccess(data: Unit) { override fun onSuccess(data: Unit) {
// statuses["invite"] = "invite" statuses["invite"] = "invite"
// super.onSuccess(data) super.onSuccess(data)
// } }
// }) })
//
// mTestHelper.await(lock1) mTestHelper.await(lock1)
//
// assertTrue(statuses.containsKey("invite") && statuses.containsKey("onNewRoom")) assertTrue(statuses.containsKey("invite") && statuses.containsKey("onNewRoom"))
//
// bobSession.dataHandler.removeListener(bobEventListener) // bobSession.dataHandler.removeListener(bobEventListener)
//
// val lock2 = CountDownLatch(2) val lock2 = CountDownLatch(2)
//
// bobSession.joinRoom(aliceRoomId, callback = TestMatrixCallback(lock2)) bobSession.joinRoom(aliceRoomId, callback = TestMatrixCallback(lock2))
//
// room.addEventListener(object : MXEventListener() { // room.addEventListener(object : MXEventListener() {
// override fun onLiveEvent(event: Event, roomState: RoomState) { // override fun onLiveEvent(event: Event, roomState: RoomState) {
// if (TextUtils.equals(event.getType(), Event.EVENT_TYPE_STATE_ROOM_MEMBER)) { // if (TextUtils.equals(event.getType(), Event.EVENT_TYPE_STATE_ROOM_MEMBER)) {
@ -155,37 +128,37 @@ package im.vector.matrix.android.common
// } // }
// } // }
// }) // })
//
// mTestHelper.await(lock2) mTestHelper.await(lock2)
//
// // Ensure bob can send messages to the room // Ensure bob can send messages to the room
// val roomFromBobPOV = bobSession.getRoom(aliceRoomId)!! // val roomFromBobPOV = bobSession.getRoom(aliceRoomId)!!
// assertNotNull(roomFromBobPOV.state.powerLevels) // assertNotNull(roomFromBobPOV.powerLevels)
// assertTrue(roomFromBobPOV.state.powerLevels.maySendMessage(bobSession.myUserId)) // assertTrue(roomFromBobPOV.powerLevels.maySendMessage(bobSession.myUserId))
//
// assertTrue(statuses.toString() + "", statuses.containsKey("AliceJoin")) assertTrue(statuses.toString() + "", statuses.containsKey("AliceJoin"))
//
// bobSession.dataHandler.removeListener(bobEventListener) // bobSession.dataHandler.removeListener(bobEventListener)
//
// return CryptoTestData(aliceSession, aliceRoomId, bobSession) return CryptoTestData(aliceSession, aliceRoomId, bobSession)
// } }
//
// /** /**
// * @return Alice, Bob and Sam session * @return Alice, Bob and Sam session
// */ */
// fun doE2ETestWithAliceAndBobAndSamInARoom(): CryptoTestData { fun doE2ETestWithAliceAndBobAndSamInARoom(): CryptoTestData {
// val statuses = HashMap<String, String>() val statuses = HashMap<String, String>()
//
// val cryptoTestData = doE2ETestWithAliceAndBobInARoom(true) val cryptoTestData = doE2ETestWithAliceAndBobInARoom()
// val aliceSession = cryptoTestData.firstSession val aliceSession = cryptoTestData.firstSession
// val aliceRoomId = cryptoTestData.roomId val aliceRoomId = cryptoTestData.roomId
//
// val room = aliceSession.getRoom(aliceRoomId)!! val room = aliceSession.getRoom(aliceRoomId)!!
//
// val samSession = mTestHelper.createAccount(TestConstants.USER_SAM, defaultSessionParams) val samSession = mTestHelper.createAccount(TestConstants.USER_SAM, defaultSessionParams)
//
// val lock1 = CountDownLatch(2) val lock1 = CountDownLatch(2)
//
// val samEventListener = object : MXEventListener() { // val samEventListener = object : MXEventListener() {
// override fun onNewRoom(roomId: String) { // override fun onNewRoom(roomId: String) {
// if (TextUtils.equals(roomId, aliceRoomId)) { // if (TextUtils.equals(roomId, aliceRoomId)) {
@ -198,161 +171,166 @@ package im.vector.matrix.android.common
// } // }
// //
// samSession.dataHandler.addListener(samEventListener) // samSession.dataHandler.addListener(samEventListener)
//
// room.invite(aliceSession, samSession.myUserId, object : TestMatrixCallback<Void?>(lock1) { room.invite(samSession.myUserId, null, object : TestMatrixCallback<Unit>(lock1) {
// override fun onSuccess(info: Void?) { override fun onSuccess(data: Unit) {
// statuses["invite"] = "invite" statuses["invite"] = "invite"
// super.onSuccess(info) super.onSuccess(data)
// } }
// }) })
//
// mTestHelper.await(lock1) mTestHelper.await(lock1)
//
// assertTrue(statuses.containsKey("invite") && statuses.containsKey("onNewRoom")) assertTrue(statuses.containsKey("invite") && statuses.containsKey("onNewRoom"))
//
// samSession.dataHandler.removeListener(samEventListener) // samSession.dataHandler.removeListener(samEventListener)
//
// val lock2 = CountDownLatch(1) val lock2 = CountDownLatch(1)
//
// samSession.joinRoom(aliceRoomId, object : TestMatrixCallback<String>(lock2) { samSession.joinRoom(aliceRoomId, null, object : TestMatrixCallback<Unit>(lock2) {
// override fun onSuccess(info: String) { override fun onSuccess(data: Unit) {
// statuses["joinRoom"] = "joinRoom" statuses["joinRoom"] = "joinRoom"
// super.onSuccess(info) super.onSuccess(data)
// } }
// }) })
//
// mTestHelper.await(lock2) mTestHelper.await(lock2)
// assertTrue(statuses.containsKey("joinRoom")) assertTrue(statuses.containsKey("joinRoom"))
//
// // wait the initial sync // wait the initial sync
// SystemClock.sleep(1000) SystemClock.sleep(1000)
//
// samSession.dataHandler.removeListener(samEventListener) // samSession.dataHandler.removeListener(samEventListener)
//
// return CryptoTestData(aliceSession, aliceRoomId, cryptoTestData.secondSession, samSession) return CryptoTestData(aliceSession, aliceRoomId, cryptoTestData.secondSession, samSession)
// } }
//
// /** /**
// * @param cryptedBob * @return Alice and Bob sessions
// * @return Alice and Bob sessions */
// */ fun doE2ETestWithAliceAndBobInARoomWithEncryptedMessages(): CryptoTestData {
// fun doE2ETestWithAliceAndBobInARoomWithEncryptedMessages(cryptedBob: Boolean): CryptoTestData { val cryptoTestData = doE2ETestWithAliceAndBobInARoom()
// val cryptoTestData = doE2ETestWithAliceAndBobInARoom(cryptedBob) val aliceSession = cryptoTestData.firstSession
// val aliceSession = cryptoTestData.firstSession val aliceRoomId = cryptoTestData.roomId
// val aliceRoomId = cryptoTestData.roomId val bobSession = cryptoTestData.secondSession!!
// val bobSession = cryptoTestData.secondSession!!
// bobSession.setWarnOnUnknownDevices(false)
// bobSession.setWarnOnUnknownDevices(false)
// aliceSession.setWarnOnUnknownDevices(false)
// aliceSession.setWarnOnUnknownDevices(false)
// val roomFromBobPOV = bobSession.getRoom(aliceRoomId)!!
// val roomFromBobPOV = bobSession.getRoom(aliceRoomId)!! val roomFromAlicePOV = aliceSession.getRoom(aliceRoomId)!!
// val roomFromAlicePOV = aliceSession.getRoom(aliceRoomId)!!
// var lock = CountDownLatch(1)
// var messagesReceivedByBobCount = 0
// var lock = CountDownLatch(3) val bobEventsListener = object : Timeline.Listener {
// override fun onTimelineFailure(throwable: Throwable) {
// val bobEventsListener = object : MXEventListener() { }
// override fun onLiveEvent(event: Event, roomState: RoomState) {
// if (TextUtils.equals(event.getType(), Event.EVENT_TYPE_MESSAGE) && !TextUtils.equals(event.getSender(), bobSession.myUserId)) { override fun onTimelineUpdated(snapshot: List<TimelineEvent>) {
// messagesReceivedByBobCount++ val size = snapshot.filter { it.root.senderId != bobSession.myUserId && it.root.getClearType() == EventType.MESSAGE }
// lock.countDown() .size
// }
// } if (size == 3) {
// } lock.countDown()
// }
// roomFromBobPOV.addEventListener(bobEventsListener) }
// }
// val results = HashMap<String, Any>()
// val bobTimeline = roomFromBobPOV.createTimeline(null, TimelineSettings(10))
// bobSession.dataHandler.addListener(object : MXEventListener() { bobTimeline.addListener(bobEventsListener)
// override fun onToDeviceEvent(event: Event) {
// results["onToDeviceEvent"] = event val results = HashMap<String, Any>()
// lock.countDown()
// } // bobSession.dataHandler.addListener(object : MXEventListener() {
// }) // override fun onToDeviceEvent(event: Event) {
// // results["onToDeviceEvent"] = event
// // Alice sends a message // lock.countDown()
// roomFromAlicePOV.sendEvent(buildTextEvent(messagesFromAlice[0], aliceSession, aliceRoomId), TestMatrixCallback<Void>(lock, true)) // }
// mTestHelper.await(lock) // })
// assertTrue(results.containsKey("onToDeviceEvent"))
// Alice sends a message
roomFromAlicePOV.sendTextMessage(messagesFromAlice[0])
assertTrue(results.containsKey("onToDeviceEvent"))
// assertEquals(1, messagesReceivedByBobCount) // assertEquals(1, messagesReceivedByBobCount)
//
// // Bob send a message // Bob send a message
// lock = CountDownLatch(1) lock = CountDownLatch(1)
// roomFromBobPOV.sendEvent(buildTextEvent(messagesFromBob[0], bobSession, aliceRoomId), TestMatrixCallback<Void>(lock, true)) roomFromBobPOV.sendTextMessage(messagesFromBob[0])
// // android does not echo the messages sent from itself // android does not echo the messages sent from itself
// messagesReceivedByBobCount++ // messagesReceivedByBobCount++
// mTestHelper.await(lock) mTestHelper.await(lock)
// assertEquals(2, messagesReceivedByBobCount) // assertEquals(2, messagesReceivedByBobCount)
//
// // Bob send a message // Bob send a message
// lock = CountDownLatch(1) lock = CountDownLatch(1)
// roomFromBobPOV.sendEvent(buildTextEvent(messagesFromBob[1], bobSession, aliceRoomId), TestMatrixCallback<Void>(lock, true)) roomFromBobPOV.sendTextMessage(messagesFromBob[1])
// // android does not echo the messages sent from itself // android does not echo the messages sent from itself
// messagesReceivedByBobCount++ // messagesReceivedByBobCount++
// mTestHelper.await(lock) mTestHelper.await(lock)
// assertEquals(3, messagesReceivedByBobCount) // assertEquals(3, messagesReceivedByBobCount)
//
// // Bob send a message // Bob send a message
// lock = CountDownLatch(1) lock = CountDownLatch(1)
// roomFromBobPOV.sendEvent(buildTextEvent(messagesFromBob[2], bobSession, aliceRoomId), TestMatrixCallback<Void>(lock, true)) roomFromBobPOV.sendTextMessage(messagesFromBob[2])
// // android does not echo the messages sent from itself // android does not echo the messages sent from itself
// messagesReceivedByBobCount++ // messagesReceivedByBobCount++
// mTestHelper.await(lock) mTestHelper.await(lock)
// assertEquals(4, messagesReceivedByBobCount) // assertEquals(4, messagesReceivedByBobCount)
//
// // Alice sends a message // Alice sends a message
// lock = CountDownLatch(2) lock = CountDownLatch(2)
// roomFromAlicePOV.sendEvent(buildTextEvent(messagesFromAlice[1], aliceSession, aliceRoomId), TestMatrixCallback<Void>(lock, true)) roomFromAlicePOV.sendTextMessage(messagesFromAlice[1])
// mTestHelper.await(lock) mTestHelper.await(lock)
// assertEquals(5, messagesReceivedByBobCount) // assertEquals(5, messagesReceivedByBobCount)
//
// return cryptoTestData bobTimeline.removeListener(bobEventsListener)
// }
// return cryptoTestData
// fun checkEncryptedEvent(event: CryptoEvent, roomId: String, clearMessage: String, senderSession: Session) { }
// assertEquals(EventType.ENCRYPTED, event.wireType)
// assertNotNull(event.wireContent) fun checkEncryptedEvent(event: Event, roomId: String, clearMessage: String, senderSession: Session) {
// assertEquals(EventType.ENCRYPTED, event.type)
// val eventWireContent = event.wireContent.asJsonObject assertNotNull(event.content)
// assertNotNull(eventWireContent)
// val eventWireContent = event.content.toContent()
// assertNull(eventWireContent.get("body")) assertNotNull(eventWireContent)
// assertEquals(MXCRYPTO_ALGORITHM_MEGOLM, eventWireContent.get("algorithm").asString)
// assertNull(eventWireContent.get("body"))
// assertNotNull(eventWireContent.get("ciphertext")) assertEquals(MXCRYPTO_ALGORITHM_MEGOLM, eventWireContent.get("algorithm"))
// assertNotNull(eventWireContent.get("session_id"))
// assertNotNull(eventWireContent.get("sender_key")) assertNotNull(eventWireContent.get("ciphertext"))
// assertNotNull(eventWireContent.get("session_id"))
// assertEquals(senderSession.sessionParams.credentials.deviceId, eventWireContent.get("device_id").asString) assertNotNull(eventWireContent.get("sender_key"))
//
// assertNotNull(event.getEventId()) assertEquals(senderSession.sessionParams.credentials.deviceId, eventWireContent.get("device_id"))
// assertEquals(roomId, event.getRoomId())
// assertEquals(EventType.MESSAGE, event.getType()) assertNotNull(event.eventId)
// assertTrue(event.getAge() < 10000) assertEquals(roomId, event.roomId)
// assertEquals(EventType.MESSAGE, event.getClearType())
// val eventContent = event.contentAsJsonObject // TODO assertTrue(event.getAge() < 10000)
// assertNotNull(eventContent)
// assertEquals(clearMessage, eventContent.get("body").asString) val eventContent = event.toContent()
// assertEquals(senderSession.myUserId, event.getSender()) assertNotNull(eventContent)
// } assertEquals(clearMessage, eventContent.get("body"))
// assertEquals(senderSession.myUserId, event.senderId)
// fun createFakeMegolmBackupAuthData(): MegolmBackupAuthData { }
// return MegolmBackupAuthData(
// publicKey = "abcdefg", fun createFakeMegolmBackupAuthData(): MegolmBackupAuthData {
// signatures = HashMap<String, Map<String, String>>().apply { return MegolmBackupAuthData(
// this["something"] = HashMap<String, String>().apply { publicKey = "abcdefg",
// this["ed25519:something"] = "hijklmnop" signatures = HashMap<String, Map<String, String>>().apply {
// } this["something"] = HashMap<String, String>().apply {
// } this["ed25519:something"] = "hijklmnop"
// ) }
// } }
// )
// fun createFakeMegolmBackupCreationInfo(): MegolmBackupCreationInfo { }
// return MegolmBackupCreationInfo().apply {
// algorithm = MXCRYPTO_ALGORITHM_MEGOLM_BACKUP fun createFakeMegolmBackupCreationInfo(): MegolmBackupCreationInfo {
// authData = createFakeMegolmBackupAuthData() return MegolmBackupCreationInfo().apply {
// } algorithm = MXCRYPTO_ALGORITHM_MEGOLM_BACKUP
// } authData = createFakeMegolmBackupAuthData()
// } }
}
}

View File

@ -16,7 +16,4 @@
package im.vector.matrix.android.common package im.vector.matrix.android.common
data class SessionTestParams @JvmOverloads constructor(val withInitialSync: Boolean = false, data class SessionTestParams @JvmOverloads constructor(val withInitialSync: Boolean = false)
val withCryptoEnabled: Boolean = false,
val withLazyLoading: Boolean = true,
val withLegacyCryptoStore: Boolean = false)