| Index: ash/wm/video_detector_unittest.cc
|
| diff --git a/ash/wm/video_detector_unittest.cc b/ash/wm/video_detector_unittest.cc
|
| index 0730ee7b7e50968ca9b08da0b23939667fa989c7..01688e640893881a41b8ab4aabb512bab3034d1f 100644
|
| --- a/ash/wm/video_detector_unittest.cc
|
| +++ b/ash/wm/video_detector_unittest.cc
|
| @@ -6,6 +6,7 @@
|
|
|
| #include "ash/shell.h"
|
| #include "ash/test/ash_test_base.h"
|
| +#include "ash/wm/mock_video_detector_observer.h"
|
| #include "base/compiler_specific.h"
|
| #include "base/memory/scoped_ptr.h"
|
| #include "base/time.h"
|
| @@ -16,28 +17,11 @@
|
| #include "ui/aura/window.h"
|
| #include "ui/gfx/rect.h"
|
|
|
| +using ::testing::StrictMock;
|
| +
|
| namespace ash {
|
| namespace test {
|
|
|
| -// Implementation that just counts the number of times we've been told that a
|
| -// video is playing.
|
| -class TestVideoDetectorObserver : public VideoDetectorObserver {
|
| - public:
|
| - TestVideoDetectorObserver() : num_invocations_(0) {}
|
| -
|
| - int num_invocations() const { return num_invocations_; }
|
| - void reset_stats() { num_invocations_ = 0; }
|
| -
|
| - // VideoDetectorObserver implementation.
|
| - virtual void OnVideoDetected() OVERRIDE { num_invocations_++; }
|
| -
|
| - private:
|
| - // Number of times that OnVideoDetected() has been called.
|
| - int num_invocations_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(TestVideoDetectorObserver);
|
| -};
|
| -
|
| class VideoDetectorTest : public AshTestBase {
|
| public:
|
| VideoDetectorTest() {}
|
| @@ -45,7 +29,6 @@ class VideoDetectorTest : public AshTestBase {
|
|
|
| virtual void SetUp() OVERRIDE {
|
| AshTestBase::SetUp();
|
| - observer_.reset(new TestVideoDetectorObserver);
|
| detector_ = Shell::GetInstance()->video_detector();
|
| detector_->AddObserver(observer_.get());
|
|
|
| @@ -67,7 +50,7 @@ class VideoDetectorTest : public AshTestBase {
|
|
|
| VideoDetector* detector_; // not owned
|
|
|
| - scoped_ptr<TestVideoDetectorObserver> observer_;
|
| + StrictMock<MockVideoDetectorObserver> observer_;
|
|
|
| base::TimeTicks now_;
|
|
|
| @@ -87,34 +70,33 @@ TEST_F(VideoDetectorTest, Basic) {
|
| VideoDetector::kMinUpdateHeight));
|
| for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i)
|
| detector_->OnWindowPaintScheduled(window.get(), update_region);
|
| - EXPECT_EQ(0, observer_->num_invocations());
|
| + EXPECT_TRUE(Mock::VerifyAndClearExpectations(&observer_));
|
|
|
| // Send not-quite-enough adaquately-sized updates.
|
| - observer_->reset_stats();
|
| AdvanceTime(base::TimeDelta::FromSeconds(2));
|
| update_region.set_size(
|
| gfx::Size(VideoDetector::kMinUpdateWidth,
|
| VideoDetector::kMinUpdateHeight));
|
| for (int i = 0; i < VideoDetector::kMinFramesPerSecond - 1; ++i)
|
| detector_->OnWindowPaintScheduled(window.get(), update_region);
|
| - EXPECT_EQ(0, observer_->num_invocations());
|
| + Mock::VerifyAndClearExpectations(&observer_);
|
|
|
| // We should get notified after the next update, but not in response to
|
| // additional updates.
|
| + observer_.ExpectOnVideoDetected(false);
|
| detector_->OnWindowPaintScheduled(window.get(), update_region);
|
| - EXPECT_EQ(1, observer_->num_invocations());
|
| + Mock::VerifyAndClearExpectations(&observer_);
|
| + observer_.ExpectOnVideoDetected(false);
|
| detector_->OnWindowPaintScheduled(window.get(), update_region);
|
| - EXPECT_EQ(1, observer_->num_invocations());
|
| + Mock::VerifyAndClearExpectations(&observer_);
|
|
|
| // Spread out the frames over two seconds; we shouldn't detect video.
|
| - observer_->reset_stats();
|
| AdvanceTime(base::TimeDelta::FromSeconds(2));
|
| for (int i = 0; i < VideoDetector::kMinFramesPerSecond - 1; ++i)
|
| detector_->OnWindowPaintScheduled(window.get(), update_region);
|
| AdvanceTime(base::TimeDelta::FromSeconds(1));
|
| for (int i = 0; i < VideoDetector::kMinFramesPerSecond - 1; ++i)
|
| detector_->OnWindowPaintScheduled(window.get(), update_region);
|
| - EXPECT_EQ(0, observer_->num_invocations());
|
| }
|
|
|
| TEST_F(VideoDetectorTest, WindowNotVisible) {
|
| @@ -134,18 +116,17 @@ TEST_F(VideoDetectorTest, WindowNotVisible) {
|
| VideoDetector::kMinUpdateHeight));
|
| for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i)
|
| detector_->OnWindowPaintScheduled(window.get(), update_region);
|
| - EXPECT_EQ(0, observer_->num_invocations());
|
| + Mock::VerifyAndClearExpectations(&observer_);
|
|
|
| // Make the window visible and send more updates.
|
| - observer_->reset_stats();
|
| AdvanceTime(base::TimeDelta::FromSeconds(2));
|
| window->Show();
|
| + observer_.ExpectOnVideoDetected(false);
|
| for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i)
|
| detector_->OnWindowPaintScheduled(window.get(), update_region);
|
| - EXPECT_EQ(1, observer_->num_invocations());
|
| + Mock::VerifyAndClearExpectations(&observer_);
|
|
|
| // We also shouldn't report video in a window that's fully offscreen.
|
| - observer_->reset_stats();
|
| AdvanceTime(base::TimeDelta::FromSeconds(2));
|
| gfx::Rect offscreen_bounds(
|
| gfx::Point(Shell::GetPrimaryRootWindow()->bounds().width(), 0),
|
| @@ -154,7 +135,6 @@ TEST_F(VideoDetectorTest, WindowNotVisible) {
|
| ASSERT_EQ(offscreen_bounds, window->bounds());
|
| for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i)
|
| detector_->OnWindowPaintScheduled(window.get(), update_region);
|
| - EXPECT_EQ(0, observer_->num_invocations());
|
| }
|
|
|
| TEST_F(VideoDetectorTest, MultipleWindows) {
|
| @@ -171,11 +151,11 @@ TEST_F(VideoDetectorTest, MultipleWindows) {
|
| gfx::Point(),
|
| gfx::Size(VideoDetector::kMinUpdateWidth,
|
| VideoDetector::kMinUpdateHeight));
|
| + observer_.ExpectOnVideoDetected(false);
|
| for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i)
|
| detector_->OnWindowPaintScheduled(window1.get(), update_region);
|
| for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i)
|
| detector_->OnWindowPaintScheduled(window2.get(), update_region);
|
| - EXPECT_EQ(1, observer_->num_invocations());
|
| }
|
|
|
| // Test that the observer receives repeated notifications.
|
| @@ -188,17 +168,33 @@ TEST_F(VideoDetectorTest, RepeatedNotifications) {
|
| gfx::Point(),
|
| gfx::Size(VideoDetector::kMinUpdateWidth,
|
| VideoDetector::kMinUpdateHeight));
|
| + observer_.ExpectOnVideoDetected(false);
|
| for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i)
|
| detector_->OnWindowPaintScheduled(window.get(), update_region);
|
| - EXPECT_EQ(1, observer_->num_invocations());
|
| + Mock::VerifyAndClearExpectations(&observer_);
|
|
|
| // Let enough time pass that a second notification should be sent.
|
| - observer_->reset_stats();
|
| + observer_.ExpectOnVideoDetected(false);
|
| AdvanceTime(base::TimeDelta::FromSeconds(
|
| static_cast<int64>(VideoDetector::kNotifyIntervalSec + 1)));
|
| for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i)
|
| detector_->OnWindowPaintScheduled(window.get(), update_region);
|
| - EXPECT_EQ(1, observer_->num_invocations());
|
| +}
|
| +
|
| +// Test that the observer receives a true value when the window is fullscreen.
|
| +TEST_F(VideoDetectorTest, FullscreenWindow) {
|
| + 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));
|
| + observer_.ExpectOnVideoDetected(true);
|
| + for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i)
|
| + detector_->OnWindowPaintScheduled(window.get(), update_region);
|
| }
|
|
|
| } // namespace test
|
|
|