OLD | NEW |
| (Empty) |
1 # Copyright (c) 2012 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 os | |
5 import re | |
6 import StringIO | |
7 | |
8 from telemetry import tab_test_case | |
9 from telemetry import util | |
10 | |
11 class TabConsoleTest(tab_test_case.TabTestCase): | |
12 def testConsoleOutputStream(self): | |
13 unittest_data_dir = os.path.join(os.path.dirname(__file__), | |
14 '..', 'unittest_data') | |
15 self._browser.SetHTTPServerDirectory(unittest_data_dir) | |
16 | |
17 stream = StringIO.StringIO() | |
18 self._tab.message_output_stream = stream | |
19 | |
20 self._tab.Navigate( | |
21 self._browser.http_server.UrlOf('page_that_logs_to_console.html')) | |
22 self._tab.WaitForDocumentReadyStateToBeComplete() | |
23 | |
24 initial = self._tab.EvaluateJavaScript('window.__logCount') | |
25 def GotLog(): | |
26 current = self._tab.EvaluateJavaScript('window.__logCount') | |
27 return current > initial | |
28 util.WaitFor(GotLog, 5) | |
29 | |
30 lines = [l for l in stream.getvalue().split('\n') if len(l)] | |
31 | |
32 self.assertTrue(len(lines) >= 1) | |
33 for l in lines: | |
34 u_l = 'http://localhost:(\d+)/page_that_logs_to_console.html:9' | |
35 self.assertTrue(re.match('At %s: Hello, world' % u_l, l)) | |
36 | |
OLD | NEW |