1
1
#! /usr/bin/env python3
2
# -*- coding: utf-8 -*-
2
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
4
# Copyright (C) 2013 Canonical Ltd.
4
# Copyright (C) 2013, 2014 Canonical Ltd.
5
5
# Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
7
# This program is free software: you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License version 3, as published
9
# by the Free Software Foundation.
11
from autopilot.testcase import AutopilotTestCase
12
from autopilot.input import Mouse, Touch, Pointer
13
from autopilot.platform import model
14
from autopilot.matchers import Eventually
15
from subprocess import Popen
16
from testtools.matchers import Contains, Equals, NotEquals, GreaterThan
17
from time import sleep
20
from online_accounts_ui.emulators.items import EmulatorBase
7
# This file is part of ubuntu-system-settings-online-accounts.
9
# ubuntu-system-settings-online-accounts is free software: you can
10
# redistribute it and/or modify it under the terms of the GNU General Public
11
# License as published by the Free Software Foundation; version 3.
13
# ubuntu-system-settings-online-accounts is distributed in the hope that it
14
# will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
15
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
from online_accounts_ui import tests
23
24
# You can find a couple of OAuth 1.0a and 2.0 tests in the repository history
29
30
# This issue will be solved when we move the signon-ui implementation in the
30
31
# same process as online-accounts-ui
33
class OnlineAccountsUiTests(AutopilotTestCase):
34
if model() == 'Desktop':
36
('with mouse', dict(input_device_class=Mouse)),
40
('with touch', dict(input_device_class=Touch)),
44
super(OnlineAccountsUiTests, self).setUp()
46
# On the phone, this fails because of https://bugs.launchpad.net/bugs/1252294
47
if model() != 'Desktop':
50
self.pointer = Pointer(self.input_device_class.create())
51
# Increase the timeout of online-accounts-ui, to make sure it won't
52
# quit before the system settings panel asks it to open.
53
self.patch_environment('OAU_DAEMON_TIMEOUT', '120')
54
self.app = self.launch_test_application('online-accounts-ui',
55
'--desktop_file_hint=/usr/share/applications/online-accounts-ui.desktop',
57
emulator_base=EmulatorBase,
59
self.system_settings = Popen(['system-settings', 'online-accounts',
60
'--desktop_file_hint=/usr/share/applications/ubuntu-system-settings.desktop'])
62
self.window = self.app.select_single("QQuickView")
63
self.assertThat(self.window.visible, Eventually(Equals(True)))
66
super(OnlineAccountsUiTests, self).tearDown()
67
# This matches the logic in setUp()
68
if model() != 'Desktop':
70
self.system_settings.terminate()
33
class MainViewTestCase(tests.BaseOnlineAccountsUITestCase):
72
35
def test_title(self):
73
""" Checks whether the Online Accounts window title is correct """
74
# On the phone, this fails because of https://bugs.launchpad.net/bugs/1252294
75
if model() != 'Desktop':
78
header = self.window.select_single('Header', visible=True)
79
self.assertThat(header, NotEquals(None))
80
self.assertThat(header.title, Eventually(Equals('Accounts')))
36
"""Checks whether the Online Accounts window title is correct."""
37
# TODO turn this into a QML test. --elopio - 2014-07-03
38
header = self.application.main_view.get_header()
39
self.assertTrue(header.visible)
40
self.assertEquals(header.title, 'Accounts')
43
class AvailableProvidersTestCase(tests.BaseOnlineAccountsUITestCase):
45
required_providers = ['FakeOAuth', 'TestLogin']
46
scenarios = [(provider, {'provider': provider})
47
for provider in required_providers]
82
49
def test_available_providers(self):
83
""" Checks whether all the expected providers are available """
84
# On the phone, this fails because of https://bugs.launchpad.net/bugs/1252294
85
if model() != 'Desktop':
88
required_providers = [
91
for provider in required_providers:
92
provider_item = self.app.select_single('Standard', text=provider)
93
self.assertThat(provider_item, NotEquals(None))
50
"""Checks whether all the expected providers are available."""
51
no_accounts_page = self.application.main_view.no_accounts_page
52
available_providers = no_accounts_page.get_providers()
53
self.assertIn(self.provider, available_providers)
56
class CreateAccountTestCase(tests.BaseOnlineAccountsUITestCase):
95
58
def test_create_account_with_form(self):
96
""" Test the creation of an account using a username/password form"""
97
# On the phone, this fails because of https://bugs.launchpad.net/bugs/1252294
98
if model() != 'Desktop':
100
page = self.app.select_single('NoAccountsPage')
101
self.assertThat(page, NotEquals(None))
103
provider_item = self.app.select_single('Standard', text='TestLogin')
104
self.assertThat(provider_item, NotEquals(None))
106
# Depending on the number of installed providers, it may be that our
107
# test provider is not visible; in that case, scroll the page
108
self.pointer.move_to_object(page)
109
(page_center_x, page_center_y) = self.pointer.position()
110
page_bottom = page.globalRect[1] + page.globalRect[3]
111
while provider_item.center[1] > page_bottom - 20:
112
self.pointer.move(page_center_x, page_center_y)
114
self.pointer.move(page_center_x, page_center_y - provider_item.height * 2)
115
# wait some time before releasing, to avoid a flick
117
self.pointer.release()
118
self.pointer.move_to_object(provider_item)
121
# Move to the username field
122
username_field = self.app.select_single('TextField', objectName='usernameField')
123
self.pointer.move_to_object(username_field)
125
self.keyboard.type('pinkuser')
126
self.keyboard.press_and_release('Tab')
127
self.keyboard.type('lolcat')
129
continue_btn = self.app.select_single('Button', objectName='continueButton')
130
self.pointer.move_to_object(continue_btn)
133
# The account should be created shortly
135
account_item = self.app.select_single('AccountItem', text='TestLogin')
136
self.assertThat(account_item, NotEquals(None))
137
self.assertThat(account_item.subText, Equals('pinkuser'))
140
self.pointer.move_to_object(account_item)
144
edit_page = self.app.select_single('AccountEditPage')
145
self.assertThat(edit_page, NotEquals(None))
146
remove_button = edit_page.select_single('Button')
147
self.assertThat(remove_button, NotEquals(None))
148
self.pointer.move_to_object(remove_button)
152
removal_page = self.app.select_single('RemovalConfirmation')
153
self.assertThat(removal_page, NotEquals(None))
154
remove_button = removal_page.select_single('Button', text='Remove')
155
self.assertThat(remove_button, NotEquals(None))
156
self.pointer.move_to_object(remove_button)
159
# Check that the account has been deleted
160
account_item.wait_until_destroyed()
59
"""Test the creation of an account using a username/password form."""
60
accounts_page = self.application.main_view.add_test_login_account(
61
user_name='pinkuser', password='lolcat')
63
self.assertIn(('TestLogin', 'pinkuser'), accounts_page.get_accounts())
65
accounts_page.delete_account('TestLogin', 'pinkuser')