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 profile_chrome import profiler 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 = profiler.GetSupportedBrowsers()[self.browser] 19 self.device = devices[0] 20 21 curr_browser = self.GetChromeProcessID() 22 if curr_browser == None: 23 self.StartBrowser() 24 25 def StartBrowser(self): 26 # Turn on the device screen. 27 self.device.SetScreen(True) 28 29 # Unlock device. 30 self.device.SendKeyEvent(keyevent.KEYCODE_MENU) 31 32 # Start browser. 33 self.device.StartActivity( 34 intent.Intent(activity=self.package_info.activity, 35 package=self.package_info.package, 36 data='about:blank', 37 extras={'create_new_tab': True}), 38 blocking=True, force_stop=True) 39 40 def GetChromeProcessID(self): 41 chrome_processes = self.device.GetPids(self.package_info.package) 42 if (self.package_info.package in chrome_processes and 43 len(chrome_processes[self.package_info.package]) > 0): 44 return chrome_processes[self.package_info.package][0] 45 return None 46