123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766 |
- // Copyright (c) 2020 The Chromium Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style license that can be
- // found in the LICENSE file.
- #include <memory>
- #include <tuple>
- #include <vector>
- #include "ash/app_list/app_list_controller_impl.h"
- #include "ash/app_list/test/app_list_test_helper.h"
- #include "ash/app_list/views/app_list_view.h"
- #include "ash/assistant/assistant_controller_impl.h"
- #include "ash/constants/ash_features.h"
- #include "ash/focus_cycler.h"
- #include "ash/public/cpp/assistant/controller/assistant_ui_controller.h"
- #include "ash/public/cpp/test/assistant_test_api.h"
- #include "ash/public/cpp/test/shell_test_api.h"
- #include "ash/shelf/drag_window_from_shelf_controller_test_api.h"
- #include "ash/shelf/home_button.h"
- #include "ash/shelf/hotseat_widget.h"
- #include "ash/shelf/scrollable_shelf_view.h"
- #include "ash/shelf/shelf.h"
- #include "ash/shelf/shelf_app_button.h"
- #include "ash/shelf/shelf_controller.h"
- #include "ash/shelf/shelf_focus_cycler.h"
- #include "ash/shelf/shelf_layout_manager.h"
- #include "ash/shelf/shelf_metrics.h"
- #include "ash/shelf/shelf_navigation_widget.h"
- #include "ash/shelf/shelf_test_util.h"
- #include "ash/shelf/shelf_view.h"
- #include "ash/shelf/shelf_view_test_api.h"
- #include "ash/shelf/test/hotseat_state_watcher.h"
- #include "ash/shelf/test/shelf_layout_manager_test_base.h"
- #include "ash/shelf/test/widget_animation_smoothness_inspector.h"
- #include "ash/shell.h"
- #include "ash/system/ime_menu/ime_menu_tray.h"
- #include "ash/system/overview/overview_button_tray.h"
- #include "ash/system/status_area_widget.h"
- #include "ash/system/unified/unified_system_tray.h"
- #include "ash/test/ash_test_base.h"
- #include "ash/test/layer_animation_verifier.h"
- #include "ash/wm/overview/overview_controller.h"
- #include "ash/wm/tablet_mode/tablet_mode_controller_test_api.h"
- #include "ash/wm/window_state.h"
- #include "ash/wm/wm_event.h"
- #include "ash/wm/work_area_insets.h"
- #include "base/test/icu_test_util.h"
- #include "base/test/metrics/histogram_tester.h"
- #include "base/test/scoped_feature_list.h"
- #include "chromeos/ash/services/assistant/public/cpp/assistant_service.h"
- #include "testing/gtest/include/gtest/gtest.h"
- #include "ui/aura/client/aura_constants.h"
- #include "ui/compositor/presentation_time_recorder.h"
- #include "ui/compositor/scoped_animation_duration_scale_mode.h"
- #include "ui/compositor/scoped_layer_animation_settings.h"
- #include "ui/events/gesture_detection/gesture_configuration.h"
- #include "ui/events/test/event_generator.h"
- #include "ui/views/test/widget_animation_waiter.h"
- #include "ui/wm/core/window_util.h"
- namespace ash {
- namespace {
- ShelfWidget* GetShelfWidget() {
- return AshTestBase::GetPrimaryShelf()->shelf_widget();
- }
- ShelfLayoutManager* GetShelfLayoutManager() {
- return AshTestBase::GetPrimaryShelf()->shelf_layout_manager();
- }
- } // namespace
- class HotseatWidgetTest
- : public ShelfLayoutManagerTestBase,
- public testing::WithParamInterface<
- std::tuple<ShelfAutoHideBehavior,
- /*is_assistant_enabled*/ bool,
- /*navigation_buttons_shown_in_tablet_mode*/ bool>> {
- public:
- HotseatWidgetTest()
- : ShelfLayoutManagerTestBase(
- base::test::TaskEnvironment::TimeSource::MOCK_TIME),
- shelf_auto_hide_behavior_(std::get<0>(GetParam())),
- is_assistant_enabled_(std::get<1>(GetParam())),
- navigation_buttons_shown_in_tablet_mode_(std::get<2>(GetParam())) {
- if (is_assistant_enabled_)
- assistant_test_api_ = AssistantTestApi::Create();
- std::vector<base::Feature> enabled_features;
- std::vector<base::Feature> disabled_features;
- if (navigation_buttons_shown_in_tablet_mode_) {
- disabled_features.push_back(features::kHideShelfControlsInTabletMode);
- } else {
- enabled_features.push_back(features::kHideShelfControlsInTabletMode);
- }
- enabled_features.push_back(features::kShelfPalmRejectionSwipeOffset);
- scoped_feature_list_.InitWithFeatures(enabled_features, disabled_features);
- }
- // testing::Test:
- void SetUp() override {
- ShelfLayoutManagerTestBase::SetUp();
- if (is_assistant_enabled_) {
- assistant_test_api_->SetAssistantEnabled(true);
- assistant_test_api_->GetAssistantState()->NotifyFeatureAllowed(
- assistant::AssistantAllowedState::ALLOWED);
- assistant_test_api_->GetAssistantState()->NotifyStatusChanged(
- assistant::AssistantStatus::READY);
- assistant_test_api_->WaitUntilIdle();
- }
- }
- void TearDown() override {
- // Some tests may override this value, make sure it's reset.
- ui::PresentationTimeRecorder::SetReportPresentationTimeImmediatelyForTest(
- false);
- ShelfLayoutManagerTestBase::TearDown();
- }
- ShelfAutoHideBehavior shelf_auto_hide_behavior() const {
- return shelf_auto_hide_behavior_;
- }
- bool is_assistant_enabled() const { return is_assistant_enabled_; }
- bool navigation_buttons_shown_in_tablet_mode() const {
- return navigation_buttons_shown_in_tablet_mode_;
- }
- AssistantTestApi* assistant_test_api() { return assistant_test_api_.get(); }
- void ShowShelfAndActivateAssistant() {
- if (shelf_auto_hide_behavior() == ShelfAutoHideBehavior::kAlways)
- SwipeUpOnShelf();
- // If the launcher button is not expected to be shown, show the assistant UI
- // directly; otherwise, simulate the long press on the home button,
- if (!navigation_buttons_shown_in_tablet_mode_ &&
- Shell::Get()->tablet_mode_controller()->InTabletMode()) {
- AssistantUiController::Get()->ShowUi(
- assistant::AssistantEntryPoint::kLongPressLauncher);
- return;
- }
- views::View* home_button =
- GetPrimaryShelf()->navigation_widget()->GetHomeButton();
- auto center_point = home_button->GetBoundsInScreen().CenterPoint();
- GetEventGenerator()->set_current_screen_location(center_point);
- GetEventGenerator()->PressTouch();
- GetAppListTestHelper()->WaitUntilIdle();
- // Advance clock to make sure long press gesture is triggered.
- task_environment()->AdvanceClock(base::Seconds(5));
- GetAppListTestHelper()->WaitUntilIdle();
- GetEventGenerator()->ReleaseTouch();
- GetAppListTestHelper()->WaitUntilIdle();
- }
- void ShowShelfAndGoHome() {
- // If the launcher button is not expected to be shown, go home directly;
- // otherwise, simulate tap on the home button,
- if (!navigation_buttons_shown_in_tablet_mode_ &&
- Shell::Get()->tablet_mode_controller()->InTabletMode()) {
- Shell::Get()->app_list_controller()->GoHome(GetPrimaryDisplay().id());
- return;
- }
- // Ensure the shelf, and the home button, are visible.
- if (shelf_auto_hide_behavior() == ShelfAutoHideBehavior::kAlways)
- SwipeUpOnShelf();
- views::View* home_button =
- GetPrimaryShelf()->navigation_widget()->GetHomeButton();
- GetEventGenerator()->GestureTapAt(
- home_button->GetBoundsInScreen().CenterPoint());
- }
- void StartOverview() {
- ASSERT_FALSE(Shell::Get()->overview_controller()->InOverviewSession());
- // If the overview button is not expected to be shown, start overview
- // directly; otherwise, simulate tap on the overview button, which should
- // toggle overview.
- if (!navigation_buttons_shown_in_tablet_mode_ &&
- Shell::Get()->tablet_mode_controller()->InTabletMode()) {
- EnterOverview();
- return;
- }
- const gfx::Point overview_button_center = GetPrimaryShelf()
- ->status_area_widget()
- ->overview_button_tray()
- ->GetBoundsInScreen()
- .CenterPoint();
- GetEventGenerator()->GestureTapAt(overview_button_center);
- }
- void EndOverview() {
- ASSERT_TRUE(Shell::Get()->overview_controller()->InOverviewSession());
- // If the overview button is not expected to be shown, end overview
- // directly; otherwise, simulate tap on the overview button, which should
- // toggle overview.
- if (!navigation_buttons_shown_in_tablet_mode_ &&
- Shell::Get()->tablet_mode_controller()->InTabletMode()) {
- ExitOverview();
- return;
- }
- const gfx::Point overview_button_center = GetPrimaryShelf()
- ->status_area_widget()
- ->overview_button_tray()
- ->GetBoundsInScreen()
- .CenterPoint();
- GetEventGenerator()->GestureTapAt(overview_button_center);
- }
- private:
- const ShelfAutoHideBehavior shelf_auto_hide_behavior_;
- const bool is_assistant_enabled_;
- const bool navigation_buttons_shown_in_tablet_mode_;
- std::unique_ptr<AssistantTestApi> assistant_test_api_;
- base::test::ScopedFeatureList scoped_feature_list_;
- };
- // Counts the number of times the work area changes.
- class DisplayWorkAreaChangeCounter : public display::DisplayObserver {
- public:
- DisplayWorkAreaChangeCounter() {
- Shell::Get()->display_manager()->AddObserver(this);
- }
- DisplayWorkAreaChangeCounter(const DisplayWorkAreaChangeCounter&) = delete;
- DisplayWorkAreaChangeCounter& operator=(const DisplayWorkAreaChangeCounter&) =
- delete;
- ~DisplayWorkAreaChangeCounter() override {
- Shell::Get()->display_manager()->RemoveObserver(this);
- }
- void OnDisplayMetricsChanged(const display::Display& display,
- uint32_t metrics) override {
- if (metrics & display::DisplayObserver::DISPLAY_METRIC_WORK_AREA)
- work_area_change_count_++;
- }
- int count() const { return work_area_change_count_; }
- private:
- int work_area_change_count_ = 0;
- };
- // Watches the shelf for state changes.
- class ShelfStateWatcher : public ShelfObserver {
- public:
- ShelfStateWatcher() { AshTestBase::GetPrimaryShelf()->AddObserver(this); }
- ~ShelfStateWatcher() override {
- AshTestBase::GetPrimaryShelf()->RemoveObserver(this);
- }
- void WillChangeVisibilityState(ShelfVisibilityState new_state) override {
- state_change_count_++;
- }
- int state_change_count() const { return state_change_count_; }
- private:
- int state_change_count_ = 0;
- };
- // Watches the Hotseat transition animation states.
- class HotseatTransitionAnimationObserver
- : public HotseatTransitionAnimator::Observer {
- public:
- explicit HotseatTransitionAnimationObserver(
- HotseatTransitionAnimator* hotseat_transition_animator)
- : hotseat_transition_animator_(hotseat_transition_animator) {
- hotseat_transition_animator_->AddObserver(this);
- }
- ~HotseatTransitionAnimationObserver() override {
- hotseat_transition_animator_->RemoveObserver(this);
- }
- // HotseatTransitionAnimtor::Observer:
- void OnHotseatTransitionAnimationWillStart(HotseatState from_state,
- HotseatState to_start) override {
- ++observer_counts_.started;
- }
- void OnHotseatTransitionAnimationEnded(HotseatState from_state,
- HotseatState to_start) override {
- ++observer_counts_.ended;
- if (run_loop_)
- run_loop_->Quit();
- }
- void OnHotseatTransitionAnimationAborted() override {
- ++observer_counts_.aborted;
- }
- void Wait() {
- run_loop_ = std::make_unique<base::RunLoop>();
- run_loop_->Run();
- }
- void Reset() {
- if (run_loop_)
- run_loop_->Quit();
- observer_counts_ = {0};
- }
- // Checks that the started and ending/aborting methods have fired the same
- // amount of times.
- bool ObserverCountsEqual() const {
- return observer_counts_.started ==
- (observer_counts_.ended + observer_counts_.aborted);
- }
- int AnimationAbortedCalls() const { return observer_counts_.aborted; }
- private:
- // Struct which keeps track of the counts of the Observer method has fired.
- // These are used to verify that started calls = ended calls + aborted calls.
- struct ObserverCounts {
- int started;
- int ended;
- int aborted;
- } observer_counts_ = {0};
- std::unique_ptr<base::RunLoop> run_loop_;
- HotseatTransitionAnimator* hotseat_transition_animator_;
- };
- // Used to test the Hotseat, ScrollableShelf, and DenseShelf features.
- INSTANTIATE_TEST_SUITE_P(
- All,
- HotseatWidgetTest,
- testing::Combine(
- testing::Values(ShelfAutoHideBehavior::kNever,
- ShelfAutoHideBehavior::kAlways),
- /*is_assistant_enabled*/ testing::Bool(),
- /*navigation_buttons_shown_in_tablet_mode*/ testing::Bool()));
- TEST_P(HotseatWidgetTest, LongPressHomeWithoutAppWindow) {
- GetPrimaryShelf()->SetAutoHideBehavior(shelf_auto_hide_behavior());
- TabletModeControllerTestApi().EnterTabletMode();
- GetAppListTestHelper()->CheckVisibility(true);
- HotseatStateWatcher watcher(GetShelfLayoutManager());
- ShowShelfAndActivateAssistant();
- GetAppListTestHelper()->CheckVisibility(true);
- EXPECT_EQ(
- is_assistant_enabled(),
- GetAppListTestHelper()->GetAppListView()->IsShowingEmbeddedAssistantUI());
- // Hotseat should not change when showing Assistant.
- watcher.CheckEqual({});
- }
- TEST_P(HotseatWidgetTest, LongPressHomeWithAppWindow) {
- GetPrimaryShelf()->SetAutoHideBehavior(shelf_auto_hide_behavior());
- TabletModeControllerTestApi().EnterTabletMode();
- GetAppListTestHelper()->CheckVisibility(true);
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- GetAppListTestHelper()->CheckVisibility(false);
- HotseatStateWatcher watcher(GetShelfLayoutManager());
- ShowShelfAndActivateAssistant();
- GetAppListTestHelper()->CheckVisibility(false);
- EXPECT_EQ(
- is_assistant_enabled(),
- GetAppListTestHelper()->GetAppListView()->IsShowingEmbeddedAssistantUI());
- std::vector<HotseatState> expected_state;
- if (shelf_auto_hide_behavior() == ShelfAutoHideBehavior::kAlways) {
- // |ShowShelfAndActivateAssistant()| will bring up shelf so it will trigger
- // one hotseat state change.
- expected_state.push_back(HotseatState::kExtended);
- // Launching the assistant from a shelf button on an autohidden shelf will
- // hide the shelf at the end of the operation.
- if (is_assistant_enabled() && navigation_buttons_shown_in_tablet_mode())
- expected_state.push_back(HotseatState::kHidden);
- }
- watcher.CheckEqual(expected_state);
- }
- // Tests that closing a window which was opened prior to entering tablet mode
- // results in a kShownHomeLauncher hotseat.
- TEST_P(HotseatWidgetTest, ClosingLastWindowInTabletMode) {
- GetPrimaryShelf()->SetAutoHideBehavior(shelf_auto_hide_behavior());
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- // Activate the window and go to tablet mode.
- wm::ActivateWindow(window.get());
- TabletModeControllerTestApi().EnterTabletMode();
- // Close the window, the AppListView should be shown, and the hotseat should
- // be kShownHomeLauncher.
- window->Hide();
- EXPECT_EQ(HotseatState::kShownHomeLauncher,
- GetShelfLayoutManager()->hotseat_state());
- GetAppListTestHelper()->CheckVisibility(true);
- }
- // Tests that the hotseat is kShownHomeLauncher when entering tablet mode with
- // no windows.
- TEST_P(HotseatWidgetTest, GoingToTabletModeNoWindows) {
- GetPrimaryShelf()->SetAutoHideBehavior(shelf_auto_hide_behavior());
- TabletModeControllerTestApi().EnterTabletMode();
- GetAppListTestHelper()->CheckVisibility(true);
- EXPECT_EQ(HotseatState::kShownHomeLauncher,
- GetShelfLayoutManager()->hotseat_state());
- }
- // Tests that the hotseat is kHidden when entering tablet mode with a window.
- TEST_P(HotseatWidgetTest, GoingToTabletModeWithWindows) {
- GetPrimaryShelf()->SetAutoHideBehavior(shelf_auto_hide_behavior());
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- // Activate the window and go to tablet mode.
- wm::ActivateWindow(window.get());
- TabletModeControllerTestApi().EnterTabletMode();
- EXPECT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
- GetAppListTestHelper()->CheckVisibility(false);
- }
- // The in-app Hotseat should not be hidden automatically when the shelf context
- // menu shows (https://crbug.com/1020388).
- TEST_P(HotseatWidgetTest, InAppShelfShowingContextMenu) {
- GetPrimaryShelf()->SetAutoHideBehavior(shelf_auto_hide_behavior());
- TabletModeControllerTestApi().EnterTabletMode();
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- EXPECT_FALSE(Shell::Get()->app_list_controller()->IsVisible(
- display::Screen::GetScreen()->GetPrimaryDisplay().id()));
- ShelfTestUtil::AddAppShortcut("app_id", TYPE_PINNED_APP);
- // Swipe up on the shelf to show the hotseat.
- SwipeUpOnShelf();
- EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
- ShelfViewTestAPI shelf_view_test_api(
- GetPrimaryShelf()->shelf_widget()->shelf_view_for_testing());
- ShelfAppButton* app_icon = shelf_view_test_api.GetButton(0);
- // Accelerate the generation of the long press event.
- ui::GestureConfiguration::GetInstance()->set_show_press_delay_in_ms(1);
- ui::GestureConfiguration::GetInstance()->set_short_press_time(
- base::Milliseconds(1));
- ui::GestureConfiguration::GetInstance()->set_long_press_time_in_ms(1);
- // Press the icon enough long time to generate the long press event.
- GetEventGenerator()->MoveTouch(app_icon->GetBoundsInScreen().CenterPoint());
- GetEventGenerator()->PressTouch();
- ui::GestureConfiguration* gesture_config =
- ui::GestureConfiguration::GetInstance();
- const int long_press_delay_ms = gesture_config->long_press_time_in_ms() +
- gesture_config->show_press_delay_in_ms();
- base::RunLoop run_loop;
- base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
- FROM_HERE, run_loop.QuitClosure(),
- base::Milliseconds(long_press_delay_ms));
- run_loop.Run();
- GetEventGenerator()->ReleaseTouch();
- // Expects that the hotseat's state is kExntended.
- EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
- // Ensures that the ink drop state is InkDropState::ACTIVATED before closing
- // the menu.
- app_icon->FireRippleActivationTimerForTest();
- }
- // Tests that a window that is created after going to tablet mode, then closed,
- // results in a kShownHomeLauncher hotseat.
- TEST_P(HotseatWidgetTest, CloseLastWindowOpenedInTabletMode) {
- GetPrimaryShelf()->SetAutoHideBehavior(shelf_auto_hide_behavior());
- TabletModeControllerTestApi().EnterTabletMode();
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- // Activate the window after entering tablet mode.
- wm::ActivateWindow(window.get());
- EXPECT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
- GetAppListTestHelper()->CheckVisibility(false);
- // Hide the window, the hotseat should be kShownHomeLauncher, and the home
- // launcher should be visible.
- window->Hide();
- EXPECT_EQ(HotseatState::kShownHomeLauncher,
- GetShelfLayoutManager()->hotseat_state());
- GetAppListTestHelper()->CheckVisibility(true);
- }
- // Verifies removing a shelf item by dragging it off the extended hotseat.
- TEST_P(HotseatWidgetTest, DragItemOffExtendedHotseat) {
- TabletModeControllerTestApi().EnterTabletMode();
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- ShelfTestUtil::AddAppShortcut("app_id_1", TYPE_PINNED_APP);
- ShelfTestUtil::AddAppShortcut("app_id_2", TYPE_PINNED_APP);
- ShelfView* shelf_view = GetPrimaryShelf()
- ->hotseat_widget()
- ->scrollable_shelf_view()
- ->shelf_view();
- EXPECT_EQ(2u, shelf_view->view_model_for_test()->view_size());
- // Show the in-app shelf.
- SwipeUpOnShelf();
- EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
- // Start mouse drag on a shelf item.
- ShelfAppButton* dragged_button =
- ShelfViewTestAPI(shelf_view).GetButton(/*index=*/0);
- GetEventGenerator()->MoveMouseTo(
- dragged_button->GetBoundsInScreen().CenterPoint());
- GetEventGenerator()->PressLeftButton();
- EXPECT_TRUE(dragged_button->FireDragTimerForTest());
- EXPECT_TRUE(shelf_view->drag_view());
- // Move mouse. Verify that the hotseat is still extended.
- GetEventGenerator()->MoveMouseBy(/*x=*/0, /*y=*/-80);
- EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
- // Release the mouse press. Verify that:
- // 1. Shelf item count decreases by one; and
- // 2. Hotseat is still extended.
- GetEventGenerator()->ReleaseLeftButton();
- EXPECT_EQ(1u, shelf_view->view_model_for_test()->view_size());
- EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
- }
- // Tests that swiping up on an autohidden shelf shows the hotseat, and swiping
- // down hides it.
- TEST_P(HotseatWidgetTest, ShowingAndHidingAutohiddenShelf) {
- if (shelf_auto_hide_behavior() != ShelfAutoHideBehavior::kAlways)
- return;
- GetPrimaryShelf()->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
- TabletModeControllerTestApi().EnterTabletMode();
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- SwipeUpOnShelf();
- EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
- EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, GetPrimaryShelf()->GetAutoHideState());
- SwipeDownOnShelf();
- EXPECT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
- EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, GetPrimaryShelf()->GetAutoHideState());
- // Swipe down again, nothing should change.
- SwipeDownOnShelf();
- EXPECT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
- EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, GetPrimaryShelf()->GetAutoHideState());
- }
- // Tests that swiping up on several places in the in-app shelf shows the
- // hotseat (crbug.com/1016931).
- TEST_P(HotseatWidgetTest, SwipeUpInAppShelfShowsHotseat) {
- TabletModeControllerTestApi().EnterTabletMode();
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- base::HistogramTester histogram_tester;
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeDownToHide, 0);
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeUpToShow, 0);
- // Swipe up from the center of the shelf.
- SwipeUpOnShelf();
- EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeDownToHide, 0);
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeUpToShow, 1);
- // Swipe down from the hotseat to hide it.
- gfx::Rect hotseat_bounds =
- GetPrimaryShelf()->hotseat_widget()->GetWindowBoundsInScreen();
- gfx::Point start = hotseat_bounds.top_center();
- gfx::Point end = start + gfx::Vector2d(0, 80);
- const base::TimeDelta kTimeDelta = base::Milliseconds(100);
- const int kNumScrollSteps = 4;
- GetEventGenerator()->GestureScrollSequence(start, end, kTimeDelta,
- kNumScrollSteps);
- ASSERT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeDownToHide, 1);
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeUpToShow, 1);
- // Swipe up from the right part of the shelf (the system tray).
- start = GetShelfWidget()
- ->status_area_widget()
- ->GetWindowBoundsInScreen()
- .CenterPoint();
- end = start + gfx::Vector2d(0, -80);
- GetEventGenerator()->GestureScrollSequence(start, end, kTimeDelta,
- kNumScrollSteps);
- EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeDownToHide, 1);
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeUpToShow, 2);
- // Swipe down from the hotseat to hide it.
- start = hotseat_bounds.top_center();
- end = start + gfx::Vector2d(0, 80);
- GetEventGenerator()->GestureScrollSequence(start, end, kTimeDelta,
- kNumScrollSteps);
- ASSERT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeDownToHide, 2);
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeUpToShow, 2);
- // Swipe up from the left part of the shelf (the home/back button).
- start = GetShelfWidget()
- ->navigation_widget()
- ->GetWindowBoundsInScreen()
- .CenterPoint();
- end = start + gfx::Vector2d(0, -80);
- GetEventGenerator()->GestureScrollSequence(start, end, kTimeDelta,
- kNumScrollSteps);
- EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeDownToHide, 2);
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeUpToShow, 3);
- }
- // Tests that swiping up on the hotseat does nothing.
- TEST_P(HotseatWidgetTest, SwipeUpOnHotseatBackgroundDoesNothing) {
- GetPrimaryShelf()->SetAutoHideBehavior(shelf_auto_hide_behavior());
- TabletModeControllerTestApi().EnterTabletMode();
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- base::HistogramTester histogram_tester;
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeDownToHide, 0);
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeUpToShow, 0);
- // Swipe up on the shelf to show the hotseat.
- EXPECT_FALSE(Shell::Get()->app_list_controller()->IsVisible(
- display::Screen::GetScreen()->GetPrimaryDisplay().id()));
- SwipeUpOnShelf();
- EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeDownToHide, 0);
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeUpToShow, 1);
- if (shelf_auto_hide_behavior() == ShelfAutoHideBehavior::kAlways)
- EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, GetPrimaryShelf()->GetAutoHideState());
- // Swipe up on the Hotseat (parent of ShelfView) does nothing.
- gfx::Point start(GetPrimaryShelf()
- ->shelf_widget()
- ->hotseat_widget()
- ->GetWindowBoundsInScreen()
- .top_center());
- const gfx::Point end(start + gfx::Vector2d(0, -300));
- const base::TimeDelta kTimeDelta = base::Milliseconds(100);
- const int kNumScrollSteps = 4;
- GetEventGenerator()->GestureScrollSequence(start, end, kTimeDelta,
- kNumScrollSteps);
- EXPECT_FALSE(Shell::Get()->app_list_controller()->IsVisible(
- display::Screen::GetScreen()->GetPrimaryDisplay().id()));
- EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
- if (shelf_auto_hide_behavior() == ShelfAutoHideBehavior::kAlways)
- EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, GetPrimaryShelf()->GetAutoHideState());
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeDownToHide, 0);
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeUpToShow, 1);
- }
- // Tests that tapping an active window with an extended hotseat results in a
- // hidden hotseat.
- TEST_P(HotseatWidgetTest, TappingActiveWindowHidesHotseat) {
- GetPrimaryShelf()->SetAutoHideBehavior(shelf_auto_hide_behavior());
- TabletModeControllerTestApi().EnterTabletMode();
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- base::HistogramTester histogram_tester;
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeDownToHide, 0);
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeUpToShow, 0);
- histogram_tester.ExpectBucketCount(
- kHotseatGestureHistogramName,
- InAppShelfGestures::kHotseatHiddenDueToInteractionOutsideOfShelf, 0);
- // Swipe up on the shelf to show the hotseat.
- SwipeUpOnShelf();
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeDownToHide, 0);
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeUpToShow, 1);
- histogram_tester.ExpectBucketCount(
- kHotseatGestureHistogramName,
- InAppShelfGestures::kHotseatHiddenDueToInteractionOutsideOfShelf, 0);
- // Tap the shelf background, nothing should happen.
- gfx::Rect display_bounds =
- display::Screen::GetScreen()->GetPrimaryDisplay().bounds();
- gfx::Point tap_point = display_bounds.bottom_center();
- GetEventGenerator()->GestureTapAt(tap_point);
- EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
- if (shelf_auto_hide_behavior() == ShelfAutoHideBehavior::kAlways)
- EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, GetPrimaryShelf()->GetAutoHideState());
- // Tap the active window, the hotseat should hide.
- tap_point.Offset(0, -200);
- GetEventGenerator()->GestureTapAt(tap_point);
- EXPECT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
- if (shelf_auto_hide_behavior() == ShelfAutoHideBehavior::kAlways)
- EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, GetPrimaryShelf()->GetAutoHideState());
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeDownToHide, 0);
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeUpToShow, 1);
- histogram_tester.ExpectBucketCount(
- kHotseatGestureHistogramName,
- InAppShelfGestures::kHotseatHiddenDueToInteractionOutsideOfShelf, 1);
- }
- // Tests that gesture dragging an active window hides the hotseat.
- TEST_P(HotseatWidgetTest, GestureDraggingActiveWindowHidesHotseat) {
- GetPrimaryShelf()->SetAutoHideBehavior(shelf_auto_hide_behavior());
- TabletModeControllerTestApi().EnterTabletMode();
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- base::HistogramTester histogram_tester;
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeDownToHide, 0);
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeUpToShow, 0);
- // Swipe up on the shelf to show the hotseat.
- SwipeUpOnShelf();
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeDownToHide, 0);
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeUpToShow, 1);
- if (shelf_auto_hide_behavior() == ShelfAutoHideBehavior::kAlways)
- EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, GetPrimaryShelf()->GetAutoHideState());
- // Gesture drag on the active window, the hotseat should hide.
- gfx::Rect display_bounds =
- display::Screen::GetScreen()->GetPrimaryDisplay().bounds();
- gfx::Point start = display_bounds.bottom_center();
- start.Offset(0, -200);
- gfx::Point end = start;
- end.Offset(0, -200);
- GetEventGenerator()->GestureScrollSequence(start, end, base::Milliseconds(10),
- 4);
- EXPECT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
- if (shelf_auto_hide_behavior() == ShelfAutoHideBehavior::kAlways)
- EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, GetPrimaryShelf()->GetAutoHideState());
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeDownToHide, 0);
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeUpToShow, 1);
- }
- // Tests that a swipe up on the shelf shows the hotseat while in split view.
- TEST_P(HotseatWidgetTest, SwipeUpOnShelfShowsHotseatInSplitView) {
- TabletModeControllerTestApi().EnterTabletMode();
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- std::unique_ptr<aura::Window> window2 =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- base::HistogramTester histogram_tester;
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeDownToHide, 0);
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeUpToShow, 0);
- // Go into split view mode by first going into overview, and then snapping
- // the open window on one side.
- EnterOverview();
- SplitViewController* split_view_controller =
- SplitViewController::Get(Shell::GetPrimaryRootWindow());
- split_view_controller->SnapWindow(window.get(), SplitViewController::LEFT);
- split_view_controller->SnapWindow(window2.get(), SplitViewController::RIGHT);
- EXPECT_TRUE(split_view_controller->BothSnapped());
- // We should still be able to drag up the hotseat.
- SwipeUpOnShelf();
- EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeDownToHide, 0);
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeUpToShow, 1);
- }
- // Tests that HotseatTransitionAimationObserver starting and ending calls have a
- // 1:1 relation. This test verifies that behavior.
- TEST_P(HotseatWidgetTest, ObserverCallsMatch) {
- ui::ScopedAnimationDurationScaleMode non_zero(
- ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
- // Enter tablet mode to show the home launcher. Hotseat state should be
- // kShownHomeLauncher.
- TabletModeControllerTestApi().EnterTabletMode();
- ASSERT_EQ(HotseatState::kShownHomeLauncher,
- GetShelfLayoutManager()->hotseat_state());
- // Create a window to transition to the in-app shelf. Hotseat state should be
- // kHidden.
- HotseatTransitionAnimationObserver observer(
- GetPrimaryShelf()->shelf_widget()->hotseat_transition_animator());
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 800, 800));
- observer.Wait();
- EXPECT_TRUE(observer.ObserverCountsEqual());
- ASSERT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
- observer.Reset();
- // Go to home launcher again. Hotseat state should be kShownHomeLauncher.
- ShowShelfAndGoHome();
- observer.Wait();
- EXPECT_TRUE(observer.ObserverCountsEqual());
- ASSERT_EQ(HotseatState::kShownHomeLauncher,
- GetShelfLayoutManager()->hotseat_state());
- observer.Reset();
- // Go to overview and cancel immediately. Hotseat state should be
- // kShownHomeLauncher.
- StartOverview();
- EXPECT_TRUE(Shell::Get()->overview_controller()->IsInStartAnimation());
- // No animations should have been started so no animations are in progress
- // or aborted.
- EXPECT_TRUE(observer.ObserverCountsEqual());
- EXPECT_EQ(0, observer.AnimationAbortedCalls());
- EndOverview();
- // No animations should have been started or aborted.
- EXPECT_EQ(0, observer.AnimationAbortedCalls());
- EXPECT_TRUE(observer.ObserverCountsEqual());
- ASSERT_EQ(HotseatState::kShownHomeLauncher,
- GetShelfLayoutManager()->hotseat_state());
- observer.Reset();
- // Go to overview. Hotseat state should be kExtended.
- StartOverview();
- ASSERT_EQ(HotseatState::kShownHomeLauncher,
- GetShelfLayoutManager()->hotseat_state());
- EXPECT_TRUE(observer.ObserverCountsEqual());
- }
- // Tests that a swipe up on the shelf shows the hotseat while in split view.
- TEST_P(HotseatWidgetTest, DisableBlurDuringOverviewMode) {
- TabletModeControllerTestApi().EnterTabletMode();
- ASSERT_EQ(
- ShelfConfig::Get()->shelf_blur_radius(),
- GetShelfWidget()->hotseat_widget()->GetHotseatBackgroundBlurForTest());
- // Go into overview and check that at the end of the animation, background
- // blur is disabled.
- StartOverview();
- WaitForOverviewAnimation(/*enter=*/true);
- EXPECT_EQ(
- 0, GetShelfWidget()->hotseat_widget()->GetHotseatBackgroundBlurForTest());
- // Exit overview and check that at the end of the animation, background
- // blur is enabled again.
- EndOverview();
- WaitForOverviewAnimation(/*enter=*/false);
- EXPECT_EQ(
- ShelfConfig::Get()->shelf_blur_radius(),
- GetShelfWidget()->hotseat_widget()->GetHotseatBackgroundBlurForTest());
- }
- // Tests that releasing the hotseat gesture below the threshold results in a
- // kHidden hotseat when the shelf is shown.
- TEST_P(HotseatWidgetTest, ReleasingSlowDragBelowThreshold) {
- GetPrimaryShelf()->SetAutoHideBehavior(ShelfAutoHideBehavior::kNever);
- TabletModeControllerTestApi().EnterTabletMode();
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- base::HistogramTester histogram_tester;
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeDownToHide, 0);
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeUpToShow, 0);
- gfx::Rect display_bounds =
- display::Screen::GetScreen()->GetPrimaryDisplay().bounds();
- const gfx::Point start(display_bounds.bottom_center());
- const int hotseat_size = GetPrimaryShelf()
- ->shelf_widget()
- ->hotseat_widget()
- ->GetWindowBoundsInScreen()
- .height();
- const gfx::Point end(start + gfx::Vector2d(0, -hotseat_size / 2 + 1));
- const base::TimeDelta kTimeDelta = base::Milliseconds(1000);
- const int kNumScrollSteps = 4;
- GetEventGenerator()->GestureScrollSequence(start, end, kTimeDelta,
- kNumScrollSteps);
- EXPECT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeDownToHide, 0);
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeUpToShow, 0);
- }
- // Tests that releasing the hotseat gesture above the threshold results in a
- // kExtended hotseat.
- TEST_P(HotseatWidgetTest, ReleasingSlowDragAboveThreshold) {
- GetPrimaryShelf()->SetAutoHideBehavior(shelf_auto_hide_behavior());
- TabletModeControllerTestApi().EnterTabletMode();
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- base::HistogramTester histogram_tester;
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeDownToHide, 0);
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeUpToShow, 0);
- gfx::Rect display_bounds =
- display::Screen::GetScreen()->GetPrimaryDisplay().bounds();
- const gfx::Point start(display_bounds.bottom_center());
- const int hotseat_size = GetPrimaryShelf()
- ->shelf_widget()
- ->hotseat_widget()
- ->GetWindowBoundsInScreen()
- .height();
- const gfx::Point end(start + gfx::Vector2d(0, -hotseat_size * 3.0f / 2.0f));
- const base::TimeDelta kTimeDelta = base::Milliseconds(1000);
- const int kNumScrollSteps = 4;
- GetEventGenerator()->GestureScrollSequence(start, end, kTimeDelta,
- kNumScrollSteps);
- EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
- if (shelf_auto_hide_behavior() == ShelfAutoHideBehavior::kAlways)
- EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, GetPrimaryShelf()->GetAutoHideState());
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeDownToHide, 0);
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeUpToShow, 1);
- }
- // Tests that releasing the hotseat gesture when a stylus app is active has a
- // bigger thresehold than normal apps.
- TEST_P(HotseatWidgetTest, HotseatDragGestureForStylusApp) {
- GetPrimaryShelf()->SetAutoHideBehavior(shelf_auto_hide_behavior());
- TabletModeControllerTestApi().EnterTabletMode();
- // Taken from ShelfLayoutManager.
- const int kShelfPalmRejectionSwipeOffset = 80;
- const std::string stylus_app = "fhapgmpiiiigioilnjmkiohjhlegnceb";
- ShelfModel* model = Shell::Get()->shelf_controller()->model();
- const ShelfID test_stylus_app_id(stylus_app);
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- window->SetProperty(kShelfIDKey, test_stylus_app_id.Serialize());
- wm::ActivateWindow(window.get());
- EXPECT_EQ(test_stylus_app_id, model->active_shelf_id());
- base::HistogramTester histogram_tester;
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeDownToHide, 0);
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeUpToShow, 0);
- gfx::Rect display_bounds =
- display::Screen::GetScreen()->GetPrimaryDisplay().bounds();
- const gfx::Point start(display_bounds.bottom_center());
- const int hotseat_size = GetPrimaryShelf()
- ->shelf_widget()
- ->hotseat_widget()
- ->GetWindowBoundsInScreen()
- .height();
- const gfx::Point normal_thereshold(
- start + gfx::Vector2d(0, -hotseat_size * 3.0f / 2.0f));
- const base::TimeDelta kTimeDelta = base::Milliseconds(1000);
- const int kNumScrollSteps = 4;
- GetEventGenerator()->GestureScrollSequence(start, normal_thereshold,
- kTimeDelta, kNumScrollSteps);
- EXPECT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
- const gfx::Point offset_thereshold(
- normal_thereshold + gfx::Vector2d(0, -kShelfPalmRejectionSwipeOffset));
- GetEventGenerator()->GestureScrollSequence(start, offset_thereshold,
- kTimeDelta, kNumScrollSteps);
- EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
- if (shelf_auto_hide_behavior() == ShelfAutoHideBehavior::kAlways)
- EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, GetPrimaryShelf()->GetAutoHideState());
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeDownToHide, 0);
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeUpToShow, 1);
- }
- // Tests that showing overview after showing the hotseat results in only one
- // animation, to |kExtended|.
- TEST_P(HotseatWidgetTest, ShowingOverviewFromShownAnimatesOnce) {
- GetPrimaryShelf()->SetAutoHideBehavior(shelf_auto_hide_behavior());
- TabletModeControllerTestApi().EnterTabletMode();
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- std::unique_ptr<HotseatStateWatcher> state_watcher_ =
- std::make_unique<HotseatStateWatcher>(GetShelfLayoutManager());
- SwipeUpOnShelf();
- ASSERT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
- StartOverview();
- state_watcher_->CheckEqual({HotseatState::kExtended});
- }
- // Tests that the hotseat is not flush with the bottom of the screen when home
- // launcher is showing.
- TEST_P(HotseatWidgetTest, HotseatNotFlushWhenHomeLauncherShowing) {
- GetPrimaryShelf()->SetAutoHideBehavior(shelf_auto_hide_behavior());
- TabletModeControllerTestApi().EnterTabletMode();
- const int display_height =
- display::Screen::GetScreen()->GetPrimaryDisplay().bounds().height();
- const int hotseat_bottom = GetPrimaryShelf()
- ->shelf_widget()
- ->hotseat_widget()
- ->GetWindowBoundsInScreen()
- .bottom();
- EXPECT_LT(hotseat_bottom, display_height);
- }
- // Tests that home -> overview results in only one hotseat state change.
- TEST_P(HotseatWidgetTest, HomeToOverviewChangesStateOnce) {
- GetPrimaryShelf()->SetAutoHideBehavior(shelf_auto_hide_behavior());
- TabletModeControllerTestApi().EnterTabletMode();
- // First, try with no windows open.
- {
- HotseatStateWatcher watcher(GetShelfLayoutManager());
- StartOverview();
- WaitForOverviewAnimation(/*enter=*/true);
- watcher.CheckEqual({/* shelf state should not change*/});
- }
- // Open a window, then open the home launcher.
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- ShowShelfAndGoHome();
- GetAppListTestHelper()->CheckVisibility(true);
- // Activate overview and expect the hotseat only changes state to extended.
- {
- HotseatStateWatcher watcher(GetShelfLayoutManager());
- StartOverview();
- WaitForOverviewAnimation(/*enter=*/true);
- watcher.CheckEqual({/* shelf state should not change*/});
- }
- }
- // Verifies that the hotseat widget and the status area widget are animated to
- // the target location when entering overview mode in home launcher
- // (https://crbug.com/1079347).
- TEST_P(HotseatWidgetTest, VerifyShelfAnimationWhenEnteringOverview) {
- GetPrimaryShelf()->SetAutoHideBehavior(shelf_auto_hide_behavior());
- TabletModeControllerTestApi().EnterTabletMode();
- ui::ScopedAnimationDurationScaleMode non_zero_duration_mode(
- ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
- HotseatWidget* hotseat_widget = GetPrimaryShelf()->hotseat_widget();
- ASSERT_EQ(HotseatState::kShownHomeLauncher, hotseat_widget->state());
- ui::LayerAnimator* hotseat_layer_animator =
- hotseat_widget->GetNativeView()->layer()->GetAnimator();
- ui::LayerAnimator* status_area_layer_animator = GetShelfWidget()
- ->status_area_widget()
- ->GetNativeView()
- ->layer()
- ->GetAnimator();
- ASSERT_FALSE(hotseat_layer_animator->is_animating());
- ASSERT_FALSE(status_area_layer_animator->is_animating());
- StartOverview();
- EXPECT_FALSE(hotseat_layer_animator->is_animating());
- EXPECT_FALSE(status_area_layer_animator->is_animating());
- ASSERT_EQ(HotseatState::kShownHomeLauncher, hotseat_widget->state());
- }
- // Tests that home -> in-app results in only one state change.
- TEST_P(HotseatWidgetTest, HomeToInAppChangesStateOnce) {
- GetPrimaryShelf()->SetAutoHideBehavior(shelf_auto_hide_behavior());
- TabletModeControllerTestApi().EnterTabletMode();
- // Go to in-app, the hotseat should hide.
- HotseatStateWatcher watcher(GetShelfLayoutManager());
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- watcher.CheckEqual({HotseatState::kHidden});
- }
- // Tests that in-app -> home via closing the only window, swiping from the
- // bottom of the shelf, and tapping the home launcher button results in only one
- // state change.
- TEST_P(HotseatWidgetTest, InAppToHomeChangesStateOnce) {
- GetPrimaryShelf()->SetAutoHideBehavior(shelf_auto_hide_behavior());
- TabletModeControllerTestApi().EnterTabletMode();
- // Go to in-app with an extended hotseat.
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- SwipeUpOnShelf();
- // Press the home button, the hotseat should transition directly to
- // kShownHomeLauncher.
- {
- HotseatStateWatcher watcher(GetShelfLayoutManager());
- ShowShelfAndGoHome();
- watcher.CheckEqual({HotseatState::kShownHomeLauncher});
- }
- // Go to in-app.
- window->Show();
- wm::ActivateWindow(window.get());
- // Extend the hotseat, then Swipe up to go home, the hotseat should transition
- // directly to kShownHomeLauncher.
- SwipeUpOnShelf();
- {
- ui::ScopedAnimationDurationScaleMode regular_animations(
- ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
- HotseatStateWatcher watcher(GetShelfLayoutManager());
- FlingUpOnShelf();
- watcher.CheckEqual({HotseatState::kShownHomeLauncher});
- // Wait for the window animation to complete, and verify the hotseat state
- // remained kShownHomeLauncher.
- ShellTestApi().WaitForWindowFinishAnimating(window.get());
- watcher.CheckEqual({HotseatState::kShownHomeLauncher});
- }
- // Nothing left to test for autohidden shelf.
- if (shelf_auto_hide_behavior() == ShelfAutoHideBehavior::kAlways)
- return;
- // Go to in-app and do not extend the hotseat.
- window->Show();
- wm::ActivateWindow(window.get());
- // TODO(manucornet): This is flaky when the shelf is always auto-hidden.
- // Investigate and fix (sometimes fails when the assistant is enabled,
- // sometimes not).
- if (shelf_auto_hide_behavior() == ShelfAutoHideBehavior::kNever)
- return;
- // Press the home button, the hotseat should transition directly to
- // kShownHomeLauncher.
- {
- HotseatStateWatcher watcher(GetShelfLayoutManager());
- ShowShelfAndGoHome();
- watcher.CheckEqual({HotseatState::kShownHomeLauncher});
- }
- }
- // Tests that transitioning from overview to home while a transition from home
- // to overview is still in progress ends up with hotseat in kShownHomeLauncher
- // state (and in app shelf not visible).
- TEST_P(HotseatWidgetTest, HomeToOverviewAndBack) {
- GetPrimaryShelf()->SetAutoHideBehavior(shelf_auto_hide_behavior());
- TabletModeControllerTestApi().EnterTabletMode();
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- WindowState::Get(window.get())->Minimize();
- HotseatStateWatcher watcher(GetShelfLayoutManager());
- // Start going to overview.
- {
- ui::ScopedAnimationDurationScaleMode regular_animations(
- ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
- StartOverview();
- watcher.CheckEqual({/*Hotseat state should not change*/});
- }
- OverviewController* overview_controller = Shell::Get()->overview_controller();
- EXPECT_TRUE(overview_controller->InOverviewSession());
- ShowShelfAndGoHome();
- GetAppListTestHelper()->CheckVisibility(true);
- EXPECT_FALSE(overview_controller->InOverviewSession());
- EXPECT_FALSE(ShelfConfig::Get()->is_in_app());
- watcher.CheckEqual({/*Hotseat state should not change*/});
- }
- TEST_P(HotseatWidgetTest, InAppToOverviewAndBack) {
- GetPrimaryShelf()->SetAutoHideBehavior(shelf_auto_hide_behavior());
- TabletModeControllerTestApi().EnterTabletMode();
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- // Start watching hotseat state before swipping up the shelf, so hotseat
- // change expectation match for both auto-hidden and always-shown shelf.
- HotseatStateWatcher watcher(GetShelfLayoutManager());
- // Make sure shelf (and overview button) are visible - this is moves the
- // hotseat into kExtended state.
- if (shelf_auto_hide_behavior() == ShelfAutoHideBehavior::kAlways)
- SwipeUpOnShelf();
- // Start going to overview - use non zero animation so transition is not
- // immediate.
- {
- ui::ScopedAnimationDurationScaleMode regular_animations(
- ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
- StartOverview();
- }
- OverviewController* overview_controller = Shell::Get()->overview_controller();
- EXPECT_TRUE(overview_controller->InOverviewSession());
- GetAppListTestHelper()->CheckVisibility(false);
- // Hotseat should be extended as overview is starting.
- watcher.CheckEqual({HotseatState::kExtended});
- // Exit overview to go back to the app window.
- EndOverview();
- EXPECT_FALSE(overview_controller->InOverviewSession());
- EXPECT_TRUE(ShelfConfig::Get()->is_in_app());
- // The hotseat is expected to be hidden.
- watcher.CheckEqual({HotseatState::kExtended, HotseatState::kHidden});
- }
- // Tests transition to home screen initiated while transition from app window to
- // overview is in progress.
- TEST_P(HotseatWidgetTest, ShowShelfAndGoHomeDuringInAppToOverviewTransition) {
- GetPrimaryShelf()->SetAutoHideBehavior(shelf_auto_hide_behavior());
- TabletModeControllerTestApi().EnterTabletMode();
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- // Start watching hotseat state before swipping up the shelf, so hotseat
- // change expectation match for both auto-hidden and always-shown shelf.
- HotseatStateWatcher watcher(GetShelfLayoutManager());
- // Make sure shelf (and overview button) are visible - this is moves the
- // hotseat into kExtended state.
- if (shelf_auto_hide_behavior() == ShelfAutoHideBehavior::kAlways)
- SwipeUpOnShelf();
- // Start going to overview - use non zero animation so transition is not
- // immediate.
- {
- ui::ScopedAnimationDurationScaleMode regular_animations(
- ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
- StartOverview();
- }
- OverviewController* overview_controller = Shell::Get()->overview_controller();
- EXPECT_TRUE(overview_controller->InOverviewSession());
- GetAppListTestHelper()->CheckVisibility(false);
- // Hotseat should be extended as overview is starting.
- watcher.CheckEqual({HotseatState::kExtended});
- // Go home - expect transition to home (with hotseat in kShownHomeLauncher
- // state, and in app shelf hidden).
- ShowShelfAndGoHome();
- GetAppListTestHelper()->CheckVisibility(true);
- EXPECT_FALSE(overview_controller->InOverviewSession());
- EXPECT_FALSE(ShelfConfig::Get()->is_in_app());
- watcher.CheckEqual(
- {HotseatState::kExtended, HotseatState::kShownHomeLauncher});
- }
- // Tests that in-app -> overview results in only one state change with an
- // autohidden shelf.
- TEST_P(HotseatWidgetTest, InAppToOverviewChangesStateOnceAutohiddenShelf) {
- GetPrimaryShelf()->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
- TabletModeControllerTestApi().EnterTabletMode();
- // Test going to overview mode using the controller from an autohide hidden
- // shelf. Go to in-app.
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- {
- HotseatStateWatcher watcher(GetShelfLayoutManager());
- // Enter overview by using the controller.
- EnterOverview();
- WaitForOverviewAnimation(/*enter=*/true);
- watcher.CheckEqual({HotseatState::kExtended});
- }
- ExitOverview();
- WaitForOverviewAnimation(/*enter=*/false);
- // Test in-app -> overview again with the autohide shown shelf.
- EXPECT_TRUE(ShelfConfig::Get()->is_in_app());
- EXPECT_EQ(ShelfAutoHideState::SHELF_AUTO_HIDE_HIDDEN,
- GetShelfLayoutManager()->auto_hide_state());
- SwipeUpOnShelf();
- {
- HotseatStateWatcher watcher(GetShelfLayoutManager());
- // Enter overview by using the controller.
- EnterOverview();
- WaitForOverviewAnimation(/*enter=*/true);
- watcher.CheckEqual({});
- EXPECT_EQ(HotseatState::kExtended,
- GetShelfLayoutManager()->hotseat_state());
- }
- }
- // Tests that going between Applist and overview in tablet mode with no windows
- // results in no work area change.
- TEST_P(HotseatWidgetTest,
- WorkAreaDoesNotUpdateAppListToFromOverviewWithNoWindow) {
- TabletModeControllerTestApi().EnterTabletMode();
- DisplayWorkAreaChangeCounter counter;
- EnterOverview();
- WaitForOverviewAnimation(/*enter=*/true);
- EXPECT_EQ(0, counter.count());
- EnterOverview();
- WaitForOverviewAnimation(/*enter=*/true);
- EXPECT_EQ(0, counter.count());
- }
- // Tests that switching between AppList and overview with a window results in no
- // work area change.
- TEST_P(HotseatWidgetTest,
- WorkAreaDoesNotUpdateAppListToFromOverviewWithWindow) {
- DisplayWorkAreaChangeCounter counter;
- TabletModeControllerTestApi().EnterTabletMode();
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- ASSERT_EQ(1, counter.count());
- ShowShelfAndGoHome();
- StartOverview();
- WaitForOverviewAnimation(/*enter=*/true);
- EXPECT_EQ(1, counter.count());
- EndOverview();
- WaitForOverviewAnimation(/*enter=*/false);
- EXPECT_EQ(1, counter.count());
- }
- // Tests that switching between AppList and an active window does not update the
- // work area.
- TEST_P(HotseatWidgetTest, WorkAreaDoesNotUpdateOpenWindowToFromAppList) {
- TabletModeControllerTestApi().EnterTabletMode();
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- ASSERT_TRUE(ShelfConfig::Get()->is_in_app());
- // Go to the home launcher, work area should not update.
- DisplayWorkAreaChangeCounter counter;
- ShowShelfAndGoHome();
- GetAppListTestHelper()->CheckVisibility(true);
- EXPECT_EQ(0, counter.count());
- // Go back to the window, work area should not update.
- wm::ActivateWindow(window.get());
- EXPECT_TRUE(ShelfConfig::Get()->is_in_app());
- EXPECT_EQ(0, counter.count());
- }
- // Tests that switching between overview and an active window does not update
- // the work area.
- TEST_P(HotseatWidgetTest, WorkAreaDoesNotUpdateOpenWindowToFromOverview) {
- TabletModeControllerTestApi().EnterTabletMode();
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- ASSERT_TRUE(ShelfConfig::Get()->is_in_app());
- // Go to overview, there should not be a work area update.
- DisplayWorkAreaChangeCounter counter;
- StartOverview();
- WaitForOverviewAnimation(/*enter=*/true);
- EXPECT_EQ(0, counter.count());
- // Go back to the app, there should not be a work area update.
- wm::ActivateWindow(window.get());
- EXPECT_TRUE(ShelfConfig::Get()->is_in_app());
- EXPECT_EQ(0, counter.count());
- }
- // Tests that the shelf opaque background is properly updated after a tablet
- // mode transition with no apps.
- TEST_P(HotseatWidgetTest, ShelfBackgroundNotVisibleInTabletModeNoApps) {
- TabletModeControllerTestApi().EnterTabletMode();
- EXPECT_FALSE(GetShelfWidget()->GetOpaqueBackground()->visible());
- }
- // Tests that the shelf opaque background is properly updated after a tablet
- // mode transition with no apps with dense shelf.
- TEST_P(HotseatWidgetTest, DenseShelfBackgroundNotVisibleInTabletModeNoApps) {
- UpdateDisplay("300x1000");
- TabletModeControllerTestApi().EnterTabletMode();
- EXPECT_FALSE(GetShelfWidget()->GetOpaqueBackground()->visible());
- }
- // Tests that the hotseat is extended if focused with a keyboard.
- TEST_P(HotseatWidgetTest, ExtendHotseatIfFocusedWithKeyboard) {
- TabletModeControllerTestApi().EnterTabletMode();
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- ASSERT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
- // Focus the shelf. Hotseat should now show extended.
- GetPrimaryShelf()->shelf_focus_cycler()->FocusShelf(false /* last_element */);
- EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
- // Focus the status area. Hotseat should now hide, as it was
- // automatically extended by focusing it.
- GetPrimaryShelf()->shelf_focus_cycler()->FocusStatusArea(
- false /* last_element */);
- EXPECT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
- // Now swipe up to show the shelf and then focus it with the keyboard. Hotseat
- // should keep extended.
- SwipeUpOnShelf();
- GetPrimaryShelf()->shelf_focus_cycler()->FocusShelf(false /* last_element */);
- EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
- // Now focus the status area widget again. Hotseat should remain shown, as it
- // was manually extended.
- GetPrimaryShelf()->shelf_focus_cycler()->FocusStatusArea(
- false /* last_element */);
- EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
- }
- // Tests that if the hotseat was hidden while being focused, doing a traversal
- // focus on the next element brings it up again.
- TEST_P(HotseatWidgetTest, SwipeDownOnFocusedHotseat) {
- TabletModeControllerTestApi().EnterTabletMode();
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- ShelfTestUtil::AddAppShortcut("app_id_1", TYPE_APP);
- ShelfTestUtil::AddAppShortcut("app_id_2", TYPE_APP);
- ASSERT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
- // Focus the shelf, then swipe down on the shelf to hide it. Hotseat should be
- // hidden.
- GetPrimaryShelf()->shelf_focus_cycler()->FocusShelf(false /* last_element */);
- gfx::Rect hotseat_bounds =
- GetPrimaryShelf()->hotseat_widget()->GetWindowBoundsInScreen();
- gfx::Point start = hotseat_bounds.top_center();
- gfx::Point end = start + gfx::Vector2d(0, 80);
- GetEventGenerator()->GestureScrollSequence(
- start, end, base::Milliseconds(100), 4 /*scroll_steps*/);
- EXPECT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
- // Focus to the next element in the hotseat. The hotseat should show again.
- PressAndReleaseKey(ui::VKEY_TAB);
- EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
- }
- // Tests that in overview, we can still exit by clicking on the hotseat if the
- // point is not on the visible area.
- TEST_P(HotseatWidgetTest, ExitOverviewWithClickOnHotseat) {
- std::unique_ptr<aura::Window> window1 = AshTestBase::CreateTestWindow();
- ShelfTestUtil::AddAppShortcut("app_id_1", TYPE_APP);
- TabletModeControllerTestApi().EnterTabletMode();
- ASSERT_TRUE(TabletModeControllerTestApi().IsTabletModeStarted());
- ASSERT_FALSE(WindowState::Get(window1.get())->IsMinimized());
- // Enter overview, hotseat is visible. Choose the point to the farthest left.
- // This point will not be visible.
- auto* overview_controller = Shell::Get()->overview_controller();
- auto* hotseat_widget = GetPrimaryShelf()->hotseat_widget();
- EnterOverview();
- ASSERT_TRUE(overview_controller->InOverviewSession());
- ASSERT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
- gfx::Point far_left_point =
- hotseat_widget->GetWindowBoundsInScreen().left_center();
- // Tests that on clicking, we exit overview and all windows are minimized.
- GetEventGenerator()->set_current_screen_location(far_left_point);
- GetEventGenerator()->ClickLeftButton();
- EXPECT_EQ(HotseatState::kShownHomeLauncher,
- GetShelfLayoutManager()->hotseat_state());
- EXPECT_TRUE(WindowState::Get(window1.get())->IsMinimized());
- EXPECT_FALSE(overview_controller->InOverviewSession());
- }
- // Hides the hotseat if the hotseat is in kExtendedMode and the system tray
- // is about to show (see https://crbug.com/1028321).
- TEST_P(HotseatWidgetTest, DismissHotseatWhenSystemTrayShows) {
- GetPrimaryShelf()->SetAutoHideBehavior(shelf_auto_hide_behavior());
- TabletModeControllerTestApi().EnterTabletMode();
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- SwipeUpOnShelf();
- ASSERT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
- // Activates the system tray when hotseat is in kExtended mode and waits for
- // the update in system tray to finish.
- StatusAreaWidget* status_area_widget = GetShelfWidget()->status_area_widget();
- const gfx::Point status_area_widget_center =
- status_area_widget->GetNativeView()->GetBoundsInScreen().CenterPoint();
- GetEventGenerator()->GestureTapAt(status_area_widget_center);
- base::RunLoop().RunUntilIdle();
- // Expects that the system tray shows and the hotseat is hidden.
- EXPECT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
- EXPECT_TRUE(status_area_widget->unified_system_tray()->IsBubbleShown());
- // Early out since the remaining code is only meaningful for auto-hide shelf.
- if (GetPrimaryShelf()->auto_hide_behavior() !=
- ShelfAutoHideBehavior::kAlways) {
- return;
- }
- // Auto-hide shelf should show when opening the system tray.
- EXPECT_EQ(ShelfAutoHideState::SHELF_AUTO_HIDE_SHOWN,
- GetShelfLayoutManager()->auto_hide_state());
- // Auto-hide shelf should hide when closing the system tray.
- GetEventGenerator()->GestureTapAt(status_area_widget_center);
- // Waits for the system tray to be closed.
- base::RunLoop().RunUntilIdle();
- EXPECT_EQ(ShelfAutoHideState::SHELF_AUTO_HIDE_HIDDEN,
- GetShelfLayoutManager()->auto_hide_state());
- }
- // Tests that the hotseat hides when it is in kExtendedMode and a status area
- // tray bubble is shown.
- TEST_P(HotseatWidgetTest, DismissHotseatWhenStatusAreaTrayShows) {
- TabletModeControllerTestApi().EnterTabletMode();
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- StatusAreaWidget* status_area_widget = GetShelfWidget()->status_area_widget();
- status_area_widget->ime_menu_tray()->SetVisiblePreferred(true);
- // Show the hotseat.
- SwipeUpOnShelf();
- ASSERT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
- EXPECT_FALSE(status_area_widget->ime_menu_tray()->GetBubbleView());
- // Show the ime menu tray bubble, and wait for the hotseat to be hidden.
- GetEventGenerator()->GestureTapAt(
- status_area_widget->ime_menu_tray()->GetBoundsInScreen().CenterPoint());
- base::RunLoop().RunUntilIdle();
- // The hotseat should be hidden and the tray bubble should be shown.
- EXPECT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
- EXPECT_TRUE(status_area_widget->ime_menu_tray()->GetBubbleView());
- // Swiping up on the shelf should hide the tray bubble and extend the hotseat.
- SwipeUpOnShelf();
- EXPECT_FALSE(status_area_widget->ime_menu_tray()->GetBubbleView());
- EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
- }
- // Tests that the work area updates once each when going to/from tablet mode
- // with no windows open.
- TEST_P(HotseatWidgetTest, WorkAreaUpdatesClamshellToFromHomeLauncherNoWindows) {
- DisplayWorkAreaChangeCounter counter;
- TabletModeControllerTestApi().EnterTabletMode();
- EXPECT_EQ(1, counter.count());
- TabletModeControllerTestApi().LeaveTabletMode();
- EXPECT_EQ(2, counter.count());
- }
- // Tests that the work area changes just once when opening a window in tablet
- // mode.
- TEST_P(HotseatWidgetTest, OpenWindowInTabletModeChangesWorkArea) {
- DisplayWorkAreaChangeCounter counter;
- TabletModeControllerTestApi().EnterTabletMode();
- ASSERT_EQ(1, counter.count());
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- EXPECT_EQ(1, counter.count());
- }
- // Tests that going to and from tablet mode with an open window results in a
- // work area change.
- TEST_P(HotseatWidgetTest, ToFromTabletModeWithWindowChangesWorkArea) {
- DisplayWorkAreaChangeCounter counter;
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- TabletModeControllerTestApi().EnterTabletMode();
- EXPECT_EQ(1, counter.count());
- TabletModeControllerTestApi().LeaveTabletMode();
- EXPECT_EQ(2, counter.count());
- }
- // Tests that the work area changes when fullscreening the active window or
- // autohiding the shelf.
- TEST_P(HotseatWidgetTest, ShelfVisibilityChangeChangesWorkArea) {
- UpdateDisplay("800x603");
- TabletModeControllerTestApi().EnterTabletMode();
- auto window = AshTestBase::CreateTestWindow(gfx::Rect(400, 400));
- // The expected work area is 3 pixels smaller to leave space to swipe the auto
- // hide shelf up.
- const gfx::Rect expected_auto_hide_work_area(800, 600);
- const gfx::Rect expected_in_app_work_area(
- 800, 603 - ShelfConfig::Get()->in_app_shelf_size());
- auto get_work_area = []() -> gfx::Rect {
- return WorkAreaInsets::ForWindow(Shell::GetPrimaryRootWindow())
- ->user_work_area_bounds();
- };
- DisplayWorkAreaChangeCounter counter;
- WMEvent toggle_fullscreen(WM_EVENT_TOGGLE_FULLSCREEN);
- WindowState::Get(window.get())->OnWMEvent(&toggle_fullscreen);
- EXPECT_EQ(expected_auto_hide_work_area, get_work_area());
- EXPECT_EQ(1, counter.count());
- WindowState::Get(window.get())->OnWMEvent(&toggle_fullscreen);
- EXPECT_EQ(expected_in_app_work_area, get_work_area());
- EXPECT_EQ(2, counter.count());
- GetPrimaryShelf()->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
- EXPECT_EQ(expected_auto_hide_work_area, get_work_area());
- EXPECT_EQ(3, counter.count());
- GetPrimaryShelf()->SetAutoHideBehavior(ShelfAutoHideBehavior::kNever);
- EXPECT_EQ(expected_in_app_work_area, get_work_area());
- EXPECT_EQ(4, counter.count());
- }
- // Tests that the hotseat is flush with the bottom of the screen when in
- // clamshell mode and the shelf is oriented on the bottom.
- TEST_P(HotseatWidgetTest, HotseatFlushWithScreenBottomInClamshell) {
- GetPrimaryShelf()->SetAutoHideBehavior(shelf_auto_hide_behavior());
- const int display_height =
- display::Screen::GetScreen()->GetPrimaryDisplay().bounds().height();
- const int hotseat_bottom = GetPrimaryShelf()
- ->shelf_widget()
- ->hotseat_widget()
- ->GetWindowBoundsInScreen()
- .bottom();
- EXPECT_EQ(hotseat_bottom, display_height);
- }
- // Tests that upward drag gesture from the shelf in tablet mode affects the
- // active window presentation.
- TEST_P(HotseatWidgetTest, DragActiveWindowInTabletMode) {
- GetPrimaryShelf()->SetAutoHideBehavior(shelf_auto_hide_behavior());
- TabletModeControllerTestApi().EnterTabletMode();
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- // Swipe up to bring up the hotseat first.
- SwipeUpOnShelf();
- ASSERT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
- // Now swipe up again to start drag the active window.
- ui::test::EventGenerator* generator = GetEventGenerator();
- const gfx::Rect bottom_shelf_bounds =
- GetShelfWidget()->GetWindowBoundsInScreen();
- generator->MoveMouseTo(bottom_shelf_bounds.CenterPoint());
- generator->PressTouch();
- EXPECT_TRUE(window->layer()->transform().IsIdentity());
- // Drag upward, test the window transform changes.
- const gfx::Rect display_bounds =
- display::Screen::GetScreen()->GetPrimaryDisplay().bounds();
- generator->MoveTouch(display_bounds.CenterPoint());
- const gfx::Transform upward_transform = window->layer()->transform();
- EXPECT_FALSE(upward_transform.IsIdentity());
- // Drag downwad, test the window tranfrom changes.
- generator->MoveTouch(display_bounds.bottom_center());
- const gfx::Transform downward_transform = window->layer()->transform();
- EXPECT_NE(upward_transform, downward_transform);
- generator->ReleaseTouch();
- EXPECT_TRUE(window->layer()->transform().IsIdentity());
- }
- // Tests that when hotseat and drag-window-to-overview features are both
- // enabled, hotseat is not extended after dragging a window to overview, and
- // then activating the window.
- TEST_P(HotseatWidgetTest, ExitingOverviewHidesHotseat) {
- const ShelfAutoHideBehavior auto_hide_behavior = shelf_auto_hide_behavior();
- GetPrimaryShelf()->SetAutoHideBehavior(auto_hide_behavior);
- TabletModeControllerTestApi().EnterTabletMode();
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- // If the shelf is auto-hidden, swipe up to bring up shelf and hotseat first
- // (otherwise, the window drag to overview will not be handled).
- if (auto_hide_behavior == ShelfAutoHideBehavior::kAlways) {
- SwipeUpOnShelf();
- ASSERT_EQ(HotseatState::kExtended,
- GetShelfLayoutManager()->hotseat_state());
- }
- // Swipe up to start dragging the active window.
- const gfx::Rect bottom_shelf_bounds =
- GetShelfWidget()->GetWindowBoundsInScreen();
- StartScroll(bottom_shelf_bounds.CenterPoint());
- // Ensure swipe goes past the top of the hotseat first to activate the window
- // drag controller.
- UpdateScroll(
- -GetPrimaryShelf()->hotseat_widget()->GetHotseatFullDragAmount());
- // Drag upward, to the center of the screen, and release (this should enter
- // the overview).
- const gfx::Rect display_bounds =
- display::Screen::GetScreen()->GetPrimaryDisplay().bounds();
- UpdateScroll(display_bounds.CenterPoint().y() -
- bottom_shelf_bounds.CenterPoint().y());
- // Small scroll update, to simulate the user holding the pointer.
- UpdateScroll(2);
- DragWindowFromShelfController* window_drag_controller =
- GetShelfLayoutManager()->window_drag_controller_for_testing();
- ASSERT_TRUE(window_drag_controller);
- DragWindowFromShelfControllerTestApi test_api;
- test_api.WaitUntilOverviewIsShown(window_drag_controller);
- EndScroll(/*is_fling=*/false, 0.f);
- OverviewController* overview_controller = Shell::Get()->overview_controller();
- EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
- EXPECT_TRUE(overview_controller->InOverviewSession());
- // Activate the window - the overview session should exit, and hotseat should
- // be hidden.
- wm::ActivateWindow(window.get());
- EXPECT_FALSE(overview_controller->InOverviewSession());
- EXPECT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
- }
- // Tests that failing to drag the maximized window to overview mode results in
- // an extended hotseat.
- TEST_P(HotseatWidgetTest, FailingOverviewDragResultsInExtendedHotseat) {
- const ShelfAutoHideBehavior auto_hide_behavior = shelf_auto_hide_behavior();
- GetPrimaryShelf()->SetAutoHideBehavior(auto_hide_behavior);
- TabletModeControllerTestApi().EnterTabletMode();
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- // If the shelf is auto-hidden, swipe up to bring up shelf and hotseat first
- // (otherwise, the window drag to overview will not be handled).
- if (auto_hide_behavior == ShelfAutoHideBehavior::kAlways) {
- SwipeUpOnShelf();
- ASSERT_EQ(HotseatState::kExtended,
- GetShelfLayoutManager()->hotseat_state());
- }
- // Swipe up to start dragging the active window.
- const gfx::Rect bottom_shelf_bounds =
- GetShelfWidget()->GetWindowBoundsInScreen();
- StartScroll(bottom_shelf_bounds.top_center());
- const int extended_hotseat_distance_from_top_of_shelf =
- ShelfConfig::Get()->hotseat_bottom_padding() +
- GetPrimaryShelf()->hotseat_widget()->GetHotseatSize();
- // Overview is triggered when the bottom of the dragged window goes past the
- // top of the hotseat. The window scaling and translation are handled slightly
- // differently for if the hotseat is extended or not.
- if (HotseatState::kExtended == GetShelfLayoutManager()->hotseat_state()) {
- // Drag upward, a bit below the hotseat extended height, to ensure that the
- // bottom of the dragged window doesn't go past the top of the hotseat, so
- // that it doesn't go into overview.
- UpdateScroll(-extended_hotseat_distance_from_top_of_shelf + 20);
- } else {
- // Drag upward, a bit past the hotseat extended height so that the window
- // drag controller is activated, but not enough to go to overview.
- UpdateScroll(-extended_hotseat_distance_from_top_of_shelf - 30);
- }
- EndScroll(/*is_fling=*/false, 0.f);
- ASSERT_FALSE(Shell::Get()->overview_controller()->InOverviewSession());
- EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
- }
- // Tests that hotseat remains in extended state while in overview mode when
- // flinging the shelf up or down.
- TEST_P(HotseatWidgetTest, SwipeOnHotseatInOverview) {
- GetPrimaryShelf()->SetAutoHideBehavior(shelf_auto_hide_behavior());
- TabletModeControllerTestApi().EnterTabletMode();
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- OverviewController* overview_controller = Shell::Get()->overview_controller();
- EnterOverview();
- Shelf* const shelf = GetPrimaryShelf();
- SwipeUpOnShelf();
- EXPECT_TRUE(overview_controller->InOverviewSession());
- EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
- if (shelf_auto_hide_behavior() == ShelfAutoHideBehavior::kAlways) {
- EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
- EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
- } else {
- EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
- }
- // Drag from the hotseat to the bezel, the hotseat should remain in extended
- // state.
- DragHotseatDownToBezel();
- EXPECT_TRUE(overview_controller->InOverviewSession());
- EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
- if (shelf_auto_hide_behavior() == ShelfAutoHideBehavior::kAlways) {
- EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
- EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
- } else {
- EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
- }
- SwipeUpOnShelf();
- EXPECT_TRUE(overview_controller->InOverviewSession());
- EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
- if (shelf_auto_hide_behavior() == ShelfAutoHideBehavior::kAlways) {
- EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
- EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
- } else {
- EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
- }
- }
- TEST_P(HotseatWidgetTest, SwipeOnHotseatInSplitViewWithOverview) {
- Shelf* const shelf = GetPrimaryShelf();
- shelf->SetAutoHideBehavior(shelf_auto_hide_behavior());
- TabletModeControllerTestApi().EnterTabletMode();
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- OverviewController* overview_controller = Shell::Get()->overview_controller();
- EnterOverview();
- SplitViewController* split_view_controller =
- SplitViewController::Get(Shell::GetPrimaryRootWindow());
- split_view_controller->SnapWindow(window.get(), SplitViewController::LEFT);
- SwipeUpOnShelf();
- EXPECT_TRUE(split_view_controller->InSplitViewMode());
- EXPECT_TRUE(overview_controller->InOverviewSession());
- EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
- if (shelf_auto_hide_behavior() == ShelfAutoHideBehavior::kAlways) {
- EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
- EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
- } else {
- EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
- }
- DragHotseatDownToBezel();
- EXPECT_TRUE(split_view_controller->InSplitViewMode());
- EXPECT_TRUE(overview_controller->InOverviewSession());
- EXPECT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
- if (shelf_auto_hide_behavior() == ShelfAutoHideBehavior::kAlways) {
- EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
- EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
- } else {
- EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
- }
- SwipeUpOnShelf();
- EXPECT_TRUE(split_view_controller->InSplitViewMode());
- EXPECT_TRUE(overview_controller->InOverviewSession());
- EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
- if (shelf_auto_hide_behavior() == ShelfAutoHideBehavior::kAlways) {
- EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
- EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
- } else {
- EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
- }
- }
- TEST_P(HotseatWidgetTest, SwipeOnHotseatInSplitView) {
- Shelf* const shelf = GetPrimaryShelf();
- shelf->SetAutoHideBehavior(shelf_auto_hide_behavior());
- TabletModeControllerTestApi().EnterTabletMode();
- std::unique_ptr<aura::Window> window1 =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- std::unique_ptr<aura::Window> window2 =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window1.get());
- SplitViewController* split_view_controller =
- SplitViewController::Get(Shell::GetPrimaryRootWindow());
- split_view_controller->SnapWindow(window1.get(), SplitViewController::LEFT);
- split_view_controller->SnapWindow(window2.get(), SplitViewController::RIGHT);
- EXPECT_TRUE(split_view_controller->InSplitViewMode());
- SwipeUpOnShelf();
- EXPECT_TRUE(split_view_controller->InSplitViewMode());
- EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
- if (shelf_auto_hide_behavior() == ShelfAutoHideBehavior::kAlways) {
- EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
- EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
- } else {
- EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
- }
- DragHotseatDownToBezel();
- EXPECT_TRUE(split_view_controller->InSplitViewMode());
- EXPECT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
- if (shelf_auto_hide_behavior() == ShelfAutoHideBehavior::kAlways) {
- EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
- EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
- } else {
- EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
- }
- SwipeUpOnShelf();
- EXPECT_TRUE(split_view_controller->InSplitViewMode());
- EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
- if (shelf_auto_hide_behavior() == ShelfAutoHideBehavior::kAlways) {
- EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
- EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
- } else {
- EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
- }
- }
- // Tests that swiping downward, towards the bezel, from a variety of points
- // results in hiding the hotseat.
- TEST_P(HotseatWidgetTest, HotseatHidesWhenSwipedToBezel) {
- // Go to in-app shelf and extend the hotseat.
- TabletModeControllerTestApi().EnterTabletMode();
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- SwipeUpOnShelf();
- // Drag from the hotseat to the bezel, the hotseat should hide.
- DragHotseatDownToBezel();
- EXPECT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
- // Reset the hotseat and swipe from the center of the hotseat, it should hide.
- SwipeUpOnShelf();
- gfx::Rect shelf_widget_bounds = GetShelfWidget()->GetWindowBoundsInScreen();
- gfx::Rect hotseat_bounds =
- GetPrimaryShelf()->hotseat_widget()->GetWindowBoundsInScreen();
- gfx::Point start = hotseat_bounds.CenterPoint();
- const gfx::Point end =
- gfx::Point(shelf_widget_bounds.x() + shelf_widget_bounds.width() / 2,
- shelf_widget_bounds.bottom() + 1);
- const base::TimeDelta kTimeDelta = base::Milliseconds(100);
- const int kNumScrollSteps = 4;
- GetEventGenerator()->GestureScrollSequence(start, end, kTimeDelta,
- kNumScrollSteps);
- EXPECT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
- // Reset the hotseat and swipe from the bottom of the hotseat, it should hide.
- SwipeUpOnShelf();
- start = hotseat_bounds.bottom_center();
- start.Offset(0, -1);
- GetEventGenerator()->GestureScrollSequence(start, end, kTimeDelta,
- kNumScrollSteps);
- EXPECT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
- // Reset the hotseat and swipe from the center of the in-app shelf, it should
- // hide.
- SwipeUpOnShelf();
- start = shelf_widget_bounds.CenterPoint();
- GetEventGenerator()->GestureScrollSequence(start, end, kTimeDelta,
- kNumScrollSteps);
- EXPECT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
- // Reset the hotseat and swipe from the bottom of the in-app shelf, it should
- // hide.
- SwipeUpOnShelf();
- EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
- start = shelf_widget_bounds.bottom_center();
- // The first few events which get sent to ShelfLayoutManager are
- // ui::ET_TAP_DOWN, and ui::ET_GESTURE_START. After a few px we get
- // ui::ET_GESTURE_SCROLL_UPDATE. Add 6 px of slop to get the first events out
- // of the way, and 1 extra px to ensure we are not on the bottom edge of the
- // display.
- start.Offset(0, -7);
- GetEventGenerator()->GestureScrollSequence(start, end, kTimeDelta,
- kNumScrollSteps);
- EXPECT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
- }
- // Tests that flinging up the in-app shelf should show the hotseat.
- TEST_P(HotseatWidgetTest, FlingUpHotseatWithShortFling) {
- TabletModeControllerTestApi().EnterTabletMode();
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- GetAppListTestHelper()->CheckVisibility(false);
- base::HistogramTester histogram_tester;
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeUpToShow, 0);
- // Scrolls the hotseat by a distance not sufficuent to trigger the action of
- // entering home screen from the in-app shelf.
- gfx::Rect display_bounds =
- display::Screen::GetScreen()->GetPrimaryDisplay().bounds();
- const gfx::Point start(display_bounds.bottom_center());
- const gfx::Point end(start + gfx::Vector2d(0, -20));
- const int fling_speed =
- DragWindowFromShelfController::kVelocityToHomeScreenThreshold + 1;
- const int scroll_steps = 20;
- base::TimeDelta scroll_time =
- GetEventGenerator()->CalculateScrollDurationForFlingVelocity(
- start, end, fling_speed, scroll_steps);
- GetEventGenerator()->GestureScrollSequence(start, end, scroll_time,
- scroll_steps);
- base::RunLoop().RunUntilIdle();
- EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
- GetAppListTestHelper()->CheckVisibility(false);
- histogram_tester.ExpectBucketCount(kHotseatGestureHistogramName,
- InAppShelfGestures::kSwipeUpToShow, 1);
- }
- // Tests that flinging up the in-app shelf should show the home launcher if the
- // gesture distance is long enough.
- TEST_P(HotseatWidgetTest, FlingUpHotseatWithLongFling) {
- TabletModeControllerTestApi().EnterTabletMode();
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- GetAppListTestHelper()->CheckVisibility(false);
- base::HistogramTester histogram_tester;
- histogram_tester.ExpectBucketCount(
- kHotseatGestureHistogramName,
- InAppShelfGestures::kFlingUpToShowHomeScreen, 0);
- // Scrolls the hotseat by the sufficient distance to trigger the action of
- // entering home screen from the in-app shelf.
- gfx::Rect display_bounds =
- display::Screen::GetScreen()->GetPrimaryDisplay().bounds();
- const gfx::Point start(display_bounds.bottom_center());
- const gfx::Point end(start + gfx::Vector2d(0, -200));
- const int fling_speed =
- DragWindowFromShelfController::kVelocityToHomeScreenThreshold + 1;
- const int scroll_steps = 20;
- base::TimeDelta scroll_time =
- GetEventGenerator()->CalculateScrollDurationForFlingVelocity(
- start, end, fling_speed, scroll_steps);
- GetEventGenerator()->GestureScrollSequence(start, end, scroll_time,
- scroll_steps);
- base::RunLoop().RunUntilIdle();
- EXPECT_EQ(HotseatState::kShownHomeLauncher,
- GetShelfLayoutManager()->hotseat_state());
- GetAppListTestHelper()->CheckVisibility(true);
- histogram_tester.ExpectBucketCount(
- kHotseatGestureHistogramName,
- InAppShelfGestures::kFlingUpToShowHomeScreen, 1);
- }
- // Tests that UpdateVisibilityState is ignored during a shelf drag. This
- // prevents drag from getting interrupted.
- TEST_P(HotseatWidgetTest, NoVisibilityStateUpdateDuringDrag) {
- // Autohide the shelf, then start a shelf drag.
- GetPrimaryShelf()->SetAutoHideBehavior(ShelfAutoHideBehavior::kAlways);
- std::unique_ptr<aura::Window> window1 =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window1.get());
- ASSERT_EQ(SHELF_AUTO_HIDE_HIDDEN, GetPrimaryShelf()->GetAutoHideState());
- // Drag the autohidden shelf up a bit, then open a new window and activate it
- // during the drag. The shelf state should not change.
- gfx::Point start_drag = GetVisibleShelfWidgetBoundsInScreen().top_center();
- GetEventGenerator()->set_current_screen_location(start_drag);
- GetEventGenerator()->PressTouch();
- GetEventGenerator()->MoveTouchBy(0, -2);
- auto shelf_state_watcher = std::make_unique<ShelfStateWatcher>();
- std::unique_ptr<aura::Window> window2 =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window2.get());
- window2->SetBounds(gfx::Rect(0, 0, 200, 200));
- EXPECT_EQ(0, shelf_state_watcher->state_change_count());
- }
- // Tests that when tablet mode has ended, the hotseat background is no longer
- // visible. See crbug/1050383
- TEST_P(HotseatWidgetTest, HotseatBackgroundDisappearsAfterTabletModeEnd) {
- HotseatWidget* hotseat = GetPrimaryShelf()->hotseat_widget();
- EXPECT_FALSE(hotseat->GetIsTranslucentBackgroundVisibleForTest());
- TabletModeControllerTestApi().EnterTabletMode();
- EXPECT_TRUE(hotseat->GetIsTranslucentBackgroundVisibleForTest());
- TabletModeControllerTestApi().LeaveTabletMode();
- EXPECT_FALSE(hotseat->GetIsTranslucentBackgroundVisibleForTest());
- }
- // Tests that popups don't activate the hotseat. (crbug.com/1018266)
- TEST_P(HotseatWidgetTest, HotseatRemainsHiddenIfPopupLaunched) {
- // Go to in-app shelf and extend the hotseat.
- TabletModeControllerTestApi().EnterTabletMode();
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- SwipeUpOnShelf();
- EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
- // Hide hotseat by clicking outside its bounds.
- gfx::Rect hotseat_bounds =
- GetPrimaryShelf()->hotseat_widget()->GetWindowBoundsInScreen();
- gfx::Point start = hotseat_bounds.top_center();
- GetEventGenerator()->GestureTapAt(gfx::Point(start.x() + 1, start.y() - 1));
- EXPECT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
- // Create a popup window and wait until all actions finish. The hotseat should
- // remain hidden.
- aura::Window* window_2 = CreateTestWindowInParent(window.get());
- window_2->SetBounds(gfx::Rect(201, 0, 100, 100));
- window_2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
- window_2->Show();
- GetAppListTestHelper()->WaitUntilIdle();
- EXPECT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
- }
- // Tests that blur is not showing during animations.
- TEST_P(HotseatWidgetTest, NoBlurDuringAnimations) {
- TabletModeControllerTestApi().EnterTabletMode();
- ASSERT_EQ(
- ShelfConfig::Get()->shelf_blur_radius(),
- GetShelfWidget()->hotseat_widget()->GetHotseatBackgroundBlurForTest());
- ui::ScopedAnimationDurationScaleMode regular_animations(
- ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
- // Open a window, as the hotseat animates to kHidden, it should lose its blur.
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- EXPECT_EQ(
- 0, GetShelfWidget()->hotseat_widget()->GetHotseatBackgroundBlurForTest());
- // Wait for the animation to finish, hotseat blur should return.
- ShellTestApi().WaitForWindowFinishAnimating(window.get());
- EXPECT_EQ(
- ShelfConfig::Get()->shelf_blur_radius(),
- GetShelfWidget()->hotseat_widget()->GetHotseatBackgroundBlurForTest());
- }
- // Tests that hotseat bounds don't jump when transitioning from drag to
- // animation.
- TEST_P(HotseatWidgetTest, AnimationAfterDrag) {
- TabletModeControllerTestApi().EnterTabletMode();
- // Add an app to shelf - the app will be used to track the shelf view position
- // throughout the test.
- ShelfTestUtil::AddAppShortcut("fake_app", TYPE_PINNED_APP);
- // Open a window so the hotseat transitions to hidden state.
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- ui::ScopedAnimationDurationScaleMode animation_duration(
- ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
- HotseatWidget* const hotseat_widget = GetPrimaryShelf()->hotseat_widget();
- gfx::Point last_app_views_position =
- hotseat_widget->GetWindowBoundsInScreen().origin();
- // Returns whether the hotseat vertical position has changed comapred to
- // |last_hotseat_y|, and updates |last_hotseat_y| to match the current hotseat
- // position.
- auto app_views_moved = [&last_app_views_position, &hotseat_widget]() -> bool {
- gfx::Point app_views_position =
- ShelfViewTestAPI(hotseat_widget->scrollable_shelf_view()->shelf_view())
- .GetViewAt(0)
- ->GetBoundsInScreen()
- .origin();
- hotseat_widget->GetLayer()->transform().TransformPoint(&app_views_position);
- const bool position_changed = app_views_position != last_app_views_position;
- last_app_views_position = app_views_position;
- return position_changed;
- };
- ui::test::EventGenerator* generator = GetEventGenerator();
- const gfx::Rect display_bounds =
- display::Screen::GetScreen()->GetPrimaryDisplay().bounds();
- // Drag upwards from the bottom of the screen to bring up hotseat - this
- // should request presentation time metric to be reported.
- generator->PressTouch(display_bounds.bottom_center());
- // Drag the hotseat upward, by the height of the shelf.
- const int shelf_height = GetShelfWidget()->GetWindowBoundsInScreen().height();
- generator->MoveTouchBy(0, -shelf_height);
- ASSERT_TRUE(app_views_moved());
- // Release touch, and verify the hotseat position remained the same.
- generator->ReleaseTouch();
- EXPECT_FALSE(app_views_moved());
- // Wait for the hotseat to animate to extended state.
- ShellTestApi().WaitForWindowFinishAnimating(
- hotseat_widget->GetNativeWindow());
- ASSERT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
- EXPECT_TRUE(app_views_moved());
- // Drag hotseat down.
- generator->PressTouch(hotseat_widget->GetWindowBoundsInScreen().top_center());
- generator->MoveTouchBy(0, shelf_height);
- ASSERT_TRUE(app_views_moved());
- // Release touch, and verify the hotseat position remained the same.
- generator->ReleaseTouch();
- EXPECT_FALSE(app_views_moved());
- // Wait for the hotseat to animate to extended state.
- ShellTestApi().WaitForWindowFinishAnimating(
- hotseat_widget->GetNativeWindow());
- ASSERT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
- ASSERT_TRUE(app_views_moved());
- // Drag the hotseat back up, and release so animation to extended state
- // starts.
- generator->PressTouch(display_bounds.bottom_center());
- generator->MoveTouchBy(0, -shelf_height);
- ASSERT_TRUE(app_views_moved());
- generator->ReleaseTouch();
- EXPECT_FALSE(app_views_moved());
- // Close the test widget to start transition to the shown state.
- window.reset();
- // The apparent hotseat bound should remain the same as the transition to show
- // state starts.
- ASSERT_EQ(HotseatState::kShownHomeLauncher,
- GetShelfLayoutManager()->hotseat_state());
- EXPECT_FALSE(app_views_moved());
- // Finish the animation to shown state.
- ShellTestApi().WaitForWindowFinishAnimating(
- hotseat_widget->GetNativeWindow());
- ASSERT_EQ(HotseatState::kShownHomeLauncher,
- GetShelfLayoutManager()->hotseat_state());
- EXPECT_TRUE(app_views_moved());
- }
- // Tests that hotseat bounds don't jump when the hotseat widget is translated
- // when a transitionj animation starts.
- TEST_P(HotseatWidgetTest, InitialAnimationPositionWithNonIdentityTransform) {
- TabletModeControllerTestApi().EnterTabletMode();
- // Add an app to shelf - the app will be used to track the shelf view position
- // throughout the test.
- ShelfTestUtil::AddAppShortcut("fake_app", TYPE_PINNED_APP);
- // Open a window so the hotseat transitions to hidden state.
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- // Make sure that all shelf item views complete their bounds animations
- // before starting the test (tests depend on the first item bounds within the
- // shelf view).
- auto* shelf_view = GetPrimaryShelf()->GetShelfViewForTesting();
- ShelfViewTestAPI(shelf_view).RunMessageLoopUntilAnimationsDone();
- HotseatWidget* const hotseat_widget = GetPrimaryShelf()->hotseat_widget();
- gfx::Point last_app_views_position =
- hotseat_widget->GetWindowBoundsInScreen().origin();
- // Returns whether the hotseat vertical position has changed comapred to
- // |last_hotseat_y|, and updates |last_hotseat_y| to match the current hotseat
- // position.
- auto app_views_moved = [&last_app_views_position, &hotseat_widget]() -> bool {
- gfx::Point app_views_position =
- ShelfViewTestAPI(hotseat_widget->scrollable_shelf_view()->shelf_view())
- .GetViewAt(0)
- ->GetBoundsInScreen()
- .origin();
- hotseat_widget->GetLayer()->transform().TransformPoint(&app_views_position);
- const bool position_changed = app_views_position != last_app_views_position;
- last_app_views_position = app_views_position;
- return position_changed;
- };
- ui::test::EventGenerator* generator = GetEventGenerator();
- const gfx::Rect display_bounds =
- display::Screen::GetScreen()->GetPrimaryDisplay().bounds();
- // Drag upwards from the bottom of the screen to bring up hotseat - this
- // should request presentation time metric to be reported.
- generator->PressTouch(display_bounds.bottom_center());
- // Drag the hotseat upward, to transition hotseat to the extended state.
- const int shelf_height = GetShelfWidget()->GetWindowBoundsInScreen().height();
- generator->MoveTouchBy(0, -shelf_height);
- // Release touch, and verify the hotseat position remained the same.
- generator->ReleaseTouch();
- ASSERT_TRUE(app_views_moved());
- ui::ScopedAnimationDurationScaleMode animation_duration(
- ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
- auto set_animated_transform = [](ui::Layer* layer,
- const gfx::Vector2d& initial_offset) {
- // Set translate animation on the hotseat widget, to simulate a state which
- // the widget may have while a transform animation is in progress.
- gfx::Transform initial_transform;
- initial_transform.Translate(initial_offset.x(), initial_offset.y());
- layer->SetTransform(initial_transform);
- // Set up an animation to identity transform.
- ui::ScopedLayerAnimationSettings animation(layer->GetAnimator());
- animation.SetTransitionDuration(base::Milliseconds(300));
- layer->SetTransform(gfx::Transform());
- };
- set_animated_transform(hotseat_widget->GetLayer(), gfx::Vector2d(0, -10));
- ASSERT_TRUE(app_views_moved());
- // Tap in the middle of the screen to initiate transition to hidden state.
- generator->GestureTapAt(display_bounds.CenterPoint());
- ASSERT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
- // Verify the current hotseat position remains unchanged.
- EXPECT_FALSE(app_views_moved());
- // Wait for the hotseat animation to hidden state to finish.
- ShellTestApi().WaitForWindowFinishAnimating(
- hotseat_widget->GetNativeWindow());
- ASSERT_EQ(HotseatState::kHidden, GetShelfLayoutManager()->hotseat_state());
- EXPECT_TRUE(app_views_moved());
- // Set the hotseat widget transform again.
- set_animated_transform(hotseat_widget->GetLayer(), gfx::Vector2d(0, -10));
- ASSERT_TRUE(app_views_moved());
- // CLose the window to transition to the shown state.
- window.reset();
- ASSERT_EQ(HotseatState::kShownHomeLauncher,
- GetShelfLayoutManager()->hotseat_state());
- // The apparent hotseat bound should remain the same as the transition to show
- // state starts.
- EXPECT_FALSE(app_views_moved());
- // Finish the animation to shown state.
- ShellTestApi().WaitForWindowFinishAnimating(
- hotseat_widget->GetNativeWindow());
- EXPECT_TRUE(app_views_moved());
- // Open another widow, and move the hotseat to extended state.
- window = AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- generator->PressTouch(display_bounds.bottom_center());
- generator->MoveTouchBy(0, -shelf_height);
- generator->ReleaseTouch();
- ShellTestApi().WaitForWindowFinishAnimating(
- hotseat_widget->GetNativeWindow());
- ASSERT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
- set_animated_transform(hotseat_widget->GetLayer(), gfx::Vector2d(0, -10));
- ASSERT_TRUE(app_views_moved());
- // Close the window to transition to shown hotseat state.
- window.reset();
- ASSERT_EQ(HotseatState::kShownHomeLauncher,
- GetShelfLayoutManager()->hotseat_state());
- // The apparent hotseat bound should remain the same as the transition to show
- // state starts.
- EXPECT_FALSE(app_views_moved());
- // Finish the animation to shown state.
- ShellTestApi().WaitForWindowFinishAnimating(
- hotseat_widget->GetNativeWindow());
- EXPECT_TRUE(app_views_moved());
- }
- TEST_P(HotseatWidgetTest, PresentationTimeMetricDuringDrag) {
- ui::PresentationTimeRecorder::SetReportPresentationTimeImmediatelyForTest(
- true);
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- GetPrimaryShelf()->SetAutoHideBehavior(shelf_auto_hide_behavior());
- TabletModeControllerTestApi().EnterTabletMode();
- ui::test::EventGenerator* generator = GetEventGenerator();
- const gfx::Rect display_bounds =
- display::Screen::GetScreen()->GetPrimaryDisplay().bounds();
- // Drag upwards from the bottom of the screen to bring up hotseat - this
- // should request presentation time metric to be reported.
- generator->PressTouch(display_bounds.bottom_center());
- HotseatWidget* const hotseat_widget = GetPrimaryShelf()->hotseat_widget();
- int last_hotseat_y = hotseat_widget->GetWindowBoundsInScreen().y();
- // Returns whether the hotseat vertical position has changed comapred to
- // |last_hotseat_y|, and updates |last_hotseat_y| to match the current hotseat
- // position.
- auto hotseat_moved = [&last_hotseat_y, &hotseat_widget]() -> bool {
- const int hotseat_y = hotseat_widget->GetWindowBoundsInScreen().y();
- const bool y_changed = hotseat_y != last_hotseat_y;
- last_hotseat_y = hotseat_y;
- return y_changed;
- };
- base::HistogramTester histogram_tester;
- auto check_bucket_size = [&histogram_tester](int expected_size) {
- histogram_tester.ExpectTotalCount(
- "Ash.HotseatTransition.Drag.PresentationTime", expected_size);
- histogram_tester.ExpectTotalCount(
- "Ash.HotseatTransition.Drag.PresentationTime.MaxLatency", 0);
- };
- int expected_bucket_size = 0;
- {
- SCOPED_TRACE("Initial state");
- check_bucket_size(expected_bucket_size);
- }
- const int shelf_height = GetShelfWidget()->GetWindowBoundsInScreen().height();
- {
- SCOPED_TRACE("Upward drag with move - 1");
- generator->MoveTouchBy(0, -shelf_height / 2);
- ASSERT_TRUE(hotseat_moved());
- check_bucket_size(++expected_bucket_size);
- }
- {
- SCOPED_TRACE("Upward drag with move - 2");
- generator->MoveTouchBy(0, -shelf_height / 2);
- ASSERT_TRUE(hotseat_moved());
- check_bucket_size(++expected_bucket_size);
- }
- {
- SCOPED_TRACE("Downward drag with move");
- generator->MoveTouchBy(0, shelf_height / 2);
- ASSERT_TRUE(hotseat_moved());
- check_bucket_size(++expected_bucket_size);
- }
- {
- SCOPED_TRACE("Upward drag with move - 3");
- generator->MoveTouchBy(0, -shelf_height / 2);
- ASSERT_TRUE(hotseat_moved());
- check_bucket_size(++expected_bucket_size);
- }
- const int hotseat_height =
- GetPrimaryShelf()->hotseat_widget()->GetWindowBoundsInScreen().height();
- {
- SCOPED_TRACE("Upward drag with move above shelf - 1");
- generator->MoveTouchBy(0, -hotseat_height / 2);
- ASSERT_TRUE(hotseat_moved());
- check_bucket_size(++expected_bucket_size);
- }
- {
- SCOPED_TRACE("Upward drag with move above shelf - 2");
- generator->MoveTouchBy(0, -hotseat_height / 2);
- ASSERT_TRUE(hotseat_moved());
- check_bucket_size(++expected_bucket_size);
- }
- {
- SCOPED_TRACE("Downward drag with move above shelf");
- generator->MoveTouchBy(0, hotseat_height / 2);
- ASSERT_TRUE(hotseat_moved());
- check_bucket_size(++expected_bucket_size);
- }
- {
- SCOPED_TRACE("Upward drag with move above shelf - 3");
- generator->MoveTouchBy(0, -hotseat_height - hotseat_height / 2);
- ASSERT_TRUE(hotseat_moved());
- check_bucket_size(++expected_bucket_size);
- }
- // Once the hotseat has been fully extended, presentation time metric should
- // stop being reported, as the hotseat is expected to stop moving.
- {
- SCOPED_TRACE("Upward drag without moving - 1");
- generator->MoveTouchBy(0, -hotseat_height);
- ASSERT_FALSE(hotseat_moved());
- check_bucket_size(expected_bucket_size);
- }
- {
- SCOPED_TRACE("Upward drag without moving - 2");
- generator->MoveTouchBy(0, -hotseat_height / 2);
- ASSERT_FALSE(hotseat_moved());
- check_bucket_size(expected_bucket_size);
- }
- // Move hotseat downwards - the presentation time should not get reported
- // until the hotseat starts moving downwards.
- {
- SCOPED_TRACE("Downward drag without moving - 1");
- generator->MoveTouchBy(0, hotseat_height / 2);
- ASSERT_FALSE(hotseat_moved());
- check_bucket_size(expected_bucket_size);
- }
- {
- SCOPED_TRACE("Downward drag without moving - 2");
- generator->MoveTouchBy(0, hotseat_height);
- ASSERT_FALSE(hotseat_moved());
- check_bucket_size(expected_bucket_size);
- }
- generator->ReleaseTouch();
- window.reset();
- {
- SCOPED_TRACE("Drag ended.");
- histogram_tester.ExpectTotalCount(
- "Ash.HotseatTransition.Drag.PresentationTime", expected_bucket_size);
- histogram_tester.ExpectTotalCount(
- "Ash.HotseatTransition.Drag.PresentationTime.MaxLatency", 1);
- }
- }
- // TODO(manucornet): Enable this test once the new API for layer animation
- // sequence observers is available.
- TEST_P(HotseatWidgetTest, DISABLED_OverviewToHomeAnimationAndBackIsSmooth) {
- // Go into tablet mode and make sure animations are over.
- HotseatWidget* hotseat = GetPrimaryShelf()->hotseat_widget();
- views::WidgetAnimationWaiter waiter(hotseat);
- TabletModeControllerTestApi().EnterTabletMode();
- waiter.WaitForAnimation();
- ui::ScopedAnimationDurationScaleMode regular_animations(
- ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
- // Go into overview and back to know what to expect in terms of bounds.
- const gfx::Rect shown_hotseat_bounds = hotseat->GetWindowBoundsInScreen();
- {
- views::WidgetAnimationWaiter waiter(hotseat);
- StartOverview();
- waiter.WaitForAnimation();
- }
- const gfx::Rect extended_hotseat_bounds = hotseat->GetWindowBoundsInScreen();
- {
- views::WidgetAnimationWaiter waiter(hotseat);
- EndOverview();
- waiter.WaitForAnimation();
- }
- // The extended hotseat should be higher (lower value of Y) than the
- // shown hotseat.
- EXPECT_GT(shown_hotseat_bounds.y(), extended_hotseat_bounds.y());
- // We should start with the hotseat in its shown position again.
- EXPECT_EQ(shown_hotseat_bounds, hotseat->GetWindowBoundsInScreen());
- {
- WidgetAnimationSmoothnessInspector inspector(hotseat);
- views::WidgetAnimationWaiter waiter(hotseat);
- StartOverview();
- waiter.WaitForAnimation();
- EXPECT_TRUE(inspector.CheckAnimation(4));
- }
- // The hotseat should now be extended.
- EXPECT_EQ(extended_hotseat_bounds, hotseat->GetWindowBoundsInScreen());
- {
- WidgetAnimationSmoothnessInspector inspector(hotseat);
- views::WidgetAnimationWaiter waiter(hotseat);
- EndOverview();
- waiter.WaitForAnimation();
- EXPECT_TRUE(inspector.CheckAnimation(4));
- }
- // And we should now be back where we started.
- EXPECT_EQ(shown_hotseat_bounds, hotseat->GetWindowBoundsInScreen());
- }
- class HotseatWidgetRTLTest : public ShelfLayoutManagerTestBase,
- public testing::WithParamInterface<bool> {
- public:
- // Use MOCK_TIME to increase number of commits during animation.
- HotseatWidgetRTLTest()
- : ShelfLayoutManagerTestBase(
- base::test::TaskEnvironment::TimeSource::MOCK_TIME),
- scoped_locale_(GetParam() ? "ar" : "") {}
- HotseatWidgetRTLTest(const HotseatWidgetRTLTest&) = delete;
- HotseatWidgetRTLTest& operator=(const HotseatWidgetRTLTest&) = delete;
- ~HotseatWidgetRTLTest() override = default;
- private:
- base::test::ScopedRestoreICUDefaultLocale scoped_locale_;
- };
- INSTANTIATE_TEST_SUITE_P(RTL, HotseatWidgetRTLTest, testing::Bool());
- // The test to verify the hotseat transition animation from the extended state
- // to the home launcher state.
- // TODO(https://crbug.com/1210530): Disable this test due to flakiness.
- TEST_P(HotseatWidgetRTLTest,
- DISABLED_VerifyTransitionFromExtendedModeToHomeLauncher) {
- TabletModeControllerTestApi().EnterTabletMode();
- const auto app_id =
- ShelfTestUtil::AddAppShortcut("fake_app", TYPE_PINNED_APP);
- // Open a window so the hotseat transitions to hidden state.
- std::unique_ptr<aura::Window> window =
- AshTestBase::CreateTestWindow(gfx::Rect(0, 0, 400, 400));
- wm::ActivateWindow(window.get());
- // Swipe the hotseat up to enter the extended mode.
- SwipeUpOnShelf();
- EXPECT_EQ(HotseatState::kExtended, GetShelfLayoutManager()->hotseat_state());
- // Animation should be long enough in order to collect sufficient data.
- // TODO(https://crbug.com/1208651): remove this line when we solve that issue.
- ui::ScopedAnimationDurationScaleMode animation_duration(
- ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
- // Wait until shelf animation completes.
- auto* shelf_view = GetPrimaryShelf()->GetShelfViewForTesting();
- ShelfViewTestAPI shelf_test_api(shelf_view);
- shelf_test_api.RunMessageLoopUntilAnimationsDone();
- // Observe a shelf icon.
- auto* observed_view = shelf_view->GetShelfAppButton(app_id.id);
- LayerAnimationVerifier verifier(
- GetPrimaryShelf()->hotseat_widget()->GetNativeView()->layer(),
- observed_view);
- // Transit the hotseat from the extended state to the home launcher state.
- // Wait until the transition animation finishes.
- views::WidgetAnimationWaiter waiter(GetPrimaryShelf()->hotseat_widget());
- FlingUpOnShelf();
- waiter.WaitForAnimation();
- // Verify the hotseat state at the end of the animation.
- EXPECT_EQ(HotseatState::kShownHomeLauncher,
- GetShelfLayoutManager()->hotseat_state());
- }
- } // namespace ash
|