1 // Copyright 2019 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "ash/wm/desks/desks_test_util.h" 6 7 #include "ash/shell.h" 8 #include "ash/wm/desks/desk.h" 9 #include "ash/wm/overview/overview_controller.h" 10 #include "testing/gtest/include/gtest/gtest.h" 11 12 namespace ash { 13 DeskSwitchAnimationWaiter()14DeskSwitchAnimationWaiter::DeskSwitchAnimationWaiter() { 15 DesksController::Get()->AddObserver(this); 16 } 17 ~DeskSwitchAnimationWaiter()18DeskSwitchAnimationWaiter::~DeskSwitchAnimationWaiter() { 19 DesksController::Get()->RemoveObserver(this); 20 } 21 Wait()22void DeskSwitchAnimationWaiter::Wait() { 23 auto* controller = DesksController::Get(); 24 EXPECT_TRUE(controller->AreDesksBeingModified()); 25 run_loop_.Run(); 26 EXPECT_FALSE(controller->AreDesksBeingModified()); 27 } 28 OnDeskAdded(const Desk * desk)29void DeskSwitchAnimationWaiter::OnDeskAdded(const Desk* desk) {} 30 OnDeskRemoved(const Desk * desk)31void DeskSwitchAnimationWaiter::OnDeskRemoved(const Desk* desk) {} 32 OnDeskActivationChanged(const Desk * activated,const Desk * deactivated)33void DeskSwitchAnimationWaiter::OnDeskActivationChanged( 34 const Desk* activated, 35 const Desk* deactivated) {} 36 OnDeskSwitchAnimationLaunching()37void DeskSwitchAnimationWaiter::OnDeskSwitchAnimationLaunching() {} 38 OnDeskSwitchAnimationFinished()39void DeskSwitchAnimationWaiter::OnDeskSwitchAnimationFinished() { 40 run_loop_.Quit(); 41 } 42 ActivateDesk(const Desk * desk)43void ActivateDesk(const Desk* desk) { 44 ASSERT_FALSE(desk->is_active()); 45 DeskSwitchAnimationWaiter waiter; 46 auto* desks_controller = DesksController::Get(); 47 desks_controller->ActivateDesk(desk, DesksSwitchSource::kMiniViewButton); 48 EXPECT_EQ(desk, desks_controller->GetTargetActiveDesk()); 49 waiter.Wait(); 50 ASSERT_TRUE(desk->is_active()); 51 } 52 RemoveDesk(const Desk * desk)53void RemoveDesk(const Desk* desk) { 54 auto* controller = DesksController::Get(); 55 const bool in_overview = 56 Shell::Get()->overview_controller()->InOverviewSession(); 57 const bool should_wait = controller->active_desk() == desk && !in_overview; 58 DeskSwitchAnimationWaiter waiter; 59 controller->RemoveDesk(desk, DesksCreationRemovalSource::kButton); 60 if (should_wait) 61 waiter.Wait(); 62 } 63 64 } // namespace ash 65