Exemplo n.º 1
0
class DisabledTogglesTestCase(gallery.GalleryTestCase):

    toggles_scenarios = [('checkbox disabled unchecked',
                          dict(object_name='checkbox_disabled_unchecked',
                               initial_state=False)),
                         ('checkbox disabled checked',
                          dict(object_name='checkbox_disabled_checked',
                               initial_state=True)),
                         ('switch disabled unchecked',
                          dict(object_name='switch_disabled_unchecked',
                               initial_state=False)),
                         ('switch disabled checked',
                          dict(object_name='switch_disabled_checked',
                               initial_state=True))]

    scenarios = testscenarios.multiply_scenarios(
        ubuntu_scenarios.get_device_simulation_scenarios(), toggles_scenarios)

    def setUp(self):
        super().setUp()
        self.open_page('togglesElement')

    def test_change_toggles_state(self):
        toggle = self.main_view.select_single(emulators.CheckBox,
                                              objectName=self.object_name)
        self.assertThat(toggle.enabled, Equals(False))
        self.assertThat(toggle.checked, Equals(self.initial_state))

        self.assertRaises(AssertionError, toggle.change_state, timeout=1)
Exemplo n.º 2
0
class MainWindowTestCase(tests.UnityTestCase):

    scenarios = ubuntu_scenarios.get_device_simulation_scenarios()

    def setUp(self):
        super().setUp()
        self.launch_unity()
        process_helpers.unlock_unity()
Exemplo n.º 3
0
class IndicatorTestCase(tests.UnityTestCase):

    device_emulation_scenarios = (
        ubuntu_scenarios.get_device_simulation_scenarios())

    def setUp(self):
        super().setUp()
        self.unity_proxy = self.launch_unity()
        process_helpers.unlock_unity()
 def test_get_nexus_4_scenario(self):
     expected_scenarios = [
         ('Simulating Nexus 4 in desktop',
          dict(app_width=768, app_height=1280, grid_unit_px=18)),
     ]
     with mock.patch('autopilot.platform.model') as mock_model:
         mock_model.return_value = 'Desktop'
         scenarios = ubuntu_scenarios.get_device_simulation_scenarios(
             devices=ubuntu_scenarios.NEXUS4_DEVICE)
     self.assertEqual(expected_scenarios, scenarios)
    def test_get_default_scenarios_must_return_supported_devices(self):
        expected_scenarios = [
            ('Simulating Nexus 4 in desktop',
             dict(app_width=768, app_height=1280, grid_unit_px=18)),
            ('Simulating Nexus 10 in desktop',
             dict(app_width=2560, app_height=1600, grid_unit_px=20))
        ]

        with mock.patch('autopilot.platform.model') as mock_model:
            mock_model.return_value = 'Desktop'
            scenarios = ubuntu_scenarios.get_device_simulation_scenarios()
        self.assertEqual(expected_scenarios, scenarios)
Exemplo n.º 6
0
class WriteAndClearTextInputTestCase(GalleryTestCase):

    def text_to_write_string():
        return 'Hello World'

    def text_to_write_number():
        return locale.format('%.2f', -1001.23)

    # text_to_write is a function to ensure
    # that locale is evaluated after setUp
    text_input_scenarios = [
        ('standard textfield', dict(
            objectName='textfield_standard',
            text_to_write=text_to_write_string,
            expected_text=text_to_write_string())),
        ('password textfield', dict(
            objectName='textfield_password',
            text_to_write=text_to_write_string,
            expected_text=text_to_write_string())),
        # The text_to_write contains a decimal separator based on locale
        # eg. -1001.23 or -1001,23 or -۱۰۰۱٫۲۳
        # The test expects integers, TextField rejects that character
        ('only integers textfield', dict(
            objectName='textfield_numbers',
            text_to_write=text_to_write_number,
            expected_text='-100123'))
    ]

    scenarios = testscenarios.multiply_scenarios(
        ubuntu_scenarios.get_device_simulation_scenarios(),
        text_input_scenarios)

    def setUp(self):
        super().setUp()
        # Apply the user locale from the environment
        # The UITK does the same, so the test must be localized
        locale.setlocale(locale.LC_ALL, "")
        self.open_page('textinputsElement')

    def test_write_on_textfield_must_update_text(self):
        textfield = self.main_view.select_single(
            emulators.TextField, objectName=self.objectName)

        textfield.write(self.text_to_write())
        self.assertEqual(self.expected_text, textfield.text)

    def test_clear_textfield_must_remove_text(self):
        textfield = self.main_view.select_single(
            emulators.TextField, objectName=self.objectName)
        textfield.write(self.text_to_write())

        textfield.clear()
        self.assertEqual('', textfield.text)
