summaryrefslogtreecommitdiffstats
path: root/net/tools
diff options
context:
space:
mode:
authorlipalani@chromium.org <lipalani@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-22 23:14:08 +0000
committerlipalani@chromium.org <lipalani@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-22 23:14:08 +0000
commit10059eb371a361c7648d6708c67496bb0c1f0d37 (patch)
tree0816b222566530f846d672a3b753f5b64992ee33 /net/tools
parent7b013fc11ea01577388793d5ddf71ef00151c59f (diff)
downloadchromium_src-10059eb371a361c7648d6708c67496bb0c1f0d37.zip
chromium_src-10059eb371a361c7648d6708c67496bb0c1f0d37.tar.gz
chromium_src-10059eb371a361c7648d6708c67496bb0c1f0d37.tar.bz2
Python server to test the actionable error feature.
BUG=94007,70276 TEST= Review URL: http://codereview.chromium.org/7811026 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@102392 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/tools')
-rwxr-xr-xnet/tools/testserver/chromiumsync.py63
-rwxr-xr-xnet/tools/testserver/testserver.py16
2 files changed, 78 insertions, 1 deletions
diff --git a/net/tools/testserver/chromiumsync.py b/net/tools/testserver/chromiumsync.py
index e1c049c..96ee7db 100755
--- a/net/tools/testserver/chromiumsync.py
+++ b/net/tools/testserver/chromiumsync.py
@@ -108,6 +108,10 @@ class TransientError(Error):
"""The client would be sent a transient error."""
+class SyncInducedError(Error):
+ """The client would be sent an error."""
+
+
def GetEntryType(entry):
"""Extract the sync type from a SyncEntry.
@@ -421,6 +425,8 @@ class SyncDataModel(object):
self.migration_history = MigrationHistory()
+ self.induced_error = sync_pb2.ClientToServerResponse.Error()
+
def _SaveEntry(self, entry):
"""Insert or update an entry in the change log, and give it a new version.
@@ -886,6 +892,12 @@ class SyncDataModel(object):
True)
self._SaveEntry(nigori_new)
+ def SetInducedError(self, error):
+ self.induced_error = error
+
+ def GetInducedError(self):
+ return self.induced_error
+
class TestServer(object):
"""An object to handle requests for one (and only one) Chrome Sync account.
@@ -928,6 +940,12 @@ class TestServer(object):
if self.transient_error:
raise TransientError
+ def CheckSendError(self):
+ """Raises SyncInducedError if needed."""
+ if (self.account.induced_error.error_type !=
+ sync_pb2.ClientToServerResponse.UNKNOWN):
+ raise SyncInducedError
+
def HandleMigrate(self, path):
query = urlparse.urlparse(path)[4]
code = 200
@@ -950,6 +968,39 @@ class TestServer(object):
return (code, '<html><title>Migration: %d</title><H1>%d %s</H1></html>' %
(code, code, response))
+ def HandleSetInducedError(self, path):
+ query = urlparse.urlparse(path)[4]
+ self.account_lock.acquire()
+ code = 200;
+ response = 'Success'
+ error = sync_pb2.ClientToServerResponse.Error()
+ try:
+ error_type = urlparse.parse_qs(query)['error']
+ action = urlparse.parse_qs(query)['action']
+ error.error_type = int(error_type[0])
+ error.action = int(action[0])
+ try:
+ error.url = (urlparse.parse_qs(query)['url'])[0]
+ except KeyError:
+ error.url = ''
+ try:
+ error.error_description =(
+ (urlparse.parse_qs(query)['error_description'])[0])
+ except KeyError:
+ error.error_description = ''
+ self.account.SetInducedError(error)
+ response = ('Error = %d, action = %d, url = %s, description = %s' %
+ (error.error_type, error.action,
+ error.url,
+ error.error_description))
+ except error:
+ response = 'Could not parse url'
+ code = 400
+ finally:
+ self.account_lock.release()
+ return (code, '<html><title>SetError: %d</title><H1>%d %s</H1></html>' %
+ (code, code, response))
+
def HandleCreateBirthdayError(self):
self.account.ResetStoreBirthday()
return (
@@ -998,6 +1049,7 @@ class TestServer(object):
self.CheckStoreBirthday(request)
response.store_birthday = self.account.store_birthday
self.CheckTransientError();
+ self.CheckSendError();
print_context('->')
@@ -1036,11 +1088,22 @@ class TestServer(object):
response.error_code = sync_pb2.ClientToServerResponse.NOT_MY_BIRTHDAY
return (200, response.SerializeToString())
except TransientError, error:
+ ### This is deprecated now. Would be removed once test cases are removed.
print_context('<-')
print 'TRANSIENT_ERROR'
response.store_birthday = self.account.store_birthday
response.error_code = sync_pb2.ClientToServerResponse.TRANSIENT_ERROR
return (200, response.SerializeToString())
+ except SyncInducedError, error:
+ print_context('<-')
+ print 'INDUCED_ERROR'
+ response.store_birthday = self.account.store_birthday
+ error = self.account.GetInducedError()
+ response.error.error_type = error.error_type
+ response.error.url = error.url
+ response.error.error_description = error.error_description
+ response.error.action = error.action
+ return (200, response.SerializeToString())
finally:
self.account_lock.release()
diff --git a/net/tools/testserver/testserver.py b/net/tools/testserver/testserver.py
index cc66ffd..7affa1f 100755
--- a/net/tools/testserver/testserver.py
+++ b/net/tools/testserver/testserver.py
@@ -1414,7 +1414,8 @@ class SyncPageHandler(BasePageHandler):
self.ChromiumSyncSendNotificationOpHandler,
self.ChromiumSyncBirthdayErrorOpHandler,
self.ChromiumSyncTransientErrorOpHandler,
- self.ChromiumSyncSyncTabsOpHandler]
+ self.ChromiumSyncSyncTabsOpHandler,
+ self.ChromiumSyncErrorOpHandler]
post_handlers = [self.ChromiumSyncCommandHandler,
self.ChromiumSyncTimeHandler]
@@ -1555,6 +1556,19 @@ class SyncPageHandler(BasePageHandler):
self.wfile.write(raw_reply)
return True;
+ def ChromiumSyncErrorOpHandler(self):
+ test_name = "/chromiumsync/error"
+ if not self._ShouldHandleRequest(test_name):
+ return False
+ result, raw_reply = self.server._sync_handler.HandleSetInducedError(
+ self.path)
+ self.send_response(result)
+ self.send_header('Content-Type', 'text/html')
+ self.send_header('Content-Length', len(raw_reply))
+ self.end_headers()
+ self.wfile.write(raw_reply)
+ return True;
+
def ChromiumSyncSyncTabsOpHandler(self):
test_name = "/chromiumsync/synctabs"
if not self._ShouldHandleRequest(test_name):