aboutsummaryrefslogtreecommitdiff
path: root/catapult/telemetry/telemetry/internal/platform/power_monitor/pm_mock.py
blob: d9bbab5ba870105a120d31713953f3c7e690b207 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

class MockBrowserBackend(object):
  def __init__(self, package):
    self.package = package

class MockBrowser(object):
  def __init__(self, package):
    self._browser_backend = MockBrowserBackend(package)

class MockBattery(object):
  def __init__(self,
               power_results,
               starts_charging=True,
               voltage=4.0,
               fuelgauge=None):
    # voltage in millivolts
    self._power_results = power_results
    self._charging = starts_charging
    self._voltage = voltage
    self._fuelgauge = fuelgauge if fuelgauge else []
    self._fuel_idx = 0

  def SupportsFuelGauge(self):
    return len(self._fuelgauge) >= 0

  def GetFuelGaugeChargeCounter(self):
    try:
      x = self._fuelgauge[self._fuel_idx]
      self._fuel_idx += 1
      return x
    except IndexError:
      assert False, "Too many GetFuelGaugeChargeCounter() calls."

  def GetCharging(self):
    return self._charging

  def SetCharging(self, charging):
    if charging:
      assert not self._charging, "Mock battery already charging."
      self._charging = True
    else:
      assert self._charging, "Mock battery already not charging."
      self._charging = False

  def GetPowerData(self):
    return self._power_results

  def GetBatteryInfo(self):
    # the voltage returned by GetBatteryInfo() is in millivolts
    return {'voltage': int(self._voltage*1000)}

class MockPlatformBackend(object):
  def __init__(self, command_dict=None):
    self._cdict = (command_dict if command_dict else {})

  def RunCommand(self, command):
    assert command in self._cdict, "Mock platform error: Unexpected command."
    return self._cdict[command]