Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: net/tools/testserver/testserver.py

Issue 7753023: [Sync] Add tests for migration triggered by notifications (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/test/live_sync/migration_errors_test.cc ('k') | net/tools/testserver/xmppserver.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python2.4 1 #!/usr/bin/python2.4
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """This is a simple HTTP/FTP/SYNC/TCP/UDP/ server used for testing Chrome. 6 """This is a simple HTTP/FTP/SYNC/TCP/UDP/ server used for testing Chrome.
7 7
8 It supports several test URLs, as specified by the handlers in TestPageHandler. 8 It supports several test URLs, as specified by the handlers in TestPageHandler.
9 By default, it listens on an ephemeral port and sends the port number back to 9 By default, it listens on an ephemeral port and sends the port number back to
10 the originating process over a pipe. The originating process can specify an 10 the originating process over a pipe. The originating process can specify an
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 # unless strictly necessary. 126 # unless strictly necessary.
127 import chromiumsync 127 import chromiumsync
128 import xmppserver 128 import xmppserver
129 StoppableHTTPServer.__init__(self, server_address, request_handler_class) 129 StoppableHTTPServer.__init__(self, server_address, request_handler_class)
130 self._sync_handler = chromiumsync.TestServer() 130 self._sync_handler = chromiumsync.TestServer()
131 self._xmpp_socket_map = {} 131 self._xmpp_socket_map = {}
132 self._xmpp_server = xmppserver.XmppServer( 132 self._xmpp_server = xmppserver.XmppServer(
133 self._xmpp_socket_map, ('localhost', 0)) 133 self._xmpp_socket_map, ('localhost', 0))
134 self.xmpp_port = self._xmpp_server.getsockname()[1] 134 self.xmpp_port = self._xmpp_server.getsockname()[1]
135 135
136 def GetXmppServer(self):
137 return self._xmpp_server
138
136 def HandleCommand(self, query, raw_request): 139 def HandleCommand(self, query, raw_request):
137 return self._sync_handler.HandleCommand(query, raw_request) 140 return self._sync_handler.HandleCommand(query, raw_request)
138 141
139 def HandleRequestNoBlock(self): 142 def HandleRequestNoBlock(self):
140 """Handles a single request. 143 """Handles a single request.
141 144
142 Copied from SocketServer._handle_request_noblock(). 145 Copied from SocketServer._handle_request_noblock().
143 """ 146 """
144 try: 147 try:
145 request, client_address = self.get_request() 148 request, client_address = self.get_request()
(...skipping 1253 matching lines...) Expand 10 before | Expand all | Expand 10 after
1399 self.wfile.write(chunk) 1402 self.wfile.write(chunk)
1400 self.wfile.write('\r\n') 1403 self.wfile.write('\r\n')
1401 1404
1402 1405
1403 class SyncPageHandler(BasePageHandler): 1406 class SyncPageHandler(BasePageHandler):
1404 """Handler for the main HTTP sync server.""" 1407 """Handler for the main HTTP sync server."""
1405 1408
1406 def __init__(self, request, client_address, sync_http_server): 1409 def __init__(self, request, client_address, sync_http_server):
1407 get_handlers = [self.ChromiumSyncMigrationOpHandler, 1410 get_handlers = [self.ChromiumSyncMigrationOpHandler,
1408 self.ChromiumSyncTimeHandler, 1411 self.ChromiumSyncTimeHandler,
1412 self.ChromiumSyncDisableNotificationsOpHandler,
1413 self.ChromiumSyncEnableNotificationsOpHandler,
1414 self.ChromiumSyncSendNotificationOpHandler,
1409 self.ChromiumSyncBirthdayErrorOpHandler, 1415 self.ChromiumSyncBirthdayErrorOpHandler,
1410 self.ChromiumSyncTransientErrorOpHandler, 1416 self.ChromiumSyncTransientErrorOpHandler,
1411 self.ChromiumSyncSyncTabsOpHandler] 1417 self.ChromiumSyncSyncTabsOpHandler]
1412 1418
1413 post_handlers = [self.ChromiumSyncCommandHandler, 1419 post_handlers = [self.ChromiumSyncCommandHandler,
1414 self.ChromiumSyncTimeHandler] 1420 self.ChromiumSyncTimeHandler]
1415 BasePageHandler.__init__(self, request, client_address, 1421 BasePageHandler.__init__(self, request, client_address,
1416 sync_http_server, [], get_handlers, 1422 sync_http_server, [], get_handlers,
1417 post_handlers, []) 1423 post_handlers, [])
1418 1424
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1450 raw_request = self.rfile.read(length) 1456 raw_request = self.rfile.read(length)
1451 1457
1452 http_response, raw_reply = self.server.HandleCommand( 1458 http_response, raw_reply = self.server.HandleCommand(
1453 self.path, raw_request) 1459 self.path, raw_request)
1454 self.send_response(http_response) 1460 self.send_response(http_response)
1455 self.end_headers() 1461 self.end_headers()
1456 self.wfile.write(raw_reply) 1462 self.wfile.write(raw_reply)
1457 return True 1463 return True
1458 1464
1459 def ChromiumSyncMigrationOpHandler(self): 1465 def ChromiumSyncMigrationOpHandler(self):
1460 """Handle a chromiumsync test-op command arriving via http.
1461 """
1462 test_name = "/chromiumsync/migrate" 1466 test_name = "/chromiumsync/migrate"
1463 if not self._ShouldHandleRequest(test_name): 1467 if not self._ShouldHandleRequest(test_name):
1464 return False 1468 return False
1465 1469
1466 http_response, raw_reply = self.server._sync_handler.HandleMigrate( 1470 http_response, raw_reply = self.server._sync_handler.HandleMigrate(
1467 self.path) 1471 self.path)
1468 self.send_response(http_response) 1472 self.send_response(http_response)
1469 self.send_header('Content-Type', 'text/html') 1473 self.send_header('Content-Type', 'text/html')
1470 self.send_header('Content-Length', len(raw_reply)) 1474 self.send_header('Content-Length', len(raw_reply))
1471 self.end_headers() 1475 self.end_headers()
1472 self.wfile.write(raw_reply) 1476 self.wfile.write(raw_reply)
1473 return True 1477 return True
1474 1478
1479 def ChromiumSyncDisableNotificationsOpHandler(self):
1480 test_name = "/chromiumsync/disablenotifications"
1481 if not self._ShouldHandleRequest(test_name):
1482 return False
1483 self.server.GetXmppServer().DisableNotifications()
1484 result = 200
1485 raw_reply = ('<html><title>Notifications disabled</title>'
1486 '<H1>Notifications disabled</H1></html>')
1487 self.send_response(result)
1488 self.send_header('Content-Type', 'text/html')
1489 self.send_header('Content-Length', len(raw_reply))
1490 self.end_headers()
1491 self.wfile.write(raw_reply)
1492 return True;
1493
1494 def ChromiumSyncEnableNotificationsOpHandler(self):
1495 test_name = "/chromiumsync/enablenotifications"
1496 if not self._ShouldHandleRequest(test_name):
1497 return False
1498 self.server.GetXmppServer().EnableNotifications()
1499 result = 200
1500 raw_reply = ('<html><title>Notifications enabled</title>'
1501 '<H1>Notifications enabled</H1></html>')
1502 self.send_response(result)
1503 self.send_header('Content-Type', 'text/html')
1504 self.send_header('Content-Length', len(raw_reply))
1505 self.end_headers()
1506 self.wfile.write(raw_reply)
1507 return True;
1508
1509 def ChromiumSyncSendNotificationOpHandler(self):
1510 test_name = "/chromiumsync/sendnotification"
1511 if not self._ShouldHandleRequest(test_name):
1512 return False
1513 query = urlparse.urlparse(self.path)[4]
1514 query_params = urlparse.parse_qs(query)
1515 channel = ''
1516 data = ''
1517 if 'channel' in query_params:
1518 channel = query_params['channel'][0]
1519 if 'data' in query_params:
1520 data = query_params['data'][0]
1521 self.server.GetXmppServer().SendNotification(channel, data)
1522 result = 200
1523 raw_reply = ('<html><title>Notification sent</title>'
1524 '<H1>Notification sent with channel "%s" '
1525 'and data "%s"</H1></html>'
1526 % (channel, data))
1527 self.send_response(result)
1528 self.send_header('Content-Type', 'text/html')
1529 self.send_header('Content-Length', len(raw_reply))
1530 self.end_headers()
1531 self.wfile.write(raw_reply)
1532 return True;
1533
1475 def ChromiumSyncBirthdayErrorOpHandler(self): 1534 def ChromiumSyncBirthdayErrorOpHandler(self):
1476 test_name = "/chromiumsync/birthdayerror" 1535 test_name = "/chromiumsync/birthdayerror"
1477 if not self._ShouldHandleRequest(test_name): 1536 if not self._ShouldHandleRequest(test_name):
1478 return False 1537 return False
1479 result, raw_reply = self.server._sync_handler.HandleCreateBirthdayError() 1538 result, raw_reply = self.server._sync_handler.HandleCreateBirthdayError()
1480 self.send_response(result) 1539 self.send_response(result)
1481 self.send_header('Content-Type', 'text/html') 1540 self.send_header('Content-Type', 'text/html')
1482 self.send_header('Content-Length', len(raw_reply)) 1541 self.send_header('Content-Length', len(raw_reply))
1483 self.end_headers() 1542 self.end_headers()
1484 self.wfile.write(raw_reply) 1543 self.wfile.write(raw_reply)
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
1766 'random key if none is specified on the command ' 1825 'random key if none is specified on the command '
1767 'line.') 1826 'line.')
1768 option_parser.add_option('', '--policy-user', default='user@example.com', 1827 option_parser.add_option('', '--policy-user', default='user@example.com',
1769 dest='policy_user', 1828 dest='policy_user',
1770 help='Specify the user name the server should ' 1829 help='Specify the user name the server should '
1771 'report back to the client as the user owning the ' 1830 'report back to the client as the user owning the '
1772 'token used for making the policy request.') 1831 'token used for making the policy request.')
1773 options, args = option_parser.parse_args() 1832 options, args = option_parser.parse_args()
1774 1833
1775 sys.exit(main(options, args)) 1834 sys.exit(main(options, args))
OLDNEW
« no previous file with comments | « chrome/test/live_sync/migration_errors_test.cc ('k') | net/tools/testserver/xmppserver.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698