[Merge] lp:~vrruiz/gallery-app/autopilot-app-class into lp:gallery-app

Leo Arias leo.arias at canonical.com
Fri Jun 27 23:09:43 UTC 2014


Review: Needs Fixing

Victor, I'm sorry it took so long to make this review. You will likely have to merge with trunk now.
I'll try harder to make the reviews the same day. But next time I won't make soon a review you request please keep pinging me. I'll owe you a beer for every day you wait :)

For the gallery and apps developers: this change seeks to make it easier for us to test multiple applications at the same time. On its own, it just seems like a huge branch not really useful, and now you will have to call something like self.app.main_view instead of just self.main_view. But it makes a lot of sense when you see a test like this:

address_book = AddressBook.launch()
add_contact_page = address_book.main_view.go_to_add_contact()
add_contact_page.click_contact_image()
gallery_app = GalleryApp()
gallery_app.main_view.pick_image(...)
add_contact_page.main_view.fill_form(...)
add_contact_page.save()

For that we need to move the app helpers out of the test cases because there's no nice way to make a test case that inherits from both the base test cases in address book and gallery.

Diff comments:

> === modified file 'tests/autopilot/gallery_app/__init__.py'
> --- tests/autopilot/gallery_app/__init__.py	2013-03-19 13:04:59 +0000
> +++ tests/autopilot/gallery_app/__init__.py	2014-06-10 15:49:31 +0000
> @@ -6,3 +6,422 @@
>  # by the Free Software Foundation.
>  
>  """Autopilot tests and emulators for gallery - top level package."""
> +
> +import os
> +import logging
> +import shutil
> +import signal
> +
> +from time import sleep
> +
> +from testtools.matchers import Equals, NotEquals, GreaterThan, Is
> +from autopilot.matchers import Eventually
> +from autopilot.platform import model
> +from autopilot.introspection import get_proxy_object_for_existing_process
> +from pkg_resources import resource_filename
> +
> +from ubuntuuitoolkit import emulators as toolkit_emulators
> +

This empty line is not needed.

> +from gallery_app.emulators import main_screen
> +from gallery_app.emulators.album_editor import AlbumEditor
> +from gallery_app.emulators.album_view import AlbumView
> +from gallery_app.emulators.albums_view import AlbumsView
> +from gallery_app.emulators.events_view import EventsView
> +from gallery_app.emulators.gallery_utils import GalleryUtils
> +from gallery_app.emulators.media_selector import MediaSelector
> +from gallery_app.emulators.media_viewer import MediaViewer
> +from gallery_app.emulators.photo_viewer import PhotoViewer
> +from gallery_app.emulators.photos_view import PhotosView
> +from gallery_app.emulators.picker_screen import PickerScreen
> +
> +logger = logging.getLogger(__name__)
> +
> +
> +class EnvironmentTypes:
> +    installed = "installed"

Please prefer single quotes instead of double quotes, to be consistent with the rest of our python projects.
Also, wouldn't these be better as constants for the module or the GalleryApp class? It seems that you want to have an enum here, but IMO you are doing it in a weird way. There are some nicer ways to do enums if that's what you want: http://stackoverflow.com/questions/36932/how-can-i-represent-an-enum-in-python
I would just go with the constants.

> +    local = "local"
> +    click = "click"
> +
> +
> +class GalleryApp():
> +    """A class to drive the UI of the gallery-app."""

Something I've just found out this week. From pep257:
"Insert a blank line before and after all docstrings (one-line or multi-line) that document a class"

> +
> +    sample_file_source = "/sample01.jpg"
> +    local_location = "../src/gallery-app"
> +    tap_press_time = 1
> +
> +    _db = '~/.local/share/com.ubuntu.gallery/gallery-app/' \
> +          'database/gallery.sqlite'
> +    _thumbs = '~/.cache/com.ubuntu.gallery/gallery-app/thumbnails'
> +
> +    _default_sample_destination_dir = "/tmp/gallery-ap_sd"
> +    sample_destination_dir = ""
> +
> +    ARGS = []

This ARGS is not a constant, because you change it's value on the init, so it shouldn't be all capital letters. Also, why do you need it as a class attribute instead of an instance attribute? I think self.args = args on the init would be enough.

> +    app = None
> +
> +    def __init__(self, test_case, args=[]):
> +        """Constructor
> +
> +        :param test_case: An AutopilotTestCase object. This is required
> +        to be able to launch the application.
> +        
> +        """
> +        # Start app
> +        self.ARGS = args
> +        self.test_case = test_case
> +        env_type = self._get_environment_launch_type()
> +        self.configure_sample_files(env_type)
> +        self.launch_gallery_app(env_type)
> +
> +    def __del__(self):
> +        """Destructor"""
> +        shutil.rmtree(self.sample_destination_dir)

I'm not sure about having clean ups on the App classes. It feels weird, as I tend to assume that clean ups happen only on the test case tear downs.
This makes me think that it feels wrong to have sample file source, _db, _thumbs, sample_destination_dir in this class. Wouldn't it be better to put all that on a base test class? Ideally, as a Fixture. I think the app class should take care only about opening, introspecting and simulating user actions on the app. Setting the environment for that app should be a task for a test case.

What do you think?

