Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: ash/wm/video_detector_unittest.cc

Issue 10913134: Add is_fullscreen to video updates (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix outstanding issue with unit test Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/wm/video_detector.cc ('k') | chrome/browser/chromeos/power/video_activity_notifier.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ash/wm/window_util.h" 9 #include "ash/wm/window_util.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/time.h" 12 #include "base/time.h"
13 #include "third_party/skia/include/core/SkColor.h" 13 #include "third_party/skia/include/core/SkColor.h"
14 #include "ui/aura/client/aura_constants.h"
14 #include "ui/aura/client/window_types.h" 15 #include "ui/aura/client/window_types.h"
15 #include "ui/aura/root_window.h" 16 #include "ui/aura/root_window.h"
16 #include "ui/aura/test/test_windows.h" 17 #include "ui/aura/test/test_windows.h"
17 #include "ui/aura/window.h" 18 #include "ui/aura/window.h"
18 #include "ui/gfx/rect.h" 19 #include "ui/gfx/rect.h"
19 20
20 namespace ash { 21 namespace ash {
21 namespace test { 22 namespace test {
22 23
23 // Implementation that just counts the number of times we've been told that a 24 // Implementation that just counts the number of times we've been told that a
24 // video is playing. 25 // video is playing.
25 class TestVideoDetectorObserver : public VideoDetectorObserver { 26 class TestVideoDetectorObserver : public VideoDetectorObserver {
26 public: 27 public:
27 TestVideoDetectorObserver() : num_invocations_(0) {} 28 TestVideoDetectorObserver() : num_invocations_(0),
29 num_fullscreens_(0),
30 num_not_fullscreens_(0) {}
28 31
29 int num_invocations() const { return num_invocations_; } 32 int num_invocations() const { return num_invocations_; }
30 void reset_stats() { num_invocations_ = 0; } 33 int num_fullscreens() const { return num_fullscreens_; }
34 int num_not_fullscreens() const { return num_not_fullscreens_; }
35 void reset_stats() {
36 num_invocations_ = 0;
37 num_fullscreens_ = 0;
38 num_not_fullscreens_ = 0;
39 }
31 40
32 // VideoDetectorObserver implementation. 41 // VideoDetectorObserver implementation.
33 virtual void OnVideoDetected() OVERRIDE { num_invocations_++; } 42 virtual void OnVideoDetected(bool is_fullscreen) OVERRIDE {
43 num_invocations_++;
44 if (is_fullscreen)
45 num_fullscreens_++;
46 else
47 num_not_fullscreens_++;
48 }
34 49
35 private: 50 private:
36 // Number of times that OnVideoDetected() has been called. 51 // Number of times that OnVideoDetected() has been called.
37 int num_invocations_; 52 int num_invocations_;
53 // Number of times that OnVideoDetected() has been called with is_fullscreen
54 // == true.
55 int num_fullscreens_;
56 // Number of times that OnVideoDetected() has been called with is_fullscreen
57 // == false.
58 int num_not_fullscreens_;
38 59
39 DISALLOW_COPY_AND_ASSIGN(TestVideoDetectorObserver); 60 DISALLOW_COPY_AND_ASSIGN(TestVideoDetectorObserver);
40 }; 61 };
41 62
42 class VideoDetectorTest : public AshTestBase { 63 class VideoDetectorTest : public AshTestBase {
43 public: 64 public:
44 VideoDetectorTest() {} 65 VideoDetectorTest() {}
45 virtual ~VideoDetectorTest() {} 66 virtual ~VideoDetectorTest() {}
46 67
47 virtual void SetUp() OVERRIDE { 68 virtual void SetUp() OVERRIDE {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 gfx::Size(VideoDetector::kMinUpdateWidth, 118 gfx::Size(VideoDetector::kMinUpdateWidth,
98 VideoDetector::kMinUpdateHeight)); 119 VideoDetector::kMinUpdateHeight));
99 for (int i = 0; i < VideoDetector::kMinFramesPerSecond - 1; ++i) 120 for (int i = 0; i < VideoDetector::kMinFramesPerSecond - 1; ++i)
100 detector_->OnWindowPaintScheduled(window.get(), update_region); 121 detector_->OnWindowPaintScheduled(window.get(), update_region);
101 EXPECT_EQ(0, observer_->num_invocations()); 122 EXPECT_EQ(0, observer_->num_invocations());
102 123
103 // 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
104 // additional updates. 125 // additional updates.
105 detector_->OnWindowPaintScheduled(window.get(), update_region); 126 detector_->OnWindowPaintScheduled(window.get(), update_region);
106 EXPECT_EQ(1, observer_->num_invocations()); 127 EXPECT_EQ(1, observer_->num_invocations());
128 EXPECT_EQ(0, observer_->num_fullscreens());
129 EXPECT_EQ(1, observer_->num_not_fullscreens());
107 detector_->OnWindowPaintScheduled(window.get(), update_region); 130 detector_->OnWindowPaintScheduled(window.get(), update_region);
108 EXPECT_EQ(1, observer_->num_invocations()); 131 EXPECT_EQ(1, observer_->num_invocations());
132 EXPECT_EQ(0, observer_->num_fullscreens());
133 EXPECT_EQ(1, observer_->num_not_fullscreens());
109 134
110 // Spread out the frames over two seconds; we shouldn't detect video. 135 // Spread out the frames over two seconds; we shouldn't detect video.
111 observer_->reset_stats(); 136 observer_->reset_stats();
112 AdvanceTime(base::TimeDelta::FromSeconds(2)); 137 AdvanceTime(base::TimeDelta::FromSeconds(2));
113 for (int i = 0; i < VideoDetector::kMinFramesPerSecond - 1; ++i) 138 for (int i = 0; i < VideoDetector::kMinFramesPerSecond - 1; ++i)
114 detector_->OnWindowPaintScheduled(window.get(), update_region); 139 detector_->OnWindowPaintScheduled(window.get(), update_region);
115 AdvanceTime(base::TimeDelta::FromSeconds(1)); 140 AdvanceTime(base::TimeDelta::FromSeconds(1));
116 for (int i = 0; i < VideoDetector::kMinFramesPerSecond - 1; ++i) 141 for (int i = 0; i < VideoDetector::kMinFramesPerSecond - 1; ++i)
117 detector_->OnWindowPaintScheduled(window.get(), update_region); 142 detector_->OnWindowPaintScheduled(window.get(), update_region);
118 EXPECT_EQ(0, observer_->num_invocations()); 143 EXPECT_EQ(0, observer_->num_invocations());
(...skipping 18 matching lines...) Expand all
137 detector_->OnWindowPaintScheduled(window.get(), update_region); 162 detector_->OnWindowPaintScheduled(window.get(), update_region);
138 EXPECT_EQ(0, observer_->num_invocations()); 163 EXPECT_EQ(0, observer_->num_invocations());
139 164
140 // Make the window visible and send more updates. 165 // Make the window visible and send more updates.
141 observer_->reset_stats(); 166 observer_->reset_stats();
142 AdvanceTime(base::TimeDelta::FromSeconds(2)); 167 AdvanceTime(base::TimeDelta::FromSeconds(2));
143 window->Show(); 168 window->Show();
144 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) 169 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i)
145 detector_->OnWindowPaintScheduled(window.get(), update_region); 170 detector_->OnWindowPaintScheduled(window.get(), update_region);
146 EXPECT_EQ(1, observer_->num_invocations()); 171 EXPECT_EQ(1, observer_->num_invocations());
172 EXPECT_EQ(0, observer_->num_fullscreens());
173 EXPECT_EQ(1, observer_->num_not_fullscreens());
147 174
148 // We also shouldn't report video in a window that's fully offscreen. 175 // We also shouldn't report video in a window that's fully offscreen.
149 observer_->reset_stats(); 176 observer_->reset_stats();
150 AdvanceTime(base::TimeDelta::FromSeconds(2)); 177 AdvanceTime(base::TimeDelta::FromSeconds(2));
151 gfx::Rect offscreen_bounds( 178 gfx::Rect offscreen_bounds(
152 gfx::Point(Shell::GetPrimaryRootWindow()->bounds().width(), 0), 179 gfx::Point(Shell::GetPrimaryRootWindow()->bounds().width(), 0),
153 window_bounds.size()); 180 window_bounds.size());
154 window->SetBounds(offscreen_bounds); 181 window->SetBounds(offscreen_bounds);
155 ASSERT_EQ(offscreen_bounds, window->bounds()); 182 ASSERT_EQ(offscreen_bounds, window->bounds());
156 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) 183 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i)
(...skipping 13 matching lines...) Expand all
170 // single notification. 197 // single notification.
171 gfx::Rect update_region( 198 gfx::Rect update_region(
172 gfx::Point(), 199 gfx::Point(),
173 gfx::Size(VideoDetector::kMinUpdateWidth, 200 gfx::Size(VideoDetector::kMinUpdateWidth,
174 VideoDetector::kMinUpdateHeight)); 201 VideoDetector::kMinUpdateHeight));
175 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) 202 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i)
176 detector_->OnWindowPaintScheduled(window1.get(), update_region); 203 detector_->OnWindowPaintScheduled(window1.get(), update_region);
177 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) 204 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i)
178 detector_->OnWindowPaintScheduled(window2.get(), update_region); 205 detector_->OnWindowPaintScheduled(window2.get(), update_region);
179 EXPECT_EQ(1, observer_->num_invocations()); 206 EXPECT_EQ(1, observer_->num_invocations());
207 EXPECT_EQ(0, observer_->num_fullscreens());
208 EXPECT_EQ(1, observer_->num_not_fullscreens());
180 } 209 }
181 210
182 // Test that the observer receives repeated notifications. 211 // Test that the observer receives repeated notifications.
183 TEST_F(VideoDetectorTest, RepeatedNotifications) { 212 TEST_F(VideoDetectorTest, RepeatedNotifications) {
184 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768)); 213 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768));
185 scoped_ptr<aura::Window> window( 214 scoped_ptr<aura::Window> window(
186 aura::test::CreateTestWindow(SK_ColorRED, 12345, window_bounds, NULL)); 215 aura::test::CreateTestWindow(SK_ColorRED, 12345, window_bounds, NULL));
187 216
188 gfx::Rect update_region( 217 gfx::Rect update_region(
189 gfx::Point(), 218 gfx::Point(),
190 gfx::Size(VideoDetector::kMinUpdateWidth, 219 gfx::Size(VideoDetector::kMinUpdateWidth,
191 VideoDetector::kMinUpdateHeight)); 220 VideoDetector::kMinUpdateHeight));
192 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) 221 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i)
193 detector_->OnWindowPaintScheduled(window.get(), update_region); 222 detector_->OnWindowPaintScheduled(window.get(), update_region);
194 EXPECT_EQ(1, observer_->num_invocations()); 223 EXPECT_EQ(1, observer_->num_invocations());
195 224 EXPECT_EQ(0, observer_->num_fullscreens());
225 EXPECT_EQ(1, observer_->num_not_fullscreens());
196 // Let enough time pass that a second notification should be sent. 226 // Let enough time pass that a second notification should be sent.
197 observer_->reset_stats(); 227 observer_->reset_stats();
198 AdvanceTime(base::TimeDelta::FromSeconds( 228 AdvanceTime(base::TimeDelta::FromSeconds(
199 static_cast<int64>(VideoDetector::kNotifyIntervalSec + 1))); 229 static_cast<int64>(VideoDetector::kNotifyIntervalSec + 1)));
200 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) 230 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i)
201 detector_->OnWindowPaintScheduled(window.get(), update_region); 231 detector_->OnWindowPaintScheduled(window.get(), update_region);
202 EXPECT_EQ(1, observer_->num_invocations()); 232 EXPECT_EQ(1, observer_->num_invocations());
233 EXPECT_EQ(0, observer_->num_fullscreens());
234 EXPECT_EQ(1, observer_->num_not_fullscreens());
235 }
236
237 // Test that the observer receives a true value when the window is fullscreen.
238 TEST_F(VideoDetectorTest, FullscreenWindow) {
239 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768));
240 scoped_ptr<aura::Window> window(
241 aura::test::CreateTestWindow(SK_ColorRED, 12345, window_bounds, NULL));
242 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
243 window->Focus();
244 gfx::Rect update_region(
245 gfx::Point(),
246 gfx::Size(VideoDetector::kMinUpdateWidth,
247 VideoDetector::kMinUpdateHeight));
248 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i)
249 detector_->OnWindowPaintScheduled(window.get(), update_region);
250 EXPECT_EQ(1, observer_->num_invocations());
251 EXPECT_EQ(1, observer_->num_fullscreens());
252 EXPECT_EQ(0, observer_->num_not_fullscreens());
203 } 253 }
204 254
205 } // namespace test 255 } // namespace test
206 } // namespace ash 256 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/video_detector.cc ('k') | chrome/browser/chromeos/power/video_activity_notifier.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698