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

Side by Side Diff: ash/wallpaper/wallpaper_controller_unittest.cc

Issue 2814243002: Removes a couple more functions from WmWindow (Closed)
Patch Set: feedback Created 3 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/system/tray/tray_event_filter.cc ('k') | ash/wm/always_on_top_controller.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/wallpaper/wallpaper_controller.h" 5 #include "ash/wallpaper/wallpaper_controller.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <cstdlib> 8 #include <cstdlib>
9 9
10 #include "ash/ash_switches.h" 10 #include "ash/ash_switches.h"
11 #include "ash/public/cpp/config.h" 11 #include "ash/public/cpp/config.h"
12 #include "ash/public/cpp/shell_window_ids.h" 12 #include "ash/public/cpp/shell_window_ids.h"
13 #include "ash/root_window_controller.h" 13 #include "ash/root_window_controller.h"
14 #include "ash/session/session_controller.h" 14 #include "ash/session/session_controller.h"
15 #include "ash/shell.h" 15 #include "ash/shell.h"
16 #include "ash/shell_port.h"
17 #include "ash/test/ash_test_base.h" 16 #include "ash/test/ash_test_base.h"
18 #include "ash/test/test_session_controller_client.h" 17 #include "ash/test/test_session_controller_client.h"
19 #include "ash/test/test_wallpaper_delegate.h" 18 #include "ash/test/test_wallpaper_delegate.h"
20 #include "ash/wallpaper/wallpaper_view.h" 19 #include "ash/wallpaper/wallpaper_view.h"
21 #include "ash/wallpaper/wallpaper_widget_controller.h" 20 #include "ash/wallpaper/wallpaper_widget_controller.h"
22 #include "ash/wm_window.h" 21 #include "ash/wm_window.h"
23 #include "base/command_line.h" 22 #include "base/command_line.h"
24 #include "base/message_loop/message_loop.h" 23 #include "base/message_loop/message_loop.h"
25 #include "base/run_loop.h" 24 #include "base/run_loop.h"
26 #include "base/strings/stringprintf.h" 25 #include "base/strings/stringprintf.h"
27 #include "base/threading/sequenced_worker_pool.h" 26 #include "base/threading/sequenced_worker_pool.h"
28 #include "third_party/skia/include/core/SkBitmap.h" 27 #include "third_party/skia/include/core/SkBitmap.h"
29 #include "third_party/skia/include/core/SkColor.h" 28 #include "third_party/skia/include/core/SkColor.h"
29 #include "ui/aura/window.h"
30 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 30 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
31 #include "ui/compositor/test/layer_animator_test_controller.h" 31 #include "ui/compositor/test/layer_animator_test_controller.h"
32 #include "ui/gfx/canvas.h" 32 #include "ui/gfx/canvas.h"
33 #include "ui/views/widget/widget.h" 33 #include "ui/views/widget/widget.h"
34 34
35 using wallpaper::WALLPAPER_LAYOUT_CENTER; 35 using wallpaper::WALLPAPER_LAYOUT_CENTER;
36 using wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED; 36 using wallpaper::WALLPAPER_LAYOUT_CENTER_CROPPED;
37 using wallpaper::WALLPAPER_LAYOUT_STRETCH; 37 using wallpaper::WALLPAPER_LAYOUT_STRETCH;
38 using wallpaper::WALLPAPER_LAYOUT_TILE; 38 using wallpaper::WALLPAPER_LAYOUT_TILE;
39 39
40 using session_manager::SessionState; 40 using session_manager::SessionState;
41 41
42 namespace ash { 42 namespace ash {
43 namespace { 43 namespace {
44 44
45 // Containers IDs used for tests. 45 // Containers IDs used for tests.
46 const int kWallpaperId = ash::kShellWindowId_WallpaperContainer; 46 const int kWallpaperId = ash::kShellWindowId_WallpaperContainer;
47 const int kLockScreenWallpaperId = 47 const int kLockScreenWallpaperId =
48 ash::kShellWindowId_LockScreenWallpaperContainer; 48 ash::kShellWindowId_LockScreenWallpaperContainer;
49 49
50 // Returns number of child windows in a shell window container. 50 // Returns number of child windows in a shell window container.
51 int ChildCountForContainer(int container_id) { 51 int ChildCountForContainer(int container_id) {
52 WmWindow* root = ShellPort::Get()->GetPrimaryRootWindow(); 52 aura::Window* root = Shell::Get()->GetPrimaryRootWindow();
53 WmWindow* container = root->GetChildByShellWindowId(container_id); 53 aura::Window* container = root->GetChildById(container_id);
54 return static_cast<int>(container->GetChildren().size()); 54 return static_cast<int>(container->children().size());
55 } 55 }
56 56
57 // Steps a widget's layer animation until it is completed. Animations must be 57 // Steps a widget's layer animation until it is completed. Animations must be
58 // enabled. 58 // enabled.
59 void RunAnimationForWidget(views::Widget* widget) { 59 void RunAnimationForWidget(views::Widget* widget) {
60 // Animations must be enabled for stepping to work. 60 // Animations must be enabled for stepping to work.
61 ASSERT_NE(ui::ScopedAnimationDurationScaleMode::duration_scale_mode(), 61 ASSERT_NE(ui::ScopedAnimationDurationScaleMode::duration_scale_mode(),
62 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); 62 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION);
63 63
64 ui::Layer* layer = widget->GetLayer(); 64 ui::Layer* layer = widget->GetLayer();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 public: 113 public:
114 WallpaperControllerTest() 114 WallpaperControllerTest()
115 : controller_(nullptr), wallpaper_delegate_(nullptr) {} 115 : controller_(nullptr), wallpaper_delegate_(nullptr) {}
116 ~WallpaperControllerTest() override {} 116 ~WallpaperControllerTest() override {}
117 117
118 void SetUp() override { 118 void SetUp() override {
119 test::AshTestBase::SetUp(); 119 test::AshTestBase::SetUp();
120 // Ash shell initialization creates wallpaper. Reset it so we can manually 120 // Ash shell initialization creates wallpaper. Reset it so we can manually
121 // control wallpaper creation and animation in our tests. 121 // control wallpaper creation and animation in our tests.
122 RootWindowController* root_window_controller = 122 RootWindowController* root_window_controller =
123 ShellPort::Get()->GetPrimaryRootWindow()->GetRootWindowController(); 123 Shell::Get()->GetPrimaryRootWindowController();
124 root_window_controller->SetWallpaperWidgetController(nullptr); 124 root_window_controller->SetWallpaperWidgetController(nullptr);
125 root_window_controller->SetAnimatingWallpaperWidgetController(nullptr); 125 root_window_controller->SetAnimatingWallpaperWidgetController(nullptr);
126 controller_ = Shell::Get()->wallpaper_controller(); 126 controller_ = Shell::Get()->wallpaper_controller();
127 wallpaper_delegate_ = static_cast<test::TestWallpaperDelegate*>( 127 wallpaper_delegate_ = static_cast<test::TestWallpaperDelegate*>(
128 Shell::Get()->wallpaper_delegate()); 128 Shell::Get()->wallpaper_delegate());
129 controller_->set_wallpaper_reload_delay_for_test(0); 129 controller_->set_wallpaper_reload_delay_for_test(0);
130 } 130 }
131 131
132 WallpaperView* wallpaper_view() { 132 WallpaperView* wallpaper_view() {
133 WallpaperWidgetController* controller = 133 WallpaperWidgetController* controller =
134 ShellPort::Get() 134 Shell::Get()
135 ->GetPrimaryRootWindow() 135 ->GetPrimaryRootWindowController()
136 ->GetRootWindowController()
137 ->animating_wallpaper_widget_controller() 136 ->animating_wallpaper_widget_controller()
138 ->GetController(false); 137 ->GetController(false);
139 EXPECT_TRUE(controller); 138 EXPECT_TRUE(controller);
140 return static_cast<WallpaperView*>( 139 return static_cast<WallpaperView*>(
141 controller->widget()->GetContentsView()->child_at(0)); 140 controller->widget()->GetContentsView()->child_at(0));
142 } 141 }
143 142
144 protected: 143 protected:
145 // A color that can be passed to CreateImage(). Specifically chosen to not 144 // A color that can be passed to CreateImage(). Specifically chosen to not
146 // conflict with any of the default wallpaper colors. 145 // conflict with any of the default wallpaper colors.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 EXPECT_EQ(SK_ColorBLACK, bitmap.getColor(i, j)); 179 EXPECT_EQ(SK_ColorBLACK, bitmap.getColor(i, j));
181 } 180 }
182 } 181 }
183 } 182 }
184 } 183 }
185 184
186 // Runs AnimatingWallpaperWidgetController's animation to completion. 185 // Runs AnimatingWallpaperWidgetController's animation to completion.
187 // TODO(bshe): Don't require tests to run animations; it's slow. 186 // TODO(bshe): Don't require tests to run animations; it's slow.
188 void RunDesktopControllerAnimation() { 187 void RunDesktopControllerAnimation() {
189 WallpaperWidgetController* controller = 188 WallpaperWidgetController* controller =
190 ShellPort::Get() 189 Shell::Get()
191 ->GetPrimaryRootWindow() 190 ->GetPrimaryRootWindowController()
192 ->GetRootWindowController()
193 ->animating_wallpaper_widget_controller() 191 ->animating_wallpaper_widget_controller()
194 ->GetController(false); 192 ->GetController(false);
195 EXPECT_TRUE(controller); 193 EXPECT_TRUE(controller);
196 ASSERT_NO_FATAL_FAILURE(RunAnimationForWidget(controller->widget())); 194 ASSERT_NO_FATAL_FAILURE(RunAnimationForWidget(controller->widget()));
197 } 195 }
198 196
199 // Convenience function to ensure ShouldCalculateColors() returns true. 197 // Convenience function to ensure ShouldCalculateColors() returns true.
200 void EnableShelfColoring() { 198 void EnableShelfColoring() {
201 const gfx::ImageSkia kImage = CreateImage(10, 10, kCustomWallpaperColor); 199 const gfx::ImageSkia kImage = CreateImage(10, 10, kCustomWallpaperColor);
202 controller_->SetWallpaperImage(kImage, WALLPAPER_LAYOUT_STRETCH); 200 controller_->SetWallpaperImage(kImage, WALLPAPER_LAYOUT_STRETCH);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 // We cannot short-circuit animations for this test. 257 // We cannot short-circuit animations for this test.
260 ui::ScopedAnimationDurationScaleMode test_duration_mode( 258 ui::ScopedAnimationDurationScaleMode test_duration_mode(
261 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); 259 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
262 260
263 // Create the wallpaper and its view. 261 // Create the wallpaper and its view.
264 WallpaperController* controller = Shell::Get()->wallpaper_controller(); 262 WallpaperController* controller = Shell::Get()->wallpaper_controller();
265 controller->CreateEmptyWallpaper(); 263 controller->CreateEmptyWallpaper();
266 264
267 // The new wallpaper is ready to animate. 265 // The new wallpaper is ready to animate.
268 RootWindowController* root_window_controller = 266 RootWindowController* root_window_controller =
269 ShellPort::Get()->GetPrimaryRootWindow()->GetRootWindowController(); 267 Shell::Get()->GetPrimaryRootWindowController();
270 EXPECT_TRUE(root_window_controller->animating_wallpaper_widget_controller() 268 EXPECT_TRUE(root_window_controller->animating_wallpaper_widget_controller()
271 ->GetController(false)); 269 ->GetController(false));
272 EXPECT_FALSE(root_window_controller->wallpaper_widget_controller()); 270 EXPECT_FALSE(root_window_controller->wallpaper_widget_controller());
273 271
274 // Force the animation to play to completion. 272 // Force the animation to play to completion.
275 RunDesktopControllerAnimation(); 273 RunDesktopControllerAnimation();
276 EXPECT_FALSE(root_window_controller->animating_wallpaper_widget_controller() 274 EXPECT_FALSE(root_window_controller->animating_wallpaper_widget_controller()
277 ->GetController(false)); 275 ->GetController(false));
278 EXPECT_TRUE(root_window_controller->wallpaper_widget_controller()); 276 EXPECT_TRUE(root_window_controller->wallpaper_widget_controller());
279 } 277 }
(...skipping 15 matching lines...) Expand all
295 // User locks the screen, which moves the wallpaper forward. 293 // User locks the screen, which moves the wallpaper forward.
296 controller->MoveToLockedContainer(); 294 controller->MoveToLockedContainer();
297 295
298 // Suspend/resume cycle causes wallpaper to refresh, loading a new wallpaper 296 // Suspend/resume cycle causes wallpaper to refresh, loading a new wallpaper
299 // that will animate in on top of the old one. 297 // that will animate in on top of the old one.
300 controller->CreateEmptyWallpaper(); 298 controller->CreateEmptyWallpaper();
301 299
302 // In this state we have two wallpaper views stored in different properties. 300 // In this state we have two wallpaper views stored in different properties.
303 // Both are in the lock screen wallpaper container. 301 // Both are in the lock screen wallpaper container.
304 RootWindowController* root_window_controller = 302 RootWindowController* root_window_controller =
305 ShellPort::Get()->GetPrimaryRootWindow()->GetRootWindowController(); 303 Shell::Get()->GetPrimaryRootWindowController();
306 EXPECT_TRUE(root_window_controller->animating_wallpaper_widget_controller() 304 EXPECT_TRUE(root_window_controller->animating_wallpaper_widget_controller()
307 ->GetController(false)); 305 ->GetController(false));
308 EXPECT_TRUE(root_window_controller->wallpaper_widget_controller()); 306 EXPECT_TRUE(root_window_controller->wallpaper_widget_controller());
309 EXPECT_EQ(0, ChildCountForContainer(kWallpaperId)); 307 EXPECT_EQ(0, ChildCountForContainer(kWallpaperId));
310 EXPECT_EQ(2, ChildCountForContainer(kLockScreenWallpaperId)); 308 EXPECT_EQ(2, ChildCountForContainer(kLockScreenWallpaperId));
311 309
312 // Before the wallpaper's animation completes, user unlocks the screen, which 310 // Before the wallpaper's animation completes, user unlocks the screen, which
313 // moves the wallpaper to the back. 311 // moves the wallpaper to the back.
314 controller->MoveToUnlockedContainer(); 312 controller->MoveToUnlockedContainer();
315 313
(...skipping 20 matching lines...) Expand all
336 WallpaperController* controller = Shell::Get()->wallpaper_controller(); 334 WallpaperController* controller = Shell::Get()->wallpaper_controller();
337 controller->CreateEmptyWallpaper(); 335 controller->CreateEmptyWallpaper();
338 336
339 // Run wallpaper show animation to completion. 337 // Run wallpaper show animation to completion.
340 RunDesktopControllerAnimation(); 338 RunDesktopControllerAnimation();
341 339
342 // Change to a new wallpaper. 340 // Change to a new wallpaper.
343 controller->CreateEmptyWallpaper(); 341 controller->CreateEmptyWallpaper();
344 342
345 RootWindowController* root_window_controller = 343 RootWindowController* root_window_controller =
346 ShellPort::Get()->GetPrimaryRootWindow()->GetRootWindowController(); 344 Shell::Get()->GetPrimaryRootWindowController();
347 WallpaperWidgetController* animating_controller = 345 WallpaperWidgetController* animating_controller =
348 root_window_controller->animating_wallpaper_widget_controller() 346 root_window_controller->animating_wallpaper_widget_controller()
349 ->GetController(false); 347 ->GetController(false);
350 EXPECT_TRUE(animating_controller); 348 EXPECT_TRUE(animating_controller);
351 EXPECT_TRUE(root_window_controller->wallpaper_widget_controller()); 349 EXPECT_TRUE(root_window_controller->wallpaper_widget_controller());
352 350
353 // Change to another wallpaper before animation finished. 351 // Change to another wallpaper before animation finished.
354 controller->CreateEmptyWallpaper(); 352 controller->CreateEmptyWallpaper();
355 353
356 // The animating controller should immediately move to wallpaper controller. 354 // The animating controller should immediately move to wallpaper controller.
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 EXPECT_TRUE(ShouldCalculateColors()); 524 EXPECT_TRUE(ShouldCalculateColors());
527 525
528 SetSessionState(SessionState::LOCKED); 526 SetSessionState(SessionState::LOCKED);
529 EXPECT_FALSE(ShouldCalculateColors()); 527 EXPECT_FALSE(ShouldCalculateColors());
530 528
531 SetSessionState(SessionState::LOGIN_SECONDARY); 529 SetSessionState(SessionState::LOGIN_SECONDARY);
532 EXPECT_FALSE(ShouldCalculateColors()); 530 EXPECT_FALSE(ShouldCalculateColors());
533 } 531 }
534 532
535 } // namespace ash 533 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/tray/tray_event_filter.cc ('k') | ash/wm/always_on_top_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698