Chromium Code Reviews| 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_model.h" | 7 #include "ash/launcher/launcher_model.h" |
| 8 #include "ash/launcher/launcher_view.h" | 8 #include "ash/launcher/launcher_view.h" |
| 9 | 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_view_test_api.h" | 14 #include "ash/test/launcher_view_test_api.h" |
| 14 #include "ash/wm/window_util.h" | 15 #include "ash/wm/window_util.h" |
| 15 #include "ui/aura/root_window.h" | 16 #include "ui/aura/root_window.h" |
| 16 #include "ui/gfx/display.h" | 17 #include "ui/gfx/display.h" |
| 17 #include "ui/gfx/screen.h" | 18 #include "ui/gfx/screen.h" |
| 18 #include "ui/views/corewm/corewm_switches.h" | 19 #include "ui/views/corewm/corewm_switches.h" |
| 19 #include "ui/views/view.h" | 20 #include "ui/views/view.h" |
| 20 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
| 21 | 22 |
| 22 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
| 23 #include "base/win/windows_version.h" | 24 #include "base/win/windows_version.h" |
| 24 #endif | 25 #endif |
| 25 | 26 |
| 26 typedef ash::test::AshTestBase LauncherTest; | 27 typedef ash::test::AshTestBase LauncherTest; |
| 27 using ash::internal::LauncherView; | 28 using ash::internal::LauncherView; |
| 28 using ash::internal::LauncherButton; | 29 using ash::internal::LauncherButton; |
| 29 | 30 |
| 30 namespace ash { | 31 namespace ash { |
| 31 | 32 |
| 33 class LauncherTest : public ash::test::AshTestBase { | |
| 34 public: | |
| 35 LauncherTest() {} | |
| 36 virtual ~LauncherTest() {} | |
| 37 | |
| 38 virtual void SetUp() { | |
| 39 test::AshTestBase::SetUp(); | |
| 40 | |
| 41 launcher_ = Launcher::ForPrimaryDisplay(); | |
| 42 ASSERT_TRUE(launcher_); | |
| 43 | |
| 44 ash::test::LauncherTestAPI test(launcher_); | |
| 45 launcher_view_ = test.launcher_view(); | |
| 46 launcher_model_ = launcher_view_->model(); | |
| 47 | |
| 48 test_.reset(new ash::test::LauncherViewTestAPI(launcher_view_)); | |
| 49 } | |
| 50 | |
| 51 virtual void TearDown() OVERRIDE { | |
| 52 test::AshTestBase::TearDown(); | |
| 53 } | |
| 54 | |
| 55 Launcher* launcher() { | |
| 56 return launcher_; | |
| 57 } | |
| 58 | |
| 59 LauncherView* launcher_view() { | |
| 60 return launcher_view_; | |
| 61 } | |
| 62 | |
| 63 LauncherModel* launcher_model() { | |
| 64 return launcher_model_; | |
| 65 } | |
| 66 | |
| 67 ash::test::LauncherViewTestAPI* test_api() { | |
| 68 return test_.get(); | |
| 69 } | |
| 70 | |
| 71 private: | |
| 72 Launcher* launcher_; | |
|
sky
2013/09/13 17:12:25
member initialize these to NULL.
simonhong_
2013/09/13 17:21:48
Done.
| |
| 73 LauncherView* launcher_view_; | |
| 74 LauncherModel* launcher_model_; | |
| 75 scoped_ptr<ash::test::LauncherViewTestAPI> test_; | |
| 76 | |
| 77 DISALLOW_COPY_AND_ASSIGN(LauncherTest); | |
| 78 }; | |
| 79 | |
| 32 // Confirms that LauncherItem reflects the appropriated state. | 80 // Confirms that LauncherItem reflects the appropriated state. |
| 33 TEST_F(LauncherTest, StatusReflection) { | 81 TEST_F(LauncherTest, StatusReflection) { |
| 34 Launcher* launcher = Launcher::ForPrimaryDisplay(); | 82 // Initially we have the app list. |
| 35 ASSERT_TRUE(launcher); | 83 int button_count = test_api()->GetButtonCount(); |
| 36 LauncherView* launcher_view = launcher->GetLauncherViewForTest(); | |
| 37 test::LauncherViewTestAPI test(launcher_view); | |
| 38 LauncherModel* model = launcher_view->model(); | |
| 39 | |
| 40 // Initially we have the app list and chrome icon. | |
| 41 int button_count = test.GetButtonCount(); | |
| 42 | 84 |
| 43 // Add running platform app. | 85 // Add running platform app. |
| 44 LauncherItem item; | 86 LauncherItem item; |
| 45 item.type = TYPE_PLATFORM_APP; | 87 item.type = TYPE_PLATFORM_APP; |
| 46 item.status = STATUS_RUNNING; | 88 item.status = STATUS_RUNNING; |
| 47 int index = model->Add(item); | 89 int index = launcher_model()->Add(item); |
| 48 ASSERT_EQ(++button_count, test.GetButtonCount()); | 90 ASSERT_EQ(++button_count, test_api()->GetButtonCount()); |
| 49 LauncherButton* button = test.GetButton(index); | 91 LauncherButton* button = test_api()->GetButton(index); |
| 50 EXPECT_EQ(LauncherButton::STATE_RUNNING, button->state()); | 92 EXPECT_EQ(LauncherButton::STATE_RUNNING, button->state()); |
| 51 | 93 |
| 52 // Remove it. | 94 // Remove it. |
| 53 model->RemoveItemAt(index); | 95 launcher_model()->RemoveItemAt(index); |
| 54 ASSERT_EQ(--button_count, test.GetButtonCount()); | 96 ASSERT_EQ(--button_count, test_api()->GetButtonCount()); |
| 55 } | 97 } |
| 56 | 98 |
| 57 // Confirm that using the menu will clear the hover attribute. To avoid another | 99 // Confirm that using the menu will clear the hover attribute. To avoid another |
| 58 // browser test we check this here. | 100 // browser test we check this here. |
| 59 TEST_F(LauncherTest, checkHoverAfterMenu) { | 101 TEST_F(LauncherTest, checkHoverAfterMenu) { |
| 60 Launcher* launcher = Launcher::ForPrimaryDisplay(); | 102 // Initially we have the app list. |
| 61 ASSERT_TRUE(launcher); | 103 int button_count = test_api()->GetButtonCount(); |
| 62 LauncherView* launcher_view = launcher->GetLauncherViewForTest(); | |
| 63 test::LauncherViewTestAPI test(launcher_view); | |
| 64 LauncherModel* model = launcher_view->model(); | |
| 65 | |
| 66 // Initially we have the app list and chrome icon. | |
| 67 int button_count = test.GetButtonCount(); | |
| 68 | 104 |
| 69 // Add running platform app. | 105 // Add running platform app. |
| 70 LauncherItem item; | 106 LauncherItem item; |
| 71 item.type = TYPE_PLATFORM_APP; | 107 item.type = TYPE_PLATFORM_APP; |
| 72 item.status = STATUS_RUNNING; | 108 item.status = STATUS_RUNNING; |
| 73 int index = model->Add(item); | 109 int index = launcher_model()->Add(item); |
| 74 ASSERT_EQ(++button_count, test.GetButtonCount()); | 110 ASSERT_EQ(++button_count, test_api()->GetButtonCount()); |
| 75 LauncherButton* button = test.GetButton(index); | 111 LauncherButton* button = test_api()->GetButton(index); |
| 76 button->AddState(LauncherButton::STATE_HOVERED); | 112 button->AddState(LauncherButton::STATE_HOVERED); |
| 77 button->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE); | 113 button->ShowContextMenu(gfx::Point(), ui::MENU_SOURCE_MOUSE); |
| 78 EXPECT_FALSE(button->state() & LauncherButton::STATE_HOVERED); | 114 EXPECT_FALSE(button->state() & LauncherButton::STATE_HOVERED); |
| 79 | 115 |
| 80 // Remove it. | 116 // Remove it. |
| 81 model->RemoveItemAt(index); | 117 launcher_model()->RemoveItemAt(index); |
| 82 } | 118 } |
| 83 | 119 |
| 84 TEST_F(LauncherTest, ShowOverflowBubble) { | 120 TEST_F(LauncherTest, ShowOverflowBubble) { |
| 85 Launcher* launcher = Launcher::ForPrimaryDisplay(); | 121 LauncherID first_item_id = launcher_model()->next_id(); |
| 86 ASSERT_TRUE(launcher); | |
| 87 | |
| 88 LauncherView* launcher_view = launcher->GetLauncherViewForTest(); | |
| 89 test::LauncherViewTestAPI test(launcher_view); | |
| 90 | |
| 91 LauncherModel* model = launcher_view->model(); | |
| 92 LauncherID first_item_id = model->next_id(); | |
| 93 | 122 |
| 94 // Add platform app button until overflow. | 123 // Add platform app button until overflow. |
| 95 int items_added = 0; | 124 int items_added = 0; |
| 96 while (!test.IsOverflowButtonVisible()) { | 125 while (!test_api()->IsOverflowButtonVisible()) { |
| 97 LauncherItem item; | 126 LauncherItem item; |
| 98 item.type = TYPE_PLATFORM_APP; | 127 item.type = TYPE_PLATFORM_APP; |
| 99 item.status = STATUS_RUNNING; | 128 item.status = STATUS_RUNNING; |
| 100 model->Add(item); | 129 launcher_model()->Add(item); |
| 101 | 130 |
| 102 ++items_added; | 131 ++items_added; |
| 103 ASSERT_LT(items_added, 10000); | 132 ASSERT_LT(items_added, 10000); |
| 104 } | 133 } |
| 105 | 134 |
| 106 // Shows overflow bubble. | 135 // Shows overflow bubble. |
| 107 test.ShowOverflowBubble(); | 136 test_api()->ShowOverflowBubble(); |
| 108 EXPECT_TRUE(launcher->IsShowingOverflowBubble()); | 137 EXPECT_TRUE(launcher()->IsShowingOverflowBubble()); |
| 109 | 138 |
| 110 // Removes the first item in main launcher view. | 139 // Removes the first item in main launcher view. |
| 111 model->RemoveItemAt(model->ItemIndexByID(first_item_id)); | 140 launcher_model()->RemoveItemAt( |
| 141 launcher_model()->ItemIndexByID(first_item_id)); | |
| 112 | 142 |
| 113 // Waits for all transitions to finish and there should be no crash. | 143 // Waits for all transitions to finish and there should be no crash. |
| 114 test.RunMessageLoopUntilAnimationsDone(); | 144 test_api()->RunMessageLoopUntilAnimationsDone(); |
| 115 EXPECT_FALSE(launcher->IsShowingOverflowBubble()); | 145 EXPECT_FALSE(launcher()->IsShowingOverflowBubble()); |
| 116 } | 146 } |
| 117 | 147 |
| 118 } // namespace ash | 148 } // namespace ash |
| OLD | NEW |