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

Side by Side Diff: ash/common/wm/workspace/workspace_layout_manager_unittest.cc

Issue 2699033002: Replace WmWindowObserver with aura::WindowObserver. (Closed)
Patch Set: Check for null images in ShelfWindowWatcher. Created 3 years, 10 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
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/common/wm/workspace/workspace_layout_manager.h" 5 #include "ash/common/wm/workspace/workspace_layout_manager.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "ash/common/session/session_state_delegate.h" 10 #include "ash/common/session/session_state_delegate.h"
11 #include "ash/common/shelf/shelf_constants.h" 11 #include "ash/common/shelf/shelf_constants.h"
12 #include "ash/common/shelf/shelf_layout_manager.h" 12 #include "ash/common/shelf/shelf_layout_manager.h"
13 #include "ash/common/shelf/wm_shelf.h" 13 #include "ash/common/shelf/wm_shelf.h"
14 #include "ash/common/shell_observer.h" 14 #include "ash/common/shell_observer.h"
15 #include "ash/common/test/ash_test.h" 15 #include "ash/common/test/ash_test.h"
16 #include "ash/common/test/test_session_state_delegate.h" 16 #include "ash/common/test/test_session_state_delegate.h"
17 #include "ash/common/wm/fullscreen_window_finder.h" 17 #include "ash/common/wm/fullscreen_window_finder.h"
18 #include "ash/common/wm/maximize_mode/workspace_backdrop_delegate.h" 18 #include "ash/common/wm/maximize_mode/workspace_backdrop_delegate.h"
19 #include "ash/common/wm/window_state.h" 19 #include "ash/common/wm/window_state.h"
20 #include "ash/common/wm/wm_event.h" 20 #include "ash/common/wm/wm_event.h"
21 #include "ash/common/wm/wm_screen_util.h" 21 #include "ash/common/wm/wm_screen_util.h"
22 #include "ash/common/wm/workspace/workspace_window_resizer.h" 22 #include "ash/common/wm/workspace/workspace_window_resizer.h"
23 #include "ash/common/wm_lookup.h" 23 #include "ash/common/wm_lookup.h"
24 #include "ash/common/wm_shell.h" 24 #include "ash/common/wm_shell.h"
25 #include "ash/common/wm_window.h"
25 #include "ash/public/cpp/shell_window_ids.h" 26 #include "ash/public/cpp/shell_window_ids.h"
26 #include "ash/root_window_controller.h" 27 #include "ash/root_window_controller.h"
28 #include "ash/wm/window_state_aura.h"
27 #include "base/command_line.h" 29 #include "base/command_line.h"
28 #include "base/run_loop.h" 30 #include "base/run_loop.h"
29 #include "ui/aura/env.h" 31 #include "ui/aura/env.h"
30 #include "ui/base/ui_base_switches.h" 32 #include "ui/base/ui_base_switches.h"
31 #include "ui/base/ui_base_types.h" 33 #include "ui/base/ui_base_types.h"
32 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 34 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
33 #include "ui/display/display.h" 35 #include "ui/display/display.h"
34 #include "ui/display/screen.h" 36 #include "ui/display/screen.h"
35 #include "ui/gfx/geometry/insets.h" 37 #include "ui/gfx/geometry/insets.h"
36 #include "ui/views/widget/widget.h" 38 #include "ui/views/widget/widget.h"
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 window_state->SetRestoreBoundsInScreen(gfx::Rect(295, 0, 30, 40)); 287 window_state->SetRestoreBoundsInScreen(gfx::Rect(295, 0, 30, 40));
286 window->SetShowState(ui::SHOW_STATE_FULLSCREEN); 288 window->SetShowState(ui::SHOW_STATE_FULLSCREEN);
287 EXPECT_EQ(root_windows[1], window->GetRootWindow()); 289 EXPECT_EQ(root_windows[1], window->GetRootWindow());
288 EXPECT_EQ("300,0 400x500", window->GetBoundsInScreen().ToString()); 290 EXPECT_EQ("300,0 400x500", window->GetBoundsInScreen().ToString());
289 291
290 window_state->Restore(); 292 window_state->Restore();
291 EXPECT_EQ(root_windows[1], window->GetRootWindow()); 293 EXPECT_EQ(root_windows[1], window->GetRootWindow());
292 EXPECT_EQ("295,0 30x40", window->GetBoundsInScreen().ToString()); 294 EXPECT_EQ("295,0 30x40", window->GetBoundsInScreen().ToString());
293 } 295 }
294 296
295 // WmWindowObserver implementation used by 297 // aura::WindowObserver implementation used by
296 // DontClobberRestoreBoundsWindowObserver. This code mirrors what 298 // DontClobberRestoreBoundsWindowObserver. This code mirrors what
297 // BrowserFrameAsh does. In particular when this code sees the window was 299 // BrowserFrameAsh does. In particular when this code sees the window was
298 // maximized it changes the bounds of a secondary window. The secondary window 300 // maximized it changes the bounds of a secondary window. The secondary window
299 // mirrors the status window. 301 // mirrors the status window.
300 class DontClobberRestoreBoundsWindowObserver : public WmWindowObserver { 302 class DontClobberRestoreBoundsWindowObserver : public aura::WindowObserver {
301 public: 303 public:
302 DontClobberRestoreBoundsWindowObserver() : window_(nullptr) {} 304 DontClobberRestoreBoundsWindowObserver() : window_(nullptr) {}
303 305
304 void set_window(WmWindow* window) { window_ = window; } 306 void set_window(WmWindow* window) { window_ = window; }
305 307
306 // WmWindowObserver: 308 // aura::WindowObserver:
307 void OnWindowPropertyChanged(WmWindow* window, 309 void OnWindowPropertyChanged(aura::Window* window,
308 WmWindowProperty property) override { 310 const void* key,
311 intptr_t old) override {
309 if (!window_) 312 if (!window_)
310 return; 313 return;
311 314
312 if (window->GetWindowState()->IsMaximized()) { 315 if (wm::GetWindowState(window)->IsMaximized()) {
313 WmWindow* w = window_; 316 WmWindow* w = window_;
314 window_ = nullptr; 317 window_ = nullptr;
315 318
316 gfx::Rect shelf_bounds(AshTest::GetPrimaryShelf()->GetIdealBounds()); 319 gfx::Rect shelf_bounds(AshTest::GetPrimaryShelf()->GetIdealBounds());
317 const gfx::Rect& window_bounds(w->GetBounds()); 320 const gfx::Rect& window_bounds(w->GetBounds());
318 w->SetBounds(gfx::Rect(window_bounds.x(), shelf_bounds.y() - 1, 321 w->SetBounds(gfx::Rect(window_bounds.x(), shelf_bounds.y() - 1,
319 window_bounds.width(), window_bounds.height())); 322 window_bounds.width(), window_bounds.height()));
320 } 323 }
321 } 324 }
322 325
323 private: 326 private:
324 WmWindow* window_; 327 WmWindow* window_;
325 328
326 DISALLOW_COPY_AND_ASSIGN(DontClobberRestoreBoundsWindowObserver); 329 DISALLOW_COPY_AND_ASSIGN(DontClobberRestoreBoundsWindowObserver);
327 }; 330 };
328 331
329 // Creates a window, maximized the window and from within the maximized 332 // Creates a window, maximized the window and from within the maximized
330 // notification sets the bounds of a window to overlap the shelf. Verifies this 333 // notification sets the bounds of a window to overlap the shelf. Verifies this
331 // doesn't effect the restore bounds. 334 // doesn't effect the restore bounds.
332 TEST_F(WorkspaceLayoutManagerTest, DontClobberRestoreBounds) { 335 TEST_F(WorkspaceLayoutManagerTest, DontClobberRestoreBounds) {
333 DontClobberRestoreBoundsWindowObserver window_observer; 336 DontClobberRestoreBoundsWindowObserver window_observer;
334 WindowOwner window_owner(WmShell::Get()->NewWindow(ui::wm::WINDOW_TYPE_NORMAL, 337 WindowOwner window_owner(WmShell::Get()->NewWindow(ui::wm::WINDOW_TYPE_NORMAL,
335 ui::LAYER_TEXTURED)); 338 ui::LAYER_TEXTURED));
336 WmWindow* window = window_owner.window(); 339 WmWindow* window = window_owner.window();
337 window->SetBounds(gfx::Rect(10, 20, 30, 40)); 340 window->SetBounds(gfx::Rect(10, 20, 30, 40));
338 // NOTE: for this test to exercise the failure the observer needs to be added 341 // NOTE: for this test to exercise the failure the observer needs to be added
339 // before the parent set. This mimics what BrowserFrameAsh does. 342 // before the parent set. This mimics what BrowserFrameAsh does.
340 window->AddObserver(&window_observer); 343 window->aura_window()->AddObserver(&window_observer);
341 ParentWindowInPrimaryRootWindow(window); 344 ParentWindowInPrimaryRootWindow(window);
342 window->Show(); 345 window->Show();
343 346
344 wm::WindowState* window_state = window->GetWindowState(); 347 wm::WindowState* window_state = window->GetWindowState();
345 window_state->Activate(); 348 window_state->Activate();
346 349
347 std::unique_ptr<WindowOwner> window2_owner( 350 std::unique_ptr<WindowOwner> window2_owner(
348 CreateTestWindow(gfx::Rect(12, 20, 30, 40))); 351 CreateTestWindow(gfx::Rect(12, 20, 30, 40)));
349 WmWindow* window2 = window2_owner->window(); 352 WmWindow* window2 = window2_owner->window();
350 AddTransientChild(window, window2); 353 AddTransientChild(window, window2);
351 window2->Show(); 354 window2->Show();
352 355
353 window_observer.set_window(window2); 356 window_observer.set_window(window2);
354 window_state->Maximize(); 357 window_state->Maximize();
355 EXPECT_EQ("10,20 30x40", window_state->GetRestoreBoundsInScreen().ToString()); 358 EXPECT_EQ("10,20 30x40", window_state->GetRestoreBoundsInScreen().ToString());
356 window->RemoveObserver(&window_observer); 359 window->aura_window()->RemoveObserver(&window_observer);
357 } 360 }
358 361
359 // Verifies when a window is maximized all descendant windows have a size. 362 // Verifies when a window is maximized all descendant windows have a size.
360 TEST_F(WorkspaceLayoutManagerTest, ChildBoundsResetOnMaximize) { 363 TEST_F(WorkspaceLayoutManagerTest, ChildBoundsResetOnMaximize) {
361 std::unique_ptr<WindowOwner> window_owner( 364 std::unique_ptr<WindowOwner> window_owner(
362 CreateTestWindow(gfx::Rect(10, 20, 30, 40))); 365 CreateTestWindow(gfx::Rect(10, 20, 30, 40)));
363 WmWindow* window = window_owner->window(); 366 WmWindow* window = window_owner->window();
364 window->Show(); 367 window->Show();
365 wm::WindowState* window_state = window->GetWindowState(); 368 wm::WindowState* window_state = window->GetWindowState();
366 window_state->Activate(); 369 window_state->Activate();
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 std::unique_ptr<WindowOwner> window_owner(CreateTestWindow(bounds)); 614 std::unique_ptr<WindowOwner> window_owner(CreateTestWindow(bounds));
612 WmWindow* window = window_owner->window(); 615 WmWindow* window = window_owner->window();
613 window->SetShowState(ui::SHOW_STATE_MINIMIZED); 616 window->SetShowState(ui::SHOW_STATE_MINIMIZED);
614 // Note: Currently minimize doesn't do anything except set the state. 617 // Note: Currently minimize doesn't do anything except set the state.
615 // See crbug.com/104571. 618 // See crbug.com/104571.
616 EXPECT_EQ(bounds.ToString(), window->GetBounds().ToString()); 619 EXPECT_EQ(bounds.ToString(), window->GetBounds().ToString());
617 window->SetShowState(ui::SHOW_STATE_NORMAL); 620 window->SetShowState(ui::SHOW_STATE_NORMAL);
618 EXPECT_EQ(bounds.ToString(), window->GetBounds().ToString()); 621 EXPECT_EQ(bounds.ToString(), window->GetBounds().ToString());
619 } 622 }
620 623
621 // A WmWindowObserver which sets the focus when the window becomes visible. 624 // A aura::WindowObserver which sets the focus when the window becomes visible.
622 class FocusDuringUnminimizeWindowObserver : public WmWindowObserver { 625 class FocusDuringUnminimizeWindowObserver : public aura::WindowObserver {
623 public: 626 public:
624 FocusDuringUnminimizeWindowObserver() 627 FocusDuringUnminimizeWindowObserver()
625 : window_(nullptr), show_state_(ui::SHOW_STATE_END) {} 628 : window_(nullptr), show_state_(ui::SHOW_STATE_END) {}
626 ~FocusDuringUnminimizeWindowObserver() override { SetWindow(nullptr); } 629 ~FocusDuringUnminimizeWindowObserver() override { SetWindow(nullptr); }
627 630
628 void SetWindow(WmWindow* window) { 631 void SetWindow(WmWindow* window) {
629 if (window_) 632 if (window_)
630 window_->RemoveObserver(this); 633 window_->aura_window()->RemoveObserver(this);
631 window_ = window; 634 window_ = window;
632 if (window_) 635 if (window_)
633 window_->AddObserver(this); 636 window_->aura_window()->AddObserver(this);
634 } 637 }
635 638
636 // WmWindowObserver: 639 // aura::WindowObserver:
637 void OnWindowVisibilityChanged(WmWindow* window, bool visible) override { 640 void OnWindowVisibilityChanged(aura::Window* window, bool visible) override {
638 if (window_) { 641 if (window_) {
639 if (visible) 642 if (visible)
640 window_->SetFocused(); 643 window_->SetFocused();
641 show_state_ = window_->GetShowState(); 644 show_state_ = window_->GetShowState();
642 } 645 }
643 } 646 }
644 647
645 ui::WindowShowState GetShowStateAndReset() { 648 ui::WindowShowState GetShowStateAndReset() {
646 ui::WindowShowState ret = show_state_; 649 ui::WindowShowState ret = show_state_;
647 show_state_ = ui::SHOW_STATE_END; 650 show_state_ = ui::SHOW_STATE_END;
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 window->SetBounds(keyboard_bounds()); 1259 window->SetBounds(keyboard_bounds());
1257 window->GetWindowState()->set_ignore_keyboard_bounds_change(true); 1260 window->GetWindowState()->set_ignore_keyboard_bounds_change(true);
1258 window->Activate(); 1261 window->Activate();
1259 1262
1260 EXPECT_EQ(keyboard_bounds(), window->GetBounds()); 1263 EXPECT_EQ(keyboard_bounds(), window->GetBounds());
1261 ShowKeyboard(); 1264 ShowKeyboard();
1262 EXPECT_EQ(keyboard_bounds(), window->GetBounds()); 1265 EXPECT_EQ(keyboard_bounds(), window->GetBounds());
1263 } 1266 }
1264 1267
1265 } // namespace ash 1268 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/wm/workspace/workspace_layout_manager.cc ('k') | ash/common/wm/workspace/workspace_window_resizer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698