Пример #1
0
    def setUp(self):
        super(UnityTestCase, self).setUp()
        try:
            ensure_unity_is_running()
        except RuntimeError:
            log.error("Unity doesn't appear to be running, exiting.")
            sys.exit(1)

        self._unity = get_proxy_object_for_existing_process(
            connection_name=Unity.DBUS_SERVICE,
            object_path=Unity.DBUS_OBJECT,
            emulator_base=Unity
        )

        self._setUpUnityLogging()
        self._initial_workspace_num = self.workspace.current_workspace
        self.addCleanup(self.check_test_behavior)
        #
        # Setting this here since the show desktop feature seems to be a bit
        # ropey. Once it's been proven to work reliably we can remove this line:
        self.set_unity_log_level("unity.wm.compiz", "DEBUG")

        # For the length of the test, disable screen locking
        self._desktop_settings = Gio.Settings.new("org.gnome.desktop.lockdown")
        lock_state = self._desktop_settings.get_boolean("disable-lock-screen")
        self._desktop_settings.set_boolean("disable-lock-screen", True)
        self.addCleanup(self._desktop_settings.set_boolean, "disable-lock-screen", lock_state)
    def test_launch_fake_application_from_url_dispatcher(self):
        if platform.model() == 'Desktop':
            self.skipTest('Not yet working on desktop')

        path = os.path.abspath(__file__)
        dir_path = os.path.dirname(path)
        qml_file_path = os.path.join(
            dir_path, 'test_fixture_setup.LaunchFakeApplicationTestCase.qml')
        with open(qml_file_path) as qml_file:
            qml_file_contents = qml_file.read()

        fake_application = fixture_setup.FakeApplication(
            qml_file_contents=qml_file_contents,
            url_dispatcher_protocols=['testprotocol'])
        self.useFixture(fake_application)

        self.useFixture(fixture_setup.InitctlEnvironmentVariable(
            QT_LOAD_TESTABILITY=1))

        self.addCleanup(
            subprocess.check_output,
            ['ubuntu-app-stop', fake_application.application_name])

        subprocess.check_output(
            ['url-dispatcher', 'testprotocol://test'])

        pid = int(subprocess.check_output(
            ['ubuntu-app-pid', fake_application.application_name]).strip())

        application = introspection.get_proxy_object_for_existing_process(
            pid=pid)

        # We can select a component from the application.
        application.select_single('Label', objectName='testLabel')
Пример #3
0
    def ensure_app_has_quit(self):
        """Terminate as gracefully as possible the application and ensure
        that it has fully quit before returning"""

        if model() == "Desktop":
            # On desktop to cleanly quit an app we just do the
            # equivalent of clicking on the close button in the window.
            self.keyboard.press_and_release("Alt+F4")
        else:
            # On unity8 at the moment we have no clean way to close the app.
            # So we ask the shell first to show the home, unfocusing our app,
            # which will save its state. Then we simply send it a SIGTERM to
            # force it to quit.
            # See bug https://bugs.launchpad.net/unity8/+bug/1261720 for more
            # details.
            from unity8 import process_helpers
            pid = process_helpers._get_unity_pid()
            unity8 = get_proxy_object_for_existing_process(pid=pid)
            shell = unity8.select_single("Shell")
            shell.slots.showHome()
            self.assertThat(shell.focusedApplicationId,
                            Eventually(NotEquals("gallery-app")))
            self.app.process.send_signal(signal.SIGTERM)

        # Either way, we wait for the underlying process to be fully finished.
        self.app.process.wait()
        self.assertIsNotNone(self.app.process.returncode)
Пример #4
0
    def ensure_app_has_quit(self):
        """Terminate as gracefully as possible the application and ensure
        that it has fully quit before returning"""

        if model() == "Desktop":
            # On desktop to cleanly quit an app we just do the
            # equivalent of clicking on the close button in the window.
            self.keyboard.press_and_release("Alt+F4")
        else:
            # On unity8 at the moment we have no clean way to close the app.
            # So we ask the shell first to show the home, unfocusing our app,
            # which will save its state. Then we simply send it a SIGTERM to
            # force it to quit.
            # See bug https://bugs.launchpad.net/unity8/+bug/1261720 for more
            # details.
            from unity8 import process_helpers
            pid = process_helpers._get_unity_pid()
            unity8 = get_proxy_object_for_existing_process(pid=pid)
            shell = unity8.select_single("Shell")
            shell.slots.showHome()
            self.assertThat(shell.focusedApplicationId,
                            Eventually(NotEquals("gallery-app")))
            self.app.process.send_signal(signal.SIGTERM)

        # Either way, we wait for the underlying process to be fully finished.
        self.app.process.wait()
        self.assertIsNotNone(self.app.process.returncode)
