summaryrefslogtreecommitdiffstats
path: root/sync
diff options
context:
space:
mode:
authorpetewil@chromium.org <petewil@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-17 04:57:12 +0000
committerpetewil@chromium.org <petewil@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-17 04:57:12 +0000
commitc60b5453e002337d8295ebd467c3753c1969cf41 (patch)
tree071179e9fffdb222afbe4bc50fb518b1f65133cd /sync
parenta21c90dcae61e3a0edb6a713694e94b3a58656b9 (diff)
downloadchromium_src-c60b5453e002337d8295ebd467c3753c1969cf41.zip
chromium_src-c60b5453e002337d8295ebd467c3753c1969cf41.tar.gz
chromium_src-c60b5453e002337d8295ebd467c3753c1969cf41.tar.bz2
Add a test for the SyncedNotificationAppInfo using the test sync server.
This will be used to test the ProcessSyncChanges path, since new app infos are not often added to production. Note that this changelist includes the changes for changelist 19373003, which I plan to check in before this change. So, you can ignore those files for now, and just focus on the changes to chromiumsync.py, sync_testserver.py, and synced_notification_app_info.html BUG=280266 Review URL: https://codereview.chromium.org/203943002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@264422 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync')
-rw-r--r--sync/tools/testserver/chromiumsync.py74
-rwxr-xr-xsync/tools/testserver/sync_testserver.py48
-rw-r--r--sync/tools/testserver/synced_notifications.html18
-rw-r--r--sync/tools/testserver/synced_notifications_app_info.html49
4 files changed, 183 insertions, 6 deletions
diff --git a/sync/tools/testserver/chromiumsync.py b/sync/tools/testserver/chromiumsync.py
index 1e87042..661366a 100644
--- a/sync/tools/testserver/chromiumsync.py
+++ b/sync/tools/testserver/chromiumsync.py
@@ -1196,12 +1196,7 @@ class SyncDataModel(object):
entity.parent_id_string = self._ServerTagToId(
'google_chrome_synced_notifications')
entity.name = 'Synced notification added for testing'
-
- # Set the version to one more than the greatest version number already seen.
- entries = sorted(self._entries.values(), key=operator.attrgetter('version'))
- if len(entries) < 1:
- raise ClientNotConnectedError
- entity.version = entries[-1].version + 1
+ entity.version = self._GetNextVersionNumber()
entity.client_defined_unique_tag = self._CreateSyncedNotificationClientTag(
specifics.synced_notification.coalesced_notification.key)
@@ -1212,6 +1207,13 @@ class SyncDataModel(object):
return google.protobuf.text_format.MessageToString(entity)
+ def _GetNextVersionNumber(self):
+ """Set the version to one more than the greatest version number seen."""
+ entries = sorted(self._entries.values(), key=operator.attrgetter('version'))
+ if len(entries) < 1:
+ raise ClientNotConnectedError
+ return entries[-1].version + 1
+
def _CreateSyncedNotificationEntitySpecifics(self, unique_id,
serialized_notification):
"""Create the EntitySpecifics proto for a synced notification."""
@@ -1244,6 +1246,66 @@ class SyncDataModel(object):
hash_input = serialized_type.SerializeToString() + key
return base64.b64encode(hashlib.sha1(hash_input).digest())
+ def AddSyncedNotificationAppInfo(self, app_info):
+ """Adds an app info struct to the server data.
+
+ The notification will be delivered to the client on the next GetUpdates
+ call.
+
+ Args:
+ app_info: A serialized AppInfo.
+
+ Returns:
+ The string representation of the added SyncEntity.
+
+ Raises:
+ ClientNotConnectedError: if the client has not yet connected to this
+ server
+ """
+ specifics = self._CreateSyncedNotificationAppInfoEntitySpecifics(app_info)
+
+ # Create the root SyncEntity representing a single app info protobuf.
+ entity = sync_pb2.SyncEntity()
+ entity.specifics.CopyFrom(specifics)
+ entity.parent_id_string = self._ServerTagToId(
+ 'google_chrome_synced_notification_app_info')
+ entity.name = 'App info added for testing'
+ entity.version = self._GetNextVersionNumber()
+
+ # App Infos do not have a strong id, it only needs to be unique.
+ entity.client_defined_unique_tag = "foo"
+ entity.id_string = "foo"
+
+ self._entries[entity.id_string] = copy.deepcopy(entity)
+
+ print "entity before exit is ", entity
+
+ return google.protobuf.text_format.MessageToString(entity)
+
+ def _CreateSyncedNotificationAppInfoEntitySpecifics(
+ self, synced_notification_app_info):
+ """Create the EntitySpecifics proto for a synced notification app info."""
+ # Create a single, empty app_info object
+ app_info = \
+ synced_notification_app_info_specifics_pb2.SyncedNotificationAppInfo()
+ # Fill the app_info object from the text format protobuf.
+ google.protobuf.text_format.Merge(synced_notification_app_info, app_info)
+
+ # Create a new specifics object with a contained app_info
+ specifics = sync_pb2.EntitySpecifics()
+ app_info_specifics = \
+ synced_notification_app_info_specifics_pb2.\
+ SyncedNotificationAppInfoSpecifics()
+
+ # Copy the app info from the text format protobuf
+ contained_app_info = app_info_specifics.synced_notification_app_info.add()
+ contained_app_info.CopyFrom(app_info)
+
+ # And put the new app_info_specifics into the specifics before returning.
+ specifics.synced_notification_app_info.CopyFrom(app_info_specifics)
+
+ return specifics
+
class TestServer(object):
"""An object to handle requests for one (and only one) Chrome Sync account.
diff --git a/sync/tools/testserver/sync_testserver.py b/sync/tools/testserver/sync_testserver.py
index 5954e01..66789ea 100755
--- a/sync/tools/testserver/sync_testserver.py
+++ b/sync/tools/testserver/sync_testserver.py
@@ -156,6 +156,8 @@ class SyncPageHandler(testserver_base.BasePageHandler):
self.GaiaSetOAuth2TokenResponseHandler,
self.TriggerSyncedNotificationHandler,
self.SyncedNotificationsPageHandler,
+ self.TriggerSyncedNotificationAppInfoHandler,
+ self.SyncedNotificationsAppInfoPageHandler,
self.CustomizeClientCommandHandler]
post_handlers = [self.ChromiumSyncCommandHandler,
@@ -532,6 +534,37 @@ class SyncPageHandler(testserver_base.BasePageHandler):
self.wfile.write(reply)
return True
+ def TriggerSyncedNotificationAppInfoHandler(self):
+ test_name = "/triggersyncednotificationappinfo"
+ if not self._ShouldHandleRequest(test_name):
+ return False
+
+ query = urlparse.urlparse(self.path)[4]
+ query_params = urlparse.parse_qs(query)
+
+ app_info = ''
+
+ if 'synced_notification_app_info' in query_params:
+ app_info = query_params['synced_notification_app_info'][0]
+
+ try:
+ app_info_string = self.server._sync_handler.account \
+ .AddSyncedNotificationAppInfo(app_info)
+ reply = "A synced notification app info was sent:\n\n"
+ reply += "<code>{}</code>.".format(app_info_string)
+ response_code = 200
+ except chromiumsync.ClientNotConnectedError:
+ reply = ('The client is not connected to the server, so the app info'
+ ' could not be created.')
+ response_code = 400
+
+ self.send_response(response_code)
+ self.send_header('Content-Type', 'text/html')
+ self.send_header('Content-Length', len(reply))
+ self.end_headers()
+ self.wfile.write(reply)
+ return True
+
def CustomizeClientCommandHandler(self):
test_name = "/customizeclientcommand"
if not self._ShouldHandleRequest(test_name):
@@ -576,6 +609,21 @@ class SyncPageHandler(testserver_base.BasePageHandler):
self.wfile.write(html)
return True
+ def SyncedNotificationsAppInfoPageHandler(self):
+ test_name = "/syncednotificationsappinfo"
+ if not self._ShouldHandleRequest(test_name):
+ return False
+
+ html = \
+ open('sync/tools/testserver/synced_notification_app_info.html', 'r').\
+ read()
+
+ self.send_response(200)
+ self.send_header('Content-Type', 'text/html')
+ self.send_header('Content-Length', len(html))
+ self.end_headers()
+ self.wfile.write(html)
+ return True
class SyncServerRunner(testserver_base.TestServerRunner):
"""TestServerRunner for the net test servers."""
diff --git a/sync/tools/testserver/synced_notifications.html b/sync/tools/testserver/synced_notifications.html
index c06f80b..10cac30 100644
--- a/sync/tools/testserver/synced_notifications.html
+++ b/sync/tools/testserver/synced_notifications.html
@@ -47,5 +47,23 @@
' }\n' +
'}');
</script>
+ <br/>
+ <script type="text/javascript">
+ appendNotificationLink('New Service notification',
+ 'key: \"foo\"\n' +
+ 'app_id: \"maps_street_view\"\n' +
+ 'priority: 2\n' +
+ 'read_state: 1\n' +
+ 'render_info {\n' +
+ ' collapsed_info {\n' +
+ ' creation_timestamp_usec: 42\n' +
+ ' simple_collapsed_layout {\n' +
+ ' annotation: \"787 6th Street South\"\n' +
+ ' description: \"Building B\"\n' +
+ ' heading: \"Google Kirkland\"\n' +
+ ' }\n' +
+ ' }\n' +
+ '}');
+ </script>
</body>
</html>
diff --git a/sync/tools/testserver/synced_notifications_app_info.html b/sync/tools/testserver/synced_notifications_app_info.html
new file mode 100644
index 0000000..42cbd12
--- /dev/null
+++ b/sync/tools/testserver/synced_notifications_app_info.html
@@ -0,0 +1,49 @@
+<html>
+ <head>
+ <title>Synced notification App Info</title>
+
+ <script type="text/javascript">
+ // Creates link (appended to the bottom of the page body) to trigger a
+ // new synced notification app info. The link's title will be |title|
+ // and the ASCII-serialized app info will be
+ // |synced_notification_app_info|.
+ function appendSyncedNotificationAppInfoLink(title, app_info) {
+ var link = document.createElement('a');
+ link.innerHTML = title;
+ link.setAttribute('target', '_blank');
+ link.setAttribute('href', 'triggersyncednotificationappinfo?' +
+ 'synced_notification_app_info=' +
+ encodeURIComponent(app_info));
+ document.body.appendChild(link);
+ }
+ </script>
+ </head>
+
+ <body>
+ <h1>Synced Notification App Info</h1>
+
+ <h2>Step 0: Sign in to the browser and set up Sync</h2>
+
+ <h2>Step 1: Click this link (only required once per server lifetime)</h2>
+
+ <a href="/customizeclientcommand?sessions_commit_delay_seconds=0">
+ Make synced notification app info triggering instant</a>
+
+ <h2>Step 2: Ctrl-Click the link below to send a synced notification app info</h2>
+
+ <script type="text/javascript">
+ // JSON version of an app info protobuf
+ appendSyncedNotificationAppInfoLink(
+ 'Simple SyncedNotificationAppInfo',
+ 'settings_display_name: \"Google Maps\"\n' +
+ 'icon: {\n' +
+ ' alt_text: \"Google Maps\"\n' +
+ ' preferred_height: 80\n' +
+ ' preferred_width: 80\n' +
+ ' url: \"https://ssl.gstatic.com/s2/oz/images/notifications/app_icons/system-gplus_62d72f2ec5e1ef193f0dfa600eabcfeb.png\"\n' +
+ '}\n' +
+ 'app_id: \"maps_street_view\"\n' +
+ 'app_id: \"maps_earth_view\"\n');
+ </script>
+ </body>
+</html>