OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 "ash/system/chromeos/power/video_activity_notifier.h" | 5 #include "ash/system/chromeos/power/video_activity_notifier.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "ash/test/ash_test_base.h" | 9 #include "ash/test/ash_test_base.h" |
10 #include "ash/wm/video_detector.h" | 10 #include "ash/wm/video_detector.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 | 41 |
42 DISALLOW_COPY_AND_ASSIGN(VideoActivityNotifierTest); | 42 DISALLOW_COPY_AND_ASSIGN(VideoActivityNotifierTest); |
43 }; | 43 }; |
44 | 44 |
45 // Test that powerd is notified immediately when video changes to a new playing | 45 // Test that powerd is notified immediately when video changes to a new playing |
46 // state or the screen is unlocked. | 46 // state or the screen is unlocked. |
47 TEST_F(VideoActivityNotifierTest, NotifyImmediatelyOnStateChange) { | 47 TEST_F(VideoActivityNotifierTest, NotifyImmediatelyOnStateChange) { |
48 EXPECT_FALSE(power_client_->have_video_activity_report()); | 48 EXPECT_FALSE(power_client_->have_video_activity_report()); |
49 | 49 |
50 notifier_->OnVideoStateChanged(VideoDetector::State::PLAYING_WINDOWED); | 50 notifier_->OnVideoStateChanged(VideoDetector::State::PLAYING_WINDOWED); |
51 EXPECT_EQ(false, power_client_->PopVideoActivityReport()); | 51 EXPECT_FALSE(power_client_->PopVideoActivityReport()); |
52 | 52 |
53 notifier_->OnVideoStateChanged(VideoDetector::State::PLAYING_FULLSCREEN); | 53 notifier_->OnVideoStateChanged(VideoDetector::State::PLAYING_FULLSCREEN); |
54 EXPECT_EQ(true, power_client_->PopVideoActivityReport()); | 54 EXPECT_TRUE(power_client_->PopVideoActivityReport()); |
55 | 55 |
56 notifier_->OnLockStateChanged(true); | 56 notifier_->OnLockStateChanged(true); |
57 EXPECT_FALSE(power_client_->have_video_activity_report()); | 57 EXPECT_FALSE(power_client_->have_video_activity_report()); |
58 | 58 |
59 notifier_->OnLockStateChanged(false); | 59 notifier_->OnLockStateChanged(false); |
60 EXPECT_EQ(true, power_client_->PopVideoActivityReport()); | 60 EXPECT_TRUE(power_client_->PopVideoActivityReport()); |
61 | 61 |
62 notifier_->OnVideoStateChanged(VideoDetector::State::PLAYING_WINDOWED); | 62 notifier_->OnVideoStateChanged(VideoDetector::State::PLAYING_WINDOWED); |
63 EXPECT_EQ(false, power_client_->PopVideoActivityReport()); | 63 EXPECT_FALSE(power_client_->PopVideoActivityReport()); |
64 | 64 |
65 notifier_->OnVideoStateChanged(VideoDetector::State::NOT_PLAYING); | 65 notifier_->OnVideoStateChanged(VideoDetector::State::NOT_PLAYING); |
66 EXPECT_FALSE(power_client_->have_video_activity_report()); | 66 EXPECT_FALSE(power_client_->have_video_activity_report()); |
67 | 67 |
68 notifier_->OnVideoStateChanged(VideoDetector::State::PLAYING_WINDOWED); | 68 notifier_->OnVideoStateChanged(VideoDetector::State::PLAYING_WINDOWED); |
69 EXPECT_EQ(false, power_client_->PopVideoActivityReport()); | 69 EXPECT_FALSE(power_client_->PopVideoActivityReport()); |
70 } | 70 } |
71 | 71 |
72 // Test that powerd is notified periodically while video is ongoing. | 72 // Test that powerd is notified periodically while video is ongoing. |
73 TEST_F(VideoActivityNotifierTest, NotifyPeriodically) { | 73 TEST_F(VideoActivityNotifierTest, NotifyPeriodically) { |
74 // The timer shouldn't be running initially. | 74 // The timer shouldn't be running initially. |
75 EXPECT_FALSE(notifier_->TriggerTimeoutForTest()); | 75 EXPECT_FALSE(notifier_->TriggerTimeoutForTest()); |
76 | 76 |
77 // The timer should start in response to windowed video. | 77 // The timer should start in response to windowed video. |
78 notifier_->OnVideoStateChanged(VideoDetector::State::PLAYING_WINDOWED); | 78 notifier_->OnVideoStateChanged(VideoDetector::State::PLAYING_WINDOWED); |
79 EXPECT_EQ(false, power_client_->PopVideoActivityReport()); | 79 EXPECT_FALSE(power_client_->PopVideoActivityReport()); |
80 EXPECT_FALSE(power_client_->have_video_activity_report()); | 80 EXPECT_FALSE(power_client_->have_video_activity_report()); |
81 EXPECT_TRUE(notifier_->TriggerTimeoutForTest()); | 81 EXPECT_TRUE(notifier_->TriggerTimeoutForTest()); |
82 EXPECT_EQ(false, power_client_->PopVideoActivityReport()); | 82 EXPECT_FALSE(power_client_->PopVideoActivityReport()); |
83 EXPECT_FALSE(power_client_->have_video_activity_report()); | 83 EXPECT_FALSE(power_client_->have_video_activity_report()); |
84 | 84 |
85 // After fullscreen video starts, the timer should start reporting that | 85 // After fullscreen video starts, the timer should start reporting that |
86 // instead. | 86 // instead. |
87 notifier_->OnVideoStateChanged(VideoDetector::State::PLAYING_FULLSCREEN); | 87 notifier_->OnVideoStateChanged(VideoDetector::State::PLAYING_FULLSCREEN); |
88 EXPECT_EQ(true, power_client_->PopVideoActivityReport()); | 88 EXPECT_TRUE(power_client_->PopVideoActivityReport()); |
89 EXPECT_FALSE(power_client_->have_video_activity_report()); | 89 EXPECT_FALSE(power_client_->have_video_activity_report()); |
90 EXPECT_TRUE(notifier_->TriggerTimeoutForTest()); | 90 EXPECT_TRUE(notifier_->TriggerTimeoutForTest()); |
91 EXPECT_EQ(true, power_client_->PopVideoActivityReport()); | 91 EXPECT_TRUE(power_client_->PopVideoActivityReport()); |
92 EXPECT_FALSE(power_client_->have_video_activity_report()); | 92 EXPECT_FALSE(power_client_->have_video_activity_report()); |
93 | 93 |
94 // Locking the screen should stop the timer. | 94 // Locking the screen should stop the timer. |
95 notifier_->OnLockStateChanged(true); | 95 notifier_->OnLockStateChanged(true); |
96 EXPECT_FALSE(notifier_->TriggerTimeoutForTest()); | 96 EXPECT_FALSE(notifier_->TriggerTimeoutForTest()); |
97 EXPECT_FALSE(power_client_->have_video_activity_report()); | 97 EXPECT_FALSE(power_client_->have_video_activity_report()); |
98 | 98 |
99 // Unlocking it should restart the timer. | 99 // Unlocking it should restart the timer. |
100 notifier_->OnLockStateChanged(false); | 100 notifier_->OnLockStateChanged(false); |
101 EXPECT_EQ(true, power_client_->PopVideoActivityReport()); | 101 EXPECT_TRUE(power_client_->PopVideoActivityReport()); |
102 EXPECT_FALSE(power_client_->have_video_activity_report()); | 102 EXPECT_FALSE(power_client_->have_video_activity_report()); |
103 EXPECT_TRUE(notifier_->TriggerTimeoutForTest()); | 103 EXPECT_TRUE(notifier_->TriggerTimeoutForTest()); |
104 EXPECT_EQ(true, power_client_->PopVideoActivityReport()); | 104 EXPECT_TRUE(power_client_->PopVideoActivityReport()); |
105 EXPECT_FALSE(power_client_->have_video_activity_report()); | 105 EXPECT_FALSE(power_client_->have_video_activity_report()); |
106 | 106 |
107 // The timer should stop when video video. | 107 // The timer should stop when video video. |
108 notifier_->OnVideoStateChanged(VideoDetector::State::NOT_PLAYING); | 108 notifier_->OnVideoStateChanged(VideoDetector::State::NOT_PLAYING); |
109 EXPECT_FALSE(notifier_->TriggerTimeoutForTest()); | 109 EXPECT_FALSE(notifier_->TriggerTimeoutForTest()); |
110 EXPECT_FALSE(power_client_->have_video_activity_report()); | 110 EXPECT_FALSE(power_client_->have_video_activity_report()); |
111 } | 111 } |
112 | 112 |
113 } // namespace ash | 113 } // namespace ash |
OLD | NEW |