summaryrefslogtreecommitdiff
path: root/systrace/catapult/systrace/systrace/tracing_agents/agents_unittest.py
blob: 4071cafac5bab7edbe684101ac6a91efafceb85f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# 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)