| 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 <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 private: | 133 private: |
| 134 std::unique_ptr<TestWmShelfObserver> observer_; | 134 std::unique_ptr<TestWmShelfObserver> observer_; |
| 135 std::unique_ptr<ShelfViewTestAPI> shelf_view_test_; | 135 std::unique_ptr<ShelfViewTestAPI> shelf_view_test_; |
| 136 | 136 |
| 137 DISALLOW_COPY_AND_ASSIGN(WmShelfObserverIconTest); | 137 DISALLOW_COPY_AND_ASSIGN(WmShelfObserverIconTest); |
| 138 }; | 138 }; |
| 139 | 139 |
| 140 // A ShelfItemDelegate that tracks selections and reports a custom action. | 140 // A ShelfItemDelegate that tracks selections and reports a custom action. |
| 141 class ShelfItemSelectionTracker : public ShelfItemDelegate { | 141 class ShelfItemSelectionTracker : public ShelfItemDelegate { |
| 142 public: | 142 public: |
| 143 ShelfItemSelectionTracker() : ShelfItemDelegate(AppLaunchId()) {} | 143 ShelfItemSelectionTracker() : ShelfItemDelegate(ShelfID()) {} |
| 144 ~ShelfItemSelectionTracker() override {} | 144 ~ShelfItemSelectionTracker() override {} |
| 145 | 145 |
| 146 size_t item_selected_count() const { return item_selected_count_; } | 146 size_t item_selected_count() const { return item_selected_count_; } |
| 147 void set_item_selected_action(ShelfAction item_selected_action) { | 147 void set_item_selected_action(ShelfAction item_selected_action) { |
| 148 item_selected_action_ = item_selected_action; | 148 item_selected_action_ = item_selected_action; |
| 149 } | 149 } |
| 150 | 150 |
| 151 // ShelfItemDelegate: | 151 // ShelfItemDelegate: |
| 152 void ItemSelected(std::unique_ptr<ui::Event> event, | 152 void ItemSelected(std::unique_ptr<ui::Event> event, |
| 153 int64_t display_id, | 153 int64_t display_id, |
| 154 ShelfLaunchSource source, | 154 ShelfLaunchSource source, |
| 155 const ItemSelectedCallback& callback) override { | 155 const ItemSelectedCallback& callback) override { |
| 156 item_selected_count_++; | 156 item_selected_count_++; |
| 157 callback.Run(item_selected_action_, base::nullopt); | 157 callback.Run(item_selected_action_, base::nullopt); |
| 158 } | 158 } |
| 159 void ExecuteCommand(uint32_t command_id, int32_t event_flags) override {} | 159 void ExecuteCommand(uint32_t command_id, int32_t event_flags) override {} |
| 160 void Close() override {} | 160 void Close() override {} |
| 161 | 161 |
| 162 private: | 162 private: |
| 163 size_t item_selected_count_ = 0; | 163 size_t item_selected_count_ = 0; |
| 164 ShelfAction item_selected_action_ = SHELF_ACTION_NONE; | 164 ShelfAction item_selected_action_ = SHELF_ACTION_NONE; |
| 165 | 165 |
| 166 DISALLOW_COPY_AND_ASSIGN(ShelfItemSelectionTracker); | 166 DISALLOW_COPY_AND_ASSIGN(ShelfItemSelectionTracker); |
| 167 }; | 167 }; |
| 168 | 168 |
| 169 TEST_F(WmShelfObserverIconTest, AddRemove) { | 169 TEST_F(WmShelfObserverIconTest, AddRemove) { |
| 170 ShelfItem item; | 170 ShelfItem item; |
| 171 item.id = ShelfID("foo"); |
| 171 item.type = TYPE_APP; | 172 item.type = TYPE_APP; |
| 172 EXPECT_FALSE(observer()->icon_positions_changed()); | 173 EXPECT_FALSE(observer()->icon_positions_changed()); |
| 173 const int shelf_item_index = Shell::Get()->shelf_model()->Add(item); | 174 const int shelf_item_index = Shell::Get()->shelf_model()->Add(item); |
| 174 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); | 175 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); |
| 175 EXPECT_TRUE(observer()->icon_positions_changed()); | 176 EXPECT_TRUE(observer()->icon_positions_changed()); |
| 176 observer()->Reset(); | 177 observer()->Reset(); |
| 177 | 178 |
| 178 EXPECT_FALSE(observer()->icon_positions_changed()); | 179 EXPECT_FALSE(observer()->icon_positions_changed()); |
| 179 Shell::Get()->shelf_model()->RemoveItemAt(shelf_item_index); | 180 Shell::Get()->shelf_model()->RemoveItemAt(shelf_item_index); |
| 180 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); | 181 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); |
| 181 EXPECT_TRUE(observer()->icon_positions_changed()); | 182 EXPECT_TRUE(observer()->icon_positions_changed()); |
| 182 observer()->Reset(); | 183 observer()->Reset(); |
| 183 } | 184 } |
| 184 | 185 |
| 185 // Make sure creating/deleting an window on one displays notifies a | 186 // Make sure creating/deleting an window on one displays notifies a |
| 186 // shelf on external display as well as one on primary. | 187 // shelf on external display as well as one on primary. |
| 187 TEST_F(WmShelfObserverIconTest, AddRemoveWithMultipleDisplays) { | 188 TEST_F(WmShelfObserverIconTest, AddRemoveWithMultipleDisplays) { |
| 188 // TODO: investigate failure in mash, http://crbug.com/695751. | 189 // TODO: investigate failure in mash, http://crbug.com/695751. |
| 189 if (Shell::GetAshConfig() == Config::MASH) | 190 if (Shell::GetAshConfig() == Config::MASH) |
| 190 return; | 191 return; |
| 191 | 192 |
| 192 UpdateDisplay("400x400,400x400"); | 193 UpdateDisplay("400x400,400x400"); |
| 193 observer()->Reset(); | 194 observer()->Reset(); |
| 194 | 195 |
| 195 WmWindow* second_root = ShellPort::Get()->GetAllRootWindows()[1]; | 196 WmWindow* second_root = ShellPort::Get()->GetAllRootWindows()[1]; |
| 196 WmShelf* second_shelf = second_root->GetRootWindowController()->GetShelf(); | 197 WmShelf* second_shelf = second_root->GetRootWindowController()->GetShelf(); |
| 197 TestWmShelfObserver second_observer(second_shelf); | 198 TestWmShelfObserver second_observer(second_shelf); |
| 198 | 199 |
| 199 ShelfItem item; | 200 ShelfItem item; |
| 201 item.id = ShelfID("foo"); |
| 200 item.type = TYPE_APP; | 202 item.type = TYPE_APP; |
| 201 EXPECT_FALSE(observer()->icon_positions_changed()); | 203 EXPECT_FALSE(observer()->icon_positions_changed()); |
| 202 EXPECT_FALSE(second_observer.icon_positions_changed()); | 204 EXPECT_FALSE(second_observer.icon_positions_changed()); |
| 203 const int shelf_item_index = Shell::Get()->shelf_model()->Add(item); | 205 const int shelf_item_index = Shell::Get()->shelf_model()->Add(item); |
| 204 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); | 206 shelf_view_test()->RunMessageLoopUntilAnimationsDone(); |
| 205 EXPECT_TRUE(observer()->icon_positions_changed()); | 207 EXPECT_TRUE(observer()->icon_positions_changed()); |
| 206 EXPECT_TRUE(second_observer.icon_positions_changed()); | 208 EXPECT_TRUE(second_observer.icon_positions_changed()); |
| 207 observer()->Reset(); | 209 observer()->Reset(); |
| 208 second_observer.Reset(); | 210 second_observer.Reset(); |
| 209 | 211 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 } | 267 } |
| 266 | 268 |
| 267 protected: | 269 protected: |
| 268 // Add shelf items of various types, and optionally wait for animations. | 270 // Add shelf items of various types, and optionally wait for animations. |
| 269 ShelfID AddItem(ShelfItemType type, bool wait_for_animations) { | 271 ShelfID AddItem(ShelfItemType type, bool wait_for_animations) { |
| 270 ShelfItem item; | 272 ShelfItem item; |
| 271 item.type = type; | 273 item.type = type; |
| 272 if (type == TYPE_APP || type == TYPE_APP_PANEL) | 274 if (type == TYPE_APP || type == TYPE_APP_PANEL) |
| 273 item.status = STATUS_RUNNING; | 275 item.status = STATUS_RUNNING; |
| 274 | 276 |
| 275 ShelfID id = model_->next_id(); | 277 static int id = 0; |
| 276 item.app_launch_id = AppLaunchId(base::IntToString(id)); | 278 item.id = ShelfID(base::IntToString(id++)); |
| 277 model_->Add(item); | 279 model_->Add(item); |
| 278 // Set a delegate; some tests require one to select the item. | 280 // Set a delegate; some tests require one to select the item. |
| 279 model_->SetShelfItemDelegate(id, | 281 model_->SetShelfItemDelegate(item.id, |
| 280 base::MakeUnique<ShelfItemSelectionTracker>()); | 282 base::MakeUnique<ShelfItemSelectionTracker>()); |
| 281 if (wait_for_animations) | 283 if (wait_for_animations) |
| 282 test_api_->RunMessageLoopUntilAnimationsDone(); | 284 test_api_->RunMessageLoopUntilAnimationsDone(); |
| 283 return id; | 285 return item.id; |
| 284 } | 286 } |
| 285 ShelfID AddAppShortcut() { return AddItem(TYPE_PINNED_APP, true); } | 287 ShelfID AddAppShortcut() { return AddItem(TYPE_PINNED_APP, true); } |
| 286 ShelfID AddPanel() { return AddItem(TYPE_APP_PANEL, true); } | 288 ShelfID AddPanel() { return AddItem(TYPE_APP_PANEL, true); } |
| 287 ShelfID AddAppNoWait() { return AddItem(TYPE_APP, false); } | 289 ShelfID AddAppNoWait() { return AddItem(TYPE_APP, false); } |
| 288 ShelfID AddApp() { return AddItem(TYPE_APP, true); } | 290 ShelfID AddApp() { return AddItem(TYPE_APP, true); } |
| 289 | 291 |
| 290 void SetShelfItemTypeToAppShortcut(ShelfID id) { | 292 void SetShelfItemTypeToAppShortcut(const ShelfID& id) { |
| 291 int index = model_->ItemIndexByID(id); | 293 int index = model_->ItemIndexByID(id); |
| 292 DCHECK_GE(index, 0); | 294 DCHECK_GE(index, 0); |
| 293 | 295 |
| 294 ShelfItem item = model_->items()[index]; | 296 ShelfItem item = model_->items()[index]; |
| 295 | 297 |
| 296 if (item.type == TYPE_APP) { | 298 if (item.type == TYPE_APP) { |
| 297 item.type = TYPE_PINNED_APP; | 299 item.type = TYPE_PINNED_APP; |
| 298 model_->Set(index, item); | 300 model_->Set(index, item); |
| 299 } | 301 } |
| 300 test_api_->RunMessageLoopUntilAnimationsDone(); | 302 test_api_->RunMessageLoopUntilAnimationsDone(); |
| 301 } | 303 } |
| 302 | 304 |
| 303 void RemoveByID(ShelfID id) { | 305 void RemoveByID(const ShelfID& id) { |
| 304 model_->RemoveItemAt(model_->ItemIndexByID(id)); | 306 model_->RemoveItemAt(model_->ItemIndexByID(id)); |
| 305 test_api_->RunMessageLoopUntilAnimationsDone(); | 307 test_api_->RunMessageLoopUntilAnimationsDone(); |
| 306 } | 308 } |
| 307 | 309 |
| 308 ShelfButton* GetButtonByID(ShelfID id) { | 310 ShelfButton* GetButtonByID(const ShelfID& id) { |
| 309 int index = model_->ItemIndexByID(id); | 311 int index = model_->ItemIndexByID(id); |
| 310 return test_api_->GetButton(index); | 312 return test_api_->GetButton(index); |
| 311 } | 313 } |
| 312 | 314 |
| 313 ShelfItem GetItemByID(ShelfID id) { | 315 ShelfItem GetItemByID(const ShelfID& id) { |
| 314 ShelfItems::const_iterator items = model_->ItemByID(id); | 316 ShelfItems::const_iterator items = model_->ItemByID(id); |
| 315 return *items; | 317 return *items; |
| 316 } | 318 } |
| 317 | 319 |
| 318 void CheckModelIDs( | 320 void CheckModelIDs( |
| 319 const std::vector<std::pair<ShelfID, views::View*>>& id_map) { | 321 const std::vector<std::pair<ShelfID, views::View*>>& id_map) { |
| 320 size_t map_index = 0; | 322 size_t map_index = 0; |
| 321 for (size_t model_index = 0; model_index < model_->items().size(); | 323 for (size_t model_index = 0; model_index < model_->items().size(); |
| 322 ++model_index) { | 324 ++model_index) { |
| 323 ShelfItem item = model_->items()[model_index]; | 325 ShelfItem item = model_->items()[model_index]; |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 } | 579 } |
| 578 | 580 |
| 579 // Returns the item's ShelfID at |index|. | 581 // Returns the item's ShelfID at |index|. |
| 580 ShelfID GetItemId(int index) { | 582 ShelfID GetItemId(int index) { |
| 581 DCHECK_GE(index, 0); | 583 DCHECK_GE(index, 0); |
| 582 return model_->items()[index].id; | 584 return model_->items()[index].id; |
| 583 } | 585 } |
| 584 | 586 |
| 585 // Returns the center coordinates for a button. Helper function for an event | 587 // Returns the center coordinates for a button. Helper function for an event |
| 586 // generator. | 588 // generator. |
| 587 gfx::Point GetButtonCenter(ShelfID button_id) { | 589 gfx::Point GetButtonCenter(const ShelfID& button_id) { |
| 588 return GetButtonCenter( | 590 return GetButtonCenter( |
| 589 test_api_->GetButton(model_->ItemIndexByID(button_id))); | 591 test_api_->GetButton(model_->ItemIndexByID(button_id))); |
| 590 } | 592 } |
| 591 | 593 |
| 592 gfx::Point GetButtonCenter(ShelfButton* button) { | 594 gfx::Point GetButtonCenter(ShelfButton* button) { |
| 593 return button->GetBoundsInScreen().CenterPoint(); | 595 return button->GetBoundsInScreen().CenterPoint(); |
| 594 } | 596 } |
| 595 | 597 |
| 596 ShelfModel* model_ = nullptr; | 598 ShelfModel* model_ = nullptr; |
| 597 ShelfView* shelf_view_ = nullptr; | 599 ShelfView* shelf_view_ = nullptr; |
| (...skipping 1334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1932 std::unique_ptr<views::InkDrop> ink_drop_; | 1934 std::unique_ptr<views::InkDrop> ink_drop_; |
| 1933 std::vector<views::InkDropState> requested_states_; | 1935 std::vector<views::InkDropState> requested_states_; |
| 1934 | 1936 |
| 1935 private: | 1937 private: |
| 1936 DISALLOW_COPY_AND_ASSIGN(InkDropSpy); | 1938 DISALLOW_COPY_AND_ASSIGN(InkDropSpy); |
| 1937 }; | 1939 }; |
| 1938 | 1940 |
| 1939 // A ShelfItemDelegate that returns a menu for the shelf item. | 1941 // A ShelfItemDelegate that returns a menu for the shelf item. |
| 1940 class ListMenuShelfItemDelegate : public ShelfItemDelegate { | 1942 class ListMenuShelfItemDelegate : public ShelfItemDelegate { |
| 1941 public: | 1943 public: |
| 1942 ListMenuShelfItemDelegate() : ShelfItemDelegate(AppLaunchId()) {} | 1944 ListMenuShelfItemDelegate() : ShelfItemDelegate(ShelfID()) {} |
| 1943 ~ListMenuShelfItemDelegate() override {} | 1945 ~ListMenuShelfItemDelegate() override {} |
| 1944 | 1946 |
| 1945 private: | 1947 private: |
| 1946 // ShelfItemDelegate: | 1948 // ShelfItemDelegate: |
| 1947 void ItemSelected(std::unique_ptr<ui::Event> event, | 1949 void ItemSelected(std::unique_ptr<ui::Event> event, |
| 1948 int64_t display_id, | 1950 int64_t display_id, |
| 1949 ShelfLaunchSource source, | 1951 ShelfLaunchSource source, |
| 1950 const ItemSelectedCallback& callback) override { | 1952 const ItemSelectedCallback& callback) override { |
| 1951 // Two items are needed to show a menu; the data in the items is not tested. | 1953 // Two items are needed to show a menu; the data in the items is not tested. |
| 1952 std::vector<mojom::MenuItemPtr> items; | 1954 std::vector<mojom::MenuItemPtr> items; |
| (...skipping 1104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3057 EXPECT_EQ(views::InkDropState::ACTIVATED, | 3059 EXPECT_EQ(views::InkDropState::ACTIVATED, |
| 3058 overflow_button_ink_drop_->GetTargetInkDropState()); | 3060 overflow_button_ink_drop_->GetTargetInkDropState()); |
| 3059 EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(), | 3061 EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(), |
| 3060 IsEmpty()); | 3062 IsEmpty()); |
| 3061 | 3063 |
| 3062 ASSERT_TRUE(test_api_->IsShowingOverflowBubble()); | 3064 ASSERT_TRUE(test_api_->IsShowingOverflowBubble()); |
| 3063 } | 3065 } |
| 3064 | 3066 |
| 3065 } // namespace test | 3067 } // namespace test |
| 3066 } // namespace ash | 3068 } // namespace ash |
| OLD | NEW |