2
* This file is part of the webaccounts-browser-plugin.
3
* Copyright (C) Canonical Ltd. 2012
5
* Author: Alberto Mardegan <alberto.mardegan@canonical.com>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21
#include "fake-capture-service.h"
22
#include "login-handler.h"
24
#include <glib-object.h>
25
#include <gtest/gtest.h>
26
#include <libaccounts-glib/ag-account.h>
27
#include <libaccounts-glib/ag-manager.h>
29
TEST (npapi, wrong_domain) {
30
FakeCaptureService service;
31
static const gchar json_string[] = "{"
32
" 'login': 'my user name', "
33
" 'domain': 'invalid.com' "
36
fake_capture_service_init (&service);
38
/* This should fail because there isn't a provider handling the domain
40
webaccounts_login_handler_set_json (json_string);
41
EXPECT_FALSE (service.called);
43
fake_capture_service_unset (&service);
46
TEST (npapi, existing_account) {
49
FakeCaptureService service;
51
static const gchar json_string[] = "{"
52
" 'login': 'user@test.com', "
53
" 'domain': 'example.com' "
56
/* first, create an account for user@test.com */
57
manager = ag_manager_new ();
58
ASSERT_TRUE (manager != NULL);
60
account = ag_manager_create_account (manager, "MyProvider");
61
ASSERT_TRUE (account != NULL);
62
ag_account_set_display_name (account, "user@test.com");
63
ag_account_store_blocking (account, NULL);
65
g_object_unref (account);
66
g_object_unref (manager);
68
fake_capture_service_init (&service);
70
/* This should fail because an account for that username already exists */
71
webaccounts_login_handler_set_json (json_string);
72
EXPECT_FALSE (service.called);
74
fake_capture_service_unset (&service);
77
TEST (npapi, username) {
78
FakeCaptureService service;
79
static const gchar json_string[] = "{"
80
" 'login': 'my user name', "
81
" 'domain': 'example.com' "
84
fake_capture_service_init (&service);
86
webaccounts_login_handler_set_json (json_string);
87
EXPECT_TRUE (service.called);
88
EXPECT_STREQ ("my user name", service.username);
89
EXPECT_STREQ ("MyProvider", service.provider_name);
91
fake_capture_service_unset (&service);
94
TEST (npapi, cookies) {
95
FakeCaptureService service;
98
static const gchar json_string[] = "{"
99
" 'login': 'Happy User', "
100
" 'domain': 'example.com', "
102
" 'example.com': 'a list of cookies', "
103
" 'test.com': 'more cookies' "
107
fake_capture_service_init (&service);
109
webaccounts_login_handler_set_json (json_string);
110
EXPECT_TRUE (service.called);
111
EXPECT_STREQ ("Happy User", service.username);
112
EXPECT_STREQ ("MyProvider", service.provider_name);
113
ASSERT_TRUE (service.cookies != NULL);
115
/* check the cookie contents */
116
ok = g_variant_lookup (service.cookies, "example.com", "s", &cookie);
118
EXPECT_STREQ ("a list of cookies", cookie);
121
ok = g_variant_lookup (service.cookies, "test.com", "s", &cookie);
123
EXPECT_STREQ ("more cookies", cookie);
126
fake_capture_service_unset (&service);
129
int main (int argc, char **argv)
131
::testing::InitGoogleTest (&argc, argv);
135
return RUN_ALL_TESTS ();