Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: ash/shelf/shelf_view_unittest.cc

Issue 2688353005: Fix shelf alignment and auto-hide initialization. (Closed)
Patch Set: Fix mash_unittests by installing a TestShellDelegate. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 EXPECT_TRUE(observer()->icon_positions_changed()); 236 EXPECT_TRUE(observer()->icon_positions_changed());
237 observer()->Reset(); 237 observer()->Reset();
238 } 238 }
239 239
240 //////////////////////////////////////////////////////////////////////////////// 240 ////////////////////////////////////////////////////////////////////////////////
241 // ShelfView tests. 241 // ShelfView tests.
242 242
243 // A ShelfDelegate test double that will always convert between ShelfIDs and app 243 // A ShelfDelegate test double that will always convert between ShelfIDs and app
244 // ids. This does not support pinning and unpinning operations and the return 244 // ids. This does not support pinning and unpinning operations and the return
245 // value of IsAppPinned(...) is configurable. 245 // value of IsAppPinned(...) is configurable.
246 class TestShelfDelegateForShelfView : public ShelfDelegate { 246 class TestShelfDelegateForShelfView : public TestShelfDelegate {
247 public: 247 public:
248 TestShelfDelegateForShelfView() {} 248 TestShelfDelegateForShelfView() {}
249 ~TestShelfDelegateForShelfView() override {} 249 ~TestShelfDelegateForShelfView() override {}
250 250
251 void set_is_app_pinned(bool is_pinned) { is_app_pinned_ = is_pinned; } 251 void set_is_app_pinned(bool is_pinned) { is_app_pinned_ = is_pinned; }
252 252
253 // ShelfDelegate overrides: 253 // ShelfDelegate overrides:
254 ShelfID GetShelfIDForAppID(const std::string& app_id) override { 254 ShelfID GetShelfIDForAppID(const std::string& app_id) override {
255 ShelfID id = 0; 255 ShelfID id = 0;
256 EXPECT_TRUE(base::StringToInt(app_id, &id)); 256 EXPECT_TRUE(base::StringToInt(app_id, &id));
257 return id; 257 return id;
258 } 258 }
259 259
260 ShelfID GetShelfIDForAppIDAndLaunchID(const std::string& app_id,
261 const std::string& launch_id) override {
262 return GetShelfIDForAppID(app_id);
263 }
264
265 bool HasShelfIDToAppIDMapping(ShelfID id) const override { return true; } 260 bool HasShelfIDToAppIDMapping(ShelfID id) const override { return true; }
266 261
267 const std::string& GetAppIDForShelfID(ShelfID id) override { 262 const std::string& GetAppIDForShelfID(ShelfID id) override {
268 // Use |app_id_| member variable because returning a reference to local 263 // Use |app_id_| member variable because returning a reference to local
269 // variable is not allowed. 264 // variable is not allowed.
270 app_id_ = base::IntToString(id); 265 app_id_ = base::IntToString(id);
271 return app_id_; 266 return app_id_;
272 } 267 }
273 268
274 void PinAppWithID(const std::string& app_id) override { NOTREACHED(); } 269 void PinAppWithID(const std::string& app_id) override { NOTREACHED(); }
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 test_api_->HideOverflowBubble(); 672 test_api_->HideOverflowBubble();
678 } 673 }
679 674
680 // Returns the item's ShelfID at |index|. 675 // Returns the item's ShelfID at |index|.
681 ShelfID GetItemId(int index) { 676 ShelfID GetItemId(int index) {
682 DCHECK_GE(index, 0); 677 DCHECK_GE(index, 0);
683 return model_->items()[index].id; 678 return model_->items()[index].id;
684 } 679 }
685 680
686 void ReplaceShelfDelegate() { 681 void ReplaceShelfDelegate() {
682 // Clear the value first to avoid TestShelfDelegate's singleton check.
683 WmShell::Get()->SetShelfDelegateForTesting(nullptr);
687 shelf_delegate_ = new TestShelfDelegateForShelfView(); 684 shelf_delegate_ = new TestShelfDelegateForShelfView();
688 test_api_->SetShelfDelegate(shelf_delegate_); 685 test_api_->SetShelfDelegate(shelf_delegate_);
689 WmShell::Get()->SetShelfDelegateForTesting( 686 WmShell::Get()->SetShelfDelegateForTesting(
690 base::WrapUnique(shelf_delegate_)); 687 base::WrapUnique(shelf_delegate_));
691 } 688 }
692 689
693 ShelfModel* model_; 690 ShelfModel* model_;
694 ShelfView* shelf_view_; 691 ShelfView* shelf_view_;
695 int browser_index_; 692 int browser_index_;
696 693
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 bool is_rtl_; 727 bool is_rtl_;
731 std::string original_locale_; 728 std::string original_locale_;
732 }; 729 };
733 730
734 class ShelfViewTextDirectionTest : public ShelfViewTest, 731 class ShelfViewTextDirectionTest : public ShelfViewTest,
735 public testing::WithParamInterface<bool> { 732 public testing::WithParamInterface<bool> {
736 public: 733 public:
737 ShelfViewTextDirectionTest() : text_direction_change_(GetParam()) {} 734 ShelfViewTextDirectionTest() : text_direction_change_(GetParam()) {}
738 virtual ~ShelfViewTextDirectionTest() {} 735 virtual ~ShelfViewTextDirectionTest() {}
739 736
740 void SetUp() override { ShelfViewTest::SetUp(); }
741
742 void TearDown() override { ShelfViewTest::TearDown(); }
743
744 private: 737 private:
745 ScopedTextDirectionChange text_direction_change_; 738 ScopedTextDirectionChange text_direction_change_;
746 739
747 DISALLOW_COPY_AND_ASSIGN(ShelfViewTextDirectionTest); 740 DISALLOW_COPY_AND_ASSIGN(ShelfViewTextDirectionTest);
748 }; 741 };
749 742
750 // Checks that the ideal item icon bounds match the view's bounds in the screen 743 // Checks that the ideal item icon bounds match the view's bounds in the screen
751 // in both LTR and RTL. 744 // in both LTR and RTL.
752 TEST_P(ShelfViewTextDirectionTest, IdealBoundsOfItemIcon) { 745 TEST_P(ShelfViewTextDirectionTest, IdealBoundsOfItemIcon) {
753 ShelfID id = AddApp(); 746 ShelfID id = AddApp();
(...skipping 2216 matching lines...) Expand 10 before | Expand all | Expand 10 after
2970 EXPECT_EQ(views::InkDropState::ACTIVATED, 2963 EXPECT_EQ(views::InkDropState::ACTIVATED,
2971 overflow_button_ink_drop_->GetTargetInkDropState()); 2964 overflow_button_ink_drop_->GetTargetInkDropState());
2972 EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(), 2965 EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
2973 IsEmpty()); 2966 IsEmpty());
2974 2967
2975 ASSERT_TRUE(test_api_->IsShowingOverflowBubble()); 2968 ASSERT_TRUE(test_api_->IsShowingOverflowBubble());
2976 } 2969 }
2977 2970
2978 } // namespace test 2971 } // namespace test
2979 } // namespace ash 2972 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698