Exemplo n.º 7
0
class GalleryAppTestCase(gallery.GalleryTestCase):
    """Generic tests for the Gallery"""

    scenarios = ubuntu_scenarios.get_device_simulation_scenarios()

    def test_select_main_view_must_return_main_window_emulator(self):
        main_view = self.main_view
        self.assertIsInstance(main_view, ubuntuuitoolkit.MainView)

    def test_slider(self):
        self.open_page('slidersElement')

        item_data = [["slider_standard"], ["slider_live"], ["slider_range"]]

        for data in item_data:
            objName = data[0]
            self.getObject(objName)
            self.tap(objName)

            # TODO: move slider value

    def test_progress_and_activity(self):
        self.open_page('progressBarsElement')

        item_data = [["progressbar_standard"], ["progressbar_indeterminate"],
                     ["activityindicator_standard"]]

        for data in item_data:
            objName = data[0]
            self.getObject(objName)
            self.tap(objName)

            # TODO: check for properties

    def test_ubuntushape(self):
        # Flaky test case
        # FIXME: https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1308979
        return

        self.open_page('ubuntuShapesElement')

        item_data = [["ubuntushape_color_hex"],
                     ["ubuntushape_color_lightblue"],
                     ["ubuntushape_color_darkgray"], ["ubuntushape_image"],
                     ["ubuntushape_radius_small"],
                     ["ubuntushape_radius_medium"], ["ubuntushape_sizes_15_6"],
                     ["ubuntushape_sizes_10_14"]]

        for data in item_data:
            objName = data[0]
            self.getObject(objName)
class SystemIntegrationTests(UnityTestCase):

    scenarios = ubuntu_scenarios.get_device_simulation_scenarios()

    @unittest.skipIf(platform.model() == "Desktop",
                     "Test is broken on otto, see bug 1281634.")
    def test_networkmanager_integration(self):
        self.launch_unity()

        # invoke policykit to check permissions
        pid = subprocess.check_output(["pidof", "-s", "unity8"],
                                      universal_newlines=True)
        subprocess.check_call(
            "pkcheck --action-id "
            "org.freedesktop.NetworkManager.enable-disable-network "
            "--process " + pid,
            shell=True)
Exemplo n.º 9
0
class OptionSelectorTestCase(GalleryTestCase):

    scenarios = ubuntu_scenarios.get_device_simulation_scenarios()

    def setUp(self):
        super().setUp()
        self.open_page('optionSelectorsElement')

    def test_select_option_from_collapsed_optionselector(self):
        collapsed_option_selector = self.main_view.select_single(
            ubuntuuitoolkit.OptionSelector,
            objectName='optionselector_collapsed')

        self.assertEqual(collapsed_option_selector.get_selected_text(),
                         'Value 1')

        collapsed_option_selector.select_option(
            'UCLabel', text='Once upon a time there was a story nobody told.')
        self.assertEqual(collapsed_option_selector.get_selected_index(), 3)

    def test_select_option_from_expanded_optionselector(self):
        expanded_option_selector = self.main_view.select_single(
            ubuntuuitoolkit.OptionSelector,
            objectName='optionselector_expanded')

        self.assertEqual(expanded_option_selector.get_selected_text(),
                         'Value 1')

        expanded_option_selector.select_option(
            'UCLabel', text='Once upon a time there was a story nobody told.')
        self.assertEqual(expanded_option_selector.get_selected_index(), 3)

    def test_select_option_from_optionselector_with_custom_model(self):
        option_selector_with_custom_model = self.main_view.select_single(
            ubuntuuitoolkit.OptionSelector,
            objectName='optionselector_custommodel')
        option_selector_with_custom_model.swipe_into_view()

        self.assertEqual(
            option_selector_with_custom_model.get_selected_index(), 0)

        option_selector_with_custom_model.select_option('UCLabel',
                                                        text='Name 4')
        self.assertEqual(
            option_selector_with_custom_model.get_selected_index(), 3)
