<commit_before># Copyright 2014 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 unittest

from systrace import util

from devil.android import device_utils
from devil.android.sdk import intent
from devil.android.sdk import keyevent


class BaseAgentTest(unittest.TestCase):
  def setUp(self):
    devices = device_utils.DeviceUtils.HealthyDevices()
    self.browser = 'stable'
    self.package_info = util.get_supported_browsers()[self.browser]
    self.device = devices[0]

    curr_browser = self.GetChromeProcessID()
    if curr_browser == None:
      self.StartBrowser()

  def tearDown(self):
    # Stop the browser after each test to ensure that it doesn't interfere
    # with subsequent tests, e.g. by holding the devtools socket open.
    self.device.ForceStop(self.package_info.package)

  def StartBrowser(self):
    # Turn on the device screen.
    self.device.SetScreen(True)

    # Unlock device.
    self.device.SendKeyEvent(keyevent.KEYCODE_MENU)

    # Start browser.
    self.device.StartActivity(
      intent.Intent(activity=self.package_info.activity,
                    package=self.package_info.package,
                    data='about:blank',
                    extras={'create_new_tab': True}),
      blocking=True, force_stop=True)

  def GetChromeProcessID(self):
    chrome_processes = self.device.GetPids(self.package_info.package)
    if (self.package_info.package in chrome_processes and
        len(chrome_processes[self.package_info.package]) > 0):
      return chrome_processes[self.package_info.package][0]
    return None<commit_msg>[Systrace] Simplify BaseAgentTest.GetChromeProcessID<commit_after># Copyright 2014 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 unittest

from systrace import util

from devil.android import device_utils
from devil.android.sdk import intent
from devil.android.sdk import keyevent


class BaseAgentTest(unittest.TestCase):
  def setUp(self):
    devices = device_utils.DeviceUtils.HealthyDevices()
    self.browser = 'stable'
    self.package_info = util.get_supported_browsers()[self.browser]
    self.device = devices[0]

    curr_browser = self.GetChromeProcessID()
    if curr_browser == None:
      self.StartBrowser()

  def tearDown(self):
    # Stop the browser after each test to ensure that it doesn't interfere
    # with subsequent tests, e.g. by holding the devtools socket open.
    self.device.ForceStop(self.package_info.package)

  def StartBrowser(self):
    # Turn on the device screen.
    self.device.SetScreen(True)

    # Unlock device.
    self.device.SendKeyEvent(keyevent.KEYCODE_MENU)

    # Start browser.
    self.device.StartActivity(
      intent.Intent(activity=self.package_info.activity,
                    package=self.package_info.package,
                    data='about:blank',
                    extras={'create_new_tab': True}),
      blocking=True, force_stop=True)

  def GetChromeProcessID(self):
    return self.device.GetApplicationPids(
        self.package_info.package, at_most_one=True)
{'fraction_non_alphanumeric': 0.08571428571428572, 'fraction_numerical': 0.0037267080745341614, 'mean_word_length': 3.4798331015299024, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '7552969', 'n_tokens_mistral': 964, 'n_tokens_neox': 922, 'n_words': 242}