video_detector_unittest.cc revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/wm/video_detector.h" 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/shell.h" 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/test/ash_test_base.h" 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ash/wm/window_util.h" 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/compiler_specific.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/time.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "third_party/skia/include/core/SkColor.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/client/aura_constants.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/client/window_types.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/root_window.h" 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/test/test_windows.h" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/aura/window.h" 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/rect.h" 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ash { 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace test { 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Implementation that just counts the number of times we've been told that a 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// video is playing. 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class TestVideoDetectorObserver : public VideoDetectorObserver { 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) TestVideoDetectorObserver() : num_invocations_(0), 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) num_fullscreens_(0), 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) num_not_fullscreens_(0) {} 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int num_invocations() const { return num_invocations_; } 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int num_fullscreens() const { return num_fullscreens_; } 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int num_not_fullscreens() const { return num_not_fullscreens_; } 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void reset_stats() { 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) num_invocations_ = 0; 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) num_fullscreens_ = 0; 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) num_not_fullscreens_ = 0; 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // VideoDetectorObserver implementation. 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnVideoDetected(bool is_fullscreen) OVERRIDE { 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) num_invocations_++; 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (is_fullscreen) 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) num_fullscreens_++; 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) else 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) num_not_fullscreens_++; 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Number of times that OnVideoDetected() has been called. 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int num_invocations_; 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Number of times that OnVideoDetected() has been called with is_fullscreen 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // == true. 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int num_fullscreens_; 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Number of times that OnVideoDetected() has been called with is_fullscreen 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // == false. 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int num_not_fullscreens_; 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(TestVideoDetectorObserver); 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class VideoDetectorTest : public AshTestBase { 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VideoDetectorTest() {} 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~VideoDetectorTest() {} 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void SetUp() OVERRIDE { 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AshTestBase::SetUp(); 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer_.reset(new TestVideoDetectorObserver); 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) detector_ = Shell::GetInstance()->video_detector(); 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) detector_->AddObserver(observer_.get()); 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) now_ = base::TimeTicks::Now(); 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) detector_->set_now_for_test(now_); 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void TearDown() OVERRIDE { 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) detector_->RemoveObserver(observer_.get()); 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AshTestBase::TearDown(); 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Move |detector_|'s idea of the current time forward by |delta|. 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void AdvanceTime(base::TimeDelta delta) { 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) now_ += delta; 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) detector_->set_now_for_test(now_); 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VideoDetector* detector_; // not owned 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<TestVideoDetectorObserver> observer_; 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::TimeTicks now_; 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(VideoDetectorTest); 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(VideoDetectorTest, Basic) { 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768)); 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<aura::Window> window( 1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CreateTestWindowInShell(SK_ColorRED, 12345, window_bounds)); 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Send enough updates, but make them be too small to trigger detection. 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect update_region( 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Point(), 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Size(VideoDetector::kMinUpdateWidth - 1, 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VideoDetector::kMinUpdateHeight)); 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) detector_->OnWindowPaintScheduled(window.get(), update_region); 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, observer_->num_invocations()); 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Send not-quite-enough adaquately-sized updates. 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer_->reset_stats(); 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AdvanceTime(base::TimeDelta::FromSeconds(2)); 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) update_region.set_size( 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Size(VideoDetector::kMinUpdateWidth, 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VideoDetector::kMinUpdateHeight)); 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (int i = 0; i < VideoDetector::kMinFramesPerSecond - 1; ++i) 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) detector_->OnWindowPaintScheduled(window.get(), update_region); 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, observer_->num_invocations()); 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // We should get notified after the next update, but not in response to 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // additional updates. 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) detector_->OnWindowPaintScheduled(window.get(), update_region); 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(1, observer_->num_invocations()); 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, observer_->num_fullscreens()); 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(1, observer_->num_not_fullscreens()); 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) detector_->OnWindowPaintScheduled(window.get(), update_region); 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(1, observer_->num_invocations()); 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, observer_->num_fullscreens()); 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(1, observer_->num_not_fullscreens()); 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Spread out the frames over two seconds; we shouldn't detect video. 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer_->reset_stats(); 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AdvanceTime(base::TimeDelta::FromSeconds(2)); 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (int i = 0; i < VideoDetector::kMinFramesPerSecond - 1; ++i) 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) detector_->OnWindowPaintScheduled(window.get(), update_region); 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AdvanceTime(base::TimeDelta::FromSeconds(1)); 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (int i = 0; i < VideoDetector::kMinFramesPerSecond - 1; ++i) 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) detector_->OnWindowPaintScheduled(window.get(), update_region); 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, observer_->num_invocations()); 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(VideoDetectorTest, WindowNotVisible) { 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768)); 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<aura::Window> window( 1492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CreateTestWindowInShell(SK_ColorRED, 12345, window_bounds)); 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Reparent the window to the root to make sure that visibility changes aren't 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // animated. 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Shell::GetPrimaryRootWindow()->AddChild(window.get()); 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // We shouldn't report video that's played in a hidden window. 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window->Hide(); 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect update_region( 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Point(), 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Size(VideoDetector::kMinUpdateWidth, 1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VideoDetector::kMinUpdateHeight)); 1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) 1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) detector_->OnWindowPaintScheduled(window.get(), update_region); 1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, observer_->num_invocations()); 1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Make the window visible and send more updates. 1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer_->reset_stats(); 1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AdvanceTime(base::TimeDelta::FromSeconds(2)); 1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window->Show(); 1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) detector_->OnWindowPaintScheduled(window.get(), update_region); 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(1, observer_->num_invocations()); 1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, observer_->num_fullscreens()); 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(1, observer_->num_not_fullscreens()); 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // We also shouldn't report video in a window that's fully offscreen. 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer_->reset_stats(); 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AdvanceTime(base::TimeDelta::FromSeconds(2)); 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect offscreen_bounds( 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Point(Shell::GetPrimaryRootWindow()->bounds().width(), 0), 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_bounds.size()); 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window->SetBounds(offscreen_bounds); 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(offscreen_bounds, window->bounds()); 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) detector_->OnWindowPaintScheduled(window.get(), update_region); 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, observer_->num_invocations()); 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(VideoDetectorTest, MultipleWindows) { 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Create two windows. 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768)); 1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<aura::Window> window1( 1922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CreateTestWindowInShell(SK_ColorRED, 12345, window_bounds)); 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<aura::Window> window2( 1942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CreateTestWindowInShell(SK_ColorBLUE, 23456, window_bounds)); 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Even if there's video playing in both, the observer should only receive a 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // single notification. 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect update_region( 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Point(), 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Size(VideoDetector::kMinUpdateWidth, 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VideoDetector::kMinUpdateHeight)); 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) detector_->OnWindowPaintScheduled(window1.get(), update_region); 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) detector_->OnWindowPaintScheduled(window2.get(), update_region); 2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(1, observer_->num_invocations()); 2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, observer_->num_fullscreens()); 2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(1, observer_->num_not_fullscreens()); 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Test that the observer receives repeated notifications. 2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(VideoDetectorTest, RepeatedNotifications) { 2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768)); 2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<aura::Window> window( 2152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CreateTestWindowInShell(SK_ColorRED, 12345, window_bounds)); 2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect update_region( 2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Point(), 2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Size(VideoDetector::kMinUpdateWidth, 2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VideoDetector::kMinUpdateHeight)); 2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) 2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) detector_->OnWindowPaintScheduled(window.get(), update_region); 2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(1, observer_->num_invocations()); 2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, observer_->num_fullscreens()); 2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(1, observer_->num_not_fullscreens()); 2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Let enough time pass that a second notification should be sent. 2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) observer_->reset_stats(); 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) AdvanceTime(base::TimeDelta::FromSeconds( 2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static_cast<int64>(VideoDetector::kNotifyIntervalSec + 1))); 2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) 2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) detector_->OnWindowPaintScheduled(window.get(), update_region); 2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(1, observer_->num_invocations()); 2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, observer_->num_fullscreens()); 2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(1, observer_->num_not_fullscreens()); 2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Test that the observer receives a true value when the window is fullscreen. 2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(VideoDetectorTest, FullscreenWindow) { 2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768)); 2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<aura::Window> window( 2412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CreateTestWindowInShell(SK_ColorRED, 12345, window_bounds)); 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); 2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window->Focus(); 2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Rect update_region( 2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Point(), 2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::Size(VideoDetector::kMinUpdateWidth, 2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VideoDetector::kMinUpdateHeight)); 2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) 2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) detector_->OnWindowPaintScheduled(window.get(), update_region); 2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(1, observer_->num_invocations()); 2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(1, observer_->num_fullscreens()); 2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0, observer_->num_not_fullscreens()); 2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace test 2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace ash 257