@@ -285,7 +285,7 @@ mod tests {
285
285
use crate :: contact:: ContactId ;
286
286
use crate :: message:: { MessengerMessage , Viewtype } ;
287
287
use crate :: receive_imf:: receive_imf;
288
- use crate :: test_utils:: TestContext ;
288
+ use crate :: test_utils:: { TestContext , TestContextManager } ;
289
289
290
290
#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
291
291
async fn test_htmlparse_plain_unspecified ( ) {
@@ -442,24 +442,25 @@ test some special html-characters as < > and & but also " and &#x
442
442
#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
443
443
async fn test_html_forwarding ( ) {
444
444
// alice receives a non-delta html-message
445
- let alice = TestContext :: new_alice ( ) . await ;
445
+ let mut tcm = TestContextManager :: new ( ) ;
446
+ let alice = & tcm. alice ( ) . await ;
446
447
let chat = alice
447
448
. create_chat_with_contact ( "" , "[email protected] " )
448
449
. await ;
449
450
let raw = include_bytes ! ( "../test-data/message/text_alt_plain_html.eml" ) ;
450
- receive_imf ( & alice, raw, false ) . await . unwrap ( ) ;
451
+ receive_imf ( alice, raw, false ) . await . unwrap ( ) ;
451
452
let msg = alice. get_last_msg_in ( chat. get_id ( ) ) . await ;
452
453
assert_ne ! ( msg. get_from_id( ) , ContactId :: SELF ) ;
453
454
assert_eq ! ( msg. is_dc_message, MessengerMessage :: No ) ;
454
455
assert ! ( !msg. is_forwarded( ) ) ;
455
456
assert ! ( msg. get_text( ) . contains( "this is plain" ) ) ;
456
457
assert ! ( msg. has_html( ) ) ;
457
- let html = msg. get_id ( ) . get_html ( & alice) . await . unwrap ( ) . unwrap ( ) ;
458
+ let html = msg. get_id ( ) . get_html ( alice) . await . unwrap ( ) . unwrap ( ) ;
458
459
assert ! ( html. contains( "this is <b>html</b>" ) ) ;
459
460
460
461
// alice: create chat with bob and forward received html-message there
461
462
let chat = alice
. create_chat_with_contact ( "" , "[email protected] " ) . await ;
462
- forward_msgs ( & alice, & [ msg. get_id ( ) ] , chat. get_id ( ) )
463
+ forward_msgs ( alice, & [ msg. get_id ( ) ] , chat. get_id ( ) )
463
464
. await
464
465
. unwrap ( ) ;
465
466
let msg = alice. get_last_msg_in ( chat. get_id ( ) ) . await ;
@@ -468,11 +469,11 @@ test some special html-characters as < > and & but also " and &#x
468
469
assert ! ( msg. is_forwarded( ) ) ;
469
470
assert ! ( msg. get_text( ) . contains( "this is plain" ) ) ;
470
471
assert ! ( msg. has_html( ) ) ;
471
- let html = msg. get_id ( ) . get_html ( & alice) . await . unwrap ( ) . unwrap ( ) ;
472
+ let html = msg. get_id ( ) . get_html ( alice) . await . unwrap ( ) . unwrap ( ) ;
472
473
assert ! ( html. contains( "this is <b>html</b>" ) ) ;
473
474
474
475
// bob: check that bob also got the html-part of the forwarded message
475
- let bob = TestContext :: new_bob ( ) . await ;
476
+ let bob = & tcm . bob ( ) . await ;
476
477
let chat = bob
. create_chat_with_contact ( "" , "[email protected] " ) . await ;
477
478
let msg = bob. recv_msg ( & alice. pop_sent_msg ( ) . await ) . await ;
478
479
assert_eq ! ( chat. id, msg. chat_id) ;
@@ -481,7 +482,7 @@ test some special html-characters as < > and & but also " and &#x
481
482
assert ! ( msg. is_forwarded( ) ) ;
482
483
assert ! ( msg. get_text( ) . contains( "this is plain" ) ) ;
483
484
assert ! ( msg. has_html( ) ) ;
484
- let html = msg. get_id ( ) . get_html ( & bob) . await . unwrap ( ) . unwrap ( ) ;
485
+ let html = msg. get_id ( ) . get_html ( bob) . await . unwrap ( ) . unwrap ( ) ;
485
486
assert ! ( html. contains( "this is <b>html</b>" ) ) ;
486
487
}
487
488
@@ -519,10 +520,11 @@ test some special html-characters as < > and & but also " and &#x
519
520
520
521
#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
521
522
async fn test_html_forwarding_encrypted ( ) {
523
+ let mut tcm = TestContextManager :: new ( ) ;
522
524
// Alice receives a non-delta html-message
523
525
// (`ShowEmails=AcceptedContacts` lets Alice actually receive non-delta messages for known
524
526
// contacts, the contact is marked as known by creating a chat using `chat_with_contact()`)
525
- let alice = TestContext :: new_alice ( ) . await ;
527
+ let alice = & tcm . alice ( ) . await ;
526
528
alice
527
529
. set_config ( Config :: ShowEmails , Some ( "1" ) )
528
530
. await
@@ -531,19 +533,19 @@ test some special html-characters as < > and & but also " and &#x
531
533
. create_chat_with_contact ( "" , "[email protected] " )
532
534
. await ;
533
535
let raw = include_bytes ! ( "../test-data/message/text_alt_plain_html.eml" ) ;
534
- receive_imf ( & alice, raw, false ) . await . unwrap ( ) ;
536
+ receive_imf ( alice, raw, false ) . await . unwrap ( ) ;
535
537
let msg = alice. get_last_msg_in ( chat. get_id ( ) ) . await ;
536
538
537
539
// forward the message to saved-messages,
538
540
// this will encrypt the message as new_alice() has set up keys
539
541
let chat = alice. get_self_chat ( ) . await ;
540
- forward_msgs ( & alice, & [ msg. get_id ( ) ] , chat. get_id ( ) )
542
+ forward_msgs ( alice, & [ msg. get_id ( ) ] , chat. get_id ( ) )
541
543
. await
542
544
. unwrap ( ) ;
543
545
let msg = alice. pop_sent_msg ( ) . await ;
544
546
545
547
// receive the message on another device
546
- let alice = TestContext :: new_alice ( ) . await ;
548
+ let alice = & tcm . alice ( ) . await ;
547
549
alice
548
550
. set_config ( Config :: ShowEmails , Some ( "0" ) )
549
551
. await
@@ -556,38 +558,39 @@ test some special html-characters as < > and & but also " and &#x
556
558
assert ! ( msg. is_forwarded( ) ) ;
557
559
assert ! ( msg. get_text( ) . contains( "this is plain" ) ) ;
558
560
assert ! ( msg. has_html( ) ) ;
559
- let html = msg. get_id ( ) . get_html ( & alice) . await . unwrap ( ) . unwrap ( ) ;
561
+ let html = msg. get_id ( ) . get_html ( alice) . await . unwrap ( ) . unwrap ( ) ;
560
562
assert ! ( html. contains( "this is <b>html</b>" ) ) ;
561
563
}
562
564
563
565
#[ tokio:: test( flavor = "multi_thread" , worker_threads = 2 ) ]
564
566
async fn test_set_html ( ) {
565
- let alice = TestContext :: new_alice ( ) . await ;
566
- let bob = TestContext :: new_bob ( ) . await ;
567
+ let mut tcm = TestContextManager :: new ( ) ;
568
+ let alice = & tcm. alice ( ) . await ;
569
+ let bob = & tcm. bob ( ) . await ;
567
570
568
571
// alice sends a message with html-part to bob
569
- let chat_id = alice. create_chat ( & bob) . await . id ;
572
+ let chat_id = alice. create_chat ( bob) . await . id ;
570
573
let mut msg = Message :: new_text ( "plain text" . to_string ( ) ) ;
571
574
msg. set_html ( Some ( "<b>html</b> text" . to_string ( ) ) ) ;
572
575
assert ! ( msg. mime_modified) ;
573
- chat:: send_msg ( & alice, chat_id, & mut msg) . await . unwrap ( ) ;
576
+ chat:: send_msg ( alice, chat_id, & mut msg) . await . unwrap ( ) ;
574
577
575
578
// check the message is written correctly to alice's db
576
579
let msg = alice. get_last_msg_in ( chat_id) . await ;
577
580
assert_eq ! ( msg. get_text( ) , "plain text" ) ;
578
581
assert ! ( !msg. is_forwarded( ) ) ;
579
582
assert ! ( msg. mime_modified) ;
580
- let html = msg. get_id ( ) . get_html ( & alice) . await . unwrap ( ) . unwrap ( ) ;
583
+ let html = msg. get_id ( ) . get_html ( alice) . await . unwrap ( ) . unwrap ( ) ;
581
584
assert ! ( html. contains( "<b>html</b> text" ) ) ;
582
585
583
586
// let bob receive the message
584
- let chat_id = bob. create_chat ( & alice) . await . id ;
587
+ let chat_id = bob. create_chat ( alice) . await . id ;
585
588
let msg = bob. recv_msg ( & alice. pop_sent_msg ( ) . await ) . await ;
586
589
assert_eq ! ( msg. chat_id, chat_id) ;
587
590
assert_eq ! ( msg. get_text( ) , "plain text" ) ;
588
591
assert ! ( !msg. is_forwarded( ) ) ;
589
592
assert ! ( msg. mime_modified) ;
590
- let html = msg. get_id ( ) . get_html ( & bob) . await . unwrap ( ) . unwrap ( ) ;
593
+ let html = msg. get_id ( ) . get_html ( bob) . await . unwrap ( ) . unwrap ( ) ;
591
594
assert ! ( html. contains( "<b>html</b> text" ) ) ;
592
595
}
593
596
0 commit comments