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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/download/internal/scheduler/battery_listener.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/download/internal/scheduler/battery_listener_unittest.cc
diff --git a/components/download/internal/scheduler/battery_listener_unittest.cc b/components/download/internal/scheduler/battery_listener_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..02a87afde1e83b33d27883b636d3ffb42c633740
--- /dev/null
+++ b/components/download/internal/scheduler/battery_listener_unittest.cc
@@ -0,0 +1,72 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/download/internal/scheduler/battery_listener.h"
+
+#include "base/memory/ptr_util.h"
+#include "base/message_loop/message_loop.h"
+#include "base/test/power_monitor_test_base.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace download {
+
+using BatteryRequirements = SchedulingParams::BatteryRequirements;
+
+class MockObserver : public BatteryListener::Observer {
+ public:
+ MOCK_METHOD1(OnBatteryChange, void(SchedulingParams::BatteryRequirements));
+};
+
+class BatteryListenerTest : public testing::Test {
+ public:
+ BatteryListenerTest() {}
+ ~BatteryListenerTest() override = default;
+
+ void CallBatteryChange(bool on_battery_power) {
+ DCHECK(listener_);
+ static_cast<base::PowerObserver*>(listener_.get())
+ ->OnPowerStateChange(on_battery_power);
+ }
+
+ void SetUp() override {
+ power_monitor_ = base::MakeUnique<base::PowerMonitor>(
+ base::MakeUnique<base::PowerMonitorTestSource>());
+
+ observer_ = base::MakeUnique<MockObserver>();
+ listener_ = base::MakeUnique<BatteryListener>();
+ listener_->AddObserver(observer_.get());
+ }
+
+ void TearDown() override {
+ listener_.reset();
+ observer_.reset();
+ }
+
+ std::unique_ptr<BatteryListener> listener_;
+ std::unique_ptr<MockObserver> observer_;
+
+ base::MessageLoop message_loop_;
+ std::unique_ptr<base::PowerMonitor> power_monitor_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(BatteryListenerTest);
+};
+
+// Ensures observer methods are corrected called.
+TEST_F(BatteryListenerTest, NotifyObservers) {
+ listener_->Start();
+ EXPECT_CALL(*observer_.get(),
+ OnBatteryChange(BatteryRequirements::BATTERY_INSENSITIVE))
+ .RetiresOnSaturation();
+ CallBatteryChange(true);
+
+ EXPECT_CALL(*observer_.get(),
+ OnBatteryChange(BatteryRequirements::BATTERY_SENSITIVE))
+ .RetiresOnSaturation();
+ CallBatteryChange(false);
+ listener_->Stop();
+};
+
+} // namespace download
« 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