Commit a7037544 authored by Jun Mukai's avatar Jun Mukai Committed by Commit Bot

Use AnimationDelegateViews for PaginationModel page transition

The page transition in ash::PaginationModel is used to provide
the animation effect on several views in ash, but currently
this is the default gfx::Animation which runs independently from
the compositor.

It would be plausible to run with the compositor by using
AnimationDelegateViews. The use of UnifiedSystemTralModel is
still TODO, so the use of the compositor is still optional.

Bug: 980722
Test: ash_unittests
Change-Id: I34a1cb2f8b179354a99bf5bcaad07249ca252fda
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1692976
Commit-Queue: Jun Mukai <mukai@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#676255}
parent 4c10fa6b
......@@ -681,7 +681,7 @@ class APP_LIST_EXPORT AppsGridView : public views::View,
// This can be NULL. Only grid views inside folders have a folder delegate.
AppsGridViewFolderDelegate* folder_delegate_ = nullptr;
ash::PaginationModel pagination_model_;
ash::PaginationModel pagination_model_{this};
// Must appear after |pagination_model_|.
std::unique_ptr<ash::PaginationController> pagination_controller_;
......
......@@ -308,7 +308,7 @@ class APP_LIST_EXPORT ContentsView : public views::View,
int page_before_assistant_ = 0;
// Manages the pagination for the launcher pages.
ash::PaginationModel pagination_model_;
ash::PaginationModel pagination_model_{this};
// If true, SetActiveState immediately.
bool set_active_state_without_animation_ = false;
......
......@@ -77,7 +77,7 @@ class APP_LIST_EXPORT HorizontalPageContainer
gfx::Vector2d GetOffsetForPageIndex(int index) const;
// Manages the pagination for the horizontal pages.
ash::PaginationModel pagination_model_;
ash::PaginationModel pagination_model_{this};
// Must appear after |pagination_model_|.
std::unique_ptr<ash::PaginationController> pagination_controller_;
......
......@@ -308,6 +308,7 @@ source_set("unit_tests") {
"//testing/gtest",
"//ui/aura:test_support",
"//ui/gfx:test_support",
"//ui/views:test_support",
]
}
......
......@@ -16,8 +16,9 @@ namespace {
constexpr int kPageTransitionDurationDampening = 3;
} // namespace
PaginationModel::PaginationModel()
: total_pages_(-1),
PaginationModel::PaginationModel(views::View* view)
: views::AnimationDelegateViews(view),
total_pages_(-1),
selected_page_(-1),
transition_(-1, 0),
pending_selected_page_(-1),
......
......@@ -12,18 +12,19 @@
#include "base/macros.h"
#include "base/observer_list.h"
#include "base/time/time.h"
#include "ui/gfx/animation/animation_delegate.h"
#include "ui/views/animation/animation_delegate_views.h"
namespace gfx {
class SlideAnimation;
}
namespace ash {
class PaginationModelObserver;
// A simple pagination model that consists of two numbers: the total pages and
// the currently selected page. The model is a single selection model that at
// the most one page can become selected at any time.
class ASH_PUBLIC_EXPORT PaginationModel : public gfx::AnimationDelegate {
class ASH_PUBLIC_EXPORT PaginationModel : public views::AnimationDelegateViews {
public:
// Holds info for transition animation and touch scroll.
struct Transition {
......@@ -45,7 +46,7 @@ class ASH_PUBLIC_EXPORT PaginationModel : public gfx::AnimationDelegate {
double progress;
};
PaginationModel();
explicit PaginationModel(views::View* owner_view);
~PaginationModel() override;
void SetTotalPages(int total_pages);
......
......@@ -11,8 +11,7 @@
#include "base/macros.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/test/scoped_task_environment.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/views/test/widget_test.h"
namespace ash {
namespace test {
......@@ -112,23 +111,26 @@ class TestPaginationModelObserver : public PaginationModelObserver {
DISALLOW_COPY_AND_ASSIGN(TestPaginationModelObserver);
};
class PaginationModelTest : public testing::Test {
class PaginationModelTest : public views::test::WidgetTest {
public:
PaginationModelTest()
: scoped_task_environment_(
base::test::ScopedTaskEnvironment::MainThreadType::UI) {}
~PaginationModelTest() override {}
PaginationModelTest() = default;
~PaginationModelTest() override = default;
// testing::Test overrides:
void SetUp() override {
pagination_.SetTotalPages(5);
pagination_.SetTransitionDurations(1, 1);
observer_.set_model(&pagination_);
pagination_.AddObserver(&observer_);
views::test::WidgetTest::SetUp();
widget_.reset(CreateTopLevelPlatformWidget());
pagination_ = std::make_unique<PaginationModel>(widget_->GetContentsView());
pagination_->SetTotalPages(5);
pagination_->SetTransitionDurations(1, 1);
observer_.set_model(pagination_.get());
pagination_->AddObserver(&observer_);
}
void TearDown() override {
pagination_.RemoveObserver(&observer_);
pagination_->RemoveObserver(&observer_);
observer_.set_model(NULL);
widget_.reset();
views::test::WidgetTest::TearDown();
}
protected:
......@@ -137,27 +139,29 @@ class PaginationModelTest : public testing::Test {
int expected_transition_start,
int expected_transition_end) {
observer_.set_expected_page_selection(0);
pagination_.SelectPage(start_page, false /* animate */);
pagination_->SelectPage(start_page, /*animate=*/false);
observer_.Reset();
observer_.set_expected_page_selection(expected_selection);
observer_.set_expected_transition_start(expected_transition_start);
observer_.set_expected_transition_end(expected_transition_end);
}
PaginationModel pagination_;
PaginationModel* pagination() { return pagination_.get(); }
TestPaginationModelObserver observer_;
private:
base::test::ScopedTaskEnvironment scoped_task_environment_;
WidgetAutoclosePtr widget_;
std::unique_ptr<PaginationModel> pagination_;
DISALLOW_COPY_AND_ASSIGN(PaginationModelTest);
};
TEST_F(PaginationModelTest, SelectPage) {
pagination_.SelectPage(2, false /* animate */);
pagination_.SelectPage(4, false /* animate */);
pagination_.SelectPage(3, false /* animate */);
pagination_.SelectPage(1, false /* animate */);
pagination()->SelectPage(2, /*animate=*/false);
pagination()->SelectPage(4, /*animate=*/false);
pagination()->SelectPage(3, /*animate=*/false);
pagination()->SelectPage(1, /*animate=*/false);
EXPECT_EQ(0, observer_.transition_start_count());
EXPECT_EQ(0, observer_.transition_end_count());
......@@ -165,17 +169,17 @@ TEST_F(PaginationModelTest, SelectPage) {
EXPECT_EQ(std::string("2 4 3 1"), observer_.selected_pages());
// Nothing happens if select the same page.
pagination_.SelectPage(1, false /* animate */);
pagination()->SelectPage(1, /*animate=*/false);
EXPECT_EQ(4, observer_.selection_count());
EXPECT_EQ(std::string("2 4 3 1"), observer_.selected_pages());
}
TEST_F(PaginationModelTest, IsValidPageRelative) {
pagination_.SelectPage(0, false /*animate*/);
ASSERT_FALSE(pagination_.IsValidPageRelative(-1));
ASSERT_FALSE(pagination_.IsValidPageRelative(5));
ASSERT_TRUE(pagination_.IsValidPageRelative(1));
ASSERT_TRUE(pagination_.IsValidPageRelative(4));
pagination()->SelectPage(0, false /*animate*/);
ASSERT_FALSE(pagination()->IsValidPageRelative(-1));
ASSERT_FALSE(pagination()->IsValidPageRelative(5));
ASSERT_TRUE(pagination()->IsValidPageRelative(1));
ASSERT_TRUE(pagination()->IsValidPageRelative(4));
}
TEST_F(PaginationModelTest, SelectPageAnimated) {
......@@ -183,7 +187,7 @@ TEST_F(PaginationModelTest, SelectPageAnimated) {
// One transition.
SetStartPageAndExpects(kStartPage, 1, 0, 0);
pagination_.SelectPage(1, true /* animate */);
pagination()->SelectPage(1, /*animate=*/true);
base::RunLoop().Run();
EXPECT_EQ(1, observer_.transition_start_count());
EXPECT_EQ(1, observer_.transition_end_count());
......@@ -192,8 +196,8 @@ TEST_F(PaginationModelTest, SelectPageAnimated) {
// Two transitions in a row.
SetStartPageAndExpects(kStartPage, 2, 0, 0);
pagination_.SelectPage(1, true /* animate */);
pagination_.SelectPage(3, true /* animate */);
pagination()->SelectPage(1, /*animate=*/true);
pagination()->SelectPage(3, /*animate=*/true);
base::RunLoop().Run();
EXPECT_EQ(2, observer_.transition_start_count());
EXPECT_EQ(2, observer_.transition_end_count());
......@@ -202,8 +206,8 @@ TEST_F(PaginationModelTest, SelectPageAnimated) {
// Transition to same page twice and only one should happen.
SetStartPageAndExpects(kStartPage, 1, 0, 0);
pagination_.SelectPage(1, true /* animate */);
pagination_.SelectPage(1, true /* animate */); // Ignored.
pagination()->SelectPage(1, /*animate=*/true);
pagination()->SelectPage(1, /*animate=*/true); // Ignored.
base::RunLoop().Run();
EXPECT_EQ(1, observer_.transition_start_count());
EXPECT_EQ(1, observer_.transition_end_count());
......@@ -212,10 +216,10 @@ TEST_F(PaginationModelTest, SelectPageAnimated) {
// More than two transitions and only the first and last would happen.
SetStartPageAndExpects(kStartPage, 2, 0, 0);
pagination_.SelectPage(1, true /* animate */);
pagination_.SelectPage(3, true /* animate */); // Ignored
pagination_.SelectPage(4, true /* animate */); // Ignored
pagination_.SelectPage(2, true /* animate */);
pagination()->SelectPage(1, /*animate=*/true);
pagination()->SelectPage(3, /*animate=*/true); // Ignored
pagination()->SelectPage(4, /*animate=*/true); // Ignored
pagination()->SelectPage(2, /*animate=*/true);
base::RunLoop().Run();
EXPECT_EQ(2, observer_.transition_start_count());
EXPECT_EQ(2, observer_.transition_end_count());
......@@ -227,10 +231,10 @@ TEST_F(PaginationModelTest, SelectPageAnimated) {
// one will be reversed by the kStart transition and the second one will be
// finished.
SetStartPageAndExpects(kStartPage, 1, 0, 0);
pagination_.SelectPage(1, true /* animate */);
pagination_.SelectPage(2, true /* animate */); // Ignored
pagination_.SelectPage(kStartPage, true /* animate */);
pagination_.SelectPage(3, true /* animate */);
pagination()->SelectPage(1, /*animate=*/true);
pagination()->SelectPage(2, /*animate=*/true); // Ignored
pagination()->SelectPage(kStartPage, /*animate=*/true);
pagination()->SelectPage(3, /*animate=*/true);
base::RunLoop().Run();
EXPECT_EQ(std::string("3"), observer_.selected_pages());
}
......@@ -240,37 +244,37 @@ TEST_F(PaginationModelTest, SimpleScroll) {
// Scroll to the next page (negative delta) and finish it.
SetStartPageAndExpects(kStartPage, 1, 0, 0);
pagination_.StartScroll();
pagination_.UpdateScroll(-0.1);
EXPECT_EQ(kStartPage + 1, pagination_.transition().target_page);
pagination_.EndScroll(false); // Finish transition
pagination()->StartScroll();
pagination()->UpdateScroll(-0.1);
EXPECT_EQ(kStartPage + 1, pagination()->transition().target_page);
pagination()->EndScroll(false); // Finish transition
base::RunLoop().Run();
EXPECT_EQ(1, observer_.selection_count());
// Scroll to the previous page (positive delta) and finish it.
SetStartPageAndExpects(kStartPage, 1, 0, 0);
pagination_.StartScroll();
pagination_.UpdateScroll(0.1);
EXPECT_EQ(kStartPage - 1, pagination_.transition().target_page);
pagination_.EndScroll(false); // Finish transition
pagination()->StartScroll();
pagination()->UpdateScroll(0.1);
EXPECT_EQ(kStartPage - 1, pagination()->transition().target_page);
pagination()->EndScroll(false); // Finish transition
base::RunLoop().Run();
EXPECT_EQ(1, observer_.selection_count());
// Scroll to the next page (negative delta) and cancel it.
SetStartPageAndExpects(kStartPage, 0, 1, 0);
pagination_.StartScroll();
pagination_.UpdateScroll(-0.1);
EXPECT_EQ(kStartPage + 1, pagination_.transition().target_page);
pagination_.EndScroll(true); // Cancel transition
pagination()->StartScroll();
pagination()->UpdateScroll(-0.1);
EXPECT_EQ(kStartPage + 1, pagination()->transition().target_page);
pagination()->EndScroll(true); // Cancel transition
base::RunLoop().Run();
EXPECT_EQ(0, observer_.selection_count());
// Scroll to the previous page (position delta) and cancel it.
SetStartPageAndExpects(kStartPage, 0, 1, 0);
pagination_.StartScroll();
pagination_.UpdateScroll(0.1);
EXPECT_EQ(kStartPage - 1, pagination_.transition().target_page);
pagination_.EndScroll(true); // Cancel transition
pagination()->StartScroll();
pagination()->UpdateScroll(0.1);
EXPECT_EQ(kStartPage - 1, pagination()->transition().target_page);
pagination()->EndScroll(true); // Cancel transition
base::RunLoop().Run();
EXPECT_EQ(0, observer_.selection_count());
}
......@@ -281,46 +285,46 @@ TEST_F(PaginationModelTest, ScrollWithTransition) {
// Scroll to the next page (negative delta) with a transition in the same
// direction.
SetStartPageAndExpects(kStartPage, 1, 0, 0);
pagination_.SetTransition(PaginationModel::Transition(kStartPage + 1, 0.5));
pagination_.StartScroll();
pagination_.UpdateScroll(-0.1);
EXPECT_EQ(kStartPage + 1, pagination_.transition().target_page);
EXPECT_EQ(0.6, pagination_.transition().progress);
pagination_.EndScroll(false);
pagination()->SetTransition(PaginationModel::Transition(kStartPage + 1, 0.5));
pagination()->StartScroll();
pagination()->UpdateScroll(-0.1);
EXPECT_EQ(kStartPage + 1, pagination()->transition().target_page);
EXPECT_EQ(0.6, pagination()->transition().progress);
pagination()->EndScroll(false);
base::RunLoop().Run();
EXPECT_EQ(1, observer_.selection_count());
// Scroll to the next page (negative delta) with a transition in a different
// direction.
SetStartPageAndExpects(kStartPage, 0, 1, 0);
pagination_.SetTransition(PaginationModel::Transition(kStartPage - 1, 0.5));
pagination_.StartScroll();
pagination_.UpdateScroll(-0.1);
EXPECT_EQ(kStartPage - 1, pagination_.transition().target_page);
EXPECT_EQ(0.4, pagination_.transition().progress);
pagination_.EndScroll(true);
pagination()->SetTransition(PaginationModel::Transition(kStartPage - 1, 0.5));
pagination()->StartScroll();
pagination()->UpdateScroll(-0.1);
EXPECT_EQ(kStartPage - 1, pagination()->transition().target_page);
EXPECT_EQ(0.4, pagination()->transition().progress);
pagination()->EndScroll(true);
// Scroll to the previous page (positive delta) with a transition in the same
// direction.
SetStartPageAndExpects(kStartPage, 1, 0, 0);
pagination_.SetTransition(PaginationModel::Transition(kStartPage - 1, 0.5));
pagination_.StartScroll();
pagination_.UpdateScroll(0.1);
EXPECT_EQ(kStartPage - 1, pagination_.transition().target_page);
EXPECT_EQ(0.6, pagination_.transition().progress);
pagination_.EndScroll(false);
pagination()->SetTransition(PaginationModel::Transition(kStartPage - 1, 0.5));
pagination()->StartScroll();
pagination()->UpdateScroll(0.1);
EXPECT_EQ(kStartPage - 1, pagination()->transition().target_page);
EXPECT_EQ(0.6, pagination()->transition().progress);
pagination()->EndScroll(false);
base::RunLoop().Run();
EXPECT_EQ(1, observer_.selection_count());
// Scroll to the previous page (positive delta) with a transition in a
// different direction.
SetStartPageAndExpects(kStartPage, 0, 1, 0);
pagination_.SetTransition(PaginationModel::Transition(kStartPage + 1, 0.5));
pagination_.StartScroll();
pagination_.UpdateScroll(0.1);
EXPECT_EQ(kStartPage + 1, pagination_.transition().target_page);
EXPECT_EQ(0.4, pagination_.transition().progress);
pagination_.EndScroll(true);
pagination()->SetTransition(PaginationModel::Transition(kStartPage + 1, 0.5));
pagination()->StartScroll();
pagination()->UpdateScroll(0.1);
EXPECT_EQ(kStartPage + 1, pagination()->transition().target_page);
EXPECT_EQ(0.4, pagination()->transition().progress);
pagination()->EndScroll(true);
}
TEST_F(PaginationModelTest, LongScroll) {
......@@ -329,31 +333,31 @@ TEST_F(PaginationModelTest, LongScroll) {
// Scroll to the next page (negative delta) with a transition in the same
// direction. And scroll enough to change page twice.
SetStartPageAndExpects(kStartPage, 2, 0, 0);
pagination_.SetTransition(PaginationModel::Transition(kStartPage + 1, 0.5));
pagination_.StartScroll();
pagination_.UpdateScroll(-0.1);
EXPECT_EQ(kStartPage + 1, pagination_.transition().target_page);
EXPECT_EQ(0.6, pagination_.transition().progress);
pagination_.UpdateScroll(-0.5);
pagination()->SetTransition(PaginationModel::Transition(kStartPage + 1, 0.5));
pagination()->StartScroll();
pagination()->UpdateScroll(-0.1);
EXPECT_EQ(kStartPage + 1, pagination()->transition().target_page);
EXPECT_EQ(0.6, pagination()->transition().progress);
pagination()->UpdateScroll(-0.5);
EXPECT_EQ(1, observer_.selection_count());
pagination_.UpdateScroll(-0.5);
EXPECT_EQ(kStartPage + 2, pagination_.transition().target_page);
pagination_.EndScroll(false);
pagination()->UpdateScroll(-0.5);
EXPECT_EQ(kStartPage + 2, pagination()->transition().target_page);
pagination()->EndScroll(false);
base::RunLoop().Run();
EXPECT_EQ(2, observer_.selection_count());
// Scroll to the next page (negative delta) with a transition in a different
// direction. And scroll enough to revert it and switch page once.
SetStartPageAndExpects(kStartPage, 1, 0, 0);
pagination_.SetTransition(PaginationModel::Transition(kStartPage - 1, 0.5));
pagination_.StartScroll();
pagination_.UpdateScroll(-0.1);
EXPECT_EQ(kStartPage - 1, pagination_.transition().target_page);
EXPECT_EQ(0.4, pagination_.transition().progress);
pagination_.UpdateScroll(-0.5); // This clears the transition.
pagination_.UpdateScroll(-0.5); // This starts a new transition.
EXPECT_EQ(kStartPage + 1, pagination_.transition().target_page);
pagination_.EndScroll(false);
pagination()->SetTransition(PaginationModel::Transition(kStartPage - 1, 0.5));
pagination()->StartScroll();
pagination()->UpdateScroll(-0.1);
EXPECT_EQ(kStartPage - 1, pagination()->transition().target_page);
EXPECT_EQ(0.4, pagination()->transition().progress);
pagination()->UpdateScroll(-0.5); // This clears the transition.
pagination()->UpdateScroll(-0.5); // This starts a new transition.
EXPECT_EQ(kStartPage + 1, pagination()->transition().target_page);
pagination()->EndScroll(false);
base::RunLoop().Run();
EXPECT_EQ(1, observer_.selection_count());
......@@ -361,31 +365,31 @@ TEST_F(PaginationModelTest, LongScroll) {
// Scroll to the previous page (positive delta) with a transition in the same
// direction. And scroll enough to change page twice.
SetStartPageAndExpects(kStartPage, 2, 0, 0);
pagination_.SetTransition(PaginationModel::Transition(kStartPage - 1, 0.5));
pagination_.StartScroll();
pagination_.UpdateScroll(0.1);
EXPECT_EQ(kStartPage - 1, pagination_.transition().target_page);
EXPECT_EQ(0.6, pagination_.transition().progress);
pagination_.UpdateScroll(0.5);
pagination()->SetTransition(PaginationModel::Transition(kStartPage - 1, 0.5));
pagination()->StartScroll();
pagination()->UpdateScroll(0.1);
EXPECT_EQ(kStartPage - 1, pagination()->transition().target_page);
EXPECT_EQ(0.6, pagination()->transition().progress);
pagination()->UpdateScroll(0.5);
EXPECT_EQ(1, observer_.selection_count());
pagination_.UpdateScroll(0.5);
EXPECT_EQ(kStartPage - 2, pagination_.transition().target_page);
pagination_.EndScroll(false);
pagination()->UpdateScroll(0.5);
EXPECT_EQ(kStartPage - 2, pagination()->transition().target_page);
pagination()->EndScroll(false);
base::RunLoop().Run();
EXPECT_EQ(2, observer_.selection_count());
// Scroll to the previous page (positive delta) with a transition in a
// different direction. And scroll enough to revert it and switch page once.
SetStartPageAndExpects(kStartPage, 1, 0, 0);
pagination_.SetTransition(PaginationModel::Transition(kStartPage + 1, 0.5));
pagination_.StartScroll();
pagination_.UpdateScroll(0.1);
EXPECT_EQ(kStartPage + 1, pagination_.transition().target_page);
EXPECT_EQ(0.4, pagination_.transition().progress);
pagination_.UpdateScroll(0.5); // This clears the transition.
pagination_.UpdateScroll(0.5); // This starts a new transition.
EXPECT_EQ(kStartPage - 1, pagination_.transition().target_page);
pagination_.EndScroll(false);
pagination()->SetTransition(PaginationModel::Transition(kStartPage + 1, 0.5));
pagination()->StartScroll();
pagination()->UpdateScroll(0.1);
EXPECT_EQ(kStartPage + 1, pagination()->transition().target_page);
EXPECT_EQ(0.4, pagination()->transition().progress);
pagination()->UpdateScroll(0.5); // This clears the transition.
pagination()->UpdateScroll(0.5); // This starts a new transition.
EXPECT_EQ(kStartPage - 1, pagination()->transition().target_page);
pagination()->EndScroll(false);
base::RunLoop().Run();
EXPECT_EQ(1, observer_.selection_count());
}
......@@ -396,68 +400,68 @@ TEST_F(PaginationModelTest, FireTransitionZero) {
// Scroll to next page then revert the scroll and make sure transition
// progress 0 is fired when previous scroll is cleared.
SetStartPageAndExpects(kStartPage, 0, 0, 0);
pagination_.StartScroll();
pagination_.UpdateScroll(-0.1);
pagination()->StartScroll();
pagination()->UpdateScroll(-0.1);
int target_page = kStartPage + 1;
EXPECT_EQ(target_page, pagination_.transition().target_page);
EXPECT_EQ(target_page, pagination()->transition().target_page);
observer_.set_transition_page(target_page);
pagination_.UpdateScroll(0.2); // This clears the transition.
pagination()->UpdateScroll(0.2); // This clears the transition.
EXPECT_EQ(1, observer_.transition_start_count());
pagination_.EndScroll(true); // Cancel transition.
pagination()->EndScroll(true); // Cancel transition.
// Similar to above but in the other direction.
SetStartPageAndExpects(kStartPage, 0, 0, 0);
pagination_.StartScroll();
pagination_.UpdateScroll(0.1);
pagination()->StartScroll();
pagination()->UpdateScroll(0.1);
target_page = kStartPage - 1;
EXPECT_EQ(target_page, pagination_.transition().target_page);
EXPECT_EQ(target_page, pagination()->transition().target_page);
observer_.set_transition_page(target_page);
pagination_.UpdateScroll(-0.2); // This clears the transition.
pagination()->UpdateScroll(-0.2); // This clears the transition.
EXPECT_EQ(1, observer_.transition_start_count());
pagination_.EndScroll(true); // Cancel transition.
pagination()->EndScroll(true); // Cancel transition.
}
TEST_F(PaginationModelTest, SelectedPageIsLost) {
pagination_.SetTotalPages(2);
pagination()->SetTotalPages(2);
// The selected page is set to 0 once the total number of pages are set.
EXPECT_EQ(0, pagination_.selected_page());
EXPECT_EQ(0, pagination()->selected_page());
pagination_.SelectPage(1, false /* animate */);
EXPECT_EQ(1, pagination_.selected_page());
pagination()->SelectPage(1, /*animate=*/false);
EXPECT_EQ(1, pagination()->selected_page());
// The selected page is unchanged if it's still valid.
pagination_.SetTotalPages(3);
EXPECT_EQ(1, pagination_.selected_page());
pagination_.SetTotalPages(2);
EXPECT_EQ(1, pagination_.selected_page());
pagination()->SetTotalPages(3);
EXPECT_EQ(1, pagination()->selected_page());
pagination()->SetTotalPages(2);
EXPECT_EQ(1, pagination()->selected_page());
// But if the currently selected_page exceeds the total number of pages,
// it automatically switches to the last page.
pagination_.SetTotalPages(1);
EXPECT_EQ(0, pagination_.selected_page());
pagination()->SetTotalPages(1);
EXPECT_EQ(0, pagination()->selected_page());
}
TEST_F(PaginationModelTest, SelectPageRelativeBeginning) {
// Test starts with 5 pages. Select Page 1.
pagination_.SelectPage(1, false);
pagination()->SelectPage(1, false);
pagination_.SelectPageRelative(-1, false);
EXPECT_EQ(0, pagination_.selected_page());
pagination()->SelectPageRelative(-1, false);
EXPECT_EQ(0, pagination()->selected_page());
}
TEST_F(PaginationModelTest, SelectPageRelativeMiddle) {
// Test starts with 5 pages. Select page 2.
pagination_.SelectPage(2, false);
pagination()->SelectPage(2, false);
pagination_.SelectPageRelative(-1, false);
EXPECT_EQ(1, pagination_.selected_page());
pagination()->SelectPageRelative(-1, false);
EXPECT_EQ(1, pagination()->selected_page());
pagination_.SelectPageRelative(1, false);
EXPECT_EQ(2, pagination_.selected_page());
pagination()->SelectPageRelative(1, false);
EXPECT_EQ(2, pagination()->selected_page());
}
} // namespace test
......
......@@ -74,7 +74,7 @@ void UnifiedSystemTrayModel::DBusObserver::KeyboardBrightnessChanged(
UnifiedSystemTrayModel::UnifiedSystemTrayModel()
: dbus_observer_(std::make_unique<DBusObserver>(this)),
pagination_model_(std::make_unique<PaginationModel>()) {}
pagination_model_(std::make_unique<PaginationModel>(nullptr)) {}
UnifiedSystemTrayModel::~UnifiedSystemTrayModel() = default;
......
......@@ -12,6 +12,7 @@
namespace views {
AnimationDelegateViews::AnimationDelegateViews(View* view) : view_(view) {
if (view)
scoped_observer_.Add(view);
}
......
......@@ -18,7 +18,7 @@ namespace views {
class View;
// Provides default implementaton to adapt CompositorAnimationRunner for
// Animation.
// Animation. Falls back to the default animation runner when |view| is nullptr.
class VIEWS_EXPORT AnimationDelegateViews
: public gfx::AnimationDelegate,
public ViewObserver,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment