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

Side by Side Diff: content/renderer/battery_status/battery_status_dispatcher_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 "content/renderer/battery_status/battery_status_dispatcher.h"
6
7 #include <utility>
8
9 #include "base/macros.h"
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
15 namespace content {
16
17 class MockBatteryStatusListener : public blink::WebBatteryStatusListener {
18 public:
19 MockBatteryStatusListener() : did_change_battery_status_(false) {}
20 ~MockBatteryStatusListener() override {}
21
22 // blink::WebBatteryStatusListener method.
23 void updateBatteryStatus(const blink::WebBatteryStatus& status) override {
24 status_ = status;
25 did_change_battery_status_ = true;
26 }
27
28 const blink::WebBatteryStatus& status() const { return status_; }
29 bool did_change_battery_status() const { return did_change_battery_status_; }
30
31 private:
32 bool did_change_battery_status_;
33 blink::WebBatteryStatus status_;
34
35 DISALLOW_COPY_AND_ASSIGN(MockBatteryStatusListener);
36 };
37
38 class BatteryStatusDispatcherTest : public testing::Test {
39 public:
40 void UpdateBatteryStatus(const device::BatteryStatus& status) {
41 device::BatteryStatusPtr status_ptr(device::BatteryStatus::New());
42 *status_ptr = status;
43 dispatcher_->DidChange(std::move(status_ptr));
44 }
45
46 const MockBatteryStatusListener& listener() const {
47 return listener_;
48 }
49
50 protected:
51 void SetUp() override {
52 dispatcher_.reset(new BatteryStatusDispatcher(&listener_));
53 }
54
55 private:
56 // We need to create a MockRenderThread so RenderThread::Get() doesn't return
57 // null.
58 MockRenderThread render_thread_;
59 MockBatteryStatusListener listener_;
60 scoped_ptr<BatteryStatusDispatcher> dispatcher_;
61 };
62
63 TEST_F(BatteryStatusDispatcherTest, UpdateListener) {
64 // TODO(darin): This test isn't super interesting. It just exercises
65 // conversion b/w device::BatteryStatus and blink::WebBatteryStatus.
66
67 device::BatteryStatus status;
68 status.charging = true;
69 status.charging_time = 100;
70 status.discharging_time = 200;
71 status.level = 0.5;
72
73 UpdateBatteryStatus(status);
74
75 const blink::WebBatteryStatus& received_status = listener().status();
76 EXPECT_TRUE(listener().did_change_battery_status());
77 EXPECT_EQ(status.charging, received_status.charging);
78 EXPECT_EQ(status.charging_time, received_status.chargingTime);
79 EXPECT_EQ(status.discharging_time, received_status.dischargingTime);
80 EXPECT_EQ(status.level, received_status.level);
81 }
82
83 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/battery_status/battery_status_dispatcher.cc ('k') | content/renderer/renderer_blink_platform_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698