Пример #5
0
 def get_dash(self):
     pid = process_helpers.get_job_pid('unity8-dash')
     dash_proxy = introspection.get_proxy_object_for_existing_process(
         pid=pid,
         emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
     dash_app = dash_helpers.DashApp(dash_proxy)
     return dash_app.dash
Пример #6
0
    def setUp(self):
        super(UnityTestCase, self).setUp()
        try:
            ensure_unity_is_running()
        except RuntimeError:
            log.error("Unity doesn't appear to be running, exiting.")
            sys.exit(1)

        self._unity = get_proxy_object_for_existing_process(
            connection_name=Unity.DBUS_SERVICE,
            object_path=Unity.DBUS_OBJECT,
            emulator_base=Unity)

        self._setUpUnityLogging()
        self._initial_workspace_num = self.workspace.current_workspace
        self.addCleanup(self.check_test_behavior)
        #
        # Setting this here since the show desktop feature seems to be a bit
        # ropey. Once it's been proven to work reliably we can remove this line:
        self.set_unity_log_level("unity.wm.compiz", "DEBUG")

        # For the length of the test, disable screen locking
        self._desktop_settings = Gio.Settings.new("org.gnome.desktop.lockdown")
        lock_state = self._desktop_settings.get_boolean("disable-lock-screen")
        self._desktop_settings.set_boolean("disable-lock-screen", True)
        self.addCleanup(self._desktop_settings.set_boolean,
                        "disable-lock-screen", lock_state)
Пример #7
0
 def get_dash(self):
     pid = process_helpers.get_job_pid('unity8-dash')
     dash_proxy = introspection.get_proxy_object_for_existing_process(
         pid=pid,
         emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase
     )
     dash_app = dash_helpers.DashApp(dash_proxy)
     return dash_app.dash
Пример #8
0
    def test_creating_app_for_non_running_app_fails(self):
        """Attempting to create an application proxy object for a process
        (using a PID) that isn't running must raise an exception.

        """
        pid = _get_unused_pid()

        self.assertThat(
            lambda: get_proxy_object_for_existing_process(pid=pid),
            raises(ProcessSearchError("PID %d could not be found" % pid)))
Пример #9
0
    def launch_application(self):
        '''
        Hmm... launch ubiquity


        :returns: The application proxy object.
        '''
        my_process = int(os.environ['UBIQUITY_PID'])
        my_dbus = str(os.environ['DBUS_SESSION_BUS_ADDRESS'])
        return get_proxy_object_for_existing_process(
            pid=my_process, dbus_bus=my_dbus)
Пример #10
0
def _assertUnityReady():
        unity_pid = process_helpers._get_unity_pid()
        unity = get_proxy_object_for_existing_process(
            pid=unity_pid,
            emulator_base=UnityEmulatorBase,
        )
        dash = unity.wait_select_single(Dash)
        home_scope = dash.get_scope('home')

        home_scope.isLoaded.wait_for(True)
        home_scope.isCurrent.wait_for(True)
Пример #11
0
    def launch_application(self):
        """
        Hmm... launch ubiquity


        :returns: The application proxy object.
        """
        my_process = int(os.environ["UBIQUITY_PID"])
        my_dbus = str(os.environ["DBUS_SESSION_BUS_ADDRESS"])
        return get_proxy_object_for_existing_process(
            pid=my_process, dbus_bus=my_dbus, emulator_base=AutopilotGtkEmulatorBase
        )
Пример #12
0
    def launch_application(self):
        '''
        Hmm... launch ubiquity


        :returns: The application proxy object.
        '''
        my_process = int(os.environ['UBIQUITY_PID'])
        my_dbus = str(os.environ['DBUS_SESSION_BUS_ADDRESS'])
        return get_proxy_object_for_existing_process(
            pid=my_process, dbus_bus=my_dbus,
            emulator_base=AutopilotGtkEmulatorBase)
Пример #13
0
def ensure_unity_is_running(timeout=300):
    """Poll the unity debug interface, and return when it's ready for use.

    The default timeout is 300 seconds (5 minutes) to account for the case where
    Unity has crashed and is taking a while to get restarted (on a slow VM for
    example).

    If, after the timeout period, unity is still not up, this function raises a
    RuntimeError exception.

    """
    sleep_period=10
    for i in range(0, timeout, sleep_period):
        try:
            get_proxy_object_for_existing_process(
                connection_name=UnityIntrospectionObject.DBUS_SERVICE,
                object_path=UnityIntrospectionObject.DBUS_OBJECT
            )
            return True
        except ProcessSearchError:
            sleep(sleep_period)
    raise RuntimeError("Unity debug interface is down after %d seconds of polling." % (timeout))
Пример #14
0
    def launch_application(self):
        binary_arg = 'BINARY={}'.format(self.binary_path)
        testability_arg = 'QT_LOAD_TESTABILITY={}'.format(1)
        env_args = [
            '{}={}'.format(key, value) for key, value in self.variables.items()
        ]
        all_args = [binary_arg, testability_arg] + env_args

        pid = process_helpers.start_job('unity8-dash', *all_args)
        return introspection.get_proxy_object_for_existing_process(
            pid=pid,
            emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase
        )
Пример #15
0
def ensure_unity_is_running(timeout=300):
    """Poll the unity debug interface, and return when it's ready for use.

    The default timeout is 300 seconds (5 minutes) to account for the case where
    Unity has crashed and is taking a while to get restarted (on a slow VM for
    example).

    If, after the timeout period, unity is still not up, this function raises a
    RuntimeError exception.

    """
    sleep_period = 10
    for i in range(0, timeout, sleep_period):
        try:
            get_proxy_object_for_existing_process(
                connection_name=UnityIntrospectionObject.DBUS_SERVICE,
                object_path=UnityIntrospectionObject.DBUS_OBJECT)
            return True
        except ProcessSearchError:
            sleep(sleep_period)
    raise RuntimeError(
        "Unity debug interface is down after %d seconds of polling." %
        (timeout))
Пример #16
0
    def maliit(self):
        # We cache __mallit_server as a class attribute because
        # get_proxy_object_for_existing_process clears backends for proxy
        # objects, this means that if this is called twice within a test the
        # first keyboard object created has now lost all its _Backends.
        if Keyboard.__maliit is None:
            try:
                Keyboard.__maliit = get_proxy_object_for_existing_process(
                    connection_name='org.maliit.server',
                    emulator_base=toolkit.LomiriUIToolkitCustomProxyObjectBase)

                if Keyboard.__maliit is None:
                    raise RuntimeError("Maliit Server could not be found.")
            except ProcessSearchError as e:
                e.args += (
                    "Unable to find maliit-server dbus object. Has it been "
                    "started with introspection enabled?", )
                raise
        return Keyboard.__maliit
Пример #17
0
    def maliit(self):
        # We cache __mallit_server as a class attribute because
        # get_proxy_object_for_existing_process clears backends for proxy
        # objects, this means that if this is called twice within a test the
        # first keyboard object created has now lost all its _Backends.
        if Keyboard.__maliit is None:
            try:
                Keyboard.__maliit = get_proxy_object_for_existing_process(
                    connection_name='org.maliit.server',
                    emulator_base=UbuntuKeyboardEmulatorBase
                )

                if Keyboard.__maliit is None:
                    raise RuntimeError("Maliit Server could not be found.")
            except ProcessSearchError as e:
                e.args += (
                    "Unable to find maliit-server dbus object. Has it been "
                    "started with introspection enabled?",
                )
                raise
        return Keyboard.__maliit
Пример #18
0
 def _set_proxy(self):
     proxy_base = ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase
     super()._set_proxy(
         get_proxy_object_for_existing_process(
             pid=self.process.pid,
             emulator_base=proxy_base))
Пример #19
0
def _get_unity_proxy_object(pid):
    return get_proxy_object_for_existing_process(
        pid=pid,
        emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase
    )
Пример #20
0
def _get_unity_proxy_object(pid):
    return get_proxy_object_for_existing_process(
        pid=pid,
        emulator_base=ubuntuuitoolkit.UbuntuUIToolkitCustomProxyObjectBase)
Пример #21
0
    def launch(self,
               application,
               arguments=[],
               app_type=None,
               launch_dir=None,
               capture_output=True):
        """Launch an application and return a proxy object.

        Use this method to launch an application and start testing it. The
        arguments passed in ``arguments`` are used as arguments to the
        application to launch. Additional keyword arguments are used to control
        the manner in which the application is launched.

        This fixture is designed to be flexible enough to launch all supported
        types of applications. Autopilot can automatically determine how to
        enable introspection support for dynamically linked binary
        applications. For example, to launch a binary Gtk application, a test
        might start with::

            from autopilot.application import NormalApplicationLauncher
            launcher = NormalApplicationLauncher()
            launcher.setUp()
            app_proxy = launcher.launch('gedit')

        For use within a testcase, use useFixture:

            from autopilot.application import NormalApplicationLauncher
            launcher = self.useFixture(NormalApplicationLauncher())
            app_proxy = launcher.launch('gedit')

        Applications can be given command line arguments by supplying an
        ``arguments`` argument to this method. For example, if we want to
        launch ``gedit`` with a certain document loaded, we might do this::

            app_proxy = launcher.launch(
                'gedit', arguments=['/tmp/test-document.txt'])

        ... a Qt5 Qml application is launched in a similar fashion::

            app_proxy = launcher.launch(
                'qmlscene', arguments=['my_scene.qml'])

        If you wish to launch an application that is not a dynamically linked
        binary, you must specify the application type. For example, a Qt4
        python application might be launched like this::

            app_proxy = launcher.launch(
                'my_qt_app.py', app_type='qt')

        Similarly, a python/Gtk application is launched like so::

            app_proxy = launcher.launch(
                'my_gtk_app.py', app_type='gtk')

        :param application: The application to launch. The application can be
            specified as:

             * A full, absolute path to an executable file.
               (``/usr/bin/gedit``)
             * A relative path to an executable file.
               (``./build/my_app``)
             * An app name, which will be searched for in $PATH (``my_app``)

        :keyword arguments: If set, the list of arguments is passed to the
            launched app.

        :keyword app_type: If set, provides a hint to autopilot as to which
            kind of introspection to enable. This is needed when the
            application you wish to launch is *not* a dynamically linked
            binary. Valid values are 'gtk' or 'qt'. These strings are case
            insensitive.

        :keyword launch_dir: If set to a directory that exists the process
            will be launched from that directory.

        :keyword capture_output: If set to True (the default), the process
            output will be captured and attached to the test as test detail.

        :return: A proxy object that represents the application. Introspection
         data is retrievable via this object.

        """
        _logger.info(
            "Attempting to launch application '%s' with arguments '%s' as a "
            "normal process", application, ' '.join(arguments))
        app_path = _get_application_path(application)
        app_path, arguments = self._setup_environment(app_path, app_type,
                                                      arguments)
        process = self._launch_application_process(app_path, capture_output,
                                                   launch_dir, arguments)
        proxy_object = get_proxy_object_for_existing_process(
            dbus_bus=self.dbus_bus,
            emulator_base=self.proxy_base,
            process=process,
            pid=process.pid)
        proxy_object.set_process(process)
        return proxy_object
Пример #22
0
 def launch_application(self):
     my_process = int(os.environ['UBIQUITY_PID'])
     my_dbus = str(os.environ['DBUS_SESSION_BUS_ADDRESS'])
     return get_proxy_object_for_existing_process(
         pid=my_process, dbus_bus=my_dbus)
Пример #23
0
 def _get_proxy_object(self, pid):
     return get_proxy_object_for_existing_process(
         dbus_bus=self.dbus_bus, emulator_base=self.proxy_base, pid=pid)