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

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

Issue 492963008: Ash: Double-clicking on a shelf item now opens the item (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « ash/shelf/shelf_view.cc ('k') | ash/test/shelf_view_test_api.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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/ash_switches.h" 10 #include "ash/ash_switches.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 122
123 // TestShelfItemDelegate which tracks whether it gets selected. 123 // TestShelfItemDelegate which tracks whether it gets selected.
124 class ShelfItemSelectionTracker : public TestShelfItemDelegate { 124 class ShelfItemSelectionTracker : public TestShelfItemDelegate {
125 public: 125 public:
126 ShelfItemSelectionTracker() : TestShelfItemDelegate(NULL), selected_(false) { 126 ShelfItemSelectionTracker() : TestShelfItemDelegate(NULL), selected_(false) {
127 } 127 }
128 128
129 virtual ~ShelfItemSelectionTracker() { 129 virtual ~ShelfItemSelectionTracker() {
130 } 130 }
131 131
132 // Resets to the initial state.
133 void Reset() { selected_ = false; }
134
132 // Returns true if the delegate was selected. 135 // Returns true if the delegate was selected.
133 bool WasSelected() { 136 bool WasSelected() {
134 return selected_; 137 return selected_;
135 } 138 }
136 139
137 // TestShelfItemDelegate: 140 // TestShelfItemDelegate:
138 virtual bool ItemSelected(const ui::Event& event) OVERRIDE { 141 virtual bool ItemSelected(const ui::Event& event) OVERRIDE {
139 selected_ = true; 142 selected_ = true;
140 return false; 143 return false;
141 } 144 }
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 281
279 // 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
280 // GetAppIDForShelfID(). 283 // GetAppIDForShelfID().
281 std::string app_id_; 284 std::string app_id_;
282 285
283 DISALLOW_COPY_AND_ASSIGN(TestShelfDelegateForShelfView); 286 DISALLOW_COPY_AND_ASSIGN(TestShelfDelegateForShelfView);
284 }; 287 };
285 288
286 class ShelfViewTest : public AshTestBase { 289 class ShelfViewTest : public AshTestBase {
287 public: 290 public:
288 ShelfViewTest() : model_(NULL), shelf_view_(NULL), browser_index_(1) {} 291 ShelfViewTest()
292 : model_(NULL),
293 shelf_view_(NULL),
294 browser_index_(1),
295 item_manager_(NULL) {}
289 virtual ~ShelfViewTest() {} 296 virtual ~ShelfViewTest() {}
290 297
291 virtual void SetUp() OVERRIDE { 298 virtual void SetUp() OVERRIDE {
292 AshTestBase::SetUp(); 299 AshTestBase::SetUp();
293 test::ShellTestApi test_api(Shell::GetInstance()); 300 test::ShellTestApi test_api(Shell::GetInstance());
294 model_ = test_api.shelf_model(); 301 model_ = test_api.shelf_model();
295 Shelf* shelf = Shelf::ForPrimaryDisplay(); 302 Shelf* shelf = Shelf::ForPrimaryDisplay();
296 shelf_view_ = ShelfTestAPI(shelf).shelf_view(); 303 shelf_view_ = ShelfTestAPI(shelf).shelf_view();
297 304
298 // The bounds should be big enough for 4 buttons + overflow chevron. 305 // The bounds should be big enough for 4 buttons + overflow chevron.
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 ShelfItem item = model_->items()[model_index]; 407 ShelfItem item = model_->items()[model_index];
401 ShelfID id = item.id; 408 ShelfID id = item.id;
402 EXPECT_EQ(id_map[map_index].first, id); 409 EXPECT_EQ(id_map[map_index].first, id);
403 EXPECT_EQ(id_map[map_index].second, GetButtonByID(id)); 410 EXPECT_EQ(id_map[map_index].second, GetButtonByID(id));
404 ++map_index; 411 ++map_index;
405 } 412 }
406 ASSERT_EQ(map_index, id_map.size()); 413 ASSERT_EQ(map_index, id_map.size());
407 } 414 }
408 415
409 void VerifyShelfItemBoundsAreValid() { 416 void VerifyShelfItemBoundsAreValid() {
410 for (int i=0;i <= test_api_->GetLastVisibleIndex(); ++i) { 417 for (int i = 0; i <= test_api_->GetLastVisibleIndex(); ++i) {
411 if (test_api_->GetButton(i)) { 418 if (test_api_->GetButton(i)) {
412 gfx::Rect shelf_view_bounds = shelf_view_->GetLocalBounds(); 419 gfx::Rect shelf_view_bounds = shelf_view_->GetLocalBounds();
413 gfx::Rect item_bounds = test_api_->GetBoundsByIndex(i); 420 gfx::Rect item_bounds = test_api_->GetBoundsByIndex(i);
414 EXPECT_GE(item_bounds.x(), 0); 421 EXPECT_GE(item_bounds.x(), 0);
415 EXPECT_GE(item_bounds.y(), 0); 422 EXPECT_GE(item_bounds.y(), 0);
416 EXPECT_LE(item_bounds.right(), shelf_view_bounds.width()); 423 EXPECT_LE(item_bounds.right(), shelf_view_bounds.width());
417 EXPECT_LE(item_bounds.bottom(), shelf_view_bounds.height()); 424 EXPECT_LE(item_bounds.bottom(), shelf_view_bounds.height());
418 } 425 }
419 } 426 }
420 } 427 }
421 428
422 views::View* SimulateButtonPressed(ShelfButtonHost::Pointer pointer, 429 ShelfButton* SimulateButtonPressed(ShelfButtonHost::Pointer pointer,
423 int button_index) { 430 int button_index) {
424 ShelfButtonHost* button_host = shelf_view_; 431 ShelfButtonHost* button_host = shelf_view_;
425 views::View* button = test_api_->GetButton(button_index); 432 ShelfButton* button = test_api_->GetButton(button_index);
426 ui::MouseEvent click_event(ui::ET_MOUSE_PRESSED, 433 ui::MouseEvent click_event(ui::ET_MOUSE_PRESSED,
427 gfx::Point(), 434 gfx::Point(),
428 button->GetBoundsInScreen().origin(), 0, 0); 435 button->GetBoundsInScreen().origin(), 0, 0);
429 button_host->PointerPressedOnButton(button, pointer, click_event); 436 button_host->PointerPressedOnButton(button, pointer, click_event);
430 return button; 437 return button;
431 } 438 }
432 439
433 views::View* SimulateClick(ShelfButtonHost::Pointer pointer, 440 // Simulates a single mouse click.
434 int button_index) { 441 void SimulateClick(int button_index) {
435 ShelfButtonHost* button_host = shelf_view_; 442 ShelfButtonHost* button_host = shelf_view_;
436 views::View* button = SimulateButtonPressed(pointer, button_index); 443 ShelfButton* button =
444 SimulateButtonPressed(ShelfButtonHost::MOUSE, button_index);
445 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED,
446 gfx::Point(),
447 button->GetBoundsInScreen().origin(),
448 0,
449 0);
450 test_api_->ButtonPressed(button, release_event);
437 button_host->PointerReleasedOnButton(button, ShelfButtonHost::MOUSE, false); 451 button_host->PointerReleasedOnButton(button, ShelfButtonHost::MOUSE, false);
438 return button; 452 }
453
454 // Simulates the second click of a double click.
455 void SimulateDoubleClick(int button_index) {
456 ShelfButtonHost* button_host = shelf_view_;
457 ShelfButton* button =
458 SimulateButtonPressed(ShelfButtonHost::MOUSE, button_index);
459 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED,
460 gfx::Point(),
461 button->GetBoundsInScreen().origin(),
462 ui::EF_IS_DOUBLE_CLICK,
463 0);
464 test_api_->ButtonPressed(button, release_event);
465 button_host->PointerReleasedOnButton(button, ShelfButtonHost::MOUSE, false);
439 } 466 }
440 467
441 views::View* SimulateDrag(ShelfButtonHost::Pointer pointer, 468 views::View* SimulateDrag(ShelfButtonHost::Pointer pointer,
442 int button_index, 469 int button_index,
443 int destination_index) { 470 int destination_index) {
444 ShelfButtonHost* button_host = shelf_view_; 471 ShelfButtonHost* button_host = shelf_view_;
445 views::View* button = SimulateButtonPressed(pointer, button_index); 472 views::View* button = SimulateButtonPressed(pointer, button_index);
446 473
447 // Drag. 474 // Drag.
448 views::View* destination = test_api_->GetButton(destination_index); 475 views::View* destination = test_api_->GetButton(destination_index);
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 ShelfItemDelegateManager* item_manager_; 626 ShelfItemDelegateManager* item_manager_;
600 627
601 scoped_ptr<ShelfViewTestAPI> test_api_; 628 scoped_ptr<ShelfViewTestAPI> test_api_;
602 629
603 private: 630 private:
604 DISALLOW_COPY_AND_ASSIGN(ShelfViewTest); 631 DISALLOW_COPY_AND_ASSIGN(ShelfViewTest);
605 }; 632 };
606 633
607 class ScopedTextDirectionChange { 634 class ScopedTextDirectionChange {
608 public: 635 public:
609 ScopedTextDirectionChange(bool is_rtl) 636 explicit ScopedTextDirectionChange(bool is_rtl) : is_rtl_(is_rtl) {
610 : is_rtl_(is_rtl) {
611 original_locale_ = l10n_util::GetApplicationLocale(std::string()); 637 original_locale_ = l10n_util::GetApplicationLocale(std::string());
612 if (is_rtl_) 638 if (is_rtl_)
613 base::i18n::SetICUDefaultLocale("he"); 639 base::i18n::SetICUDefaultLocale("he");
614 CheckTextDirectionIsCorrect(); 640 CheckTextDirectionIsCorrect();
615 } 641 }
616 642
617 ~ScopedTextDirectionChange() { 643 ~ScopedTextDirectionChange() {
618 if (is_rtl_) 644 if (is_rtl_)
619 base::i18n::SetICUDefaultLocale(original_locale_); 645 base::i18n::SetICUDefaultLocale(original_locale_);
620 } 646 }
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
1036 1062
1037 // Check that clicking first on one item and then dragging another works as 1063 // Check that clicking first on one item and then dragging another works as
1038 // expected. 1064 // expected.
1039 TEST_F(ShelfViewTest, ClickOneDragAnother) { 1065 TEST_F(ShelfViewTest, ClickOneDragAnother) {
1040 ShelfButtonHost* button_host = shelf_view_; 1066 ShelfButtonHost* button_host = shelf_view_;
1041 1067
1042 std::vector<std::pair<ShelfID, views::View*> > id_map; 1068 std::vector<std::pair<ShelfID, views::View*> > id_map;
1043 SetupForDragTest(&id_map); 1069 SetupForDragTest(&id_map);
1044 1070
1045 // A click on item 1 is simulated. 1071 // A click on item 1 is simulated.
1046 SimulateClick(ShelfButtonHost::MOUSE, 1); 1072 SimulateClick(1);
1047 1073
1048 // Dragging browser index at 0 should change the model order correctly. 1074 // Dragging browser index at 0 should change the model order correctly.
1049 EXPECT_TRUE(model_->items()[1].type == TYPE_BROWSER_SHORTCUT); 1075 EXPECT_TRUE(model_->items()[1].type == TYPE_BROWSER_SHORTCUT);
1050 views::View* dragged_button = SimulateDrag(ShelfButtonHost::MOUSE, 1, 3); 1076 views::View* dragged_button = SimulateDrag(ShelfButtonHost::MOUSE, 1, 3);
1051 std::rotate(id_map.begin() + 1, 1077 std::rotate(id_map.begin() + 1,
1052 id_map.begin() + 2, 1078 id_map.begin() + 2,
1053 id_map.begin() + 4); 1079 id_map.begin() + 4);
1054 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map)); 1080 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(id_map));
1055 button_host->PointerReleasedOnButton( 1081 button_host->PointerReleasedOnButton(
1056 dragged_button, ShelfButtonHost::MOUSE, false); 1082 dragged_button, ShelfButtonHost::MOUSE, false);
1057 EXPECT_TRUE(model_->items()[3].type == TYPE_BROWSER_SHORTCUT); 1083 EXPECT_TRUE(model_->items()[3].type == TYPE_BROWSER_SHORTCUT);
1058 } 1084 }
1059 1085
1086 // Tests that double-clicking an item does not activate it twice.
1087 TEST_F(ShelfViewTest, ClickingTwiceActivatesOnce) {
1088 // Watch for selection of the browser shortcut.
1089 ShelfID browser_shelf_id = model_->items()[browser_index_].id;
1090 ShelfItemSelectionTracker* selection_tracker = new ShelfItemSelectionTracker;
1091 item_manager_->SetShelfItemDelegate(
1092 browser_shelf_id,
1093 scoped_ptr<ShelfItemDelegate>(selection_tracker).Pass());
1094
1095 // A single click selects the item.
1096 SimulateClick(browser_index_);
1097 EXPECT_TRUE(selection_tracker->WasSelected());
1098
1099 // A double-click does not select the item.
1100 selection_tracker->Reset();
1101 SimulateDoubleClick(browser_index_);
1102 EXPECT_FALSE(selection_tracker->WasSelected());
1103 }
1104
1060 // Check that clicking an item and jittering the mouse a bit still selects the 1105 // Check that clicking an item and jittering the mouse a bit still selects the
1061 // item. 1106 // item.
1062 TEST_F(ShelfViewTest, ClickAndMoveSlightly) { 1107 TEST_F(ShelfViewTest, ClickAndMoveSlightly) {
1063 std::vector<std::pair<ShelfID, views::View*> > id_map; 1108 std::vector<std::pair<ShelfID, views::View*> > id_map;
1064 SetupForDragTest(&id_map); 1109 SetupForDragTest(&id_map);
1065 1110
1066 ShelfID shelf_id = (id_map.begin() + 1)->first; 1111 ShelfID shelf_id = (id_map.begin() + 1)->first;
1067 views::View* button = (id_map.begin() + 1)->second; 1112 views::View* button = (id_map.begin() + 1)->second;
1068 1113
1069 // Replace the ShelfItemDelegate for |shelf_id| with one which tracks whether 1114 // Replace the ShelfItemDelegate for |shelf_id| with one which tracks whether
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
1669 test_api_->RunMessageLoopUntilAnimationsDone(); 1714 test_api_->RunMessageLoopUntilAnimationsDone();
1670 CheckAllItemsAreInBounds(); 1715 CheckAllItemsAreInBounds();
1671 } 1716 }
1672 1717
1673 INSTANTIATE_TEST_CASE_P(LtrRtl, ShelfViewTextDirectionTest, testing::Bool()); 1718 INSTANTIATE_TEST_CASE_P(LtrRtl, ShelfViewTextDirectionTest, testing::Bool());
1674 INSTANTIATE_TEST_CASE_P(VisibleBounds, ShelfViewVisibleBoundsTest, 1719 INSTANTIATE_TEST_CASE_P(VisibleBounds, ShelfViewVisibleBoundsTest,
1675 testing::Bool()); 1720 testing::Bool());
1676 1721
1677 } // namespace test 1722 } // namespace test
1678 } // namespace ash 1723 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_view.cc ('k') | ash/test/shelf_view_test_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698