Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1218)

Side by Side Diff: third_party/WebKit/Source/platform/battery/battery_dispatcher_proxy_unittest.cc

Issue 1538803002: Migrates battery_status from content/renderer/ to WebKit/platform/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Synced. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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 #include "platform/battery/battery_dispatcher_proxy.h"
6
7 #include "platform/battery/battery_status.h"
8 #include "platform/testing/MessageLoopForMojo.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "wtf/Noncopyable.h"
11 #include "wtf/OwnPtr.h"
12 #include "wtf/PassOwnPtr.h"
13
14 namespace blink {
15
16 class MockBatteryStatusListener : public BatteryDispatcherProxy::Listener {
17 WTF_MAKE_NONCOPYABLE(MockBatteryStatusListener);
18 public:
19 MockBatteryStatusListener() : did_change_battery_status_(false) {}
20
21 // BatteryDispatcherProxy::Listener method.
22 void OnUpdateBatteryStatus(const BatteryStatus& status) override {
23 status_ = status;
24 did_change_battery_status_ = true;
25 }
26
27 const BatteryStatus& status() const { return status_; }
28 bool did_change_battery_status() const { return did_change_battery_status_; }
29
30 private:
31 bool did_change_battery_status_;
32 BatteryStatus status_;
33 };
34
35 class BatteryDispatcherProxyTest : 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_->OnDidChange(std::move(status_ptr));
41 }
42
43 const MockBatteryStatusListener& listener() const { return listener_; }
44
45 protected:
46 void SetUp() override {
47 dispatcher_ = adoptPtr(new BatteryDispatcherProxy(&listener_));
48 }
49
50 private:
51 base::MessageLoop message_loop_;
52 MockBatteryStatusListener listener_;
53 OwnPtr<BatteryDispatcherProxy> dispatcher_;
54 };
55
56 TEST_F(BatteryDispatcherProxyTest, UpdateListener) {
57 // TODO(darin): This test isn't super interesting. It just exercises
58 // conversion b/w device::BatteryStatus and blink::BatteryStatus.
59
60 device::BatteryStatus status;
61 status.charging = true;
62 status.charging_time = 100;
63 status.discharging_time = 200;
64 status.level = 0.5;
65
66 UpdateBatteryStatus(status);
67
68 const BatteryStatus& received_status = listener().status();
69 EXPECT_TRUE(listener().did_change_battery_status());
70 EXPECT_EQ(status.charging, received_status.charging());
71 EXPECT_EQ(status.charging_time, received_status.charging_time());
72 EXPECT_EQ(status.discharging_time, received_status.discharging_time());
73 EXPECT_EQ(status.level, received_status.level());
74 }
75
76 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698