@@ -29,24 +29,17 @@ use matrix_sdk_common::{
29
29
} ;
30
30
use matrix_sdk_test:: { ALICE , DEFAULT_TEST_ROOM_ID , event_factory:: EventFactory } ;
31
31
use ruma:: {
32
- EventId , RoomId ,
33
- api:: client:: media:: get_content_thumbnail:: v3:: Method ,
34
- event_id,
32
+ EventId , RoomId , event_id,
35
33
events:: {
36
- AnyMessageLikeEvent , AnyTimelineEvent ,
37
- relation:: RelationType ,
38
- room:: { MediaSource , message:: RoomMessageEventContentWithoutRelation } ,
34
+ AnyMessageLikeEvent , AnyTimelineEvent , relation:: RelationType ,
35
+ room:: message:: RoomMessageEventContentWithoutRelation ,
39
36
} ,
40
- mxc_uri,
41
37
push:: Action ,
42
- room_id, uint ,
38
+ room_id,
43
39
} ;
44
40
45
- use super :: { DynEventCacheStore , media:: IgnoreMediaRetentionPolicy } ;
46
- use crate :: {
47
- event_cache:: { Gap , store:: DEFAULT_CHUNK_CAPACITY } ,
48
- media:: { MediaFormat , MediaRequestParameters , MediaThumbnailSettings } ,
49
- } ;
41
+ use super :: DynEventCacheStore ;
42
+ use crate :: event_cache:: { Gap , store:: DEFAULT_CHUNK_CAPACITY } ;
50
43
51
44
/// Create a test event with all data filled, for testing that linked chunk
52
45
/// correctly stores event data.
@@ -118,12 +111,6 @@ pub fn check_test_event(event: &TimelineEvent, text: &str) {
118
111
/// `event_cache_store_integration_tests!` macro.
119
112
#[ allow( async_fn_in_trait) ]
120
113
pub trait EventCacheStoreIntegrationTests {
121
- /// Test media content storage.
122
- async fn test_media_content ( & self ) ;
123
-
124
- /// Test replacing a MXID.
125
- async fn test_replace_media_key ( & self ) ;
126
-
127
114
/// Test handling updates to a linked chunk and reloading these updates from
128
115
/// the store.
129
116
async fn test_handle_updates_and_rebuild_linked_chunk ( & self ) ;
@@ -163,190 +150,6 @@ pub trait EventCacheStoreIntegrationTests {
163
150
}
164
151
165
152
impl EventCacheStoreIntegrationTests for DynEventCacheStore {
166
- async fn test_media_content ( & self ) {
167
- let uri = mxc_uri ! ( "mxc://localhost/media" ) ;
168
- let request_file = MediaRequestParameters {
169
- source : MediaSource :: Plain ( uri. to_owned ( ) ) ,
170
- format : MediaFormat :: File ,
171
- } ;
172
- let request_thumbnail = MediaRequestParameters {
173
- source : MediaSource :: Plain ( uri. to_owned ( ) ) ,
174
- format : MediaFormat :: Thumbnail ( MediaThumbnailSettings :: with_method (
175
- Method :: Crop ,
176
- uint ! ( 100 ) ,
177
- uint ! ( 100 ) ,
178
- ) ) ,
179
- } ;
180
-
181
- let other_uri = mxc_uri ! ( "mxc://localhost/media-other" ) ;
182
- let request_other_file = MediaRequestParameters {
183
- source : MediaSource :: Plain ( other_uri. to_owned ( ) ) ,
184
- format : MediaFormat :: File ,
185
- } ;
186
-
187
- let content: Vec < u8 > = "hello" . into ( ) ;
188
- let thumbnail_content: Vec < u8 > = "world" . into ( ) ;
189
- let other_content: Vec < u8 > = "foo" . into ( ) ;
190
-
191
- // Media isn't present in the cache.
192
- assert ! (
193
- self . get_media_content( & request_file) . await . unwrap( ) . is_none( ) ,
194
- "unexpected media found"
195
- ) ;
196
- assert ! (
197
- self . get_media_content( & request_thumbnail) . await . unwrap( ) . is_none( ) ,
198
- "media not found"
199
- ) ;
200
-
201
- // Let's add the media.
202
- self . add_media_content ( & request_file, content. clone ( ) , IgnoreMediaRetentionPolicy :: No )
203
- . await
204
- . expect ( "adding media failed" ) ;
205
-
206
- // Media is present in the cache.
207
- assert_eq ! (
208
- self . get_media_content( & request_file) . await . unwrap( ) . as_ref( ) ,
209
- Some ( & content) ,
210
- "media not found though added"
211
- ) ;
212
- assert_eq ! (
213
- self . get_media_content_for_uri( uri) . await . unwrap( ) . as_ref( ) ,
214
- Some ( & content) ,
215
- "media not found by URI though added"
216
- ) ;
217
-
218
- // Let's remove the media.
219
- self . remove_media_content ( & request_file) . await . expect ( "removing media failed" ) ;
220
-
221
- // Media isn't present in the cache.
222
- assert ! (
223
- self . get_media_content( & request_file) . await . unwrap( ) . is_none( ) ,
224
- "media still there after removing"
225
- ) ;
226
- assert ! (
227
- self . get_media_content_for_uri( uri) . await . unwrap( ) . is_none( ) ,
228
- "media still found by URI after removing"
229
- ) ;
230
-
231
- // Let's add the media again.
232
- self . add_media_content ( & request_file, content. clone ( ) , IgnoreMediaRetentionPolicy :: No )
233
- . await
234
- . expect ( "adding media again failed" ) ;
235
-
236
- assert_eq ! (
237
- self . get_media_content( & request_file) . await . unwrap( ) . as_ref( ) ,
238
- Some ( & content) ,
239
- "media not found after adding again"
240
- ) ;
241
-
242
- // Let's add the thumbnail media.
243
- self . add_media_content (
244
- & request_thumbnail,
245
- thumbnail_content. clone ( ) ,
246
- IgnoreMediaRetentionPolicy :: No ,
247
- )
248
- . await
249
- . expect ( "adding thumbnail failed" ) ;
250
-
251
- // Media's thumbnail is present.
252
- assert_eq ! (
253
- self . get_media_content( & request_thumbnail) . await . unwrap( ) . as_ref( ) ,
254
- Some ( & thumbnail_content) ,
255
- "thumbnail not found"
256
- ) ;
257
-
258
- // We get a file with the URI, we don't know which one.
259
- assert ! (
260
- self . get_media_content_for_uri( uri) . await . unwrap( ) . is_some( ) ,
261
- "media not found by URI though two where added"
262
- ) ;
263
-
264
- // Let's add another media with a different URI.
265
- self . add_media_content (
266
- & request_other_file,
267
- other_content. clone ( ) ,
268
- IgnoreMediaRetentionPolicy :: No ,
269
- )
270
- . await
271
- . expect ( "adding other media failed" ) ;
272
-
273
- // Other file is present.
274
- assert_eq ! (
275
- self . get_media_content( & request_other_file) . await . unwrap( ) . as_ref( ) ,
276
- Some ( & other_content) ,
277
- "other file not found"
278
- ) ;
279
- assert_eq ! (
280
- self . get_media_content_for_uri( other_uri) . await . unwrap( ) . as_ref( ) ,
281
- Some ( & other_content) ,
282
- "other file not found by URI"
283
- ) ;
284
-
285
- // Let's remove media based on URI.
286
- self . remove_media_content_for_uri ( uri) . await . expect ( "removing all media for uri failed" ) ;
287
-
288
- assert ! (
289
- self . get_media_content( & request_file) . await . unwrap( ) . is_none( ) ,
290
- "media wasn't removed"
291
- ) ;
292
- assert ! (
293
- self . get_media_content( & request_thumbnail) . await . unwrap( ) . is_none( ) ,
294
- "thumbnail wasn't removed"
295
- ) ;
296
- assert ! (
297
- self . get_media_content( & request_other_file) . await . unwrap( ) . is_some( ) ,
298
- "other media was removed"
299
- ) ;
300
- assert ! (
301
- self . get_media_content_for_uri( uri) . await . unwrap( ) . is_none( ) ,
302
- "media found by URI wasn't removed"
303
- ) ;
304
- assert ! (
305
- self . get_media_content_for_uri( other_uri) . await . unwrap( ) . is_some( ) ,
306
- "other media found by URI was removed"
307
- ) ;
308
- }
309
-
310
- async fn test_replace_media_key ( & self ) {
311
- let uri = mxc_uri ! ( "mxc://sendqueue.local/tr4n-s4ct-10n1-d" ) ;
312
- let req = MediaRequestParameters {
313
- source : MediaSource :: Plain ( uri. to_owned ( ) ) ,
314
- format : MediaFormat :: File ,
315
- } ;
316
-
317
- let content = "hello" . as_bytes ( ) . to_owned ( ) ;
318
-
319
- // Media isn't present in the cache.
320
- assert ! ( self . get_media_content( & req) . await . unwrap( ) . is_none( ) , "unexpected media found" ) ;
321
-
322
- // Add the media.
323
- self . add_media_content ( & req, content. clone ( ) , IgnoreMediaRetentionPolicy :: No )
324
- . await
325
- . expect ( "adding media failed" ) ;
326
-
327
- // Sanity-check: media is found after adding it.
328
- assert_eq ! ( self . get_media_content( & req) . await . unwrap( ) . unwrap( ) , b"hello" ) ;
329
-
330
- // Replacing a media request works.
331
- let new_uri = mxc_uri ! ( "mxc://matrix.org/tr4n-s4ct-10n1-d" ) ;
332
- let new_req = MediaRequestParameters {
333
- source : MediaSource :: Plain ( new_uri. to_owned ( ) ) ,
334
- format : MediaFormat :: File ,
335
- } ;
336
- self . replace_media_key ( & req, & new_req)
337
- . await
338
- . expect ( "replacing the media request key failed" ) ;
339
-
340
- // Finding with the previous request doesn't work anymore.
341
- assert ! (
342
- self . get_media_content( & req) . await . unwrap( ) . is_none( ) ,
343
- "unexpected media found with the old key"
344
- ) ;
345
-
346
- // Finding with the new request does work.
347
- assert_eq ! ( self . get_media_content( & new_req) . await . unwrap( ) . unwrap( ) , b"hello" ) ;
348
- }
349
-
350
153
async fn test_handle_updates_and_rebuild_linked_chunk ( & self ) {
351
154
let room_id = room_id ! ( "!r0:matrix.org" ) ;
352
155
let linked_chunk_id = LinkedChunkId :: Room ( room_id) ;
@@ -1333,20 +1136,6 @@ macro_rules! event_cache_store_integration_tests {
1333
1136
1334
1137
use super :: get_event_cache_store;
1335
1138
1336
- #[ async_test]
1337
- async fn test_media_content( ) {
1338
- let event_cache_store =
1339
- get_event_cache_store( ) . await . unwrap( ) . into_event_cache_store( ) ;
1340
- event_cache_store. test_media_content( ) . await ;
1341
- }
1342
-
1343
- #[ async_test]
1344
- async fn test_replace_media_key( ) {
1345
- let event_cache_store =
1346
- get_event_cache_store( ) . await . unwrap( ) . into_event_cache_store( ) ;
1347
- event_cache_store. test_replace_media_key( ) . await ;
1348
- }
1349
-
1350
1139
#[ async_test]
1351
1140
async fn test_handle_updates_and_rebuild_linked_chunk( ) {
1352
1141
let event_cache_store =
0 commit comments