Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / tools / telemetry / telemetry / core / platform / platform_backend_unittest.py
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
5 import logging
6 import time
7 import unittest
8
9 from telemetry.core import platform as platform_module
10
11
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.')
20       return
21
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'
29
30     platform.StartMonitoringPower(browser_mock)
31     time.sleep(0.001)
32     output = platform.StopMonitoringPower()
33     self.assertTrue(output.has_key('energy_consumption_mwh'))
34     self.assertTrue(output.has_key('identifier'))