Chromium Code Reviews| Index: ash/wm/video_detector_unittest.cc |
| diff --git a/ash/wm/video_detector_unittest.cc b/ash/wm/video_detector_unittest.cc |
| index 2a7ffd92df34ac5d7aeb929a7fb43f0f7c28aeda..7fc72010b84f8da9de59384d711e0e3ea33c7750 100644 |
| --- a/ash/wm/video_detector_unittest.cc |
| +++ b/ash/wm/video_detector_unittest.cc |
| @@ -11,6 +11,7 @@ |
| #include "base/memory/scoped_ptr.h" |
| #include "base/time.h" |
| #include "third_party/skia/include/core/SkColor.h" |
| +#include "ui/aura/client/aura_constants.h" |
| #include "ui/aura/client/window_types.h" |
| #include "ui/aura/root_window.h" |
| #include "ui/aura/test/test_windows.h" |
| @@ -24,17 +25,37 @@ namespace test { |
| // video is playing. |
| class TestVideoDetectorObserver : public VideoDetectorObserver { |
| public: |
| - TestVideoDetectorObserver() : num_invocations_(0) {} |
| + TestVideoDetectorObserver() : num_invocations_(0), |
| + num_fullscreens_(0), |
| + num_not_fullscreens_(0) {} |
| int num_invocations() const { return num_invocations_; } |
| - void reset_stats() { num_invocations_ = 0; } |
| + int num_fullscreens() const { return num_fullscreens_; } |
| + int num_not_fullscreens() const { return num_not_fullscreens_; } |
| + void reset_stats() { |
| + num_invocations_ = 0; |
| + num_fullscreens_ = 0; |
| + num_not_fullscreens_ = 0; |
| + } |
| // VideoDetectorObserver implementation. |
| - virtual void OnVideoDetected() OVERRIDE { num_invocations_++; } |
| + virtual void OnVideoDetected(bool is_fullscreen) OVERRIDE { |
| + num_invocations_++; |
| + if (is_fullscreen) |
| + num_fullscreens_++; |
| + else |
| + num_not_fullscreens_++; |
| + } |
| private: |
| // Number of times that OnVideoDetected() has been called. |
| int num_invocations_; |
| + // Number of times that OnVideoDetected() has been called with is_fullscreen |
| + // == true. |
| + int num_fullscreens_; |
| + // Number of times that OnVideoDetected() has been called with is_fullscreen |
| + // == false. |
| + int num_not_fullscreens_; |
| DISALLOW_COPY_AND_ASSIGN(TestVideoDetectorObserver); |
| }; |
| @@ -104,8 +125,12 @@ TEST_F(VideoDetectorTest, Basic) { |
| // additional updates. |
| detector_->OnWindowPaintScheduled(window.get(), update_region); |
| EXPECT_EQ(1, observer_->num_invocations()); |
| + EXPECT_EQ(0, observer_->num_fullscreens()); |
| + EXPECT_EQ(1, observer_->num_not_fullscreens()); |
| detector_->OnWindowPaintScheduled(window.get(), update_region); |
| EXPECT_EQ(1, observer_->num_invocations()); |
| + EXPECT_EQ(0, observer_->num_fullscreens()); |
| + EXPECT_EQ(1, observer_->num_not_fullscreens()); |
| // Spread out the frames over two seconds; we shouldn't detect video. |
| observer_->reset_stats(); |
| @@ -144,6 +169,8 @@ TEST_F(VideoDetectorTest, WindowNotVisible) { |
| for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) |
| detector_->OnWindowPaintScheduled(window.get(), update_region); |
| EXPECT_EQ(1, observer_->num_invocations()); |
| + EXPECT_EQ(0, observer_->num_fullscreens()); |
| + EXPECT_EQ(1, observer_->num_not_fullscreens()); |
| // We also shouldn't report video in a window that's fully offscreen. |
| observer_->reset_stats(); |
| @@ -177,6 +204,8 @@ TEST_F(VideoDetectorTest, MultipleWindows) { |
| for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) |
| detector_->OnWindowPaintScheduled(window2.get(), update_region); |
| EXPECT_EQ(1, observer_->num_invocations()); |
| + EXPECT_EQ(0, observer_->num_fullscreens()); |
| + EXPECT_EQ(1, observer_->num_not_fullscreens()); |
| } |
| // Test that the observer receives repeated notifications. |
| @@ -192,7 +221,8 @@ TEST_F(VideoDetectorTest, RepeatedNotifications) { |
| for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) |
| detector_->OnWindowPaintScheduled(window.get(), update_region); |
| EXPECT_EQ(1, observer_->num_invocations()); |
| - |
| + EXPECT_EQ(0, observer_->num_fullscreens()); |
| + EXPECT_EQ(1, observer_->num_not_fullscreens()); |
| // Let enough time pass that a second notification should be sent. |
| observer_->reset_stats(); |
| AdvanceTime(base::TimeDelta::FromSeconds( |
| @@ -200,6 +230,32 @@ TEST_F(VideoDetectorTest, RepeatedNotifications) { |
| for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) |
| detector_->OnWindowPaintScheduled(window.get(), update_region); |
| EXPECT_EQ(1, observer_->num_invocations()); |
| + EXPECT_EQ(0, observer_->num_fullscreens()); |
| + EXPECT_EQ(1, observer_->num_not_fullscreens()); |
| +} |
| + |
| +// Test that the observer receives a true value when the window is fullscreen. |
| +// This test fails on Win Aura, but given it is testing whether a field for a |
| +// message to cros is correct it isn't signficant. |
| +#if defined(OS_WIN) |
| +TEST_F(VideoDetectorTest, DISABLED_FullscreenWindow) { |
|
flackr
2012/09/07 17:06:18
Typically I've seen us use the following pattern f
rharrison
2012/09/07 18:20:55
Done.
|
| +#else |
| +TEST_F(VideoDetectorTest, FullscreenWindow) { |
| +#endif |
| + gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768)); |
| + scoped_ptr<aura::Window> window( |
| + aura::test::CreateTestWindow(SK_ColorRED, 12345, window_bounds, NULL)); |
| + window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); |
| + |
| + gfx::Rect update_region( |
| + gfx::Point(), |
| + gfx::Size(VideoDetector::kMinUpdateWidth, |
| + VideoDetector::kMinUpdateHeight)); |
| + for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) |
| + detector_->OnWindowPaintScheduled(window.get(), update_region); |
| + EXPECT_EQ(1, observer_->num_invocations()); |
| + EXPECT_EQ(1, observer_->num_fullscreens()); |
| + EXPECT_EQ(0, observer_->num_not_fullscreens()); |
| } |
| } // namespace test |