| 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/common/shelf/shelf_view.h" | 5 #include "ash/common/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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 EXPECT_TRUE(observer()->icon_positions_changed()); | 237 EXPECT_TRUE(observer()->icon_positions_changed()); |
| 238 observer()->Reset(); | 238 observer()->Reset(); |
| 239 } | 239 } |
| 240 | 240 |
| 241 //////////////////////////////////////////////////////////////////////////////// | 241 //////////////////////////////////////////////////////////////////////////////// |
| 242 // ShelfView tests. | 242 // ShelfView tests. |
| 243 | 243 |
| 244 // A ShelfDelegate test double that will always convert between ShelfIDs and app | 244 // A ShelfDelegate test double that will always convert between ShelfIDs and app |
| 245 // ids. This does not support pinning and unpinning operations and the return | 245 // ids. This does not support pinning and unpinning operations and the return |
| 246 // value of IsAppPinned(...) is configurable. | 246 // value of IsAppPinned(...) is configurable. |
| 247 class TestShelfDelegateForShelfView : public ShelfDelegate { | 247 class TestShelfDelegateForShelfView : public TestShelfDelegate { |
| 248 public: | 248 public: |
| 249 TestShelfDelegateForShelfView() {} | 249 explicit TestShelfDelegateForShelfView(ShelfModel* model) |
| 250 : TestShelfDelegate(model) {} |
| 250 ~TestShelfDelegateForShelfView() override {} | 251 ~TestShelfDelegateForShelfView() override {} |
| 251 | 252 |
| 252 void set_is_app_pinned(bool is_pinned) { is_app_pinned_ = is_pinned; } | 253 void set_is_app_pinned(bool is_pinned) { is_app_pinned_ = is_pinned; } |
| 253 | 254 |
| 254 // ShelfDelegate overrides: | 255 // ShelfDelegate overrides: |
| 255 ShelfID GetShelfIDForAppID(const std::string& app_id) override { | 256 ShelfID GetShelfIDForAppID(const std::string& app_id) override { |
| 256 ShelfID id = 0; | 257 ShelfID id = 0; |
| 257 EXPECT_TRUE(base::StringToInt(app_id, &id)); | 258 EXPECT_TRUE(base::StringToInt(app_id, &id)); |
| 258 return id; | 259 return id; |
| 259 } | 260 } |
| 260 | 261 |
| 261 ShelfID GetShelfIDForAppIDAndLaunchID(const std::string& app_id, | |
| 262 const std::string& launch_id) override { | |
| 263 return GetShelfIDForAppID(app_id); | |
| 264 } | |
| 265 | |
| 266 bool HasShelfIDToAppIDMapping(ShelfID id) const override { return true; } | 262 bool HasShelfIDToAppIDMapping(ShelfID id) const override { return true; } |
| 267 | 263 |
| 268 const std::string& GetAppIDForShelfID(ShelfID id) override { | 264 const std::string& GetAppIDForShelfID(ShelfID id) override { |
| 269 // Use |app_id_| member variable because returning a reference to local | 265 // Use |app_id_| member variable because returning a reference to local |
| 270 // variable is not allowed. | 266 // variable is not allowed. |
| 271 app_id_ = base::IntToString(id); | 267 app_id_ = base::IntToString(id); |
| 272 return app_id_; | 268 return app_id_; |
| 273 } | 269 } |
| 274 | 270 |
| 275 void PinAppWithID(const std::string& app_id) override { NOTREACHED(); } | 271 void PinAppWithID(const std::string& app_id) override { NOTREACHED(); } |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 test_api_->HideOverflowBubble(); | 674 test_api_->HideOverflowBubble(); |
| 679 } | 675 } |
| 680 | 676 |
| 681 // Returns the item's ShelfID at |index|. | 677 // Returns the item's ShelfID at |index|. |
| 682 ShelfID GetItemId(int index) { | 678 ShelfID GetItemId(int index) { |
| 683 DCHECK_GE(index, 0); | 679 DCHECK_GE(index, 0); |
| 684 return model_->items()[index].id; | 680 return model_->items()[index].id; |
| 685 } | 681 } |
| 686 | 682 |
| 687 void ReplaceShelfDelegate() { | 683 void ReplaceShelfDelegate() { |
| 688 shelf_delegate_ = new TestShelfDelegateForShelfView(); | 684 // Clear the value first to avoid TestShelfDelegate's singleton check. |
| 685 WmShell::Get()->SetShelfDelegateForTesting(nullptr); |
| 686 shelf_delegate_ = new TestShelfDelegateForShelfView(model_); |
| 689 test_api_->SetShelfDelegate(shelf_delegate_); | 687 test_api_->SetShelfDelegate(shelf_delegate_); |
| 690 WmShell::Get()->SetShelfDelegateForTesting( | 688 WmShell::Get()->SetShelfDelegateForTesting( |
| 691 base::WrapUnique(shelf_delegate_)); | 689 base::WrapUnique(shelf_delegate_)); |
| 692 } | 690 } |
| 693 | 691 |
| 694 ShelfModel* model_; | 692 ShelfModel* model_; |
| 695 ShelfView* shelf_view_; | 693 ShelfView* shelf_view_; |
| 696 int browser_index_; | 694 int browser_index_; |
| 697 | 695 |
| 698 // Owned by ash::WmShell. | 696 // Owned by ash::WmShell. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 731 bool is_rtl_; | 729 bool is_rtl_; |
| 732 std::string original_locale_; | 730 std::string original_locale_; |
| 733 }; | 731 }; |
| 734 | 732 |
| 735 class ShelfViewTextDirectionTest : public ShelfViewTest, | 733 class ShelfViewTextDirectionTest : public ShelfViewTest, |
| 736 public testing::WithParamInterface<bool> { | 734 public testing::WithParamInterface<bool> { |
| 737 public: | 735 public: |
| 738 ShelfViewTextDirectionTest() : text_direction_change_(GetParam()) {} | 736 ShelfViewTextDirectionTest() : text_direction_change_(GetParam()) {} |
| 739 virtual ~ShelfViewTextDirectionTest() {} | 737 virtual ~ShelfViewTextDirectionTest() {} |
| 740 | 738 |
| 741 void SetUp() override { ShelfViewTest::SetUp(); } | |
| 742 | |
| 743 void TearDown() override { ShelfViewTest::TearDown(); } | |
| 744 | |
| 745 private: | 739 private: |
| 746 ScopedTextDirectionChange text_direction_change_; | 740 ScopedTextDirectionChange text_direction_change_; |
| 747 | 741 |
| 748 DISALLOW_COPY_AND_ASSIGN(ShelfViewTextDirectionTest); | 742 DISALLOW_COPY_AND_ASSIGN(ShelfViewTextDirectionTest); |
| 749 }; | 743 }; |
| 750 | 744 |
| 751 // Checks that the ideal item icon bounds match the view's bounds in the screen | 745 // Checks that the ideal item icon bounds match the view's bounds in the screen |
| 752 // in both LTR and RTL. | 746 // in both LTR and RTL. |
| 753 TEST_P(ShelfViewTextDirectionTest, IdealBoundsOfItemIcon) { | 747 TEST_P(ShelfViewTextDirectionTest, IdealBoundsOfItemIcon) { |
| 754 ShelfID id = AddApp(); | 748 ShelfID id = AddApp(); |
| (...skipping 2267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3022 EXPECT_EQ(views::InkDropState::ACTIVATED, | 3016 EXPECT_EQ(views::InkDropState::ACTIVATED, |
| 3023 overflow_button_ink_drop_->GetTargetInkDropState()); | 3017 overflow_button_ink_drop_->GetTargetInkDropState()); |
| 3024 EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(), | 3018 EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(), |
| 3025 IsEmpty()); | 3019 IsEmpty()); |
| 3026 | 3020 |
| 3027 ASSERT_TRUE(test_api_->IsShowingOverflowBubble()); | 3021 ASSERT_TRUE(test_api_->IsShowingOverflowBubble()); |
| 3028 } | 3022 } |
| 3029 | 3023 |
| 3030 } // namespace test | 3024 } // namespace test |
| 3031 } // namespace ash | 3025 } // namespace ash |
| OLD | NEW |