| 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 <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "ash/common/wm/window_state.h" | 9 #include "ash/common/wm/window_state.h" |
| 10 #include "ash/common/wm/wm_event.h" | 10 #include "ash/common/wm/wm_event.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "ui/gfx/geometry/rect.h" | 21 #include "ui/gfx/geometry/rect.h" |
| 22 #include "ui/wm/public/window_types.h" | 22 #include "ui/wm/public/window_types.h" |
| 23 | 23 |
| 24 namespace ash { | 24 namespace ash { |
| 25 namespace test { | 25 namespace test { |
| 26 | 26 |
| 27 // Implementation that just counts the number of times we've been told that a | 27 // Implementation that just counts the number of times we've been told that a |
| 28 // video is playing. | 28 // video is playing. |
| 29 class TestVideoDetectorObserver : public VideoDetectorObserver { | 29 class TestVideoDetectorObserver : public VideoDetectorObserver { |
| 30 public: | 30 public: |
| 31 TestVideoDetectorObserver() : num_invocations_(0), | 31 TestVideoDetectorObserver() |
| 32 num_fullscreens_(0), | 32 : num_invocations_(0), num_fullscreens_(0), num_not_fullscreens_(0) {} |
| 33 num_not_fullscreens_(0) {} | |
| 34 | 33 |
| 35 int num_invocations() const { return num_invocations_; } | 34 int num_invocations() const { return num_invocations_; } |
| 36 int num_fullscreens() const { return num_fullscreens_; } | 35 int num_fullscreens() const { return num_fullscreens_; } |
| 37 int num_not_fullscreens() const { return num_not_fullscreens_; } | 36 int num_not_fullscreens() const { return num_not_fullscreens_; } |
| 38 void reset_stats() { | 37 void reset_stats() { |
| 39 num_invocations_ = 0; | 38 num_invocations_ = 0; |
| 40 num_fullscreens_ = 0; | 39 num_fullscreens_ = 0; |
| 41 num_not_fullscreens_ = 0; | 40 num_not_fullscreens_ = 0; |
| 42 } | 41 } |
| 43 | 42 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 private: | 98 private: |
| 100 DISALLOW_COPY_AND_ASSIGN(VideoDetectorTest); | 99 DISALLOW_COPY_AND_ASSIGN(VideoDetectorTest); |
| 101 }; | 100 }; |
| 102 | 101 |
| 103 TEST_F(VideoDetectorTest, Basic) { | 102 TEST_F(VideoDetectorTest, Basic) { |
| 104 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768)); | 103 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768)); |
| 105 std::unique_ptr<aura::Window> window( | 104 std::unique_ptr<aura::Window> window( |
| 106 CreateTestWindowInShell(SK_ColorRED, 12345, window_bounds)); | 105 CreateTestWindowInShell(SK_ColorRED, 12345, window_bounds)); |
| 107 | 106 |
| 108 // Send enough updates, but make them be too small to trigger detection. | 107 // Send enough updates, but make them be too small to trigger detection. |
| 109 gfx::Rect update_region( | 108 gfx::Rect update_region(gfx::Point(), |
| 110 gfx::Point(), | 109 gfx::Size(VideoDetector::kMinUpdateWidth - 1, |
| 111 gfx::Size(VideoDetector::kMinUpdateWidth - 1, | 110 VideoDetector::kMinUpdateHeight)); |
| 112 VideoDetector::kMinUpdateHeight)); | |
| 113 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) | 111 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) |
| 114 detector_->OnDelegatedFrameDamage(window.get(), update_region); | 112 detector_->OnDelegatedFrameDamage(window.get(), update_region); |
| 115 EXPECT_EQ(0, observer_->num_invocations()); | 113 EXPECT_EQ(0, observer_->num_invocations()); |
| 116 | 114 |
| 117 // Send not-quite-enough adaquately-sized updates. | 115 // Send not-quite-enough adaquately-sized updates. |
| 118 observer_->reset_stats(); | 116 observer_->reset_stats(); |
| 119 AdvanceTime(base::TimeDelta::FromSeconds(2)); | 117 AdvanceTime(base::TimeDelta::FromSeconds(2)); |
| 120 update_region.set_size( | 118 update_region.set_size(gfx::Size(VideoDetector::kMinUpdateWidth, |
| 121 gfx::Size(VideoDetector::kMinUpdateWidth, | 119 VideoDetector::kMinUpdateHeight)); |
| 122 VideoDetector::kMinUpdateHeight)); | |
| 123 for (int i = 0; i < VideoDetector::kMinFramesPerSecond - 1; ++i) | 120 for (int i = 0; i < VideoDetector::kMinFramesPerSecond - 1; ++i) |
| 124 detector_->OnDelegatedFrameDamage(window.get(), update_region); | 121 detector_->OnDelegatedFrameDamage(window.get(), update_region); |
| 125 EXPECT_EQ(0, observer_->num_invocations()); | 122 EXPECT_EQ(0, observer_->num_invocations()); |
| 126 | 123 |
| 127 // We should get notified after the next update, but not in response to | 124 // We should get notified after the next update, but not in response to |
| 128 // additional updates. | 125 // additional updates. |
| 129 detector_->OnDelegatedFrameDamage(window.get(), update_region); | 126 detector_->OnDelegatedFrameDamage(window.get(), update_region); |
| 130 EXPECT_EQ(1, observer_->num_invocations()); | 127 EXPECT_EQ(1, observer_->num_invocations()); |
| 131 EXPECT_EQ(0, observer_->num_fullscreens()); | 128 EXPECT_EQ(0, observer_->num_fullscreens()); |
| 132 EXPECT_EQ(1, observer_->num_not_fullscreens()); | 129 EXPECT_EQ(1, observer_->num_not_fullscreens()); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 AdvanceTime(kSlowInterval); | 163 AdvanceTime(kSlowInterval); |
| 167 detector_->OnDelegatedFrameDamage(window.get(), update_region); | 164 detector_->OnDelegatedFrameDamage(window.get(), update_region); |
| 168 } | 165 } |
| 169 EXPECT_EQ(2, observer_->num_invocations()); | 166 EXPECT_EQ(2, observer_->num_invocations()); |
| 170 } | 167 } |
| 171 | 168 |
| 172 TEST_F(VideoDetectorTest, Shutdown) { | 169 TEST_F(VideoDetectorTest, Shutdown) { |
| 173 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768)); | 170 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768)); |
| 174 std::unique_ptr<aura::Window> window( | 171 std::unique_ptr<aura::Window> window( |
| 175 CreateTestWindowInShell(SK_ColorRED, 12345, window_bounds)); | 172 CreateTestWindowInShell(SK_ColorRED, 12345, window_bounds)); |
| 176 gfx::Rect update_region( | 173 gfx::Rect update_region(gfx::Point(), |
| 177 gfx::Point(), | 174 gfx::Size(VideoDetector::kMinUpdateWidth, |
| 178 gfx::Size(VideoDetector::kMinUpdateWidth, | 175 VideoDetector::kMinUpdateHeight)); |
| 179 VideoDetector::kMinUpdateHeight)); | |
| 180 | 176 |
| 181 // It should not detect video during the shutdown. | 177 // It should not detect video during the shutdown. |
| 182 Shell::GetInstance()->OnAppTerminating(); | 178 Shell::GetInstance()->OnAppTerminating(); |
| 183 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) | 179 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) |
| 184 detector_->OnDelegatedFrameDamage(window.get(), update_region); | 180 detector_->OnDelegatedFrameDamage(window.get(), update_region); |
| 185 EXPECT_EQ(0, observer_->num_invocations()); | 181 EXPECT_EQ(0, observer_->num_invocations()); |
| 186 } | 182 } |
| 187 | 183 |
| 188 TEST_F(VideoDetectorTest, WindowNotVisible) { | 184 TEST_F(VideoDetectorTest, WindowNotVisible) { |
| 189 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768)); | 185 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768)); |
| 190 std::unique_ptr<aura::Window> window( | 186 std::unique_ptr<aura::Window> window( |
| 191 CreateTestWindowInShell(SK_ColorRED, 12345, window_bounds)); | 187 CreateTestWindowInShell(SK_ColorRED, 12345, window_bounds)); |
| 192 | 188 |
| 193 // Reparent the window to the root to make sure that visibility changes aren't | 189 // Reparent the window to the root to make sure that visibility changes aren't |
| 194 // animated. | 190 // animated. |
| 195 Shell::GetPrimaryRootWindow()->AddChild(window.get()); | 191 Shell::GetPrimaryRootWindow()->AddChild(window.get()); |
| 196 | 192 |
| 197 // We shouldn't report video that's played in a hidden window. | 193 // We shouldn't report video that's played in a hidden window. |
| 198 window->Hide(); | 194 window->Hide(); |
| 199 gfx::Rect update_region( | 195 gfx::Rect update_region(gfx::Point(), |
| 200 gfx::Point(), | 196 gfx::Size(VideoDetector::kMinUpdateWidth, |
| 201 gfx::Size(VideoDetector::kMinUpdateWidth, | 197 VideoDetector::kMinUpdateHeight)); |
| 202 VideoDetector::kMinUpdateHeight)); | |
| 203 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) | 198 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) |
| 204 detector_->OnDelegatedFrameDamage(window.get(), update_region); | 199 detector_->OnDelegatedFrameDamage(window.get(), update_region); |
| 205 EXPECT_EQ(0, observer_->num_invocations()); | 200 EXPECT_EQ(0, observer_->num_invocations()); |
| 206 | 201 |
| 207 // Make the window visible and send more updates. | 202 // Make the window visible and send more updates. |
| 208 observer_->reset_stats(); | 203 observer_->reset_stats(); |
| 209 AdvanceTime(base::TimeDelta::FromSeconds(2)); | 204 AdvanceTime(base::TimeDelta::FromSeconds(2)); |
| 210 window->Show(); | 205 window->Show(); |
| 211 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) | 206 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) |
| 212 detector_->OnDelegatedFrameDamage(window.get(), update_region); | 207 detector_->OnDelegatedFrameDamage(window.get(), update_region); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 230 TEST_F(VideoDetectorTest, MultipleWindows) { | 225 TEST_F(VideoDetectorTest, MultipleWindows) { |
| 231 // Create two windows. | 226 // Create two windows. |
| 232 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768)); | 227 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768)); |
| 233 std::unique_ptr<aura::Window> window1( | 228 std::unique_ptr<aura::Window> window1( |
| 234 CreateTestWindowInShell(SK_ColorRED, 12345, window_bounds)); | 229 CreateTestWindowInShell(SK_ColorRED, 12345, window_bounds)); |
| 235 std::unique_ptr<aura::Window> window2( | 230 std::unique_ptr<aura::Window> window2( |
| 236 CreateTestWindowInShell(SK_ColorBLUE, 23456, window_bounds)); | 231 CreateTestWindowInShell(SK_ColorBLUE, 23456, window_bounds)); |
| 237 | 232 |
| 238 // Even if there's video playing in both, the observer should only receive a | 233 // Even if there's video playing in both, the observer should only receive a |
| 239 // single notification. | 234 // single notification. |
| 240 gfx::Rect update_region( | 235 gfx::Rect update_region(gfx::Point(), |
| 241 gfx::Point(), | 236 gfx::Size(VideoDetector::kMinUpdateWidth, |
| 242 gfx::Size(VideoDetector::kMinUpdateWidth, | 237 VideoDetector::kMinUpdateHeight)); |
| 243 VideoDetector::kMinUpdateHeight)); | |
| 244 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) | 238 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) |
| 245 detector_->OnDelegatedFrameDamage(window1.get(), update_region); | 239 detector_->OnDelegatedFrameDamage(window1.get(), update_region); |
| 246 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) | 240 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) |
| 247 detector_->OnDelegatedFrameDamage(window2.get(), update_region); | 241 detector_->OnDelegatedFrameDamage(window2.get(), update_region); |
| 248 EXPECT_EQ(1, observer_->num_invocations()); | 242 EXPECT_EQ(1, observer_->num_invocations()); |
| 249 EXPECT_EQ(0, observer_->num_fullscreens()); | 243 EXPECT_EQ(0, observer_->num_fullscreens()); |
| 250 EXPECT_EQ(1, observer_->num_not_fullscreens()); | 244 EXPECT_EQ(1, observer_->num_not_fullscreens()); |
| 251 } | 245 } |
| 252 | 246 |
| 253 // Test that the observer receives repeated notifications. | 247 // Test that the observer receives repeated notifications. |
| 254 TEST_F(VideoDetectorTest, RepeatedNotifications) { | 248 TEST_F(VideoDetectorTest, RepeatedNotifications) { |
| 255 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768)); | 249 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768)); |
| 256 std::unique_ptr<aura::Window> window( | 250 std::unique_ptr<aura::Window> window( |
| 257 CreateTestWindowInShell(SK_ColorRED, 12345, window_bounds)); | 251 CreateTestWindowInShell(SK_ColorRED, 12345, window_bounds)); |
| 258 | 252 |
| 259 gfx::Rect update_region( | 253 gfx::Rect update_region(gfx::Point(), |
| 260 gfx::Point(), | 254 gfx::Size(VideoDetector::kMinUpdateWidth, |
| 261 gfx::Size(VideoDetector::kMinUpdateWidth, | 255 VideoDetector::kMinUpdateHeight)); |
| 262 VideoDetector::kMinUpdateHeight)); | |
| 263 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) | 256 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) |
| 264 detector_->OnDelegatedFrameDamage(window.get(), update_region); | 257 detector_->OnDelegatedFrameDamage(window.get(), update_region); |
| 265 EXPECT_EQ(1, observer_->num_invocations()); | 258 EXPECT_EQ(1, observer_->num_invocations()); |
| 266 EXPECT_EQ(0, observer_->num_fullscreens()); | 259 EXPECT_EQ(0, observer_->num_fullscreens()); |
| 267 EXPECT_EQ(1, observer_->num_not_fullscreens()); | 260 EXPECT_EQ(1, observer_->num_not_fullscreens()); |
| 268 // Let enough time pass that a second notification should be sent. | 261 // Let enough time pass that a second notification should be sent. |
| 269 observer_->reset_stats(); | 262 observer_->reset_stats(); |
| 270 AdvanceTime(base::TimeDelta::FromSeconds( | 263 AdvanceTime(base::TimeDelta::FromSeconds( |
| 271 static_cast<int64_t>(VideoDetector::kNotifyIntervalSec + 1))); | 264 static_cast<int64_t>(VideoDetector::kNotifyIntervalSec + 1))); |
| 272 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) | 265 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 284 UpdateDisplay("1024x768,1024x768"); | 277 UpdateDisplay("1024x768,1024x768"); |
| 285 | 278 |
| 286 const gfx::Rect kLeftBounds(gfx::Point(), gfx::Size(1024, 768)); | 279 const gfx::Rect kLeftBounds(gfx::Point(), gfx::Size(1024, 768)); |
| 287 std::unique_ptr<aura::Window> window( | 280 std::unique_ptr<aura::Window> window( |
| 288 CreateTestWindowInShell(SK_ColorRED, 12345, kLeftBounds)); | 281 CreateTestWindowInShell(SK_ColorRED, 12345, kLeftBounds)); |
| 289 wm::WindowState* window_state = wm::GetWindowState(window.get()); | 282 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 290 const wm::WMEvent toggle_fullscreen_event(wm::WM_EVENT_TOGGLE_FULLSCREEN); | 283 const wm::WMEvent toggle_fullscreen_event(wm::WM_EVENT_TOGGLE_FULLSCREEN); |
| 291 window_state->OnWMEvent(&toggle_fullscreen_event); | 284 window_state->OnWMEvent(&toggle_fullscreen_event); |
| 292 ASSERT_TRUE(window_state->IsFullscreen()); | 285 ASSERT_TRUE(window_state->IsFullscreen()); |
| 293 window->Focus(); | 286 window->Focus(); |
| 294 const gfx::Rect kUpdateRegion( | 287 const gfx::Rect kUpdateRegion(gfx::Point(), |
| 295 gfx::Point(), | 288 gfx::Size(VideoDetector::kMinUpdateWidth, |
| 296 gfx::Size(VideoDetector::kMinUpdateWidth, | 289 VideoDetector::kMinUpdateHeight)); |
| 297 VideoDetector::kMinUpdateHeight)); | |
| 298 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) | 290 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) |
| 299 detector_->OnDelegatedFrameDamage(window.get(), kUpdateRegion); | 291 detector_->OnDelegatedFrameDamage(window.get(), kUpdateRegion); |
| 300 EXPECT_EQ(1, observer_->num_invocations()); | 292 EXPECT_EQ(1, observer_->num_invocations()); |
| 301 EXPECT_EQ(1, observer_->num_fullscreens()); | 293 EXPECT_EQ(1, observer_->num_fullscreens()); |
| 302 EXPECT_EQ(0, observer_->num_not_fullscreens()); | 294 EXPECT_EQ(0, observer_->num_not_fullscreens()); |
| 303 | 295 |
| 304 // Make the first window non-fullscreen and open a second fullscreen window on | 296 // Make the first window non-fullscreen and open a second fullscreen window on |
| 305 // a different desktop. | 297 // a different desktop. |
| 306 window_state->OnWMEvent(&toggle_fullscreen_event); | 298 window_state->OnWMEvent(&toggle_fullscreen_event); |
| 307 ASSERT_FALSE(window_state->IsFullscreen()); | 299 ASSERT_FALSE(window_state->IsFullscreen()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 332 AdvanceTime(base::TimeDelta::FromSeconds(2)); | 324 AdvanceTime(base::TimeDelta::FromSeconds(2)); |
| 333 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) | 325 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) |
| 334 detector_->OnDelegatedFrameDamage(window.get(), kUpdateRegion); | 326 detector_->OnDelegatedFrameDamage(window.get(), kUpdateRegion); |
| 335 EXPECT_EQ(1, observer_->num_invocations()); | 327 EXPECT_EQ(1, observer_->num_invocations()); |
| 336 EXPECT_EQ(0, observer_->num_fullscreens()); | 328 EXPECT_EQ(0, observer_->num_fullscreens()); |
| 337 EXPECT_EQ(1, observer_->num_not_fullscreens()); | 329 EXPECT_EQ(1, observer_->num_not_fullscreens()); |
| 338 } | 330 } |
| 339 | 331 |
| 340 } // namespace test | 332 } // namespace test |
| 341 } // namespace ash | 333 } // namespace ash |
| OLD | NEW |