<commit_before>#!/usr/bin/python
# Copyright (c) 2012 The Native Client 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 re

import pyauto_nacl  # Must be imported before pyauto
import pyauto
import nacl_utils
import os
import sys


# Keep in sync with plugin_error.h
ERROR_SUCCESS = 0
ERROR_SEL_LDR_START_STATUS = 27

# Keep in sync with nacl_error_code.h
LOAD_OK = 0
LOAD_VALIDATION_FAILED = 57


class NaClUMATest(pyauto.PyUITest):
  """Tests for the UMA stats NaCl records."""

  # Surf to about:histograms and scrape the UMA data.
  def getHistogramData(self, path):
    js = """\
var results = document.getElementsByTagName('pre');
var text = '';
for (var i = 0; i < results.length; ++i) {
  text = text + results[i].innerHTML + '\\n';
}
window.domAutomationController.send(text);
"""
    self.NavigateToURL('about:histograms/%s' % path)
    data = self.ExecuteJavascript(js, 0, 0)
    return data.replace('<br>', '\n');

  # Turn scraped UMA data into a 2-level dictionary.
  # Histogram name -> histogram bucket -> count
  def parseHistogramData(self, data):
    spacer_pattern = re.compile('\d+\s+\.\.\.')
    data_pattern = re.compile('(\d+)\s*-*O\s*\(\s*(\d+)')

    hists = {}
    name = None
    for line in data.strip().split('\n'):
      line = line.strip()
      if line == '':
        continue

      if line.startswith('Histogram: '):
        # Start a new histogram<commit_msg>Update nacl_uma test to work with new chrome://histograms semantics.<commit_after>#!/usr/bin/python
# Copyright (c) 2012 The Native Client 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 re

import pyauto_nacl  # Must be imported before pyauto
import pyauto
import nacl_utils
import os
import sys


# Keep in sync with plugin_error.h
ERROR_SUCCESS = 0
ERROR_SEL_LDR_START_STATUS = 27

# Keep in sync with nacl_error_code.h
LOAD_OK = 0
LOAD_VALIDATION_FAILED = 57


class NaClUMATest(pyauto.PyUITest):
  """Tests for the UMA stats NaCl records."""

  # Surf to about:histograms and scrape the UMA data.
  def getHistogramData(self, path):
    js = """\
var results = document.getElementsByTagName('pre');
var text = '';
for (var i = 0; i < results.length; ++i) {
  text = text + results[i].innerHTML + '\\n';
}
window.domAutomationController.send(text);
"""
    self.NavigateToURL('about:histograms/%s' % path)
    # about:histograms is now "as of last page load", so reload it to get the
    # newest histograms.
    self.NavigateToURL('about:histograms/%s' % path)
    data = self.ExecuteJavascript(js, 0, 0)
    return data.replace('<br>', '\n');

  # Turn scraped UMA data into a 2-level dictionary.
  # Histogram name -> histogram bucket -> count
  def parseHistogramData(self, data):
    spacer_pattern = re.compile('\d+\s+\.\.\.')
    data_pattern = re.compile('(\d+)\s*-*O\s*\(\s*(\d+)')

    hists = {}
    name = None
    for line in data.strip().split('\n'):
      line = line.strip()
      if line == '':
        continue

      if line.startswith('Histogram: '):
        # Start a new histogram
{'fraction_non_alphanumeric': 0.13186813186813187, 'fraction_numerical': 0.008791208791208791, 'mean_word_length': 3.425, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7294698', 'n_tokens_mistral': 1095, 'n_tokens_neox': 1029, 'n_words': 325}