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

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

Issue 2182183002: Notify WindowStateObserver when minimizing in maximized mode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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/maximize_mode/maximize_mode_controller.h" 10 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h"
11 #include "ash/common/wm/mru_window_tracker.h" 11 #include "ash/common/wm/mru_window_tracker.h"
12 #include "ash/common/wm/overview/window_selector_controller.h" 12 #include "ash/common/wm/overview/window_selector_controller.h"
13 #include "ash/common/wm/switchable_windows.h" 13 #include "ash/common/wm/switchable_windows.h"
14 #include "ash/common/wm/window_state.h" 14 #include "ash/common/wm/window_state.h"
15 #include "ash/common/wm/window_state_observer.h"
15 #include "ash/common/wm/wm_event.h" 16 #include "ash/common/wm/wm_event.h"
16 #include "ash/common/wm_shell.h" 17 #include "ash/common/wm_shell.h"
17 #include "ash/root_window_controller.h" 18 #include "ash/root_window_controller.h"
18 #include "ash/screen_util.h" 19 #include "ash/screen_util.h"
19 #include "ash/shelf/shelf.h" 20 #include "ash/shelf/shelf.h"
20 #include "ash/shell.h" 21 #include "ash/shell.h"
21 #include "ash/test/ash_test_base.h" 22 #include "ash/test/ash_test_base.h"
22 #include "ash/test/shell_test_api.h" 23 #include "ash/test/shell_test_api.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 1527 matching lines...) Expand 10 before | Expand all | Expand 10 after
1579 wm::GetWindowState(window.get())->OnWMEvent(&dock_event); 1576 wm::GetWindowState(window.get())->OnWMEvent(&dock_event);
1580 EXPECT_TRUE(wm::GetWindowState(window.get())->IsDocked()); 1577 EXPECT_TRUE(wm::GetWindowState(window.get())->IsDocked());
1581 EXPECT_FALSE(wm::GetWindowState(window.get())->IsMaximized()); 1578 EXPECT_FALSE(wm::GetWindowState(window.get())->IsMaximized());
1582 1579
1583 MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager(); 1580 MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager();
1584 EXPECT_TRUE(wm::GetWindowState(window.get())->IsDocked()); 1581 EXPECT_TRUE(wm::GetWindowState(window.get())->IsDocked());
1585 EXPECT_FALSE(wm::GetWindowState(window.get())->IsMaximized()); 1582 EXPECT_FALSE(wm::GetWindowState(window.get())->IsMaximized());
1586 EXPECT_EQ(0, manager->GetNumberOfManagedWindows()); 1583 EXPECT_EQ(0, manager->GetNumberOfManagedWindows());
1587 } 1584 }
1588 1585
1589 #endif // OS_WIN 1586 namespace {
1587
1588 class TestObserver : public wm::WindowStateObserver {
1589 public:
1590 TestObserver(){};
1591 ~TestObserver() override{};
1592
1593 // wm::WindowStateObserver:
1594 void OnPreWindowStateTypeChange(wm::WindowState* window_state,
1595 wm::WindowStateType old_type) override {
1596 pre_count_++;
1597 last_old_state_ = old_type;
1598 }
1599
1600 void OnPostWindowStateTypeChange(wm::WindowState* window_state,
1601 wm::WindowStateType old_type) override {
1602 post_count_++;
1603 EXPECT_EQ(last_old_state_, old_type);
1604 }
1605
1606 int GetPreCountAndReset() {
1607 int r = pre_count_;
1608 pre_count_ = 0;
1609 return r;
1610 }
1611
1612 int GetPostCountAndReset() {
1613 int r = post_count_;
1614 post_count_ = 0;
1615 return r;
1616 }
1617
1618 wm::WindowStateType GetLastOldStateAndReset() {
1619 wm::WindowStateType r = last_old_state_;
1620 last_old_state_ = wm::WINDOW_STATE_TYPE_DEFAULT;
1621 return r;
1622 }
1623
1624 private:
1625 int pre_count_ = 0;
1626 int post_count_ = 0;
1627 wm::WindowStateType last_old_state_ = wm::WINDOW_STATE_TYPE_DEFAULT;
1628
1629 DISALLOW_COPY_AND_ASSIGN(TestObserver);
1630 };
1631
1632 } // namespace
1633
1634 TEST_F(MaximizeModeWindowManagerTest, StateTyepChange) {
1635 TestObserver observer;
1636 gfx::Rect rect(10, 10, 200, 50);
1637 std::unique_ptr<aura::Window> window(
1638 CreateWindow(ui::wm::WINDOW_TYPE_NORMAL, rect));
1639
1640 CreateMaximizeModeWindowManager();
1641
1642 wm::WindowState* window_state = wm::GetWindowState(window.get());
1643 window_state->AddObserver(&observer);
1644
1645 window->Show();
1646 EXPECT_TRUE(window_state->IsMaximized());
1647 EXPECT_EQ(0, observer.GetPreCountAndReset());
1648 EXPECT_EQ(0, observer.GetPostCountAndReset());
1649
1650 // Window is already in maximized mode.
1651 wm::WMEvent maximize_event(wm::WM_EVENT_MAXIMIZE);
1652 window_state->OnWMEvent(&maximize_event);
1653 EXPECT_EQ(0, observer.GetPreCountAndReset());
1654 EXPECT_EQ(0, observer.GetPostCountAndReset());
1655
1656 wm::WMEvent fullscreen_event(wm::WM_EVENT_FULLSCREEN);
1657 window_state->OnWMEvent(&fullscreen_event);
1658 EXPECT_EQ(1, observer.GetPreCountAndReset());
1659 EXPECT_EQ(1, observer.GetPostCountAndReset());
1660 EXPECT_EQ(wm::WINDOW_STATE_TYPE_MAXIMIZED,
1661 observer.GetLastOldStateAndReset());
1662
1663 window_state->OnWMEvent(&maximize_event);
1664 EXPECT_EQ(1, observer.GetPreCountAndReset());
1665 EXPECT_EQ(1, observer.GetPostCountAndReset());
1666 EXPECT_EQ(wm::WINDOW_STATE_TYPE_FULLSCREEN,
1667 observer.GetLastOldStateAndReset());
1668
1669 wm::WMEvent minimize_event(wm::WM_EVENT_MINIMIZE);
1670 window_state->OnWMEvent(&minimize_event);
1671 EXPECT_EQ(1, observer.GetPreCountAndReset());
1672 EXPECT_EQ(1, observer.GetPostCountAndReset());
1673 EXPECT_EQ(wm::WINDOW_STATE_TYPE_MAXIMIZED,
1674 observer.GetLastOldStateAndReset());
1675
1676 wm::WMEvent restore_event(wm::WM_EVENT_NORMAL);
1677 window_state->OnWMEvent(&restore_event);
1678 EXPECT_EQ(1, observer.GetPreCountAndReset());
1679 EXPECT_EQ(1, observer.GetPostCountAndReset());
1680 EXPECT_EQ(wm::WINDOW_STATE_TYPE_MINIMIZED,
1681 observer.GetLastOldStateAndReset());
1682
1683 window_state->RemoveObserver(&observer);
1684
1685 DestroyMaximizeModeWindowManager();
1686 }
1590 1687
1591 } // namespace ash 1688 } // 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