Add ICU message format support
[chromium-blink-merge.git] / content / renderer / battery_status / battery_status_dispatcher_unittest.cc
blob7e6068e89472a595673baabacd93f3e306791103
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.
5 #include "content/renderer/battery_status/battery_status_dispatcher.h"
7 #include "content/public/test/mock_render_thread.h"
8 #include "content/public/test/test_utils.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "third_party/WebKit/public/platform/WebBatteryStatusListener.h"
12 namespace content {
14 class MockBatteryStatusListener : public blink::WebBatteryStatusListener {
15 public:
16 MockBatteryStatusListener() : did_change_battery_status_(false) {}
17 virtual ~MockBatteryStatusListener() {}
19 // blink::WebBatteryStatusListener method.
20 void updateBatteryStatus(const blink::WebBatteryStatus& status) override {
21 status_ = status;
22 did_change_battery_status_ = true;
25 const blink::WebBatteryStatus& status() const { return status_; }
26 bool did_change_battery_status() const { return did_change_battery_status_; }
28 private:
29 bool did_change_battery_status_;
30 blink::WebBatteryStatus status_;
32 DISALLOW_COPY_AND_ASSIGN(MockBatteryStatusListener);
35 class BatteryStatusDispatcherTest : public testing::Test {
36 public:
37 void UpdateBatteryStatus(const device::BatteryStatus& status) {
38 device::BatteryStatusPtr status_ptr(device::BatteryStatus::New());
39 *status_ptr = status;
40 dispatcher_->DidChange(status_ptr.Pass());
43 const MockBatteryStatusListener& listener() const {
44 return listener_;
47 protected:
48 void SetUp() override {
49 dispatcher_.reset(new BatteryStatusDispatcher(&listener_));
52 private:
53 // We need to create a MockRenderThread so RenderThread::Get() doesn't return
54 // null.
55 MockRenderThread render_thread_;
56 MockBatteryStatusListener listener_;
57 scoped_ptr<BatteryStatusDispatcher> dispatcher_;
60 TEST_F(BatteryStatusDispatcherTest, UpdateListener) {
61 // TODO(darin): This test isn't super interesting. It just exercises
62 // conversion b/w device::BatteryStatus and blink::WebBatteryStatus.
64 device::BatteryStatus status;
65 status.charging = true;
66 status.charging_time = 100;
67 status.discharging_time = 200;
68 status.level = 0.5;
70 UpdateBatteryStatus(status);
72 const blink::WebBatteryStatus& received_status = listener().status();
73 EXPECT_TRUE(listener().did_change_battery_status());
74 EXPECT_EQ(status.charging, received_status.charging);
75 EXPECT_EQ(status.charging_time, received_status.chargingTime);
76 EXPECT_EQ(status.discharging_time, received_status.dischargingTime);
77 EXPECT_EQ(status.level, received_status.level);
80 } // namespace content