| 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 "ash/wm/window_cycle_controller.h" | 5 #include "ash/wm/window_cycle_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "ash/aura/wm_window_aura.h" |
| 10 #include "ash/common/shell_window_ids.h" | 11 #include "ash/common/shell_window_ids.h" |
| 11 #include "ash/common/wm/window_state.h" | 12 #include "ash/common/wm/window_state.h" |
| 12 #include "ash/session/session_state_delegate.h" | 13 #include "ash/session/session_state_delegate.h" |
| 13 #include "ash/shelf/shelf.h" | 14 #include "ash/shelf/shelf.h" |
| 14 #include "ash/shelf/shelf_widget.h" | 15 #include "ash/shelf/shelf_widget.h" |
| 15 #include "ash/shell.h" | 16 #include "ash/shell.h" |
| 16 #include "ash/test/ash_test_base.h" | 17 #include "ash/test/ash_test_base.h" |
| 17 #include "ash/test/shelf_test_api.h" | 18 #include "ash/test/shelf_test_api.h" |
| 18 #include "ash/test/shelf_view_test_api.h" | 19 #include "ash/test/shelf_view_test_api.h" |
| 19 #include "ash/test/test_shelf_delegate.h" | 20 #include "ash/test/test_shelf_delegate.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 48 | 49 |
| 49 // ui::EventHandler: | 50 // ui::EventHandler: |
| 50 void OnKeyEvent(ui::KeyEvent* event) override { key_events_++; } | 51 void OnKeyEvent(ui::KeyEvent* event) override { key_events_++; } |
| 51 | 52 |
| 52 private: | 53 private: |
| 53 size_t key_events_; | 54 size_t key_events_; |
| 54 | 55 |
| 55 DISALLOW_COPY_AND_ASSIGN(KeyEventCounter); | 56 DISALLOW_COPY_AND_ASSIGN(KeyEventCounter); |
| 56 }; | 57 }; |
| 57 | 58 |
| 59 bool IsWindowMinimized(aura::Window* window) { |
| 60 return WmWindowAura::Get(window)->GetWindowState()->IsMinimized(); |
| 61 } |
| 62 |
| 58 } // namespace | 63 } // namespace |
| 59 | 64 |
| 60 using aura::test::CreateTestWindowWithId; | 65 using aura::test::CreateTestWindowWithId; |
| 61 using aura::test::TestWindowDelegate; | 66 using aura::test::TestWindowDelegate; |
| 62 using aura::Window; | 67 using aura::Window; |
| 63 | 68 |
| 64 class WindowCycleControllerTest : public test::AshTestBase { | 69 class WindowCycleControllerTest : public test::AshTestBase { |
| 65 public: | 70 public: |
| 66 WindowCycleControllerTest() {} | 71 WindowCycleControllerTest() {} |
| 67 ~WindowCycleControllerTest() override {} | 72 ~WindowCycleControllerTest() override {} |
| 68 | 73 |
| 69 void SetUp() override { | 74 void SetUp() override { |
| 70 test::AshTestBase::SetUp(); | 75 test::AshTestBase::SetUp(); |
| 71 ASSERT_TRUE(test::TestShelfDelegate::instance()); | 76 ASSERT_TRUE(test::TestShelfDelegate::instance()); |
| 72 | 77 |
| 73 shelf_view_test_.reset(new test::ShelfViewTestAPI( | 78 shelf_view_test_.reset(new test::ShelfViewTestAPI( |
| 74 test::ShelfTestAPI(Shelf::ForPrimaryDisplay()).shelf_view())); | 79 test::ShelfTestAPI(Shelf::ForPrimaryDisplay()).shelf_view())); |
| 75 shelf_view_test_->SetAnimationDuration(1); | 80 shelf_view_test_->SetAnimationDuration(1); |
| 76 } | 81 } |
| 77 | 82 |
| 78 aura::Window* CreatePanelWindow() { | 83 aura::Window* CreatePanelWindow() { |
| 79 gfx::Rect rect(100, 100); | 84 gfx::Rect rect(100, 100); |
| 80 aura::Window* window = CreateTestWindowInShellWithDelegateAndType( | 85 aura::Window* window = CreateTestWindowInShellWithDelegateAndType( |
| 81 NULL, ui::wm::WINDOW_TYPE_PANEL, 0, rect); | 86 NULL, ui::wm::WINDOW_TYPE_PANEL, 0, rect); |
| 82 test::TestShelfDelegate::instance()->AddShelfItem(window); | 87 test::TestShelfDelegate::instance()->AddShelfItem(window); |
| 83 shelf_view_test_->RunMessageLoopUntilAnimationsDone(); | 88 shelf_view_test_->RunMessageLoopUntilAnimationsDone(); |
| 84 return window; | 89 return window; |
| 85 } | 90 } |
| 86 | 91 |
| 87 const WindowCycleList::WindowList& GetWindows( | 92 const aura::Window::Windows GetWindows(WindowCycleController* controller) { |
| 88 WindowCycleController* controller) { | 93 return WmWindowAura::ToAuraWindows( |
| 89 return controller->window_cycle_list()->windows(); | 94 controller->window_cycle_list()->windows()); |
| 90 } | 95 } |
| 91 | 96 |
| 92 private: | 97 private: |
| 93 std::unique_ptr<test::ShelfViewTestAPI> shelf_view_test_; | 98 std::unique_ptr<test::ShelfViewTestAPI> shelf_view_test_; |
| 94 | 99 |
| 95 DISALLOW_COPY_AND_ASSIGN(WindowCycleControllerTest); | 100 DISALLOW_COPY_AND_ASSIGN(WindowCycleControllerTest); |
| 96 }; | 101 }; |
| 97 | 102 |
| 98 TEST_F(WindowCycleControllerTest, HandleCycleWindowBaseCases) { | 103 TEST_F(WindowCycleControllerTest, HandleCycleWindowBaseCases) { |
| 99 WindowCycleController* controller = | 104 WindowCycleController* controller = |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 // are passed. | 515 // are passed. |
| 511 TEST_F(WindowCycleControllerTest, CyclePreservesMinimization) { | 516 TEST_F(WindowCycleControllerTest, CyclePreservesMinimization) { |
| 512 WindowCycleController* controller = | 517 WindowCycleController* controller = |
| 513 Shell::GetInstance()->window_cycle_controller(); | 518 Shell::GetInstance()->window_cycle_controller(); |
| 514 | 519 |
| 515 std::unique_ptr<aura::Window> window0(CreateTestWindowInShellWithId(0)); | 520 std::unique_ptr<aura::Window> window0(CreateTestWindowInShellWithId(0)); |
| 516 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(1)); | 521 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(1)); |
| 517 wm::ActivateWindow(window1.get()); | 522 wm::ActivateWindow(window1.get()); |
| 518 wm::GetWindowState(window1.get())->Minimize(); | 523 wm::GetWindowState(window1.get())->Minimize(); |
| 519 wm::ActivateWindow(window0.get()); | 524 wm::ActivateWindow(window0.get()); |
| 520 EXPECT_TRUE(wm::IsWindowMinimized(window1.get())); | 525 EXPECT_TRUE(IsWindowMinimized(window1.get())); |
| 521 | 526 |
| 522 // On window 2. | 527 // On window 2. |
| 523 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 528 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 524 EXPECT_FALSE(wm::IsWindowMinimized(window1.get())); | 529 EXPECT_FALSE(IsWindowMinimized(window1.get())); |
| 525 | 530 |
| 526 // Back on window 1. | 531 // Back on window 1. |
| 527 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 532 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 528 EXPECT_TRUE(wm::IsWindowMinimized(window1.get())); | 533 EXPECT_TRUE(IsWindowMinimized(window1.get())); |
| 529 | 534 |
| 530 controller->StopCycling(); | 535 controller->StopCycling(); |
| 531 | 536 |
| 532 EXPECT_TRUE(wm::IsWindowMinimized(window1.get())); | 537 EXPECT_TRUE(IsWindowMinimized(window1.get())); |
| 533 } | 538 } |
| 534 | 539 |
| 535 // Tests cycles between panel and normal windows. | 540 // Tests cycles between panel and normal windows. |
| 536 TEST_F(WindowCycleControllerTest, CyclePanels) { | 541 TEST_F(WindowCycleControllerTest, CyclePanels) { |
| 537 WindowCycleController* controller = | 542 WindowCycleController* controller = |
| 538 Shell::GetInstance()->window_cycle_controller(); | 543 Shell::GetInstance()->window_cycle_controller(); |
| 539 | 544 |
| 540 std::unique_ptr<aura::Window> window0(CreateTestWindowInShellWithId(0)); | 545 std::unique_ptr<aura::Window> window0(CreateTestWindowInShellWithId(0)); |
| 541 std::unique_ptr<aura::Window> panel0(CreatePanelWindow()); | 546 std::unique_ptr<aura::Window> panel0(CreatePanelWindow()); |
| 542 std::unique_ptr<aura::Window> panel1(CreatePanelWindow()); | 547 std::unique_ptr<aura::Window> panel1(CreatePanelWindow()); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 generator.PressKey(ui::VKEY_TAB, ui::EF_ALT_DOWN); | 635 generator.PressKey(ui::VKEY_TAB, ui::EF_ALT_DOWN); |
| 631 EXPECT_EQ(0u, key_count.GetCountAndReset()); | 636 EXPECT_EQ(0u, key_count.GetCountAndReset()); |
| 632 generator.ReleaseKey(ui::VKEY_TAB, ui::EF_ALT_DOWN); | 637 generator.ReleaseKey(ui::VKEY_TAB, ui::EF_ALT_DOWN); |
| 633 EXPECT_EQ(0u, key_count.GetCountAndReset()); | 638 EXPECT_EQ(0u, key_count.GetCountAndReset()); |
| 634 generator.ReleaseKey(ui::VKEY_MENU, ui::EF_NONE); | 639 generator.ReleaseKey(ui::VKEY_MENU, ui::EF_NONE); |
| 635 EXPECT_TRUE(wm::GetWindowState(w1.get())->IsActive()); | 640 EXPECT_TRUE(wm::GetWindowState(w1.get())->IsActive()); |
| 636 EXPECT_EQ(0u, key_count.GetCountAndReset()); | 641 EXPECT_EQ(0u, key_count.GetCountAndReset()); |
| 637 } | 642 } |
| 638 | 643 |
| 639 } // namespace ash | 644 } // namespace ash |
| OLD | NEW |