> +
> +    @property
> +    def gallery_utils(self):
> +        return GalleryUtils(self.app)
> +
> +    @property
> +    def main_view(self):
> +        return self.app.select_single(main_screen.MainScreen)
> +
> +    @property
> +    def album_editor(self):
> +        return self.app.select_single(AlbumEditor)
> +
> +    @property
> +    def album_view(self):
> +        return AlbumView(self.app)
> +
> +    @property
> +    def albums_view(self):
> +        return AlbumsView(self.app)
> +
> +    @property
> +    def events_view(self):
> +        return EventsView(self.app)
> +
> +    @property
> +    def media_selector(self):
> +        return MediaSelector(self.app)
> +
> +    @property
> +    def media_view(self):
> +        return self.app.select_single(MediaViewer)
> +
> +    @property
> +    def photo_viewer(self):
> +        return PhotoViewer(self.app)
> +
> +    @property
> +    def photos_view(self):
> +        return PhotosView(self.app)
> +
> +    @property
> +    def picker_view(self):
> +        return self.app.select_single(PickerScreen)
> +
> +    def _get_environment_launch_type(self):
> +        """Returns the type of the environment in which to setup and launch
> +        gallery-app.
> +
> +        """
> +        # Lets assume we are installed system wide if this file is somewhere
> +        # in /usr
> +        if os.path.realpath(__file__).startswith("/usr/"):
> +            return EnvironmentTypes.installed
> +        if model() == 'Desktop':
> +            return EnvironmentTypes.installed
> +        else:
> +            if os.path.exists(self.local_location):
> +                return EnvironmentTypes.local
> +            else:
> +                return EnvironmentTypes.click
> +
> +    def _get_sample_destination_dir(self, env_type):
> +        if env_type == EnvironmentTypes.click:
> +            pic_dir = os.path.expanduser("~/Pictures")
> +            pic_bak_dir = pic_dir + '.apbak'
> +            # Only save and restore if it previously existed
> +            if os.path.exists(pic_dir):
> +                shutil.move(pic_dir, pic_bak_dir)
> +                self.addCleanup(
> +                    logger.debug, "Restoring backed up pics to %s" % pic_dir)
> +                self.addCleanup(shutil.move, pic_bak_dir, pic_dir)
> +            return pic_dir
> +        else:
> +            return self._default_sample_destination_dir
> +
> +    def configure_db(self):
> +        db = os.path.expanduser(self._db)
> +        db_bak = db + '.apbak'
> +        # Only save and restore if it previously existed
> +        if os.path.exists(db):
> +            shutil.move(db, db_bak)
> +            self.addCleanup(shutil.move, db_bak, db)
> +        if not os.path.exists(os.path.dirname(db)):
> +            os.makedirs(os.path.dirname(db))
> +        mock_db = os.path.join(self.sample_destination_dir, '.database',
> +                               'gallery_confined.sqlite')
> +        shutil.move(mock_db, db)
> +
> +    def configure_thumbnails(self):
> +        thumbs = os.path.expanduser(self._thumbs)
> +        thumbs_bak = thumbs + '.apbak'
> +        # Only save and restore if it previously existed
> +        if os.path.exists(thumbs):
> +            shutil.move(thumbs, thumbs_bak)
> +            self.addCleanup(shutil.move, thumbs_bak, thumbs)
> +        if not os.path.exists(os.path.dirname(thumbs)):
> +            os.makedirs(os.path.dirname(thumbs))
> +        mock_thumbs = os.path.join(self.sample_destination_dir, '.thumbnails')
> +        shutil.move(mock_thumbs, thumbs)
> +
> +    def configure_sample_files(self, env_type):
> +        self.sample_dir = resource_filename('gallery_app', 'data')
> +        self.sample_destination_dir = \
> +            self._get_sample_destination_dir(env_type)
> +        if (os.path.exists(self.sample_destination_dir)):
> +            shutil.rmtree(self.sample_destination_dir)
> +        ## FIXME self.assertFalse(os.path.exists(self.sample_destination_dir))
> +
> +        self.sample_file = os.path.join(
> +            self.sample_destination_dir,
> +            "sample04.jpg"
> +        )
> +
> +        default_data_dir = os.path.join(
> +            self.sample_dir,
> +            "default")
> +        shutil.copytree(default_data_dir, self.sample_destination_dir)
> +        ## FIXME self.assertTrue(os.path.isfile(self.sample_file))
> +
> +        self.sample_file_source = \
> +            default_data_dir + self.sample_file_source
> +
> +        if env_type == EnvironmentTypes.click:
> +            self.configure_db()
> +            self.configure_thumbnails()
> +
> +    def do_reset_config(self):
> +        config = os.path.expanduser(
> +            os.path.join("~", ".config", "gallery-app.conf"))
> +        if os.path.exists(config):
> +            os.remove(config)
> +
> +    @property
> +    def pointing_device(self):
> +        """Return pointing device"""
> +        return toolkit_emulators.get_pointing_device()
> +
> +    def launch_gallery_app(self, env_type):
> +        """Launch"""
> +        if env_type == EnvironmentTypes.installed:
> +            self.launch_test_installed()
> +        elif env_type == EnvironmentTypes.local:
> +            self.launch_test_local()
> +        elif env_type == EnvironmentTypes.click:
> +            self.launch_test_click()
> +        else:
> +            raise ValueError("Unknown environment type: %s", env_type)
> +
> +    def launch_test_local(self):
> +        logger.debug("Launching local gallery-app binary.")
> +        self.ARGS.append(self.sample_destination_dir)
> +        self.app = self.test_case.launch_test_application(
> +            self.local_location,
> +            *self.ARGS,
> +            emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
> +
> +    def launch_test_installed(self):
> +        if model() == 'Desktop':
> +            logger.debug(
> +                "Launching installed gallery-app binary for desktop."
> +            )
> +            self.ARGS.append(self.sample_destination_dir)
> +            self.app = self.test_case.launch_test_application(
> +                "gallery-app",
> +                *self.ARGS,
> +                emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
> +        else:
> +            logger.debug(
> +                "Launching installed gallery-app binary for device."
> +            )
> +            self.ARGS.append("--desktop_file_hint="
> +                             "/usr/share/applications/gallery-app.desktop")
> +            self.ARGS.append(self.sample_destination_dir)
> +            self.app = self.test_case.launch_test_application(
> +                "gallery-app",
> +                *self.ARGS,
> +                app_type='qt',
> +                emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
> +
> +    def launch_test_click(self):
> +        """
> +        Since this test runs under confinement, the only location photos
> +        are searchable in is ~/Pictures.
> +        """
> +        logger.debug("Launching gallery-app via click package.")
> +        self.app = self.test_case.launch_click_package(
> +            package_id="com.ubuntu.gallery",
> +            app_uris=' '.join(self.ARGS),
> +            emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
> +
> +    def ui_update(self):
> +        """ Gives the program the time to update the UI"""
> +        sleep(0.1)
> +
> +    def click_item(self, item, delay=0.1):
> +        """Does a mouse click on the passed item, and moved the mouse there
> +           before"""
> +        # In jenkins test may fail because we don't wait before clicking the
> +        # target so we add a little delay before click.
> +        if model() == 'Desktop' and delay <= 0.25:
> +            delay = 0.25
> +
> +        self.pointing_device.move_to_object(item)
> +        sleep(delay)
> +        self.pointing_device.click()
> +
> +    def tap_item(self, item):
> +        """Does a long mouse press on the passed item, and moved the mouse
> +           there before"""
> +        self.pointing_device.move_to_object(item)
> +        self.pointing_device.press()
> +        sleep(1)
> +        self.pointing_device.release()
> +
> +    def switch_to_albums_tab(self):
> +        self.main_view.switch_to_tab("albumsTab")
> +
> +        albums_loader = self.gallery_utils.get_albums_viewer_loader()
> +        self.test_case.assertThat(albums_loader.progress, Eventually(Equals(1)))
> +
> +        # The next check assumes that at least one album is available
> +        # Check if the albums are availabe - they need some time to load.
> +        self.test_case.assertThat(lambda: len(self.gallery_utils.get_all_albums()),
> +                        Eventually(GreaterThan(0)))
> +        self.ensure_tabs_dont_move()
> +
> +    def ensure_tabs_dont_move(self):
> +        # FIXME find a (functional) way to test if the tabs still move
> +        sleep(1)
> +
> +    def open_album_at(self, position):
> +        album = self.album_view.get_album_at(position)
> +        # workaround lp:1247698
> +        self.main_view.close_toolbar()
> +        self.click_item(album)
> +        self.ensure_view_is_fully_open()
> +
> +    def open_first_album(self):
> +        self.open_album_at(-1)
> +
> +    def get_delete_dialog(self):
> +        """Raises StateNotFoundError if get_delete_dialog fails."""
> +        delete_dialog = self.gallery_utils.get_delete_dialog()
> +        return delete_dialog
> +
> +    def edit_first_album(self):
> +        """Edit first album."""
> +        first_album = self.gallery_utils.get_first_album()
> +        # workaround lp:1247698
> +        self.main_view.close_toolbar()
> +        self.tap_item(first_album)
> +        edit_button = self.gallery_utils.get_edit_album_button()
> +        self.click_item(edit_button)
> +
> +    def ensure_view_is_fully_open(self):
> +        animated_view = self.album_view.get_animated_album_view()
> +        self.test_case.assertThat(animated_view.isOpen, Eventually(Equals(True)))
> +        self.test_case.assertThat(animated_view.animationRunning,
> +                        Eventually(Equals(False)))
> +        view = self.album_view.get_album_view()
> +        self.test_case.assertThat(view.visible, Eventually(Equals(True)))
> +
> +    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)
> +            shell = unity8.select_single("Shell")
> +            shell.slots.showHome()
> +            self.test_case.assertThat(shell.currentFocusedAppId,
> +                            Eventually(NotEquals("gallery-app"))) # FIXME
> +            self.app.process.send_signal(signal.SIGTERM)
> +
> +        # Either way, we wait for the underlying process to be fully finished.
> +        self.app.process.wait()
> +        self.test_case.assertIsNotNone(self.app.process.returncode) # FIXME
> +
> +    def get_events_view(self):
> +        return self.app.wait_select_single("EventsOverview",
> +                                           objectName="organicEventView")
> +
> +    def enable_select_mode(self):
> +        self.main_view.open_toolbar().click_button("selectButton")
> +
> +    def delete_one_picture(self):
> +        self.main_view.open_toolbar().click_button("deleteButton")
> +        self.get_delete_dialog()
> +        delete_item = self.photo_viewer.get_delete_popover_delete_item()
> +        self.click_item(delete_item)
> +        self.ensure_closed_delete_dialog()
> +
> +    def open_first_photo(self):
> +        self.test_case.assertThat(
> +            lambda: self.events_view.number_of_photos_in_events(),
> +            Eventually(GreaterThan(0))
> +        )
> +
> +        # workaround lp:1247698
> +        # toolbar needs to be gone to click on an image.
> +        self.main_view.close_toolbar()
> +
> +        self.events_view.click_photo(self.sample_file)
> +
> +        photo_viewer_loader = self.photo_viewer.get_main_photo_viewer_loader()
> +        self.test_case.assertThat(photo_viewer_loader.loaded, Eventually(Equals(True)))
> +        sleep(1)
> +        photo_viewer = self.photo_viewer.get_main_photo_viewer()
> +        self.test_case.assertThat(photo_viewer.visible, Eventually(Equals(True)))
> +
> +    def ensure_closed_delete_dialog(self):
> +        self.test_case.assertThat(self.photo_viewer.delete_dialog_shown,
> +                        Eventually(Is(False)))
> +
> +    def click_edit_button(self):
> +        self.main_view.open_toolbar().click_button("editButton")
> +        edit_dialog = self.photo_viewer.get_photo_edit_dialog()
> +        self.test_case.assertThat(edit_dialog.visible, (Eventually(Equals(True))))
> +        self.test_case.assertThat(edit_dialog.opacity, (Eventually(Equals(1))))
> +
> +    def switch_to_photos_tab(self):
> +        self.main_view.switch_to_tab("photosTab")
> +        self.ensure_tabs_dont_move()
> +
> +    def click_first_photo(self):
> +        photo = self.photos_view.get_first_photo_in_photos_view()
> +        self.click_item(photo)
> +
> +    def select_first_event_media(self):
> +        first_media = self.picker_view.first_media_in_events_view()
> +        self.click_item(first_media)
> +
> +    def select_first_grid_media(self):
> +        first_media = self.picker_view.first_media_in_events_view()
> +        self.click_item(first_media)
> 
> === modified file 'tests/autopilot/gallery_app/tests/__init__.py'
> --- tests/autopilot/gallery_app/tests/__init__.py	2014-05-20 15:19:35 +0000
> +++ tests/autopilot/gallery_app/tests/__init__.py	2014-06-10 15:49:31 +0000
> @@ -7,308 +7,30 @@
>  
>  """gallery autopilot tests."""
>  
> -import os
> -import logging
> -import shutil
> -import signal
> +from time import sleep
>  
> -from testtools.matchers import Equals, NotEquals, GreaterThan
> +from testtools.matchers import Equals
>  from autopilot.matchers import Eventually
> -from autopilot.platform import model
>  from autopilot.testcase import AutopilotTestCase
> -from autopilot.introspection import get_proxy_object_for_existing_process
> -from pkg_resources import resource_filename
> -
> -from ubuntuuitoolkit import emulators as toolkit_emulators
> -from gallery_app.emulators import main_screen
> -from gallery_app.emulators.gallery_utils import GalleryUtils
> -
> -from time import sleep
> -
> -logger = logging.getLogger(__name__)
> -
> -
> -class EnvironmentTypes:
> -    installed = "installed"
> -    local = "local"
> -    click = "click"
> +
> +from gallery_app import GalleryApp
>  
>  
>  class GalleryTestCase(AutopilotTestCase):
> -
>      """A common test case class that provides several useful methods for
>         gallery tests."""
>  
> -    sample_file_source = "/sample01.jpg"
> -    tap_press_time = 1
> -    local_location = "../../src/gallery-app"
> -
> -    _db = '~/.local/share/com.ubuntu.gallery/gallery-app/' \
> -          'database/gallery.sqlite'
> -    _thumbs = '~/.cache/com.ubuntu.gallery/gallery-app/thumbnails'
> -
> -    _default_sample_destination_dir = "/tmp/gallery-ap_sd"
> -
>      ARGS = []
>  
> -    @property
> -    def gallery_utils(self):
> -        return GalleryUtils(self.app)
> -
> -    @property
> -    def main_view(self):
> -        return self.app.select_single(main_screen.MainScreen)
> -
> -    def _get_environment_launch_type(self):
> -        """Returns the type of the environment in which to setup and launch
> -        gallery-app.
> -
> -        """
> -        # Lets assume we are installed system wide if this file is somewhere
> -        # in /usr
> -        if os.path.realpath(__file__).startswith("/usr/"):
> -            return EnvironmentTypes.installed
> -        if model() == 'Desktop':
> -            return EnvironmentTypes.installed
> -        else:
> -            if os.path.exists(self.local_location):
> -                return EnvironmentTypes.local
> -            else:
> -                return EnvironmentTypes.click
> -
> -    def _get_sample_destination_dir(self, env_type):
> -        if env_type == EnvironmentTypes.click:
> -            pic_dir = os.path.expanduser("~/Pictures")
> -            pic_bak_dir = pic_dir + '.apbak'
> -            # Only save and restore if it previously existed
> -            if os.path.exists(pic_dir):
> -                shutil.move(pic_dir, pic_bak_dir)
> -                self.addCleanup(
> -                    logger.debug, "Restoring backed up pics to %s" % pic_dir)
> -                self.addCleanup(shutil.move, pic_bak_dir, pic_dir)
> -            return pic_dir
> -        else:
> -            return self._default_sample_destination_dir
> -
> -    def configure_db(self):
> -        db = os.path.expanduser(self._db)
> -        db_bak = db + '.apbak'
> -        # Only save and restore if it previously existed
> -        if os.path.exists(db):
> -            shutil.move(db, db_bak)
> -            self.addCleanup(shutil.move, db_bak, db)
> -        if not os.path.exists(os.path.dirname(db)):
> -            os.makedirs(os.path.dirname(db))
> -        mock_db = os.path.join(self.sample_destination_dir, '.database',
> -                               'gallery_confined.sqlite')
> -        shutil.move(mock_db, db)
> -
> -    def configure_thumbnails(self):
> -        thumbs = os.path.expanduser(self._thumbs)
> -        thumbs_bak = thumbs + '.apbak'
> -        # Only save and restore if it previously existed
> -        if os.path.exists(thumbs):
> -            shutil.move(thumbs, thumbs_bak)
> -            self.addCleanup(shutil.move, thumbs_bak, thumbs)
> -        if not os.path.exists(os.path.dirname(thumbs)):
> -            os.makedirs(os.path.dirname(thumbs))
> -        mock_thumbs = os.path.join(self.sample_destination_dir, '.thumbnails')
> -        shutil.move(mock_thumbs, thumbs)
> -
> -    def configure_sample_files(self, env_type):
> -        self.sample_dir = resource_filename('gallery_app', 'data')
> -        self.sample_destination_dir = \
> -            self._get_sample_destination_dir(env_type)
> -        if (os.path.exists(self.sample_destination_dir)):
> -            shutil.rmtree(self.sample_destination_dir)
> -        self.assertFalse(os.path.exists(self.sample_destination_dir))
> -
> -        self.sample_file = os.path.join(
> -            self.sample_destination_dir,
> -            "sample04.jpg"
> -        )
> -
> -        default_data_dir = os.path.join(
> -            self.sample_dir,
> -            "default")
> -        shutil.copytree(default_data_dir, self.sample_destination_dir)
> -        self.assertTrue(os.path.isfile(self.sample_file))
> -
> -        self.sample_file_source = \
> -            default_data_dir + self.sample_file_source
> -
> -        if env_type == EnvironmentTypes.click:
> -            self.configure_db()
> -            self.configure_thumbnails()
> -
> -    def do_reset_config(self):
> -        config = os.path.expanduser(
> -            os.path.join("~", ".config", "gallery-app.conf"))
> -        if os.path.exists(config):
> -            os.remove(config)
> -
>      def setUp(self):
> -        self.pointing_device = toolkit_emulators.get_pointing_device()
>          super(GalleryTestCase, self).setUp()
>  
> -        env_type = self._get_environment_launch_type()
> -        self.configure_sample_files(env_type)
> -
> -        self.launch_gallery_app(env_type)
> -
> -        self.addCleanup(shutil.rmtree, self.sample_destination_dir)
> -        self.addCleanup(logger.debug,
> -                        "Deleting %s" % self.sample_destination_dir)
> +        self.gallery_app = GalleryApp(self, self.ARGS)
>  
>          """ This is needed to wait for the application to start.
>          In the testfarm, the application may take some time to show up."""
> -        self.assertThat(self.gallery_utils.get_qml_view().visible,
> +        self.assertThat(self.gallery_app.gallery_utils.get_qml_view().visible,
>                          Eventually(Equals(True)))
>          """FIXME somehow on the server gallery sometimes is not fully started
>          for switching to the albums view. Therefore this hack of sleeping"""
>          sleep(2)
> -
> -    def launch_gallery_app(self, env_type):
> -        if env_type == EnvironmentTypes.installed:
> -            self.launch_test_installed()
> -        elif env_type == EnvironmentTypes.local:
> -            self.launch_test_local()
> -        elif env_type == EnvironmentTypes.click:
> -            self.launch_test_click()
> -        else:
> -            raise ValueError("Unknown environment type: %s", env_type)
> -
> -    def launch_test_local(self):
> -        logger.debug("Launching local gallery-app binary.")
> -        self.ARGS.append(self.sample_destination_dir)
> -        self.app = self.launch_test_application(
> -            self.local_location,
> -            *self.ARGS,
> -            emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
> -
> -    def launch_test_installed(self):
> -        if model() == 'Desktop':
> -            logger.debug(
> -                "Launching installed gallery-app binary for desktop."
> -            )
> -            self.ARGS.append(self.sample_destination_dir)
> -            self.app = self.launch_test_application(
> -                "gallery-app",
> -                *self.ARGS,
> -                emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
> -        else:
> -            logger.debug(
> -                "Launching installed gallery-app binary for device."
> -            )
> -            self.ARGS.append("--desktop_file_hint="
> -                             "/usr/share/applications/gallery-app.desktop")
> -            self.ARGS.append(self.sample_destination_dir)
> -            self.app = self.launch_test_application(
> -                "gallery-app",
> -                *self.ARGS,
> -                app_type='qt',
> -                emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
> -
> -    def launch_test_click(self):
> -        '''
> -        Since this test runs under confinement, the only location photos
> -        are searchable in is ~/Pictures.
> -        '''
> -        logger.debug("Launching gallery-app via click package.")
> -        self.app = self.launch_click_package(
> -            package_id="com.ubuntu.gallery",
> -            app_uris=' '.join(self.ARGS),
> -            emulator_base=toolkit_emulators.UbuntuUIToolkitEmulatorBase)
> -
> -    def ui_update(self):
> -        """ Gives the program the time to update the UI"""
> -        sleep(0.1)
> -
> -    def click_item(self, item, delay=0.1):
> -        """Does a mouse click on the passed item, and moved the mouse there
> -           before"""
> -        # In jenkins test may fail because we don't wait before clicking the
> -        # target so we add a little delay before click.
> -        if model() == 'Desktop' and delay <= 0.25:
> -            delay = 0.25
> -
> -        self.pointing_device.move_to_object(item)
> -        sleep(delay)
> -        self.pointing_device.click()
> -
> -    def tap_item(self, item):
> -        """Does a long mouse press on the passed item, and moved the mouse
> -           there before"""
> -        self.pointing_device.move_to_object(item)
> -        self.pointing_device.press()
> -        sleep(1)
> -        self.pointing_device.release()
> -
> -    def switch_to_albums_tab(self):
> -        self.main_view.switch_to_tab("albumsTab")
> -
> -        albums_loader = self.gallery_utils.get_albums_viewer_loader()
> -        self.assertThat(albums_loader.progress, Eventually(Equals(1)))
> -
> -        # The next check assumes that at least one album is available
> -        # Check if the albums are availabe - they need some time to load.
> -        self.assertThat(lambda: len(self.gallery_utils.get_all_albums()),
> -                        Eventually(GreaterThan(0)))
> -        self.ensure_tabs_dont_move()
> -
> -    def ensure_tabs_dont_move(self):
> -        # FIXME find a (functional) way to test if the tabs still move
> -        sleep(1)
> -
> -    def open_album_at(self, position):
> -        album = self.album_view.get_album_at(position)
> -        # workaround lp:1247698
> -        self.main_view.close_toolbar()
> -        self.click_item(album)
> -        self.ensure_view_is_fully_open()
> -
> -    def open_first_album(self):
> -        self.open_album_at(-1)
> -
> -    def ensure_view_is_fully_open(self):
> -        animated_view = self.album_view.get_animated_album_view()
> -        self.assertThat(animated_view.isOpen, Eventually(Equals(True)))
> -        self.assertThat(animated_view.animationRunning,
> -                        Eventually(Equals(False)))
> -        view = self.album_view.get_album_view()
> -        self.assertThat(view.visible, Eventually(Equals(True)))
> -
> -    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)
> -            shell = unity8.select_single("Shell")
> -            shell.slots.showHome()
> -            self.assertThat(shell.currentFocusedAppId,
> -                            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)
> -
> -    def get_delete_dialog(self):
> -        """Raises StateNotFoundError if get_delete_dialog fails."""
> -        delete_dialog = self.gallery_utils.get_delete_dialog()
> -        self.assertThat(delete_dialog.visible, Eventually(Equals(True)))
> -        self.assertThat(delete_dialog.opacity, Eventually(Equals(1)))
> -        return delete_dialog
> 
> === modified file 'tests/autopilot/gallery_app/tests/test_album_editor.py'
> --- tests/autopilot/gallery_app/tests/test_album_editor.py	2014-05-21 06:38:11 +0000
> +++ tests/autopilot/gallery_app/tests/test_album_editor.py	2014-06-10 15:49:31 +0000
> @@ -11,9 +11,7 @@
>  from testtools.matchers import Equals
>  from autopilot.matchers import Eventually
>  
> -from gallery_app.emulators.album_view import AlbumView
> -from gallery_app.emulators.media_selector import MediaSelector
> -from gallery_app.emulators import album_editor
> +from gallery_app import GalleryApp
>  from gallery_app.tests import GalleryTestCase
>  
>  from time import sleep
> @@ -21,34 +19,17 @@
>  class TestAlbumEditor(GalleryTestCase):
>      """Tests the album editor of the gallery app"""
>  
> -    @property
> -    def album_view(self):
> -        return AlbumView(self.app)
> -
> -    @property
> -    def media_selector(self):
> -        return MediaSelector(self.app)
> -
>      def setUp(self):
> -        self.ARGS = []
>          super(TestAlbumEditor, self).setUp()
> -        self.switch_to_albums_tab()
> -        self.main_view.close_toolbar()
> -        self.edit_first_album()
> -
> -    def edit_first_album(self):
> -        first_album = self.gallery_utils.get_first_album()
> -        # workaround lp:1247698
> -        self.main_view.close_toolbar()
> -        self.tap_item(first_album)
> -        edit_button = self.gallery_utils.get_edit_album_button()
> -        self.click_item(edit_button)
> -        editor = self.app.select_single(album_editor.AlbumEditor)
> +        self.gallery_app.switch_to_albums_tab()
> +        self.gallery_app.main_view.close_toolbar()
> +        self.gallery_app.edit_first_album()
> +        editor = self.gallery_app.album_editor
>          editor.ensure_fully_open()
>  
>      def test_album_title_fields(self):
>          """tests the title and sub title"""
> -        editor = self.app.select_single(album_editor.AlbumEditor)
> +        editor = self.gallery_app.album_editor
>          title_field = editor.album_title_entry_field()
>          subtitle_field = editor.album_subtitle_entry_field()
>  
> @@ -59,7 +40,7 @@
>          self.assertThat(subtitle_field.text, Eventually(Equals(text)))
>  
>          # workaround lp:1247698
> -        self.main_view.close_toolbar()
> +        self.gallery_app.main_view.close_toolbar()
>          editor.click_title_field()
>          self.assertThat(title_field.activeFocus, Eventually(Equals(True)))
>          self.keyboard.press_and_release("Ctrl+a")
> @@ -80,61 +61,60 @@
>      def test_add_photo(self):
>          """Tests adding a photo using the media selector"""
>          # first open, but cancel before adding a photo
> -        editor = self.app.select_single(album_editor.AlbumEditor)
> +        editor = self.gallery_app.album_editor
>          # workaround lp:1247698
> -        self.main_view.close_toolbar()
> +        self.gallery_app.main_view.close_toolbar()
>          editor.add_photos()
> -        self.media_selector.ensure_fully_open()
> +        self.gallery_app.media_selector.ensure_fully_open()
>  
>          sleep(5)
> -        self.main_view.get_toolbar().click_custom_button("cancelButton")
> +        self.gallery_app.main_view.get_toolbar().click_custom_button("cancelButton")
>          editor.ensure_fully_closed()
>  
> -        self.main_view.close_toolbar()
> -        self.open_first_album()
> -        num_photos_start = self.album_view.number_of_photos()
> +        self.gallery_app.main_view.close_toolbar()
> +        self.gallery_app.open_first_album()
> +        num_photos_start = self.gallery_app.album_view.number_of_photos()
>          self.assertThat(num_photos_start, Equals(1))
> -        self.main_view.open_toolbar().click_button("backButton")
> -        self.album_view.ensure_animated_fully_closed()
> +        self.gallery_app.main_view.open_toolbar().click_button("backButton")
> +        self.gallery_app.album_view.ensure_animated_fully_closed()
>  
>          # now open to add a photo
> -        self.main_view.close_toolbar()
> -        self.edit_first_album()
> -        editor = self.app.select_single(album_editor.AlbumEditor)
> +        self.gallery_app.main_view.close_toolbar()
> +        self.gallery_app.edit_first_album()
> +        editor = self.gallery_app.album_editor
>          # workaround lp:1247698
> -        self.main_view.close_toolbar()
> -        editor.add_photos()
> +        self.gallery_app.main_view.close_toolbar()
> +        self.gallery_app.album_editor.add_photos()
>          self.media_selector.ensure_fully_open()
>  
>          photo = self.media_selector.get_second_photo()
> -        self.click_item(photo)
> -        self.main_view.get_toolbar().click_custom_button("addButton")
> -        editor = self.app.select_single(album_editor.AlbumEditor)
> -        editor.ensure_fully_closed()
> +        self.gallery_app.click_item(photo)
> +        self.gallery_app.main_view.get_toolbar().click_custom_button("addButton")
> +        self.gallery_app.album_editor.ensure_fully_closed()
>  
> -        self.main_view.close_toolbar()
> -        self.open_first_album()
> -        num_photos = self.album_view.number_of_photos()
> +        self.gallery_app.main_view.close_toolbar()
> +        self.gallery_app.open_first_album()
> +        num_photos = self.gallery_app.album_view.number_of_photos()
>          self.assertThat(num_photos, Equals(num_photos_start + 1))
>  
>      def test_cover_image(self):
>          """Test to change the album cover image"""
> -        editor = self.app.select_single(album_editor.AlbumEditor)
> +        editor = self.gallery_app.album_editor
>          cover_image = editor.album_cover_image()
>          self.assertThat(
>              cover_image.source.endswith("album-cover-default-large.png"),
>              Equals(True))
> -        self.main_view.close_toolbar()
> +        self.gallery_app.main_view.close_toolbar()
>  
>          # click somewhere rather at the bottom of the cover
>          # workaround lp:1247698
> -        self.main_view.close_toolbar()
> +        self.gallery_app.main_view.close_toolbar()
>          x, y, w, h = cover_image.globalRect
> -        self.pointing_device.move(x + int(w / 2), y + h - int(h / 10))
> -        self.pointing_device.click()
> +        self.gallery_app.pointing_device.move(x + int(w / 2), y + h - int(h / 10))
> +        self.gallery_app.pointing_device.click()
>  
> -        green_item = self.gallery_utils.get_cover_menu_item("Green")
> -        self.click_item(green_item)
> +        green_item = self.gallery_app.gallery_utils.get_cover_menu_item("Green")
> +        self.gallery_app.click_item(green_item)
>  
>          self.assertThat(lambda: cover_image.source.endswith(
>              "album-cover-green-large.png"), Eventually(Equals(True)))
> 
> === modified file 'tests/autopilot/gallery_app/tests/test_album_view.py'
> --- tests/autopilot/gallery_app/tests/test_album_view.py	2014-05-22 17:06:01 +0000
> +++ tests/autopilot/gallery_app/tests/test_album_view.py	2014-06-10 15:49:31 +0000
> @@ -11,10 +11,6 @@
>  from testtools.matchers import Equals, GreaterThan, LessThan
>  from autopilot.matchers import Eventually
>  
> -from gallery_app.emulators.album_view import AlbumView
> -from gallery_app.emulators.albums_view import AlbumsView
> -from gallery_app.emulators.media_selector import MediaSelector
> -from gallery_app.emulators import album_editor
>  from gallery_app.tests import GalleryTestCase
>  
>  from time import sleep
> @@ -24,139 +20,127 @@
>  class TestAlbumView(GalleryTestCase):
>      """Tests the album view of the gallery app"""
>  
> -    @property
> -    def album_view(self):
> -        return AlbumView(self.app)
> -
> -    @property
> -    def albums_view(self):
> -        return AlbumsView(self.app)
> -
> -    @property
> -    def media_selector(self):
> -        return MediaSelector(self.app)
> -
>      def setUp(self):
>          self.ARGS = []
>          super(TestAlbumView, self).setUp()
> -        self.switch_to_albums_tab()
> +        self.gallery_app.switch_to_albums_tab()
>  
>      def test_album_view_open_photo(self):
> -        self.main_view.close_toolbar()
> -        self.open_first_album()
> -        self.main_view.close_toolbar()
> -        photo = self.album_view.get_first_photo()
> +        self.gallery_app.main_view.close_toolbar()
> +        self.gallery_app.open_first_album()
> +        self.gallery_app.main_view.close_toolbar()
> +        photo = self.gallery_app.album_view.get_first_photo()
>          # workaround lp:1247698
> -        self.main_view.close_toolbar()
> -        self.click_item(photo)
> +        self.gallery_app.main_view.close_toolbar()
> +        self.gallery_app.click_item(photo)
>          sleep(5)
> -        photo_view = self.main_view.wait_select_single("PopupPhotoViewer")
> +        photo_view = self.gallery_app.main_view.wait_select_single("PopupPhotoViewer")
>          self.assertThat(photo_view.visible, Eventually(Equals(True)))
>  
>      def test_album_view_flipping(self):
> -        self.main_view.close_toolbar()
> +        self.gallery_app.main_view.close_toolbar()
>  
>          # For some reason here the album at position 0 in the autopilot list is
>          # actually the second album, they seem to be returned in reverse order.
> -        self.open_album_at(0)
> -        self.main_view.close_toolbar()
> +        self.gallery_app.open_album_at(0)
> +        self.gallery_app.main_view.close_toolbar()
>  
> -        spread = self.album_view.get_spread_view()
> +        spread = self.gallery_app.album_view.get_spread_view()
>  
>          # check that we can page to the cover and back (we check for lesser
>          # than 1 because it can either be 0 if we are on a one page spread
>          # or -1 if we are on a two page spread, for example on desktop)
> -        self.album_view.swipe_page_left(1)
> +        self.gallery_app.album_view.swipe_page_left(1)
>          self.assertThat(spread.viewingPage, Eventually(LessThan(1)))
> -        self.album_view.swipe_page_right(0)
> +        self.gallery_app.album_view.swipe_page_right(0)
>          self.assertThat(spread.viewingPage, Eventually(Equals(1)))
>  
>          # drag to next page and check we have flipped away from page 1
>          # can't check precisely for page 2 because depending on form factor
>          # and orientation we might be displaying two pages at the same time
> -        self.album_view.swipe_page_right(1)
> +        self.gallery_app.album_view.swipe_page_right(1)
>          self.assertThat(spread.viewingPage, Eventually(GreaterThan(1)))
>  
>      def test_add_photo(self):
> -        self.main_view.close_toolbar()
> -        self.open_first_album()
> -        num_photos_start = self.album_view.number_of_photos()
> +        self.gallery_app.main_view.close_toolbar()
> +        self.gallery_app.open_first_album()
> +        num_photos_start = self.gallery_app.album_view.number_of_photos()
>          self.assertThat(num_photos_start, Equals(1))
>  
>          # open media selector but cancel
> -        self.main_view.open_toolbar().click_button("addButton")
> -        self.media_selector.ensure_fully_open()
> +        self.gallery_app.main_view.open_toolbar().click_button("addButton")
> +        self.gallery_app.media_selector.ensure_fully_open()
>  
> -        self.main_view.get_toolbar().click_custom_button("cancelButton")
> +        self.gallery_app.main_view.get_toolbar().click_custom_button("cancelButton")
>          sleep(1)
>  
> -        num_photos = self.album_view.number_of_photos()
> +        num_photos = self.gallery_app.album_view.number_of_photos()
>          self.assertThat(num_photos, Equals(num_photos_start))
>  
>          # open media selector and add a photo
> -        self.main_view.open_toolbar().click_button("addButton")
> -        self.media_selector.ensure_fully_open()
> +        self.gallery_app.main_view.open_toolbar().click_button("addButton")
> +        self.gallery_app.media_selector.ensure_fully_open()
>  
> -        photo = self.media_selector.get_second_photo()
> -        self.click_item(photo)
> -        self.main_view.get_toolbar().click_custom_button("addButton")
> +        photo = self.gallery_app.media_selector.get_second_photo()
> +        self.gallery_app.click_item(photo)
> +        self.gallery_app.main_view.get_toolbar().click_custom_button("addButton")
>  
>          self.assertThat(
> -            lambda: self.album_view.number_of_photos(),
> +            lambda: self.gallery_app.album_view.number_of_photos(),
>              Eventually(Equals(num_photos_start + 1)))
>  
>      def test_add_photo_to_new_album(self):
> -        self.main_view.open_toolbar().click_button("addButton")
> -        self.ui_update()
> +        self.gallery_app.main_view.open_toolbar().click_button("addButton")
> +        self.gallery_app.ui_update()
>  
> -        editor = self.app.select_single(album_editor.AlbumEditor)
> +        editor = self.gallery_app.album_editor
>          editor.ensure_fully_open()
> -        self.main_view.close_toolbar()
> +        self.gallery_app.main_view.close_toolbar()
>          editor.close()
>  
> -        self.open_first_album()
> -        self.main_view.close_toolbar()
> -        num_photos_start = self.album_view.number_of_photos()
> +        self.gallery_app.open_first_album()
> +        self.gallery_app.main_view.close_toolbar()
> +        num_photos_start = self.gallery_app.album_view.number_of_photos()
>          self.assertThat(num_photos_start, Equals(0))
>  
> -        plus = self.album_view.get_plus_icon_empty_album()
> +        plus = self.gallery_app.album_view.get_plus_icon_empty_album()
>          # workaround lp:1247698
> -        self.main_view.close_toolbar()
> -        self.click_item(plus)
> -        self.media_selector.ensure_fully_open()
> +        self.gallery_app.main_view.close_toolbar()
> +        self.gallery_app.click_item(plus)
> +        self.gallery_app.media_selector.ensure_fully_open()
>  
> -        photo = self.media_selector.get_second_photo()
> -        self.click_item(photo)
> -        self.main_view.get_toolbar().click_custom_button("addButton")
> +        photo = self.gallery_app.media_selector.get_second_photo()
> +        self.gallery_app.click_item(photo)
> +        self.gallery_app.main_view.get_toolbar().click_custom_button("addButton")
>  
>          self.assertThat(
> -            lambda: self.album_view.number_of_photos(),
> +            lambda: self.gallery_app.album_view.number_of_photos(),
>              Eventually(Equals(num_photos_start + 1)))
>  
>      @skip("Temporarily disable as it fails in some cases, supposedly due to "
>            "problems with the infrastructure")
>      def test_save_state(self):
> -        self.main_view.close_toolbar()
> -        self.open_first_album()
> -
> -        id = self.album_view.get_album_view().albumId
> -
> -        self.ensure_app_has_quit()
> +        self.gallery_app.main_view.close_toolbar()
> +        self.gallery_app.open_first_album()
> +
> +        id = self.gallery_app.album_view.get_album_view().albumId
> +
> +        self.gallery_app.ensure_app_has_quit()
>          self.start_app()
>  
> -        view = self.album_view.get_album_view()
> +        view = self.gallery_app.album_view.get_album_view()
>          self.assertThat(view.visible, Eventually(Equals(True)))
>          self.assertThat(view.albumId, Eventually(Equals(id)))
>  
>      @skip("Temporarily disable as it fails in some cases, supposedly due to "
>            "problems with the infrastructure")
>      def test_no_save_state_on_back(self):
> -        self.main_view.close_toolbar()
> -        self.open_first_album()
> -        self.main_view.open_toolbar().click_button("backButton")
> +        self.gallery_app.main_view.close_toolbar()
> +        self.gallery_app.open_first_album()
> +        self.gallery_app.main_view.open_toolbar().click_button("backButton")
>  
>          self.ensure_app_has_quit()
>          self.start_app()
>  
> -        view = self.album_view.get_animated_album_view()
> +        view = self.gallery_app.album_view.get_animated_album_view()
>          self.assertThat(view.isOpen, Equals(False))
> 
> === modified file 'tests/autopilot/gallery_app/tests/test_albums_view.py'
> --- tests/autopilot/gallery_app/tests/test_albums_view.py	2014-05-20 15:19:35 +0000
> +++ tests/autopilot/gallery_app/tests/test_albums_view.py	2014-06-10 15:49:31 +0000
> @@ -13,8 +13,6 @@
>  from autopilot.platform import model
>  
>  from gallery_app.tests import GalleryTestCase
> -from gallery_app.emulators.albums_view import AlbumsView
> -from gallery_app.emulators import album_editor
>  
>  from os import environ as env
>  
> @@ -22,13 +20,7 @@
>  class TestAlbumsView(GalleryTestCase):
>      envDesktopMode = None
>  
> -    @property
> -    def albums_view(self):
> -        return AlbumsView(self.app)
> -
>      def setUp(self):
> -        self.ARGS = []
> -
>          self.envDesktopMode = env.get("DESKTOP_MODE")
>  
>          if model() == "Desktop":
> @@ -37,7 +29,7 @@
>              env["DESKTOP_MODE"] = "0"
>  
>          super(TestAlbumsView, self).setUp()
> -        self.switch_to_albums_tab()
> +        self.gallery_app.switch_to_albums_tab()
>  
>      def tearDown(self):
>          if self.envDesktopMode:
> @@ -49,10 +41,10 @@
>  
>      def test_add_album(self):
>          """Add one album, and checks if the number of albums went up by one"""
> -        albums = self.albums_view.number_of_albums_in_albums_view()
> -        self.main_view.open_toolbar().click_button("addButton")
> +        albums = self.gallery_app.albums_view.number_of_albums_in_albums_view()
> +        self.gallery_app.main_view.open_toolbar().click_button("addButton")
>          self.assertThat(
> -            lambda: self.albums_view.number_of_albums_in_albums_view(),
> +            lambda: self.gallery_app.albums_view.number_of_albums_in_albums_view(),
>              Eventually(Equals(albums+1))
>          )
>  
> @@ -60,20 +52,20 @@
>          """Add one album, cancel it and checks if the number of albums does
>          not change
>          """
> -        albums = self.albums_view.number_of_albums_in_albums_view()
> -        self.main_view.open_toolbar().click_button("addButton")
> -        editor = self.app.select_single(album_editor.AlbumEditor)
> +        albums = self.gallery_app.albums_view.number_of_albums_in_albums_view()
> +        self.gallery_app.main_view.open_toolbar().click_button("addButton")
> +        editor = self.gallery_app.album_editor
>          editor.ensure_fully_open()
> -        self.main_view.get_toolbar().click_custom_button("cancelButton")
> +        self.gallery_app.main_view.get_toolbar().click_custom_button("cancelButton")
>          self.assertThat(
> -            lambda: self.albums_view.number_of_albums_in_albums_view(),
> +            lambda: self.gallery_app.albums_view.number_of_albums_in_albums_view(),
>              Eventually(Equals(albums))
>          )
>  
>      # Check if Camera Button is not visible at Desktop mode
>      def test_camera_button_visible(self):
> -        self.main_view.open_toolbar()
> -        toolbar = self.main_view.get_toolbar()
> +        self.gallery_app.main_view.open_toolbar()
> +        toolbar = self.gallery_app.main_view.get_toolbar()
>          cameraButton = toolbar.select_single(
>              "ActionItem",
>              objectName="cameraButton"
> 
> === modified file 'tests/autopilot/gallery_app/tests/test_events_view.py'
> --- tests/autopilot/gallery_app/tests/test_events_view.py	2014-04-30 23:28:14 +0000
> +++ tests/autopilot/gallery_app/tests/test_events_view.py	2014-06-10 15:49:31 +0000
> @@ -13,7 +13,6 @@
>  from autopilot.platform import model
>  
>  from gallery_app.tests import GalleryTestCase
> -from gallery_app.emulators.events_view import EventsView
>  
>  from os import environ as env
>  from os.path import exists
> @@ -24,10 +23,6 @@
>      """Tests the main gallery features"""
>      envDesktopMode = None
>  
> -    @property
> -    def events_view(self):
> -        return EventsView(self.app)
> -
>      def setUp(self):
>          self.ARGS = []
>  
> @@ -41,9 +36,9 @@
>          # This is needed to wait for the application to start.
>          # In the testfarm, the application may take some time to show up.
>          super(TestEventsView, self).setUp()
> -        self.main_view.switch_to_tab("eventsTab")
> +        self.gallery_app.main_view.switch_to_tab("eventsTab")
>          """Wait for the data to be loaded and displayed"""
> -        self.assertThat(lambda: self.events_view.number_of_events(),
> +        self.assertThat(lambda: self.gallery_app.events_view.number_of_events(),
>                          Eventually(GreaterThan(0)))
>  
>      def tearDown(self):
> @@ -54,77 +49,70 @@
>  
>          super(TestEventsView, self).tearDown()
>  
> -    def get_events_view(self):
> -        return self.app.wait_select_single("EventsOverview",
> -                                           objectName="organicEventView")
> -
> -    def enable_select_mode(self):
> -        self.main_view.open_toolbar().click_button("selectButton")
> -
>      def test_select_button_cancel(self):
>          """Clicking the cancel button after clicking the select button must
>             hide the toolbar automatically."""
> -        events_view = self.get_events_view()
> +        events_view = self.gallery_app.get_events_view()
>          self.assertFalse(events_view.inSelectionMode)
>  
> -        self.enable_select_mode()
> +        self.gallery_app.enable_select_mode()
>          self.assertTrue(events_view.inSelectionMode)
>  
> -        self.main_view.get_toolbar().click_custom_button("cancelButton")
> +        self.gallery_app.main_view.get_toolbar().click_custom_button("cancelButton")
>  
> -        toolbar = self.main_view.get_toolbar()
> +        toolbar = self.gallery_app.main_view.get_toolbar()
>          self.assertThat(toolbar.opened, Eventually(Equals(False)))
>          self.assertFalse(events_view.inSelectionMode)
>  
>      def test_delete_a_photo(self):
>          """Selecting a photo must make the delete button clickable."""
> -        self.assertThat(lambda: exists(self.sample_file),
> -                        Eventually(Equals(True)))
> -
> -        self.enable_select_mode()
> -        self.events_view.click_photo(self.sample_file)
> -        self.main_view.open_toolbar().click_button("deleteButton")
> -        self.assertThat(self.gallery_utils.delete_dialog_shown,
> -                        Eventually(Is(True)))
> -
> -        self.gallery_utils.click_delete_dialog_cancel_button()
> -        self.assertThat(self.gallery_utils.delete_dialog_shown,
> -                        Eventually(Is(False)))
> -
> -        self.assertThat(lambda: exists(self.sample_file),
> -                        Eventually(Equals(True)))
> -
> -        self.main_view.open_toolbar().click_button("deleteButton")
> -        self.assertThat(self.gallery_utils.delete_dialog_shown,
> -                        Eventually(Is(True)))
> -
> -        self.gallery_utils.click_delete_dialog_delete_button()
> -        self.assertThat(self.gallery_utils.delete_dialog_shown,
> -                        Eventually(Is(False)))
> -
> -        self.assertThat(lambda: exists(self.sample_file),
> +        self.assertThat(lambda: exists(self.gallery_app.sample_file),
> +                        Eventually(Equals(True)))
> +
> +        self.gallery_app.enable_select_mode()
> +        self.gallery_app.events_view.click_photo(self.gallery_app.sample_file)
> +        self.gallery_app.main_view.open_toolbar().click_button("deleteButton")
> +        self.assertThat(self.gallery_app.gallery_utils.delete_dialog_shown,
> +                        Eventually(Is(True)))
> +
> +        self.gallery_app.gallery_utils.click_delete_dialog_cancel_button()
> +        self.assertThat(self.gallery_app.gallery_utils.delete_dialog_shown,
> +                        Eventually(Is(False)))
> +
> +        self.assertThat(lambda: exists(self.gallery_app.sample_file),
> +                        Eventually(Equals(True)))
> +
> +        self.gallery_app.main_view.open_toolbar().click_button("deleteButton")
> +        self.assertThat(self.gallery_app.gallery_utils.delete_dialog_shown,
> +                        Eventually(Is(True)))
> +
> +        self.gallery_app.gallery_utils.click_delete_dialog_delete_button()
> +        self.assertThat(self.gallery_app.gallery_utils.delete_dialog_shown,
> +                        Eventually(Is(False)))
> +
> +        self.assertThat(lambda: exists(self.gallery_app.sample_file),
>                          Eventually(Equals(False)))
>  
>      def test_adding_a_video(self):
>          if model() == "Desktop":
> -            before = self.events_view.get_event(0)
> +            before = self.gallery_app.events_view.get_event(0)
>              video_file = "video.mp4"
> -            shutil.copyfile(self.sample_dir+"/option01/"+video_file,
> -                            self.sample_destination_dir+"/"+video_file)
> +            shutil.copyfile(self.gallery_app.sample_dir+"/option01/"+video_file,
> +                            self.gallery_app.sample_destination_dir+"/"+video_file)
>              video_file = "video.mkv"
> -            shutil.copyfile(self.sample_dir+"/option01/"+video_file,
> -                            self.sample_destination_dir+"/"+video_file)
> -            after = self.events_view.get_event(0)
> +            shutil.copyfile(self.gallery_app.sample_dir+"/option01/"+video_file,
> +                            self.gallery_app.sample_destination_dir+"/"+video_file)
> +            after = self.gallery_app.events_view.get_event(0)
>              self.assertThat(lambda: str(after),
>                              Eventually(NotEquals(str(before))))
>              self.assertThat(
> -                lambda: self.events_view.number_of_photos_in_events(),
> +                lambda: self.gallery_app.events_view.number_of_photos_in_events(),
>                  Eventually(Equals(3)))
>  
>      # Check if Camera Button is not visible at Desktop mode
>      def test_camera_button_visible(self):
> -        self.main_view.open_toolbar()
> -        toolbar = self.main_view.get_toolbar()
> +        self.gallery_app.main_view.open_toolbar()
> +        toolbar = self.gallery_app.main_view.get_toolbar()
>          cameraButton = toolbar.select_single(
>              "ActionItem",
>              objectName="cameraButton"
> 
> === modified file 'tests/autopilot/gallery_app/tests/test_photo_viewer.py'
> --- tests/autopilot/gallery_app/tests/test_photo_viewer.py	2014-05-20 15:19:35 +0000
> +++ tests/autopilot/gallery_app/tests/test_photo_viewer.py	2014-06-10 15:49:31 +0000
> @@ -8,12 +8,9 @@
>  
>  """Tests the Photo editor of the gallery app."""
>  
> -from testtools.matchers import Equals, NotEquals, GreaterThan, Is
> +from testtools.matchers import Equals, NotEquals
>  from autopilot.matchers import Eventually
>  
> -from gallery_app.emulators.photo_viewer import PhotoViewer
> -from gallery_app.emulators.media_viewer import MediaViewer
> -from gallery_app.emulators.events_view import EventsView
>  from gallery_app.tests import GalleryTestCase
>  
>  import os
> @@ -26,38 +23,11 @@
>  
>  
>  class TestPhotoViewerBase(GalleryTestCase):
> -    @property
> -    def photo_viewer(self):
> -        return PhotoViewer(self.app)
> -
> -    @property
> -    def events_view(self):
> -        return EventsView(self.app)
> -
>      def setUp(self):
> -        self.ARGS = []
>          super(TestPhotoViewerBase, self).setUp()
> -        self.main_view.switch_to_tab("eventsTab")
> -        self.open_first_photo()
> -        self.main_view.open_toolbar()
> -
> -    def open_first_photo(self):
> -        self.assertThat(
> -            lambda: self.events_view.number_of_photos_in_events(),
> -            Eventually(GreaterThan(0))
> -        )
> -
> -        # workaround lp:1247698
> -        # toolbar needs to be gone to click on an image.
> -        self.main_view.close_toolbar()
> -
> -        self.events_view.click_photo(self.sample_file)
> -
> -        photo_viewer_loader = self.photo_viewer.get_main_photo_viewer_loader()
> -        self.assertThat(photo_viewer_loader.loaded, Eventually(Equals(True)))
> -        sleep(1)
> -        photo_viewer = self.photo_viewer.get_main_photo_viewer()
> -        self.assertThat(photo_viewer.visible, Eventually(Equals(True)))
> +        self.gallery_app.main_view.switch_to_tab("eventsTab")
> +        self.gallery_app.open_first_photo()
> +        self.gallery_app.main_view.open_toolbar()
>  
>  
>  class TestPhotoViewer(TestPhotoViewerBase):
> @@ -67,15 +37,15 @@
>      def test_save_state(self):
>          """Quitting the app once a photo has been opened will return
>          to that same photo on restart"""
> -        path = self.photo_viewer.get_photo_component().select_single(
> +        path = self.gallery_app.photo_viewer.get_photo_component().select_single(
>              "QQuickImage").source
>  
>          self.ensure_app_has_quit()
>          self.start_app()
>  
> -        photo_viewer = self.photo_viewer.get_main_photo_viewer()
> +        photo_viewer = self.gallery_app.photo_viewer.get_main_photo_viewer()
>          self.assertThat(photo_viewer.visible, Eventually(Equals(True)))
> -        new_path = self.photo_viewer.get_photo_component().select_single(
> +        new_path = self.gallery_app.photo_viewer.get_photo_component().select_single(
>              "QQuickImage").source
>  
>          self.assertThat(path, Equals(new_path))
> @@ -85,76 +55,59 @@
>      def test_no_save_state_on_back(self):
>          """Quitting the app once a photo has been opened and then closed
>          will not reopen a photo on restart"""
> -        self.main_view.open_toolbar().click_button("backButton")
> +        self.gallery_app.main_view.open_toolbar().click_button("backButton")
>  
>          self.ensure_app_has_quit()
>          self.start_app()
>  
> -        photo_viewer_loader = self.photo_viewer.get_main_photo_viewer_loader()
> +        photo_viewer_loader = self.gallery_app.photo_viewer.get_main_photo_viewer_loader()
>          self.assertThat(photo_viewer_loader.source, Equals(""))
>  
> -    def get_delete_dialog(self):
> -        delete_dialog = self.photo_viewer.get_delete_dialog()
> -        self.assertThat(delete_dialog.visible, Eventually(Equals(True)))
> -        self.assertThat(delete_dialog.opacity, Eventually(Equals(1)))
> -        return delete_dialog
> -
> -    def ensure_closed_delete_dialog(self):
> -        self.assertThat(self.photo_viewer.delete_dialog_shown,
> -                        Eventually(Is(False)))
> -
>      def test_nav_bar_back_button(self):
>          """Clicking the back button must close the photo."""
> -        self.main_view.open_toolbar().click_button("backButton")
> -        photo_viewer = self.photo_viewer.get_main_photo_viewer()
> +        self.gallery_app.main_view.open_toolbar().click_button("backButton")
> +        photo_viewer = self.gallery_app.photo_viewer.get_main_photo_viewer()
>          self.assertThat(photo_viewer.visible, Eventually(Equals(False)))
>  
> -    def delete_one_picture(self):
> -        self.main_view.open_toolbar().click_button("deleteButton")
> -        self.get_delete_dialog()
> -        delete_item = self.photo_viewer.get_delete_popover_delete_item()
> -        self.click_item(delete_item)
> -        self.ensure_closed_delete_dialog()
> -
>      def test_photo_delete_works(self):
>          """Clicking the trash button must show the delete dialog."""
> -        self.main_view.open_toolbar().click_button("deleteButton")
> -        self.get_delete_dialog()
> -
> -        photo_viewer = self.photo_viewer.get_main_photo_viewer()
> -
> -        cancel_item = self.photo_viewer.get_delete_popover_cancel_item()
> -        self.click_item(cancel_item)
> -        self.ensure_closed_delete_dialog()
> -
> -        self.assertThat(lambda: os.path.exists(self.sample_file),
> +        self.gallery_app.main_view.open_toolbar().click_button("deleteButton")
> +        self.gallery_app.get_delete_dialog()
> +
> +        photo_viewer = self.gallery_app.photo_viewer.get_main_photo_viewer()
> +
> +        cancel_item = self.gallery_app.photo_viewer.get_delete_popover_cancel_item()
> +        self.gallery_app.click_item(cancel_item)
> +        self.gallery_app.ensure_closed_delete_dialog()
> +
> +        self.assertThat(lambda: os.path.exists(self.gallery_app.sample_file),
>                          Eventually(Equals(True)))
>  
> -        self.delete_one_picture()
> -        self.assertThat(lambda: os.path.exists(self.sample_file),
> +        self.gallery_app.delete_one_picture()
> +        self.assertThat(lambda: os.path.exists(self.gallery_app.sample_file),
>                          Eventually(Equals(False)))
>  
>          # Delete all other pictures and make sure the photo viewer closes
> -        self.delete_one_picture()
> -        self.delete_one_picture()
> -        self.delete_one_picture()
> -        self.delete_one_picture()
> +        self.gallery_app.delete_one_picture()
> +        self.gallery_app.delete_one_picture()
> +        self.gallery_app.delete_one_picture()
> +        self.gallery_app.delete_one_picture()
>  
>          self.assertThat(photo_viewer.visible, Eventually(Equals(False)))
>  
>      def test_nav_bar_album_picker_button(self):
>          """Clicking the album picker must show the picker dialog."""
> -        self.main_view.open_toolbar().click_button("addButton")
> -        album_picker = self.photo_viewer.get_popup_album_picker()
> +        self.gallery_app.main_view.open_toolbar().click_button("addButton")
> +        album_picker = self.gallery_app.photo_viewer.get_popup_album_picker()
>          self.assertThat(album_picker.visible, Eventually(Equals(True)))
>  
>      def test_double_click_zoom(self):
>          """Double clicking an opened photo must zoom it."""
> -        opened_photo = self.photo_viewer.get_photo_component()
> +        opened_photo = self.gallery_app.photo_viewer.get_photo_component()
>  
> -        self.pointing_device.move_to_object(opened_photo)
> -        self.pointing_device.click()
> -        self.pointing_device.click()
> +        self.gallery_app.pointing_device.move_to_object(opened_photo)
> +        self.gallery_app.pointing_device.click()
> +        self.gallery_app.pointing_device.click()
>  
>          self.assertThat(
>              opened_photo.isZoomAnimationInProgress,
> @@ -162,8 +115,8 @@
>          )
>          self.assertThat(opened_photo.fullyZoomed, Eventually(Equals(True)))
>  
> -        self.pointing_device.click()
> -        self.pointing_device.click()
> +        self.gallery_app.pointing_device.click()
> +        self.gallery_app.pointing_device.click()
>  
>          self.assertThat(
>              opened_photo.isZoomAnimationInProgress,
> @@ -173,26 +126,26 @@
>  
>      def test_swipe_change_image(self):
>          """Swiping left and right on a photo should move to another photo"""
> -        list = self.photo_viewer.get_photos_list()
> +        list = self.gallery_app.photo_viewer.get_photos_list()
>          self.assertThat(list.currentIndex, Eventually(Equals(0)))
>  
>          # Slide left should move to the next image
>          x, y, w, h = list.globalRect
>          mid_y = y + h // 2
>          mid_x = x + w // 2
> -        self.pointing_device.drag(mid_x, mid_y, x + 10, mid_y)
> +        self.gallery_app.pointing_device.drag(mid_x, mid_y, x + 10, mid_y)
>  
>          self.assertThat(list.moving, Eventually(Equals(False)))
>          self.assertThat(list.currentIndex, Eventually(Equals(1)))
>  
>          # Slide right should get us back to the start
> -        self.pointing_device.drag(mid_x, mid_y, x + w - 10, mid_y)
> +        self.gallery_app.pointing_device.drag(mid_x, mid_y, x + w - 10, mid_y)
>  
>          self.assertThat(list.moving, Eventually(Equals(False)))
>          self.assertThat(list.currentIndex, Eventually(Equals(0)))
>  
>          # Slide right again shouldn't go anywhere
> -        self.pointing_device.drag(mid_x, mid_y, x + w - 10, mid_y)
> +        self.gallery_app.pointing_device.drag(mid_x, mid_y, x + w - 10, mid_y)
>  
>          self.assertThat(list.moving, Eventually(Equals(False)))
>          self.assertThat(list.currentIndex, Eventually(Equals(0)))
> @@ -202,98 +155,91 @@
>  
>      def setUp(self):
>          super(TestPhotoEditor, self).setUp()
> -        self.click_edit_button()
> -        self.media_view = self.app.select_single(MediaViewer)
> -
> -    def click_edit_button(self):
> -        self.main_view.open_toolbar().click_button("editButton")
> -        edit_dialog = self.photo_viewer.get_photo_edit_dialog()
> -        self.assertThat(edit_dialog.visible, (Eventually(Equals(True))))
> -        self.assertThat(edit_dialog.opacity, (Eventually(Equals(1))))
> +        self.gallery_app.click_edit_button()
>  
>      def test_photo_editor_crop(self):
>          """Cropping a photo must crop it."""
> -        old_file_size = os.path.getsize(self.sample_file)
> +        old_file_size = os.path.getsize(self.gallery_app.sample_file)
>  
> -        crop_box = self.photo_viewer.get_crop_interactor()
> +        crop_box = self.gallery_app.photo_viewer.get_crop_interactor()
>          item_width = crop_box.width
>          item_height = crop_box.height
>  
> -        self.photo_viewer.click_crop_item()
> +        self.gallery_app.photo_viewer.click_crop_item()
>  
>          self.assertThat(crop_box.state, Eventually(Equals("shown")))
>          self.assertThat(crop_box.opacity, Eventually(Equals(1)))
>  
> -        crop_corner = self.photo_viewer.get_top_left_crop_corner()
> +        crop_corner = self.gallery_app.photo_viewer.get_top_left_crop_corner()
>          x, y, h, w = crop_corner.globalRect
>          x = x + w // 2
>          y = y + h // 2
> -        self.pointing_device.drag(x, y,
> +        self.gallery_app.pointing_device.drag(x, y,
>                                    x + item_width // 2, y + item_height // 2)
>  
>          # wait for animation being finished
> -        crop_overlay = self.photo_viewer.get_crop_overlay()
> +        crop_overlay = self.gallery_app.photo_viewer.get_crop_overlay()
>          self.assertThat(crop_overlay.interpolationFactor,
>                          Eventually(Equals(1.0)))
>  
> -        crop_button = self.photo_viewer.get_crop_overlays_crop_icon()
> -        self.click_item(crop_button)
> -        self.media_view.ensure_spinner_not_running()
> +        crop_button = self.gallery_app.photo_viewer.get_crop_overlays_crop_icon()
> +        self.gallery_app.click_item(crop_button)
> +        self.gallery_app.media_view.ensure_spinner_not_running()
>  
>          # wait for new photo being set/reloaded, so saving thumbnailing etc.
>          # is done
> -        edit_preview = self.photo_viewer.get_edit_preview()
> -        new_source = "image://thumbnailer/" + self.sample_file
> +        edit_preview = self.gallery_app.photo_viewer.get_edit_preview()
> +        new_source = "image://thumbnailer/" + self.gallery_app.sample_file
>  
>          self.assertThat(edit_preview.source, Eventually(Equals(new_source)))
>  
> -        new_file_size = os.path.getsize(self.sample_file)
> +        new_file_size = os.path.getsize(self.gallery_app.sample_file)
>          self.assertThat(old_file_size > new_file_size, Equals(True))
>  
>      def test_photo_editor_rotate(self):
>          """Makes sure that the photo editor inside the photo viewer works using
>             the rotate function"""
> -        opened_photo = self.photo_viewer.get_opened_photo()
> +        opened_photo = self.gallery_app.photo_viewer.get_opened_photo()
>          item_height = opened_photo.height
>  
>          def is_landscape():
>              return opened_photo.paintedWidth > opened_photo.paintedHeight
>          self.assertThat(is_landscape(), Equals(True))
>  
> -        self.photo_viewer.click_rotate_item()
> -        self.media_view.ensure_spinner_not_running()
> +        self.gallery_app.photo_viewer.click_rotate_item()
> +        self.gallery_app.media_view.ensure_spinner_not_running()
>  
>          self.assertThat(opened_photo.paintedHeight,
>                          Eventually(Equals(item_height)))
>          self.assertThat(lambda: is_landscape(),
>                          Eventually(Equals(False)))
>  
> -        self.main_view.open_toolbar()
> -        self.click_edit_button()
> -        self.photo_viewer.click_undo_item()
> -        self.media_view.ensure_spinner_not_running()
> +        self.gallery_app.main_view.open_toolbar()
> +        self.gallery_app.click_edit_button()
> +        self.gallery_app.photo_viewer.click_undo_item()
> +        self.gallery_app.media_view.ensure_spinner_not_running()
>  
>          self.assertThat(opened_photo.paintedHeight,
>                          Eventually(NotEquals(item_height)))
>          self.assertThat(lambda: is_landscape(),
>                          Eventually(Equals(True)))
>  
> -        self.main_view.open_toolbar()
> -        self.click_edit_button()
> -        self.photo_viewer.click_redo_item()
> -        self.media_view.ensure_spinner_not_running()
> +        self.gallery_app.main_view.open_toolbar()
> +        self.gallery_app.click_edit_button()
> +        self.gallery_app.photo_viewer.click_redo_item()
> +        self.gallery_app.media_view.ensure_spinner_not_running()
>  
>          self.assertThat(opened_photo.paintedHeight,
>                          Eventually(Equals(item_height)))
>          is_landscape = opened_photo.paintedWidth > opened_photo.paintedHeight
>          self.assertThat(is_landscape, Equals(False))
>  
> -        self.main_view.open_toolbar()
> -        self.click_edit_button()
> -        self.photo_viewer.click_rotate_item()
> -        self.main_view.open_toolbar()
> -        self.click_edit_button()
> -        self.photo_viewer.click_revert_item()
> +        self.gallery_app.main_view.open_toolbar()
> +        self.gallery_app.click_edit_button()
> +        self.gallery_app.photo_viewer.click_rotate_item()
> +        self.gallery_app.main_view.open_toolbar()
> +        self.gallery_app.click_edit_button()
> +        self.gallery_app.photo_viewer.click_revert_item()
>  
>          self.assertThat(opened_photo.paintedHeight,
>                          Eventually(NotEquals(item_height)))
> @@ -307,66 +253,66 @@
>          sleep(1)
>  
>      def test_photo_editor_redo_undo_revert_enhance_states(self):
> -        undo_item = self.photo_viewer.get_undo_menu_item()
> -        redo_item = self.photo_viewer.get_redo_menu_item()
> -        revert_item = self.photo_viewer.get_revert_menu_item()
> +        undo_item = self.gallery_app.photo_viewer.get_undo_menu_item()
> +        redo_item = self.gallery_app.photo_viewer.get_redo_menu_item()
> +        revert_item = self.gallery_app.photo_viewer.get_revert_menu_item()
>  
>          self.assertThat(undo_item.enabled, Eventually(Equals(False)))
>          self.assertThat(redo_item.enabled, Eventually(Equals(False)))
>          self.assertThat(revert_item.enabled, Eventually(Equals(False)))
>  
> -        self.photo_viewer.click_rotate_item()
> -        self.media_view.ensure_spinner_not_running()
> +        self.gallery_app.photo_viewer.click_rotate_item()
> +        self.gallery_app.media_view.ensure_spinner_not_running()
>  
> -        self.click_edit_button()
> -        undo_item = self.photo_viewer.get_undo_menu_item()
> -        redo_item = self.photo_viewer.get_redo_menu_item()
> -        revert_item = self.photo_viewer.get_revert_menu_item()
> +        self.gallery_app.click_edit_button()
> +        undo_item = self.gallery_app.photo_viewer.get_undo_menu_item()
> +        redo_item = self.gallery_app.photo_viewer.get_redo_menu_item()
> +        revert_item = self.gallery_app.photo_viewer.get_revert_menu_item()
>  
>          self.assertThat(undo_item.enabled, Eventually(Equals(True)))
>          self.assertThat(redo_item.enabled, Eventually(Equals(False)))
>          self.assertThat(revert_item.enabled, Eventually(Equals(True)))
>  
> -        self.photo_viewer.click_undo_item()
> -        self.media_view.ensure_spinner_not_running()
> +        self.gallery_app.photo_viewer.click_undo_item()
> +        self.gallery_app.media_view.ensure_spinner_not_running()
>  
> -        self.click_edit_button()
> -        undo_item = self.photo_viewer.get_undo_menu_item()
> -        redo_item = self.photo_viewer.get_redo_menu_item()
> -        revert_item = self.photo_viewer.get_revert_menu_item()
> +        self.gallery_app.click_edit_button()
> +        undo_item = self.gallery_app.photo_viewer.get_undo_menu_item()
> +        redo_item = self.gallery_app.photo_viewer.get_redo_menu_item()
> +        revert_item = self.gallery_app.photo_viewer.get_revert_menu_item()
>  
>          self.assertThat(undo_item.enabled, Eventually(Equals(False)))
>          self.assertThat(redo_item.enabled, Eventually(Equals(True)))
>          self.assertThat(revert_item.enabled, Eventually(Equals(False)))
>  
> -        self.photo_viewer.click_redo_item()
> -        self.media_view.ensure_spinner_not_running()
> +        self.gallery_app.photo_viewer.click_redo_item()
> +        self.gallery_app.media_view.ensure_spinner_not_running()
>  
> -        self.click_edit_button()
> -        undo_item = self.photo_viewer.get_undo_menu_item()
> -        redo_item = self.photo_viewer.get_redo_menu_item()
> -        revert_item = self.photo_viewer.get_revert_menu_item()
> +        self.gallery_app.click_edit_button()
> +        undo_item = self.gallery_app.photo_viewer.get_undo_menu_item()
> +        redo_item = self.gallery_app.photo_viewer.get_redo_menu_item()
> +        revert_item = self.gallery_app.photo_viewer.get_revert_menu_item()
>  
>          self.assertThat(undo_item.enabled, Eventually(Equals(True)))
>          self.assertThat(redo_item.enabled, Eventually(Equals(False)))
>          self.assertThat(revert_item.enabled, Eventually(Equals(True)))
>  
> -        self.photo_viewer.click_revert_item()
> -        self.media_view.ensure_spinner_not_running()
> +        self.gallery_app.photo_viewer.click_revert_item()
> +        self.gallery_app.media_view.ensure_spinner_not_running()
>  
> -        self.click_edit_button()
> -        undo_item = self.photo_viewer.get_undo_menu_item()
> -        redo_item = self.photo_viewer.get_redo_menu_item()
> -        revert_item = self.photo_viewer.get_revert_menu_item()
> +        self.gallery_app.click_edit_button()
> +        undo_item = self.gallery_app.photo_viewer.get_undo_menu_item()
> +        redo_item = self.gallery_app.photo_viewer.get_redo_menu_item()
> +        revert_item = self.gallery_app.photo_viewer.get_revert_menu_item()
>  
>          self.assertThat(undo_item.enabled, Eventually(Equals(True)))
>          self.assertThat(redo_item.enabled, Eventually(Equals(False)))
>          self.assertThat(revert_item.enabled, Eventually(Equals(False)))
>  
> -        self.photo_viewer.click_enhance_item()
> -        self.media_view.ensure_spinner_not_running()
> -
> -        self.click_edit_button()
> -
> -        revert_item = self.photo_viewer.get_revert_menu_item()
> +        self.gallery_app.photo_viewer.click_enhance_item()
> +        self.gallery_app.media_view.ensure_spinner_not_running()
> +
> +        self.gallery_app.click_edit_button()
> +
> +        revert_item = self.gallery_app.photo_viewer.get_revert_menu_item()
>          self.assertThat(lambda: revert_item.enabled, Eventually(Equals(True)))
> 
> === modified file 'tests/autopilot/gallery_app/tests/test_photos_view.py'
> --- tests/autopilot/gallery_app/tests/test_photos_view.py	2014-05-20 20:59:52 +0000
> +++ tests/autopilot/gallery_app/tests/test_photos_view.py	2014-06-10 15:49:31 +0000
> @@ -14,7 +14,6 @@
>  from autopilot.platform import model
>  
>  from gallery_app.tests import GalleryTestCase
> -from gallery_app.emulators.photos_view import PhotosView
>  
>  from time import sleep
>  from os import environ as env
> @@ -24,10 +23,6 @@
>  class TestPhotosView(GalleryTestCase):
>      envDesktopMode = None
>  
> -    @property
> -    def photos_view(self):
> -        return PhotosView(self.app)
> -
>      def setUp(self):
>          self.ARGS = []
>          self.envDesktopMode = env.get("DESKTOP_MODE")
> @@ -38,7 +33,7 @@
>              env["DESKTOP_MODE"] = "0"
>  
>          super(TestPhotosView, self).setUp()
> -        self.switch_to_photos_tab()
> +        self.gallery_app.switch_to_photos_tab()
>  
>      def tearDown(self):
>          if self.envDesktopMode:
> @@ -48,82 +43,74 @@
>  
>          super(TestPhotosView, self).tearDown()
>  
> -    def switch_to_photos_tab(self):
> -        self.main_view.switch_to_tab("photosTab")
> -        self.ensure_tabs_dont_move()
> -
> -    def click_first_photo(self):
> -        photo = self.photos_view.get_first_photo_in_photos_view()
> -        self.click_item(photo)
> -
>      def test_open_photo(self):
> -        self.main_view.close_toolbar()
> -        self.click_first_photo()
> +        self.gallery_app.main_view.close_toolbar()
> +        self.gallery_app.click_first_photo()
>          sleep(5)
> -        photo_viewer = self.photos_view.get_main_photo_viewer()
> +        photo_viewer = self.gallery_app.photos_view.get_main_photo_viewer()
>          self.assertThat(photo_viewer.visible, Eventually(Equals(True)))
>  
>      def test_select_button_cancel(self):
>          """Clicking the cancel button after clicking the select button must
>          hide the toolbar automatically."""
> -        photos_overview = self.app.select_single("PhotosOverview")
> +        photos_overview = self.gallery_app.app.select_single("PhotosOverview")
>          self.assertFalse(photos_overview.inSelectionMode)
>  
> -        self.main_view.open_toolbar().click_button("selectButton")
> +        self.gallery_app.main_view.open_toolbar().click_button("selectButton")
>          self.assertTrue(photos_overview.inSelectionMode)
>  
> -        self.main_view.open_toolbar().click_custom_button("cancelButton")
> +        self.gallery_app.main_view.open_toolbar().click_custom_button("cancelButton")
>  
> -        toolbar = self.main_view.get_toolbar()
> +        toolbar = self.gallery_app.main_view.get_toolbar()
>          self.assertThat(toolbar.opened, Eventually(Equals(False)))
>          self.assertFalse(photos_overview.inSelectionMode)
>  
> -        first_photo = self.photos_view.get_first_photo_in_photos_view()
> -        self.tap_item(first_photo)
> +        first_photo = self.gallery_app.photos_view.get_first_photo_in_photos_view()
> +        self.gallery_app.tap_item(first_photo)
>          self.assertTrue(photos_overview.inSelectionMode)
>  
>      def test_delete_photo_dialog_appears(self):
>          """Selecting a photo must make the delete button clickable."""
> -        self.main_view.open_toolbar().click_button("selectButton")
> -        self.click_first_photo()
> -        self.main_view.open_toolbar().click_button("deleteButton")
> +        self.gallery_app.main_view.open_toolbar().click_button("selectButton")
> +        self.gallery_app.click_first_photo()
> +        self.gallery_app.main_view.open_toolbar().click_button("deleteButton")
>  
> -        self.assertThat(self.gallery_utils.delete_dialog_shown,
> +        self.assertThat(self.gallery_app.gallery_utils.delete_dialog_shown,
>                          Eventually(Is(True)))
>  
> -        cancel_item = self.photos_view.get_delete_dialog_cancel_button()
> -        self.click_item(cancel_item)
> -        self.assertThat(self.gallery_utils.delete_dialog_shown,
> +        cancel_item = self.gallery_app.photos_view.get_delete_dialog_cancel_button()
> +        self.gallery_app.click_item(cancel_item)
> +        self.assertThat(self.gallery_app.gallery_utils.delete_dialog_shown,
>                          Eventually(Is(False)))
>  
>      def test_delete_a_photo(self):
>          """Must be able to select a photo and use the dialog to delete it."""
> -        number_of_photos = self.photos_view.number_of_photos()
> -        self.main_view.open_toolbar().click_button("selectButton")
> -        self.click_first_photo()
> -        self.main_view.open_toolbar().click_button("deleteButton")
> +        number_of_photos = self.gallery_app.photos_view.number_of_photos()
> +        self.gallery_app.main_view.open_toolbar().click_button("selectButton")
> +        self.gallery_app.click_first_photo()
> +        self.gallery_app.main_view.open_toolbar().click_button("deleteButton")
>  
> -        self.assertThat(self.gallery_utils.delete_dialog_shown,
> +        self.assertThat(self.gallery_app.gallery_utils.delete_dialog_shown,
>                          Eventually(Is(True)))
>  
> -        self.main_view.open_toolbar().click_button("deleteButton")
> +        self.gallery_app.main_view.open_toolbar().click_button("deleteButton")
>  
> -        delete_item = self.photos_view.get_delete_dialog_delete_button()
> -        self.click_item(delete_item)
> +        delete_item = self.gallery_app.photos_view.get_delete_dialog_delete_button()
> +        self.gallery_app.click_item(delete_item)
>          self.assertThat(
> -            self.gallery_utils.delete_dialog_shown,
> +            self.gallery_app.gallery_utils.delete_dialog_shown,
>              Eventually(Is(False))
>          )
>  
> -        self.assertThat(lambda: self.photos_view.number_of_photos(),
> +        self.assertThat(lambda: self.gallery_app.photos_view.number_of_photos(),
>                          Eventually(Equals(number_of_photos - 1)))
>  
>      @unittest.skip("Temporarily disable as it fails in some cases, "
>                     "supposedly due to problems with the infrastructure")
>      def test_save_state(self):
> -        self.switch_to_photos_tab()
> +        self.gallery_app.switch_to_photos_tab()
>  
> -        tabs = self.main_view.select_single("Tabs")
> +        tabs = self.gallery_app.main_view.select_single("Tabs")
>          tab = tabs.get_current_tab()
>          self.assertThat(tab.objectName, Equals("photosTab"))
>          index = tab.index
> @@ -131,7 +118,7 @@
>          self.ensure_app_has_quit()
>          self.start_app()
>  
> -        tabs = self.main_view.select_single("Tabs")
> +        tabs = self.gallery_app.main_view.select_single("Tabs")
>          tab = tabs.get_current_tab()
>          self.assertThat(tabs.selectedTabIndex, Eventually(Equals(index)))
>          self.assertThat(tab.objectName, Equals("photosTab"))
> @@ -141,8 +128,8 @@
>          'Key based tests only make sense on Desktop'
>      )
>      def test_toggle_fullscreen(self):
> -        self.switch_to_photos_tab()
> -        view = self.main_view
> +        self.gallery_app.switch_to_photos_tab()
> +        view = self.gallery_app.main_view
>          self.assertThat(view.fullScreen, Eventually(Equals(False)))
>          self.keyboard.press_and_release('F11')
>          self.assertThat(view.fullScreen, Eventually(Equals(True)))
> @@ -157,8 +144,8 @@
>  
>      # Check if Camera Button is not visible at Desktop mode
>      def test_camera_button_visible(self):
> -        self.main_view.open_toolbar()
> -        toolbar = self.main_view.get_toolbar()
> +        self.gallery_app.main_view.open_toolbar()
> +        toolbar = self.gallery_app.main_view.get_toolbar()
>          cameraButton = toolbar.select_single(
>              "ActionItem",
>              objectName="cameraButton"
> 
> === modified file 'tests/autopilot/gallery_app/tests/test_picker_mode.py'
> --- tests/autopilot/gallery_app/tests/test_picker_mode.py	2014-05-21 16:02:19 +0000
> +++ tests/autopilot/gallery_app/tests/test_picker_mode.py	2014-06-10 15:49:31 +0000
> @@ -11,54 +11,43 @@
>  from testtools.matchers import Equals
>  from autopilot.matchers import Eventually
>  
> -from gallery_app.emulators.picker_screen import PickerScreen
> +from gallery_app import GalleryApp
>  from gallery_app.tests import GalleryTestCase
> +
>  import unittest
>  
>  from unittest import skip
>  
>  class TestPickerMode(GalleryTestCase):
>  
> -    @property
> -    def picker_view(self):
> -        return self.app.select_single(PickerScreen)
> -
>      def setUp(self):
>          self.ARGS.append("--pick-mode")
>          super(TestPickerMode, self).setUp()
>  
> -    def select_first_event_media(self):
> -        first_media = self.picker_view.first_media_in_events_view()
> -        self.click_item(first_media)
> -
> -    def select_first_grid_media(self):
> -        first_media = self.picker_view.first_media_in_events_view()
> -        self.click_item(first_media)
> -
>      @unittest.skip("Temporarily disable as it fails in some cases, "
>                     "supposedly due to problems with the infrastructure")
>      def test_pick_first_photo(self):
>          """Check if the button enabled state follows the selection"""
> -        pick_button = self.picker_view.pick_button()
> +        pick_button = self.gallery_app.picker_view.pick_button()
>          self.assertThat(pick_button.enabled, Eventually(Equals(False)))
> -        first_events_media = self.picker_view.first_media_in_events_view()
> +        first_events_media = self.gallery_app.picker_view.first_media_in_events_view()
>          self.assertThat(
>              first_events_media.isSelected,
>              Eventually(Equals(False))
>          )
>  
> -        self.select_first_event_media()
> +        self.gallery_app.select_first_event_media()
>  
> -        pick_button = self.picker_view.pick_button()
> +        pick_button = self.gallery_app.picker_view.pick_button()
>          self.assertThat(pick_button.enabled, Eventually(Equals(True)))
>          self.assertThat(
>              first_events_media.isSelected,
>              Eventually(Equals(True))
>          )
>  
> -        self.select_first_event_media()
> +        self.gallery_app.select_first_event_media()
>  
> -        pick_button = self.picker_view.pick_button()
> +        pick_button = self.gallery_app.picker_view.pick_button()
>          self.assertThat(pick_button.enabled, Eventually(Equals(False)))
>          self.assertThat(
>              first_events_media.isSelected,
> @@ -68,14 +57,14 @@
>      @skip("Temporarily disable as it fails in some cases")
>      def test_pick_named_photo(self):
>          """Select a named photo and press Pick button."""
> -        self.picker_view.switch_to_tab('photosTab')
> -        pick_button = self.picker_view.pick_button()
> +        self.gallery_app.picker_view.switch_to_tab('photosTab')
> +        pick_button = self.gallery_app.picker_view.pick_button()
>          self.assertFalse(pick_button.enabled)
>  
>          # create the image location path based on sample location
>          image_path = 'image://thumbnailer/{}/sample02.jpg'.format(
>              self.sample_destination_dir)
> -        self.picker_view.select_named_photo(image_path)
> +        self.gallery_app.picker_view.select_named_photo(image_path)
>  
>          self.assertTrue(pick_button.enabled)
>          self.click_item(pick_button)
> @@ -84,38 +73,38 @@
>                     "supposedly due to problems with the infrastructure")
>      def test_selection_synchronisation(self):
>          """Checks if the selection is the same for both views"""
> -        first_events_media = self.picker_view.first_media_in_events_view()
> +        first_events_media = self.gallery_app.picker_view.first_media_in_events_view()
>          self.assertThat(
>              first_events_media.isSelected,
>              Eventually(Equals(False))
>          )
>  
> -        self.select_first_event_media()
> +        self.gallery_app.select_first_event_media()
>          self.assertThat(
>              first_events_media.isSelected,
>              Eventually(Equals(True))
>          )
>  
> -        self.picker_view.switch_to_next_tab()
> +        self.gallery_app.picker_view.switch_to_next_tab()
>  
> -        first_grid_media = self.picker_view.first_media_in_grid_view()
> +        first_grid_media = self.gallery_app.picker_view.first_media_in_grid_view()
>          self.assertThat(first_grid_media.isSelected, Eventually(Equals(True)))
>  
>      @unittest.skip("Temporarily disable as it fails in some cases, "
>                     "supposedly due to problems with the infrastructure")
>      def test_save_picker_state(self):
> -        self.picker_view.switch_to_tab("photosTab")
> -        self.ensure_tabs_dont_move()
> +        self.gallery_app.picker_view.switch_to_tab("photosTab")
> +        self.gallery_app.ensure_tabs_dont_move()
>  
> -        tabs = self.picker_view.select_single("Tabs")
> +        tabs = self.gallery_app.picker_view.select_single("Tabs")
>          tab = tabs.get_current_tab()
>          self.assertThat(tab.objectName, Equals("photosTab"))
>          index = tab.index
>  
> -        self.ensure_app_has_quit()
> +        self.gallery_app.ensure_app_has_quit()
>          self.start_app()
>  
> -        tabs = self.picker_view.select_single("Tabs")
> +        tabs = self.gallery_app.picker_view.select_single("Tabs")
>          tab = tabs.get_current_tab()
>          self.assertThat(tabs.selectedTabIndex, Eventually(Equals(index)))
>          self.assertThat(tab.objectName, Equals("photosTab"))
> 


-- 
https://code.launchpad.net/~vrruiz/gallery-app/autopilot-app-class/+merge/222667
Your team Ubuntu Phablet Team is subscribed to branch lp:gallery-app.



More information about the Ubuntu-reviews mailing list