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/window_types.h" | 13 #include "ui/aura/client/window_types.h" |
14 #include "ui/aura/root_window.h" | 14 #include "ui/aura/root_window.h" |
15 #include "ui/aura/test/test_windows.h" | 15 #include "ui/aura/test/test_windows.h" |
16 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
17 #include "ui/gfx/rect.h" | 17 #include "ui/gfx/rect.h" |
18 | 18 |
19 namespace ash { | 19 namespace ash { |
20 namespace test { | 20 namespace test { |
21 | 21 |
22 // Implementation that just counts the number of times we've been told that a | 22 // Implementation that just counts the number of times we've been told that a |
23 // video is playing. | 23 // video is playing. |
24 class TestVideoDetectorObserver : public VideoDetectorObserver { | 24 class TestVideoDetectorObserver : public VideoDetectorObserver { |
25 public: | 25 public: |
26 TestVideoDetectorObserver() : num_invocations_(0) {} | 26 TestVideoDetectorObserver() : num_invocations_(0), |
27 num_fullscreens_(0), | |
28 num_not_fullscreens_(0)_{} | |
27 | 29 |
28 int num_invocations() const { return num_invocations_; } | 30 int num_invocations() const { return num_invocations_; } |
29 void reset_stats() { num_invocations_ = 0; } | 31 int num_fullscreens() const { return num_fullscreens_; } |
32 int num_not_fullscreens() const { return num_not_fullscreens_; } | |
33 void reset_stats() { | |
34 num_invocations_ = 0; | |
35 num_fullscreens_ = 0; | |
36 num_not_fullscreens_ = 0; | |
37 } | |
30 | 38 |
31 // VideoDetectorObserver implementation. | 39 // VideoDetectorObserver implementation. |
32 virtual void OnVideoDetected() OVERRIDE { num_invocations_++; } | 40 virtual void OnVideoDetected(bool is_fullscreen) OVERRIDE { |
41 num_invocations_++; | |
42 if (is_fullscreen) | |
43 num_fullscreens++; | |
44 else | |
45 num_not_fullscreens++; | |
46 } | |
33 | 47 |
34 private: | 48 private: |
35 // Number of times that OnVideoDetected() has been called. | 49 // Number of times that OnVideoDetected() has been called. |
36 int num_invocations_; | 50 int num_invocations_; |
51 // Number of times that OnVideoDetected() has been called with is_fullscreen | |
52 // == true. | |
53 int num_fullscreens_; | |
54 // Number of times that OnVideoDetected() has been called with is_fullscreen | |
55 // == false. | |
56 int num_not_fullscreens_; | |
37 | 57 |
38 DISALLOW_COPY_AND_ASSIGN(TestVideoDetectorObserver); | 58 DISALLOW_COPY_AND_ASSIGN(TestVideoDetectorObserver); |
39 }; | 59 }; |
40 | 60 |
41 class VideoDetectorTest : public AshTestBase { | 61 class VideoDetectorTest : public AshTestBase { |
42 public: | 62 public: |
43 VideoDetectorTest() {} | 63 VideoDetectorTest() {} |
44 virtual ~VideoDetectorTest() {} | 64 virtual ~VideoDetectorTest() {} |
45 | 65 |
46 virtual void SetUp() OVERRIDE { | 66 virtual void SetUp() OVERRIDE { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 aura::test::CreateTestWindow(SK_ColorRED, 12345, window_bounds, NULL)); | 101 aura::test::CreateTestWindow(SK_ColorRED, 12345, window_bounds, NULL)); |
82 | 102 |
83 // Send enough updates, but make them be too small to trigger detection. | 103 // Send enough updates, but make them be too small to trigger detection. |
84 gfx::Rect update_region( | 104 gfx::Rect update_region( |
85 gfx::Point(), | 105 gfx::Point(), |
86 gfx::Size(VideoDetector::kMinUpdateWidth - 1, | 106 gfx::Size(VideoDetector::kMinUpdateWidth - 1, |
87 VideoDetector::kMinUpdateHeight)); | 107 VideoDetector::kMinUpdateHeight)); |
88 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) | 108 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) |
89 detector_->OnWindowPaintScheduled(window.get(), update_region); | 109 detector_->OnWindowPaintScheduled(window.get(), update_region); |
90 EXPECT_EQ(0, observer_->num_invocations()); | 110 EXPECT_EQ(0, observer_->num_invocations()); |
91 | 111 // Send not-quite-enough adaquately-sized updates. |
Daniel Erat
2012/08/31 19:15:58
nit: re-add blank line before this one and fix ind
rharrison
2012/09/04 20:12:56
Done.
| |
92 // Send not-quite-enough adaquately-sized updates. | |
93 observer_->reset_stats(); | 112 observer_->reset_stats(); |
94 AdvanceTime(base::TimeDelta::FromSeconds(2)); | 113 AdvanceTime(base::TimeDelta::FromSeconds(2)); |
95 update_region.set_size( | 114 update_region.set_size( |
96 gfx::Size(VideoDetector::kMinUpdateWidth, | 115 gfx::Size(VideoDetector::kMinUpdateWidth, |
97 VideoDetector::kMinUpdateHeight)); | 116 VideoDetector::kMinUpdateHeight)); |
98 for (int i = 0; i < VideoDetector::kMinFramesPerSecond - 1; ++i) | 117 for (int i = 0; i < VideoDetector::kMinFramesPerSecond - 1; ++i) |
99 detector_->OnWindowPaintScheduled(window.get(), update_region); | 118 detector_->OnWindowPaintScheduled(window.get(), update_region); |
100 EXPECT_EQ(0, observer_->num_invocations()); | 119 EXPECT_EQ(0, observer_->num_invocations()); |
101 | 120 // We should get notified after the next update, but not in response to |
Daniel Erat
2012/08/31 19:15:58
ditto
rharrison
2012/09/04 20:12:56
Done.
| |
102 // We should get notified after the next update, but not in response to | |
103 // additional updates. | 121 // additional updates. |
104 detector_->OnWindowPaintScheduled(window.get(), update_region); | 122 detector_->OnWindowPaintScheduled(window.get(), update_region); |
105 EXPECT_EQ(1, observer_->num_invocations()); | 123 EXPECT_EQ(1, observer_->num_invocations()); |
124 EXPECT_EQ(0, observer_->num_fullscreens()); | |
125 EXPECT_EQ(1, observer_->num_not_fullscreens()); | |
106 detector_->OnWindowPaintScheduled(window.get(), update_region); | 126 detector_->OnWindowPaintScheduled(window.get(), update_region); |
107 EXPECT_EQ(1, observer_->num_invocations()); | 127 EXPECT_EQ(1, observer_->num_invocations()); |
108 | 128 EXPECT_EQ(0, observer_->num_fullscreens()); |
109 // Spread out the frames over two seconds; we shouldn't detect video. | 129 EXPECT_EQ(1, observer_->num_not_fullscreens()); |
130 // Spread out the frames over two seconds; we shouldn't detect video. | |
Daniel Erat
2012/08/31 19:15:58
ditto
rharrison
2012/09/04 20:12:56
Done.
| |
110 observer_->reset_stats(); | 131 observer_->reset_stats(); |
111 AdvanceTime(base::TimeDelta::FromSeconds(2)); | 132 AdvanceTime(base::TimeDelta::FromSeconds(2)); |
112 for (int i = 0; i < VideoDetector::kMinFramesPerSecond - 1; ++i) | 133 for (int i = 0; i < VideoDetector::kMinFramesPerSecond - 1; ++i) |
113 detector_->OnWindowPaintScheduled(window.get(), update_region); | 134 detector_->OnWindowPaintScheduled(window.get(), update_region); |
114 AdvanceTime(base::TimeDelta::FromSeconds(1)); | 135 AdvanceTime(base::TimeDelta::FromSeconds(1)); |
115 for (int i = 0; i < VideoDetector::kMinFramesPerSecond - 1; ++i) | 136 for (int i = 0; i < VideoDetector::kMinFramesPerSecond - 1; ++i) |
116 detector_->OnWindowPaintScheduled(window.get(), update_region); | 137 detector_->OnWindowPaintScheduled(window.get(), update_region); |
117 EXPECT_EQ(0, observer_->num_invocations()); | 138 EXPECT_EQ(0, observer_->num_invocations()); |
118 } | 139 } |
119 | 140 TEST_F(VideoDetectorTest, WindowNotVisible) { |
Daniel Erat
2012/08/31 19:15:58
ditto
rharrison
2012/09/04 20:12:56
Done.
| |
120 TEST_F(VideoDetectorTest, WindowNotVisible) { | |
121 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768)); | 141 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768)); |
122 scoped_ptr<aura::Window> window( | 142 scoped_ptr<aura::Window> window( |
123 aura::test::CreateTestWindow(SK_ColorRED, 12345, window_bounds, NULL)); | 143 aura::test::CreateTestWindow(SK_ColorRED, 12345, window_bounds, NULL)); |
124 | 144 |
125 // Reparent the window to the root to make sure that visibility changes aren't | 145 // Reparent the window to the root to make sure that visibility changes aren't |
126 // animated. | 146 // animated. |
127 Shell::GetPrimaryRootWindow()->AddChild(window.get()); | 147 Shell::GetPrimaryRootWindow()->AddChild(window.get()); |
128 | 148 |
129 // We shouldn't report video that's played in a hidden window. | 149 // We shouldn't report video that's played in a hidden window. |
130 window->Hide(); | 150 window->Hide(); |
131 gfx::Rect update_region( | 151 gfx::Rect update_region( |
132 gfx::Point(), | 152 gfx::Point(), |
133 gfx::Size(VideoDetector::kMinUpdateWidth, | 153 gfx::Size(VideoDetector::kMinUpdateWidth, |
134 VideoDetector::kMinUpdateHeight)); | 154 VideoDetector::kMinUpdateHeight)); |
135 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) | 155 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) |
136 detector_->OnWindowPaintScheduled(window.get(), update_region); | 156 detector_->OnWindowPaintScheduled(window.get(), update_region); |
137 EXPECT_EQ(0, observer_->num_invocations()); | 157 EXPECT_EQ(0, observer_->num_invocations()); |
138 | 158 // Make the window visible and send more updates. |
Daniel Erat
2012/08/31 19:15:58
ditto
rharrison
2012/09/04 20:12:56
Done.
| |
139 // Make the window visible and send more updates. | |
140 observer_->reset_stats(); | 159 observer_->reset_stats(); |
141 AdvanceTime(base::TimeDelta::FromSeconds(2)); | 160 AdvanceTime(base::TimeDelta::FromSeconds(2)); |
142 window->Show(); | 161 window->Show(); |
143 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) | 162 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) |
144 detector_->OnWindowPaintScheduled(window.get(), update_region); | 163 detector_->OnWindowPaintScheduled(window.get(), update_region); |
145 EXPECT_EQ(1, observer_->num_invocations()); | 164 EXPECT_EQ(1, observer_->num_invocations()); |
146 | 165 EXPECT_EQ(0, observer_->num_fullscreens()); |
147 // We also shouldn't report video in a window that's fully offscreen. | 166 EXPECT_EQ(1, observer_->num_not_fullscreens()); |
167 // We also shouldn't report video in a window that's fully offscreen. | |
Daniel Erat
2012/08/31 19:15:58
ditto
rharrison
2012/09/04 20:12:56
Done.
| |
148 observer_->reset_stats(); | 168 observer_->reset_stats(); |
149 AdvanceTime(base::TimeDelta::FromSeconds(2)); | 169 AdvanceTime(base::TimeDelta::FromSeconds(2)); |
150 gfx::Rect offscreen_bounds( | 170 gfx::Rect offscreen_bounds( |
151 gfx::Point(Shell::GetPrimaryRootWindow()->bounds().width(), 0), | 171 gfx::Point(Shell::GetPrimaryRootWindow()->bounds().width(), 0), |
152 window_bounds.size()); | 172 window_bounds.size()); |
153 window->SetBounds(offscreen_bounds); | 173 window->SetBounds(offscreen_bounds); |
154 ASSERT_EQ(offscreen_bounds, window->bounds()); | 174 ASSERT_EQ(offscreen_bounds, window->bounds()); |
155 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) | 175 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) |
156 detector_->OnWindowPaintScheduled(window.get(), update_region); | 176 detector_->OnWindowPaintScheduled(window.get(), update_region); |
157 EXPECT_EQ(0, observer_->num_invocations()); | 177 EXPECT_EQ(0, observer_->num_invocations()); |
158 } | 178 } |
159 | 179 TEST_F(VideoDetectorTest, MultipleWindows) { |
Daniel Erat
2012/08/31 19:15:58
ditto
rharrison
2012/09/04 20:12:56
Done.
| |
160 TEST_F(VideoDetectorTest, MultipleWindows) { | |
161 // Create two windows. | 180 // Create two windows. |
162 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768)); | 181 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768)); |
163 scoped_ptr<aura::Window> window1( | 182 scoped_ptr<aura::Window> window1( |
164 aura::test::CreateTestWindow(SK_ColorRED, 12345, window_bounds, NULL)); | 183 aura::test::CreateTestWindow(SK_ColorRED, 12345, window_bounds, NULL)); |
165 scoped_ptr<aura::Window> window2( | 184 scoped_ptr<aura::Window> window2( |
166 aura::test::CreateTestWindow(SK_ColorBLUE, 23456, window_bounds, NULL)); | 185 aura::test::CreateTestWindow(SK_ColorBLUE, 23456, window_bounds, NULL)); |
167 | 186 |
168 // Even if there's video playing in both, the observer should only receive a | 187 // Even if there's video playing in both, the observer should only receive a |
169 // single notification. | 188 // single notification. |
170 gfx::Rect update_region( | 189 gfx::Rect update_region( |
171 gfx::Point(), | 190 gfx::Point(), |
172 gfx::Size(VideoDetector::kMinUpdateWidth, | 191 gfx::Size(VideoDetector::kMinUpdateWidth, |
173 VideoDetector::kMinUpdateHeight)); | 192 VideoDetector::kMinUpdateHeight)); |
174 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) | 193 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) |
175 detector_->OnWindowPaintScheduled(window1.get(), update_region); | 194 detector_->OnWindowPaintScheduled(window1.get(), update_region); |
176 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) | 195 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) |
177 detector_->OnWindowPaintScheduled(window2.get(), update_region); | 196 detector_->OnWindowPaintScheduled(window2.get(), update_region); |
178 EXPECT_EQ(1, observer_->num_invocations()); | 197 EXPECT_EQ(1, observer_->num_invocations()); |
198 EXPECT_EQ(0, observer_->num_fullscreens()); | |
199 EXPECT_EQ(1, observer_->num_not_fullscreens()); | |
179 } | 200 } |
180 | 201 |
181 // Test that the observer receives repeated notifications. | 202 // Test that the observer receives repeated notifications. |
182 TEST_F(VideoDetectorTest, RepeatedNotifications) { | 203 TEST_F(VideoDetectorTest, RepeatedNotifications) { |
183 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768)); | 204 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768)); |
184 scoped_ptr<aura::Window> window( | 205 scoped_ptr<aura::Window> window( |
185 aura::test::CreateTestWindow(SK_ColorRED, 12345, window_bounds, NULL)); | 206 aura::test::CreateTestWindow(SK_ColorRED, 12345, window_bounds, NULL)); |
186 | 207 |
187 gfx::Rect update_region( | 208 gfx::Rect update_region( |
188 gfx::Point(), | 209 gfx::Point(), |
189 gfx::Size(VideoDetector::kMinUpdateWidth, | 210 gfx::Size(VideoDetector::kMinUpdateWidth, |
190 VideoDetector::kMinUpdateHeight)); | 211 VideoDetector::kMinUpdateHeight)); |
191 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) | 212 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) |
192 detector_->OnWindowPaintScheduled(window.get(), update_region); | 213 detector_->OnWindowPaintScheduled(window.get(), update_region); |
193 EXPECT_EQ(1, observer_->num_invocations()); | 214 EXPECT_EQ(1, observer_->num_invocations()); |
194 | 215 EXPECT_EQ(0, observer_->num_fullscreens()); |
216 EXPECT_EQ(1, observer_->num_not_fullscreens()); | |
195 // Let enough time pass that a second notification should be sent. | 217 // Let enough time pass that a second notification should be sent. |
196 observer_->reset_stats(); | 218 observer_->reset_stats(); |
197 AdvanceTime(base::TimeDelta::FromSeconds( | 219 AdvanceTime(base::TimeDelta::FromSeconds( |
198 static_cast<int64>(VideoDetector::kNotifyIntervalSec + 1))); | 220 static_cast<int64>(VideoDetector::kNotifyIntervalSec + 1))); |
199 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) | 221 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) |
200 detector_->OnWindowPaintScheduled(window.get(), update_region); | 222 detector_->OnWindowPaintScheduled(window.get(), update_region); |
201 EXPECT_EQ(1, observer_->num_invocations()); | 223 EXPECT_EQ(1, observer_->num_invocations()); |
224 EXPECT_EQ(0, observer_->num_fullscreens()); | |
225 EXPECT_EQ(1, observer_->num_not_fullscreens()); | |
226 } | |
227 | |
228 // Test that the observer receives a true value when the window is fullscreen. | |
229 TEST_F(VideoDetectorTest, FullscreenWindow) { | |
230 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768)); | |
231 scoped_ptr<aura::Window> window( | |
232 aura::test::CreateTestWindow(SK_ColorRED, 12345, window_bounds, NULL)); | |
233 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | |
234 | |
235 gfx::Rect update_region( | |
236 gfx::Point(), | |
237 gfx::Size(VideoDetector::kMinUpdateWidth, | |
238 - VideoDetector::kMinUpdateHeight)); | |
Daniel Erat
2012/08/31 19:15:58
editor mishap? it looks like you have a minus sig
rharrison
2012/09/04 20:12:56
I suspect all of these issues come from me fouling
| |
239 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) | |
240 detector_->OnWindowPaintScheduled(window.get(), update_region); | |
241 EXPECT_EQ(1, observer_->num_invocations()); | |
242 EXPECT_EQ(1, observer_->num_fullscreens()); | |
243 EXPECT_EQ(0, observer_->num_not_fullscreens()); | |
202 } | 244 } |
203 | 245 |
204 } // namespace test | 246 } // namespace test |
205 } // namespace ash | 247 } // namespace ash |
OLD | NEW |