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

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

Issue 1867223004: Convert //ash from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 4 years, 8 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
« no previous file with comments | « ash/wm/toplevel_window_event_handler_unittest.cc ('k') | ash/wm/window_animations.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 <memory>
8
7 #include "ash/shell.h" 9 #include "ash/shell.h"
8 #include "ash/test/ash_test_base.h" 10 #include "ash/test/ash_test_base.h"
9 #include "ash/wm/window_state.h" 11 #include "ash/wm/window_state.h"
10 #include "ash/wm/wm_event.h" 12 #include "ash/wm/wm_event.h"
11 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/time/time.h" 14 #include "base/time/time.h"
14 #include "third_party/skia/include/core/SkColor.h" 15 #include "third_party/skia/include/core/SkColor.h"
15 #include "ui/aura/client/aura_constants.h" 16 #include "ui/aura/client/aura_constants.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/aura/window_event_dispatcher.h" 19 #include "ui/aura/window_event_dispatcher.h"
19 #include "ui/gfx/geometry/rect.h" 20 #include "ui/gfx/geometry/rect.h"
20 #include "ui/wm/public/window_types.h" 21 #include "ui/wm/public/window_types.h"
21 22
22 namespace ash { 23 namespace ash {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 84
84 protected: 85 protected:
85 // Move |detector_|'s idea of the current time forward by |delta|. 86 // Move |detector_|'s idea of the current time forward by |delta|.
86 void AdvanceTime(base::TimeDelta delta) { 87 void AdvanceTime(base::TimeDelta delta) {
87 now_ += delta; 88 now_ += delta;
88 detector_->set_now_for_test(now_); 89 detector_->set_now_for_test(now_);
89 } 90 }
90 91
91 VideoDetector* detector_; // not owned 92 VideoDetector* detector_; // not owned
92 93
93 scoped_ptr<TestVideoDetectorObserver> observer_; 94 std::unique_ptr<TestVideoDetectorObserver> observer_;
94 95
95 base::TimeTicks now_; 96 base::TimeTicks now_;
96 97
97 private: 98 private:
98 DISALLOW_COPY_AND_ASSIGN(VideoDetectorTest); 99 DISALLOW_COPY_AND_ASSIGN(VideoDetectorTest);
99 }; 100 };
100 101
101 TEST_F(VideoDetectorTest, Basic) { 102 TEST_F(VideoDetectorTest, Basic) {
102 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768)); 103 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768));
103 scoped_ptr<aura::Window> window( 104 std::unique_ptr<aura::Window> window(
104 CreateTestWindowInShell(SK_ColorRED, 12345, window_bounds)); 105 CreateTestWindowInShell(SK_ColorRED, 12345, window_bounds));
105 106
106 // Send enough updates, but make them be too small to trigger detection. 107 // Send enough updates, but make them be too small to trigger detection.
107 gfx::Rect update_region( 108 gfx::Rect update_region(
108 gfx::Point(), 109 gfx::Point(),
109 gfx::Size(VideoDetector::kMinUpdateWidth - 1, 110 gfx::Size(VideoDetector::kMinUpdateWidth - 1,
110 VideoDetector::kMinUpdateHeight)); 111 VideoDetector::kMinUpdateHeight));
111 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) 112 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i)
112 detector_->OnDelegatedFrameDamage(window.get(), update_region); 113 detector_->OnDelegatedFrameDamage(window.get(), update_region);
113 EXPECT_EQ(0, observer_->num_invocations()); 114 EXPECT_EQ(0, observer_->num_invocations());
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 1000 / (VideoDetector::kMinFramesPerSecond - 2)); 163 1000 / (VideoDetector::kMinFramesPerSecond - 2));
163 for (int i = 0; i < kNumFrames; ++i) { 164 for (int i = 0; i < kNumFrames; ++i) {
164 AdvanceTime(kSlowInterval); 165 AdvanceTime(kSlowInterval);
165 detector_->OnDelegatedFrameDamage(window.get(), update_region); 166 detector_->OnDelegatedFrameDamage(window.get(), update_region);
166 } 167 }
167 EXPECT_EQ(2, observer_->num_invocations()); 168 EXPECT_EQ(2, observer_->num_invocations());
168 } 169 }
169 170
170 TEST_F(VideoDetectorTest, Shutdown) { 171 TEST_F(VideoDetectorTest, Shutdown) {
171 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768)); 172 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768));
172 scoped_ptr<aura::Window> window( 173 std::unique_ptr<aura::Window> window(
173 CreateTestWindowInShell(SK_ColorRED, 12345, window_bounds)); 174 CreateTestWindowInShell(SK_ColorRED, 12345, window_bounds));
174 gfx::Rect update_region( 175 gfx::Rect update_region(
175 gfx::Point(), 176 gfx::Point(),
176 gfx::Size(VideoDetector::kMinUpdateWidth, 177 gfx::Size(VideoDetector::kMinUpdateWidth,
177 VideoDetector::kMinUpdateHeight)); 178 VideoDetector::kMinUpdateHeight));
178 179
179 // It should not detect video during the shutdown. 180 // It should not detect video during the shutdown.
180 Shell::GetInstance()->OnAppTerminating(); 181 Shell::GetInstance()->OnAppTerminating();
181 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) 182 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i)
182 detector_->OnDelegatedFrameDamage(window.get(), update_region); 183 detector_->OnDelegatedFrameDamage(window.get(), update_region);
183 EXPECT_EQ(0, observer_->num_invocations()); 184 EXPECT_EQ(0, observer_->num_invocations());
184 } 185 }
185 186
186 TEST_F(VideoDetectorTest, WindowNotVisible) { 187 TEST_F(VideoDetectorTest, WindowNotVisible) {
187 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768)); 188 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768));
188 scoped_ptr<aura::Window> window( 189 std::unique_ptr<aura::Window> window(
189 CreateTestWindowInShell(SK_ColorRED, 12345, window_bounds)); 190 CreateTestWindowInShell(SK_ColorRED, 12345, window_bounds));
190 191
191 // Reparent the window to the root to make sure that visibility changes aren't 192 // Reparent the window to the root to make sure that visibility changes aren't
192 // animated. 193 // animated.
193 Shell::GetPrimaryRootWindow()->AddChild(window.get()); 194 Shell::GetPrimaryRootWindow()->AddChild(window.get());
194 195
195 // We shouldn't report video that's played in a hidden window. 196 // We shouldn't report video that's played in a hidden window.
196 window->Hide(); 197 window->Hide();
197 gfx::Rect update_region( 198 gfx::Rect update_region(
198 gfx::Point(), 199 gfx::Point(),
(...skipping 22 matching lines...) Expand all
221 window->SetBounds(offscreen_bounds); 222 window->SetBounds(offscreen_bounds);
222 ASSERT_EQ(offscreen_bounds, window->bounds()); 223 ASSERT_EQ(offscreen_bounds, window->bounds());
223 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) 224 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i)
224 detector_->OnDelegatedFrameDamage(window.get(), update_region); 225 detector_->OnDelegatedFrameDamage(window.get(), update_region);
225 EXPECT_EQ(0, observer_->num_invocations()); 226 EXPECT_EQ(0, observer_->num_invocations());
226 } 227 }
227 228
228 TEST_F(VideoDetectorTest, MultipleWindows) { 229 TEST_F(VideoDetectorTest, MultipleWindows) {
229 // Create two windows. 230 // Create two windows.
230 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768)); 231 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768));
231 scoped_ptr<aura::Window> window1( 232 std::unique_ptr<aura::Window> window1(
232 CreateTestWindowInShell(SK_ColorRED, 12345, window_bounds)); 233 CreateTestWindowInShell(SK_ColorRED, 12345, window_bounds));
233 scoped_ptr<aura::Window> window2( 234 std::unique_ptr<aura::Window> window2(
234 CreateTestWindowInShell(SK_ColorBLUE, 23456, window_bounds)); 235 CreateTestWindowInShell(SK_ColorBLUE, 23456, window_bounds));
235 236
236 // Even if there's video playing in both, the observer should only receive a 237 // Even if there's video playing in both, the observer should only receive a
237 // single notification. 238 // single notification.
238 gfx::Rect update_region( 239 gfx::Rect update_region(
239 gfx::Point(), 240 gfx::Point(),
240 gfx::Size(VideoDetector::kMinUpdateWidth, 241 gfx::Size(VideoDetector::kMinUpdateWidth,
241 VideoDetector::kMinUpdateHeight)); 242 VideoDetector::kMinUpdateHeight));
242 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) 243 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i)
243 detector_->OnDelegatedFrameDamage(window1.get(), update_region); 244 detector_->OnDelegatedFrameDamage(window1.get(), update_region);
244 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) 245 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i)
245 detector_->OnDelegatedFrameDamage(window2.get(), update_region); 246 detector_->OnDelegatedFrameDamage(window2.get(), update_region);
246 EXPECT_EQ(1, observer_->num_invocations()); 247 EXPECT_EQ(1, observer_->num_invocations());
247 EXPECT_EQ(0, observer_->num_fullscreens()); 248 EXPECT_EQ(0, observer_->num_fullscreens());
248 EXPECT_EQ(1, observer_->num_not_fullscreens()); 249 EXPECT_EQ(1, observer_->num_not_fullscreens());
249 } 250 }
250 251
251 // Test that the observer receives repeated notifications. 252 // Test that the observer receives repeated notifications.
252 TEST_F(VideoDetectorTest, RepeatedNotifications) { 253 TEST_F(VideoDetectorTest, RepeatedNotifications) {
253 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768)); 254 gfx::Rect window_bounds(gfx::Point(), gfx::Size(1024, 768));
254 scoped_ptr<aura::Window> window( 255 std::unique_ptr<aura::Window> window(
255 CreateTestWindowInShell(SK_ColorRED, 12345, window_bounds)); 256 CreateTestWindowInShell(SK_ColorRED, 12345, window_bounds));
256 257
257 gfx::Rect update_region( 258 gfx::Rect update_region(
258 gfx::Point(), 259 gfx::Point(),
259 gfx::Size(VideoDetector::kMinUpdateWidth, 260 gfx::Size(VideoDetector::kMinUpdateWidth,
260 VideoDetector::kMinUpdateHeight)); 261 VideoDetector::kMinUpdateHeight));
261 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) 262 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i)
262 detector_->OnDelegatedFrameDamage(window.get(), update_region); 263 detector_->OnDelegatedFrameDamage(window.get(), update_region);
263 EXPECT_EQ(1, observer_->num_invocations()); 264 EXPECT_EQ(1, observer_->num_invocations());
264 EXPECT_EQ(0, observer_->num_fullscreens()); 265 EXPECT_EQ(0, observer_->num_fullscreens());
(...skipping 10 matching lines...) Expand all
275 } 276 }
276 277
277 // Test that the observer receives a true value when the window is fullscreen. 278 // Test that the observer receives a true value when the window is fullscreen.
278 TEST_F(VideoDetectorTest, FullscreenWindow) { 279 TEST_F(VideoDetectorTest, FullscreenWindow) {
279 if (!SupportsMultipleDisplays()) 280 if (!SupportsMultipleDisplays())
280 return; 281 return;
281 282
282 UpdateDisplay("1024x768,1024x768"); 283 UpdateDisplay("1024x768,1024x768");
283 284
284 const gfx::Rect kLeftBounds(gfx::Point(), gfx::Size(1024, 768)); 285 const gfx::Rect kLeftBounds(gfx::Point(), gfx::Size(1024, 768));
285 scoped_ptr<aura::Window> window( 286 std::unique_ptr<aura::Window> window(
286 CreateTestWindowInShell(SK_ColorRED, 12345, kLeftBounds)); 287 CreateTestWindowInShell(SK_ColorRED, 12345, kLeftBounds));
287 wm::WindowState* window_state = wm::GetWindowState(window.get()); 288 wm::WindowState* window_state = wm::GetWindowState(window.get());
288 const wm::WMEvent toggle_fullscreen_event(wm::WM_EVENT_TOGGLE_FULLSCREEN); 289 const wm::WMEvent toggle_fullscreen_event(wm::WM_EVENT_TOGGLE_FULLSCREEN);
289 window_state->OnWMEvent(&toggle_fullscreen_event); 290 window_state->OnWMEvent(&toggle_fullscreen_event);
290 ASSERT_TRUE(window_state->IsFullscreen()); 291 ASSERT_TRUE(window_state->IsFullscreen());
291 window->Focus(); 292 window->Focus();
292 const gfx::Rect kUpdateRegion( 293 const gfx::Rect kUpdateRegion(
293 gfx::Point(), 294 gfx::Point(),
294 gfx::Size(VideoDetector::kMinUpdateWidth, 295 gfx::Size(VideoDetector::kMinUpdateWidth,
295 VideoDetector::kMinUpdateHeight)); 296 VideoDetector::kMinUpdateHeight));
296 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) 297 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i)
297 detector_->OnDelegatedFrameDamage(window.get(), kUpdateRegion); 298 detector_->OnDelegatedFrameDamage(window.get(), kUpdateRegion);
298 EXPECT_EQ(1, observer_->num_invocations()); 299 EXPECT_EQ(1, observer_->num_invocations());
299 EXPECT_EQ(1, observer_->num_fullscreens()); 300 EXPECT_EQ(1, observer_->num_fullscreens());
300 EXPECT_EQ(0, observer_->num_not_fullscreens()); 301 EXPECT_EQ(0, observer_->num_not_fullscreens());
301 302
302 // Make the first window non-fullscreen and open a second fullscreen window on 303 // Make the first window non-fullscreen and open a second fullscreen window on
303 // a different desktop. 304 // a different desktop.
304 window_state->OnWMEvent(&toggle_fullscreen_event); 305 window_state->OnWMEvent(&toggle_fullscreen_event);
305 ASSERT_FALSE(window_state->IsFullscreen()); 306 ASSERT_FALSE(window_state->IsFullscreen());
306 const gfx::Rect kRightBounds(gfx::Point(1024, 0), gfx::Size(1024, 768)); 307 const gfx::Rect kRightBounds(gfx::Point(1024, 0), gfx::Size(1024, 768));
307 scoped_ptr<aura::Window> other_window( 308 std::unique_ptr<aura::Window> other_window(
308 CreateTestWindowInShell(SK_ColorBLUE, 6789, kRightBounds)); 309 CreateTestWindowInShell(SK_ColorBLUE, 6789, kRightBounds));
309 wm::WindowState* other_window_state = wm::GetWindowState(other_window.get()); 310 wm::WindowState* other_window_state = wm::GetWindowState(other_window.get());
310 other_window_state->OnWMEvent(&toggle_fullscreen_event); 311 other_window_state->OnWMEvent(&toggle_fullscreen_event);
311 ASSERT_TRUE(other_window_state->IsFullscreen()); 312 ASSERT_TRUE(other_window_state->IsFullscreen());
312 313
313 // When video is detected in the first (now non-fullscreen) window, fullscreen 314 // When video is detected in the first (now non-fullscreen) window, fullscreen
314 // video should still be reported due to the second window being fullscreen. 315 // video should still be reported due to the second window being fullscreen.
315 // This avoids situations where non-fullscreen video could be reported when 316 // This avoids situations where non-fullscreen video could be reported when
316 // multiple videos are playing in fullscreen and non-fullscreen windows. 317 // multiple videos are playing in fullscreen and non-fullscreen windows.
317 observer_->reset_stats(); 318 observer_->reset_stats();
(...skipping 12 matching lines...) Expand all
330 AdvanceTime(base::TimeDelta::FromSeconds(2)); 331 AdvanceTime(base::TimeDelta::FromSeconds(2));
331 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i) 332 for (int i = 0; i < VideoDetector::kMinFramesPerSecond; ++i)
332 detector_->OnDelegatedFrameDamage(window.get(), kUpdateRegion); 333 detector_->OnDelegatedFrameDamage(window.get(), kUpdateRegion);
333 EXPECT_EQ(1, observer_->num_invocations()); 334 EXPECT_EQ(1, observer_->num_invocations());
334 EXPECT_EQ(0, observer_->num_fullscreens()); 335 EXPECT_EQ(0, observer_->num_fullscreens());
335 EXPECT_EQ(1, observer_->num_not_fullscreens()); 336 EXPECT_EQ(1, observer_->num_not_fullscreens());
336 } 337 }
337 338
338 } // namespace test 339 } // namespace test
339 } // namespace ash 340 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/toplevel_window_event_handler_unittest.cc ('k') | ash/wm/window_animations.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698