power_monitor_controller_unittest.py revision c5cede9ae108bb15f6b7a8aea21c7e1fefa2834c
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
5import unittest
6
7from telemetry.core.platform.power_monitor import power_monitor_controller
8import telemetry.core.platform.power_monitor as power_monitor
9
10
11class PowerMonitorControllerTest(unittest.TestCase):
12  def testComposition(self):
13
14    class P1(power_monitor.PowerMonitor):
15      def StartMonitoringPower(self, browser):
16        raise NotImplementedError()
17      def StopMonitoringPower(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 CanMonitorPower(self):
25        return True
26      def StartMonitoringPower(self, browser):
27        pass
28      def StopMonitoringPower(self):
29        return self._value
30
31    controller = power_monitor_controller.PowerMonitorController(
32        [P1(), P2(1), P2(2)])
33    self.assertEqual(controller.CanMonitorPower(), True)
34    controller.StartMonitoringPower(None)
35    self.assertEqual(controller.StopMonitoringPower(), 1)
36