1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786 |
- // Copyright 2013 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 "cc/input/scrollbar_animation_controller.h"
- #include <utility>
- #include "base/memory/raw_ptr.h"
- #include "base/time/time.h"
- #include "cc/layers/solid_color_scrollbar_layer_impl.h"
- #include "cc/test/layer_tree_impl_test_base.h"
- #include "cc/trees/layer_tree_impl.h"
- #include "testing/gmock/include/gmock/gmock.h"
- #include "testing/gtest/include/gtest/gtest.h"
- using testing::AtLeast;
- using testing::Mock;
- using testing::NiceMock;
- using testing::_;
- namespace cc {
- namespace {
- const float kIdleThicknessScale =
- SingleScrollbarAnimationControllerThinning::kIdleThicknessScale;
- const int kThumbThickness = 10;
- class MockScrollbarAnimationControllerClient
- : public ScrollbarAnimationControllerClient {
- public:
- MockScrollbarAnimationControllerClient(LayerTreeHostImpl* host_impl,
- bool is_fluent)
- : host_impl_(host_impl), is_fluent_(is_fluent) {}
- ~MockScrollbarAnimationControllerClient() override = default;
- void PostDelayedScrollbarAnimationTask(base::OnceClosure start_fade,
- base::TimeDelta delay) override {
- start_fade_ = std::move(start_fade);
- delay_ = delay;
- }
- void SetNeedsRedrawForScrollbarAnimation() override {}
- void SetNeedsAnimateForScrollbarAnimation() override {}
- ScrollbarSet ScrollbarsFor(ElementId scroll_element_id) const override {
- return host_impl_->ScrollbarsFor(scroll_element_id);
- }
- MOCK_METHOD0(DidChangeScrollbarVisibility, void());
- bool IsFluentScrollbar() const override { return is_fluent_; }
- base::OnceClosure& start_fade() { return start_fade_; }
- base::TimeDelta& delay() { return delay_; }
- private:
- base::OnceClosure start_fade_;
- base::TimeDelta delay_;
- raw_ptr<LayerTreeHostImpl> host_impl_;
- bool is_fluent_;
- };
- class ScrollbarAnimationControllerAuraOverlayTest
- : public LayerTreeImplTestBase,
- public testing::Test {
- public:
- explicit ScrollbarAnimationControllerAuraOverlayTest(bool is_fluent = false)
- : client_(host_impl(), is_fluent) {}
- void ExpectScrollbarsOpacity(float opacity) {
- EXPECT_FLOAT_EQ(opacity, v_scrollbar_layer_->Opacity());
- EXPECT_FLOAT_EQ(opacity, h_scrollbar_layer_->Opacity());
- }
- protected:
- const base::TimeDelta kFadeDelay = base::Seconds(4);
- const base::TimeDelta kFadeDuration = base::Seconds(3);
- const base::TimeDelta kThinningDuration = base::Seconds(2);
- void SetUp() override {
- const int kTrackStart = 0;
- const int kTrackLength = 100;
- const bool kIsLeftSideVerticalScrollbar = false;
- scroll_layer_ = AddLayer<LayerImpl>();
- h_scrollbar_layer_ = AddLayer<SolidColorScrollbarLayerImpl>(
- ScrollbarOrientation::HORIZONTAL, kThumbThickness, kTrackStart,
- kIsLeftSideVerticalScrollbar);
- v_scrollbar_layer_ = AddLayer<SolidColorScrollbarLayerImpl>(
- ScrollbarOrientation::VERTICAL, kThumbThickness, kTrackStart,
- kIsLeftSideVerticalScrollbar);
- SetElementIdsForTesting();
- clip_layer_ = root_layer();
- clip_layer_->SetBounds(gfx::Size(100, 100));
- scroll_layer_->SetBounds(gfx::Size(200, 200));
- CopyProperties(clip_layer_, scroll_layer_);
- CreateTransformNode(scroll_layer_);
- CreateScrollNode(scroll_layer_, gfx::Size(100, 100));
- v_scrollbar_layer_->SetBounds(gfx::Size(kThumbThickness, kTrackLength));
- v_scrollbar_layer_->SetScrollElementId(scroll_layer_->element_id());
- CopyProperties(scroll_layer_, v_scrollbar_layer_);
- v_scrollbar_layer_->SetOffsetToTransformParent(gfx::Vector2dF(90, 0));
- auto& v_scrollbar_effect = CreateEffectNode(v_scrollbar_layer_);
- v_scrollbar_effect.opacity = 0.f;
- v_scrollbar_effect.has_potential_opacity_animation = true;
- h_scrollbar_layer_->SetBounds(gfx::Size(kTrackLength, kThumbThickness));
- h_scrollbar_layer_->SetScrollElementId(scroll_layer_->element_id());
- CopyProperties(scroll_layer_, h_scrollbar_layer_);
- h_scrollbar_layer_->SetOffsetToTransformParent(gfx::Vector2dF(0, 90));
- auto& h_scrollbar_effect = CreateEffectNode(h_scrollbar_layer_);
- h_scrollbar_effect.opacity = 0.f;
- h_scrollbar_effect.has_potential_opacity_animation = true;
- UpdateActiveTreeDrawProperties();
- scrollbar_controller_ = ScrollbarAnimationController::
- CreateScrollbarAnimationControllerAuraOverlay(
- scroll_layer_->element_id(), &client_, kFadeDelay, kFadeDuration,
- kThinningDuration, 0.0f);
- v_scrollbar_layer_->SetCurrentPos(0);
- h_scrollbar_layer_->SetCurrentPos(0);
- mouse_move_distance_to_trigger_fade_in_ =
- scrollbar_controller_
- ->GetScrollbarAnimationController(ScrollbarOrientation::VERTICAL)
- .MouseMoveDistanceToTriggerFadeIn();
- mouse_move_distance_to_trigger_expand_ =
- scrollbar_controller_
- ->GetScrollbarAnimationController(ScrollbarOrientation::VERTICAL)
- .MouseMoveDistanceToTriggerExpand();
- }
- // Return a point with given offset from the top-left of vertical scrollbar.
- gfx::PointF NearVerticalScrollbarBegin(float offset_x, float offset_y) {
- gfx::PointF p(90, 0);
- p.Offset(offset_x, offset_y);
- return p;
- }
- // Return a point with given offset from the bottom-left of vertical
- // scrollbar.
- gfx::PointF NearVerticalScrollbarEnd(float offset_x, float offset_y) {
- gfx::PointF p(90, 90);
- p.Offset(offset_x, offset_y);
- return p;
- }
- // Return a point with given offset from the top-left of horizontal scrollbar.
- gfx::PointF NearHorizontalScrollbarBegin(float offset_x, float offset_y) {
- gfx::PointF p(0, 90);
- p.Offset(offset_x, offset_y);
- return p;
- }
- float mouse_move_distance_to_trigger_fade_in_;
- float mouse_move_distance_to_trigger_expand_;
- std::unique_ptr<ScrollbarAnimationController> scrollbar_controller_;
- raw_ptr<LayerImpl> clip_layer_;
- raw_ptr<LayerImpl> scroll_layer_;
- raw_ptr<SolidColorScrollbarLayerImpl> v_scrollbar_layer_;
- raw_ptr<SolidColorScrollbarLayerImpl> h_scrollbar_layer_;
- NiceMock<MockScrollbarAnimationControllerClient> client_;
- };
- class ScrollbarAnimationControllerFluentOverlayTest
- : public ScrollbarAnimationControllerAuraOverlayTest {
- public:
- ScrollbarAnimationControllerFluentOverlayTest()
- : ScrollbarAnimationControllerAuraOverlayTest(/* is_fluent */ true) {}
- void SetUp() override {
- ScrollbarAnimationControllerAuraOverlayTest::SetUp();
- // Mock initial call for did request show on page load.
- scrollbar_controller_->DidRequestShow();
- }
- };
- // Check initialization of scrollbar. Should start off invisible and thin.
- TEST_F(ScrollbarAnimationControllerAuraOverlayTest, Idle) {
- ExpectScrollbarsOpacity(0);
- EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- v_scrollbar_layer_->thumb_thickness_scale_factor());
- }
- // Check that scrollbar appears again when the layer becomes scrollable.
- TEST_F(ScrollbarAnimationControllerAuraOverlayTest, AppearOnResize) {
- base::TimeTicks time;
- time += base::Seconds(1);
- scrollbar_controller_->DidScrollUpdate();
- ExpectScrollbarsOpacity(1);
- // Make the Layer non-scrollable, scrollbar disappears.
- clip_layer_->SetBounds(gfx::Size(200, 200));
- GetScrollNode(scroll_layer_.get())->container_bounds = gfx::Size(200, 200);
- scroll_layer_->UpdateScrollable();
- UpdateActiveTreeDrawProperties();
- scrollbar_controller_->DidScrollUpdate();
- ExpectScrollbarsOpacity(0);
- // Make the layer scrollable, scrollbar appears again.
- clip_layer_->SetBounds(gfx::Size(100, 100));
- GetScrollNode(scroll_layer_.get())->container_bounds = gfx::Size(100, 100);
- scroll_layer_->UpdateScrollable();
- UpdateActiveTreeDrawProperties();
- scrollbar_controller_->DidScrollUpdate();
- ExpectScrollbarsOpacity(1);
- }
- // Check that scrollbar disappears when the layer becomes non-scrollable.
- TEST_F(ScrollbarAnimationControllerAuraOverlayTest, HideOnResize) {
- base::TimeTicks time;
- time += base::Seconds(1);
- EXPECT_EQ(gfx::Size(200, 200), scroll_layer_->bounds());
- // Shrink along X axis, horizontal scrollbar should appear.
- clip_layer_->SetBounds(gfx::Size(100, 200));
- EXPECT_EQ(gfx::Size(100, 200), clip_layer_->bounds());
- GetScrollNode(scroll_layer_.get())->container_bounds = gfx::Size(100, 200);
- scroll_layer_->UpdateScrollable();
- UpdateActiveTreeDrawProperties();
- scrollbar_controller_->DidScrollUpdate();
- EXPECT_FLOAT_EQ(1, h_scrollbar_layer_->Opacity());
- // Shrink along Y axis and expand along X, horizontal scrollbar
- // should disappear.
- clip_layer_->SetBounds(gfx::Size(200, 100));
- EXPECT_EQ(gfx::Size(200, 100), clip_layer_->bounds());
- GetScrollNode(scroll_layer_.get())->container_bounds = gfx::Size(200, 100);
- scroll_layer_->UpdateScrollable();
- UpdateActiveTreeDrawProperties();
- scrollbar_controller_->DidScrollUpdate();
- EXPECT_FLOAT_EQ(0.0f, h_scrollbar_layer_->Opacity());
- }
- // Scroll content. Confirm the scrollbar appears and fades out.
- TEST_F(ScrollbarAnimationControllerAuraOverlayTest, BasicAppearAndFadeOut) {
- base::TimeTicks time;
- time += base::Seconds(1);
- // Scrollbar should be invisible.
- ExpectScrollbarsOpacity(0);
- EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden());
- // Scrollbar should appear only on scroll update.
- ExpectScrollbarsOpacity(0);
- EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden());
- scrollbar_controller_->DidScrollUpdate();
- ExpectScrollbarsOpacity(1);
- EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
- ExpectScrollbarsOpacity(1);
- EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
- // An fade out animation should have been enqueued.
- EXPECT_EQ(kFadeDelay, client_.delay());
- EXPECT_FALSE(client_.start_fade().is_null());
- std::move(client_.start_fade()).Run();
- // Scrollbar should fade out over kFadeDuration.
- scrollbar_controller_->Animate(time);
- time += kFadeDuration;
- scrollbar_controller_->Animate(time);
- ExpectScrollbarsOpacity(0);
- EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden());
- }
- // Confirm the scrollbar appears by WillUpdateScroll and fade out.
- TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
- BasicAppearByWillUpdateScrollThenFadeOut) {
- base::TimeTicks time;
- time += base::Seconds(1);
- // Scrollbar should be invisible.
- ExpectScrollbarsOpacity(0);
- EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden());
- // Scrollbar should appear when scroll will update.
- scrollbar_controller_->WillUpdateScroll();
- ExpectScrollbarsOpacity(1);
- EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
- // An fade out animation should have been enqueued.
- EXPECT_EQ(kFadeDelay, client_.delay());
- EXPECT_FALSE(client_.start_fade().is_null());
- std::move(client_.start_fade()).Run();
- // Scrollbar should fade out over kFadeDuration.
- scrollbar_controller_->Animate(time);
- time += kFadeDuration;
- scrollbar_controller_->Animate(time);
- ExpectScrollbarsOpacity(0);
- EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden());
- }
- // Scroll content. Move the mouse near the scrollbar track but not near thumb
- // and confirm it stay thin. Move the mouse near the scrollbar thumb and
- // confirm it becomes thick.
- TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
- MoveNearTrackThenNearThumb) {
- base::TimeTicks time;
- time += base::Seconds(1);
- scrollbar_controller_->DidScrollUpdate();
- // An fade out animation should have been enqueued.
- EXPECT_EQ(kFadeDelay, client_.delay());
- EXPECT_FALSE(client_.start_fade().is_null());
- EXPECT_FALSE(client_.start_fade().IsCancelled());
- // Now move the mouse near the vertical scrollbar track. This should cancel
- // the currently queued fading animation and stay scrollbar thin.
- scrollbar_controller_->DidMouseMove(NearVerticalScrollbarEnd(-1, 0));
- ExpectScrollbarsOpacity(1);
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- h_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_TRUE(client_.start_fade().IsCancelled());
- scrollbar_controller_->Animate(time);
- time += kThinningDuration;
- scrollbar_controller_->Animate(time);
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- h_scrollbar_layer_->thumb_thickness_scale_factor());
- scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(-1, 0));
- scrollbar_controller_->Animate(time);
- time += kThinningDuration;
- scrollbar_controller_->Animate(time);
- EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- h_scrollbar_layer_->thumb_thickness_scale_factor());
- scrollbar_controller_->DidMouseMove(NearVerticalScrollbarEnd(-1, 0));
- EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- h_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_TRUE(client_.start_fade().IsCancelled());
- scrollbar_controller_->Animate(time);
- time += kThinningDuration;
- scrollbar_controller_->Animate(time);
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- h_scrollbar_layer_->thumb_thickness_scale_factor());
- }
- // Scroll content. Move the mouse near the scrollbar thumb and confirm it
- // becomes thick. Ensure it remains visible as long as the mouse is near the
- // scrollbar.
- TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MoveNearAndDontFadeOut) {
- base::TimeTicks time;
- time += base::Seconds(1);
- scrollbar_controller_->DidScrollUpdate();
- // An fade out animation should have been enqueued.
- EXPECT_EQ(kFadeDelay, client_.delay());
- EXPECT_FALSE(client_.start_fade().is_null());
- EXPECT_FALSE(client_.start_fade().IsCancelled());
- // Now move the mouse near the vertical scrollbar thumb. This should cancel
- // the currently queued fading animation and start animating thickness.
- scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(-1, 0));
- ExpectScrollbarsOpacity(1);
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- h_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_TRUE(client_.start_fade().IsCancelled());
- // Vertical scrollbar should become thick.
- scrollbar_controller_->Animate(time);
- time += kThinningDuration;
- scrollbar_controller_->Animate(time);
- ExpectScrollbarsOpacity(1);
- EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- h_scrollbar_layer_->thumb_thickness_scale_factor());
- // Mouse is still near the Scrollbar. Once the thickness animation is
- // complete, the queued delayed fade out animation should be either cancelled
- // or null.
- EXPECT_TRUE(client_.start_fade().is_null() ||
- client_.start_fade().IsCancelled());
- }
- // Scroll content. Move the mouse over the scrollbar and confirm it becomes
- // thick. Ensure it remains visible as long as the mouse is over the scrollbar.
- TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MoveOverAndDontFadeOut) {
- base::TimeTicks time;
- time += base::Seconds(1);
- scrollbar_controller_->DidScrollUpdate();
- // An fade out animation should have been enqueued.
- EXPECT_EQ(kFadeDelay, client_.delay());
- EXPECT_FALSE(client_.start_fade().is_null());
- EXPECT_FALSE(client_.start_fade().IsCancelled());
- // Now move the mouse over the vertical scrollbar thumb. This should cancel
- // the currently queued fading animation and start animating thickness.
- scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(0, 0));
- ExpectScrollbarsOpacity(1);
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- h_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_TRUE(client_.start_fade().IsCancelled());
- // Vertical scrollbar should become thick.
- scrollbar_controller_->Animate(time);
- time += kThinningDuration;
- scrollbar_controller_->Animate(time);
- ExpectScrollbarsOpacity(1);
- EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- h_scrollbar_layer_->thumb_thickness_scale_factor());
- // Mouse is still over the Scrollbar. Once the thickness animation is
- // complete, the queued delayed fade out animation should be either cancelled
- // or null.
- EXPECT_TRUE(client_.start_fade().is_null() ||
- client_.start_fade().IsCancelled());
- }
- // Make sure a scrollbar captured before the thickening animation doesn't try
- // to fade out.
- TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
- DontFadeWhileCapturedBeforeThick) {
- base::TimeTicks time;
- time += base::Seconds(1);
- scrollbar_controller_->DidScrollUpdate();
- // An fade out animation should have been enqueued.
- EXPECT_EQ(kFadeDelay, client_.delay());
- EXPECT_FALSE(client_.start_fade().is_null());
- // Now move the mouse over the vertical scrollbar thumb and capture it. It
- // should become thick without need for an animation.
- scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(0, 0));
- scrollbar_controller_->DidMouseDown();
- ExpectScrollbarsOpacity(1);
- EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- h_scrollbar_layer_->thumb_thickness_scale_factor());
- // The fade out animation should have been cleared or cancelled.
- EXPECT_TRUE(client_.start_fade().is_null() ||
- client_.start_fade().IsCancelled());
- }
- // Make sure a scrollbar captured then move mouse away doesn't try to fade out.
- TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
- DontFadeWhileCapturedThenAway) {
- base::TimeTicks time;
- time += base::Seconds(1);
- scrollbar_controller_->DidScrollUpdate();
- // An fade out animation should have been enqueued.
- EXPECT_EQ(kFadeDelay, client_.delay());
- EXPECT_FALSE(client_.start_fade().is_null());
- // Now move the mouse over the vertical scrollbar and capture it. It should
- // become thick without need for an animation.
- scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(0, 0));
- scrollbar_controller_->DidMouseDown();
- ExpectScrollbarsOpacity(1);
- EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- h_scrollbar_layer_->thumb_thickness_scale_factor());
- // The fade out animation should have been cleared or cancelled.
- EXPECT_TRUE(client_.start_fade().is_null() ||
- client_.start_fade().IsCancelled());
- // Then move mouse away, The fade out animation should have been cleared or
- // cancelled.
- scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(
- -mouse_move_distance_to_trigger_expand_ - 1, 0));
- EXPECT_TRUE(client_.start_fade().is_null() ||
- client_.start_fade().IsCancelled());
- }
- // Make sure a scrollbar captured after a thickening animation doesn't try to
- // fade out.
- TEST_F(ScrollbarAnimationControllerAuraOverlayTest, DontFadeWhileCaptured) {
- base::TimeTicks time;
- time += base::Seconds(1);
- scrollbar_controller_->DidScrollUpdate();
- // An fade out animation should have been enqueued.
- EXPECT_EQ(kFadeDelay, client_.delay());
- EXPECT_FALSE(client_.start_fade().is_null());
- EXPECT_FALSE(client_.start_fade().IsCancelled());
- // Now move the mouse over the vertical scrollbar thumb and animate it until
- // it's thick.
- scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(0, 0));
- scrollbar_controller_->Animate(time);
- time += kThinningDuration;
- scrollbar_controller_->Animate(time);
- ExpectScrollbarsOpacity(1);
- EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- h_scrollbar_layer_->thumb_thickness_scale_factor());
- // Since the mouse is over the scrollbar, it should either clear or cancel the
- // queued fade.
- EXPECT_TRUE(client_.start_fade().is_null() ||
- client_.start_fade().IsCancelled());
- // Make sure the queued fade out animation is still null or cancelled after
- // capturing the scrollbar.
- scrollbar_controller_->DidMouseDown();
- EXPECT_TRUE(client_.start_fade().is_null() ||
- client_.start_fade().IsCancelled());
- }
- // Make sure releasing a captured scrollbar when the mouse isn't near it, causes
- // the scrollbar to fade out.
- TEST_F(ScrollbarAnimationControllerAuraOverlayTest, FadeAfterReleasedFar) {
- base::TimeTicks time;
- time += base::Seconds(1);
- scrollbar_controller_->DidScrollUpdate();
- // An fade out animation should have been enqueued.
- EXPECT_EQ(kFadeDelay, client_.delay());
- EXPECT_FALSE(client_.start_fade().is_null());
- EXPECT_FALSE(client_.start_fade().IsCancelled());
- // Now move the mouse over the vertical scrollbar thumb and capture it.
- scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(0, 0));
- scrollbar_controller_->DidMouseDown();
- ExpectScrollbarsOpacity(1);
- EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- h_scrollbar_layer_->thumb_thickness_scale_factor());
- // Since the mouse is still near the scrollbar, the queued fade should be
- // either null or cancelled.
- EXPECT_TRUE(client_.start_fade().is_null() ||
- client_.start_fade().IsCancelled());
- // Now move the mouse away from the scrollbar and release it.
- scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(
- -mouse_move_distance_to_trigger_fade_in_ - 1, 0));
- scrollbar_controller_->DidMouseUp();
- scrollbar_controller_->Animate(time);
- ExpectScrollbarsOpacity(1);
- EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- h_scrollbar_layer_->thumb_thickness_scale_factor());
- time += kThinningDuration;
- scrollbar_controller_->Animate(time);
- ExpectScrollbarsOpacity(1);
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- h_scrollbar_layer_->thumb_thickness_scale_factor());
- // The thickness animation is complete, a fade out must be queued.
- EXPECT_FALSE(client_.start_fade().is_null());
- EXPECT_FALSE(client_.start_fade().IsCancelled());
- }
- // Make sure releasing a captured scrollbar when the mouse is near/over it,
- // doesn't cause the scrollbar to fade out.
- TEST_F(ScrollbarAnimationControllerAuraOverlayTest, DontFadeAfterReleasedNear) {
- base::TimeTicks time;
- time += base::Seconds(1);
- scrollbar_controller_->DidScrollUpdate();
- // An fade out animation should have been enqueued.
- EXPECT_EQ(kFadeDelay, client_.delay());
- EXPECT_FALSE(client_.start_fade().is_null());
- EXPECT_FALSE(client_.start_fade().IsCancelled());
- // Now move the mouse over the vertical scrollbar thumb and capture it.
- scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(0, 0));
- scrollbar_controller_->DidMouseDown();
- ExpectScrollbarsOpacity(1);
- EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- h_scrollbar_layer_->thumb_thickness_scale_factor());
- // Since the mouse is over the scrollbar, the queued fade must be either
- // null or cancelled.
- EXPECT_TRUE(client_.start_fade().is_null() ||
- client_.start_fade().IsCancelled());
- // Mouse is still near the scrollbar, releasing it shouldn't do anything.
- scrollbar_controller_->DidMouseUp();
- EXPECT_TRUE(client_.start_fade().is_null() ||
- client_.start_fade().IsCancelled());
- ExpectScrollbarsOpacity(1);
- EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- h_scrollbar_layer_->thumb_thickness_scale_factor());
- }
- // Make sure moving near a scrollbar while it's fading out causes it to reset
- // the opacity and thicken.
- TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
- MoveNearScrollbarWhileFading) {
- base::TimeTicks time;
- time += base::Seconds(1);
- scrollbar_controller_->DidScrollUpdate();
- // A fade out animation should have been enqueued. Start it.
- EXPECT_EQ(kFadeDelay, client_.delay());
- EXPECT_FALSE(client_.start_fade().is_null());
- std::move(client_.start_fade()).Run();
- scrollbar_controller_->Animate(time);
- ExpectScrollbarsOpacity(1);
- // Proceed half way through the fade out animation.
- time += kFadeDuration / 2;
- scrollbar_controller_->Animate(time);
- ExpectScrollbarsOpacity(.5f);
- // Now move the mouse near the vertical scrollbar thumb. It should reset
- // opacity to 1 instantly and start animating to thick.
- scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(0, 0));
- ExpectScrollbarsOpacity(1);
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- h_scrollbar_layer_->thumb_thickness_scale_factor());
- scrollbar_controller_->Animate(time);
- time += kThinningDuration;
- scrollbar_controller_->Animate(time);
- ExpectScrollbarsOpacity(1);
- EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- h_scrollbar_layer_->thumb_thickness_scale_factor());
- }
- // Make sure we can't capture scrollbar that's completely faded out.
- TEST_F(ScrollbarAnimationControllerAuraOverlayTest, TestCantCaptureWhenFaded) {
- base::TimeTicks time;
- time += base::Seconds(1);
- scrollbar_controller_->DidScrollUpdate();
- EXPECT_EQ(kFadeDelay, client_.delay());
- EXPECT_FALSE(client_.start_fade().is_null());
- EXPECT_FALSE(client_.start_fade().IsCancelled());
- std::move(client_.start_fade()).Run();
- scrollbar_controller_->Animate(time);
- ExpectScrollbarsOpacity(1);
- // Fade the scrollbar out completely.
- time += kFadeDuration;
- scrollbar_controller_->Animate(time);
- ExpectScrollbarsOpacity(0);
- // Move mouse over the vertical scrollbar thumb. It shouldn't thicken the
- // scrollbar since it's completely faded out.
- scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(0, 0));
- scrollbar_controller_->Animate(time);
- time += kThinningDuration;
- scrollbar_controller_->Animate(time);
- ExpectScrollbarsOpacity(0);
- EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- h_scrollbar_layer_->thumb_thickness_scale_factor());
- client_.start_fade().Reset();
- // Now try to capture the scrollbar. It shouldn't do anything since it's
- // completely faded out.
- scrollbar_controller_->DidMouseDown();
- ExpectScrollbarsOpacity(0);
- EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- h_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_TRUE(client_.start_fade().is_null());
- // Similarly, releasing the scrollbar should have no effect but trigger a fade
- // in.
- scrollbar_controller_->DidMouseUp();
- ExpectScrollbarsOpacity(0);
- EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- h_scrollbar_layer_->thumb_thickness_scale_factor());
- // An fade in animation should have been enqueued.
- EXPECT_FALSE(client_.start_fade().is_null());
- EXPECT_FALSE(client_.start_fade().IsCancelled());
- EXPECT_EQ(kFadeDelay, client_.delay());
- // Play the delay animation.
- std::move(client_.start_fade()).Run();
- scrollbar_controller_->Animate(time);
- time += kFadeDuration;
- scrollbar_controller_->Animate(time);
- EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
- }
- // Initiate a scroll when the pointer is already near the scrollbar. It should
- // appear thick and remain thick.
- TEST_F(ScrollbarAnimationControllerAuraOverlayTest, ScrollWithMouseNear) {
- base::TimeTicks time;
- time += base::Seconds(1);
- scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(-1, 0));
- scrollbar_controller_->Animate(time);
- time += kThinningDuration;
- // Since the scrollbar isn't visible yet (because we haven't scrolled), we
- // shouldn't have applied the thickening.
- scrollbar_controller_->Animate(time);
- EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- h_scrollbar_layer_->thumb_thickness_scale_factor());
- scrollbar_controller_->DidScrollUpdate();
- // Now that we've received a scroll, we should be thick without an animation.
- ExpectScrollbarsOpacity(1);
- // An animation for the fade should be either null or cancelled, since
- // mouse is still near the scrollbar.
- EXPECT_TRUE(client_.start_fade().is_null() ||
- client_.start_fade().IsCancelled());
- scrollbar_controller_->Animate(time);
- ExpectScrollbarsOpacity(1);
- EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- h_scrollbar_layer_->thumb_thickness_scale_factor());
- // Scrollbar should still be thick and visible.
- time += kFadeDuration;
- scrollbar_controller_->Animate(time);
- ExpectScrollbarsOpacity(1);
- EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- h_scrollbar_layer_->thumb_thickness_scale_factor());
- }
- // Tests that main thread scroll updates immediately queue a fade out animation
- TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
- MainThreadScrollQueuesFade) {
- ASSERT_TRUE(client_.start_fade().is_null());
- // A ScrollUpdate indicates a main thread scroll update so we should schedule
- // a fade out animation since there is no scroll end notification.
- scrollbar_controller_->DidScrollUpdate();
- EXPECT_FALSE(client_.start_fade().is_null());
- EXPECT_EQ(kFadeDelay, client_.delay());
- }
- // Tests that the fade effect is animated.
- TEST_F(ScrollbarAnimationControllerAuraOverlayTest, FadeAnimated) {
- base::TimeTicks time;
- time += base::Seconds(1);
- // Scroll to make the scrollbars visible.
- scrollbar_controller_->DidScrollUpdate();
- // Appearance is instant.
- ExpectScrollbarsOpacity(1);
- // An fade out animation should have been enqueued.
- EXPECT_EQ(kFadeDelay, client_.delay());
- EXPECT_FALSE(client_.start_fade().is_null());
- std::move(client_.start_fade()).Run();
- // Test that at half the fade duration time, the opacity is at half.
- scrollbar_controller_->Animate(time);
- ExpectScrollbarsOpacity(1);
- time += kFadeDuration / 2;
- scrollbar_controller_->Animate(time);
- ExpectScrollbarsOpacity(.5f);
- time += kFadeDuration / 2;
- scrollbar_controller_->Animate(time);
- ExpectScrollbarsOpacity(0);
- }
- // Tests that the controller tells the client when the scrollbars hide/show.
- TEST_F(ScrollbarAnimationControllerAuraOverlayTest, NotifyChangedVisibility) {
- base::TimeTicks time;
- time += base::Seconds(1);
- EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1);
- // Scroll to make the scrollbars visible.
- scrollbar_controller_->DidScrollUpdate();
- EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
- Mock::VerifyAndClearExpectations(&client_);
- // Play out the fade out animation. We shouldn't notify that the scrollbars
- // are hidden until the animation is completly over. We can (but don't have
- // to) notify during the animation that the scrollbars are still visible.
- EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(0);
- ASSERT_FALSE(client_.start_fade().is_null());
- std::move(client_.start_fade()).Run();
- scrollbar_controller_->Animate(time);
- time += kFadeDuration / 4;
- EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
- scrollbar_controller_->Animate(time);
- time += kFadeDuration / 4;
- EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
- scrollbar_controller_->Animate(time);
- time += kFadeDuration / 4;
- EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
- scrollbar_controller_->Animate(time);
- ExpectScrollbarsOpacity(.25f);
- Mock::VerifyAndClearExpectations(&client_);
- EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1);
- time += kFadeDuration / 4;
- scrollbar_controller_->Animate(time);
- EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden());
- ExpectScrollbarsOpacity(0);
- Mock::VerifyAndClearExpectations(&client_);
- // Calling DidScrollUpdate without a begin (i.e. update from commit) should
- // also notify.
- EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1);
- scrollbar_controller_->DidScrollUpdate();
- EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
- Mock::VerifyAndClearExpectations(&client_);
- }
- // Move the pointer near each scrollbar. Confirm it gets thick and narrow when
- // moved away.
- TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MouseNearEach) {
- base::TimeTicks time;
- time += base::Seconds(1);
- // Scroll to make the scrollbars visible.
- scrollbar_controller_->DidScrollUpdate();
- // Near vertical scrollbar.
- scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(-1, 0));
- scrollbar_controller_->Animate(time);
- ExpectScrollbarsOpacity(1);
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- h_scrollbar_layer_->thumb_thickness_scale_factor());
- // Should animate to thickened.
- time += kThinningDuration;
- scrollbar_controller_->Animate(time);
- ExpectScrollbarsOpacity(1);
- EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- h_scrollbar_layer_->thumb_thickness_scale_factor());
- // Subsequent moves within the nearness threshold should not change anything.
- scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(-2, 0));
- scrollbar_controller_->Animate(time);
- time += base::Seconds(10);
- scrollbar_controller_->Animate(time);
- ExpectScrollbarsOpacity(1);
- EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- h_scrollbar_layer_->thumb_thickness_scale_factor());
- // Now move away from bar.
- scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(
- -mouse_move_distance_to_trigger_expand_ - 1, 0));
- scrollbar_controller_->Animate(time);
- time += kThinningDuration;
- scrollbar_controller_->Animate(time);
- ExpectScrollbarsOpacity(1);
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- h_scrollbar_layer_->thumb_thickness_scale_factor());
- // Near horizontal scrollbar
- scrollbar_controller_->DidMouseMove(NearHorizontalScrollbarBegin(0, -1));
- scrollbar_controller_->Animate(time);
- ExpectScrollbarsOpacity(1);
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- h_scrollbar_layer_->thumb_thickness_scale_factor());
- // Should animate to thickened.
- time += kThinningDuration;
- scrollbar_controller_->Animate(time);
- ExpectScrollbarsOpacity(1);
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(1, h_scrollbar_layer_->thumb_thickness_scale_factor());
- // Subsequent moves within the nearness threshold should not change anything.
- scrollbar_controller_->DidMouseMove(NearHorizontalScrollbarBegin(0, -2));
- scrollbar_controller_->Animate(time);
- time += base::Seconds(10);
- scrollbar_controller_->Animate(time);
- ExpectScrollbarsOpacity(1);
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(1, h_scrollbar_layer_->thumb_thickness_scale_factor());
- // Now move away from bar.
- scrollbar_controller_->DidMouseMove(NearHorizontalScrollbarBegin(
- 0, -mouse_move_distance_to_trigger_expand_ - 1));
- scrollbar_controller_->Animate(time);
- time += kThinningDuration;
- scrollbar_controller_->Animate(time);
- ExpectScrollbarsOpacity(1);
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- h_scrollbar_layer_->thumb_thickness_scale_factor());
- // An fade out animation should have been enqueued.
- EXPECT_FALSE(client_.start_fade().is_null());
- EXPECT_EQ(kFadeDelay, client_.delay());
- }
- // Move mouse near both scrollbars at the same time.
- TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MouseNearBoth) {
- base::TimeTicks time;
- time += base::Seconds(1);
- // Scroll to make the scrollbars visible.
- scrollbar_controller_->DidScrollUpdate();
- // Move scrollbar thumb to the end of track.
- v_scrollbar_layer_->SetCurrentPos(100);
- h_scrollbar_layer_->SetCurrentPos(100);
- // Near both Scrollbar
- scrollbar_controller_->DidMouseMove(NearVerticalScrollbarEnd(-1, -1));
- scrollbar_controller_->Animate(time);
- ExpectScrollbarsOpacity(1);
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- h_scrollbar_layer_->thumb_thickness_scale_factor());
- // Should animate to thickened.
- time += kThinningDuration;
- scrollbar_controller_->Animate(time);
- ExpectScrollbarsOpacity(1);
- EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(1, h_scrollbar_layer_->thumb_thickness_scale_factor());
- }
- // Move mouse from one to the other scrollbar before animation is finished, then
- // away before animation finished.
- TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
- MouseNearOtherBeforeAnimationFinished) {
- base::TimeTicks time;
- time += base::Seconds(1);
- // Scroll to make the scrollbars visible.
- scrollbar_controller_->DidScrollUpdate();
- // Near vertical scrollbar.
- scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(-1, 0));
- scrollbar_controller_->Animate(time);
- ExpectScrollbarsOpacity(1);
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- h_scrollbar_layer_->thumb_thickness_scale_factor());
- // Vertical scrollbar animate to half thickened.
- time += kThinningDuration / 2;
- scrollbar_controller_->Animate(time);
- ExpectScrollbarsOpacity(1);
- EXPECT_FLOAT_EQ(kIdleThicknessScale + (1.0f - kIdleThicknessScale) / 2,
- v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- h_scrollbar_layer_->thumb_thickness_scale_factor());
- // Away vertical scrollbar and near horizontal scrollbar.
- scrollbar_controller_->DidMouseMove(gfx::PointF(0, 0));
- scrollbar_controller_->DidMouseMove(NearHorizontalScrollbarBegin(0, -1));
- scrollbar_controller_->Animate(time);
- // Vertical scrollbar animate to thin. horizontal scrollbar animate to
- // thickened.
- time += kThinningDuration;
- scrollbar_controller_->Animate(time);
- ExpectScrollbarsOpacity(1);
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(1, h_scrollbar_layer_->thumb_thickness_scale_factor());
- // Away horizontal scrollbar.
- scrollbar_controller_->DidMouseMove(gfx::PointF(0, 0));
- scrollbar_controller_->Animate(time);
- // Horizontal scrollbar animate to thin.
- time += kThinningDuration;
- scrollbar_controller_->Animate(time);
- ExpectScrollbarsOpacity(1);
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- h_scrollbar_layer_->thumb_thickness_scale_factor());
- // An fade out animation should have been enqueued.
- EXPECT_FALSE(client_.start_fade().is_null());
- EXPECT_EQ(kFadeDelay, client_.delay());
- }
- // Ensure we have a delay fadeout animation after mouse leave without a mouse
- // move.
- TEST_F(ScrollbarAnimationControllerAuraOverlayTest, MouseLeaveFadeOut) {
- base::TimeTicks time;
- time += base::Seconds(1);
- // Move mouse near scrollbar.
- scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(-1, 0));
- // Scroll to make the scrollbars visible.
- scrollbar_controller_->DidScrollUpdate();
- // Should not have delay fadeout animation.
- EXPECT_TRUE(client_.start_fade().is_null() ||
- client_.start_fade().IsCancelled());
- // Mouse leave.
- scrollbar_controller_->DidMouseLeave();
- // An fade out animation should have been enqueued.
- EXPECT_FALSE(client_.start_fade().is_null());
- EXPECT_EQ(kFadeDelay, client_.delay());
- }
- // Scrollbars should schedule a delay fade in when mouse hover the show
- // scrollbar region of a hidden scrollbar.
- TEST_F(ScrollbarAnimationControllerAuraOverlayTest, BasicMouseHoverFadeIn) {
- base::TimeTicks time;
- time += base::Seconds(1);
- // Move mouse over the fade in region of scrollbar.
- scrollbar_controller_->DidMouseMove(
- NearVerticalScrollbarBegin(-mouse_move_distance_to_trigger_fade_in_, 0));
- // An fade in animation should have been enqueued.
- EXPECT_FALSE(client_.start_fade().is_null());
- EXPECT_FALSE(client_.start_fade().IsCancelled());
- EXPECT_EQ(kFadeDelay, client_.delay());
- // Play the delay animation.
- std::move(client_.start_fade()).Run();
- scrollbar_controller_->Animate(time);
- time += kFadeDuration / 2;
- scrollbar_controller_->Animate(time);
- ExpectScrollbarsOpacity(0.5);
- EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
- time += kFadeDuration / 2;
- scrollbar_controller_->Animate(time);
- ExpectScrollbarsOpacity(1);
- EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
- }
- // Scrollbars should not schedule a new delay fade in when the mouse hovers
- // inside a scrollbar already scheduled a delay fade in.
- TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
- MouseHoverScrollbarAndMoveInside) {
- base::TimeTicks time;
- time += base::Seconds(1);
- // Move mouse over the fade in region of scrollbar.
- scrollbar_controller_->DidMouseMove(
- NearVerticalScrollbarBegin(-mouse_move_distance_to_trigger_fade_in_, 0));
- // An fade in animation should have been enqueued.
- EXPECT_FALSE(client_.start_fade().is_null());
- EXPECT_FALSE(client_.start_fade().IsCancelled());
- EXPECT_EQ(kFadeDelay, client_.delay());
- client_.start_fade().Reset();
- // Move mouse still hover the fade in region of scrollbar should not
- // post a new fade in.
- scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(
- -mouse_move_distance_to_trigger_fade_in_ + 2, 0));
- EXPECT_TRUE(client_.start_fade().is_null());
- }
- // Scrollbars should cancel delay fade in when mouse hover hidden scrollbar then
- // move far away.
- TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
- MouseHoverThenOutShouldCancelFadeIn) {
- base::TimeTicks time;
- time += base::Seconds(1);
- // Move mouse over the fade in region of scrollbar.
- scrollbar_controller_->DidMouseMove(
- NearVerticalScrollbarBegin(-mouse_move_distance_to_trigger_fade_in_, 0));
- // An fade in animation should have been enqueued.
- EXPECT_FALSE(client_.start_fade().is_null());
- EXPECT_FALSE(client_.start_fade().IsCancelled());
- EXPECT_EQ(kFadeDelay, client_.delay());
- // Move mouse far away,delay fade in should be canceled.
- scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(
- -mouse_move_distance_to_trigger_fade_in_ - 1, 0));
- EXPECT_TRUE(client_.start_fade().is_null() ||
- client_.start_fade().IsCancelled());
- }
- // Scrollbars should cancel delay fade in when mouse hover hidden scrollbar then
- // move out of window.
- TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
- MouseHoverThenLeaveShouldCancelShowThenEnterShouldFadeIn) {
- base::TimeTicks time;
- time += base::Seconds(1);
- // Move mouse over the fade in region of scrollbar.
- scrollbar_controller_->DidMouseMove(
- NearVerticalScrollbarBegin(-mouse_move_distance_to_trigger_fade_in_, 0));
- // An fade in animation should have been enqueued.
- EXPECT_FALSE(client_.start_fade().is_null());
- EXPECT_FALSE(client_.start_fade().IsCancelled());
- EXPECT_EQ(kFadeDelay, client_.delay());
- // Move mouse out of window,delay fade in should be canceled.
- scrollbar_controller_->DidMouseLeave();
- EXPECT_TRUE(client_.start_fade().is_null() ||
- client_.start_fade().IsCancelled());
- // Move mouse over the fade in region of scrollbar.
- scrollbar_controller_->DidMouseMove(
- NearVerticalScrollbarBegin(-mouse_move_distance_to_trigger_fade_in_, 0));
- // An fade in animation should have been enqueued.
- EXPECT_FALSE(client_.start_fade().is_null());
- EXPECT_FALSE(client_.start_fade().IsCancelled());
- EXPECT_EQ(kFadeDelay, client_.delay());
- // Play the delay animation.
- std::move(client_.start_fade()).Run();
- scrollbar_controller_->Animate(time);
- time += kFadeDuration;
- scrollbar_controller_->Animate(time);
- EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
- }
- // Make sure mouse down will cancel hover fade in timer, then mouse move with
- // press will not trigger hover fade in, mouse release near will trigger new
- // hover fade in.
- TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
- MouseHoverThenMouseDownShouldCancelFadeInThenReleaseNearShouldFadeIn) {
- base::TimeTicks time;
- time += base::Seconds(1);
- // Move mouse over the fade in region of scrollbar.
- scrollbar_controller_->DidMouseMove(
- NearVerticalScrollbarBegin(-mouse_move_distance_to_trigger_fade_in_, 0));
- // An fade in animation should have been enqueued.
- EXPECT_FALSE(client_.start_fade().is_null());
- EXPECT_FALSE(client_.start_fade().IsCancelled());
- EXPECT_EQ(kFadeDelay, client_.delay());
- // Mouse down,delay fade in should be canceled.
- scrollbar_controller_->DidMouseDown();
- EXPECT_TRUE(client_.start_fade().is_null() ||
- client_.start_fade().IsCancelled());
- // Move mouse hover the fade in region of scrollbar with press.
- scrollbar_controller_->DidMouseMove(
- NearVerticalScrollbarBegin(-mouse_move_distance_to_trigger_fade_in_, 0));
- // Should not have delay fade animation.
- EXPECT_TRUE(client_.start_fade().is_null() ||
- client_.start_fade().IsCancelled());
- // Mouse up.
- scrollbar_controller_->DidMouseUp();
- // An fade in animation should have been enqueued.
- EXPECT_FALSE(client_.start_fade().is_null());
- EXPECT_FALSE(client_.start_fade().IsCancelled());
- EXPECT_EQ(kFadeDelay, client_.delay());
- // Play the delay animation.
- std::move(client_.start_fade()).Run();
- scrollbar_controller_->Animate(time);
- time += kFadeDuration;
- scrollbar_controller_->Animate(time);
- EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
- }
- // Make sure mouse down will cancel hover fade in timer, then mouse move with
- // press will not trigger hover fade in, mouse release far will not trigger new
- // hover fade in.
- TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
- MouseReleaseFarShouldNotFadeIn) {
- base::TimeTicks time;
- time += base::Seconds(1);
- // Move mouse over the fade in region of scrollbar.
- scrollbar_controller_->DidMouseMove(
- NearVerticalScrollbarBegin(-mouse_move_distance_to_trigger_fade_in_, 0));
- // An fade in animation should have been enqueued.
- EXPECT_FALSE(client_.start_fade().is_null());
- EXPECT_FALSE(client_.start_fade().IsCancelled());
- EXPECT_EQ(kFadeDelay, client_.delay());
- // Mouse down,delay fade in should be canceled.
- scrollbar_controller_->DidMouseDown();
- EXPECT_TRUE(client_.start_fade().is_null() ||
- client_.start_fade().IsCancelled());
- // Move mouse far from hover the fade in region of scrollbar with
- // press.
- scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(
- -mouse_move_distance_to_trigger_fade_in_ - 1, 0));
- // Should not have delay fade animation.
- EXPECT_TRUE(client_.start_fade().is_null() ||
- client_.start_fade().IsCancelled());
- // Mouse up.
- scrollbar_controller_->DidMouseUp();
- // Should not have delay fade animation.
- EXPECT_TRUE(client_.start_fade().is_null() ||
- client_.start_fade().IsCancelled());
- }
- // Ensure Aura Overlay Scrollbars shows and did not fade out when tickmarks show
- // and fade out when tickmarks hide.
- TEST_F(ScrollbarAnimationControllerAuraOverlayTest, TickmakrsShowHide) {
- base::TimeTicks time;
- time += base::Seconds(1);
- // Overlay Scrollbar hidden at beginnging.
- EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden());
- EXPECT_TRUE(client_.start_fade().is_null() ||
- client_.start_fade().IsCancelled());
- // Scrollbars show when tickmarks show.
- scrollbar_controller_->UpdateTickmarksVisibility(true);
- EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
- EXPECT_TRUE(client_.start_fade().is_null() ||
- client_.start_fade().IsCancelled());
- // Scroll update, no delay fade animation.
- scrollbar_controller_->DidScrollUpdate();
- EXPECT_TRUE(client_.start_fade().is_null() ||
- client_.start_fade().IsCancelled());
- // Scroll update with phase, no delay fade animation.
- scrollbar_controller_->DidScrollUpdate();
- EXPECT_TRUE(client_.start_fade().is_null() ||
- client_.start_fade().IsCancelled());
- EXPECT_TRUE(client_.start_fade().is_null() ||
- client_.start_fade().IsCancelled());
- // Move mouse, no delay fade animation.
- scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(0, 0));
- EXPECT_TRUE(client_.start_fade().is_null() ||
- client_.start_fade().IsCancelled());
- // Mouse leave, no delay fade animation.
- scrollbar_controller_->DidMouseLeave();
- EXPECT_TRUE(client_.start_fade().is_null() ||
- client_.start_fade().IsCancelled());
- // Scrollbars fade out animation has enqueued when tickmarks hide.
- scrollbar_controller_->UpdateTickmarksVisibility(false);
- EXPECT_FALSE(client_.start_fade().is_null());
- EXPECT_FALSE(client_.start_fade().IsCancelled());
- EXPECT_EQ(kFadeDelay, client_.delay());
- }
- TEST_F(ScrollbarAnimationControllerFluentOverlayTest,
- FluentScrollbarMinimalModeByDefault) {
- // An fade out animation should have not been enqueued. Scrollbar stays in
- // the minimal (thin) mode.
- EXPECT_TRUE(client_.start_fade().is_null());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- h_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
- ExpectScrollbarsOpacity(1.f);
- }
- TEST_F(ScrollbarAnimationControllerFluentOverlayTest,
- FluentScrollbarMinimalModeOnMouseLeave) {
- // Move mouse inside scroller.
- scrollbar_controller_->DidMouseMove(gfx::PointF(50, 50));
- EXPECT_TRUE(client_.start_fade().is_null());
- ExpectScrollbarsOpacity(1.f);
- // Trigger mouse leave to check that Fluent overlay scrollbars don't fade out.
- scrollbar_controller_->DidMouseLeave();
- // An fade out animation should have not been enqueued. Scrollbar stays in
- // the minimal (thin) mode.
- EXPECT_TRUE(client_.start_fade().is_null());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- v_scrollbar_layer_->thumb_thickness_scale_factor());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- h_scrollbar_layer_->thumb_thickness_scale_factor());
- ExpectScrollbarsOpacity(1.f);
- }
- TEST_F(ScrollbarAnimationControllerFluentOverlayTest,
- FluentScrollbarMinimalModeOnWillUpdateScroll) {
- // Scrollbar should be visible on scroll will update.
- scrollbar_controller_->WillUpdateScroll();
- // An fade out animation should have not been enqueued. Scrollbar stays in
- // the minimal (thin) mode.
- EXPECT_TRUE(client_.start_fade().is_null());
- EXPECT_FLOAT_EQ(kIdleThicknessScale,
- v_scrollbar_layer_->thumb_thickness_scale_factor());
- ExpectScrollbarsOpacity(1.f);
- }
- class ScrollbarAnimationControllerAndroidTest
- : public LayerTreeImplTestBase,
- public testing::Test,
- public ScrollbarAnimationControllerClient {
- public:
- ScrollbarAnimationControllerAndroidTest()
- : did_request_redraw_(false), did_request_animate_(false) {}
- void PostDelayedScrollbarAnimationTask(base::OnceClosure start_fade,
- base::TimeDelta delay) override {
- start_fade_ = std::move(start_fade);
- delay_ = delay;
- }
- void SetNeedsRedrawForScrollbarAnimation() override {
- did_request_redraw_ = true;
- }
- void SetNeedsAnimateForScrollbarAnimation() override {
- did_request_animate_ = true;
- }
- ScrollbarSet ScrollbarsFor(ElementId scroll_element_id) const override {
- return host_impl()->ScrollbarsFor(scroll_element_id);
- }
- void DidChangeScrollbarVisibility() override {}
- bool IsFluentScrollbar() const override { return false; }
- protected:
- void SetUp() override {
- const int kTrackStart = 0;
- const bool kIsLeftSideVerticalScrollbar = false;
- LayerImpl* root = root_layer();
- scroll_layer_ = AddLayer<LayerImpl>();
- scrollbar_layer_ = AddLayer<SolidColorScrollbarLayerImpl>(
- orientation(), kThumbThickness, kTrackStart,
- kIsLeftSideVerticalScrollbar);
- SetElementIdsForTesting();
- scroll_layer_->SetBounds(gfx::Size(200, 200));
- CopyProperties(root, scroll_layer_);
- CreateTransformNode(scroll_layer_);
- CreateScrollNode(scroll_layer_, gfx::Size(100, 100));
- scrollbar_layer_->SetScrollElementId(scroll_layer_->element_id());
- CopyProperties(scroll_layer_, scrollbar_layer_);
- auto& scrollbar_effect = CreateEffectNode(scrollbar_layer_);
- scrollbar_effect.opacity = 0.f;
- scrollbar_effect.has_potential_opacity_animation = true;
- UpdateActiveTreeDrawProperties();
- scrollbar_controller_ =
- ScrollbarAnimationController::CreateScrollbarAnimationControllerAndroid(
- scroll_layer_->element_id(), this, base::Seconds(2),
- base::Seconds(3), 0.0f);
- }
- virtual ScrollbarOrientation orientation() const {
- return ScrollbarOrientation::HORIZONTAL;
- }
- std::unique_ptr<ScrollbarAnimationController> scrollbar_controller_;
- raw_ptr<LayerImpl> scroll_layer_;
- raw_ptr<SolidColorScrollbarLayerImpl> scrollbar_layer_;
- base::OnceClosure start_fade_;
- base::TimeDelta delay_;
- bool did_request_redraw_;
- bool did_request_animate_;
- };
- class VerticalScrollbarAnimationControllerAndroidTest
- : public ScrollbarAnimationControllerAndroidTest {
- protected:
- ScrollbarOrientation orientation() const override {
- return ScrollbarOrientation::VERTICAL;
- }
- };
- TEST_F(ScrollbarAnimationControllerAndroidTest, HiddenInBegin) {
- scrollbar_layer_->SetOverlayScrollbarLayerOpacityAnimated(0.f);
- scrollbar_controller_->Animate(base::TimeTicks());
- EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity());
- }
- TEST_F(ScrollbarAnimationControllerAndroidTest,
- HiddenAfterNonScrollingGesture) {
- scrollbar_layer_->SetOverlayScrollbarLayerOpacityAnimated(0.f);
- base::TimeTicks time;
- time += base::Seconds(100);
- scrollbar_controller_->Animate(time);
- EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity());
- EXPECT_TRUE(start_fade_.is_null());
- time += base::Seconds(100);
- scrollbar_controller_->Animate(time);
- EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity());
- }
- // Confirm the scrollbar does not appear on WillUpdateScroll on Android.
- TEST_F(ScrollbarAnimationControllerAndroidTest,
- WillUpdateScrollNotAppearScrollbar) {
- base::TimeTicks time;
- time += base::Seconds(1);
- // Scrollbar should be invisible.
- EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity());
- EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden());
- // Scrollbar should appear when scroll will update.
- scrollbar_controller_->WillUpdateScroll();
- EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity());
- EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden());
- // No fade out animation should have been enqueued.
- EXPECT_TRUE(start_fade_.is_null());
- }
- TEST_F(ScrollbarAnimationControllerAndroidTest, HideOnResize) {
- EXPECT_EQ(gfx::Size(200, 200), scroll_layer_->bounds());
- EXPECT_EQ(ScrollbarOrientation::HORIZONTAL, scrollbar_layer_->orientation());
- // Shrink along X axis, horizontal scrollbar should appear.
- GetScrollNode(scroll_layer_.get())->container_bounds = gfx::Size(100, 200);
- scroll_layer_->UpdateScrollable();
- UpdateActiveTreeDrawProperties();
- scrollbar_controller_->DidScrollUpdate();
- EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
- // Shrink along Y axis and expand along X, horizontal scrollbar
- // should disappear.
- GetScrollNode(scroll_layer_.get())->container_bounds = gfx::Size(200, 100);
- scroll_layer_->UpdateScrollable();
- UpdateActiveTreeDrawProperties();
- scrollbar_controller_->DidScrollUpdate();
- EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity());
- }
- TEST_F(VerticalScrollbarAnimationControllerAndroidTest, HideOnResize) {
- EXPECT_EQ(gfx::Size(200, 200), scroll_layer_->bounds());
- EXPECT_EQ(ScrollbarOrientation::VERTICAL, scrollbar_layer_->orientation());
- // Shrink along X axis, vertical scrollbar should remain invisible.
- GetScrollNode(scroll_layer_.get())->container_bounds = gfx::Size(100, 200);
- scroll_layer_->UpdateScrollable();
- UpdateActiveTreeDrawProperties();
- scrollbar_controller_->DidScrollUpdate();
- EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity());
- // Shrink along Y axis and expand along X, vertical scrollbar should appear.
- GetScrollNode(scroll_layer_.get())->container_bounds = gfx::Size(200, 100);
- scroll_layer_->UpdateScrollable();
- UpdateActiveTreeDrawProperties();
- scrollbar_controller_->DidScrollUpdate();
- EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
- }
- TEST_F(ScrollbarAnimationControllerAndroidTest, HideOnUserNonScrollableHorz) {
- EXPECT_EQ(ScrollbarOrientation::HORIZONTAL, scrollbar_layer_->orientation());
- GetScrollNode(scroll_layer_.get())->user_scrollable_horizontal = false;
- UpdateActiveTreeDrawProperties();
- scrollbar_controller_->DidScrollUpdate();
- EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity());
- }
- TEST_F(ScrollbarAnimationControllerAndroidTest, ShowOnUserNonScrollableVert) {
- EXPECT_EQ(ScrollbarOrientation::HORIZONTAL, scrollbar_layer_->orientation());
- GetScrollNode(scroll_layer_.get())->user_scrollable_vertical = false;
- UpdateActiveTreeDrawProperties();
- scrollbar_controller_->DidScrollUpdate();
- EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
- }
- TEST_F(VerticalScrollbarAnimationControllerAndroidTest,
- HideOnUserNonScrollableVert) {
- EXPECT_EQ(ScrollbarOrientation::VERTICAL, scrollbar_layer_->orientation());
- GetScrollNode(scroll_layer_.get())->user_scrollable_vertical = false;
- UpdateActiveTreeDrawProperties();
- scrollbar_controller_->DidScrollUpdate();
- EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity());
- }
- TEST_F(VerticalScrollbarAnimationControllerAndroidTest,
- ShowOnUserNonScrollableHorz) {
- EXPECT_EQ(ScrollbarOrientation::VERTICAL, scrollbar_layer_->orientation());
- GetScrollNode(scroll_layer_.get())->user_scrollable_horizontal = false;
- UpdateActiveTreeDrawProperties();
- scrollbar_controller_->DidScrollUpdate();
- EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
- }
- TEST_F(ScrollbarAnimationControllerAndroidTest, AwakenByScrollingGesture) {
- base::TimeTicks time;
- time += base::Seconds(1);
- EXPECT_FALSE(did_request_animate_);
- scrollbar_controller_->DidScrollUpdate();
- EXPECT_FALSE(did_request_animate_);
- EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
- EXPECT_FALSE(start_fade_.is_null());
- time += base::Seconds(100);
- scrollbar_controller_->Animate(time);
- EXPECT_FALSE(did_request_animate_);
- EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
- EXPECT_FALSE(did_request_animate_);
- std::move(start_fade_).Run();
- EXPECT_TRUE(did_request_animate_);
- did_request_animate_ = false;
- time += base::Seconds(2);
- scrollbar_controller_->Animate(time);
- EXPECT_TRUE(did_request_animate_);
- did_request_animate_ = false;
- EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
- time += base::Seconds(1);
- scrollbar_controller_->Animate(time);
- EXPECT_TRUE(did_request_animate_);
- did_request_animate_ = false;
- EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->Opacity());
- time += base::Seconds(1);
- scrollbar_controller_->Animate(time);
- EXPECT_TRUE(did_request_animate_);
- did_request_animate_ = false;
- EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->Opacity());
- time += base::Seconds(1);
- scrollbar_controller_->DidScrollUpdate();
- std::move(start_fade_).Run();
- EXPECT_TRUE(did_request_animate_);
- did_request_animate_ = false;
- time += base::Seconds(2);
- scrollbar_controller_->Animate(time);
- EXPECT_TRUE(did_request_animate_);
- did_request_animate_ = false;
- EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
- time += base::Seconds(1);
- scrollbar_controller_->Animate(time);
- EXPECT_TRUE(did_request_animate_);
- did_request_animate_ = false;
- EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->Opacity());
- time += base::Seconds(1);
- scrollbar_controller_->Animate(time);
- EXPECT_TRUE(did_request_animate_);
- did_request_animate_ = false;
- EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->Opacity());
- time += base::Seconds(1);
- scrollbar_controller_->Animate(time);
- EXPECT_FALSE(did_request_animate_);
- EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity());
- }
- TEST_F(ScrollbarAnimationControllerAndroidTest, AwakenByProgrammaticScroll) {
- base::TimeTicks time;
- time += base::Seconds(1);
- scrollbar_controller_->DidScrollUpdate();
- EXPECT_FALSE(did_request_animate_);
- std::move(start_fade_).Run();
- EXPECT_TRUE(did_request_animate_);
- did_request_animate_ = false;
- scrollbar_controller_->Animate(time);
- EXPECT_TRUE(did_request_animate_);
- did_request_animate_ = false;
- EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
- time += base::Seconds(1);
- scrollbar_controller_->Animate(time);
- EXPECT_TRUE(did_request_animate_);
- did_request_animate_ = false;
- EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->Opacity());
- scrollbar_controller_->DidScrollUpdate();
- EXPECT_FALSE(did_request_animate_);
- std::move(start_fade_).Run();
- EXPECT_TRUE(did_request_animate_);
- did_request_animate_ = false;
- time += base::Seconds(2);
- scrollbar_controller_->Animate(time);
- EXPECT_TRUE(did_request_animate_);
- did_request_animate_ = false;
- EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
- time += base::Seconds(1);
- scrollbar_controller_->Animate(time);
- EXPECT_TRUE(did_request_animate_);
- did_request_animate_ = false;
- EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->Opacity());
- time += base::Seconds(1);
- scrollbar_controller_->Animate(time);
- EXPECT_TRUE(did_request_animate_);
- did_request_animate_ = false;
- EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->Opacity());
- time += base::Seconds(1);
- scrollbar_controller_->DidScrollUpdate();
- std::move(start_fade_).Run();
- time += base::Seconds(1);
- scrollbar_controller_->Animate(time);
- EXPECT_TRUE(did_request_animate_);
- did_request_animate_ = false;
- EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
- time += base::Seconds(1);
- scrollbar_controller_->Animate(time);
- EXPECT_TRUE(did_request_animate_);
- did_request_animate_ = false;
- EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->Opacity());
- time += base::Seconds(1);
- scrollbar_controller_->Animate(time);
- EXPECT_TRUE(did_request_animate_);
- did_request_animate_ = false;
- EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->Opacity());
- time += base::Seconds(1);
- scrollbar_controller_->Animate(time);
- EXPECT_FALSE(did_request_animate_);
- EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity());
- }
- TEST_F(ScrollbarAnimationControllerAndroidTest,
- AnimationPreservedByNonScrollingGesture) {
- base::TimeTicks time;
- time += base::Seconds(1);
- scrollbar_controller_->DidScrollUpdate();
- std::move(start_fade_).Run();
- EXPECT_TRUE(did_request_animate_);
- did_request_animate_ = false;
- scrollbar_controller_->Animate(time);
- EXPECT_TRUE(did_request_animate_);
- did_request_animate_ = false;
- EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
- time += base::Seconds(1);
- scrollbar_controller_->Animate(time);
- EXPECT_TRUE(did_request_animate_);
- did_request_animate_ = false;
- EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->Opacity());
- EXPECT_FALSE(did_request_animate_);
- EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->Opacity());
- time += base::Seconds(1);
- scrollbar_controller_->Animate(time);
- EXPECT_TRUE(did_request_animate_);
- did_request_animate_ = false;
- EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->Opacity());
- EXPECT_FALSE(did_request_animate_);
- EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->Opacity());
- time += base::Seconds(1);
- scrollbar_controller_->Animate(time);
- EXPECT_FALSE(did_request_animate_);
- EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity());
- }
- TEST_F(ScrollbarAnimationControllerAndroidTest,
- AnimationOverriddenByScrollingGesture) {
- base::TimeTicks time;
- time += base::Seconds(1);
- scrollbar_controller_->DidScrollUpdate();
- EXPECT_FALSE(did_request_animate_);
- std::move(start_fade_).Run();
- EXPECT_TRUE(did_request_animate_);
- did_request_animate_ = false;
- scrollbar_controller_->Animate(time);
- EXPECT_TRUE(did_request_animate_);
- did_request_animate_ = false;
- EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
- time += base::Seconds(1);
- scrollbar_controller_->Animate(time);
- EXPECT_TRUE(did_request_animate_);
- did_request_animate_ = false;
- EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->Opacity());
- EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->Opacity());
- time += base::Seconds(1);
- scrollbar_controller_->Animate(time);
- EXPECT_TRUE(did_request_animate_);
- did_request_animate_ = false;
- EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->Opacity());
- time += base::Seconds(1);
- scrollbar_controller_->DidScrollUpdate();
- EXPECT_FALSE(did_request_animate_);
- EXPECT_FLOAT_EQ(1, scrollbar_layer_->Opacity());
- time += base::Seconds(1);
- EXPECT_FALSE(did_request_animate_);
- EXPECT_FLOAT_EQ(1, scrollbar_layer_->Opacity());
- }
- } // namespace
- } // namespace cc
|