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

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: BatteryStatusDispatcher => BatteryDispatcherProxy 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/battery_status/battery_status_dispatcher.h" 5 #include "platform/battery/battery_dispatcher_proxy.h"
6 6
7 #include <utility> 7 #include "base/message_loop/message_loop.h"
8 #include "platform/battery/battery_status.h"
9 #include "platform/battery/battery_status_listener.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "wtf/Noncopyable.h"
12 #include "wtf/OwnPtr.h"
13 #include "wtf/PassOwnPtr.h"
8 14
9 #include "base/macros.h" 15 namespace blink {
10 #include "content/public/test/mock_render_thread.h"
11 #include "content/public/test/test_utils.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/WebKit/public/platform/WebBatteryStatusListener.h"
14 16
15 namespace content { 17 class MockBatteryStatusListener : public BatteryStatusListener {
16 18 WTF_MAKE_NONCOPYABLE(MockBatteryStatusListener);
17 class MockBatteryStatusListener : public blink::WebBatteryStatusListener {
18 public: 19 public:
19 MockBatteryStatusListener() : did_change_battery_status_(false) {} 20 MockBatteryStatusListener() : did_change_battery_status_(false) {}
20 ~MockBatteryStatusListener() override {}
21 21
22 // blink::WebBatteryStatusListener method. 22 // BatteryStatusListener method.
23 void updateBatteryStatus(const blink::WebBatteryStatus& status) override { 23 void OnUpdateBatteryStatus(const BatteryStatus& status) override {
24 status_ = status; 24 status_ = status;
25 did_change_battery_status_ = true; 25 did_change_battery_status_ = true;
26 } 26 }
27 27
28 const blink::WebBatteryStatus& status() const { return status_; } 28 const BatteryStatus& status() const { return status_; }
29 bool did_change_battery_status() const { return did_change_battery_status_; } 29 bool did_change_battery_status() const { return did_change_battery_status_; }
30 30
31 private: 31 private:
32 bool did_change_battery_status_; 32 bool did_change_battery_status_;
33 blink::WebBatteryStatus status_; 33 BatteryStatus status_;
34
35 DISALLOW_COPY_AND_ASSIGN(MockBatteryStatusListener);
36 }; 34 };
37 35
38 class BatteryStatusDispatcherTest : public testing::Test { 36 class BatteryDispatcherProxyTest : public testing::Test {
39 public: 37 public:
40 void UpdateBatteryStatus(const device::BatteryStatus& status) { 38 void UpdateBatteryStatus(const device::BatteryStatus& status) {
41 device::BatteryStatusPtr status_ptr(device::BatteryStatus::New()); 39 device::BatteryStatusPtr status_ptr(device::BatteryStatus::New());
42 *status_ptr = status; 40 *status_ptr = status;
43 dispatcher_->DidChange(std::move(status_ptr)); 41 dispatcher_->OnDidChange(std::move(status_ptr));
44 } 42 }
45 43
46 const MockBatteryStatusListener& listener() const { 44 const MockBatteryStatusListener& listener() const { return listener_; }
47 return listener_;
48 }
49 45
50 protected: 46 protected:
51 void SetUp() override { 47 void SetUp() override {
52 dispatcher_.reset(new BatteryStatusDispatcher(&listener_)); 48 dispatcher_ = adoptPtr(new BatteryDispatcherProxy(&listener_));
53 } 49 }
54 50
55 private: 51 private:
56 // We need to create a MockRenderThread so RenderThread::Get() doesn't return 52 base::MessageLoop message_loop_; // Mojo needs the message loop.
haraken 2016/02/15 13:18:39 Hmm. If possible, I don't want to expose base::Mes
Yuki 2016/02/16 07:31:58 Done.
57 // null.
58 MockRenderThread render_thread_;
59 MockBatteryStatusListener listener_; 53 MockBatteryStatusListener listener_;
60 scoped_ptr<BatteryStatusDispatcher> dispatcher_; 54 OwnPtr<BatteryDispatcherProxy> dispatcher_;
61 }; 55 };
62 56
63 TEST_F(BatteryStatusDispatcherTest, UpdateListener) { 57 TEST_F(BatteryDispatcherProxyTest, UpdateListener) {
64 // TODO(darin): This test isn't super interesting. It just exercises 58 // TODO(darin): This test isn't super interesting. It just exercises
65 // conversion b/w device::BatteryStatus and blink::WebBatteryStatus. 59 // conversion b/w device::BatteryStatus and blink::BatteryStatus.
66 60
67 device::BatteryStatus status; 61 device::BatteryStatus status;
68 status.charging = true; 62 status.charging = true;
69 status.charging_time = 100; 63 status.charging_time = 100;
70 status.discharging_time = 200; 64 status.discharging_time = 200;
71 status.level = 0.5; 65 status.level = 0.5;
72 66
73 UpdateBatteryStatus(status); 67 UpdateBatteryStatus(status);
74 68
75 const blink::WebBatteryStatus& received_status = listener().status(); 69 const BatteryStatus& received_status = listener().status();
76 EXPECT_TRUE(listener().did_change_battery_status()); 70 EXPECT_TRUE(listener().did_change_battery_status());
77 EXPECT_EQ(status.charging, received_status.charging); 71 EXPECT_EQ(status.charging, received_status.charging());
78 EXPECT_EQ(status.charging_time, received_status.chargingTime); 72 EXPECT_EQ(status.charging_time, received_status.charging_time());
79 EXPECT_EQ(status.discharging_time, received_status.dischargingTime); 73 EXPECT_EQ(status.discharging_time, received_status.discharging_time());
80 EXPECT_EQ(status.level, received_status.level); 74 EXPECT_EQ(status.level, received_status.level());
81 } 75 }
82 76
83 } // namespace content 77 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698