=== added file 'tests/autopilot/gallery_app/tests/test_share.py'
--- tests/autopilot/gallery_app/tests/test_share.py	1970-01-01 00:00:00 +0000
+++ tests/autopilot/gallery_app/tests/test_share.py	2014-07-08 10:18:30 +0000
@@ -0,0 +1,106 @@
+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
+# Copyright 2013 Canonical
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 3, as published
+# by the Free Software Foundation.
+
+"""Tests the Photos share options of the gallery app."""
+
+import dbus
+import dbusmock
+import subprocess
+
+from time import sleep
+from testtools.matchers import GreaterThan, Is, Not
+
+from gallery_app.tests.test_photo_viewer import TestPhotoViewerBase
+
+class FakeFriendsService(object):
+    """Fake Friends service"""
+    def __init__(self, dbus_connection):
+        super(FakeFriendsService, self).__init__()
+        self.dbus_connection = dbus_connection
+        self.mock = self._get_mock_interface()
+        self._add_methods()
+
+    def get_calls(self):
+        return self.mock.GetCalls()
+
+    def _add_methods(self):
+        self.mock.AddMethod(
+            'com.canonical.Friends.Dispatcher',
+            'Upload', 'sss', 's', 'ret = "https://www.facebook.com/649348222_10152546147613223"'
+            )
+
+    def _get_mock_interface(self):
+        return dbus.Interface(
+            self.dbus_connection.get_object(
+                'com.canonical.Friends.Dispatcher',
+                '/com/canonical/Friends/Dispatcher',
+                ),
+            dbusmock.MOCK_IFACE)
+
+
+class ShareTestCase(dbusmock.DBusTestCase, TestPhotoViewerBase):
+    """Test Facebook share"""
+
+    def setUp(self):
+        # Use the fake friends service
+        self._use_fake_friends_service()
+        super(ShareTestCase, self).setUp()
+
+    def tearDown(self):
+        super(ShareTestCase, self).tearDown()
+
+    @property
+    def post_button(self):
+        return self.main_view.wait_select_single(objectName="postButton")
+
+    @property
+    def share_panel(self):
+        return self.app.wait_select_single(objectName="shareComponent")
+
+    def ensure_share_panel_is_opened(self):
+        """Ensure that the share panel is opened"""
+        self.assertThat(self.share_panel, Not(Is(None)))
+        self.assertThat(self.post_button, Not(Is(None)))
+
+    def do_share_photo(self):
+        """Click on a photo and share it"""
+        # Tab on share button
+        self.main_view.open_toolbar().click_button("shareButton")
+        # Ensure that the share panel is opened
+        self.ensure_share_panel_is_opened()
+        # Click on "Post" button to upload image to Facebook fake service
+        self.pointing_device.click_object(self.post_button)
+
+    def _use_fake_friends_service(self):
+        """Starts a fake Friends service"""
+        self._spawn_fake_friends_service()
+        dbus_connection = self.get_dbus(system_bus=False)
+        self.fake_friends_service = FakeFriendsService(dbus_connection)
+
+    def _spawn_fake_friends_service(self):
+        self.friends_service_mock = self.spawn_server(
+            'com.canonical.Friends.Dispatcher',
+            '/com/canonical/Friends/Dispatcher',
+            'com.canonical.Friends.Dispatcher',
+            system_bus=False,
+            )
+        self.addCleanup(self._terminate_process)
+
+    def _terminate_process(self):
+        """Finish the fake Friends service"""
+        self.friends_service_mock.terminate()
+        self.friends_service_mock.wait()
+
+    def test_facebook(self):
+        """Test Facebook share"""
+        # Click on a photo and share it
+        self.do_share_photo()
+        # Wait a little bit
+        sleep(5)
+        # Check that the call to fake service was correctly done
+        calls = self.fake_friends_service.get_calls()
+        self.assertThat(len(calls), GreaterThan(0))

