Commit 8d1faf1c authored by Manu Cornet's avatar Manu Cornet Committed by Commit Bot

CrOS Shelf: Finish moving hotseat widget tests to their own test class

Split out some helper classes into their own files in the process:
HotseatStateWatcher, OverviewAnimationWaiter,
ShelfLayoutManagerTestBase.

This is a pure (albeit large) refactoring and does not modify any of the
actual test semantics.

Change-Id: Ica79e3dcead839daa83022de329b5aca8f636c40
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2015672
Commit-Queue: Manu Cornet <manucornet@chromium.org>
Reviewed-by: default avatarAlex Newcomer <newcomer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#734615}
parent 783e7037
......@@ -1842,6 +1842,12 @@ test("ash_unittests") {
"shelf/shelf_view_unittest.cc",
"shelf/shelf_widget_unittest.cc",
"shelf/shelf_window_watcher_unittest.cc",
"shelf/test/hotseat_state_watcher.cc",
"shelf/test/hotseat_state_watcher.h",
"shelf/test/overview_animation_waiter.cc",
"shelf/test/overview_animation_waiter.h",
"shelf/test/shelf_layout_manager_test_base.cc",
"shelf/test/shelf_layout_manager_test_base.h",
"shell_state_unittest.cc",
"shell_unittest.cc",
"sticky_keys/sticky_keys_overlay_unittest.cc",
......
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
// Copyright (c) 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/shelf/test/hotseat_state_watcher.h"
namespace ash {
HotseatStateWatcher::HotseatStateWatcher(
ShelfLayoutManager* shelf_layout_manager)
: shelf_layout_manager_(shelf_layout_manager) {
shelf_layout_manager_->AddObserver(this);
}
HotseatStateWatcher::~HotseatStateWatcher() {
shelf_layout_manager_->RemoveObserver(this);
}
void HotseatStateWatcher::OnHotseatStateChanged(HotseatState old_state,
HotseatState new_state) {
run_loop_.QuitWhenIdle();
state_changes_.push_back(new_state);
}
void HotseatStateWatcher::CheckEqual(std::vector<HotseatState> state_changes) {
EXPECT_EQ(state_changes_, state_changes);
}
void HotseatStateWatcher::WaitUntilStateChanged() {
run_loop_.Run();
}
} // namespace ash
// Copyright (c) 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SHELF_TEST_HOTSEAT_STATE_WATCHER_H_
#define ASH_SHELF_TEST_HOTSEAT_STATE_WATCHER_H_
#include "ash/shelf/shelf_layout_manager.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace ash {
// Records HotseatState transitions.
class HotseatStateWatcher : public ShelfLayoutManagerObserver {
public:
explicit HotseatStateWatcher(ShelfLayoutManager* shelf_layout_manager);
~HotseatStateWatcher() override;
void OnHotseatStateChanged(HotseatState old_state,
HotseatState new_state) override;
void CheckEqual(std::vector<HotseatState> state_changes);
void WaitUntilStateChanged();
private:
ShelfLayoutManager* shelf_layout_manager_;
std::vector<HotseatState> state_changes_;
base::RunLoop run_loop_;
};
} // namespace ash
#endif // ASH_SHELF_TEST_HOTSEAT_STATE_WATCHER_H_
// Copyright (c) 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/shelf/test/overview_animation_waiter.h"
#include "ash/wm/overview/overview_controller.h"
namespace ash {
OverviewAnimationWaiter::OverviewAnimationWaiter() {
Shell::Get()->overview_controller()->AddObserver(this);
}
OverviewAnimationWaiter::~OverviewAnimationWaiter() {
Shell::Get()->overview_controller()->RemoveObserver(this);
}
void OverviewAnimationWaiter::Wait() {
run_loop_.Run();
}
void OverviewAnimationWaiter::OnOverviewModeStartingAnimationComplete(
bool cancel) {
run_loop_.Quit();
}
void OverviewAnimationWaiter::OnOverviewModeEndingAnimationComplete(
bool cancel) {
run_loop_.Quit();
}
} // namespace ash
// Copyright (c) 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SHELF_TEST_OVERVIEW_ANIMATION_WAITER_H_
#define ASH_SHELF_TEST_OVERVIEW_ANIMATION_WAITER_H_
#include "ash/shell.h"
#include "ash/wm/overview/overview_observer.h"
#include "base/run_loop.h"
namespace ash {
class OverviewAnimationWaiter : public OverviewObserver {
public:
explicit OverviewAnimationWaiter();
~OverviewAnimationWaiter() override;
// Note this could only be called once because RunLoop would not run after
// Quit is called. Create a new instance if there's need to wait again.
void Wait();
// OverviewObserver:
void OnOverviewModeStartingAnimationComplete(bool cancel) override;
void OnOverviewModeEndingAnimationComplete(bool cancel) override;
private:
base::RunLoop run_loop_;
};
} // namespace ash
#endif // ASH_SHELF_TEST_OVERVIEW_ANIMATION_WAITER_H_
This diff is collapsed.
// Copyright (c) 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SHELF_TEST_SHELF_LAYOUT_MANAGER_TEST_BASE_H_
#define ASH_SHELF_TEST_SHELF_LAYOUT_MANAGER_TEST_BASE_H_
#include "ash/public/cpp/shelf_types.h"
#include "ash/test/ash_test_base.h"
#include "ash/wm/workspace/workspace_types.h"
namespace ui {
class Layer;
}
namespace ash {
class ShelfLayoutManager;
class ShelfLayoutManagerTestBase : public AshTestBase {
public:
ShelfLayoutManagerTestBase() = default;
// Calls the private SetState() function.
void SetState(ShelfLayoutManager* layout_manager, ShelfVisibilityState state);
void UpdateAutoHideStateNow();
aura::Window* CreateTestWindow();
aura::Window* CreateTestWindowInParent(aura::Window* root_window);
// Create a simple widget in the current context (will delete on TearDown).
views::Widget* CreateTestWidget();
void RunGestureDragTests(const gfx::Point& shown, const gfx::Point& hidden);
void TestHomeLauncherGestureHandler(bool autohide_shelf);
gfx::Rect GetVisibleShelfWidgetBoundsInScreen();
// Turn on the lock screen.
void LockScreen();
// Turn off the lock screen.
void UnlockScreen();
int64_t GetPrimaryDisplayId();
void StartScroll(gfx::Point start);
void UpdateScroll(float delta_y);
void EndScroll(bool is_fling, float velocity_y);
void IncreaseTimestamp();
WorkspaceWindowState GetWorkspaceWindowState() const;
const ui::Layer* GetNonLockScreenContainersContainerLayer() const;
// If |layout_manager->auto_hide_timer_| is running, stops it, runs its task,
// and returns true. Otherwise, returns false.
bool TriggerAutoHideTimeout() const;
// Performs a swipe up gesture to show an auto-hidden shelf.
void SwipeUpOnShelf();
void SwipeDownOnShelf();
void FlingUpOnShelf();
void DragHotseatDownToBezel();
// Drag Shelf from |start| to |target| by mouse.
void MouseDragShelfTo(const gfx::Point& start, const gfx::Point& target);
// Move mouse to show Shelf in auto-hide mode.
void MouseMouseToShowAutoHiddenShelf();
// Move mouse to |location| and do a two-finger vertical scroll.
void DoTwoFingerVerticalScrollAtLocation(gfx::Point location, int y_offset);
// Move mouse to |location| and do a mousewheel scroll.
void DoMouseWheelScrollAtLocation(gfx::Point location, int delta_y);
private:
base::TimeTicks timestamp_;
gfx::Point current_point_;
};
} // namespace ash
#endif // ASH_SHELF_TEST_SHELF_LAYOUT_MANAGER_TEST_BASE_H_
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