<commit_before># Copyright 2015 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.

from telemetry import decorators
from telemetry.testing import tab_test_case
from telemetry.timeline import tracing_category_filter
from telemetry.timeline import tracing_options

class TracingControllerTest(tab_test_case.TabTestCase):

  @decorators.Isolated
  def testModifiedConsoleTime(self):
    category_filter = tracing_category_filter.TracingCategoryFilter()
    options = tracing_options.TracingOptions()
    options.enable_chrome_trace = True
    self._tab.browser.platform.tracing_controller.Start(options,
                                                        category_filter)
    self.Navigate('blank.html')
    self.assertEquals(
        self._tab.EvaluateJavaScript('document.location.pathname;'),
        '/blank.html')
    self._tab.EvaluateJavaScript('console.time = function() { };')
    with self.assertRaisesRegexp(Exception, 'Page stomped on console.time'):
      self._tab.browser.platform.tracing_controller.Stop()
<commit_msg>[telemetry] Restore console.time at the end of TracingControllerTest.testModifiedConsoleTime<commit_after># Copyright 2015 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.

from telemetry import decorators
from telemetry.testing import tab_test_case
from telemetry.timeline import tracing_category_filter
from telemetry.timeline import tracing_options

class TracingControllerTest(tab_test_case.TabTestCase):

  @decorators.Isolated
  def testModifiedConsoleTime(self):
    tracing_controller = self._tab.browser.platform.tracing_controller
    category_filter = tracing_category_filter.TracingCategoryFilter()
    options = tracing_options.TracingOptions()
    options.enable_chrome_trace = True
    tracing_controller.Start(options, category_filter)
    self.Navigate('blank.html')
    self.assertEquals(
        self._tab.EvaluateJavaScript('document.location.pathname;'),
        '/blank.html')

    self._tab.EvaluateJavaScript("""
        window.__console_time = console.time;
        console.time = function() { };
        """)
    with self.assertRaisesRegexp(Exception, 'Page stomped on console.time'):
      tracing_controller.Stop()

    # Restore console.time and stop tracing so that any subsequent tests will
    # be able to use tracing normally. See crbug.com/520663.
    self._tab.EvaluateJavaScript("""
        console.time = window.__console_time;
        delete window.__console_time;
        """)
    tracing_controller.Stop()

    # Check that subsequent tests will be able to use tracing normally.
    self.assertFalse(tracing_controller.is_tracing_running)
    tracing_controller.Start(options, category_filter)
    self.assertTrue(tracing_controller.is_tracing_running)
    tracing_controller.Stop()
    self.assertFalse(tracing_controller.is_tracing_running)

{'fraction_non_alphanumeric': 0.07901726427622842, 'fraction_numerical': 0.004648074369189907, 'mean_word_length': 4.159246575342466, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5324122', 'n_tokens_mistral': 818, 'n_tokens_neox': 792, 'n_words': 194}