Revert "shelf: Users cannot hide shelf by swipe down in tablet mode anymore."

This reverts commit 4d9e568ba40d64bdab2be7c0604cdebfeb6162c2.

Original commit landed in 65 and was then reverted, but revert missed 65.

Reason for revert: <INSERT REASONING HERE>

Original change's description:
> shelf: Users cannot hide shelf by swipe down in tablet mode anymore.
>
> Test: ash_unittests ShelfLayoutManagerTest.SwipingUpOnShelfInTabletModeForFullscreenAppList
> Bug: 801684
> Change-Id: I142180f8204fc413a46381c45267c7be9463c1ef
> Reviewed-on: https://chromium-review.googlesource.com/868453
> Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
> Commit-Queue: Sammie Quon <sammiequon@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#529507}

TBR=xiyuan@chromium.org,sammiequon@chromium.org


(cherry picked from commit 313181911aa1d84f51d3e0cbab325426d0b9ab2b)

Bug: 801684
Change-Id: I5edae712f04a26eea47811e3f2fd69fd0b9c79d9
Reviewed-on: https://chromium-review.googlesource.com/877160
Reviewed-by: Sammie Quon <sammiequon@chromium.org>
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#530701}
Reviewed-on: https://chromium-review.googlesource.com/941735
Cr-Commit-Position: refs/branch-heads/3325@{#629}
Cr-Branched-From: bc084a8b5afa3744a74927344e304c02ae54189f-refs/heads/master@{#530369}
diff --git a/ash/shelf/shelf_layout_manager.cc b/ash/shelf/shelf_layout_manager.cc
index 3d64a13..0090440 100644
--- a/ash/shelf/shelf_layout_manager.cc
+++ b/ash/shelf/shelf_layout_manager.cc
@@ -86,12 +86,6 @@
   return parent && parent->id() == kShellWindowId_AppListContainer;
 }
 
-bool IsTabletModeEnabled() {
-  return Shell::Get()
-      ->tablet_mode_controller()
-      ->IsTabletModeWindowManagerEnabled();
-}
-
 }  // namespace
 
 // ShelfLayoutManager::UpdateShelfObserver -------------------------------------
@@ -1106,14 +1100,10 @@
     launcher_above_shelf_bottom_amount_ =
         shelf_bounds.bottom() - gesture_in_screen.location().y();
   } else {
-    // Only app list drags are allowed in tablet mode.
-    if (IsTabletModeEnabled())
-      return;
-
     // Disable the shelf dragging if the fullscreen app list is opened.
-    if (is_app_list_visible_)
+    if (is_app_list_visible_) {
       return;
-
+    }
     gesture_drag_status_ = GESTURE_DRAG_IN_PROGRESS;
     gesture_drag_auto_hide_state_ = visibility_state() == SHELF_AUTO_HIDE
                                         ? auto_hide_state()
@@ -1141,10 +1131,6 @@
     launcher_above_shelf_bottom_amount_ =
         shelf_bounds.bottom() - gesture_in_screen.location().y();
   } else {
-    // Only app list drags are allowed in tablet mode.
-    if (IsTabletModeEnabled())
-      return;
-
     gesture_drag_amount_ +=
         PrimaryAxisValue(gesture_in_screen.details().scroll_y(),
                          gesture_in_screen.details().scroll_x());
@@ -1154,10 +1140,6 @@
 
 void ShelfLayoutManager::CompleteGestureDrag(
     const ui::GestureEvent& gesture_in_screen) {
-  // Only app list drags are allowed in tablet mode.
-  if (IsTabletModeEnabled())
-    return;
-
   bool should_change = false;
   if (gesture_in_screen.type() == ui::ET_GESTURE_SCROLL_END) {
     // The visibility of the shelf changes only if the shelf was dragged X%
@@ -1230,7 +1212,9 @@
   } else {
     // Snap the app list to corresponding state according to the snapping
     // thresholds.
-    if (IsTabletModeEnabled()) {
+    if (Shell::Get()
+            ->tablet_mode_controller()
+            ->IsTabletModeWindowManagerEnabled()) {
       app_list_state = launcher_above_shelf_bottom_amount_ >
                                kAppListDragSnapToFullscreenThreshold
                            ? AppListState::FULLSCREEN_ALL_APPS
diff --git a/ash/shelf/shelf_layout_manager_unittest.cc b/ash/shelf/shelf_layout_manager_unittest.cc
index d1103680..31dca8c 100644
--- a/ash/shelf/shelf_layout_manager_unittest.cc
+++ b/ash/shelf/shelf_layout_manager_unittest.cc
@@ -1503,6 +1503,9 @@
   EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
   EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
 
+  // Note: A window must be visible in order to hide the shelf.
+  views::Widget* widget = CreateTestWidget();
+
   app_list::test::TestAppListPresenter test_app_list_presenter;
   shell->app_list()->SetAppListPresenter(
       test_app_list_presenter.CreateInterfacePtrAndBind());
@@ -1543,12 +1546,35 @@
   EXPECT_EQ(app_list::mojom::AppListState::CLOSED,
             test_app_list_presenter.app_list_state());
 
-  // Swiping down on the shelf should do nothing in tablet mode.
+  // Swiping down on the shelf should hide it.
   end = start + delta;
   generator.GestureScrollSequence(start, end, kTimeDelta, kNumScrollSteps);
-  EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->alignment());
-  EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
+  EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
+  EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
+  EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
+
+  // Swiping up should show the shelf but not the app list if shelf is hidden.
+  generator.GestureScrollSequence(end, start, kTimeDelta, kNumScrollSteps);
+  RunAllPendingInMessageLoop();
   EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
+  EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
+  EXPECT_EQ(2u, test_app_list_presenter.show_count());
+  EXPECT_GE(test_app_list_presenter.set_y_position_count(), 1u);
+  EXPECT_EQ(app_list::mojom::AppListState::CLOSED,
+            test_app_list_presenter.app_list_state());
+
+  // Swiping down should hide the shelf.
+  generator.GestureScrollSequence(start, end, kTimeDelta, kNumScrollSteps);
+  EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
+  EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
+  EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
+
+  // Minimize the visible window, the shelf should be shown if there are no
+  // visible windows, even in auto-hide mode.
+  widget->Minimize();
+  EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
+  EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
+  EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
 
   // Swiping up on the shelf in this state should open the app list.
   delta.set_y(ShelfLayoutManager::kAppListDragSnapToFullscreenThreshold + 10);