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

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

Issue 11421006: Desktop aura: Break aura::Window::SetParent in two. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix ash_unittests Created 8 years 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/user_activity_detector_unittest.cc ('k') | ash/wm/visibility_controller_unittest.cc » ('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"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 93
94 base::TimeTicks now_; 94 base::TimeTicks now_;
95 95
96 private: 96 private:
97 DISALLOW_COPY_AND_ASSIGN(VideoDetectorTest); 97 DISALLOW_COPY_AND_ASSIGN(VideoDetectorTest);
98 }; 98 };
99 99
100 TEST_F(VideoDetectorTest, Basic) { 100 TEST_F(VideoDetectorTest, Basic) {
101 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768)); 101 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768));
102 scoped_ptr<aura::Window> window( 102 scoped_ptr<aura::Window> window(
103 aura::test::CreateTestWindow(SK_ColorRED, 12345, window_bounds, NULL)); 103 CreateTestWindowInShell(SK_ColorRED, 12345, window_bounds));
104 104
105 // Send enough updates, but make them be too small to trigger detection. 105 // Send enough updates, but make them be too small to trigger detection.
106 gfx::Rect update_region( 106 gfx::Rect update_region(
107 gfx::Point(), 107 gfx::Point(),
108 gfx::Size(VideoDetector::kMinUpdateWidth - 1, 108 gfx::Size(VideoDetector::kMinUpdateWidth - 1,
109 VideoDetector::kMinUpdateHeight)); 109 VideoDetector::kMinUpdateHeight));
110 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) 110 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i)
111 detector_->OnWindowPaintScheduled(window.get(), update_region); 111 detector_->OnWindowPaintScheduled(window.get(), update_region);
112 EXPECT_EQ(0, observer_->num_invocations()); 112 EXPECT_EQ(0, observer_->num_invocations());
113 113
(...skipping 25 matching lines...) Expand all
139 detector_->OnWindowPaintScheduled(window.get(), update_region); 139 detector_->OnWindowPaintScheduled(window.get(), update_region);
140 AdvanceTime(base::TimeDelta::FromSeconds(1)); 140 AdvanceTime(base::TimeDelta::FromSeconds(1));
141 for (int i = 0; i < VideoDetector::kMinFramesPerSecond - 1; ++i) 141 for (int i = 0; i < VideoDetector::kMinFramesPerSecond - 1; ++i)
142 detector_->OnWindowPaintScheduled(window.get(), update_region); 142 detector_->OnWindowPaintScheduled(window.get(), update_region);
143 EXPECT_EQ(0, observer_->num_invocations()); 143 EXPECT_EQ(0, observer_->num_invocations());
144 } 144 }
145 145
146 TEST_F(VideoDetectorTest, WindowNotVisible) { 146 TEST_F(VideoDetectorTest, WindowNotVisible) {
147 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768)); 147 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768));
148 scoped_ptr<aura::Window> window( 148 scoped_ptr<aura::Window> window(
149 aura::test::CreateTestWindow(SK_ColorRED, 12345, window_bounds, NULL)); 149 CreateTestWindowInShell(SK_ColorRED, 12345, window_bounds));
150 150
151 // Reparent the window to the root to make sure that visibility changes aren't 151 // Reparent the window to the root to make sure that visibility changes aren't
152 // animated. 152 // animated.
153 Shell::GetPrimaryRootWindow()->AddChild(window.get()); 153 Shell::GetPrimaryRootWindow()->AddChild(window.get());
154 154
155 // We shouldn't report video that's played in a hidden window. 155 // We shouldn't report video that's played in a hidden window.
156 window->Hide(); 156 window->Hide();
157 gfx::Rect update_region( 157 gfx::Rect update_region(
158 gfx::Point(), 158 gfx::Point(),
159 gfx::Size(VideoDetector::kMinUpdateWidth, 159 gfx::Size(VideoDetector::kMinUpdateWidth,
(...skipping 22 matching lines...) Expand all
182 ASSERT_EQ(offscreen_bounds, window->bounds()); 182 ASSERT_EQ(offscreen_bounds, window->bounds());
183 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) 183 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i)
184 detector_->OnWindowPaintScheduled(window.get(), update_region); 184 detector_->OnWindowPaintScheduled(window.get(), update_region);
185 EXPECT_EQ(0, observer_->num_invocations()); 185 EXPECT_EQ(0, observer_->num_invocations());
186 } 186 }
187 187
188 TEST_F(VideoDetectorTest, MultipleWindows) { 188 TEST_F(VideoDetectorTest, MultipleWindows) {
189 // Create two windows. 189 // Create two windows.
190 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768)); 190 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768));
191 scoped_ptr<aura::Window> window1( 191 scoped_ptr<aura::Window> window1(
192 aura::test::CreateTestWindow(SK_ColorRED, 12345, window_bounds, NULL)); 192 CreateTestWindowInShell(SK_ColorRED, 12345, window_bounds));
193 scoped_ptr<aura::Window> window2( 193 scoped_ptr<aura::Window> window2(
194 aura::test::CreateTestWindow(SK_ColorBLUE, 23456, window_bounds, NULL)); 194 CreateTestWindowInShell(SK_ColorBLUE, 23456, window_bounds));
195 195
196 // Even if there's video playing in both, the observer should only receive a 196 // Even if there's video playing in both, the observer should only receive a
197 // single notification. 197 // single notification.
198 gfx::Rect update_region( 198 gfx::Rect update_region(
199 gfx::Point(), 199 gfx::Point(),
200 gfx::Size(VideoDetector::kMinUpdateWidth, 200 gfx::Size(VideoDetector::kMinUpdateWidth,
201 VideoDetector::kMinUpdateHeight)); 201 VideoDetector::kMinUpdateHeight));
202 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) 202 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i)
203 detector_->OnWindowPaintScheduled(window1.get(), update_region); 203 detector_->OnWindowPaintScheduled(window1.get(), update_region);
204 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) 204 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i)
205 detector_->OnWindowPaintScheduled(window2.get(), update_region); 205 detector_->OnWindowPaintScheduled(window2.get(), update_region);
206 EXPECT_EQ(1, observer_->num_invocations()); 206 EXPECT_EQ(1, observer_->num_invocations());
207 EXPECT_EQ(0, observer_->num_fullscreens()); 207 EXPECT_EQ(0, observer_->num_fullscreens());
208 EXPECT_EQ(1, observer_->num_not_fullscreens()); 208 EXPECT_EQ(1, observer_->num_not_fullscreens());
209 } 209 }
210 210
211 // Test that the observer receives repeated notifications. 211 // Test that the observer receives repeated notifications.
212 TEST_F(VideoDetectorTest, RepeatedNotifications) { 212 TEST_F(VideoDetectorTest, RepeatedNotifications) {
213 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768)); 213 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768));
214 scoped_ptr<aura::Window> window( 214 scoped_ptr<aura::Window> window(
215 aura::test::CreateTestWindow(SK_ColorRED, 12345, window_bounds, NULL)); 215 CreateTestWindowInShell(SK_ColorRED, 12345, window_bounds));
216 216
217 gfx::Rect update_region( 217 gfx::Rect update_region(
218 gfx::Point(), 218 gfx::Point(),
219 gfx::Size(VideoDetector::kMinUpdateWidth, 219 gfx::Size(VideoDetector::kMinUpdateWidth,
220 VideoDetector::kMinUpdateHeight)); 220 VideoDetector::kMinUpdateHeight));
221 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) 221 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i)
222 detector_->OnWindowPaintScheduled(window.get(), update_region); 222 detector_->OnWindowPaintScheduled(window.get(), update_region);
223 EXPECT_EQ(1, observer_->num_invocations()); 223 EXPECT_EQ(1, observer_->num_invocations());
224 EXPECT_EQ(0, observer_->num_fullscreens()); 224 EXPECT_EQ(0, observer_->num_fullscreens());
225 EXPECT_EQ(1, observer_->num_not_fullscreens()); 225 EXPECT_EQ(1, observer_->num_not_fullscreens());
226 // Let enough time pass that a second notification should be sent. 226 // Let enough time pass that a second notification should be sent.
227 observer_->reset_stats(); 227 observer_->reset_stats();
228 AdvanceTime(base::TimeDelta::FromSeconds( 228 AdvanceTime(base::TimeDelta::FromSeconds(
229 static_cast<int64>(VideoDetector::kNotifyIntervalSec + 1))); 229 static_cast<int64>(VideoDetector::kNotifyIntervalSec + 1)));
230 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) 230 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i)
231 detector_->OnWindowPaintScheduled(window.get(), update_region); 231 detector_->OnWindowPaintScheduled(window.get(), update_region);
232 EXPECT_EQ(1, observer_->num_invocations()); 232 EXPECT_EQ(1, observer_->num_invocations());
233 EXPECT_EQ(0, observer_->num_fullscreens()); 233 EXPECT_EQ(0, observer_->num_fullscreens());
234 EXPECT_EQ(1, observer_->num_not_fullscreens()); 234 EXPECT_EQ(1, observer_->num_not_fullscreens());
235 } 235 }
236 236
237 // Test that the observer receives a true value when the window is fullscreen. 237 // Test that the observer receives a true value when the window is fullscreen.
238 TEST_F(VideoDetectorTest, FullscreenWindow) { 238 TEST_F(VideoDetectorTest, FullscreenWindow) {
239 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768)); 239 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768));
240 scoped_ptr<aura::Window> window( 240 scoped_ptr<aura::Window> window(
241 aura::test::CreateTestWindow(SK_ColorRED, 12345, window_bounds, NULL)); 241 CreateTestWindowInShell(SK_ColorRED, 12345, window_bounds));
242 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); 242 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
243 window->Focus(); 243 window->Focus();
244 gfx::Rect update_region( 244 gfx::Rect update_region(
245 gfx::Point(), 245 gfx::Point(),
246 gfx::Size(VideoDetector::kMinUpdateWidth, 246 gfx::Size(VideoDetector::kMinUpdateWidth,
247 VideoDetector::kMinUpdateHeight)); 247 VideoDetector::kMinUpdateHeight));
248 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) 248 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i)
249 detector_->OnWindowPaintScheduled(window.get(), update_region); 249 detector_->OnWindowPaintScheduled(window.get(), update_region);
250 EXPECT_EQ(1, observer_->num_invocations()); 250 EXPECT_EQ(1, observer_->num_invocations());
251 EXPECT_EQ(1, observer_->num_fullscreens()); 251 EXPECT_EQ(1, observer_->num_fullscreens());
252 EXPECT_EQ(0, observer_->num_not_fullscreens()); 252 EXPECT_EQ(0, observer_->num_not_fullscreens());
253 } 253 }
254 254
255 } // namespace test 255 } // namespace test
256 } // namespace ash 256 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/user_activity_detector_unittest.cc ('k') | ash/wm/visibility_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698