Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / tools / telemetry / telemetry / core / platform / power_monitor / power_monitor_controller_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 unittest
6
7 from telemetry.core.platform.power_monitor import power_monitor_controller
8 import telemetry.core.platform.power_monitor as power_monitor
9
10
11 class PowerMonitorControllerTest(unittest.TestCase):
12   def testComposition(self):
13
14     class P1(power_monitor.PowerMonitor):
15       def StartMonitoringPowerAsync(self):
16         raise NotImplementedError()
17       def StopMonitoringPowerAsync(self):
18         raise NotImplementedError()
19
20     class P2(power_monitor.PowerMonitor):
21       def __init__(self, value):
22         super(P2, self).__init__()
23         self._value = value
24       def CanMonitorPowerAsync(self):
25         return True
26       def StartMonitoringPowerAsync(self):
27         pass
28       def StopMonitoringPowerAsync(self):
29         return self._value
30
31     controller = power_monitor_controller.PowerMonitorController(
32         [P1(), P2(1), P2(2)])
33     self.assertEqual(controller.CanMonitorPowerAsync(), True)
34     controller.StartMonitoringPowerAsync()
35     self.assertEqual(controller.StopMonitoringPowerAsync(), 1)