| OLD | NEW |
| 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 "athena/wm/public/window_manager.h" | 5 #include "athena/wm/public/window_manager.h" |
| 6 | 6 |
| 7 #include "athena/screen/public/screen_manager.h" | 7 #include "athena/screen/public/screen_manager.h" |
| 8 #include "athena/test/base/athena_test_base.h" | 8 #include "athena/test/base/athena_test_base.h" |
| 9 #include "athena/test/base/test_windows.h" | 9 #include "athena/test/base/test_windows.h" |
| 10 #include "athena/wm/public/window_list_provider.h" | 10 #include "athena/wm/public/window_list_provider.h" |
| 11 #include "athena/wm/split_view_controller.h" | 11 #include "athena/wm/split_view_controller.h" |
| 12 #include "athena/wm/test/window_manager_impl_test_api.h" | 12 #include "athena/wm/test/window_manager_impl_test_api.h" |
| 13 #include "athena/wm/window_manager_impl.h" | 13 #include "athena/wm/window_manager_impl.h" |
| 14 #include "ui/aura/client/aura_constants.h" |
| 14 #include "ui/aura/client/window_tree_client.h" | 15 #include "ui/aura/client/window_tree_client.h" |
| 15 #include "ui/aura/test/test_window_delegate.h" | 16 #include "ui/aura/test/test_window_delegate.h" |
| 16 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
| 17 #include "ui/base/hit_test.h" | 18 #include "ui/base/hit_test.h" |
| 18 #include "ui/events/test/event_generator.h" | 19 #include "ui/events/test/event_generator.h" |
| 19 #include "ui/gfx/display.h" | 20 #include "ui/gfx/display.h" |
| 20 #include "ui/gfx/screen.h" | 21 #include "ui/gfx/screen.h" |
| 21 #include "ui/wm/core/window_util.h" | 22 #include "ui/wm/core/window_util.h" |
| 22 | 23 |
| 23 namespace athena { | 24 namespace athena { |
| 24 | 25 |
| 25 class WindowManagerTest : public test::AthenaTestBase { | 26 class WindowManagerTest : public test::AthenaTestBase { |
| 26 public: | 27 public: |
| 27 WindowManagerTest() {} | 28 WindowManagerTest() {} |
| 28 ~WindowManagerTest() override {} | 29 ~WindowManagerTest() override {} |
| 29 | 30 |
| 30 scoped_ptr<aura::Window> CreateAndActivateWindow( | 31 scoped_ptr<aura::Window> CreateAndActivateWindow( |
| 31 aura::WindowDelegate* delegate) { | 32 aura::WindowDelegate* delegate) { |
| 32 scoped_ptr<aura::Window> window( | 33 scoped_ptr<aura::Window> window( |
| 33 test::CreateNormalWindow(delegate, nullptr)); | 34 test::CreateNormalWindow(delegate, nullptr)); |
| 34 window->Show(); | 35 window->Show(); |
| 35 wm::ActivateWindow(window.get()); | 36 wm::ActivateWindow(window.get()); |
| 37 window->SetProperty(aura::client::kCanMaximizeKey, true); |
| 36 return window.Pass(); | 38 return window.Pass(); |
| 37 } | 39 } |
| 38 | 40 |
| 39 private: | 41 private: |
| 40 DISALLOW_COPY_AND_ASSIGN(WindowManagerTest); | 42 DISALLOW_COPY_AND_ASSIGN(WindowManagerTest); |
| 41 }; | 43 }; |
| 42 | 44 |
| 43 TEST_F(WindowManagerTest, OverviewModeBasics) { | 45 TEST_F(WindowManagerTest, OverviewModeBasics) { |
| 44 aura::test::TestWindowDelegate delegate; | 46 aura::test::TestWindowDelegate delegate; |
| 45 scoped_ptr<aura::Window> first(CreateAndActivateWindow(&delegate)); | 47 scoped_ptr<aura::Window> first(CreateAndActivateWindow(&delegate)); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 EXPECT_TRUE(w3->IsVisible()); | 96 EXPECT_TRUE(w3->IsVisible()); |
| 95 | 97 |
| 96 // Go into split-view mode. | 98 // Go into split-view mode. |
| 97 WindowOverviewModeDelegate* overview_delegate = wm_api.wm(); | 99 WindowOverviewModeDelegate* overview_delegate = wm_api.wm(); |
| 98 overview_delegate->OnSelectSplitViewWindow(w3.get(), nullptr, w3.get()); | 100 overview_delegate->OnSelectSplitViewWindow(w3.get(), nullptr, w3.get()); |
| 99 EXPECT_TRUE(w3->IsVisible()); | 101 EXPECT_TRUE(w3->IsVisible()); |
| 100 EXPECT_TRUE(w2->IsVisible()); | 102 EXPECT_TRUE(w2->IsVisible()); |
| 101 EXPECT_FALSE(w1->IsVisible()); | 103 EXPECT_FALSE(w1->IsVisible()); |
| 102 } | 104 } |
| 103 | 105 |
| 106 TEST_F(WindowManagerTest, OnSelectWindow) { |
| 107 test::WindowManagerImplTestApi wm_api; |
| 108 aura::test::TestWindowDelegate delegate1; |
| 109 aura::test::TestWindowDelegate delegate2; |
| 110 aura::test::TestWindowDelegate delegate3; |
| 111 |
| 112 // (w1): A window that sets a maximum size |
| 113 delegate1.set_maximum_size(gfx::Size(300, 200)); |
| 114 scoped_ptr<aura::Window> w1(CreateAndActivateWindow(&delegate1)); |
| 115 w1->SetBounds(gfx::Rect(0, 0, 300, 200)); |
| 116 |
| 117 // (w2): A window that doesn't set a max size and is maximizable |
| 118 scoped_ptr<aura::Window> w2(CreateAndActivateWindow(&delegate2)); |
| 119 w2->SetBounds(gfx::Rect(0, 0, 300, 200)); |
| 120 w2->SetProperty(aura::client::kCanMaximizeKey, true); |
| 121 |
| 122 // (w3): A window that doesn't set a max size but is NOT maximizable |
| 123 scoped_ptr<aura::Window> w3(CreateAndActivateWindow(&delegate3)); |
| 124 w3->SetBounds(gfx::Rect(0, 0, 300, 200)); |
| 125 w3->SetProperty(aura::client::kCanMaximizeKey, false); |
| 126 |
| 127 const gfx::Size old_bounds1 = w1->GetTargetBounds().size(); |
| 128 const gfx::Size old_bounds2 = w2->GetTargetBounds().size(); |
| 129 const gfx::Size old_bounds3 = w3->GetTargetBounds().size(); |
| 130 const gfx::Size work_area = |
| 131 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area().size(); |
| 132 |
| 133 // Select w1, which has a max size, in the overview mode and make sure it's |
| 134 // not maximized. |
| 135 WindowManager::Get()->EnterOverview(); |
| 136 WindowOverviewModeDelegate* overview_delegate = wm_api.wm(); |
| 137 overview_delegate->OnSelectWindow(w1.get()); |
| 138 const gfx::Size new_bounds1 = w1->GetTargetBounds().size(); |
| 139 EXPECT_EQ(new_bounds1.ToString(), old_bounds1.ToString()); |
| 140 EXPECT_NE(work_area.ToString(), new_bounds1.ToString()); |
| 141 |
| 142 // Select w2, which has no max size & can be maximized, in the overview |
| 143 // mode and make sure it's actually maximized. |
| 144 WindowManager::Get()->EnterOverview(); |
| 145 overview_delegate->OnSelectWindow(w2.get()); |
| 146 const gfx::Size new_bounds2 = w2->GetTargetBounds().size(); |
| 147 EXPECT_NE(new_bounds2.ToString(), old_bounds2.ToString()); |
| 148 EXPECT_EQ(work_area.ToString(), new_bounds2.ToString()); |
| 149 |
| 150 // Select w3, which has no max size & cannot be maximized, in the overview |
| 151 // mode and make sure it's not maximized. |
| 152 WindowManager::Get()->EnterOverview(); |
| 153 overview_delegate->OnSelectWindow(w3.get()); |
| 154 const gfx::Size new_bounds3 = w3->GetTargetBounds().size(); |
| 155 EXPECT_EQ(new_bounds3.ToString(), old_bounds3.ToString()); |
| 156 EXPECT_NE(work_area.ToString(), new_bounds3.ToString()); |
| 157 } |
| 158 |
| 104 TEST_F(WindowManagerTest, NewWindowFromOverview) { | 159 TEST_F(WindowManagerTest, NewWindowFromOverview) { |
| 105 aura::test::TestWindowDelegate delegate; | 160 aura::test::TestWindowDelegate delegate; |
| 106 scoped_ptr<aura::Window> w1(CreateAndActivateWindow(&delegate)); | 161 scoped_ptr<aura::Window> w1(CreateAndActivateWindow(&delegate)); |
| 107 scoped_ptr<aura::Window> w2(CreateAndActivateWindow(&delegate)); | 162 scoped_ptr<aura::Window> w2(CreateAndActivateWindow(&delegate)); |
| 108 | 163 |
| 109 WindowManager::Get()->EnterOverview(); | 164 WindowManager::Get()->EnterOverview(); |
| 110 EXPECT_TRUE(w1->IsVisible()); | 165 EXPECT_TRUE(w1->IsVisible()); |
| 111 EXPECT_TRUE(w2->IsVisible()); | 166 EXPECT_TRUE(w2->IsVisible()); |
| 112 | 167 |
| 113 // Test that opening a new window exits overview mode. The new window could | 168 // Test that opening a new window exits overview mode. The new window could |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 int width = | 400 int width = |
| 346 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area().width(); | 401 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().work_area().width(); |
| 347 | 402 |
| 348 EXPECT_EQ(w1->bounds().width(), w2->bounds().width()); | 403 EXPECT_EQ(w1->bounds().width(), w2->bounds().width()); |
| 349 EXPECT_GE(width / 2, w1->bounds().width()); | 404 EXPECT_GE(width / 2, w1->bounds().width()); |
| 350 | 405 |
| 351 // Toggle back to normal mode. | 406 // Toggle back to normal mode. |
| 352 wm_api.wm()->ToggleSplitView(); | 407 wm_api.wm()->ToggleSplitView(); |
| 353 EXPECT_FALSE(wm_api.GetSplitViewController()->IsSplitViewModeActive()); | 408 EXPECT_FALSE(wm_api.GetSplitViewController()->IsSplitViewModeActive()); |
| 354 | 409 |
| 410 // w2 is the top window, it should be resized to max width and must be visible |
| 411 // w1 should be hidden. |
| 412 EXPECT_EQ(width, w2->bounds().width()); |
| 413 EXPECT_TRUE(w2->IsVisible()); |
| 414 EXPECT_FALSE(w1->IsVisible()); |
| 415 |
| 416 // Expect w1 to be visible and maximized when activated. |
| 417 // TODO(oshima): To change to wm::ActivateWindow once the correct window state |
| 418 // is implemented. |
| 419 w1->Show(); |
| 355 EXPECT_EQ(width, w1->bounds().width()); | 420 EXPECT_EQ(width, w1->bounds().width()); |
| 356 EXPECT_EQ(width, w2->bounds().width()); | 421 EXPECT_TRUE(w1->IsVisible()); |
| 357 } | 422 } |
| 358 | 423 |
| 359 TEST_F(WindowManagerTest, OverviewModeFromSplitMode) { | 424 TEST_F(WindowManagerTest, OverviewModeFromSplitMode) { |
| 360 test::WindowManagerImplTestApi wm_api; | 425 test::WindowManagerImplTestApi wm_api; |
| 361 | 426 |
| 362 aura::test::TestWindowDelegate delegate; | 427 aura::test::TestWindowDelegate delegate; |
| 363 scoped_ptr<aura::Window> w1(CreateAndActivateWindow(&delegate)); | 428 scoped_ptr<aura::Window> w1(CreateAndActivateWindow(&delegate)); |
| 364 scoped_ptr<aura::Window> w2(CreateAndActivateWindow(&delegate)); | 429 scoped_ptr<aura::Window> w2(CreateAndActivateWindow(&delegate)); |
| 365 scoped_ptr<aura::Window> w3(CreateAndActivateWindow(&delegate)); | 430 scoped_ptr<aura::Window> w3(CreateAndActivateWindow(&delegate)); |
| 366 | 431 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 387 aura::test::TestWindowDelegate delegate; | 452 aura::test::TestWindowDelegate delegate; |
| 388 scoped_ptr<aura::Window> w1(CreateAndActivateWindow(&delegate)); | 453 scoped_ptr<aura::Window> w1(CreateAndActivateWindow(&delegate)); |
| 389 WindowManager::Get()->EnterOverview(); | 454 WindowManager::Get()->EnterOverview(); |
| 390 | 455 |
| 391 ui::test::EventGenerator generator(root_window()); | 456 ui::test::EventGenerator generator(root_window()); |
| 392 generator.MoveMouseTo(1, 1); | 457 generator.MoveMouseTo(1, 1); |
| 393 generator.ClickLeftButton(); | 458 generator.ClickLeftButton(); |
| 394 } | 459 } |
| 395 | 460 |
| 396 } // namespace athena | 461 } // namespace athena |
| OLD | NEW |