1# Copyright 2014 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 5import unittest 6 7from systrace import util 8 9from devil.android import device_utils 10from devil.android.sdk import intent 11from devil.android.sdk import keyevent 12 13 14class BaseAgentTest(unittest.TestCase): 15 def setUp(self): 16 devices = device_utils.DeviceUtils.HealthyDevices() 17 self.browser = 'stable' 18 self.package_info = util.get_supported_browsers()[self.browser] 19 self.device = devices[0] 20 21 curr_browser = self.GetChromeProcessID() 22 if curr_browser is None: 23 self.StartBrowser() 24 25 def tearDown(self): 26 # Stop the browser after each test to ensure that it doesn't interfere 27 # with subsequent tests, e.g. by holding the devtools socket open. 28 self.device.ForceStop(self.package_info.package) 29 30 def StartBrowser(self): 31 # Turn on the device screen. 32 self.device.SetScreen(True) 33 34 # Unlock device. 35 self.device.SendKeyEvent(keyevent.KEYCODE_MENU) 36 37 # Start browser. 38 self.device.StartActivity( 39 intent.Intent(activity=self.package_info.activity, 40 package=self.package_info.package, 41 data='about:blank', 42 extras={'create_new_tab': True}), 43 blocking=True, force_stop=True) 44 45 def GetChromeProcessID(self): 46 return self.device.GetApplicationPids( 47 self.package_info.package, at_most_one=True) 48