OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/wm/video_detector.h" | 5 #include "ash/wm/video_detector.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/test/ash_test_base.h" | 8 #include "ash/test/ash_test_base.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/time.h" | 11 #include "base/time.h" |
12 #include "third_party/skia/include/core/SkColor.h" | 12 #include "third_party/skia/include/core/SkColor.h" |
| 13 #include "ui/aura/client/aura_constants.h" |
13 #include "ui/aura/client/window_types.h" | 14 #include "ui/aura/client/window_types.h" |
14 #include "ui/aura/root_window.h" | 15 #include "ui/aura/root_window.h" |
15 #include "ui/aura/test/test_windows.h" | 16 #include "ui/aura/test/test_windows.h" |
16 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
17 #include "ui/gfx/rect.h" | 18 #include "ui/gfx/rect.h" |
18 | 19 |
19 namespace ash { | 20 namespace ash { |
20 namespace test { | 21 namespace test { |
21 | 22 |
22 // Implementation that just counts the number of times we've been told that a | 23 // Implementation that just counts the number of times we've been told that a |
23 // video is playing. | 24 // video is playing. |
24 class TestVideoDetectorObserver : public VideoDetectorObserver { | 25 class TestVideoDetectorObserver : public VideoDetectorObserver { |
25 public: | 26 public: |
26 TestVideoDetectorObserver() : num_invocations_(0) {} | 27 TestVideoDetectorObserver() : num_invocations_(0), |
| 28 num_fullscreens_(0), |
| 29 num_not_fullscreens_(0) {} |
27 | 30 |
28 int num_invocations() const { return num_invocations_; } | 31 int num_invocations() const { return num_invocations_; } |
29 void reset_stats() { num_invocations_ = 0; } | 32 int num_fullscreens() const { return num_fullscreens_; } |
| 33 int num_not_fullscreens() const { return num_not_fullscreens_; } |
| 34 void reset_stats() { |
| 35 num_invocations_ = 0; |
| 36 num_fullscreens_ = 0; |
| 37 num_not_fullscreens_ = 0; |
| 38 } |
30 | 39 |
31 // VideoDetectorObserver implementation. | 40 // VideoDetectorObserver implementation. |
32 virtual void OnVideoDetected() OVERRIDE { num_invocations_++; } | 41 virtual void OnVideoDetected(bool is_fullscreen) OVERRIDE { |
| 42 num_invocations_++; |
| 43 if (is_fullscreen) |
| 44 num_fullscreens_++; |
| 45 else |
| 46 num_not_fullscreens_++; |
| 47 } |
33 | 48 |
34 private: | 49 private: |
35 // Number of times that OnVideoDetected() has been called. | 50 // Number of times that OnVideoDetected() has been called. |
36 int num_invocations_; | 51 int num_invocations_; |
| 52 // Number of times that OnVideoDetected() has been called with is_fullscreen |
| 53 // == true. |
| 54 int num_fullscreens_; |
| 55 // Number of times that OnVideoDetected() has been called with is_fullscreen |
| 56 // == false. |
| 57 int num_not_fullscreens_; |
37 | 58 |
38 DISALLOW_COPY_AND_ASSIGN(TestVideoDetectorObserver); | 59 DISALLOW_COPY_AND_ASSIGN(TestVideoDetectorObserver); |
39 }; | 60 }; |
40 | 61 |
41 class VideoDetectorTest : public AshTestBase { | 62 class VideoDetectorTest : public AshTestBase { |
42 public: | 63 public: |
43 VideoDetectorTest() {} | 64 VideoDetectorTest() {} |
44 virtual ~VideoDetectorTest() {} | 65 virtual ~VideoDetectorTest() {} |
45 | 66 |
46 virtual void SetUp() OVERRIDE { | 67 virtual void SetUp() OVERRIDE { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 gfx::Size(VideoDetector::kMinUpdateWidth, | 117 gfx::Size(VideoDetector::kMinUpdateWidth, |
97 VideoDetector::kMinUpdateHeight)); | 118 VideoDetector::kMinUpdateHeight)); |
98 for (int i = 0; i < VideoDetector::kMinFramesPerSecond - 1; ++i) | 119 for (int i = 0; i < VideoDetector::kMinFramesPerSecond - 1; ++i) |
99 detector_->OnWindowPaintScheduled(window.get(), update_region); | 120 detector_->OnWindowPaintScheduled(window.get(), update_region); |
100 EXPECT_EQ(0, observer_->num_invocations()); | 121 EXPECT_EQ(0, observer_->num_invocations()); |
101 | 122 |
102 // We should get notified after the next update, but not in response to | 123 // We should get notified after the next update, but not in response to |
103 // additional updates. | 124 // additional updates. |
104 detector_->OnWindowPaintScheduled(window.get(), update_region); | 125 detector_->OnWindowPaintScheduled(window.get(), update_region); |
105 EXPECT_EQ(1, observer_->num_invocations()); | 126 EXPECT_EQ(1, observer_->num_invocations()); |
| 127 EXPECT_EQ(0, observer_->num_fullscreens()); |
| 128 EXPECT_EQ(1, observer_->num_not_fullscreens()); |
106 detector_->OnWindowPaintScheduled(window.get(), update_region); | 129 detector_->OnWindowPaintScheduled(window.get(), update_region); |
107 EXPECT_EQ(1, observer_->num_invocations()); | 130 EXPECT_EQ(1, observer_->num_invocations()); |
| 131 EXPECT_EQ(0, observer_->num_fullscreens()); |
| 132 EXPECT_EQ(1, observer_->num_not_fullscreens()); |
108 | 133 |
109 // Spread out the frames over two seconds; we shouldn't detect video. | 134 // Spread out the frames over two seconds; we shouldn't detect video. |
110 observer_->reset_stats(); | 135 observer_->reset_stats(); |
111 AdvanceTime(base::TimeDelta::FromSeconds(2)); | 136 AdvanceTime(base::TimeDelta::FromSeconds(2)); |
112 for (int i = 0; i < VideoDetector::kMinFramesPerSecond - 1; ++i) | 137 for (int i = 0; i < VideoDetector::kMinFramesPerSecond - 1; ++i) |
113 detector_->OnWindowPaintScheduled(window.get(), update_region); | 138 detector_->OnWindowPaintScheduled(window.get(), update_region); |
114 AdvanceTime(base::TimeDelta::FromSeconds(1)); | 139 AdvanceTime(base::TimeDelta::FromSeconds(1)); |
115 for (int i = 0; i < VideoDetector::kMinFramesPerSecond - 1; ++i) | 140 for (int i = 0; i < VideoDetector::kMinFramesPerSecond - 1; ++i) |
116 detector_->OnWindowPaintScheduled(window.get(), update_region); | 141 detector_->OnWindowPaintScheduled(window.get(), update_region); |
117 EXPECT_EQ(0, observer_->num_invocations()); | 142 EXPECT_EQ(0, observer_->num_invocations()); |
(...skipping 18 matching lines...) Expand all Loading... |
136 detector_->OnWindowPaintScheduled(window.get(), update_region); | 161 detector_->OnWindowPaintScheduled(window.get(), update_region); |
137 EXPECT_EQ(0, observer_->num_invocations()); | 162 EXPECT_EQ(0, observer_->num_invocations()); |
138 | 163 |
139 // Make the window visible and send more updates. | 164 // Make the window visible and send more updates. |
140 observer_->reset_stats(); | 165 observer_->reset_stats(); |
141 AdvanceTime(base::TimeDelta::FromSeconds(2)); | 166 AdvanceTime(base::TimeDelta::FromSeconds(2)); |
142 window->Show(); | 167 window->Show(); |
143 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) | 168 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) |
144 detector_->OnWindowPaintScheduled(window.get(), update_region); | 169 detector_->OnWindowPaintScheduled(window.get(), update_region); |
145 EXPECT_EQ(1, observer_->num_invocations()); | 170 EXPECT_EQ(1, observer_->num_invocations()); |
| 171 EXPECT_EQ(0, observer_->num_fullscreens()); |
| 172 EXPECT_EQ(1, observer_->num_not_fullscreens()); |
146 | 173 |
147 // We also shouldn't report video in a window that's fully offscreen. | 174 // We also shouldn't report video in a window that's fully offscreen. |
148 observer_->reset_stats(); | 175 observer_->reset_stats(); |
149 AdvanceTime(base::TimeDelta::FromSeconds(2)); | 176 AdvanceTime(base::TimeDelta::FromSeconds(2)); |
150 gfx::Rect offscreen_bounds( | 177 gfx::Rect offscreen_bounds( |
151 gfx::Point(Shell::GetPrimaryRootWindow()->bounds().width(), 0), | 178 gfx::Point(Shell::GetPrimaryRootWindow()->bounds().width(), 0), |
152 window_bounds.size()); | 179 window_bounds.size()); |
153 window->SetBounds(offscreen_bounds); | 180 window->SetBounds(offscreen_bounds); |
154 ASSERT_EQ(offscreen_bounds, window->bounds()); | 181 ASSERT_EQ(offscreen_bounds, window->bounds()); |
155 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) | 182 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) |
(...skipping 13 matching lines...) Expand all Loading... |
169 // single notification. | 196 // single notification. |
170 gfx::Rect update_region( | 197 gfx::Rect update_region( |
171 gfx::Point(), | 198 gfx::Point(), |
172 gfx::Size(VideoDetector::kMinUpdateWidth, | 199 gfx::Size(VideoDetector::kMinUpdateWidth, |
173 VideoDetector::kMinUpdateHeight)); | 200 VideoDetector::kMinUpdateHeight)); |
174 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) | 201 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) |
175 detector_->OnWindowPaintScheduled(window1.get(), update_region); | 202 detector_->OnWindowPaintScheduled(window1.get(), update_region); |
176 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) | 203 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) |
177 detector_->OnWindowPaintScheduled(window2.get(), update_region); | 204 detector_->OnWindowPaintScheduled(window2.get(), update_region); |
178 EXPECT_EQ(1, observer_->num_invocations()); | 205 EXPECT_EQ(1, observer_->num_invocations()); |
| 206 EXPECT_EQ(0, observer_->num_fullscreens()); |
| 207 EXPECT_EQ(1, observer_->num_not_fullscreens()); |
179 } | 208 } |
180 | 209 |
181 // Test that the observer receives repeated notifications. | 210 // Test that the observer receives repeated notifications. |
182 TEST_F(VideoDetectorTest, RepeatedNotifications) { | 211 TEST_F(VideoDetectorTest, RepeatedNotifications) { |
183 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768)); | 212 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768)); |
184 scoped_ptr<aura::Window> window( | 213 scoped_ptr<aura::Window> window( |
185 aura::test::CreateTestWindow(SK_ColorRED, 12345, window_bounds, NULL)); | 214 aura::test::CreateTestWindow(SK_ColorRED, 12345, window_bounds, NULL)); |
186 | 215 |
187 gfx::Rect update_region( | 216 gfx::Rect update_region( |
188 gfx::Point(), | 217 gfx::Point(), |
189 gfx::Size(VideoDetector::kMinUpdateWidth, | 218 gfx::Size(VideoDetector::kMinUpdateWidth, |
190 VideoDetector::kMinUpdateHeight)); | 219 VideoDetector::kMinUpdateHeight)); |
191 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) | 220 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) |
192 detector_->OnWindowPaintScheduled(window.get(), update_region); | 221 detector_->OnWindowPaintScheduled(window.get(), update_region); |
193 EXPECT_EQ(1, observer_->num_invocations()); | 222 EXPECT_EQ(1, observer_->num_invocations()); |
194 | 223 EXPECT_EQ(0, observer_->num_fullscreens()); |
| 224 EXPECT_EQ(1, observer_->num_not_fullscreens()); |
195 // Let enough time pass that a second notification should be sent. | 225 // Let enough time pass that a second notification should be sent. |
196 observer_->reset_stats(); | 226 observer_->reset_stats(); |
197 AdvanceTime(base::TimeDelta::FromSeconds( | 227 AdvanceTime(base::TimeDelta::FromSeconds( |
198 static_cast<int64>(VideoDetector::kNotifyIntervalSec + 1))); | 228 static_cast<int64>(VideoDetector::kNotifyIntervalSec + 1))); |
199 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) | 229 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) |
200 detector_->OnWindowPaintScheduled(window.get(), update_region); | 230 detector_->OnWindowPaintScheduled(window.get(), update_region); |
201 EXPECT_EQ(1, observer_->num_invocations()); | 231 EXPECT_EQ(1, observer_->num_invocations()); |
| 232 EXPECT_EQ(0, observer_->num_fullscreens()); |
| 233 EXPECT_EQ(1, observer_->num_not_fullscreens()); |
| 234 } |
| 235 |
| 236 // Test that the observer receives a true value when the window is fullscreen. |
| 237 TEST_F(VideoDetectorTest, FullscreenWindow) { |
| 238 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768)); |
| 239 scoped_ptr<aura::Window> window( |
| 240 aura::test::CreateTestWindow(SK_ColorRED, 12345, window_bounds, NULL)); |
| 241 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); |
| 242 |
| 243 gfx::Rect update_region( |
| 244 gfx::Point(), |
| 245 gfx::Size(VideoDetector::kMinUpdateWidth, |
| 246 VideoDetector::kMinUpdateHeight)); |
| 247 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) |
| 248 detector_->OnWindowPaintScheduled(window.get(), update_region); |
| 249 EXPECT_EQ(1, observer_->num_invocations()); |
| 250 EXPECT_EQ(1, observer_->num_fullscreens()); |
| 251 EXPECT_EQ(0, observer_->num_not_fullscreens()); |
202 } | 252 } |
203 | 253 |
204 } // namespace test | 254 } // namespace test |
205 } // namespace ash | 255 } // namespace ash |
OLD | NEW |