Commit fb2fb8ca authored by baxley@chromium.org's avatar baxley@chromium.org

Add support for IsApplicationRunning on Mac.

PosixPlatformBackend didn't have support for detecting if an app is
running.

BUG=None

Review URL: https://codereview.chromium.org/331843007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278524 0039d316-1c4b-4281-b951-d872f2087c98
parent 19886aaf
...@@ -133,7 +133,7 @@ class Platform(object): ...@@ -133,7 +133,7 @@ class Platform(object):
def IsApplicationRunning(self, application): def IsApplicationRunning(self, application):
"""Returns whether an application is currently running.""" """Returns whether an application is currently running."""
return self._platform_backend.IsApplicationLaunchning(application) return self._platform_backend.IsApplicationRunning(application)
def CanLaunchApplication(self, application): def CanLaunchApplication(self, application):
"""Returns whether the platform can launch the given application.""" """Returns whether the platform can launch the given application."""
......
...@@ -31,7 +31,7 @@ class PosixPlatformBackend(desktop_platform_backend.DesktopPlatformBackend): ...@@ -31,7 +31,7 @@ class PosixPlatformBackend(desktop_platform_backend.DesktopPlatformBackend):
Args: Args:
columns: A list of require columns, e.g., ['pid', 'pss']. columns: A list of require columns, e.g., ['pid', 'pss'].
pid: If nont None, returns only the information of the process pid: If not None, returns only the information of the process
with the pid. with the pid.
""" """
args = ['ps'] args = ['ps']
...@@ -71,6 +71,12 @@ class PosixPlatformBackend(desktop_platform_backend.DesktopPlatformBackend): ...@@ -71,6 +71,12 @@ class PosixPlatformBackend(desktop_platform_backend.DesktopPlatformBackend):
def CanLaunchApplication(self, application): def CanLaunchApplication(self, application):
return bool(distutils.spawn.find_executable(application)) return bool(distutils.spawn.find_executable(application))
def IsApplicationRunning(self, application):
ps_output = self._GetPsOutput(['command'])
application_re = re.compile(
'(.*%s|^)%s(\s|$)' % (os.path.sep, application))
return any(application_re.match(cmd) for cmd in ps_output)
def LaunchApplication( def LaunchApplication(
self, application, parameters=None, elevate_privilege=False): self, application, parameters=None, elevate_privilege=False):
assert application, 'Must specify application to launch' assert application, 'Must specify application to launch'
......
# Copyright 2013 The Chromium Authors. All rights reserved. # Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
import os
import sys
import unittest import unittest
from telemetry import test
from telemetry.core.platform import factory
from telemetry.core.platform import posix_platform_backend from telemetry.core.platform import posix_platform_backend
...@@ -46,3 +50,13 @@ class PosixPlatformBackendTest(unittest.TestCase): ...@@ -46,3 +50,13 @@ class PosixPlatformBackendTest(unittest.TestCase):
backend.SetMockPsOutput([' 1 0 S ', ' 2 1', '3 2 ']) backend.SetMockPsOutput([' 1 0 S ', ' 2 1', '3 2 '])
result = backend.GetChildPids(1) result = backend.GetChildPids(1)
self.assertEquals(set(result), set([2, 3])) self.assertEquals(set(result), set([2, 3]))
@test.Enabled('linux', 'mac')
def testIsApplicationRunning(self):
backend = factory.GetPlatformBackendForCurrentOS()
self.assertFalse(backend.IsApplicationRunning('This_Is_A_Bad___App__Name'))
sys_exe = os.path.basename(sys.executable)
self.assertTrue(backend.IsApplicationRunning(sys_exe))
self.assertFalse(
backend.IsApplicationRunning('%s append_bad_after_space' % sys_exe))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment