- add sources.
[platform/framework/web/crosswalk.git] / src / tools / telemetry / telemetry / core / backends / chrome / inspector_console_unittest.py
1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4 import re
5 import StringIO
6
7 from telemetry.core import util
8 from telemetry.unittest import tab_test_case
9
10 class TabConsoleTest(tab_test_case.TabTestCase):
11   def testConsoleOutputStream(self):
12     self._browser.SetHTTPServerDirectories(util.GetUnittestDataDir())
13
14     stream = StringIO.StringIO()
15     self._tab.message_output_stream = stream
16
17     self._tab.Navigate(
18       self._browser.http_server.UrlOf('page_that_logs_to_console.html'))
19     self._tab.WaitForDocumentReadyStateToBeComplete()
20
21     initial = self._tab.EvaluateJavaScript('window.__logCount')
22     def GotLog():
23       current = self._tab.EvaluateJavaScript('window.__logCount')
24       return current > initial
25     util.WaitFor(GotLog, 5)
26
27     lines = [l for l in stream.getvalue().split('\n') if len(l)]
28
29     self.assertTrue(len(lines) >= 1)
30     for line in lines:
31       prefix = 'http://(.+)/page_that_logs_to_console.html:9'
32       expected_line = 'At %s: Hello, world' % prefix
33       self.assertTrue(re.match(expected_line, line))
34