Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(266)

Unified Diff: ash/shelf/shelf_widget_unittest.cc

Issue 2889673002: chromeos: Refactor shelf to create ShelfView earlier in startup (Closed)
Patch Set: rebase Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/shelf/shelf_widget.cc ('k') | ash/shelf/wm_shelf.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/shelf/shelf_widget_unittest.cc
diff --git a/ash/shelf/shelf_widget_unittest.cc b/ash/shelf/shelf_widget_unittest.cc
index 7cdac60ef9c5b6fb1b7dac06c4e311d92a9cf832..13bb5de091cef70a32249947f0a7f72b7b362bca 100644
--- a/ash/shelf/shelf_widget_unittest.cc
+++ b/ash/shelf/shelf_widget_unittest.cc
@@ -15,6 +15,7 @@
#include "ash/test/ash_test_base.h"
#include "ash/test/ash_test_helper.h"
#include "ash/test/shelf_view_test_api.h"
+#include "ash/test/test_shell_delegate.h"
#include "ash/wm/window_util.h"
#include "ash/wm_window.h"
#include "ui/aura/window_event_dispatcher.h"
@@ -24,7 +25,6 @@
#include "ui/views/widget/widget.h"
namespace ash {
-
namespace {
ShelfWidget* GetShelfWidget() {
@@ -35,10 +35,6 @@ ShelfLayoutManager* GetShelfLayoutManager() {
return GetShelfWidget()->shelf_layout_manager();
}
-} // namespace
-
-using ShelfWidgetTest = test::AshTestBase;
-
void TestLauncherAlignment(WmWindow* root,
ShelfAlignment alignment,
const gfx::Rect& expected) {
@@ -47,6 +43,8 @@ void TestLauncherAlignment(WmWindow* root,
root->GetDisplayNearestWindow().work_area().ToString());
}
+using ShelfWidgetTest = test::AshTestBase;
+
TEST_F(ShelfWidgetTest, TestAlignment) {
UpdateDisplay("400x400");
{
@@ -323,95 +321,87 @@ TEST_F(ShelfWidgetTest, HiddenShelfHitTestTouch) {
}
}
-namespace {
-
-// A ShellObserver that sets the shelf alignment and auto hide behavior when the
-// shelf is created, to simulate ChromeLauncherController's behavior.
-class ShelfInitializer : public ShellObserver {
- public:
- ShelfInitializer(ShelfAlignment alignment, ShelfAutoHideBehavior auto_hide)
- : alignment_(alignment), auto_hide_(auto_hide) {
- Shell::Get()->AddShellObserver(this);
- }
- ~ShelfInitializer() override { Shell::Get()->RemoveShellObserver(this); }
-
- // ShellObserver:
- void OnShelfCreatedForRootWindow(WmWindow* root_window) override {
- WmShelf* shelf = root_window->GetRootWindowController()->GetShelf();
- shelf->SetAlignment(alignment_);
- shelf->SetAutoHideBehavior(auto_hide_);
- shelf->UpdateVisibilityState();
- }
-
- private:
- ShelfAlignment alignment_;
- ShelfAutoHideBehavior auto_hide_;
-
- DISALLOW_COPY_AND_ASSIGN(ShelfInitializer);
-};
-
-class ShelfWidgetTestWithInitializer : public ShelfWidgetTest {
+class ShelfWidgetAfterLoginTest : public test::AshTestBase {
public:
- ShelfWidgetTestWithInitializer() { set_start_session(false); }
- ~ShelfWidgetTestWithInitializer() override {}
-
- void TestCreateShelfWithInitialValues(
- ShelfAlignment initial_alignment,
- ShelfAutoHideBehavior initial_auto_hide_behavior,
- ShelfVisibilityState expected_shelf_visibility_state,
- ShelfAutoHideState expected_shelf_auto_hide_state) {
- ShelfInitializer initializer(initial_alignment, initial_auto_hide_behavior);
+ ShelfWidgetAfterLoginTest() { set_start_session(false); }
+ ~ShelfWidgetAfterLoginTest() override = default;
+
+ void TestShelf(ShelfAlignment alignment,
+ ShelfAutoHideBehavior auto_hide_behavior,
+ ShelfVisibilityState expected_shelf_visibility_state,
+ ShelfAutoHideState expected_shelf_auto_hide_state) {
+ // Simulate login.
SetUserLoggedIn(true);
SetSessionStarted(true);
- ShelfWidget* shelf_widget = GetShelfWidget();
- ASSERT_NE(nullptr, shelf_widget);
+ // Simulate shelf settings being applied from profile prefs.
WmShelf* shelf = GetPrimaryShelf();
ASSERT_NE(nullptr, shelf);
- ShelfLayoutManager* shelf_layout_manager =
- shelf_widget->shelf_layout_manager();
- ASSERT_NE(nullptr, shelf_layout_manager);
-
- EXPECT_EQ(initial_alignment, shelf->alignment());
- EXPECT_EQ(initial_auto_hide_behavior, shelf->auto_hide_behavior());
- EXPECT_EQ(expected_shelf_visibility_state,
- shelf_layout_manager->visibility_state());
- EXPECT_EQ(expected_shelf_auto_hide_state,
- shelf_layout_manager->auto_hide_state());
+ shelf->SetAlignment(alignment);
+ shelf->SetAutoHideBehavior(auto_hide_behavior);
+ shelf->UpdateVisibilityState();
+
+ // Ensure settings are applied correctly.
+ EXPECT_EQ(alignment, shelf->alignment());
+ EXPECT_EQ(auto_hide_behavior, shelf->auto_hide_behavior());
+ EXPECT_EQ(expected_shelf_visibility_state, shelf->GetVisibilityState());
+ EXPECT_EQ(expected_shelf_auto_hide_state, shelf->GetAutoHideState());
}
private:
- DISALLOW_COPY_AND_ASSIGN(ShelfWidgetTestWithInitializer);
+ DISALLOW_COPY_AND_ASSIGN(ShelfWidgetAfterLoginTest);
};
-} // namespace
+TEST_F(ShelfWidgetAfterLoginTest, InitialValues) {
msw 2017/05/17 18:19:47 Great test!
+ // Ensure shelf components are created.
+ WmShelf* shelf = GetPrimaryShelf();
+ ASSERT_NE(nullptr, shelf);
+ ShelfWidget* shelf_widget = GetShelfWidget();
+ ASSERT_NE(nullptr, shelf_widget);
+ ASSERT_NE(nullptr, shelf_widget->shelf_view_for_testing());
+ ASSERT_NE(nullptr, shelf_widget->shelf_layout_manager());
-TEST_F(ShelfWidgetTestWithInitializer, CreateAutoHideAlwaysShelf) {
+ // Ensure settings are correct before login.
+ EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
+ EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM_LOCKED, shelf->alignment());
+ EXPECT_EQ(SHELF_AUTO_HIDE_ALWAYS_HIDDEN, shelf->auto_hide_behavior());
+ EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
+
+ // Simulate login.
+ SetUserLoggedIn(true);
+ SetSessionStarted(true);
+
+ // Ensure settings are correct after login.
+ EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
+ EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->alignment());
+ EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
+ // "Hidden" is the default state when auto-hide is turned off.
+ EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
+}
+
+TEST_F(ShelfWidgetAfterLoginTest, CreateAutoHideAlwaysShelf) {
// The actual auto hide state is shown because there are no open windows.
- TestCreateShelfWithInitialValues(SHELF_ALIGNMENT_BOTTOM,
- SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS,
- SHELF_AUTO_HIDE, SHELF_AUTO_HIDE_SHOWN);
+ TestShelf(SHELF_ALIGNMENT_BOTTOM, SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS,
+ SHELF_AUTO_HIDE, SHELF_AUTO_HIDE_SHOWN);
}
-TEST_F(ShelfWidgetTestWithInitializer, CreateAutoHideNeverShelf) {
+TEST_F(ShelfWidgetAfterLoginTest, CreateAutoHideNeverShelf) {
// The auto hide state 'HIDDEN' is returned for any non-auto-hide behavior.
- TestCreateShelfWithInitialValues(SHELF_ALIGNMENT_LEFT,
- SHELF_AUTO_HIDE_BEHAVIOR_NEVER,
- SHELF_VISIBLE, SHELF_AUTO_HIDE_HIDDEN);
+ TestShelf(SHELF_ALIGNMENT_LEFT, SHELF_AUTO_HIDE_BEHAVIOR_NEVER, SHELF_VISIBLE,
+ SHELF_AUTO_HIDE_HIDDEN);
}
-TEST_F(ShelfWidgetTestWithInitializer, CreateAutoHideAlwaysHideShelf) {
+TEST_F(ShelfWidgetAfterLoginTest, CreateAutoHideAlwaysHideShelf) {
// The auto hide state 'HIDDEN' is returned for any non-auto-hide behavior.
- TestCreateShelfWithInitialValues(SHELF_ALIGNMENT_RIGHT,
- SHELF_AUTO_HIDE_ALWAYS_HIDDEN, SHELF_HIDDEN,
- SHELF_AUTO_HIDE_HIDDEN);
+ TestShelf(SHELF_ALIGNMENT_RIGHT, SHELF_AUTO_HIDE_ALWAYS_HIDDEN, SHELF_HIDDEN,
+ SHELF_AUTO_HIDE_HIDDEN);
}
-TEST_F(ShelfWidgetTestWithInitializer, CreateLockedShelf) {
+TEST_F(ShelfWidgetAfterLoginTest, CreateLockedShelf) {
// The auto hide state 'HIDDEN' is returned for any non-auto-hide behavior.
- TestCreateShelfWithInitialValues(SHELF_ALIGNMENT_BOTTOM_LOCKED,
- SHELF_AUTO_HIDE_BEHAVIOR_NEVER,
- SHELF_VISIBLE, SHELF_AUTO_HIDE_HIDDEN);
+ TestShelf(SHELF_ALIGNMENT_BOTTOM_LOCKED, SHELF_AUTO_HIDE_BEHAVIOR_NEVER,
+ SHELF_VISIBLE, SHELF_AUTO_HIDE_HIDDEN);
}
+} // namespace
} // namespace ash
« no previous file with comments | « ash/shelf/shelf_widget.cc ('k') | ash/shelf/wm_shelf.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698