| Index: telemetry/telemetry/internal/backends/chrome_inspector/inspector_console.py
|
| diff --git a/telemetry/telemetry/internal/backends/chrome_inspector/inspector_console.py b/telemetry/telemetry/internal/backends/chrome_inspector/inspector_console.py
|
| index b4a7ba60a35c337224472ae5382754167ce8aac9..0d7b5e536da08cba46eef6851687d8d511752758 100644
|
| --- a/telemetry/telemetry/internal/backends/chrome_inspector/inspector_console.py
|
| +++ b/telemetry/telemetry/internal/backends/chrome_inspector/inspector_console.py
|
| @@ -1,6 +1,9 @@
|
| # Copyright 2013 The Chromium Authors. All rights reserved.
|
| # Use of this source code is governed by a BSD-style license that can be
|
| # found in the LICENSE file.
|
| +import StringIO
|
| +
|
| +from telemetry.internal.backends.chrome_inspector import websocket
|
|
|
|
|
| class InspectorConsole(object):
|
| @@ -13,40 +16,38 @@ class InspectorConsole(object):
|
|
|
| def _OnNotification(self, msg):
|
| if msg['method'] == 'Console.messageAdded':
|
| + assert self._message_output_stream
|
| if msg['params']['message']['url'] == 'chrome://newtab/':
|
| return
|
| - self._last_message = 'At %s:%i: %s' % (
|
| + self._last_message = '(%s) %s:%i: %s' % (
|
| + msg['params']['message']['level'],
|
| msg['params']['message']['url'],
|
| msg['params']['message']['line'],
|
| msg['params']['message']['text'])
|
| - if self._message_output_stream:
|
| - self._message_output_stream.write(
|
| - '%s\n' % self._last_message)
|
| + self._message_output_stream.write(
|
| + '%s\n' % self._last_message)
|
|
|
| elif msg['method'] == 'Console.messageRepeatCountUpdated':
|
| if self._message_output_stream:
|
| self._message_output_stream.write(
|
| '%s\n' % self._last_message)
|
|
|
| - @property
|
| - def message_output_stream(self): # pylint: disable=method-hidden
|
| - return self._message_output_stream
|
| -
|
| - @message_output_stream.setter
|
| - def message_output_stream(self, stream): # pylint: disable=method-hidden
|
| - self._message_output_stream = stream
|
| - self._UpdateConsoleEnabledState()
|
| -
|
| - def _UpdateConsoleEnabledState(self):
|
| - enabled = self._message_output_stream != None
|
| - if enabled == self._console_enabled:
|
| - return
|
| -
|
| - if enabled:
|
| - method_name = 'enable'
|
| - else:
|
| - method_name = 'disable'
|
| - self._inspector_websocket.SyncRequest({
|
| - 'method': 'Console.%s' % method_name
|
| - })
|
| - self._console_enabled = enabled
|
| + def GetCurrentConsoleOutputBuffer(self, timeout=10):
|
| + self._message_output_stream = StringIO.StringIO()
|
| + self._EnableConsoleOutputStream()
|
| + try:
|
| + self._inspector_websocket.DispatchNotifications(timeout)
|
| + return self._message_output_stream.getvalue()
|
| + except websocket.WebSocketTimeoutException:
|
| + return self._message_output_stream.getvalue()
|
| + finally:
|
| + self._DisableConsoleOutputStream()
|
| + self._message_output_stream.close()
|
| + self._message_output_stream = None
|
| +
|
| +
|
| + def _EnableConsoleOutputStream(self):
|
| + self._inspector_websocket.SyncRequest({'method': 'Console.enable'})
|
| +
|
| + def _DisableConsoleOutputStream(self):
|
| + self._inspector_websocket.SyncRequest({'method': 'Console.disable'})
|
|
|