Commit b940f4d7 authored by Andrew Xu's avatar Andrew Xu Committed by Commit Bot

[scrollable shelf] Fix broken tests related with adding shelf items

With the flag of scrollable shelf enabled, when adding a shelf item,
scrollable shelf is notified when the shelf view's bounds animations
end. Tests should wait for bounds animations to finish. Otherwise,
they will fail. This CL fixes such an issue.

Bug: 1002576
Change-Id: Ib2e80916a11a2b90f248886992f7221b1dce6563
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1808189
Commit-Queue: Andrew Xu <andrewxu@chromium.org>
Reviewed-by: default avatarManu Cornet <manucornet@chromium.org>
Reviewed-by: default avatarAlex Newcomer <newcomer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697030}
parent fbcf18bd
...@@ -78,6 +78,9 @@ class AppListAppLaunchedMetricTest : public AshTestBase { ...@@ -78,6 +78,9 @@ class AppListAppLaunchedMetricTest : public AshTestBase {
app_list_test_model_ = static_cast<app_list::test::AppListTestModel*>( app_list_test_model_ = static_cast<app_list::test::AppListTestModel*>(
Shell::Get()->app_list_controller()->GetModel()); Shell::Get()->app_list_controller()->GetModel());
shelf_test_api_ = std::make_unique<ShelfViewTestAPI>(
GetPrimaryShelf()->GetShelfViewForTesting());
} }
void TearDown() override { void TearDown() override {
...@@ -87,11 +90,13 @@ class AppListAppLaunchedMetricTest : public AshTestBase { ...@@ -87,11 +90,13 @@ class AppListAppLaunchedMetricTest : public AshTestBase {
protected: protected:
void CreateAndClickShelfItem() { void CreateAndClickShelfItem() {
// Add shelf item to be launched. // Add shelf item to be launched. Waits for the shelf view's bounds
// animations to end.
ShelfItem shelf_item; ShelfItem shelf_item;
shelf_item.id = ash::ShelfID("app_id"); shelf_item.id = ash::ShelfID("app_id");
shelf_item.type = TYPE_BROWSER_SHORTCUT; shelf_item.type = TYPE_BROWSER_SHORTCUT;
ShelfModel::Get()->Add(shelf_item); ShelfModel::Get()->Add(shelf_item);
shelf_test_api_->RunMessageLoopUntilAnimationsDone();
// The TestShelfItemDelegate will simulate a window activation after the // The TestShelfItemDelegate will simulate a window activation after the
// shelf item is clicked. // shelf item is clicked.
...@@ -103,10 +108,8 @@ class AppListAppLaunchedMetricTest : public AshTestBase { ...@@ -103,10 +108,8 @@ class AppListAppLaunchedMetricTest : public AshTestBase {
void ClickShelfItem() { void ClickShelfItem() {
// Get location of the shelf item. // Get location of the shelf item.
ShelfViewTestAPI shelf_test_api( const views::ViewModel* view_model =
GetPrimaryShelf()->GetShelfViewForTesting()); GetPrimaryShelf()->GetShelfViewForTesting()->view_model_for_test();
ShelfView* shelf_view = shelf_test_api.shelf_view();
const views::ViewModel* view_model = shelf_view->view_model_for_test();
gfx::Point center = view_model->view_at(kBrowserAppIndexOnShelf) gfx::Point center = view_model->view_at(kBrowserAppIndexOnShelf)
->GetBoundsInScreen() ->GetBoundsInScreen()
.CenterPoint(); .CenterPoint();
...@@ -189,6 +192,7 @@ class AppListAppLaunchedMetricTest : public AshTestBase { ...@@ -189,6 +192,7 @@ class AppListAppLaunchedMetricTest : public AshTestBase {
private: private:
app_list::SearchModel* search_model_ = nullptr; app_list::SearchModel* search_model_ = nullptr;
app_list::test::AppListTestModel* app_list_test_model_ = nullptr; app_list::test::AppListTestModel* app_list_test_model_ = nullptr;
std::unique_ptr<ShelfViewTestAPI> shelf_test_api_;
DISALLOW_COPY_AND_ASSIGN(AppListAppLaunchedMetricTest); DISALLOW_COPY_AND_ASSIGN(AppListAppLaunchedMetricTest);
}; };
......
...@@ -2902,6 +2902,8 @@ TEST_F(ShelfLayoutManagerTest, ShelfItemRespondToGestureEvent) { ...@@ -2902,6 +2902,8 @@ TEST_F(ShelfLayoutManagerTest, ShelfItemRespondToGestureEvent) {
generator->MoveMouseTo(0, 0); generator->MoveMouseTo(0, 0);
ShelfTestUtil::AddAppShortcut("app_id", TYPE_APP); ShelfTestUtil::AddAppShortcut("app_id", TYPE_APP);
ShelfViewTestAPI(GetPrimaryShelf()->GetShelfViewForTesting())
.RunMessageLoopUntilAnimationsDone();
// Turn on the auto-hide mode for shelf. Check the initial states. // Turn on the auto-hide mode for shelf. Check the initial states.
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
...@@ -3346,6 +3348,8 @@ TEST_F(ShelfLayoutManagerTest, ShelfRemainsCenteredOnSecondDisplay) { ...@@ -3346,6 +3348,8 @@ TEST_F(ShelfLayoutManagerTest, ShelfRemainsCenteredOnSecondDisplay) {
EXPECT_NE(display_1, display_2); EXPECT_NE(display_1, display_2);
ShelfTestUtil::AddAppShortcut("app_id", TYPE_PINNED_APP); ShelfTestUtil::AddAppShortcut("app_id", TYPE_PINNED_APP);
ShelfViewTestAPI(GetPrimaryShelf()->GetShelfViewForTesting())
.RunMessageLoopUntilAnimationsDone();
gfx::Point app_center_1 = shelf_1->GetShelfViewForTesting() gfx::Point app_center_1 = shelf_1->GetShelfViewForTesting()
->first_visible_button_for_testing() ->first_visible_button_for_testing()
->bounds() ->bounds()
......
...@@ -31,9 +31,10 @@ class ShelfTooltipManagerTest : public AshTestBase { ...@@ -31,9 +31,10 @@ class ShelfTooltipManagerTest : public AshTestBase {
void SetUp() override { void SetUp() override {
AshTestBase::SetUp(); AshTestBase::SetUp();
shelf_view_ = GetPrimaryShelf()->GetShelfViewForTesting(); shelf_view_ = GetPrimaryShelf()->GetShelfViewForTesting();
ShelfViewTestAPI test_api(shelf_view_); test_api_ = std::make_unique<ShelfViewTestAPI>(shelf_view_);
test_api.AddItem(TYPE_PINNED_APP); test_api_->AddItem(TYPE_PINNED_APP);
tooltip_manager_ = test_api.tooltip_manager(); test_api_->RunMessageLoopUntilAnimationsDone();
tooltip_manager_ = test_api_->tooltip_manager();
tooltip_manager_->set_timer_delay_for_test(0); tooltip_manager_->set_timer_delay_for_test(0);
} }
...@@ -49,6 +50,7 @@ class ShelfTooltipManagerTest : public AshTestBase { ...@@ -49,6 +50,7 @@ class ShelfTooltipManagerTest : public AshTestBase {
protected: protected:
ShelfView* shelf_view_; ShelfView* shelf_view_;
ShelfTooltipManager* tooltip_manager_; ShelfTooltipManager* tooltip_manager_;
std::unique_ptr<ShelfViewTestAPI> test_api_;
private: private:
DISALLOW_COPY_AND_ASSIGN(ShelfTooltipManagerTest); DISALLOW_COPY_AND_ASSIGN(ShelfTooltipManagerTest);
...@@ -89,6 +91,8 @@ TEST_F(ShelfTooltipManagerTest, DoNotShowForInvalidView) { ...@@ -89,6 +91,8 @@ TEST_F(ShelfTooltipManagerTest, DoNotShowForInvalidView) {
item.id = ShelfID("foo"); item.id = ShelfID("foo");
item.type = TYPE_PINNED_APP; item.type = TYPE_PINNED_APP;
const int index = model->Add(item); const int index = model->Add(item);
ShelfViewTestAPI(GetPrimaryShelf()->GetShelfViewForTesting())
.RunMessageLoopUntilAnimationsDone();
// Note: There's no easy way to correlate shelf a model index/id to its view. // Note: There's no easy way to correlate shelf a model index/id to its view.
tooltip_manager_->ShowTooltipWithDelay(shelf_view_->children().back()); tooltip_manager_->ShowTooltipWithDelay(shelf_view_->children().back());
EXPECT_TRUE(IsTimerRunning()); EXPECT_TRUE(IsTimerRunning());
......
...@@ -2378,6 +2378,11 @@ TEST_F(ShelfViewTest, ShelfDragViewAndContextMenu) { ...@@ -2378,6 +2378,11 @@ TEST_F(ShelfViewTest, ShelfDragViewAndContextMenu) {
ShelfID shelf_id("123"); ShelfID shelf_id("123");
window->SetProperty(kShelfIDKey, shelf_id.Serialize()); window->SetProperty(kShelfIDKey, shelf_id.Serialize());
window->SetProperty(kShelfItemTypeKey, static_cast<int32_t>(TYPE_DIALOG)); window->SetProperty(kShelfItemTypeKey, static_cast<int32_t>(TYPE_DIALOG));
// Waits for the bounds animation triggered by window property setting to
// finish.
test_api_->RunMessageLoopUntilAnimationsDone();
ShelfAppButton* button = GetButtonByID(shelf_id); ShelfAppButton* button = GetButtonByID(shelf_id);
ASSERT_TRUE(button); ASSERT_TRUE(button);
......
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