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
5class MockBrowserBackend(object):
6  def __init__(self, package):
7    self.package = package
8
9class MockBrowser(object):
10  def __init__(self, package):
11    self._browser_backend = MockBrowserBackend(package)
12
13class MockBattery(object):
14  def __init__(self,
15               power_results,
16               starts_charging=True,
17               voltage=4.0,
18               fuelgauge=None):
19    # voltage in millivolts
20    self._power_results = power_results
21    self._charging = starts_charging
22    self._voltage = voltage
23    self._fuelgauge = fuelgauge if fuelgauge else []
24    self._fuel_idx = 0
25
26  def SupportsFuelGauge(self):
27    return len(self._fuelgauge) >= 0
28
29  def GetFuelGaugeChargeCounter(self):
30    try:
31      x = self._fuelgauge[self._fuel_idx]
32      self._fuel_idx += 1
33      return x
34    except IndexError:
35      assert False, "Too many GetFuelGaugeChargeCounter() calls."
36
37  def GetCharging(self):
38    return self._charging
39
40  def SetCharging(self, charging):
41    if charging:
42      assert not self._charging, "Mock battery already charging."
43      self._charging = True
44    else:
45      assert self._charging, "Mock battery already not charging."
46      self._charging = False
47
48  def GetPowerData(self):
49    return self._power_results
50
51  def GetBatteryInfo(self):
52    # the voltage returned by GetBatteryInfo() is in millivolts
53    return {'voltage': int(self._voltage*1000)}
54
55class MockPlatformBackend(object):
56  def __init__(self, command_dict=None):
57    self._cdict = (command_dict if command_dict else {})
58
59  def RunCommand(self, command):
60    assert command in self._cdict, "Mock platform error: Unexpected command."
61    return self._cdict[command]
62