Commit 9138783a authored by Manu Cornet's avatar Manu Cornet Committed by Commit Bot

CrOS Shelf: Refactor some code from shelf tests into a common place

Change-Id: I7c9888e2bbd7e3646273b7b02456bec5cb82ffff
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1803660Reviewed-by: default avatarAndrew Xu <andrewxu@chromium.org>
Commit-Queue: Manu Cornet <manucornet@chromium.org>
Cr-Commit-Position: refs/heads/master@{#696615}
parent 0cb75c2e
......@@ -1779,6 +1779,8 @@ test("ash_unittests") {
"shelf/shelf_controller_unittest.cc",
"shelf/shelf_layout_manager_unittest.cc",
"shelf/shelf_locking_manager_unittest.cc",
"shelf/shelf_test_util.cc",
"shelf/shelf_test_util.h",
"shelf/shelf_tooltip_manager_unittest.cc",
"shelf/shelf_unittest.cc",
"shelf/shelf_view_unittest.cc",
......
......@@ -4,6 +4,7 @@
#include "ash/shelf/scrollable_shelf_view.h"
#include "ash/shelf/shelf_test_util.h"
#include "ash/shelf/shelf_tooltip_manager.h"
#include "ash/shelf/shelf_view_test_api.h"
#include "ash/shelf/shelf_widget.h"
......@@ -40,7 +41,6 @@ class ScrollableShelfViewTest : public AshTestBase {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
chromeos::switches::kShelfScrollable);
AshTestBase::SetUp();
model_ = ShelfModel::Get();
scrollable_shelf_view_ = GetPrimaryShelf()
->shelf_widget()
->hotseat_widget()
......@@ -52,12 +52,8 @@ class ScrollableShelfViewTest : public AshTestBase {
protected:
ShelfID AddAppShortcut() {
ShelfItem item;
item.type = TYPE_PINNED_APP;
item.id = ShelfID(base::NumberToString(id_++));
model_->Add(item);
model_->SetShelfItemDelegate(
item.id, std::make_unique<TestShelfItemDelegate>(item.id));
ShelfItem item = ShelfTestUtil::AddAppShortcut(base::NumberToString(id_++),
TYPE_PINNED_APP);
// Wait for shelf view's bounds animation to end. Otherwise the scrollable
// shelf's bounds are not updated yet.
......@@ -72,7 +68,6 @@ class ScrollableShelfViewTest : public AshTestBase {
AddAppShortcut();
}
ShelfModel* model_ = nullptr;
ScrollableShelfView* scrollable_shelf_view_ = nullptr;
ShelfView* shelf_view_ = nullptr;
std::unique_ptr<ShelfViewTestAPI> test_api_;
......@@ -119,4 +114,4 @@ TEST_F(ScrollableShelfViewTest, NotShowTooltipForHiddenIcons) {
EXPECT_FALSE(tooltip_manager->IsVisible());
}
} // namespace ash
\ No newline at end of file
} // namespace ash
......@@ -36,6 +36,7 @@
#include "ash/shelf/shelf_controller.h"
#include "ash/shelf/shelf_layout_manager_observer.h"
#include "ash/shelf/shelf_navigation_widget.h"
#include "ash/shelf/shelf_test_util.h"
#include "ash/shelf/shelf_view.h"
#include "ash/shelf/shelf_view_test_api.h"
#include "ash/shelf/shelf_widget.h"
......@@ -2900,13 +2901,7 @@ TEST_F(ShelfLayoutManagerTest, ShelfItemRespondToGestureEvent) {
ui::test::EventGenerator* generator = GetEventGenerator();
generator->MoveMouseTo(0, 0);
// Add ShelfItem.
ShelfController* controller = Shell::Get()->shelf_controller();
const std::string app_id("app_id");
ShelfItem item;
item.type = TYPE_APP;
item.id = ShelfID(app_id);
controller->model()->Add(item);
ShelfTestUtil::AddAppShortcut("app_id", TYPE_APP);
// Turn on the auto-hide mode for shelf. Check the initial states.
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
......@@ -3350,13 +3345,7 @@ TEST_F(ShelfLayoutManagerTest, ShelfRemainsCenteredOnSecondDisplay) {
display::Screen::GetScreen()->GetDisplayNearestWindow(root_windows[1]);
EXPECT_NE(display_1, display_2);
// Add an app shortcut.
ShelfController* controller = Shell::Get()->shelf_controller();
const std::string app_id("app_id");
ShelfItem item;
item.type = TYPE_PINNED_APP;
item.id = ShelfID(app_id);
controller->model()->Add(item);
ShelfTestUtil::AddAppShortcut("app_id", TYPE_PINNED_APP);
gfx::Point app_center_1 = shelf_1->GetShelfViewForTesting()
->first_visible_button_for_testing()
->bounds()
......@@ -3385,11 +3374,8 @@ TEST_F(ShelfLayoutManagerTest, ShelfShowsPinnedAppsOnOtherDisplays) {
auto add_app = []() {
ShelfController* controller = Shell::Get()->shelf_controller();
int n_apps = controller->model()->item_count();
const std::string app_id("app_id_" + base::NumberToString(n_apps));
ShelfItem item;
item.type = TYPE_PINNED_APP;
item.id = ShelfID(app_id);
controller->model()->Add(item);
ShelfTestUtil::AddAppShortcut("app_id_" + base::NumberToString(n_apps),
TYPE_PINNED_APP);
};
// Keep this low so that all apps fit at the center of the screen on all
......
// Copyright (c) 2019 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 "ash/shelf/shelf_test_util.h"
#include "ash/shelf/shelf_controller.h"
#include "ash/shell.h"
namespace ash {
// static
ShelfItem ShelfTestUtil::AddAppShortcut(const std::string id,
const ShelfItemType type) {
ShelfController* controller = Shell::Get()->shelf_controller();
ShelfItem item;
item.type = type;
if (type == TYPE_APP)
item.status = STATUS_RUNNING;
item.id = ShelfID(id);
controller->model()->Add(item);
return item;
}
} // namespace ash
// Copyright (c) 2019 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.
#ifndef ASH_SHELF_SHELF_TEST_UTIL_H_
#define ASH_SHELF_SHELF_TEST_UTIL_H_
#include <string>
#include "ash/public/cpp/shelf_item.h"
#include "base/macros.h"
namespace ash {
class ShelfTestUtil {
public:
// Adds an application shortcut to the shelf model, with the given identifier
// and the given shelf item type.
static ShelfItem AddAppShortcut(const std::string id,
const ShelfItemType type);
DISALLOW_COPY_AND_ASSIGN(ShelfTestUtil);
};
} // namespace ash
#endif // ASH_SHELF_SHELF_TEST_UTIL_H_
......@@ -36,6 +36,7 @@
#include "ash/shelf/shelf_focus_cycler.h"
#include "ash/shelf/shelf_navigation_widget.h"
#include "ash/shelf/shelf_observer.h"
#include "ash/shelf/shelf_test_util.h"
#include "ash/shelf/shelf_tooltip_manager.h"
#include "ash/shelf/shelf_view_test_api.h"
#include "ash/shelf/shelf_widget.h"
......@@ -327,13 +328,8 @@ class ShelfViewTest : public AshTestBase {
protected:
// Add shelf items of various types, and optionally wait for animations.
ShelfID AddItem(ShelfItemType type, bool wait_for_animations) {
ShelfItem item;
item.type = type;
if (type == TYPE_APP)
item.status = STATUS_RUNNING;
item.id = ShelfID(base::NumberToString(id_++));
model_->Add(item);
ShelfItem item =
ShelfTestUtil::AddAppShortcut(base::NumberToString(id_++), type);
// Set a delegate; some tests require one to select the item.
model_->SetShelfItemDelegate(item.id,
std::make_unique<ShelfItemSelectionTracker>());
......
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