OLD | NEW |
| (Empty) |
1 // Copyright 2016 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 "ash/system/chromeos/power/video_activity_notifier.h" | |
6 | |
7 #include <memory> | |
8 | |
9 #include "ash/test/ash_test_base.h" | |
10 #include "ash/wm/video_detector.h" | |
11 #include "base/macros.h" | |
12 #include "chromeos/dbus/dbus_thread_manager.h" | |
13 #include "chromeos/dbus/fake_power_manager_client.h" | |
14 | |
15 namespace ash { | |
16 | |
17 class VideoActivityNotifierTest : public test::AshTestBase { | |
18 public: | |
19 VideoActivityNotifierTest() {} | |
20 ~VideoActivityNotifierTest() override {} | |
21 | |
22 void SetUp() override { | |
23 test::AshTestBase::SetUp(); | |
24 power_client_ = static_cast<chromeos::FakePowerManagerClient*>( | |
25 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()); | |
26 detector_.reset(new VideoDetector()); | |
27 notifier_.reset(new VideoActivityNotifier(detector_.get())); | |
28 } | |
29 | |
30 void TearDown() override { | |
31 notifier_.reset(); | |
32 detector_.reset(); | |
33 test::AshTestBase::TearDown(); | |
34 } | |
35 | |
36 protected: | |
37 chromeos::FakePowerManagerClient* power_client_; // Not owned. | |
38 | |
39 std::unique_ptr<VideoDetector> detector_; | |
40 std::unique_ptr<VideoActivityNotifier> notifier_; | |
41 | |
42 DISALLOW_COPY_AND_ASSIGN(VideoActivityNotifierTest); | |
43 }; | |
44 | |
45 // Test that powerd is notified immediately when video changes to a new playing | |
46 // state or the screen is unlocked. | |
47 TEST_F(VideoActivityNotifierTest, NotifyImmediatelyOnStateChange) { | |
48 EXPECT_FALSE(power_client_->have_video_activity_report()); | |
49 | |
50 notifier_->OnVideoStateChanged(VideoDetector::State::PLAYING_WINDOWED); | |
51 EXPECT_FALSE(power_client_->PopVideoActivityReport()); | |
52 | |
53 notifier_->OnVideoStateChanged(VideoDetector::State::PLAYING_FULLSCREEN); | |
54 EXPECT_TRUE(power_client_->PopVideoActivityReport()); | |
55 | |
56 notifier_->OnLockStateChanged(true); | |
57 EXPECT_FALSE(power_client_->have_video_activity_report()); | |
58 | |
59 notifier_->OnLockStateChanged(false); | |
60 EXPECT_TRUE(power_client_->PopVideoActivityReport()); | |
61 | |
62 notifier_->OnVideoStateChanged(VideoDetector::State::PLAYING_WINDOWED); | |
63 EXPECT_FALSE(power_client_->PopVideoActivityReport()); | |
64 | |
65 notifier_->OnVideoStateChanged(VideoDetector::State::NOT_PLAYING); | |
66 EXPECT_FALSE(power_client_->have_video_activity_report()); | |
67 | |
68 notifier_->OnVideoStateChanged(VideoDetector::State::PLAYING_WINDOWED); | |
69 EXPECT_FALSE(power_client_->PopVideoActivityReport()); | |
70 } | |
71 | |
72 // Test that powerd is notified periodically while video is ongoing. | |
73 TEST_F(VideoActivityNotifierTest, NotifyPeriodically) { | |
74 // The timer shouldn't be running initially. | |
75 EXPECT_FALSE(notifier_->TriggerTimeoutForTest()); | |
76 | |
77 // The timer should start in response to windowed video. | |
78 notifier_->OnVideoStateChanged(VideoDetector::State::PLAYING_WINDOWED); | |
79 EXPECT_FALSE(power_client_->PopVideoActivityReport()); | |
80 EXPECT_FALSE(power_client_->have_video_activity_report()); | |
81 EXPECT_TRUE(notifier_->TriggerTimeoutForTest()); | |
82 EXPECT_FALSE(power_client_->PopVideoActivityReport()); | |
83 EXPECT_FALSE(power_client_->have_video_activity_report()); | |
84 | |
85 // After fullscreen video starts, the timer should start reporting that | |
86 // instead. | |
87 notifier_->OnVideoStateChanged(VideoDetector::State::PLAYING_FULLSCREEN); | |
88 EXPECT_TRUE(power_client_->PopVideoActivityReport()); | |
89 EXPECT_FALSE(power_client_->have_video_activity_report()); | |
90 EXPECT_TRUE(notifier_->TriggerTimeoutForTest()); | |
91 EXPECT_TRUE(power_client_->PopVideoActivityReport()); | |
92 EXPECT_FALSE(power_client_->have_video_activity_report()); | |
93 | |
94 // Locking the screen should stop the timer. | |
95 notifier_->OnLockStateChanged(true); | |
96 EXPECT_FALSE(notifier_->TriggerTimeoutForTest()); | |
97 EXPECT_FALSE(power_client_->have_video_activity_report()); | |
98 | |
99 // Unlocking it should restart the timer. | |
100 notifier_->OnLockStateChanged(false); | |
101 EXPECT_TRUE(power_client_->PopVideoActivityReport()); | |
102 EXPECT_FALSE(power_client_->have_video_activity_report()); | |
103 EXPECT_TRUE(notifier_->TriggerTimeoutForTest()); | |
104 EXPECT_TRUE(power_client_->PopVideoActivityReport()); | |
105 EXPECT_FALSE(power_client_->have_video_activity_report()); | |
106 | |
107 // The timer should stop when video video. | |
108 notifier_->OnVideoStateChanged(VideoDetector::State::NOT_PLAYING); | |
109 EXPECT_FALSE(notifier_->TriggerTimeoutForTest()); | |
110 EXPECT_FALSE(power_client_->have_video_activity_report()); | |
111 } | |
112 | |
113 } // namespace ash | |
OLD | NEW |