| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 if (shelf_) | 62 if (shelf_) |
| 63 shelf_->AddIconObserver(this); | 63 shelf_->AddIconObserver(this); |
| 64 } | 64 } |
| 65 | 65 |
| 66 virtual ~TestShelfIconObserver() { | 66 virtual ~TestShelfIconObserver() { |
| 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 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 Shelf* shelf_; | 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 Shelf* shelf = Shelf::ForPrimaryDisplay(); | 93 Shelf* shelf = Shelf::ForPrimaryDisplay(); |
| 94 observer_.reset(new TestShelfIconObserver(shelf)); | 94 observer_.reset(new TestShelfIconObserver(shelf)); |
| 95 | 95 |
| 96 shelf_view_test_.reset( | 96 shelf_view_test_.reset( |
| 97 new ShelfViewTestAPI(ShelfTestAPI(shelf).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 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 131 | 131 |
| 132 // Resets to the initial state. | 132 // Resets to the initial state. |
| 133 void Reset() { selected_ = false; } | 133 void Reset() { selected_ = false; } |
| 134 | 134 |
| 135 // Returns true if the delegate was selected. | 135 // Returns true if the delegate was selected. |
| 136 bool WasSelected() { | 136 bool WasSelected() { |
| 137 return selected_; | 137 return selected_; |
| 138 } | 138 } |
| 139 | 139 |
| 140 // TestShelfItemDelegate: | 140 // TestShelfItemDelegate: |
| 141 virtual bool ItemSelected(const ui::Event& event) OVERRIDE { | 141 virtual bool ItemSelected(const ui::Event& event) override { |
| 142 selected_ = true; | 142 selected_ = true; |
| 143 return false; | 143 return false; |
| 144 } | 144 } |
| 145 | 145 |
| 146 private: | 146 private: |
| 147 bool selected_; | 147 bool selected_; |
| 148 | 148 |
| 149 DISALLOW_COPY_AND_ASSIGN(ShelfItemSelectionTracker); | 149 DISALLOW_COPY_AND_ASSIGN(ShelfItemSelectionTracker); |
| 150 }; | 150 }; |
| 151 | 151 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 | 229 |
| 230 // Simple ShelfDelegate implmentation for ShelfViewTest.OverflowBubbleSize | 230 // Simple ShelfDelegate implmentation for ShelfViewTest.OverflowBubbleSize |
| 231 // and CheckDragAndDropFromOverflowBubbleToShelf | 231 // and CheckDragAndDropFromOverflowBubbleToShelf |
| 232 class TestShelfDelegateForShelfView : public ShelfDelegate { | 232 class TestShelfDelegateForShelfView : public ShelfDelegate { |
| 233 public: | 233 public: |
| 234 explicit TestShelfDelegateForShelfView(ShelfModel* model) | 234 explicit TestShelfDelegateForShelfView(ShelfModel* model) |
| 235 : model_(model) {} | 235 : model_(model) {} |
| 236 virtual ~TestShelfDelegateForShelfView() {} | 236 virtual ~TestShelfDelegateForShelfView() {} |
| 237 | 237 |
| 238 // ShelfDelegate overrides: | 238 // ShelfDelegate overrides: |
| 239 virtual void OnShelfCreated(Shelf* shelf) OVERRIDE {} | 239 virtual void OnShelfCreated(Shelf* shelf) override {} |
| 240 | 240 |
| 241 virtual void OnShelfDestroyed(Shelf* shelf) OVERRIDE {} | 241 virtual void OnShelfDestroyed(Shelf* shelf) override {} |
| 242 | 242 |
| 243 virtual ShelfID GetShelfIDForAppID(const std::string& app_id) OVERRIDE { | 243 virtual ShelfID GetShelfIDForAppID(const std::string& app_id) override { |
| 244 ShelfID id = 0; | 244 ShelfID id = 0; |
| 245 EXPECT_TRUE(base::StringToInt(app_id, &id)); | 245 EXPECT_TRUE(base::StringToInt(app_id, &id)); |
| 246 return id; | 246 return id; |
| 247 } | 247 } |
| 248 | 248 |
| 249 virtual const std::string& GetAppIDForShelfID(ShelfID id) OVERRIDE { | 249 virtual const std::string& GetAppIDForShelfID(ShelfID id) override { |
| 250 // Use |app_id_| member variable because returning a reference to local | 250 // Use |app_id_| member variable because returning a reference to local |
| 251 // variable is not allowed. | 251 // variable is not allowed. |
| 252 app_id_ = base::IntToString(id); | 252 app_id_ = base::IntToString(id); |
| 253 return app_id_; | 253 return app_id_; |
| 254 } | 254 } |
| 255 | 255 |
| 256 virtual void PinAppWithID(const std::string& app_id) OVERRIDE { | 256 virtual void PinAppWithID(const std::string& app_id) override { |
| 257 } | 257 } |
| 258 | 258 |
| 259 virtual bool IsAppPinned(const std::string& app_id) OVERRIDE { | 259 virtual bool IsAppPinned(const std::string& app_id) override { |
| 260 // Returns true for ShelfViewTest.OverflowBubbleSize. To test ripping off in | 260 // Returns true for ShelfViewTest.OverflowBubbleSize. To test ripping off in |
| 261 // that test, an item is already pinned state. | 261 // that test, an item is already pinned state. |
| 262 return true; | 262 return true; |
| 263 } | 263 } |
| 264 | 264 |
| 265 virtual bool CanPin() const OVERRIDE { | 265 virtual bool CanPin() const override { |
| 266 return true; | 266 return true; |
| 267 } | 267 } |
| 268 | 268 |
| 269 virtual void UnpinAppWithID(const std::string& app_id) OVERRIDE { | 269 virtual void UnpinAppWithID(const std::string& app_id) override { |
| 270 ShelfID id = 0; | 270 ShelfID id = 0; |
| 271 EXPECT_TRUE(base::StringToInt(app_id, &id)); | 271 EXPECT_TRUE(base::StringToInt(app_id, &id)); |
| 272 ASSERT_GT(id, 0); | 272 ASSERT_GT(id, 0); |
| 273 int index = model_->ItemIndexByID(id); | 273 int index = model_->ItemIndexByID(id); |
| 274 ASSERT_GE(index, 0); | 274 ASSERT_GE(index, 0); |
| 275 | 275 |
| 276 model_->RemoveItemAt(index); | 276 model_->RemoveItemAt(index); |
| 277 } | 277 } |
| 278 | 278 |
| 279 private: | 279 private: |
| 280 ShelfModel* model_; | 280 ShelfModel* model_; |
| 281 | 281 |
| 282 // Temp member variable for returning a value. See the comment in the | 282 // Temp member variable for returning a value. See the comment in the |
| 283 // GetAppIDForShelfID(). | 283 // GetAppIDForShelfID(). |
| 284 std::string app_id_; | 284 std::string app_id_; |
| 285 | 285 |
| 286 DISALLOW_COPY_AND_ASSIGN(TestShelfDelegateForShelfView); | 286 DISALLOW_COPY_AND_ASSIGN(TestShelfDelegateForShelfView); |
| 287 }; | 287 }; |
| 288 | 288 |
| 289 class ShelfViewTest : public AshTestBase { | 289 class ShelfViewTest : public AshTestBase { |
| 290 public: | 290 public: |
| 291 ShelfViewTest() | 291 ShelfViewTest() |
| 292 : model_(NULL), | 292 : model_(NULL), |
| 293 shelf_view_(NULL), | 293 shelf_view_(NULL), |
| 294 browser_index_(1), | 294 browser_index_(1), |
| 295 item_manager_(NULL) {} | 295 item_manager_(NULL) {} |
| 296 virtual ~ShelfViewTest() {} | 296 virtual ~ShelfViewTest() {} |
| 297 | 297 |
| 298 virtual void SetUp() OVERRIDE { | 298 virtual void SetUp() override { |
| 299 CommandLine::ForCurrentProcess()->AppendSwitch( | 299 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 300 switches::kEnableTouchFeedback); | 300 switches::kEnableTouchFeedback); |
| 301 AshTestBase::SetUp(); | 301 AshTestBase::SetUp(); |
| 302 test::ShellTestApi test_api(Shell::GetInstance()); | 302 test::ShellTestApi test_api(Shell::GetInstance()); |
| 303 model_ = test_api.shelf_model(); | 303 model_ = test_api.shelf_model(); |
| 304 Shelf* shelf = Shelf::ForPrimaryDisplay(); | 304 Shelf* shelf = Shelf::ForPrimaryDisplay(); |
| 305 shelf_view_ = ShelfTestAPI(shelf).shelf_view(); | 305 shelf_view_ = ShelfTestAPI(shelf).shelf_view(); |
| 306 | 306 |
| 307 // The bounds should be big enough for 4 buttons + overflow chevron. | 307 // The bounds should be big enough for 4 buttons + overflow chevron. |
| 308 shelf_view_->SetBounds(0, 0, 500, kShelfSize); | 308 shelf_view_->SetBounds(0, 0, 500, kShelfSize); |
| 309 | 309 |
| 310 test_api_.reset(new ShelfViewTestAPI(shelf_view_)); | 310 test_api_.reset(new ShelfViewTestAPI(shelf_view_)); |
| 311 test_api_->SetAnimationDuration(1); // Speeds up animation for test. | 311 test_api_->SetAnimationDuration(1); // Speeds up animation for test. |
| 312 | 312 |
| 313 item_manager_ = Shell::GetInstance()->shelf_item_delegate_manager(); | 313 item_manager_ = Shell::GetInstance()->shelf_item_delegate_manager(); |
| 314 DCHECK(item_manager_); | 314 DCHECK(item_manager_); |
| 315 | 315 |
| 316 // Add browser shortcut shelf item at index 0 for test. | 316 // Add browser shortcut shelf item at index 0 for test. |
| 317 AddBrowserShortcut(); | 317 AddBrowserShortcut(); |
| 318 } | 318 } |
| 319 | 319 |
| 320 virtual void TearDown() OVERRIDE { | 320 virtual void TearDown() override { |
| 321 test_api_.reset(); | 321 test_api_.reset(); |
| 322 AshTestBase::TearDown(); | 322 AshTestBase::TearDown(); |
| 323 } | 323 } |
| 324 | 324 |
| 325 protected: | 325 protected: |
| 326 void CreateAndSetShelfItemDelegateForID(ShelfID id) { | 326 void CreateAndSetShelfItemDelegateForID(ShelfID id) { |
| 327 scoped_ptr<ShelfItemDelegate> delegate(new TestShelfItemDelegate(NULL)); | 327 scoped_ptr<ShelfItemDelegate> delegate(new TestShelfItemDelegate(NULL)); |
| 328 item_manager_->SetShelfItemDelegate(id, delegate.Pass()); | 328 item_manager_->SetShelfItemDelegate(id, delegate.Pass()); |
| 329 } | 329 } |
| 330 | 330 |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 std::string original_locale_; | 656 std::string original_locale_; |
| 657 }; | 657 }; |
| 658 | 658 |
| 659 class ShelfViewTextDirectionTest | 659 class ShelfViewTextDirectionTest |
| 660 : public ShelfViewTest, | 660 : public ShelfViewTest, |
| 661 public testing::WithParamInterface<bool> { | 661 public testing::WithParamInterface<bool> { |
| 662 public: | 662 public: |
| 663 ShelfViewTextDirectionTest() : text_direction_change_(GetParam()) {} | 663 ShelfViewTextDirectionTest() : text_direction_change_(GetParam()) {} |
| 664 virtual ~ShelfViewTextDirectionTest() {} | 664 virtual ~ShelfViewTextDirectionTest() {} |
| 665 | 665 |
| 666 virtual void SetUp() OVERRIDE { | 666 virtual void SetUp() override { |
| 667 ShelfViewTest::SetUp(); | 667 ShelfViewTest::SetUp(); |
| 668 } | 668 } |
| 669 | 669 |
| 670 virtual void TearDown() OVERRIDE { | 670 virtual void TearDown() override { |
| 671 ShelfViewTest::TearDown(); | 671 ShelfViewTest::TearDown(); |
| 672 } | 672 } |
| 673 | 673 |
| 674 private: | 674 private: |
| 675 ScopedTextDirectionChange text_direction_change_; | 675 ScopedTextDirectionChange text_direction_change_; |
| 676 | 676 |
| 677 DISALLOW_COPY_AND_ASSIGN(ShelfViewTextDirectionTest); | 677 DISALLOW_COPY_AND_ASSIGN(ShelfViewTextDirectionTest); |
| 678 }; | 678 }; |
| 679 | 679 |
| 680 // Checks that the ideal item icon bounds match the view's bounds in the screen | 680 // Checks that the ideal item icon bounds match the view's bounds in the screen |
| (...skipping 1082 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1763 test_api_->RunMessageLoopUntilAnimationsDone(); | 1763 test_api_->RunMessageLoopUntilAnimationsDone(); |
| 1764 CheckAllItemsAreInBounds(); | 1764 CheckAllItemsAreInBounds(); |
| 1765 } | 1765 } |
| 1766 | 1766 |
| 1767 INSTANTIATE_TEST_CASE_P(LtrRtl, ShelfViewTextDirectionTest, testing::Bool()); | 1767 INSTANTIATE_TEST_CASE_P(LtrRtl, ShelfViewTextDirectionTest, testing::Bool()); |
| 1768 INSTANTIATE_TEST_CASE_P(VisibleBounds, ShelfViewVisibleBoundsTest, | 1768 INSTANTIATE_TEST_CASE_P(VisibleBounds, ShelfViewVisibleBoundsTest, |
| 1769 testing::Bool()); | 1769 testing::Bool()); |
| 1770 | 1770 |
| 1771 } // namespace test | 1771 } // namespace test |
| 1772 } // namespace ash | 1772 } // namespace ash |
| OLD | NEW |