2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
11 class RPCListener(object):
13 def __init__(self, shutdown_callback):
14 self.shutdown_callback = shutdown_callback
16 self.ever_failed = False
17 self.start_time = time.time()
19 def Log(self, message):
20 # Display the number of milliseconds since startup.
21 # This gives us additional data for debugging bot behavior.
22 prefix = '[%6s ms] ' % int((time.time()-self.start_time)*1000) + self.prefix
23 lines = [line.rstrip() for line in message.split('\n')]
24 text = ''.join(['%s%s\n' % (prefix, line) for line in lines])
25 sys.stdout.write(text)
27 def TestLog(self, message):
31 # Something went very wrong on the server side, everything is horked?
32 # Only called locally.
33 def ServerError(self, message):
34 self.Log('\n[SERVER_ERROR] %s' % (message,))
35 self.ever_failed = True
39 # Does nothing. Called to prevent timeouts. (The server resets the timeout
40 # every time it receives a GET request.)
44 # This happens automatically, as long as the renderer process has not crashed.
45 def JavaScriptIsAlive(self):
48 def Shutdown(self, message, passed):
50 # This check looks slightly backwards, but this is intentional.
51 # Everything but passed.lower() == 'true' is considered a failure. This
52 # means that if the test runner sends garbage, it will be a failure.
53 # NOTE in interactive mode this function may be called multiple times.
54 # ever_failed is designed to be set and never reset - if any of the runs
55 # fail, the an error code will be returned to the command line.
56 # In summary, the tester is biased towards failure - it should scream "FAIL"
57 # if things are not 100% correct. False positives must be avoided.
58 if passed.lower() != 'true':
59 self.ever_failed = True
60 close_browser = self._TestingDone()
66 def _TestingDone(self):
67 return self.shutdown_callback()