| OLD | NEW | 
|    1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |    1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 
|    2 // Use of this source code is governed by a BSD-style license that can be |    2 // Use of this source code is governed by a BSD-style license that can be | 
|    3 // found in the LICENSE file. |    3 // found in the LICENSE file. | 
|    4  |    4  | 
|    5 #include "ash/shelf/shelf_widget.h" |    5 #include "ash/shelf/shelf_widget.h" | 
|    6  |    6  | 
|    7 #include "ash/root_window_controller.h" |    7 #include "ash/root_window_controller.h" | 
|    8 #include "ash/shelf/shelf.h" |    8 #include "ash/shelf/shelf.h" | 
|    9 #include "ash/shelf/shelf_button.h" |    9 #include "ash/shelf/shelf_delegate.h" | 
|   10 #include "ash/shelf/shelf_layout_manager.h" |   10 #include "ash/shelf/shelf_layout_manager.h" | 
|   11 #include "ash/shelf/shelf_model.h" |  | 
|   12 #include "ash/shelf/shelf_view.h" |   11 #include "ash/shelf/shelf_view.h" | 
|   13 #include "ash/shell.h" |   12 #include "ash/shell.h" | 
|   14 #include "ash/test/ash_test_base.h" |   13 #include "ash/test/ash_test_base.h" | 
|   15 #include "ash/test/ash_test_helper.h" |   14 #include "ash/test/ash_test_helper.h" | 
|   16 #include "ash/test/shelf_test_api.h" |   15 #include "ash/test/shelf_test_api.h" | 
|   17 #include "ash/test/shelf_view_test_api.h" |   16 #include "ash/test/shelf_view_test_api.h" | 
|   18 #include "ash/test/test_shelf_delegate.h" |  | 
|   19 #include "ash/test/test_shell_delegate.h" |   17 #include "ash/test/test_shell_delegate.h" | 
|   20 #include "ash/wm/window_util.h" |   18 #include "ash/wm/window_util.h" | 
|   21 #include "ui/aura/window_event_dispatcher.h" |   19 #include "ui/aura/window_event_dispatcher.h" | 
|   22 #include "ui/events/event_utils.h" |   20 #include "ui/events/event_utils.h" | 
|   23 #include "ui/gfx/display.h" |   21 #include "ui/gfx/display.h" | 
|   24 #include "ui/gfx/screen.h" |   22 #include "ui/gfx/screen.h" | 
|   25 #include "ui/views/view.h" |   23 #include "ui/views/view.h" | 
|   26 #include "ui/views/widget/widget.h" |   24 #include "ui/views/widget/widget.h" | 
|   27  |   25  | 
|   28 namespace ash { |   26 namespace ash { | 
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  312     gfx::Point event_location(20, shelf_bounds.y() - 1); |  310     gfx::Point event_location(20, shelf_bounds.y() - 1); | 
|  313     ui::TouchEvent touch(ui::ET_TOUCH_PRESSED, event_location, 0, |  311     ui::TouchEvent touch(ui::ET_TOUCH_PRESSED, event_location, 0, | 
|  314                          ui::EventTimeForNow()); |  312                          ui::EventTimeForNow()); | 
|  315     EXPECT_EQ(shelf_widget->GetNativeWindow(), |  313     EXPECT_EQ(shelf_widget->GetNativeWindow(), | 
|  316               targeter->FindTargetForEvent(root, &touch)); |  314               targeter->FindTargetForEvent(root, &touch)); | 
|  317   } |  315   } | 
|  318 } |  316 } | 
|  319  |  317  | 
|  320 namespace { |  318 namespace { | 
|  321  |  319  | 
|  322 // A TestShellDelegate that attempts to set an initial shelf auto hide behavior |  320 // A TestShelfDelegate that sets the shelf alignment and auto hide behavior in | 
|  323 // when creating a ShelfDelegate, which simulates ChromeLauncherController's |  321 // OnShelfCreated, to simulate ChromeLauncherController's behavior. | 
|  324 // behavior. |  322 class TestShelfDelegate : public ShelfDelegate { | 
 |  323  public: | 
 |  324   TestShelfDelegate(ShelfAlignment initial_alignment, | 
 |  325                     ShelfAutoHideBehavior initial_auto_hide_behavior) | 
 |  326       : initial_alignment_(initial_alignment), | 
 |  327         initial_auto_hide_behavior_(initial_auto_hide_behavior) {} | 
 |  328   ~TestShelfDelegate() override {} | 
 |  329  | 
 |  330   // ShelfDelegate implementation. | 
 |  331   void OnShelfCreated(Shelf* shelf) override { | 
 |  332     shelf->SetAlignment(initial_alignment_); | 
 |  333     shelf->SetAutoHideBehavior(initial_auto_hide_behavior_); | 
 |  334   } | 
 |  335   void OnShelfDestroyed(Shelf* shelf) override {} | 
 |  336   void OnShelfAlignmentChanged(Shelf* shelf) override {} | 
 |  337   void OnShelfAutoHideBehaviorChanged(Shelf* shelf) override {} | 
 |  338   ShelfID GetShelfIDForAppID(const std::string& app_id) override { return 0; } | 
 |  339   bool HasShelfIDToAppIDMapping(ShelfID id) const override { return false; } | 
 |  340   const std::string& GetAppIDForShelfID(ShelfID id) override { | 
 |  341     return base::EmptyString(); | 
 |  342   } | 
 |  343   void PinAppWithID(const std::string& app_id) override {} | 
 |  344   bool IsAppPinned(const std::string& app_id) override { return false; } | 
 |  345   void UnpinAppWithID(const std::string& app_id) override {} | 
 |  346  | 
 |  347  private: | 
 |  348   ShelfAlignment initial_alignment_; | 
 |  349   ShelfAutoHideBehavior initial_auto_hide_behavior_; | 
 |  350  | 
 |  351   DISALLOW_COPY_AND_ASSIGN(TestShelfDelegate); | 
 |  352 }; | 
 |  353  | 
 |  354 // A TestShellDelegate that creates a TestShelfDelegate with initial values. | 
|  325 class ShelfWidgetTestShellDelegate : public test::TestShellDelegate { |  355 class ShelfWidgetTestShellDelegate : public test::TestShellDelegate { | 
|  326  public: |  356  public: | 
|  327   ShelfWidgetTestShellDelegate() {} |  357   ShelfWidgetTestShellDelegate() {} | 
|  328   ~ShelfWidgetTestShellDelegate() override {} |  358   ~ShelfWidgetTestShellDelegate() override {} | 
|  329  |  359  | 
|  330   // test::TestShellDelegate |  360   // test::TestShellDelegate | 
|  331   ShelfDelegate* CreateShelfDelegate(ShelfModel* model) override { |  361   ShelfDelegate* CreateShelfDelegate(ShelfModel* model) override { | 
|  332     ShelfDelegate* shelf_delegate = new test::TestShelfDelegate(model); |  362     return new TestShelfDelegate(initial_alignment_, | 
|  333     Shell::GetInstance()->SetShelfAutoHideBehavior( |  363                                  initial_auto_hide_behavior_); | 
|  334         initial_auto_hide_behavior_, Shell::GetPrimaryRootWindow()); |  | 
|  335     return shelf_delegate; |  | 
|  336   } |  364   } | 
|  337  |  365  | 
|  338   void set_initial_auto_hide_behavior(ash::ShelfAutoHideBehavior behavior) { |  366   void set_initial_alignment(ShelfAlignment alignment) { | 
 |  367     initial_alignment_ = alignment; | 
 |  368   } | 
 |  369  | 
 |  370   void set_initial_auto_hide_behavior(ShelfAutoHideBehavior behavior) { | 
|  339     initial_auto_hide_behavior_ = behavior; |  371     initial_auto_hide_behavior_ = behavior; | 
|  340   } |  372   } | 
|  341  |  373  | 
|  342  private: |  374  private: | 
|  343   ash::ShelfAutoHideBehavior initial_auto_hide_behavior_ = |  375   ShelfAlignment initial_alignment_ = SHELF_ALIGNMENT_BOTTOM; | 
 |  376   ShelfAutoHideBehavior initial_auto_hide_behavior_ = | 
|  344       SHELF_AUTO_HIDE_BEHAVIOR_NEVER; |  377       SHELF_AUTO_HIDE_BEHAVIOR_NEVER; | 
|  345   DISALLOW_COPY_AND_ASSIGN(ShelfWidgetTestShellDelegate); |  378   DISALLOW_COPY_AND_ASSIGN(ShelfWidgetTestShellDelegate); | 
|  346 }; |  379 }; | 
|  347  |  380  | 
|  348 class ShelfWidgetTestWithDelegate : public ShelfWidgetTest { |  381 class ShelfWidgetTestWithDelegate : public ShelfWidgetTest { | 
|  349  public: |  382  public: | 
|  350   ShelfWidgetTestWithDelegate() { set_start_session(false); } |  383   ShelfWidgetTestWithDelegate() { set_start_session(false); } | 
|  351   ~ShelfWidgetTestWithDelegate() override {} |  384   ~ShelfWidgetTestWithDelegate() override {} | 
|  352  |  385  | 
|  353   // ShelfWidgetTest: |  386   // ShelfWidgetTest: | 
|  354   void SetUp() override { |  387   void SetUp() override { | 
|  355     shelf_widget_test_shell_delegate_ = new ShelfWidgetTestShellDelegate; |  388     shelf_widget_test_shell_delegate_ = new ShelfWidgetTestShellDelegate; | 
|  356     ash_test_helper()->set_test_shell_delegate( |  389     ash_test_helper()->set_test_shell_delegate( | 
|  357         shelf_widget_test_shell_delegate_); |  390         shelf_widget_test_shell_delegate_); | 
|  358     ShelfWidgetTest::SetUp(); |  391     ShelfWidgetTest::SetUp(); | 
|  359   } |  392   } | 
|  360  |  393  | 
|  361   void TestCreateShelfWithInitialAutoHideBehavior( |  394   void TestCreateShelfWithInitialValues( | 
|  362       ash::ShelfAutoHideBehavior initial_auto_hide_behavior, |  395       ShelfAlignment initial_alignment, | 
 |  396       ShelfAutoHideBehavior initial_auto_hide_behavior, | 
|  363       ShelfVisibilityState expected_shelf_visibility_state, |  397       ShelfVisibilityState expected_shelf_visibility_state, | 
|  364       ShelfAutoHideState expected_shelf_auto_hide_state) { |  398       ShelfAutoHideState expected_shelf_auto_hide_state) { | 
 |  399     shelf_widget_test_shell_delegate_->set_initial_alignment(initial_alignment); | 
|  365     shelf_widget_test_shell_delegate_->set_initial_auto_hide_behavior( |  400     shelf_widget_test_shell_delegate_->set_initial_auto_hide_behavior( | 
|  366         initial_auto_hide_behavior); |  401         initial_auto_hide_behavior); | 
|  367     SetUserLoggedIn(true); |  402     SetUserLoggedIn(true); | 
|  368     SetSessionStarted(true); |  403     SetSessionStarted(true); | 
|  369  |  404  | 
|  370     ShelfWidget* shelf_widget = GetShelfWidget(); |  405     ShelfWidget* shelf_widget = GetShelfWidget(); | 
|  371     ASSERT_NE(nullptr, shelf_widget); |  406     ASSERT_NE(nullptr, shelf_widget); | 
|  372     Shelf* shelf = shelf_widget->shelf(); |  407     Shelf* shelf = shelf_widget->shelf(); | 
|  373     ASSERT_NE(nullptr, shelf); |  408     ASSERT_NE(nullptr, shelf); | 
|  374     ShelfLayoutManager* shelf_layout_manager = |  409     ShelfLayoutManager* shelf_layout_manager = | 
|  375         shelf_widget->shelf_layout_manager(); |  410         shelf_widget->shelf_layout_manager(); | 
|  376     ASSERT_NE(nullptr, shelf_layout_manager); |  411     ASSERT_NE(nullptr, shelf_layout_manager); | 
|  377  |  412  | 
 |  413     EXPECT_EQ(initial_alignment, shelf_layout_manager->GetAlignment()); | 
 |  414     EXPECT_EQ(initial_auto_hide_behavior, | 
 |  415               shelf_layout_manager->auto_hide_behavior()); | 
|  378     EXPECT_EQ(expected_shelf_visibility_state, |  416     EXPECT_EQ(expected_shelf_visibility_state, | 
|  379               shelf_layout_manager->visibility_state()); |  417               shelf_layout_manager->visibility_state()); | 
|  380     EXPECT_EQ(expected_shelf_auto_hide_state, |  418     EXPECT_EQ(expected_shelf_auto_hide_state, | 
|  381               shelf_layout_manager->auto_hide_state()); |  419               shelf_layout_manager->auto_hide_state()); | 
|  382   } |  420   } | 
|  383  |  421  | 
|  384  private: |  422  private: | 
|  385   ShelfWidgetTestShellDelegate* shelf_widget_test_shell_delegate_; |  423   ShelfWidgetTestShellDelegate* shelf_widget_test_shell_delegate_; | 
|  386   DISALLOW_COPY_AND_ASSIGN(ShelfWidgetTestWithDelegate); |  424   DISALLOW_COPY_AND_ASSIGN(ShelfWidgetTestWithDelegate); | 
|  387 }; |  425 }; | 
|  388  |  426  | 
|  389 }  // namespace |  427 }  // namespace | 
|  390  |  428  | 
|  391 TEST_F(ShelfWidgetTestWithDelegate, CreateAutoHideAlwaysShelf) { |  429 TEST_F(ShelfWidgetTestWithDelegate, CreateAutoHideAlwaysShelf) { | 
|  392   TestCreateShelfWithInitialAutoHideBehavior( |  430   // The actual auto hide state is shown because there are no open windows. | 
|  393       SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, SHELF_AUTO_HIDE, SHELF_AUTO_HIDE_HIDDEN); |  431   TestCreateShelfWithInitialValues(SHELF_ALIGNMENT_BOTTOM, | 
 |  432                                    SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, | 
 |  433                                    SHELF_AUTO_HIDE, SHELF_AUTO_HIDE_SHOWN); | 
|  394 } |  434 } | 
|  395  |  435  | 
|  396 TEST_F(ShelfWidgetTestWithDelegate, CreateAutoHideNeverShelf) { |  436 TEST_F(ShelfWidgetTestWithDelegate, CreateAutoHideNeverShelf) { | 
|  397   TestCreateShelfWithInitialAutoHideBehavior( |  437   // The auto hide state 'HIDDEN' is returned for any non-auto-hide behavior. | 
|  398       SHELF_AUTO_HIDE_BEHAVIOR_NEVER, SHELF_VISIBLE, SHELF_AUTO_HIDE_HIDDEN); |  438   TestCreateShelfWithInitialValues(SHELF_ALIGNMENT_LEFT, | 
 |  439                                    SHELF_AUTO_HIDE_BEHAVIOR_NEVER, | 
 |  440                                    SHELF_VISIBLE, SHELF_AUTO_HIDE_HIDDEN); | 
|  399 } |  441 } | 
|  400  |  442  | 
|  401 TEST_F(ShelfWidgetTestWithDelegate, CreateAutoHideAlwaysHideShelf) { |  443 TEST_F(ShelfWidgetTestWithDelegate, CreateAutoHideAlwaysHideShelf) { | 
|  402   TestCreateShelfWithInitialAutoHideBehavior( |  444   // The auto hide state 'HIDDEN' is returned for any non-auto-hide behavior. | 
|  403       SHELF_AUTO_HIDE_ALWAYS_HIDDEN, SHELF_HIDDEN, SHELF_AUTO_HIDE_HIDDEN); |  445   TestCreateShelfWithInitialValues(SHELF_ALIGNMENT_RIGHT, | 
 |  446                                    SHELF_AUTO_HIDE_ALWAYS_HIDDEN, SHELF_HIDDEN, | 
 |  447                                    SHELF_AUTO_HIDE_HIDDEN); | 
|  404 } |  448 } | 
|  405  |  449  | 
|  406 }  // namespace ash |  450 }  // namespace ash | 
| OLD | NEW |