| 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/root_window_controller.h" | 10 #include "ash/root_window_controller.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 | 56 |
| 57 class TestShelfIconObserver : public ShelfIconObserver { | 57 class TestShelfIconObserver : public ShelfIconObserver { |
| 58 public: | 58 public: |
| 59 explicit TestShelfIconObserver(Shelf* shelf) | 59 explicit TestShelfIconObserver(Shelf* shelf) |
| 60 : shelf_(shelf), | 60 : shelf_(shelf), |
| 61 change_notified_(false) { | 61 change_notified_(false) { |
| 62 if (shelf_) | 62 if (shelf_) |
| 63 shelf_->AddIconObserver(this); | 63 shelf_->AddIconObserver(this); |
| 64 } | 64 } |
| 65 | 65 |
| 66 virtual ~TestShelfIconObserver() { | 66 ~TestShelfIconObserver() override { |
| 67 if (shelf_) | 67 if (shelf_) |
| 68 shelf_->RemoveIconObserver(this); | 68 shelf_->RemoveIconObserver(this); |
| 69 } | 69 } |
| 70 | 70 |
| 71 // ShelfIconObserver implementation. | 71 // ShelfIconObserver implementation. |
| 72 virtual void OnShelfIconPositionsChanged() override { | 72 void OnShelfIconPositionsChanged() override { change_notified_ = true; } |
| 73 change_notified_ = true; | |
| 74 } | |
| 75 | 73 |
| 76 int change_notified() const { return change_notified_; } | 74 int change_notified() const { return change_notified_; } |
| 77 void Reset() { change_notified_ = false; } | 75 void Reset() { change_notified_ = false; } |
| 78 | 76 |
| 79 private: | 77 private: |
| 80 Shelf* shelf_; | 78 Shelf* shelf_; |
| 81 bool change_notified_; | 79 bool change_notified_; |
| 82 | 80 |
| 83 DISALLOW_COPY_AND_ASSIGN(TestShelfIconObserver); | 81 DISALLOW_COPY_AND_ASSIGN(TestShelfIconObserver); |
| 84 }; | 82 }; |
| 85 | 83 |
| 86 class ShelfViewIconObserverTest : public AshTestBase { | 84 class ShelfViewIconObserverTest : public AshTestBase { |
| 87 public: | 85 public: |
| 88 ShelfViewIconObserverTest() {} | 86 ShelfViewIconObserverTest() {} |
| 89 virtual ~ShelfViewIconObserverTest() {} | 87 ~ShelfViewIconObserverTest() override {} |
| 90 | 88 |
| 91 virtual void SetUp() override { | 89 void SetUp() override { |
| 92 AshTestBase::SetUp(); | 90 AshTestBase::SetUp(); |
| 93 Shelf* shelf = Shelf::ForPrimaryDisplay(); | 91 Shelf* shelf = Shelf::ForPrimaryDisplay(); |
| 94 observer_.reset(new TestShelfIconObserver(shelf)); | 92 observer_.reset(new TestShelfIconObserver(shelf)); |
| 95 | 93 |
| 96 shelf_view_test_.reset( | 94 shelf_view_test_.reset( |
| 97 new ShelfViewTestAPI(ShelfTestAPI(shelf).shelf_view())); | 95 new ShelfViewTestAPI(ShelfTestAPI(shelf).shelf_view())); |
| 98 shelf_view_test_->SetAnimationDuration(1); | 96 shelf_view_test_->SetAnimationDuration(1); |
| 99 } | 97 } |
| 100 | 98 |
| 101 virtual void TearDown() override { | 99 void TearDown() override { |
| 102 observer_.reset(); | 100 observer_.reset(); |
| 103 AshTestBase::TearDown(); | 101 AshTestBase::TearDown(); |
| 104 } | 102 } |
| 105 | 103 |
| 106 TestShelfIconObserver* observer() { return observer_.get(); } | 104 TestShelfIconObserver* observer() { return observer_.get(); } |
| 107 | 105 |
| 108 ShelfViewTestAPI* shelf_view_test() { | 106 ShelfViewTestAPI* shelf_view_test() { |
| 109 return shelf_view_test_.get(); | 107 return shelf_view_test_.get(); |
| 110 } | 108 } |
| 111 | 109 |
| 112 Shelf* ShelfForSecondaryDisplay() { | 110 Shelf* ShelfForSecondaryDisplay() { |
| 113 return Shelf::ForWindow(Shell::GetAllRootWindows()[1]); | 111 return Shelf::ForWindow(Shell::GetAllRootWindows()[1]); |
| 114 } | 112 } |
| 115 | 113 |
| 116 private: | 114 private: |
| 117 scoped_ptr<TestShelfIconObserver> observer_; | 115 scoped_ptr<TestShelfIconObserver> observer_; |
| 118 scoped_ptr<ShelfViewTestAPI> shelf_view_test_; | 116 scoped_ptr<ShelfViewTestAPI> shelf_view_test_; |
| 119 | 117 |
| 120 DISALLOW_COPY_AND_ASSIGN(ShelfViewIconObserverTest); | 118 DISALLOW_COPY_AND_ASSIGN(ShelfViewIconObserverTest); |
| 121 }; | 119 }; |
| 122 | 120 |
| 123 // TestShelfItemDelegate which tracks whether it gets selected. | 121 // TestShelfItemDelegate which tracks whether it gets selected. |
| 124 class ShelfItemSelectionTracker : public TestShelfItemDelegate { | 122 class ShelfItemSelectionTracker : public TestShelfItemDelegate { |
| 125 public: | 123 public: |
| 126 ShelfItemSelectionTracker() : TestShelfItemDelegate(NULL), selected_(false) { | 124 ShelfItemSelectionTracker() : TestShelfItemDelegate(NULL), selected_(false) { |
| 127 } | 125 } |
| 128 | 126 |
| 129 virtual ~ShelfItemSelectionTracker() { | 127 ~ShelfItemSelectionTracker() override {} |
| 130 } | |
| 131 | 128 |
| 132 // Resets to the initial state. | 129 // Resets to the initial state. |
| 133 void Reset() { selected_ = false; } | 130 void Reset() { selected_ = false; } |
| 134 | 131 |
| 135 // Returns true if the delegate was selected. | 132 // Returns true if the delegate was selected. |
| 136 bool WasSelected() { | 133 bool WasSelected() { |
| 137 return selected_; | 134 return selected_; |
| 138 } | 135 } |
| 139 | 136 |
| 140 // TestShelfItemDelegate: | 137 // TestShelfItemDelegate: |
| 141 virtual bool ItemSelected(const ui::Event& event) override { | 138 bool ItemSelected(const ui::Event& event) override { |
| 142 selected_ = true; | 139 selected_ = true; |
| 143 return false; | 140 return false; |
| 144 } | 141 } |
| 145 | 142 |
| 146 private: | 143 private: |
| 147 bool selected_; | 144 bool selected_; |
| 148 | 145 |
| 149 DISALLOW_COPY_AND_ASSIGN(ShelfItemSelectionTracker); | 146 DISALLOW_COPY_AND_ASSIGN(ShelfItemSelectionTracker); |
| 150 }; | 147 }; |
| 151 | 148 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 | 223 |
| 227 //////////////////////////////////////////////////////////////////////////////// | 224 //////////////////////////////////////////////////////////////////////////////// |
| 228 // ShelfView tests. | 225 // ShelfView tests. |
| 229 | 226 |
| 230 // Simple ShelfDelegate implmentation for ShelfViewTest.OverflowBubbleSize | 227 // Simple ShelfDelegate implmentation for ShelfViewTest.OverflowBubbleSize |
| 231 // and CheckDragAndDropFromOverflowBubbleToShelf | 228 // and CheckDragAndDropFromOverflowBubbleToShelf |
| 232 class TestShelfDelegateForShelfView : public ShelfDelegate { | 229 class TestShelfDelegateForShelfView : public ShelfDelegate { |
| 233 public: | 230 public: |
| 234 explicit TestShelfDelegateForShelfView(ShelfModel* model) | 231 explicit TestShelfDelegateForShelfView(ShelfModel* model) |
| 235 : model_(model) {} | 232 : model_(model) {} |
| 236 virtual ~TestShelfDelegateForShelfView() {} | 233 ~TestShelfDelegateForShelfView() override {} |
| 237 | 234 |
| 238 // ShelfDelegate overrides: | 235 // ShelfDelegate overrides: |
| 239 virtual void OnShelfCreated(Shelf* shelf) override {} | 236 void OnShelfCreated(Shelf* shelf) override {} |
| 240 | 237 |
| 241 virtual void OnShelfDestroyed(Shelf* shelf) override {} | 238 void OnShelfDestroyed(Shelf* shelf) override {} |
| 242 | 239 |
| 243 virtual ShelfID GetShelfIDForAppID(const std::string& app_id) override { | 240 ShelfID GetShelfIDForAppID(const std::string& app_id) override { |
| 244 ShelfID id = 0; | 241 ShelfID id = 0; |
| 245 EXPECT_TRUE(base::StringToInt(app_id, &id)); | 242 EXPECT_TRUE(base::StringToInt(app_id, &id)); |
| 246 return id; | 243 return id; |
| 247 } | 244 } |
| 248 | 245 |
| 249 virtual const std::string& GetAppIDForShelfID(ShelfID id) override { | 246 const std::string& GetAppIDForShelfID(ShelfID id) override { |
| 250 // Use |app_id_| member variable because returning a reference to local | 247 // Use |app_id_| member variable because returning a reference to local |
| 251 // variable is not allowed. | 248 // variable is not allowed. |
| 252 app_id_ = base::IntToString(id); | 249 app_id_ = base::IntToString(id); |
| 253 return app_id_; | 250 return app_id_; |
| 254 } | 251 } |
| 255 | 252 |
| 256 virtual void PinAppWithID(const std::string& app_id) override { | 253 void PinAppWithID(const std::string& app_id) override {} |
| 257 } | |
| 258 | 254 |
| 259 virtual bool IsAppPinned(const std::string& app_id) override { | 255 bool IsAppPinned(const std::string& app_id) override { |
| 260 // Returns true for ShelfViewTest.OverflowBubbleSize. To test ripping off in | 256 // Returns true for ShelfViewTest.OverflowBubbleSize. To test ripping off in |
| 261 // that test, an item is already pinned state. | 257 // that test, an item is already pinned state. |
| 262 return true; | 258 return true; |
| 263 } | 259 } |
| 264 | 260 |
| 265 virtual bool CanPin() const override { | 261 bool CanPin() const override { return true; } |
| 266 return true; | |
| 267 } | |
| 268 | 262 |
| 269 virtual void UnpinAppWithID(const std::string& app_id) override { | 263 void UnpinAppWithID(const std::string& app_id) override { |
| 270 ShelfID id = 0; | 264 ShelfID id = 0; |
| 271 EXPECT_TRUE(base::StringToInt(app_id, &id)); | 265 EXPECT_TRUE(base::StringToInt(app_id, &id)); |
| 272 ASSERT_GT(id, 0); | 266 ASSERT_GT(id, 0); |
| 273 int index = model_->ItemIndexByID(id); | 267 int index = model_->ItemIndexByID(id); |
| 274 ASSERT_GE(index, 0); | 268 ASSERT_GE(index, 0); |
| 275 | 269 |
| 276 model_->RemoveItemAt(index); | 270 model_->RemoveItemAt(index); |
| 277 } | 271 } |
| 278 | 272 |
| 279 private: | 273 private: |
| 280 ShelfModel* model_; | 274 ShelfModel* model_; |
| 281 | 275 |
| 282 // Temp member variable for returning a value. See the comment in the | 276 // Temp member variable for returning a value. See the comment in the |
| 283 // GetAppIDForShelfID(). | 277 // GetAppIDForShelfID(). |
| 284 std::string app_id_; | 278 std::string app_id_; |
| 285 | 279 |
| 286 DISALLOW_COPY_AND_ASSIGN(TestShelfDelegateForShelfView); | 280 DISALLOW_COPY_AND_ASSIGN(TestShelfDelegateForShelfView); |
| 287 }; | 281 }; |
| 288 | 282 |
| 289 class ShelfViewTest : public AshTestBase { | 283 class ShelfViewTest : public AshTestBase { |
| 290 public: | 284 public: |
| 291 ShelfViewTest() | 285 ShelfViewTest() |
| 292 : model_(NULL), | 286 : model_(NULL), |
| 293 shelf_view_(NULL), | 287 shelf_view_(NULL), |
| 294 browser_index_(1), | 288 browser_index_(1), |
| 295 item_manager_(NULL) {} | 289 item_manager_(NULL) {} |
| 296 virtual ~ShelfViewTest() {} | 290 ~ShelfViewTest() override {} |
| 297 | 291 |
| 298 virtual void SetUp() override { | 292 void SetUp() override { |
| 299 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 293 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 300 switches::kEnableTouchFeedback); | 294 switches::kEnableTouchFeedback); |
| 301 AshTestBase::SetUp(); | 295 AshTestBase::SetUp(); |
| 302 test::ShellTestApi test_api(Shell::GetInstance()); | 296 test::ShellTestApi test_api(Shell::GetInstance()); |
| 303 model_ = test_api.shelf_model(); | 297 model_ = test_api.shelf_model(); |
| 304 Shelf* shelf = Shelf::ForPrimaryDisplay(); | 298 Shelf* shelf = Shelf::ForPrimaryDisplay(); |
| 305 shelf_view_ = ShelfTestAPI(shelf).shelf_view(); | 299 shelf_view_ = ShelfTestAPI(shelf).shelf_view(); |
| 306 | 300 |
| 307 // The bounds should be big enough for 4 buttons + overflow chevron. | 301 // The bounds should be big enough for 4 buttons + overflow chevron. |
| 308 shelf_view_->SetBounds(0, 0, 500, kShelfSize); | 302 shelf_view_->SetBounds(0, 0, 500, kShelfSize); |
| 309 | 303 |
| 310 test_api_.reset(new ShelfViewTestAPI(shelf_view_)); | 304 test_api_.reset(new ShelfViewTestAPI(shelf_view_)); |
| 311 test_api_->SetAnimationDuration(1); // Speeds up animation for test. | 305 test_api_->SetAnimationDuration(1); // Speeds up animation for test. |
| 312 | 306 |
| 313 item_manager_ = Shell::GetInstance()->shelf_item_delegate_manager(); | 307 item_manager_ = Shell::GetInstance()->shelf_item_delegate_manager(); |
| 314 DCHECK(item_manager_); | 308 DCHECK(item_manager_); |
| 315 | 309 |
| 316 // Add browser shortcut shelf item at index 0 for test. | 310 // Add browser shortcut shelf item at index 0 for test. |
| 317 AddBrowserShortcut(); | 311 AddBrowserShortcut(); |
| 318 } | 312 } |
| 319 | 313 |
| 320 virtual void TearDown() override { | 314 void TearDown() override { |
| 321 test_api_.reset(); | 315 test_api_.reset(); |
| 322 AshTestBase::TearDown(); | 316 AshTestBase::TearDown(); |
| 323 } | 317 } |
| 324 | 318 |
| 325 protected: | 319 protected: |
| 326 void CreateAndSetShelfItemDelegateForID(ShelfID id) { | 320 void CreateAndSetShelfItemDelegateForID(ShelfID id) { |
| 327 scoped_ptr<ShelfItemDelegate> delegate(new TestShelfItemDelegate(NULL)); | 321 scoped_ptr<ShelfItemDelegate> delegate(new TestShelfItemDelegate(NULL)); |
| 328 item_manager_->SetShelfItemDelegate(id, delegate.Pass()); | 322 item_manager_->SetShelfItemDelegate(id, delegate.Pass()); |
| 329 } | 323 } |
| 330 | 324 |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 std::string original_locale_; | 650 std::string original_locale_; |
| 657 }; | 651 }; |
| 658 | 652 |
| 659 class ShelfViewTextDirectionTest | 653 class ShelfViewTextDirectionTest |
| 660 : public ShelfViewTest, | 654 : public ShelfViewTest, |
| 661 public testing::WithParamInterface<bool> { | 655 public testing::WithParamInterface<bool> { |
| 662 public: | 656 public: |
| 663 ShelfViewTextDirectionTest() : text_direction_change_(GetParam()) {} | 657 ShelfViewTextDirectionTest() : text_direction_change_(GetParam()) {} |
| 664 virtual ~ShelfViewTextDirectionTest() {} | 658 virtual ~ShelfViewTextDirectionTest() {} |
| 665 | 659 |
| 666 virtual void SetUp() override { | 660 void SetUp() override { ShelfViewTest::SetUp(); } |
| 667 ShelfViewTest::SetUp(); | |
| 668 } | |
| 669 | 661 |
| 670 virtual void TearDown() override { | 662 void TearDown() override { ShelfViewTest::TearDown(); } |
| 671 ShelfViewTest::TearDown(); | |
| 672 } | |
| 673 | 663 |
| 674 private: | 664 private: |
| 675 ScopedTextDirectionChange text_direction_change_; | 665 ScopedTextDirectionChange text_direction_change_; |
| 676 | 666 |
| 677 DISALLOW_COPY_AND_ASSIGN(ShelfViewTextDirectionTest); | 667 DISALLOW_COPY_AND_ASSIGN(ShelfViewTextDirectionTest); |
| 678 }; | 668 }; |
| 679 | 669 |
| 680 // Checks that the ideal item icon bounds match the view's bounds in the screen | 670 // Checks that the ideal item icon bounds match the view's bounds in the screen |
| 681 // in both LTR and RTL. | 671 // in both LTR and RTL. |
| 682 TEST_P(ShelfViewTextDirectionTest, IdealBoundsOfItemIcon) { | 672 TEST_P(ShelfViewTextDirectionTest, IdealBoundsOfItemIcon) { |
| (...skipping 1080 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1763 test_api_->RunMessageLoopUntilAnimationsDone(); | 1753 test_api_->RunMessageLoopUntilAnimationsDone(); |
| 1764 CheckAllItemsAreInBounds(); | 1754 CheckAllItemsAreInBounds(); |
| 1765 } | 1755 } |
| 1766 | 1756 |
| 1767 INSTANTIATE_TEST_CASE_P(LtrRtl, ShelfViewTextDirectionTest, testing::Bool()); | 1757 INSTANTIATE_TEST_CASE_P(LtrRtl, ShelfViewTextDirectionTest, testing::Bool()); |
| 1768 INSTANTIATE_TEST_CASE_P(VisibleBounds, ShelfViewVisibleBoundsTest, | 1758 INSTANTIATE_TEST_CASE_P(VisibleBounds, ShelfViewVisibleBoundsTest, |
| 1769 testing::Bool()); | 1759 testing::Bool()); |
| 1770 | 1760 |
| 1771 } // namespace test | 1761 } // namespace test |
| 1772 } // namespace ash | 1762 } // namespace ash |
| OLD | NEW |