Upstream version 7.36.149.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.platform import factory
10
11
12 class PlatformBackendTest(unittest.TestCase):
13   def testPowerMonitoringSync(self):
14     # Tests that the act of monitoring power doesn't blow up.
15     backend = factory.GetPlatformBackendForCurrentOS()
16     if not backend.CanMonitorPower():
17       logging.warning('Test not supported on this platform.')
18       return
19
20     browser_mock = lambda: None
21     # Android needs to access the package of the monitored app.
22     if backend.GetOSName() == 'android':
23       # pylint: disable=W0212
24       browser_mock._browser_backend = lambda: None
25       # Monitor the launcher, which is always present.
26       browser_mock._browser_backend.package = 'com.android.launcher'
27
28     backend.StartMonitoringPower(browser_mock)
29     time.sleep(0.001)
30     output = backend.StopMonitoringPower()
31     self.assertTrue(output.has_key('power_samples_mw'))
32     self.assertTrue(output.has_key('identifier'))