| 210 |
210 |
| 211 provider = test_purple_credential_provider_new(); |
211 provider = test_purple_credential_provider_new(); |
| 212 |
212 |
| 213 /* Register the first time cleanly. */ |
213 /* Register the first time cleanly. */ |
| 214 r = purple_credential_manager_register_provider(manager, provider, &error); |
214 r = purple_credential_manager_register_provider(manager, provider, &error); |
| 215 g_assert_true(r); |
215 g_assert_no_error(error); |
| 216 g_assert_no_error(error); |
216 g_assert_true(r); |
| 217 |
217 |
| 218 /* Register again and verify the error. */ |
218 /* Register again and verify the error. */ |
| 219 r = purple_credential_manager_register_provider(manager, provider, &error); |
219 r = purple_credential_manager_register_provider(manager, provider, &error); |
| 220 g_assert_false(r); |
220 g_assert_false(r); |
| 221 g_assert_error(error, PURPLE_CREDENTIAL_MANAGER_DOMAIN, 0); |
221 g_assert_error(error, PURPLE_CREDENTIAL_MANAGER_DOMAIN, 0); |
| 222 g_clear_error(&error); |
222 g_clear_error(&error); |
| 223 |
223 |
| 224 /* Unregister the provider. */ |
224 /* Unregister the provider. */ |
| 225 r = purple_credential_manager_unregister_provider(manager, provider, |
225 r = purple_credential_manager_unregister_provider(manager, provider, |
| 226 &error); |
226 &error); |
| 227 g_assert_true(r); |
227 g_assert_no_error(error); |
| 228 g_assert_no_error(error); |
228 g_assert_true(r); |
| 229 |
229 |
| 230 /* Unregister the provider again and verify the error. */ |
230 /* Unregister the provider again and verify the error. */ |
| 231 r = purple_credential_manager_unregister_provider(manager, provider, |
231 r = purple_credential_manager_unregister_provider(manager, provider, |
| 232 &error); |
232 &error); |
| 233 g_assert_false(r); |
233 g_assert_false(r); |
| 281 manager = purple_credential_manager_get_default(); |
281 manager = purple_credential_manager_get_default(); |
| 282 |
282 |
| 283 /* Create the provider and register it in the manager. */ |
283 /* Create the provider and register it in the manager. */ |
| 284 provider = test_purple_credential_provider_new(); |
284 provider = test_purple_credential_provider_new(); |
| 285 r = purple_credential_manager_register_provider(manager, provider, &error); |
285 r = purple_credential_manager_register_provider(manager, provider, &error); |
| 286 g_assert_true(r); |
286 g_assert_no_error(error); |
| 287 g_assert_no_error(error); |
287 g_assert_true(r); |
| 288 |
288 |
| 289 /* Set the provider as active and verify it was successful. */ |
289 /* Set the provider as active and verify it was successful. */ |
| 290 r = purple_credential_manager_set_active_provider(manager, "test-provider", |
290 r = purple_credential_manager_set_active_provider(manager, "test-provider", |
| 291 &error); |
291 &error); |
| 292 g_assert_true(r); |
292 g_assert_no_error(error); |
| 293 g_assert_no_error(error); |
293 g_assert_true(r); |
| 294 |
294 |
| 295 /* Verify that unregistering the provider fails. */ |
295 /* Verify that unregistering the provider fails. */ |
| 296 r = purple_credential_manager_unregister_provider(manager, provider, |
296 r = purple_credential_manager_unregister_provider(manager, provider, |
| 297 &error); |
297 &error); |
| 298 g_assert_false(r); |
298 g_assert_false(r); |
| 299 g_assert_error(error, PURPLE_CREDENTIAL_MANAGER_DOMAIN, 0); |
299 g_assert_error(error, PURPLE_CREDENTIAL_MANAGER_DOMAIN, 0); |
| 300 g_clear_error(&error); |
300 g_clear_error(&error); |
| 301 |
301 |
| 302 /* Now unset the active provider. */ |
302 /* Now unset the active provider. */ |
| 303 r = purple_credential_manager_set_active_provider(manager, NULL, &error); |
303 r = purple_credential_manager_set_active_provider(manager, NULL, &error); |
| 304 g_assert_true(r); |
304 g_assert_no_error(error); |
| 305 g_assert_no_error(error); |
305 g_assert_true(r); |
| 306 |
306 |
| 307 /* Finally unregister the provider now that it's no longer active. */ |
307 /* Finally unregister the provider now that it's no longer active. */ |
| 308 r = purple_credential_manager_unregister_provider(manager, provider, |
308 r = purple_credential_manager_unregister_provider(manager, provider, |
| 309 &error); |
309 &error); |
| 310 g_assert_true(r); |
310 g_assert_no_error(error); |
| 311 g_assert_no_error(error); |
311 g_assert_true(r); |
| 312 |
312 |
| 313 /* And our final cleanup. */ |
313 /* And our final cleanup. */ |
| 314 g_clear_object(&provider); |
314 g_clear_object(&provider); |
| 315 } |
315 } |
| 316 |
316 |
| 341 test_purple_credential_manager_no_provider_read_password_idle(gpointer data) { |
341 test_purple_credential_manager_no_provider_read_password_idle(gpointer data) { |
| 342 PurpleCredentialManager *m = PURPLE_CREDENTIAL_MANAGER(data); |
342 PurpleCredentialManager *m = PURPLE_CREDENTIAL_MANAGER(data); |
| 343 PurpleAccount *account = NULL; |
343 PurpleAccount *account = NULL; |
| 344 |
344 |
| 345 account = purple_account_new("test", "test"); |
345 account = purple_account_new("test", "test"); |
| |
346 purple_account_set_remember_password(account, TRUE); |
| 346 |
347 |
| 347 purple_credential_manager_read_password_async(m, account, NULL, |
348 purple_credential_manager_read_password_async(m, account, NULL, |
| 348 test_purple_credential_manager_no_provider_read_password_cb, |
349 test_purple_credential_manager_no_provider_read_password_cb, |
| 349 account); |
350 account); |
| 350 |
351 |
| 384 test_purple_credential_manager_no_provider_write_password_idle(gpointer data) { |
385 test_purple_credential_manager_no_provider_write_password_idle(gpointer data) { |
| 385 PurpleCredentialManager *m = PURPLE_CREDENTIAL_MANAGER(data); |
386 PurpleCredentialManager *m = PURPLE_CREDENTIAL_MANAGER(data); |
| 386 PurpleAccount *account = NULL; |
387 PurpleAccount *account = NULL; |
| 387 |
388 |
| 388 account = purple_account_new("test", "test"); |
389 account = purple_account_new("test", "test"); |
| |
390 purple_account_set_remember_password(account, TRUE); |
| 389 |
391 |
| 390 purple_credential_manager_write_password_async(m, account, NULL, NULL, |
392 purple_credential_manager_write_password_async(m, account, NULL, NULL, |
| 391 test_purple_credential_manager_no_provider_write_password_cb, |
393 test_purple_credential_manager_no_provider_write_password_cb, |
| 392 account); |
394 account); |
| 393 |
395 |
| 428 test_purple_credential_manager_no_provider_clear_password_idle(gpointer data) { |
430 test_purple_credential_manager_no_provider_clear_password_idle(gpointer data) { |
| 429 PurpleCredentialManager *m = PURPLE_CREDENTIAL_MANAGER(data); |
431 PurpleCredentialManager *m = PURPLE_CREDENTIAL_MANAGER(data); |
| 430 PurpleAccount *account = NULL; |
432 PurpleAccount *account = NULL; |
| 431 |
433 |
| 432 account = purple_account_new("test", "test"); |
434 account = purple_account_new("test", "test"); |
| |
435 purple_account_set_remember_password(account, TRUE); |
| 433 |
436 |
| 434 purple_credential_manager_clear_password_async(m, account, NULL, |
437 purple_credential_manager_clear_password_async(m, account, NULL, |
| 435 test_purple_credential_manager_no_provider_clear_password_cb, |
438 test_purple_credential_manager_no_provider_clear_password_cb, |
| 436 account); |
439 account); |
| 437 |
440 |
| 506 test_purple_credential_manager_read_password_idle(gpointer data) { |
509 test_purple_credential_manager_read_password_idle(gpointer data) { |
| 507 PurpleCredentialManager *m = PURPLE_CREDENTIAL_MANAGER(data); |
510 PurpleCredentialManager *m = PURPLE_CREDENTIAL_MANAGER(data); |
| 508 PurpleAccount *account = NULL; |
511 PurpleAccount *account = NULL; |
| 509 |
512 |
| 510 account = purple_account_new("test", "test"); |
513 account = purple_account_new("test", "test"); |
| |
514 purple_account_set_remember_password(account, TRUE); |
| 511 |
515 |
| 512 purple_credential_manager_read_password_async(m, account, NULL, |
516 purple_credential_manager_read_password_async(m, account, NULL, |
| 513 test_purple_credential_manager_read_password_cb, |
517 test_purple_credential_manager_read_password_cb, |
| 514 account); |
518 account); |
| 515 |
519 |
| 522 PurpleCredentialProvider *p = test_purple_credential_provider_new(); |
526 PurpleCredentialProvider *p = test_purple_credential_provider_new(); |
| 523 GError *e = NULL; |
527 GError *e = NULL; |
| 524 gboolean r = FALSE; |
528 gboolean r = FALSE; |
| 525 |
529 |
| 526 r = purple_credential_manager_register_provider(m, p, &e); |
530 r = purple_credential_manager_register_provider(m, p, &e); |
| 527 g_assert_true(r); |
531 g_assert_no_error(e); |
| 528 g_assert_no_error(e); |
532 g_assert_true(r); |
| 529 |
533 |
| 530 r = purple_credential_manager_set_active_provider(m, "test-provider", &e); |
534 r = purple_credential_manager_set_active_provider(m, "test-provider", &e); |
| 531 g_assert_true(r); |
535 g_assert_no_error(e); |
| 532 g_assert_no_error(e); |
536 g_assert_true(r); |
| 533 |
537 |
| 534 g_idle_add(test_purple_credential_manager_read_password_idle, m); |
538 g_idle_add(test_purple_credential_manager_read_password_idle, m); |
| 535 g_timeout_add_seconds(10, test_purple_credential_manager_timeout_cb, loop); |
539 g_timeout_add_seconds(10, test_purple_credential_manager_timeout_cb, loop); |
| 536 |
540 |
| 537 g_main_loop_run(loop); |
541 g_main_loop_run(loop); |
| 538 |
542 |
| 539 r = purple_credential_manager_set_active_provider(m, NULL, &e); |
543 r = purple_credential_manager_set_active_provider(m, NULL, &e); |
| 540 g_assert_true(r); |
544 g_assert_no_error(e); |
| 541 g_assert_no_error(e); |
545 g_assert_true(r); |
| 542 |
546 |
| 543 r = purple_credential_manager_unregister_provider(m, p, &e); |
547 r = purple_credential_manager_unregister_provider(m, p, &e); |
| 544 g_assert_true(r); |
548 g_assert_no_error(e); |
| 545 g_assert_no_error(e); |
549 g_assert_true(r); |
| 546 |
550 |
| 547 g_clear_object(&p); |
551 g_clear_object(&p); |
| 548 } |
552 } |
| 549 |
553 |
| 550 static void |
554 static void |
| 555 PurpleAccount *account = PURPLE_ACCOUNT(d); |
559 PurpleAccount *account = PURPLE_ACCOUNT(d); |
| 556 GError *error = NULL; |
560 GError *error = NULL; |
| 557 gboolean r = FALSE; |
561 gboolean r = FALSE; |
| 558 |
562 |
| 559 r = purple_credential_manager_write_password_finish(manager, res, &error); |
563 r = purple_credential_manager_write_password_finish(manager, res, &error); |
| 560 g_assert_true(r); |
564 g_assert_no_error(error); |
| 561 g_assert_no_error(error); |
565 g_assert_true(r); |
| 562 |
566 |
| 563 g_clear_object(&account); |
567 g_clear_object(&account); |
| 564 |
568 |
| 565 g_main_loop_quit(loop); |
569 g_main_loop_quit(loop); |
| 566 } |
570 } |
| 569 test_purple_credential_manager_write_password_idle(gpointer data) { |
573 test_purple_credential_manager_write_password_idle(gpointer data) { |
| 570 PurpleCredentialManager *m = PURPLE_CREDENTIAL_MANAGER(data); |
574 PurpleCredentialManager *m = PURPLE_CREDENTIAL_MANAGER(data); |
| 571 PurpleAccount *account = NULL; |
575 PurpleAccount *account = NULL; |
| 572 |
576 |
| 573 account = purple_account_new("test", "test"); |
577 account = purple_account_new("test", "test"); |
| |
578 purple_account_set_remember_password(account, TRUE); |
| 574 |
579 |
| 575 purple_credential_manager_write_password_async(m, account, NULL, NULL, |
580 purple_credential_manager_write_password_async(m, account, NULL, NULL, |
| 576 test_purple_credential_manager_write_password_cb, |
581 test_purple_credential_manager_write_password_cb, |
| 577 account); |
582 account); |
| 578 |
583 |
| 585 PurpleCredentialProvider *p = test_purple_credential_provider_new(); |
590 PurpleCredentialProvider *p = test_purple_credential_provider_new(); |
| 586 GError *e = NULL; |
591 GError *e = NULL; |
| 587 gboolean r = FALSE; |
592 gboolean r = FALSE; |
| 588 |
593 |
| 589 r = purple_credential_manager_register_provider(m, p, &e); |
594 r = purple_credential_manager_register_provider(m, p, &e); |
| 590 g_assert_true(r); |
595 g_assert_no_error(e); |
| 591 g_assert_no_error(e); |
596 g_assert_true(r); |
| 592 |
597 |
| 593 r = purple_credential_manager_set_active_provider(m, "test-provider", &e); |
598 r = purple_credential_manager_set_active_provider(m, "test-provider", &e); |
| 594 g_assert_true(r); |
599 g_assert_no_error(e); |
| 595 g_assert_no_error(e); |
600 g_assert_true(r); |
| 596 |
601 |
| 597 g_idle_add(test_purple_credential_manager_write_password_idle, m); |
602 g_idle_add(test_purple_credential_manager_write_password_idle, m); |
| 598 g_timeout_add_seconds(10, test_purple_credential_manager_timeout_cb, loop); |
603 g_timeout_add_seconds(10, test_purple_credential_manager_timeout_cb, loop); |
| 599 |
604 |
| 600 g_main_loop_run(loop); |
605 g_main_loop_run(loop); |
| 601 |
606 |
| 602 r = purple_credential_manager_set_active_provider(m, NULL, &e); |
607 r = purple_credential_manager_set_active_provider(m, NULL, &e); |
| 603 g_assert_true(r); |
608 g_assert_no_error(e); |
| 604 g_assert_no_error(e); |
609 g_assert_true(r); |
| 605 |
610 |
| 606 r = purple_credential_manager_unregister_provider(m, p, &e); |
611 r = purple_credential_manager_unregister_provider(m, p, &e); |
| 607 g_assert_true(r); |
612 g_assert_no_error(e); |
| 608 g_assert_no_error(e); |
613 g_assert_true(r); |
| 609 |
614 |
| 610 g_clear_object(&p); |
615 g_clear_object(&p); |
| 611 } |
616 } |
| 612 |
617 |
| 613 static void |
618 static void |
| 618 PurpleAccount *account = PURPLE_ACCOUNT(d); |
623 PurpleAccount *account = PURPLE_ACCOUNT(d); |
| 619 GError *error = NULL; |
624 GError *error = NULL; |
| 620 gboolean r = FALSE; |
625 gboolean r = FALSE; |
| 621 |
626 |
| 622 r = purple_credential_manager_clear_password_finish(manager, res, &error); |
627 r = purple_credential_manager_clear_password_finish(manager, res, &error); |
| 623 g_assert_true(r); |
628 g_assert_no_error(error); |
| 624 g_assert_no_error(error); |
629 g_assert_true(r); |
| 625 |
630 |
| 626 g_clear_object(&account); |
631 g_clear_object(&account); |
| 627 |
632 |
| 628 g_main_loop_quit(loop); |
633 g_main_loop_quit(loop); |
| 629 } |
634 } |
| 632 test_purple_credential_manager_clear_password_idle(gpointer data) { |
637 test_purple_credential_manager_clear_password_idle(gpointer data) { |
| 633 PurpleCredentialManager *m = PURPLE_CREDENTIAL_MANAGER(data); |
638 PurpleCredentialManager *m = PURPLE_CREDENTIAL_MANAGER(data); |
| 634 PurpleAccount *account = NULL; |
639 PurpleAccount *account = NULL; |
| 635 |
640 |
| 636 account = purple_account_new("test", "test"); |
641 account = purple_account_new("test", "test"); |
| |
642 purple_account_set_remember_password(account, TRUE); |
| 637 |
643 |
| 638 purple_credential_manager_clear_password_async(m, account, NULL, |
644 purple_credential_manager_clear_password_async(m, account, NULL, |
| 639 test_purple_credential_manager_clear_password_cb, |
645 test_purple_credential_manager_clear_password_cb, |
| 640 account); |
646 account); |
| 641 |
647 |
| 648 PurpleCredentialProvider *p = test_purple_credential_provider_new(); |
654 PurpleCredentialProvider *p = test_purple_credential_provider_new(); |
| 649 GError *e = NULL; |
655 GError *e = NULL; |
| 650 gboolean r = FALSE; |
656 gboolean r = FALSE; |
| 651 |
657 |
| 652 r = purple_credential_manager_register_provider(m, p, &e); |
658 r = purple_credential_manager_register_provider(m, p, &e); |
| 653 g_assert_true(r); |
659 g_assert_no_error(e); |
| 654 g_assert_no_error(e); |
660 g_assert_true(r); |
| 655 |
661 |
| 656 r = purple_credential_manager_set_active_provider(m, "test-provider", &e); |
662 r = purple_credential_manager_set_active_provider(m, "test-provider", &e); |
| 657 g_assert_true(r); |
663 g_assert_no_error(e); |
| 658 g_assert_no_error(e); |
664 g_assert_true(r); |
| 659 |
665 |
| 660 g_idle_add(test_purple_credential_manager_clear_password_idle, m); |
666 g_idle_add(test_purple_credential_manager_clear_password_idle, m); |
| 661 g_timeout_add_seconds(10, test_purple_credential_manager_timeout_cb, loop); |
667 g_timeout_add_seconds(10, test_purple_credential_manager_timeout_cb, loop); |
| 662 |
668 |
| 663 g_main_loop_run(loop); |
669 g_main_loop_run(loop); |
| 664 |
670 |
| 665 r = purple_credential_manager_set_active_provider(m, NULL, &e); |
671 r = purple_credential_manager_set_active_provider(m, NULL, &e); |
| 666 g_assert_true(r); |
672 g_assert_no_error(e); |
| 667 g_assert_no_error(e); |
673 g_assert_true(r); |
| 668 |
674 |
| 669 r = purple_credential_manager_unregister_provider(m, p, &e); |
675 r = purple_credential_manager_unregister_provider(m, p, &e); |
| 670 g_assert_true(r); |
676 g_assert_no_error(e); |
| 671 g_assert_no_error(e); |
677 g_assert_true(r); |
| 672 |
678 |
| 673 g_clear_object(&p); |
679 g_clear_object(&p); |
| 674 } |
680 } |
| 675 |
681 |
| 676 static void |
682 static void |
| 681 PurpleRequestFields *fields = NULL; |
687 PurpleRequestFields *fields = NULL; |
| 682 GError *e = NULL; |
688 GError *e = NULL; |
| 683 gboolean r = FALSE; |
689 gboolean r = FALSE; |
| 684 |
690 |
| 685 r = purple_credential_manager_register_provider(m, p, &e); |
691 r = purple_credential_manager_register_provider(m, p, &e); |
| 686 g_assert_true(r); |
692 g_assert_no_error(e); |
| 687 g_assert_no_error(e); |
693 g_assert_true(r); |
| 688 |
694 |
| 689 r = purple_credential_manager_set_active_provider(m, "test-provider", &e); |
695 r = purple_credential_manager_set_active_provider(m, "test-provider", &e); |
| 690 g_assert_true(r); |
696 g_assert_no_error(e); |
| 691 g_assert_no_error(e); |
697 g_assert_true(r); |
| 692 |
698 |
| 693 fields = purple_credential_manager_read_settings(m, &e); |
699 fields = purple_credential_manager_read_settings(m, &e); |
| |
700 g_assert_no_error(e); |
| 694 g_assert_nonnull(fields); |
701 g_assert_nonnull(fields); |
| 695 g_assert_no_error(e); |
|
| 696 purple_request_fields_destroy(fields); |
702 purple_request_fields_destroy(fields); |
| 697 |
703 |
| 698 fields = purple_request_fields_new(); |
704 fields = purple_request_fields_new(); |
| 699 r = purple_credential_manager_write_settings(m, fields, &e); |
705 r = purple_credential_manager_write_settings(m, fields, &e); |
| |
706 g_assert_no_error(e); |
| 700 g_assert_true(r); |
707 g_assert_true(r); |
| 701 g_assert_true(tp->fields == fields); |
708 g_assert_true(tp->fields == fields); |
| 702 g_assert_no_error(e); |
|
| 703 |
709 |
| 704 purple_request_fields_destroy(fields); |
710 purple_request_fields_destroy(fields); |
| 705 |
711 |
| 706 g_clear_object(&p); |
712 g_clear_object(&p); |
| 707 } |
713 } |