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.
9 from telemetry.core import platform as platform_module
12 class PlatformBackendTest(unittest.TestCase):
13 def testPowerMonitoringSync(self):
14 # Tests that the act of monitoring power doesn't blow up.
15 platform = platform_module.GetHostPlatform()
16 can_monitor_power = platform.CanMonitorPower()
17 self.assertIsInstance(can_monitor_power, bool)
18 if not can_monitor_power:
19 logging.warning('Test not supported on this platform.')
22 browser_mock = lambda: None
23 # Android needs to access the package of the monitored app.
24 if platform.GetOSName() == 'android':
25 # pylint: disable=W0212
26 browser_mock._browser_backend = lambda: None
27 # Monitor the launcher, which is always present.
28 browser_mock._browser_backend.package = 'com.android.launcher'
30 platform.StartMonitoringPower(browser_mock)
32 output = platform.StopMonitoringPower()
33 self.assertTrue(output.has_key('energy_consumption_mwh'))
34 self.assertTrue(output.has_key('identifier'))