| 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/shelf/shelf_view.h" | 5 #include "ash/shelf/shelf_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
| 11 #include "ash/launcher/launcher.h" | |
| 12 #include "ash/launcher/launcher_types.h" | 11 #include "ash/launcher/launcher_types.h" |
| 13 #include "ash/root_window_controller.h" | 12 #include "ash/root_window_controller.h" |
| 14 #include "ash/shelf/overflow_bubble.h" | 13 #include "ash/shelf/overflow_bubble.h" |
| 15 #include "ash/shelf/overflow_bubble_view.h" | 14 #include "ash/shelf/overflow_bubble_view.h" |
| 15 #include "ash/shelf/shelf.h" |
| 16 #include "ash/shelf/shelf_button.h" | 16 #include "ash/shelf/shelf_button.h" |
| 17 #include "ash/shelf/shelf_icon_observer.h" | 17 #include "ash/shelf/shelf_icon_observer.h" |
| 18 #include "ash/shelf/shelf_item_delegate_manager.h" | 18 #include "ash/shelf/shelf_item_delegate_manager.h" |
| 19 #include "ash/shelf/shelf_layout_manager.h" | 19 #include "ash/shelf/shelf_layout_manager.h" |
| 20 #include "ash/shelf/shelf_model.h" | 20 #include "ash/shelf/shelf_model.h" |
| 21 #include "ash/shelf/shelf_tooltip_manager.h" | 21 #include "ash/shelf/shelf_tooltip_manager.h" |
| 22 #include "ash/shelf/shelf_widget.h" | 22 #include "ash/shelf/shelf_widget.h" |
| 23 #include "ash/shell.h" | 23 #include "ash/shell.h" |
| 24 #include "ash/shell_window_ids.h" | 24 #include "ash/shell_window_ids.h" |
| 25 #include "ash/test/ash_test_base.h" | 25 #include "ash/test/ash_test_base.h" |
| 26 #include "ash/test/launcher_test_api.h" | |
| 27 #include "ash/test/overflow_bubble_view_test_api.h" | 26 #include "ash/test/overflow_bubble_view_test_api.h" |
| 27 #include "ash/test/shelf_test_api.h" |
| 28 #include "ash/test/shelf_view_test_api.h" | 28 #include "ash/test/shelf_view_test_api.h" |
| 29 #include "ash/test/shell_test_api.h" | 29 #include "ash/test/shell_test_api.h" |
| 30 #include "ash/test/test_shelf_delegate.h" | 30 #include "ash/test/test_shelf_delegate.h" |
| 31 #include "ash/test/test_shelf_item_delegate.h" | 31 #include "ash/test/test_shelf_item_delegate.h" |
| 32 #include "ash/wm/coordinate_conversion.h" | 32 #include "ash/wm/coordinate_conversion.h" |
| 33 #include "base/basictypes.h" | 33 #include "base/basictypes.h" |
| 34 #include "base/command_line.h" | 34 #include "base/command_line.h" |
| 35 #include "base/compiler_specific.h" | 35 #include "base/compiler_specific.h" |
| 36 #include "base/memory/scoped_ptr.h" | 36 #include "base/memory/scoped_ptr.h" |
| 37 #include "base/strings/string_number_conversions.h" | 37 #include "base/strings/string_number_conversions.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 49 #include "ui/views/widget/widget_delegate.h" | 49 #include "ui/views/widget/widget_delegate.h" |
| 50 | 50 |
| 51 namespace ash { | 51 namespace ash { |
| 52 namespace test { | 52 namespace test { |
| 53 | 53 |
| 54 //////////////////////////////////////////////////////////////////////////////// | 54 //////////////////////////////////////////////////////////////////////////////// |
| 55 // ShelfIconObserver tests. | 55 // ShelfIconObserver tests. |
| 56 | 56 |
| 57 class TestShelfIconObserver : public ShelfIconObserver { | 57 class TestShelfIconObserver : public ShelfIconObserver { |
| 58 public: | 58 public: |
| 59 explicit TestShelfIconObserver(Launcher* launcher) | 59 explicit TestShelfIconObserver(Shelf* shelf) |
| 60 : launcher_(launcher), | 60 : shelf_(shelf), |
| 61 change_notified_(false) { | 61 change_notified_(false) { |
| 62 if (launcher_) | 62 if (shelf_) |
| 63 launcher_->AddIconObserver(this); | 63 shelf_->AddIconObserver(this); |
| 64 } | 64 } |
| 65 | 65 |
| 66 virtual ~TestShelfIconObserver() { | 66 virtual ~TestShelfIconObserver() { |
| 67 if (launcher_) | 67 if (shelf_) |
| 68 launcher_->RemoveIconObserver(this); | 68 shelf_->RemoveIconObserver(this); |
| 69 } | 69 } |
| 70 | 70 |
| 71 // ShelfIconObserver implementation. | 71 // ShelfIconObserver implementation. |
| 72 virtual void OnShelfIconPositionsChanged() OVERRIDE { | 72 virtual void OnShelfIconPositionsChanged() OVERRIDE { |
| 73 change_notified_ = true; | 73 change_notified_ = true; |
| 74 } | 74 } |
| 75 | 75 |
| 76 int change_notified() const { return change_notified_; } | 76 int change_notified() const { return change_notified_; } |
| 77 void Reset() { change_notified_ = false; } | 77 void Reset() { change_notified_ = false; } |
| 78 | 78 |
| 79 private: | 79 private: |
| 80 Launcher* launcher_; | 80 Shelf* shelf_; |
| 81 bool change_notified_; | 81 bool change_notified_; |
| 82 | 82 |
| 83 DISALLOW_COPY_AND_ASSIGN(TestShelfIconObserver); | 83 DISALLOW_COPY_AND_ASSIGN(TestShelfIconObserver); |
| 84 }; | 84 }; |
| 85 | 85 |
| 86 class ShelfViewIconObserverTest : public AshTestBase { | 86 class ShelfViewIconObserverTest : public AshTestBase { |
| 87 public: | 87 public: |
| 88 ShelfViewIconObserverTest() {} | 88 ShelfViewIconObserverTest() {} |
| 89 virtual ~ShelfViewIconObserverTest() {} | 89 virtual ~ShelfViewIconObserverTest() {} |
| 90 | 90 |
| 91 virtual void SetUp() OVERRIDE { | 91 virtual void SetUp() OVERRIDE { |
| 92 AshTestBase::SetUp(); | 92 AshTestBase::SetUp(); |
| 93 Launcher* launcher = Launcher::ForPrimaryDisplay(); | 93 Shelf* shelf = Shelf::ForPrimaryDisplay(); |
| 94 observer_.reset(new TestShelfIconObserver(launcher)); | 94 observer_.reset(new TestShelfIconObserver(shelf)); |
| 95 | 95 |
| 96 shelf_view_test_.reset(new ShelfViewTestAPI( | 96 shelf_view_test_.reset( |
| 97 LauncherTestAPI(launcher).shelf_view())); | 97 new ShelfViewTestAPI(ShelfTestAPI(shelf).shelf_view())); |
| 98 shelf_view_test_->SetAnimationDuration(1); | 98 shelf_view_test_->SetAnimationDuration(1); |
| 99 } | 99 } |
| 100 | 100 |
| 101 virtual void TearDown() OVERRIDE { | 101 virtual void TearDown() OVERRIDE { |
| 102 observer_.reset(); | 102 observer_.reset(); |
| 103 AshTestBase::TearDown(); | 103 AshTestBase::TearDown(); |
| 104 } | 104 } |
| 105 | 105 |
| 106 TestShelfIconObserver* observer() { return observer_.get(); } | 106 TestShelfIconObserver* observer() { return observer_.get(); } |
| 107 | 107 |
| 108 ShelfViewTestAPI* shelf_view_test() { | 108 ShelfViewTestAPI* shelf_view_test() { |
| 109 return shelf_view_test_.get(); | 109 return shelf_view_test_.get(); |
| 110 } | 110 } |
| 111 | 111 |
| 112 Launcher* LauncherForSecondaryDisplay() { | 112 Shelf* ShelfForSecondaryDisplay() { |
| 113 return Launcher::ForWindow(Shell::GetAllRootWindows()[1]); | 113 return Shelf::ForWindow(Shell::GetAllRootWindows()[1]); |
| 114 } | 114 } |
| 115 | 115 |
| 116 private: | 116 private: |
| 117 scoped_ptr<TestShelfIconObserver> observer_; | 117 scoped_ptr<TestShelfIconObserver> observer_; |
| 118 scoped_ptr<ShelfViewTestAPI> shelf_view_test_; | 118 scoped_ptr<ShelfViewTestAPI> shelf_view_test_; |
| 119 | 119 |
| 120 DISALLOW_COPY_AND_ASSIGN(ShelfViewIconObserverTest); | 120 DISALLOW_COPY_AND_ASSIGN(ShelfViewIconObserverTest); |
| 121 }; | 121 }; |
| 122 | 122 |
| 123 TEST_F(ShelfViewIconObserverTest, AddRemove) { | 123 TEST_F(ShelfViewIconObserverTest, AddRemove) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 145 | 145 |
| 146 // Sometimes fails on trybots on win7_aura. http://crbug.com/177135 | 146 // Sometimes fails on trybots on win7_aura. http://crbug.com/177135 |
| 147 #if defined(OS_WIN) | 147 #if defined(OS_WIN) |
| 148 #define MAYBE_AddRemoveWithMultipleDisplays \ | 148 #define MAYBE_AddRemoveWithMultipleDisplays \ |
| 149 DISABLED_AddRemoveWithMultipleDisplays | 149 DISABLED_AddRemoveWithMultipleDisplays |
| 150 #else | 150 #else |
| 151 #define MAYBE_AddRemoveWithMultipleDisplays \ | 151 #define MAYBE_AddRemoveWithMultipleDisplays \ |
| 152 AddRemoveWithMultipleDisplays | 152 AddRemoveWithMultipleDisplays |
| 153 #endif | 153 #endif |
| 154 // Make sure creating/deleting an window on one displays notifies a | 154 // Make sure creating/deleting an window on one displays notifies a |
| 155 // launcher on external display as well as one on primary. | 155 // shelf on external display as well as one on primary. |
| 156 TEST_F(ShelfViewIconObserverTest, MAYBE_AddRemoveWithMultipleDisplays) { | 156 TEST_F(ShelfViewIconObserverTest, MAYBE_AddRemoveWithMultipleDisplays) { |
| 157 UpdateDisplay("400x400,400x400"); | 157 UpdateDisplay("400x400,400x400"); |
| 158 TestShelfIconObserver second_observer(LauncherForSecondaryDisplay()); | 158 TestShelfIconObserver second_observer(ShelfForSecondaryDisplay()); |
| 159 | 159 |
| 160 TestShelfDelegate* shelf_delegate = TestShelfDelegate::instance(); | 160 TestShelfDelegate* shelf_delegate = TestShelfDelegate::instance(); |
| 161 ASSERT_TRUE(shelf_delegate); | 161 ASSERT_TRUE(shelf_delegate); |
| 162 | 162 |
| 163 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 163 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
| 164 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 164 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 165 params.bounds = gfx::Rect(0, 0, 200, 200); | 165 params.bounds = gfx::Rect(0, 0, 200, 200); |
| 166 params.context = CurrentContext(); | 166 params.context = CurrentContext(); |
| 167 | 167 |
| 168 scoped_ptr<views::Widget> widget(new views::Widget()); | 168 scoped_ptr<views::Widget> widget(new views::Widget()); |
| 169 widget->Init(params); | 169 widget->Init(params); |
| 170 shelf_delegate->AddLauncherItem(widget->GetNativeWindow()); | 170 shelf_delegate->AddLauncherItem(widget->GetNativeWindow()); |
| 171 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); | 171 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); |
| 172 EXPECT_TRUE(observer()->change_notified()); | 172 EXPECT_TRUE(observer()->change_notified()); |
| 173 EXPECT_TRUE(second_observer.change_notified()); | 173 EXPECT_TRUE(second_observer.change_notified()); |
| 174 observer()->Reset(); | 174 observer()->Reset(); |
| 175 second_observer.Reset(); | 175 second_observer.Reset(); |
| 176 | 176 |
| 177 widget->GetNativeWindow()->parent()->RemoveChild(widget->GetNativeWindow()); | 177 widget->GetNativeWindow()->parent()->RemoveChild(widget->GetNativeWindow()); |
| 178 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); | 178 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); |
| 179 EXPECT_TRUE(observer()->change_notified()); | 179 EXPECT_TRUE(observer()->change_notified()); |
| 180 EXPECT_TRUE(second_observer.change_notified()); | 180 EXPECT_TRUE(second_observer.change_notified()); |
| 181 | 181 |
| 182 observer()->Reset(); | 182 observer()->Reset(); |
| 183 second_observer.Reset(); | 183 second_observer.Reset(); |
| 184 } | 184 } |
| 185 | 185 |
| 186 TEST_F(ShelfViewIconObserverTest, BoundsChanged) { | 186 TEST_F(ShelfViewIconObserverTest, BoundsChanged) { |
| 187 ShelfWidget* shelf = Shell::GetPrimaryRootWindowController()->shelf(); | 187 ShelfWidget* widget = Shell::GetPrimaryRootWindowController()->shelf(); |
| 188 Launcher* launcher = Launcher::ForPrimaryDisplay(); | 188 Shelf* shelf = Shelf::ForPrimaryDisplay(); |
| 189 gfx::Size shelf_size = | 189 gfx::Size shelf_size = widget->GetWindowBoundsInScreen().size(); |
| 190 shelf->GetWindowBoundsInScreen().size(); | |
| 191 shelf_size.set_width(shelf_size.width() / 2); | 190 shelf_size.set_width(shelf_size.width() / 2); |
| 192 ASSERT_GT(shelf_size.width(), 0); | 191 ASSERT_GT(shelf_size.width(), 0); |
| 193 launcher->SetShelfViewBounds(gfx::Rect(shelf_size)); | 192 shelf->SetShelfViewBounds(gfx::Rect(shelf_size)); |
| 194 // No animation happens for ShelfView bounds change. | 193 // No animation happens for ShelfView bounds change. |
| 195 EXPECT_TRUE(observer()->change_notified()); | 194 EXPECT_TRUE(observer()->change_notified()); |
| 196 observer()->Reset(); | 195 observer()->Reset(); |
| 197 } | 196 } |
| 198 | 197 |
| 199 //////////////////////////////////////////////////////////////////////////////// | 198 //////////////////////////////////////////////////////////////////////////////// |
| 200 // ShelfView tests. | 199 // ShelfView tests. |
| 201 | 200 |
| 202 // Simple ShelfDelegate implmentation for ShelfViewTest.OverflowBubbleSize | 201 // Simple ShelfDelegate implmentation for ShelfViewTest.OverflowBubbleSize |
| 203 // and CheckDragAndDropFromOverflowBubbleToShelf | 202 // and CheckDragAndDropFromOverflowBubbleToShelf |
| 204 class TestShelfDelegateForShelfView : public ShelfDelegate { | 203 class TestShelfDelegateForShelfView : public ShelfDelegate { |
| 205 public: | 204 public: |
| 206 explicit TestShelfDelegateForShelfView(ShelfModel* model) | 205 explicit TestShelfDelegateForShelfView(ShelfModel* model) |
| 207 : model_(model) {} | 206 : model_(model) {} |
| 208 virtual ~TestShelfDelegateForShelfView() {} | 207 virtual ~TestShelfDelegateForShelfView() {} |
| 209 | 208 |
| 210 // ShelfDelegate overrides: | 209 // ShelfDelegate overrides: |
| 211 virtual void OnLauncherCreated(Launcher* launcher) OVERRIDE {} | 210 virtual void OnShelfCreated(Shelf* shelf) OVERRIDE {} |
| 212 | 211 |
| 213 virtual void OnLauncherDestroyed(Launcher* launcher) OVERRIDE {} | 212 virtual void OnShelfDestroyed(Shelf* shelf) OVERRIDE {} |
| 214 | 213 |
| 215 virtual LauncherID GetLauncherIDForAppID(const std::string& app_id) OVERRIDE { | 214 virtual LauncherID GetLauncherIDForAppID(const std::string& app_id) OVERRIDE { |
| 216 LauncherID id = 0; | 215 LauncherID id = 0; |
| 217 EXPECT_TRUE(base::StringToInt(app_id, &id)); | 216 EXPECT_TRUE(base::StringToInt(app_id, &id)); |
| 218 return id; | 217 return id; |
| 219 } | 218 } |
| 220 | 219 |
| 221 virtual const std::string& GetAppIDForLauncherID(LauncherID id) OVERRIDE { | 220 virtual const std::string& GetAppIDForLauncherID(LauncherID id) OVERRIDE { |
| 222 // Use |app_id_| member variable because returning a reference to local | 221 // Use |app_id_| member variable because returning a reference to local |
| 223 // variable is not allowed. | 222 // variable is not allowed. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 | 259 |
| 261 class ShelfViewTest : public AshTestBase { | 260 class ShelfViewTest : public AshTestBase { |
| 262 public: | 261 public: |
| 263 ShelfViewTest() : model_(NULL), shelf_view_(NULL), browser_index_(1) {} | 262 ShelfViewTest() : model_(NULL), shelf_view_(NULL), browser_index_(1) {} |
| 264 virtual ~ShelfViewTest() {} | 263 virtual ~ShelfViewTest() {} |
| 265 | 264 |
| 266 virtual void SetUp() OVERRIDE { | 265 virtual void SetUp() OVERRIDE { |
| 267 AshTestBase::SetUp(); | 266 AshTestBase::SetUp(); |
| 268 test::ShellTestApi test_api(Shell::GetInstance()); | 267 test::ShellTestApi test_api(Shell::GetInstance()); |
| 269 model_ = test_api.shelf_model(); | 268 model_ = test_api.shelf_model(); |
| 270 Launcher* launcher = Launcher::ForPrimaryDisplay(); | 269 Shelf* shelf = Shelf::ForPrimaryDisplay(); |
| 271 shelf_view_ = test::LauncherTestAPI(launcher).shelf_view(); | 270 shelf_view_ = ShelfTestAPI(shelf).shelf_view(); |
| 272 | 271 |
| 273 // The bounds should be big enough for 4 buttons + overflow chevron. | 272 // The bounds should be big enough for 4 buttons + overflow chevron. |
| 274 shelf_view_->SetBounds(0, 0, 500, | 273 shelf_view_->SetBounds(0, 0, 500, |
| 275 internal::ShelfLayoutManager::GetPreferredShelfSize()); | 274 internal::ShelfLayoutManager::GetPreferredShelfSize()); |
| 276 | 275 |
| 277 test_api_.reset(new ShelfViewTestAPI(shelf_view_)); | 276 test_api_.reset(new ShelfViewTestAPI(shelf_view_)); |
| 278 test_api_->SetAnimationDuration(1); // Speeds up animation for test. | 277 test_api_->SetAnimationDuration(1); // Speeds up animation for test. |
| 279 | 278 |
| 280 item_manager_ = Shell::GetInstance()->shelf_item_delegate_manager(); | 279 item_manager_ = Shell::GetInstance()->shelf_item_delegate_manager(); |
| 281 DCHECK(item_manager_); | 280 DCHECK(item_manager_); |
| 282 | 281 |
| 283 // Add browser shortcut launcher item at index 0 for test. | 282 // Add browser shortcut shelf item at index 0 for test. |
| 284 AddBrowserShortcut(); | 283 AddBrowserShortcut(); |
| 285 } | 284 } |
| 286 | 285 |
| 287 virtual void TearDown() OVERRIDE { | 286 virtual void TearDown() OVERRIDE { |
| 288 test_api_.reset(); | 287 test_api_.reset(); |
| 289 AshTestBase::TearDown(); | 288 AshTestBase::TearDown(); |
| 290 } | 289 } |
| 291 | 290 |
| 292 protected: | 291 protected: |
| 293 void CreateAndSetShelfItemDelegateForID(LauncherID id) { | 292 void CreateAndSetShelfItemDelegateForID(LauncherID id) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 ++model_index) { | 374 ++model_index) { |
| 376 LauncherItem item = model_->items()[model_index]; | 375 LauncherItem item = model_->items()[model_index]; |
| 377 LauncherID id = item.id; | 376 LauncherID id = item.id; |
| 378 EXPECT_EQ(id_map[map_index].first, id); | 377 EXPECT_EQ(id_map[map_index].first, id); |
| 379 EXPECT_EQ(id_map[map_index].second, GetButtonByID(id)); | 378 EXPECT_EQ(id_map[map_index].second, GetButtonByID(id)); |
| 380 ++map_index; | 379 ++map_index; |
| 381 } | 380 } |
| 382 ASSERT_EQ(map_index, id_map.size()); | 381 ASSERT_EQ(map_index, id_map.size()); |
| 383 } | 382 } |
| 384 | 383 |
| 385 void VerifyLauncherItemBoundsAreValid() { | 384 void VerifyShelfItemBoundsAreValid() { |
| 386 for (int i=0;i <= test_api_->GetLastVisibleIndex(); ++i) { | 385 for (int i=0;i <= test_api_->GetLastVisibleIndex(); ++i) { |
| 387 if (test_api_->GetButton(i)) { | 386 if (test_api_->GetButton(i)) { |
| 388 gfx::Rect shelf_view_bounds = shelf_view_->GetLocalBounds(); | 387 gfx::Rect shelf_view_bounds = shelf_view_->GetLocalBounds(); |
| 389 gfx::Rect item_bounds = test_api_->GetBoundsByIndex(i); | 388 gfx::Rect item_bounds = test_api_->GetBoundsByIndex(i); |
| 390 EXPECT_GE(item_bounds.x(), 0); | 389 EXPECT_GE(item_bounds.x(), 0); |
| 391 EXPECT_GE(item_bounds.y(), 0); | 390 EXPECT_GE(item_bounds.y(), 0); |
| 392 EXPECT_LE(item_bounds.right(), shelf_view_bounds.width()); | 391 EXPECT_LE(item_bounds.right(), shelf_view_bounds.width()); |
| 393 EXPECT_LE(item_bounds.bottom(), shelf_view_bounds.height()); | 392 EXPECT_LE(item_bounds.bottom(), shelf_view_bounds.height()); |
| 394 } | 393 } |
| 395 } | 394 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 views::View* destination = test_api_->GetButton(destination_index); | 426 views::View* destination = test_api_->GetButton(destination_index); |
| 428 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, | 427 ui::MouseEvent drag_event(ui::ET_MOUSE_DRAGGED, |
| 429 destination->bounds().origin(), | 428 destination->bounds().origin(), |
| 430 destination->GetBoundsInScreen().origin(), 0, 0); | 429 destination->GetBoundsInScreen().origin(), 0, 0); |
| 431 button_host->PointerDraggedOnButton(button, pointer, drag_event); | 430 button_host->PointerDraggedOnButton(button, pointer, drag_event); |
| 432 return button; | 431 return button; |
| 433 } | 432 } |
| 434 | 433 |
| 435 void SetupForDragTest( | 434 void SetupForDragTest( |
| 436 std::vector<std::pair<LauncherID, views::View*> >* id_map) { | 435 std::vector<std::pair<LauncherID, views::View*> >* id_map) { |
| 437 // Initialize |id_map| with the automatically-created launcher buttons. | 436 // Initialize |id_map| with the automatically-created shelf buttons. |
| 438 for (size_t i = 0; i < model_->items().size(); ++i) { | 437 for (size_t i = 0; i < model_->items().size(); ++i) { |
| 439 internal::ShelfButton* button = test_api_->GetButton(i); | 438 internal::ShelfButton* button = test_api_->GetButton(i); |
| 440 id_map->push_back(std::make_pair(model_->items()[i].id, button)); | 439 id_map->push_back(std::make_pair(model_->items()[i].id, button)); |
| 441 } | 440 } |
| 442 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(*id_map)); | 441 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(*id_map)); |
| 443 | 442 |
| 444 // Add 5 app launcher buttons for testing. | 443 // Add 5 app shelf buttons for testing. |
| 445 for (int i = 0; i < 5; ++i) { | 444 for (int i = 0; i < 5; ++i) { |
| 446 LauncherID id = AddAppShortcut(); | 445 LauncherID id = AddAppShortcut(); |
| 447 // App Icon is located at index 0, and browser shortcut is located at | 446 // App Icon is located at index 0, and browser shortcut is located at |
| 448 // index 1. So we should start to add app shortcut at index 2. | 447 // index 1. So we should start to add app shortcut at index 2. |
| 449 id_map->insert(id_map->begin() + (i + browser_index_ + 1), | 448 id_map->insert(id_map->begin() + (i + browser_index_ + 1), |
| 450 std::make_pair(id, GetButtonByID(id))); | 449 std::make_pair(id, GetButtonByID(id))); |
| 451 } | 450 } |
| 452 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(*id_map)); | 451 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(*id_map)); |
| 453 } | 452 } |
| 454 | 453 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 DCHECK_GE(index, 0); | 560 DCHECK_GE(index, 0); |
| 562 return model_->items()[index].id; | 561 return model_->items()[index].id; |
| 563 } | 562 } |
| 564 | 563 |
| 565 void ReplaceShelfDelegateForRipOffTest() { | 564 void ReplaceShelfDelegateForRipOffTest() { |
| 566 // Replace ShelfDelegate. | 565 // Replace ShelfDelegate. |
| 567 test::ShellTestApi test_api(Shell::GetInstance()); | 566 test::ShellTestApi test_api(Shell::GetInstance()); |
| 568 test_api.SetShelfDelegate(NULL); | 567 test_api.SetShelfDelegate(NULL); |
| 569 ShelfDelegate* delegate = new TestShelfDelegateForShelfView(model_); | 568 ShelfDelegate* delegate = new TestShelfDelegateForShelfView(model_); |
| 570 test_api.SetShelfDelegate(delegate); | 569 test_api.SetShelfDelegate(delegate); |
| 571 test::LauncherTestAPI( | 570 test::ShelfTestAPI(Shelf::ForPrimaryDisplay()).SetShelfDelegate(delegate); |
| 572 Launcher::ForPrimaryDisplay()).SetShelfDelegate(delegate); | |
| 573 test_api_->SetShelfDelegate(delegate); | 571 test_api_->SetShelfDelegate(delegate); |
| 574 } | 572 } |
| 575 | 573 |
| 576 ShelfModel* model_; | 574 ShelfModel* model_; |
| 577 internal::ShelfView* shelf_view_; | 575 internal::ShelfView* shelf_view_; |
| 578 int browser_index_; | 576 int browser_index_; |
| 579 ShelfItemDelegateManager* item_manager_; | 577 ShelfItemDelegateManager* item_manager_; |
| 580 | 578 |
| 581 scoped_ptr<ShelfViewTestAPI> test_api_; | 579 scoped_ptr<ShelfViewTestAPI> test_api_; |
| 582 | 580 |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 949 // Verifies non-overflow buttons are visible. | 947 // Verifies non-overflow buttons are visible. |
| 950 for (int i = 0; i <= test_api_->GetLastVisibleIndex(); ++i) { | 948 for (int i = 0; i <= test_api_->GetLastVisibleIndex(); ++i) { |
| 951 internal::ShelfButton* button = test_api_->GetButton(i); | 949 internal::ShelfButton* button = test_api_->GetButton(i); |
| 952 if (button) { | 950 if (button) { |
| 953 EXPECT_TRUE(button->visible()) << "button index=" << i; | 951 EXPECT_TRUE(button->visible()) << "button index=" << i; |
| 954 EXPECT_EQ(1.0f, button->layer()->opacity()) << "button index=" << i; | 952 EXPECT_EQ(1.0f, button->layer()->opacity()) << "button index=" << i; |
| 955 } | 953 } |
| 956 } | 954 } |
| 957 } | 955 } |
| 958 | 956 |
| 959 // Check that model changes are handled correctly while a launcher icon is being | 957 // Check that model changes are handled correctly while a shelf icon is being |
| 960 // dragged. | 958 // dragged. |
| 961 TEST_F(ShelfViewTest, ModelChangesWhileDragging) { | 959 TEST_F(ShelfViewTest, ModelChangesWhileDragging) { |
| 962 internal::ShelfButtonHost* button_host = shelf_view_; | 960 internal::ShelfButtonHost* button_host = shelf_view_; |
| 963 | 961 |
| 964 std::vector<std::pair<LauncherID, views::View*> > id_map; | 962 std::vector<std::pair<LauncherID, views::View*> > id_map; |
| 965 SetupForDragTest(&id_map); | 963 SetupForDragTest(&id_map); |
| 966 | 964 |
| 967 // Dragging browser shortcut at index 1. | 965 // Dragging browser shortcut at index 1. |
| 968 EXPECT_TRUE(model_->items()[1].type == TYPE_BROWSER_SHORTCUT); | 966 EXPECT_TRUE(model_->items()[1].type == TYPE_BROWSER_SHORTCUT); |
| 969 views::View* dragged_button = SimulateDrag( | 967 views::View* dragged_button = SimulateDrag( |
| (...skipping 25 matching lines...) Expand all Loading... |
| 995 | 993 |
| 996 // Deleting an item keeps the remaining intact. | 994 // Deleting an item keeps the remaining intact. |
| 997 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 1, 3); | 995 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 1, 3); |
| 998 model_->RemoveItemAt(1); | 996 model_->RemoveItemAt(1); |
| 999 id_map.erase(id_map.begin() + 1); | 997 id_map.erase(id_map.begin() + 1); |
| 1000 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 998 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
| 1001 button_host->PointerReleasedOnButton(dragged_button, | 999 button_host->PointerReleasedOnButton(dragged_button, |
| 1002 internal::ShelfButtonHost::MOUSE, | 1000 internal::ShelfButtonHost::MOUSE, |
| 1003 false); | 1001 false); |
| 1004 | 1002 |
| 1005 // Adding a launcher item cancels the drag and respects the order. | 1003 // Adding a shelf item cancels the drag and respects the order. |
| 1006 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 1, 3); | 1004 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 1, 3); |
| 1007 LauncherID new_id = AddAppShortcut(); | 1005 LauncherID new_id = AddAppShortcut(); |
| 1008 id_map.insert(id_map.begin() + 6, | 1006 id_map.insert(id_map.begin() + 6, |
| 1009 std::make_pair(new_id, GetButtonByID(new_id))); | 1007 std::make_pair(new_id, GetButtonByID(new_id))); |
| 1010 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 1008 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
| 1011 button_host->PointerReleasedOnButton(dragged_button, | 1009 button_host->PointerReleasedOnButton(dragged_button, |
| 1012 internal::ShelfButtonHost::MOUSE, | 1010 internal::ShelfButtonHost::MOUSE, |
| 1013 false); | 1011 false); |
| 1014 | 1012 |
| 1015 // Adding a launcher item at the end (i.e. a panel) canels drag and respects | 1013 // Adding a shelf item at the end (i.e. a panel) canels drag and respects |
| 1016 // the order. | 1014 // the order. |
| 1017 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 1, 3); | 1015 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 1, 3); |
| 1018 new_id = AddPanel(); | 1016 new_id = AddPanel(); |
| 1019 id_map.insert(id_map.begin() + 7, | 1017 id_map.insert(id_map.begin() + 7, |
| 1020 std::make_pair(new_id, GetButtonByID(new_id))); | 1018 std::make_pair(new_id, GetButtonByID(new_id))); |
| 1021 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 1019 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
| 1022 button_host->PointerReleasedOnButton(dragged_button, | 1020 button_host->PointerReleasedOnButton(dragged_button, |
| 1023 internal::ShelfButtonHost::MOUSE, | 1021 internal::ShelfButtonHost::MOUSE, |
| 1024 false); | 1022 false); |
| 1025 } | 1023 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1061 | 1059 |
| 1062 // Deleting an item keeps the remaining intact. | 1060 // Deleting an item keeps the remaining intact. |
| 1063 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 0, 2); | 1061 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 0, 2); |
| 1064 model_->RemoveItemAt(1); | 1062 model_->RemoveItemAt(1); |
| 1065 id_map.erase(id_map.begin() + 1); | 1063 id_map.erase(id_map.begin() + 1); |
| 1066 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 1064 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
| 1067 button_host->PointerReleasedOnButton(dragged_button, | 1065 button_host->PointerReleasedOnButton(dragged_button, |
| 1068 internal::ShelfButtonHost::MOUSE, | 1066 internal::ShelfButtonHost::MOUSE, |
| 1069 false); | 1067 false); |
| 1070 | 1068 |
| 1071 // Adding a launcher item cancels the drag and respects the order. | 1069 // Adding a shelf item cancels the drag and respects the order. |
| 1072 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 0, 2); | 1070 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 0, 2); |
| 1073 LauncherID new_id = AddAppShortcut(); | 1071 LauncherID new_id = AddAppShortcut(); |
| 1074 id_map.insert(id_map.begin() + 5, | 1072 id_map.insert(id_map.begin() + 5, |
| 1075 std::make_pair(new_id, GetButtonByID(new_id))); | 1073 std::make_pair(new_id, GetButtonByID(new_id))); |
| 1076 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 1074 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
| 1077 button_host->PointerReleasedOnButton(dragged_button, | 1075 button_host->PointerReleasedOnButton(dragged_button, |
| 1078 internal::ShelfButtonHost::MOUSE, | 1076 internal::ShelfButtonHost::MOUSE, |
| 1079 false); | 1077 false); |
| 1080 | 1078 |
| 1081 // Adding a launcher item at the end (i.e. a panel) canels drag and respects | 1079 // Adding a shelf item at the end (i.e. a panel) canels drag and respects |
| 1082 // the order. | 1080 // the order. |
| 1083 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 0, 2); | 1081 dragged_button = SimulateDrag(internal::ShelfButtonHost::MOUSE, 0, 2); |
| 1084 new_id = AddPanel(); | 1082 new_id = AddPanel(); |
| 1085 id_map.insert(id_map.begin() + 7, | 1083 id_map.insert(id_map.begin() + 7, |
| 1086 std::make_pair(new_id, GetButtonByID(new_id))); | 1084 std::make_pair(new_id, GetButtonByID(new_id))); |
| 1087 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 1085 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
| 1088 button_host->PointerReleasedOnButton(dragged_button, | 1086 button_host->PointerReleasedOnButton(dragged_button, |
| 1089 internal::ShelfButtonHost::MOUSE, | 1087 internal::ShelfButtonHost::MOUSE, |
| 1090 false); | 1088 false); |
| 1091 } | 1089 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1155 id_map.begin() + 2, | 1153 id_map.begin() + 2, |
| 1156 id_map.begin() + 4); | 1154 id_map.begin() + 4); |
| 1157 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); | 1155 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); |
| 1158 button_host->PointerReleasedOnButton(dragged_button, | 1156 button_host->PointerReleasedOnButton(dragged_button, |
| 1159 internal::ShelfButtonHost::MOUSE, | 1157 internal::ShelfButtonHost::MOUSE, |
| 1160 false); | 1158 false); |
| 1161 EXPECT_TRUE(model_->items()[3].type == TYPE_BROWSER_SHORTCUT); | 1159 EXPECT_TRUE(model_->items()[3].type == TYPE_BROWSER_SHORTCUT); |
| 1162 } | 1160 } |
| 1163 | 1161 |
| 1164 // Confirm that item status changes are reflected in the buttons. | 1162 // Confirm that item status changes are reflected in the buttons. |
| 1165 TEST_F(ShelfViewTest, LauncherItemStatus) { | 1163 TEST_F(ShelfViewTest, ShelfItemStatus) { |
| 1166 // All buttons should be visible. | 1164 // All buttons should be visible. |
| 1167 ASSERT_EQ(test_api_->GetButtonCount(), | 1165 ASSERT_EQ(test_api_->GetButtonCount(), |
| 1168 test_api_->GetLastVisibleIndex() + 1); | 1166 test_api_->GetLastVisibleIndex() + 1); |
| 1169 | 1167 |
| 1170 // Add platform app button. | 1168 // Add platform app button. |
| 1171 LauncherID last_added = AddPlatformApp(); | 1169 LauncherID last_added = AddPlatformApp(); |
| 1172 LauncherItem item = GetItemByID(last_added); | 1170 LauncherItem item = GetItemByID(last_added); |
| 1173 int index = model_->ItemIndexByID(last_added); | 1171 int index = model_->ItemIndexByID(last_added); |
| 1174 internal::ShelfButton* button = GetButtonByID(last_added); | 1172 internal::ShelfButton* button = GetButtonByID(last_added); |
| 1175 ASSERT_EQ(internal::ShelfButton::STATE_RUNNING, button->state()); | 1173 ASSERT_EQ(internal::ShelfButton::STATE_RUNNING, button->state()); |
| 1176 item.status = STATUS_ACTIVE; | 1174 item.status = STATUS_ACTIVE; |
| 1177 model_->Set(index, item); | 1175 model_->Set(index, item); |
| 1178 ASSERT_EQ(internal::ShelfButton::STATE_ACTIVE, button->state()); | 1176 ASSERT_EQ(internal::ShelfButton::STATE_ACTIVE, button->state()); |
| 1179 item.status = STATUS_ATTENTION; | 1177 item.status = STATUS_ATTENTION; |
| 1180 model_->Set(index, item); | 1178 model_->Set(index, item); |
| 1181 ASSERT_EQ(internal::ShelfButton::STATE_ATTENTION, button->state()); | 1179 ASSERT_EQ(internal::ShelfButton::STATE_ATTENTION, button->state()); |
| 1182 } | 1180 } |
| 1183 | 1181 |
| 1184 TEST_F(ShelfViewLegacyShelfLayoutTest, | 1182 TEST_F(ShelfViewLegacyShelfLayoutTest, |
| 1185 LauncherItemPositionReflectedOnStateChanged) { | 1183 ShelfItemPositionReflectedOnStateChanged) { |
| 1186 // All buttons should be visible. | 1184 // All buttons should be visible. |
| 1187 ASSERT_EQ(test_api_->GetButtonCount(), | 1185 ASSERT_EQ(test_api_->GetButtonCount(), |
| 1188 test_api_->GetLastVisibleIndex() + 1); | 1186 test_api_->GetLastVisibleIndex() + 1); |
| 1189 | 1187 |
| 1190 // Add 2 items to the launcher. | 1188 // Add 2 items to the shelf. |
| 1191 LauncherID item1_id = AddPlatformApp(); | 1189 LauncherID item1_id = AddPlatformApp(); |
| 1192 LauncherID item2_id = AddPlatformAppNoWait(); | 1190 LauncherID item2_id = AddPlatformAppNoWait(); |
| 1193 internal::ShelfButton* item1_button = GetButtonByID(item1_id); | 1191 internal::ShelfButton* item1_button = GetButtonByID(item1_id); |
| 1194 internal::ShelfButton* item2_button = GetButtonByID(item2_id); | 1192 internal::ShelfButton* item2_button = GetButtonByID(item2_id); |
| 1195 | 1193 |
| 1196 internal::ShelfButton::State state_mask = | 1194 internal::ShelfButton::State state_mask = |
| 1197 static_cast<internal::ShelfButton::State>( | 1195 static_cast<internal::ShelfButton::State>( |
| 1198 internal::ShelfButton::STATE_NORMAL | | 1196 internal::ShelfButton::STATE_NORMAL | |
| 1199 internal::ShelfButton::STATE_HOVERED | | 1197 internal::ShelfButton::STATE_HOVERED | |
| 1200 internal::ShelfButton::STATE_RUNNING | | 1198 internal::ShelfButton::STATE_RUNNING | |
| 1201 internal::ShelfButton::STATE_ACTIVE | | 1199 internal::ShelfButton::STATE_ACTIVE | |
| 1202 internal::ShelfButton::STATE_ATTENTION | | 1200 internal::ShelfButton::STATE_ATTENTION | |
| 1203 internal::ShelfButton::STATE_FOCUSED); | 1201 internal::ShelfButton::STATE_FOCUSED); |
| 1204 | 1202 |
| 1205 // Clear the button states. | 1203 // Clear the button states. |
| 1206 item1_button->ClearState(state_mask); | 1204 item1_button->ClearState(state_mask); |
| 1207 item2_button->ClearState(state_mask); | 1205 item2_button->ClearState(state_mask); |
| 1208 | 1206 |
| 1209 // Since default alignment in tests is bottom, state is reflected in y-axis. | 1207 // Since default alignment in tests is bottom, state is reflected in y-axis. |
| 1210 ASSERT_EQ(item1_button->GetIconBounds().y(), | 1208 ASSERT_EQ(item1_button->GetIconBounds().y(), |
| 1211 item2_button->GetIconBounds().y()); | 1209 item2_button->GetIconBounds().y()); |
| 1212 item1_button->AddState(internal::ShelfButton::STATE_HOVERED); | 1210 item1_button->AddState(internal::ShelfButton::STATE_HOVERED); |
| 1213 ASSERT_NE(item1_button->GetIconBounds().y(), | 1211 ASSERT_NE(item1_button->GetIconBounds().y(), |
| 1214 item2_button->GetIconBounds().y()); | 1212 item2_button->GetIconBounds().y()); |
| 1215 item1_button->ClearState(internal::ShelfButton::STATE_HOVERED); | 1213 item1_button->ClearState(internal::ShelfButton::STATE_HOVERED); |
| 1216 } | 1214 } |
| 1217 | 1215 |
| 1218 // Confirm that item status changes are reflected in the buttons | 1216 // Confirm that item status changes are reflected in the buttons |
| 1219 // for platform apps. | 1217 // for platform apps. |
| 1220 TEST_F(ShelfViewTest, LauncherItemStatusPlatformApp) { | 1218 TEST_F(ShelfViewTest, ShelfItemStatusPlatformApp) { |
| 1221 // All buttons should be visible. | 1219 // All buttons should be visible. |
| 1222 ASSERT_EQ(test_api_->GetButtonCount(), | 1220 ASSERT_EQ(test_api_->GetButtonCount(), |
| 1223 test_api_->GetLastVisibleIndex() + 1); | 1221 test_api_->GetLastVisibleIndex() + 1); |
| 1224 | 1222 |
| 1225 // Add platform app button. | 1223 // Add platform app button. |
| 1226 LauncherID last_added = AddPlatformApp(); | 1224 LauncherID last_added = AddPlatformApp(); |
| 1227 LauncherItem item = GetItemByID(last_added); | 1225 LauncherItem item = GetItemByID(last_added); |
| 1228 int index = model_->ItemIndexByID(last_added); | 1226 int index = model_->ItemIndexByID(last_added); |
| 1229 internal::ShelfButton* button = GetButtonByID(last_added); | 1227 internal::ShelfButton* button = GetButtonByID(last_added); |
| 1230 ASSERT_EQ(internal::ShelfButton::STATE_RUNNING, button->state()); | 1228 ASSERT_EQ(internal::ShelfButton::STATE_RUNNING, button->state()); |
| 1231 item.status = STATUS_ACTIVE; | 1229 item.status = STATUS_ACTIVE; |
| 1232 model_->Set(index, item); | 1230 model_->Set(index, item); |
| 1233 ASSERT_EQ(internal::ShelfButton::STATE_ACTIVE, button->state()); | 1231 ASSERT_EQ(internal::ShelfButton::STATE_ACTIVE, button->state()); |
| 1234 item.status = STATUS_ATTENTION; | 1232 item.status = STATUS_ATTENTION; |
| 1235 model_->Set(index, item); | 1233 model_->Set(index, item); |
| 1236 ASSERT_EQ(internal::ShelfButton::STATE_ATTENTION, button->state()); | 1234 ASSERT_EQ(internal::ShelfButton::STATE_ATTENTION, button->state()); |
| 1237 } | 1235 } |
| 1238 | 1236 |
| 1239 // Confirm that launcher item bounds are correctly updated on shelf changes. | 1237 // Confirm that shelf item bounds are correctly updated on shelf changes. |
| 1240 TEST_F(ShelfViewTest, LauncherItemBoundsCheck) { | 1238 TEST_F(ShelfViewTest, ShelfItemBoundsCheck) { |
| 1241 VerifyLauncherItemBoundsAreValid(); | 1239 VerifyShelfItemBoundsAreValid(); |
| 1242 shelf_view_->shelf_layout_manager()->SetAutoHideBehavior( | 1240 shelf_view_->shelf_layout_manager()->SetAutoHideBehavior( |
| 1243 SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 1241 SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
| 1244 test_api_->RunMessageLoopUntilAnimationsDone(); | 1242 test_api_->RunMessageLoopUntilAnimationsDone(); |
| 1245 VerifyLauncherItemBoundsAreValid(); | 1243 VerifyShelfItemBoundsAreValid(); |
| 1246 shelf_view_->shelf_layout_manager()->SetAutoHideBehavior( | 1244 shelf_view_->shelf_layout_manager()->SetAutoHideBehavior( |
| 1247 SHELF_AUTO_HIDE_BEHAVIOR_NEVER); | 1245 SHELF_AUTO_HIDE_BEHAVIOR_NEVER); |
| 1248 test_api_->RunMessageLoopUntilAnimationsDone(); | 1246 test_api_->RunMessageLoopUntilAnimationsDone(); |
| 1249 VerifyLauncherItemBoundsAreValid(); | 1247 VerifyShelfItemBoundsAreValid(); |
| 1250 } | 1248 } |
| 1251 | 1249 |
| 1252 TEST_F(ShelfViewTest, ShelfTooltipTest) { | 1250 TEST_F(ShelfViewTest, ShelfTooltipTest) { |
| 1253 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, | 1251 ASSERT_EQ(test_api_->GetLastVisibleIndex() + 1, |
| 1254 test_api_->GetButtonCount()); | 1252 test_api_->GetButtonCount()); |
| 1255 | 1253 |
| 1256 // Prepare some items to the launcher. | 1254 // Prepare some items to the shelf. |
| 1257 LauncherID app_button_id = AddAppShortcut(); | 1255 LauncherID app_button_id = AddAppShortcut(); |
| 1258 LauncherID platform_button_id = AddPlatformApp(); | 1256 LauncherID platform_button_id = AddPlatformApp(); |
| 1259 | 1257 |
| 1260 internal::ShelfButton* app_button = GetButtonByID(app_button_id); | 1258 internal::ShelfButton* app_button = GetButtonByID(app_button_id); |
| 1261 internal::ShelfButton* platform_button = GetButtonByID(platform_button_id); | 1259 internal::ShelfButton* platform_button = GetButtonByID(platform_button_id); |
| 1262 | 1260 |
| 1263 internal::ShelfButtonHost* button_host = shelf_view_; | 1261 internal::ShelfButtonHost* button_host = shelf_view_; |
| 1264 internal::ShelfTooltipManager* tooltip_manager = | 1262 internal::ShelfTooltipManager* tooltip_manager = |
| 1265 shelf_view_->tooltip_manager(); | 1263 shelf_view_->tooltip_manager(); |
| 1266 | 1264 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1288 tooltip_manager->Close(); | 1286 tooltip_manager->Close(); |
| 1289 | 1287 |
| 1290 // Next time: enter app_button -> move immediately to tab_button. | 1288 // Next time: enter app_button -> move immediately to tab_button. |
| 1291 button_host->MouseEnteredButton(app_button); | 1289 button_host->MouseEnteredButton(app_button); |
| 1292 button_host->MouseExitedButton(app_button); | 1290 button_host->MouseExitedButton(app_button); |
| 1293 button_host->MouseEnteredButton(platform_button); | 1291 button_host->MouseEnteredButton(platform_button); |
| 1294 EXPECT_FALSE(tooltip_manager->IsVisible()); | 1292 EXPECT_FALSE(tooltip_manager->IsVisible()); |
| 1295 EXPECT_EQ(platform_button, GetTooltipAnchorView()); | 1293 EXPECT_EQ(platform_button, GetTooltipAnchorView()); |
| 1296 } | 1294 } |
| 1297 | 1295 |
| 1298 // Verify a fix for crash caused by a tooltip update for a deleted launcher | 1296 // Verify a fix for crash caused by a tooltip update for a deletedshelf |
| 1299 // button, see crbug.com/288838. | 1297 // button, see crbug.com/288838. |
| 1300 TEST_F(ShelfViewTest, RemovingItemClosesTooltip) { | 1298 TEST_F(ShelfViewTest, RemovingItemClosesTooltip) { |
| 1301 internal::ShelfButtonHost* button_host = shelf_view_; | 1299 internal::ShelfButtonHost* button_host = shelf_view_; |
| 1302 internal::ShelfTooltipManager* tooltip_manager = | 1300 internal::ShelfTooltipManager* tooltip_manager = |
| 1303 shelf_view_->tooltip_manager(); | 1301 shelf_view_->tooltip_manager(); |
| 1304 | 1302 |
| 1305 // Add an item to the launcher. | 1303 // Add an item to the shelf. |
| 1306 LauncherID app_button_id = AddAppShortcut(); | 1304 LauncherID app_button_id = AddAppShortcut(); |
| 1307 internal::ShelfButton* app_button = GetButtonByID(app_button_id); | 1305 internal::ShelfButton* app_button = GetButtonByID(app_button_id); |
| 1308 | 1306 |
| 1309 // Spawn a tooltip on that item. | 1307 // Spawn a tooltip on that item. |
| 1310 button_host->MouseEnteredButton(app_button); | 1308 button_host->MouseEnteredButton(app_button); |
| 1311 ShowTooltip(); | 1309 ShowTooltip(); |
| 1312 EXPECT_TRUE(tooltip_manager->IsVisible()); | 1310 EXPECT_TRUE(tooltip_manager->IsVisible()); |
| 1313 | 1311 |
| 1314 // Remove the app shortcut while the tooltip is open. The tooltip should be | 1312 // Remove the app shortcut while the tooltip is open. The tooltip should be |
| 1315 // closed. | 1313 // closed. |
| 1316 RemoveByID(app_button_id); | 1314 RemoveByID(app_button_id); |
| 1317 EXPECT_FALSE(tooltip_manager->IsVisible()); | 1315 EXPECT_FALSE(tooltip_manager->IsVisible()); |
| 1318 | 1316 |
| 1319 // Change the shelf layout. This should not crash. | 1317 // Change the shelf layout. This should not crash. |
| 1320 Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_LEFT, | 1318 Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_LEFT, |
| 1321 Shell::GetPrimaryRootWindow()); | 1319 Shell::GetPrimaryRootWindow()); |
| 1322 } | 1320 } |
| 1323 | 1321 |
| 1324 // Changing the shelf alignment closes any open tooltip. | 1322 // Changing the shelf alignment closes any open tooltip. |
| 1325 TEST_F(ShelfViewTest, ShelfAlignmentClosesTooltip) { | 1323 TEST_F(ShelfViewTest, ShelfAlignmentClosesTooltip) { |
| 1326 internal::ShelfButtonHost* button_host = shelf_view_; | 1324 internal::ShelfButtonHost* button_host = shelf_view_; |
| 1327 internal::ShelfTooltipManager* tooltip_manager = | 1325 internal::ShelfTooltipManager* tooltip_manager = |
| 1328 shelf_view_->tooltip_manager(); | 1326 shelf_view_->tooltip_manager(); |
| 1329 | 1327 |
| 1330 // Add an item to the launcher. | 1328 // Add an item to the shelf. |
| 1331 LauncherID app_button_id = AddAppShortcut(); | 1329 LauncherID app_button_id = AddAppShortcut(); |
| 1332 internal::ShelfButton* app_button = GetButtonByID(app_button_id); | 1330 internal::ShelfButton* app_button = GetButtonByID(app_button_id); |
| 1333 | 1331 |
| 1334 // Spawn a tooltip on the item. | 1332 // Spawn a tooltip on the item. |
| 1335 button_host->MouseEnteredButton(app_button); | 1333 button_host->MouseEnteredButton(app_button); |
| 1336 ShowTooltip(); | 1334 ShowTooltip(); |
| 1337 EXPECT_TRUE(tooltip_manager->IsVisible()); | 1335 EXPECT_TRUE(tooltip_manager->IsVisible()); |
| 1338 | 1336 |
| 1339 // Changing shelf alignment hides the tooltip. | 1337 // Changing shelf alignment hides the tooltip. |
| 1340 Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_LEFT, | 1338 Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_LEFT, |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1614 EXPECT_TRUE(drag_reinsert_bounds.Contains(last_point)); | 1612 EXPECT_TRUE(drag_reinsert_bounds.Contains(last_point)); |
| 1615 } | 1613 } |
| 1616 | 1614 |
| 1617 // Check the drag insertion bounds of shelf view in multi monitor environment. | 1615 // Check the drag insertion bounds of shelf view in multi monitor environment. |
| 1618 TEST_F(ShelfViewTest, CheckDragInsertBoundsWithMultiMonitor) { | 1616 TEST_F(ShelfViewTest, CheckDragInsertBoundsWithMultiMonitor) { |
| 1619 // win8-aura doesn't support multiple display. | 1617 // win8-aura doesn't support multiple display. |
| 1620 if (!SupportsMultipleDisplays()) | 1618 if (!SupportsMultipleDisplays()) |
| 1621 return; | 1619 return; |
| 1622 | 1620 |
| 1623 UpdateDisplay("800x600,800x600"); | 1621 UpdateDisplay("800x600,800x600"); |
| 1624 Launcher* secondary_launcher = | 1622 Shelf* secondary_shelf = Shelf::ForWindow(Shell::GetAllRootWindows()[1]); |
| 1625 Launcher::ForWindow(Shell::GetAllRootWindows()[1]); | |
| 1626 internal::ShelfView* shelf_view_for_secondary = | 1623 internal::ShelfView* shelf_view_for_secondary = |
| 1627 test::LauncherTestAPI(secondary_launcher).shelf_view(); | 1624 ShelfTestAPI(secondary_shelf).shelf_view(); |
| 1628 | 1625 |
| 1629 // The bounds should be big enough for 4 buttons + overflow chevron. | 1626 // The bounds should be big enough for 4 buttons + overflow chevron. |
| 1630 shelf_view_for_secondary->SetBounds(0, 0, 500, | 1627 shelf_view_for_secondary->SetBounds(0, 0, 500, |
| 1631 internal::ShelfLayoutManager::GetPreferredShelfSize()); | 1628 internal::ShelfLayoutManager::GetPreferredShelfSize()); |
| 1632 | 1629 |
| 1633 ShelfViewTestAPI test_api_for_secondary(shelf_view_for_secondary); | 1630 ShelfViewTestAPI test_api_for_secondary(shelf_view_for_secondary); |
| 1634 // Speeds up animation for test. | 1631 // Speeds up animation for test. |
| 1635 test_api_for_secondary.SetAnimationDuration(1); | 1632 test_api_for_secondary.SetAnimationDuration(1); |
| 1636 | 1633 |
| 1637 AddButtonsUntilOverflow(); | 1634 AddButtonsUntilOverflow(); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1698 | 1695 |
| 1699 Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_LEFT, second_root); | 1696 Shell::GetInstance()->SetShelfAlignment(SHELF_ALIGNMENT_LEFT, second_root); |
| 1700 ASSERT_EQ(SHELF_ALIGNMENT_LEFT, | 1697 ASSERT_EQ(SHELF_ALIGNMENT_LEFT, |
| 1701 Shell::GetInstance()->GetShelfAlignment(second_root)); | 1698 Shell::GetInstance()->GetShelfAlignment(second_root)); |
| 1702 | 1699 |
| 1703 // Initially, app list and browser shortcut are added. | 1700 // Initially, app list and browser shortcut are added. |
| 1704 EXPECT_EQ(2, model_->item_count()); | 1701 EXPECT_EQ(2, model_->item_count()); |
| 1705 int browser_index = model_->GetItemIndexForType(TYPE_BROWSER_SHORTCUT); | 1702 int browser_index = model_->GetItemIndexForType(TYPE_BROWSER_SHORTCUT); |
| 1706 EXPECT_GT(browser_index, 0); | 1703 EXPECT_GT(browser_index, 0); |
| 1707 | 1704 |
| 1708 Launcher* secondary_launcher = Launcher::ForWindow(second_root); | 1705 Shelf* secondary_shelf = Shelf::ForWindow(second_root); |
| 1709 internal::ShelfView* shelf_view_for_secondary = | 1706 internal::ShelfView* shelf_view_for_secondary = |
| 1710 test::LauncherTestAPI(secondary_launcher).shelf_view(); | 1707 ShelfTestAPI(secondary_shelf).shelf_view(); |
| 1711 | 1708 |
| 1712 ShelfViewTestAPI test_api_for_secondary_shelf_view(shelf_view_for_secondary); | 1709 ShelfViewTestAPI test_api_for_secondary_shelf_view(shelf_view_for_secondary); |
| 1713 internal::ShelfButton* button = | 1710 internal::ShelfButton* button = |
| 1714 test_api_for_secondary_shelf_view.GetButton(browser_index); | 1711 test_api_for_secondary_shelf_view.GetButton(browser_index); |
| 1715 | 1712 |
| 1716 // Fetch the start point of dragging. | 1713 // Fetch the start point of dragging. |
| 1717 gfx::Point start_point = button->GetBoundsInScreen().CenterPoint(); | 1714 gfx::Point start_point = button->GetBoundsInScreen().CenterPoint(); |
| 1718 wm::ConvertPointFromScreen(second_root, &start_point); | 1715 wm::ConvertPointFromScreen(second_root, &start_point); |
| 1719 | 1716 |
| 1720 aura::test::EventGenerator generator(second_root, start_point); | 1717 aura::test::EventGenerator generator(second_root, start_point); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1737 TestDraggingAnItemFromOverflowToShelf(true); | 1734 TestDraggingAnItemFromOverflowToShelf(true); |
| 1738 } | 1735 } |
| 1739 | 1736 |
| 1740 class ShelfViewVisibleBoundsTest : public ShelfViewTest, | 1737 class ShelfViewVisibleBoundsTest : public ShelfViewTest, |
| 1741 public testing::WithParamInterface<bool> { | 1738 public testing::WithParamInterface<bool> { |
| 1742 public: | 1739 public: |
| 1743 ShelfViewVisibleBoundsTest() : text_direction_change_(GetParam()) {} | 1740 ShelfViewVisibleBoundsTest() : text_direction_change_(GetParam()) {} |
| 1744 | 1741 |
| 1745 void CheckAllItemsAreInBounds() { | 1742 void CheckAllItemsAreInBounds() { |
| 1746 gfx::Rect visible_bounds = shelf_view_->GetVisibleItemsBoundsInScreen(); | 1743 gfx::Rect visible_bounds = shelf_view_->GetVisibleItemsBoundsInScreen(); |
| 1747 gfx::Rect launcher_bounds = shelf_view_->GetBoundsInScreen(); | 1744 gfx::Rect shelf_bounds = shelf_view_->GetBoundsInScreen(); |
| 1748 EXPECT_TRUE(launcher_bounds.Contains(visible_bounds)); | 1745 EXPECT_TRUE(shelf_bounds.Contains(visible_bounds)); |
| 1749 for (int i = 0; i < test_api_->GetButtonCount(); ++i) | 1746 for (int i = 0; i < test_api_->GetButtonCount(); ++i) |
| 1750 if (internal::ShelfButton* button = test_api_->GetButton(i)) | 1747 if (internal::ShelfButton* button = test_api_->GetButton(i)) |
| 1751 EXPECT_TRUE(visible_bounds.Contains(button->GetBoundsInScreen())); | 1748 EXPECT_TRUE(visible_bounds.Contains(button->GetBoundsInScreen())); |
| 1752 CheckAppListButtonIsInBounds(); | 1749 CheckAppListButtonIsInBounds(); |
| 1753 } | 1750 } |
| 1754 | 1751 |
| 1755 void CheckAppListButtonIsInBounds() { | 1752 void CheckAppListButtonIsInBounds() { |
| 1756 gfx::Rect visible_bounds = shelf_view_->GetVisibleItemsBoundsInScreen(); | 1753 gfx::Rect visible_bounds = shelf_view_->GetVisibleItemsBoundsInScreen(); |
| 1757 gfx::Rect app_list_button_bounds = shelf_view_->GetAppListButtonView()-> | 1754 gfx::Rect app_list_button_bounds = shelf_view_->GetAppListButtonView()-> |
| 1758 GetBoundsInScreen(); | 1755 GetBoundsInScreen(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1780 test_api_->RunMessageLoopUntilAnimationsDone(); | 1777 test_api_->RunMessageLoopUntilAnimationsDone(); |
| 1781 CheckAllItemsAreInBounds(); | 1778 CheckAllItemsAreInBounds(); |
| 1782 } | 1779 } |
| 1783 | 1780 |
| 1784 INSTANTIATE_TEST_CASE_P(LtrRtl, ShelfViewTextDirectionTest, testing::Bool()); | 1781 INSTANTIATE_TEST_CASE_P(LtrRtl, ShelfViewTextDirectionTest, testing::Bool()); |
| 1785 INSTANTIATE_TEST_CASE_P(VisibleBounds, ShelfViewVisibleBoundsTest, | 1782 INSTANTIATE_TEST_CASE_P(VisibleBounds, ShelfViewVisibleBoundsTest, |
| 1786 testing::Bool()); | 1783 testing::Bool()); |
| 1787 | 1784 |
| 1788 } // namespace test | 1785 } // namespace test |
| 1789 } // namespace ash | 1786 } // namespace ash |
| OLD | NEW |