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

Side by Side Diff: ash/wm/maximize_mode/maximize_mode_window_manager_unittest.cc

Issue 2193783003: Notify WindowStateObserver when minimizing in maximized mode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2785
Patch Set: Created 4 years, 4 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/common/wm/window_state_observer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/maximize_mode/maximize_mode_window_manager.h" 5 #include "ash/common/wm/maximize_mode/maximize_mode_window_manager.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "ash/aura/wm_window_aura.h" 9 #include "ash/aura/wm_window_aura.h"
10 #include "ash/common/wm/mru_window_tracker.h" 10 #include "ash/common/wm/mru_window_tracker.h"
11 #include "ash/common/wm/overview/window_selector_controller.h" 11 #include "ash/common/wm/overview/window_selector_controller.h"
12 #include "ash/common/wm/switchable_windows.h" 12 #include "ash/common/wm/switchable_windows.h"
13 #include "ash/common/wm/window_state.h" 13 #include "ash/common/wm/window_state.h"
14 #include "ash/common/wm/window_state_observer.h"
14 #include "ash/common/wm/wm_event.h" 15 #include "ash/common/wm/wm_event.h"
15 #include "ash/common/wm_shell.h" 16 #include "ash/common/wm_shell.h"
16 #include "ash/root_window_controller.h" 17 #include "ash/root_window_controller.h"
17 #include "ash/screen_util.h" 18 #include "ash/screen_util.h"
18 #include "ash/shelf/shelf.h" 19 #include "ash/shelf/shelf.h"
19 #include "ash/shell.h" 20 #include "ash/shell.h"
20 #include "ash/test/ash_test_base.h" 21 #include "ash/test/ash_test_base.h"
21 #include "ash/test/shell_test_api.h" 22 #include "ash/test/shell_test_api.h"
22 #include "ash/wm/maximize_mode/maximize_mode_controller.h" 23 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
23 #include "ash/wm/window_properties.h" 24 #include "ash/wm/window_properties.h"
24 #include "ash/wm/window_state_aura.h" 25 #include "ash/wm/window_state_aura.h"
25 #include "ash/wm/window_util.h" 26 #include "ash/wm/window_util.h"
26 #include "base/strings/stringprintf.h" 27 #include "base/strings/stringprintf.h"
27 #include "base/strings/utf_string_conversions.h" 28 #include "base/strings/utf_string_conversions.h"
28 #include "base/values.h" 29 #include "base/values.h"
29 #include "ui/aura/client/aura_constants.h" 30 #include "ui/aura/client/aura_constants.h"
30 #include "ui/aura/test/test_window_delegate.h" 31 #include "ui/aura/test/test_window_delegate.h"
31 #include "ui/aura/test/test_windows.h" 32 #include "ui/aura/test/test_windows.h"
32 #include "ui/aura/window.h" 33 #include "ui/aura/window.h"
33 #include "ui/base/hit_test.h" 34 #include "ui/base/hit_test.h"
34 #include "ui/events/test/event_generator.h" 35 #include "ui/events/test/event_generator.h"
35 36
36 namespace ash { 37 namespace ash {
37 38
38 // TODO(skuhne): These tests are failing on Widows because maximized is there
39 // differently handled. Fix this!
40 #if !defined(OS_WIN)
41
42 class MaximizeModeWindowManagerTest : public test::AshTestBase { 39 class MaximizeModeWindowManagerTest : public test::AshTestBase {
43 public: 40 public:
44 MaximizeModeWindowManagerTest() {} 41 MaximizeModeWindowManagerTest() {}
45 ~MaximizeModeWindowManagerTest() override {} 42 ~MaximizeModeWindowManagerTest() override {}
46 43
47 // Creates a window which has a fixed size. 44 // Creates a window which has a fixed size.
48 aura::Window* CreateFixedSizeNonMaximizableWindow(ui::wm::WindowType type, 45 aura::Window* CreateFixedSizeNonMaximizableWindow(ui::wm::WindowType type,
49 const gfx::Rect& bounds) { 46 const gfx::Rect& bounds) {
50 return CreateWindowInWatchedContainer(type, bounds, gfx::Size(), false, 47 return CreateWindowInWatchedContainer(type, bounds, gfx::Size(), false,
51 false); 48 false);
(...skipping 1533 matching lines...) Expand 10 before | Expand all | Expand 10 after
1585 wm::GetWindowState(window.get())->OnWMEvent(&dock_event); 1582 wm::GetWindowState(window.get())->OnWMEvent(&dock_event);
1586 EXPECT_TRUE(wm::GetWindowState(window.get())->IsDocked()); 1583 EXPECT_TRUE(wm::GetWindowState(window.get())->IsDocked());
1587 EXPECT_FALSE(wm::GetWindowState(window.get())->IsMaximized()); 1584 EXPECT_FALSE(wm::GetWindowState(window.get())->IsMaximized());
1588 1585
1589 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager(); 1586 ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
1590 EXPECT_TRUE(wm::GetWindowState(window.get())->IsDocked()); 1587 EXPECT_TRUE(wm::GetWindowState(window.get())->IsDocked());
1591 EXPECT_FALSE(wm::GetWindowState(window.get())->IsMaximized()); 1588 EXPECT_FALSE(wm::GetWindowState(window.get())->IsMaximized());
1592 EXPECT_EQ(0, manager->GetNumberOfManagedWindows()); 1589 EXPECT_EQ(0, manager->GetNumberOfManagedWindows());
1593 } 1590 }
1594 1591
1595 #endif // OS_WIN 1592 namespace {
1593
1594 class TestObserver : public wm::WindowStateObserver {
1595 public:
1596 TestObserver(){};
1597 ~TestObserver() override{};
1598
1599 // wm::WindowStateObserver:
1600 void OnPreWindowStateTypeChange(wm::WindowState* window_state,
1601 wm::WindowStateType old_type) override {
1602 pre_count_++;
1603 last_old_state_ = old_type;
1604 }
1605
1606 void OnPostWindowStateTypeChange(wm::WindowState* window_state,
1607 wm::WindowStateType old_type) override {
1608 post_count_++;
1609 EXPECT_EQ(last_old_state_, old_type);
1610 }
1611
1612 int GetPreCountAndReset() {
1613 int r = pre_count_;
1614 pre_count_ = 0;
1615 return r;
1616 }
1617
1618 int GetPostCountAndReset() {
1619 int r = post_count_;
1620 post_count_ = 0;
1621 return r;
1622 }
1623
1624 wm::WindowStateType GetLastOldStateAndReset() {
1625 wm::WindowStateType r = last_old_state_;
1626 last_old_state_ = wm::WINDOW_STATE_TYPE_DEFAULT;
1627 return r;
1628 }
1629
1630 private:
1631 int pre_count_ = 0;
1632 int post_count_ = 0;
1633 wm::WindowStateType last_old_state_ = wm::WINDOW_STATE_TYPE_DEFAULT;
1634
1635 DISALLOW_COPY_AND_ASSIGN(TestObserver);
1636 };
1637
1638 } // namespace
1639
1640 TEST_F(MaximizeModeWindowManagerTest, StateTyepChange) {
1641 TestObserver observer;
1642 gfx::Rect rect(10, 10, 200, 50);
1643 std::unique_ptr<aura::Window> window(
1644 CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
1645
1646 CreateMaximizeModeWindowManager();
1647
1648 wm::WindowState* window_state = wm::GetWindowState(window.get());
1649 window_state->AddObserver(&observer);
1650
1651 window->Show();
1652 EXPECT_TRUE(window_state->IsMaximized());
1653 EXPECT_EQ(0, observer.GetPreCountAndReset());
1654 EXPECT_EQ(0, observer.GetPostCountAndReset());
1655
1656 // Window is already in maximized mode.
1657 wm::WMEvent maximize_event(wm::WM_EVENT_MAXIMIZE);
1658 window_state->OnWMEvent(&maximize_event);
1659 EXPECT_EQ(0, observer.GetPreCountAndReset());
1660 EXPECT_EQ(0, observer.GetPostCountAndReset());
1661
1662 wm::WMEvent fullscreen_event(wm::WM_EVENT_FULLSCREEN);
1663 window_state->OnWMEvent(&fullscreen_event);
1664 EXPECT_EQ(1, observer.GetPreCountAndReset());
1665 EXPECT_EQ(1, observer.GetPostCountAndReset());
1666 EXPECT_EQ(wm::WINDOW_STATE_TYPE_MAXIMIZED,
1667 observer.GetLastOldStateAndReset());
1668
1669 window_state->OnWMEvent(&maximize_event);
1670 EXPECT_EQ(1, observer.GetPreCountAndReset());
1671 EXPECT_EQ(1, observer.GetPostCountAndReset());
1672 EXPECT_EQ(wm::WINDOW_STATE_TYPE_FULLSCREEN,
1673 observer.GetLastOldStateAndReset());
1674
1675 wm::WMEvent minimize_event(wm::WM_EVENT_MINIMIZE);
1676 window_state->OnWMEvent(&minimize_event);
1677 EXPECT_EQ(1, observer.GetPreCountAndReset());
1678 EXPECT_EQ(1, observer.GetPostCountAndReset());
1679 EXPECT_EQ(wm::WINDOW_STATE_TYPE_MAXIMIZED,
1680 observer.GetLastOldStateAndReset());
1681
1682 wm::WMEvent restore_event(wm::WM_EVENT_NORMAL);
1683 window_state->OnWMEvent(&restore_event);
1684 EXPECT_EQ(1, observer.GetPreCountAndReset());
1685 EXPECT_EQ(1, observer.GetPostCountAndReset());
1686 EXPECT_EQ(wm::WINDOW_STATE_TYPE_MINIMIZED,
1687 observer.GetLastOldStateAndReset());
1688
1689 window_state->RemoveObserver(&observer);
1690
1691 DestroyMaximizeModeWindowManager();
1692 }
1596 1693
1597 } // namespace ash 1694 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/wm/window_state_observer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698