Exemplo n.º 10
0
class DisabledTextInputTestCase(GalleryTestCase):

    scenarios = ubuntu_scenarios.get_device_simulation_scenarios()

    def setUp(self):
        super().setUp()
        self.open_page('textinputsElement')

    def test_textfield_disabled(self):
        textfield_disabled = self.main_view.select_single(
            emulators.TextField, objectName='textfield_disabled')
        self.assertFalse(textfield_disabled.enabled)

        disabled_text = textfield_disabled.text
        self.assertRaises(AssertionError,
                          textfield_disabled.write,
                          'This should not be written')
        self.assertEqual(disabled_text, textfield_disabled.text)
Exemplo n.º 11
0
class ScrollBarTestCase(gallery.GalleryTestCase):

    scenarios = ubuntu_scenarios.get_device_simulation_scenarios()

    def setUp(self):
        super().setUp()
        self.open_page('navigationElement')
        self.scrollview = self.main_view.wait_select_single(
            'ScrollView', objectName="TemplateScrollView")
        self.scrollbar = self.scrollview.select_single(
            objectName="verticalScrollbar")

    def move_mouse_to_thumb(self):
        # TODO we need a helper to move the interactive thumb.
        # --elopio 2014-05-06
        thumb = self.get_mouse_thumb()
        self.pointing_device.move_to_object(thumb)

    def get_mouse_thumb(self):
        return self.scrollbar.select_single(
            objectName='interactiveScrollbarThumb')

    def test_drag_thumb_down_must_make_bottom_visible(self):
        if platform.model() != 'Desktop':
            self.skipTest(
                'The interactive thumb is activated by the move of a mouse')

        bottom_section = self.main_view.select_single(className='PageStack')
        flickable = self.main_view.select_single(
            'QQuickFlickable', objectName='TemplateFlickable')
        self.assertEqual(flickable.is_child_visible(bottom_section), False)

        self.move_mouse_to_thumb()
        mouse_thumb = self.get_mouse_thumb()
        x, y, width, height = mouse_thumb.globalRect
        start_x = stop_x = x + (width // 2)
        start_y = y + (height // 2)
        stop_y = self.main_view.y + self.main_view.height

        self.pointing_device.drag(start_x, start_y, stop_x, stop_y)

        self.assertEqual(flickable.is_child_visible(bottom_section), True)
Exemplo n.º 12
0
class OpenPagesTestCase(gallery.GalleryTestCase):

    names = [
        'navigation', 'toggles', 'buttons', 'sliders', 'textinputs',
        'optionSelectors', 'pickers', 'progressBars', 'ubuntuShapes', 'icons',
        'labels', 'listItems', 'ubuntuListView', 'dialogs', 'popovers',
        'sheets', 'animations'
    ]

    pages_scenarios = [(name,
                        dict(element_name=name + 'Element',
                             template_name=name + 'Template'))
                       for name in names]

    scenarios = testscenarios.multiply_scenarios(
        ubuntu_scenarios.get_device_simulation_scenarios(), pages_scenarios)

    def test_open_page(self):
        self.open_page(self.element_name)
        self.main_view.wait_select_single(objectName=self.template_name)
    def test_get_scenarios_on_device_must_return_no_simulation_scenarios(self):
        with mock.patch('autopilot.platform.model') as mock_model:
            mock_model.return_value = 'Not Desktop'
            scenarios = ubuntu_scenarios.get_device_simulation_scenarios()

        self.assertEqual([('Not Desktop', {})], scenarios)
Exemplo n.º 14
0
class DashBaseTestCase(AutopilotTestCase):

    scenarios = ubuntu_scenarios.get_device_simulation_scenarios()
    qml_mock_enabled = True
    environment = {}

    def setUp(self):
        super().setUp()

        if is_unity7_running():
            self.useFixture(toolkit_fixtures.HideUnity7Launcher())

        if model() != 'Desktop':
            # On the phone, we need unity to be running and unlocked.
            self.addCleanup(process_helpers.stop_job, 'unity8')
            process_helpers.restart_unity_with_testability()
            process_helpers.unlock_unity()

        self.ensure_dash_not_running()

        if self.qml_mock_enabled:
            self.environment['QML2_IMPORT_PATH'] = (
                get_qml_import_path_with_mock())

        if self.should_simulate_device():
            # This sets the grid units, so it should be called before launching
            # the app.
            self.simulate_device()

        binary_path = get_binary_path('unity8-dash')
        dash_proxy = self.launch_dash(binary_path, self.environment)

        self.dash_app = dash_helpers.DashApp(dash_proxy)
        self.dash = self.dash_app.dash
        self.wait_for_dash()

    def ensure_dash_not_running(self):
        if process_helpers.is_job_running('unity8-dash'):
            process_helpers.stop_job('unity8-dash')

    def launch_dash(self, binary_path, variables):
        launch_dash_app_fixture = fixture_setup.LaunchDashApp(
            binary_path, variables)
        self.useFixture(launch_dash_app_fixture)
        return launch_dash_app_fixture.application_proxy

    def wait_for_dash(self):
        home_scope = self.dash.get_scope_by_index(0)
        # FIXME! There is a huge timeout here for when we're doing CI on
        # VMs. See lp:1203715
        self.assertThat(home_scope.isLoaded,
                        Eventually(Equals(True), timeout=60))
        self.assertThat(home_scope.isCurrent, Eventually(Equals(True)))

    def should_simulate_device(self):
        return (hasattr(self, 'app_width') and hasattr(self, 'app_height')
                and hasattr(self, 'grid_unit_px'))

    def simulate_device(self):
        simulate_device_fixture = self.useFixture(
            toolkit_fixtures.SimulateDevice(self.app_width, self.app_height,
                                            self.grid_unit_px))
        self.environment['GRID_UNIT_PX'] = simulate_device_fixture.grid_unit_px
        self.environment['ARGS'] = '-windowgeometry {0}x{1}'\
            .format(simulate_device_fixture.app_width,
                    simulate_device_fixture.app_height)
Exemplo n.º 15
0
class NotificationsBase(UnityTestCase):
    """Base class for all notification tests that provides helper methods."""

    scenarios = ubuntu_scenarios.get_device_simulation_scenarios(
        ubuntu_scenarios.NEXUS4_DEVICE)

    def _get_icon_path(self, icon_name):
        """Given an icons file name returns the full path (either system or
        source tree.

        Consider the graphics directory as root so for example (running tests
        from installed unity8-autopilot package):
        >>> self.get_icon_path('clock.png')
        /usr/share/unity8/graphics/clock.png

        >>> self.get_icon_path('applicationIcons/facebook.png')
        /usr/share/unity8/graphics/applicationIcons/facebook.png

        """
        if os.path.abspath(__file__).startswith('/usr/'):
            return '/usr/share/unity8/graphics/' + icon_name
        else:
            return os.path.dirname(__file__) + (
                "/../../../../../tests/graphics/" + icon_name)

    def _get_notifications_list(self):
        return self.main_window.select_single(
            "Notifications",
            objectName='notificationList'
        )

    def _assert_notification(
        self,
        notification,
        summary=None,
        body=None,
        icon=True,
        secondary_icon=False,
        opacity=None
    ):
        """Assert that the expected qualities of a notification are as
        expected.

        """

        if summary is not None:
            self.assertThat(notification.summary, Eventually(Equals(summary)))

        if body is not None:
            self.assertThat(notification.body, Eventually(Equals(body)))

        if icon:
            self.assertThat(notification.iconSource, Eventually(NotEquals("")))
        else:
            self.assertThat(notification.iconSource, Eventually(Equals("")))

        if secondary_icon:
            self.assertThat(
                notification.secondaryIconSource,
                Eventually(NotEquals(""))
            )
        else:
            self.assertThat(
                notification.secondaryIconSource,
                Eventually(Equals(""))
            )

        if opacity is not None:
            self.assertThat(notification.opacity, Eventually(Equals(opacity)))
Exemplo n.º 16
0
class TestLockscreen(UnityTestCase):
    """Tests for the lock screen."""

    scenarios = ubuntu_scenarios.get_device_simulation_scenarios()

    def test_can_unlock_pin_screen(self):
        """Must be able to unlock the PIN entry lock screen."""

        self._environment['LIBLIGHTDM_MOCK_MODE'] = "single-pin"
        self.launch_unity()
        greeter = self.main_window.get_greeter()

        if not greeter.tabletMode:
            greeter.swipe()
            self._wait_for_lockscreen()
            self.main_window.enter_pin_code("1234")
        else:
            self._enter_prompt_passphrase("1234\n")
        self.assertThat(greeter.shown, Eventually(Equals(False)))

    def test_can_unlock_passphrase_screen(self):
        """Must be able to unlock the passphrase entry screen."""

        self._environment['LIBLIGHTDM_MOCK_MODE'] = "single-passphrase"
        self.launch_unity()
        greeter = self.main_window.get_greeter()

        if not greeter.tabletMode:
            greeter.swipe()
            self._wait_for_lockscreen()
            self._enter_pin_passphrase("password")
        else:
            self._enter_prompt_passphrase("password")
        self.assertThat(greeter.shown, Eventually(Equals(False)))

    def test_pin_screen_wrong_code(self):
        """Entering the wrong pin code must not dismiss the lock screen."""
        self._environment['LIBLIGHTDM_MOCK_MODE'] = "single-pin"
        self.launch_unity()
        greeter = self.main_window.get_greeter()

        if not greeter.tabletMode:
            greeter.swipe()
            self._wait_for_lockscreen()
            self.main_window.enter_pin_code("4321")
            pinentryField = self.main_window.get_pinentryField()
            self.assertThat(pinentryField.text, Eventually(Equals("")))
        else:
            self._enter_prompt_passphrase("4231\n")
            prompt = self.main_window.get_greeter().get_prompt()
            self.assertThat(prompt.text, Eventually(Equals("")))
        self.assertThat(greeter.shown, Eventually(Equals(True)))

    def test_passphrase_screen_wrong_password(self):
        """Entering the wrong password must not dismiss the lock screen."""
        self._environment['LIBLIGHTDM_MOCK_MODE'] = "single-passphrase"
        self.launch_unity()
        greeter = self.main_window.get_greeter()

        if not greeter.tabletMode:
            greeter.swipe()
            self._wait_for_lockscreen()
            self._enter_pin_passphrase("foobar")
            pinentryField = self.main_window.get_pinentryField()
            self.assertThat(pinentryField.text, Eventually(Equals("")))
        else:
            self._enter_prompt_passphrase("foobar")
            prompt = self.main_window.get_greeter().get_prompt()
            self.assertThat(prompt.text, Eventually(Equals("")))
        self.assertThat(greeter.shown, Eventually(Equals(True)))

    def _wait_for_lockscreen(self):
        """Wait for the lock screen to load, and return it."""
        pinPadLoader = self.main_window.get_pinPadLoader()
        self.assertThat(pinPadLoader.progress, Eventually(Equals(1)))
        lockscreen = self.main_window.get_lockscreen()
        self.assertThat(lockscreen.shown, Eventually(Equals(True)))
        return lockscreen

    def _enter_pin_passphrase(self, passphrase):
        """Enter the password specified in 'passphrase' into the password entry
        field of the pin lock screen.

        :param passphrase: The string you want to enter.
        :raises: TypeError if passphrase is not a string.

        """
        if not isinstance(passphrase, str):
            raise TypeError(
                "'passphrase' parameter must be a string, not %r." %
                type(passphrase))

        pin_entry_field = self.main_window.get_pinentryField()
        # pinentryField should automatically have focus
        self.keyboard.type(passphrase)
        logger.debug("Typed passphrase: %s", pin_entry_field.text)
        self.assertEqual(pin_entry_field.text, passphrase)
        self.keyboard.type("\n")

    def _enter_prompt_passphrase(self, passphrase):
        """Enter the password specified in 'passphrase' into the password entry
        field of the main user list's prompt.

        :param passphrase: The string you want to enter.
        :raises: TypeError if passphrase is not a string.

        """
        if not isinstance(passphrase, str):
            raise TypeError(
                "'passphrase' parameter must be a string, not %r." %
                type(passphrase))

        prompt = self.main_window.get_greeter().get_prompt()
        prompt.write(passphrase)
        logger.debug("Typed passphrase: %s", prompt.text)
        self.keyboard.type("\n")