| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/launcher/launcher.h" | 5 #include "ash/launcher/launcher.h" |
| 6 #include "ash/launcher/launcher_button.h" | 6 #include "ash/launcher/launcher_button.h" |
| 7 #include "ash/launcher/launcher_item_delegate_manager.h" |
| 7 #include "ash/launcher/launcher_model.h" | 8 #include "ash/launcher/launcher_model.h" |
| 8 #include "ash/launcher/launcher_view.h" | 9 #include "ash/launcher/launcher_view.h" |
| 9 | |
| 10 #include "ash/shelf/shelf_widget.h" | 10 #include "ash/shelf/shelf_widget.h" |
| 11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 12 #include "ash/test/ash_test_base.h" | 12 #include "ash/test/ash_test_base.h" |
| 13 #include "ash/test/launcher_test_api.h" | 13 #include "ash/test/launcher_test_api.h" |
| 14 #include "ash/test/launcher_view_test_api.h" | 14 #include "ash/test/launcher_view_test_api.h" |
| 15 #include "ash/test/test_launcher_item_delegate.h" |
| 15 #include "ash/wm/window_util.h" | 16 #include "ash/wm/window_util.h" |
| 16 #include "ui/aura/root_window.h" | 17 #include "ui/aura/root_window.h" |
| 17 #include "ui/gfx/display.h" | 18 #include "ui/gfx/display.h" |
| 18 #include "ui/gfx/screen.h" | 19 #include "ui/gfx/screen.h" |
| 19 #include "ui/views/corewm/corewm_switches.h" | 20 #include "ui/views/corewm/corewm_switches.h" |
| 20 #include "ui/views/view.h" | 21 #include "ui/views/view.h" |
| 21 #include "ui/views/widget/widget.h" | 22 #include "ui/views/widget/widget.h" |
| 22 | 23 |
| 23 #if defined(OS_WIN) | 24 #if defined(OS_WIN) |
| 24 #include "base/win/windows_version.h" | 25 #include "base/win/windows_version.h" |
| 25 #endif | 26 #endif |
| 26 | 27 |
| 27 typedef ash::test::AshTestBase LauncherTest; | 28 typedef ash::test::AshTestBase LauncherTest; |
| 28 using ash::internal::LauncherView; | 29 using ash::internal::LauncherView; |
| 29 using ash::internal::LauncherButton; | 30 using ash::internal::LauncherButton; |
| 30 | 31 |
| 31 namespace ash { | 32 namespace ash { |
| 32 | 33 |
| 33 class LauncherTest : public ash::test::AshTestBase { | 34 class LauncherTest : public ash::test::AshTestBase { |
| 34 public: | 35 public: |
| 35 LauncherTest() : launcher_(NULL), | 36 LauncherTest() : launcher_(NULL), |
| 36 launcher_view_(NULL), | 37 launcher_view_(NULL), |
| 37 launcher_model_(NULL) { | 38 launcher_model_(NULL), |
| 39 item_delegate_manager_(NULL) { |
| 38 } | 40 } |
| 39 | 41 |
| 40 virtual ~LauncherTest() {} | 42 virtual ~LauncherTest() {} |
| 41 | 43 |
| 42 virtual void SetUp() { | 44 virtual void SetUp() { |
| 43 test::AshTestBase::SetUp(); | 45 test::AshTestBase::SetUp(); |
| 44 | 46 |
| 45 launcher_ = Launcher::ForPrimaryDisplay(); | 47 launcher_ = Launcher::ForPrimaryDisplay(); |
| 46 ASSERT_TRUE(launcher_); | 48 ASSERT_TRUE(launcher_); |
| 47 | 49 |
| 48 ash::test::LauncherTestAPI test(launcher_); | 50 ash::test::LauncherTestAPI test(launcher_); |
| 49 launcher_view_ = test.launcher_view(); | 51 launcher_view_ = test.launcher_view(); |
| 50 launcher_model_ = launcher_view_->model(); | 52 launcher_model_ = launcher_view_->model(); |
| 53 item_delegate_manager_ = |
| 54 Shell::GetInstance()->launcher_item_delegate_manager(); |
| 51 | 55 |
| 52 test_.reset(new ash::test::LauncherViewTestAPI(launcher_view_)); | 56 test_.reset(new ash::test::LauncherViewTestAPI(launcher_view_)); |
| 53 } | 57 } |
| 54 | 58 |
| 55 virtual void TearDown() OVERRIDE { | 59 virtual void TearDown() OVERRIDE { |
| 56 test::AshTestBase::TearDown(); | 60 test::AshTestBase::TearDown(); |
| 57 } | 61 } |
| 58 | 62 |
| 59 Launcher* launcher() { | 63 Launcher* launcher() { |
| 60 return launcher_; | 64 return launcher_; |
| 61 } | 65 } |
| 62 | 66 |
| 63 LauncherView* launcher_view() { | 67 LauncherView* launcher_view() { |
| 64 return launcher_view_; | 68 return launcher_view_; |
| 65 } | 69 } |
| 66 | 70 |
| 67 LauncherModel* launcher_model() { | 71 LauncherModel* launcher_model() { |
| 68 return launcher_model_; | 72 return launcher_model_; |
| 69 } | 73 } |
| 70 | 74 |
| 75 LauncherItemDelegateManager* item_manager() { |
| 76 return item_delegate_manager_; |
| 77 } |
| 78 |
| 71 ash::test::LauncherViewTestAPI* test_api() { | 79 ash::test::LauncherViewTestAPI* test_api() { |
| 72 return test_.get(); | 80 return test_.get(); |
| 73 } | 81 } |
| 74 | 82 |
| 75 private: | 83 private: |
| 76 Launcher* launcher_; | 84 Launcher* launcher_; |
| 77 LauncherView* launcher_view_; | 85 LauncherView* launcher_view_; |
| 78 LauncherModel* launcher_model_; | 86 LauncherModel* launcher_model_; |
| 87 LauncherItemDelegateManager* item_delegate_manager_; |
| 79 scoped_ptr<ash::test::LauncherViewTestAPI> test_; | 88 scoped_ptr<ash::test::LauncherViewTestAPI> test_; |
| 80 | 89 |
| 81 DISALLOW_COPY_AND_ASSIGN(LauncherTest); | 90 DISALLOW_COPY_AND_ASSIGN(LauncherTest); |
| 82 }; | 91 }; |
| 83 | 92 |
| 84 // Confirms that LauncherItem reflects the appropriated state. | 93 // Confirms that LauncherItem reflects the appropriated state. |
| 85 TEST_F(LauncherTest, StatusReflection) { | 94 TEST_F(LauncherTest, StatusReflection) { |
| 86 // Initially we have the app list. | 95 // Initially we have the app list. |
| 87 int button_count = test_api()->GetButtonCount(); | 96 int button_count = test_api()->GetButtonCount(); |
| 88 | 97 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 104 // browser test we check this here. | 113 // browser test we check this here. |
| 105 TEST_F(LauncherTest, checkHoverAfterMenu) { | 114 TEST_F(LauncherTest, checkHoverAfterMenu) { |
| 106 // Initially we have the app list. | 115 // Initially we have the app list. |
| 107 int button_count = test_api()->GetButtonCount(); | 116 int button_count = test_api()->GetButtonCount(); |
| 108 | 117 |
| 109 // Add running platform app. | 118 // Add running platform app. |
| 110 LauncherItem item; | 119 LauncherItem item; |
| 111 item.type = TYPE_PLATFORM_APP; | 120 item.type = TYPE_PLATFORM_APP; |
| 112 item.status = STATUS_RUNNING; | 121 item.status = STATUS_RUNNING; |
| 113 int index = launcher_model()->Add(item); | 122 int index = launcher_model()->Add(item); |
| 123 |
| 124 scoped_ptr<LauncherItemDelegate> delegate( |
| 125 new ash::test::TestLauncherItemDelegate(NULL)); |
| 126 item_manager()->SetLauncherItemDelegate(launcher_model()->items()[index].id, |
| 127 delegate.Pass()); |
| 128 |
| 114 ASSERT_EQ(++button_count, test_api()->GetButtonCount()); | 129 ASSERT_EQ(++button_count, test_api()->GetButtonCount()); |
| 115 LauncherButton* button = test_api()->GetButton(index); | 130 LauncherButton* button = test_api()->GetButton(index); |
| 116 button->AddState(LauncherButton::STATE_HOVERED); | 131 button->AddState(LauncherButton::STATE_HOVERED); |
| 117 button->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE); | 132 button->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE); |
| 118 EXPECT_FALSE(button->state() & LauncherButton::STATE_HOVERED); | 133 EXPECT_FALSE(button->state() & LauncherButton::STATE_HOVERED); |
| 119 | 134 |
| 120 // Remove it. | 135 // Remove it. |
| 121 launcher_model()->RemoveItemAt(index); | 136 launcher_model()->RemoveItemAt(index); |
| 122 } | 137 } |
| 123 | 138 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 143 // Removes the first item in main launcher view. | 158 // Removes the first item in main launcher view. |
| 144 launcher_model()->RemoveItemAt( | 159 launcher_model()->RemoveItemAt( |
| 145 launcher_model()->ItemIndexByID(first_item_id)); | 160 launcher_model()->ItemIndexByID(first_item_id)); |
| 146 | 161 |
| 147 // Waits for all transitions to finish and there should be no crash. | 162 // Waits for all transitions to finish and there should be no crash. |
| 148 test_api()->RunMessageLoopUntilAnimationsDone(); | 163 test_api()->RunMessageLoopUntilAnimationsDone(); |
| 149 EXPECT_FALSE(launcher()->IsShowingOverflowBubble()); | 164 EXPECT_FALSE(launcher()->IsShowingOverflowBubble()); |
| 150 } | 165 } |
| 151 | 166 |
| 152 } // namespace ash | 167 } // namespace ash |
| OLD | NEW |