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

Side by Side Diff: components/download/internal/scheduler/battery_listener_unittest.cc

Issue 2867073004: Battery listener for download service in native code. (Closed)
Patch Set: Work on feedbacks. Created 3 years, 7 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
« no previous file with comments | « components/download/internal/scheduler/battery_listener.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 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 "components/download/internal/scheduler/battery_listener.h"
6
7 #include "base/memory/ptr_util.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/test/power_monitor_test_base.h"
10 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace download {
14
15 using BatteryRequirements = SchedulingParams::BatteryRequirements;
16
17 class MockObserver : public BatteryListener::Observer {
18 public:
19 MOCK_METHOD1(OnBatteryChange, void(SchedulingParams::BatteryRequirements));
20 };
21
22 class BatteryListenerTest : public testing::Test {
23 public:
24 BatteryListenerTest() {}
25 ~BatteryListenerTest() override = default;
26
27 void CallBatteryChange(bool on_battery_power) {
28 DCHECK(listener_);
29 static_cast<base::PowerObserver*>(listener_.get())
30 ->OnPowerStateChange(on_battery_power);
31 }
32
33 void SetUp() override {
34 power_monitor_ = base::MakeUnique<base::PowerMonitor>(
35 base::MakeUnique<base::PowerMonitorTestSource>());
36
37 observer_ = base::MakeUnique<MockObserver>();
38 listener_ = base::MakeUnique<BatteryListener>();
39 listener_->AddObserver(observer_.get());
40 }
41
42 void TearDown() override {
43 listener_.reset();
44 observer_.reset();
45 }
46
47 std::unique_ptr<BatteryListener> listener_;
48 std::unique_ptr<MockObserver> observer_;
49
50 base::MessageLoop message_loop_;
51 std::unique_ptr<base::PowerMonitor> power_monitor_;
52
53 private:
54 DISALLOW_COPY_AND_ASSIGN(BatteryListenerTest);
55 };
56
57 // Ensures observer methods are corrected called.
58 TEST_F(BatteryListenerTest, NotifyObservers) {
59 listener_->Start();
60 EXPECT_CALL(*observer_.get(),
61 OnBatteryChange(BatteryRequirements::BATTERY_INSENSITIVE))
62 .RetiresOnSaturation();
63 CallBatteryChange(true);
64
65 EXPECT_CALL(*observer_.get(),
66 OnBatteryChange(BatteryRequirements::BATTERY_SENSITIVE))
67 .RetiresOnSaturation();
68 CallBatteryChange(false);
69 listener_->Stop();
70 };
71
72 } // namespace download
OLDNEW
« no previous file with comments | « components/download/internal/scheduler/battery_listener.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698