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

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

Issue 1260453006: ui: events: Add a class to hold common touch and stylus properties (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address build problems, add accessor and unit tests. Created 5 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
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 <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 EXPECT_LE(item_bounds.right(), shelf_view_bounds.width()); 436 EXPECT_LE(item_bounds.right(), shelf_view_bounds.width());
437 EXPECT_LE(item_bounds.bottom(), shelf_view_bounds.height()); 437 EXPECT_LE(item_bounds.bottom(), shelf_view_bounds.height());
438 } 438 }
439 } 439 }
440 } 440 }
441 441
442 ShelfButton* SimulateButtonPressed(ShelfButtonHost::Pointer pointer, 442 ShelfButton* SimulateButtonPressed(ShelfButtonHost::Pointer pointer,
443 int button_index) { 443 int button_index) {
444 ShelfButtonHost* button_host = shelf_view_; 444 ShelfButtonHost* button_host = shelf_view_;
445 ShelfButton* button = test_api_->GetButton(button_index); 445 ShelfButton* button = test_api_->GetButton(button_index);
446 ui::MouseEvent click_event(ui::ET_MOUSE_PRESSED, gfx::Point(), 446 ui::MouseEvent click_event(
447 button->GetBoundsInScreen().origin(), 447 ui::ET_MOUSE_PRESSED, gfx::Point(),
448 ui::EventTimeForNow(), 0, 0); 448 button->GetBoundsInScreen().origin(), ui::EventTimeForNow(), 0, 0,
449 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
449 button_host->PointerPressedOnButton(button, pointer, click_event); 450 button_host->PointerPressedOnButton(button, pointer, click_event);
450 return button; 451 return button;
451 } 452 }
452 453
453 // Simulates a single mouse click. 454 // Simulates a single mouse click.
454 void SimulateClick(int button_index) { 455 void SimulateClick(int button_index) {
455 ShelfButtonHost* button_host = shelf_view_; 456 ShelfButtonHost* button_host = shelf_view_;
456 ShelfButton* button = 457 ShelfButton* button =
457 SimulateButtonPressed(ShelfButtonHost::MOUSE, button_index); 458 SimulateButtonPressed(ShelfButtonHost::MOUSE, button_index);
458 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, gfx::Point(), 459 ui::MouseEvent release_event(
459 button->GetBoundsInScreen().origin(), 460 ui::ET_MOUSE_RELEASED, gfx::Point(),
460 ui::EventTimeForNow(), 0, 0); 461 button->GetBoundsInScreen().origin(), ui::EventTimeForNow(), 0, 0,
462 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
461 test_api_->ButtonPressed(button, release_event); 463 test_api_->ButtonPressed(button, release_event);
462 button_host->PointerReleasedOnButton(button, ShelfButtonHost::MOUSE, false); 464 button_host->PointerReleasedOnButton(button, ShelfButtonHost::MOUSE, false);
463 } 465 }
464 466
465 // Simulates the second click of a double click. 467 // Simulates the second click of a double click.
466 void SimulateDoubleClick(int button_index) { 468 void SimulateDoubleClick(int button_index) {
467 ShelfButtonHost* button_host = shelf_view_; 469 ShelfButtonHost* button_host = shelf_view_;
468 ShelfButton* button = 470 ShelfButton* button =
469 SimulateButtonPressed(ShelfButtonHost::MOUSE, button_index); 471 SimulateButtonPressed(ShelfButtonHost::MOUSE, button_index);
470 ui::MouseEvent release_event(ui::ET_MOUSE_RELEASED, gfx::Point(), 472 ui::MouseEvent release_event(
471 button->GetBoundsInScreen().origin(), 473 ui::ET_MOUSE_RELEASED, gfx::Point(),
472 ui::EventTimeForNow(), ui::EF_IS_DOUBLE_CLICK, 474 button->GetBoundsInScreen().origin(), ui::EventTimeForNow(),
473 0); 475 ui::EF_IS_DOUBLE_CLICK, 0,
476 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
474 test_api_->ButtonPressed(button, release_event); 477 test_api_->ButtonPressed(button, release_event);
475 button_host->PointerReleasedOnButton(button, ShelfButtonHost::MOUSE, false); 478 button_host->PointerReleasedOnButton(button, ShelfButtonHost::MOUSE, false);
476 } 479 }
477 480
478 views::View* SimulateDrag(ShelfButtonHost::Pointer pointer, 481 views::View* SimulateDrag(ShelfButtonHost::Pointer pointer,
479 int button_index, 482 int button_index,
480 int destination_index) { 483 int destination_index) {
481 ShelfButtonHost* button_host = shelf_view_; 484 ShelfButtonHost* button_host = shelf_view_;
482 views::View* button = SimulateButtonPressed(pointer, button_index); 485 views::View* button = SimulateButtonPressed(pointer, button_index);
483 486
484 // Drag. 487 // Drag.
485 views::View* destination = test_api_->GetButton(destination_index); 488 views::View* destination = test_api_->GetButton(destination_index);
486 ui::MouseEvent drag_event( 489 ui::MouseEvent drag_event(
487 ui::ET_MOUSE_DRAGGED, gfx::Point(destination->x() - button->x(), 490 ui::ET_MOUSE_DRAGGED, gfx::Point(destination->x() - button->x(),
488 destination->y() - button->y()), 491 destination->y() - button->y()),
489 destination->GetBoundsInScreen().origin(), ui::EventTimeForNow(), 0, 0); 492 destination->GetBoundsInScreen().origin(), ui::EventTimeForNow(), 0, 0,
493 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
490 button_host->PointerDraggedOnButton(button, pointer, drag_event); 494 button_host->PointerDraggedOnButton(button, pointer, drag_event);
491 return button; 495 return button;
492 } 496 }
493 497
494 void SetupForDragTest( 498 void SetupForDragTest(
495 std::vector<std::pair<ShelfID, views::View*> >* id_map) { 499 std::vector<std::pair<ShelfID, views::View*> >* id_map) {
496 // Initialize |id_map| with the automatically-created shelf buttons. 500 // Initialize |id_map| with the automatically-created shelf buttons.
497 for (size_t i = 0; i < model_->items().size(); ++i) { 501 for (size_t i = 0; i < model_->items().size(); ++i) {
498 ShelfButton* button = test_api_->GetButton(i); 502 ShelfButton* button = test_api_->GetButton(i);
499 id_map->push_back(std::make_pair(model_->items()[i].id, button)); 503 id_map->push_back(std::make_pair(model_->items()[i].id, button));
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
1187 ShelfItemSelectionTracker* selection_tracker = new ShelfItemSelectionTracker; 1191 ShelfItemSelectionTracker* selection_tracker = new ShelfItemSelectionTracker;
1188 item_manager_->SetShelfItemDelegate( 1192 item_manager_->SetShelfItemDelegate(
1189 shelf_id, 1193 shelf_id,
1190 scoped_ptr<ShelfItemDelegate>(selection_tracker).Pass()); 1194 scoped_ptr<ShelfItemDelegate>(selection_tracker).Pass());
1191 1195
1192 gfx::Vector2d press_offset(5, 30); 1196 gfx::Vector2d press_offset(5, 30);
1193 gfx::Point press_location = gfx::Point() + press_offset; 1197 gfx::Point press_location = gfx::Point() + press_offset;
1194 gfx::Point press_location_in_screen = 1198 gfx::Point press_location_in_screen =
1195 button->GetBoundsInScreen().origin() + press_offset; 1199 button->GetBoundsInScreen().origin() + press_offset;
1196 1200
1197 ui::MouseEvent click_event(ui::ET_MOUSE_PRESSED, press_location, 1201 ui::MouseEvent click_event(
1198 press_location_in_screen, ui::EventTimeForNow(), 1202 ui::ET_MOUSE_PRESSED, press_location, press_location_in_screen,
1199 ui::EF_LEFT_MOUSE_BUTTON, 0); 1203 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0,
1204 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
1200 button->OnMousePressed(click_event); 1205 button->OnMousePressed(click_event);
1201 1206
1202 ui::MouseEvent drag_event1( 1207 ui::MouseEvent drag_event1(
1203 ui::ET_MOUSE_DRAGGED, press_location + gfx::Vector2d(0, 1), 1208 ui::ET_MOUSE_DRAGGED, press_location + gfx::Vector2d(0, 1),
1204 press_location_in_screen + gfx::Vector2d(0, 1), ui::EventTimeForNow(), 1209 press_location_in_screen + gfx::Vector2d(0, 1), ui::EventTimeForNow(),
1205 ui::EF_LEFT_MOUSE_BUTTON, 0); 1210 ui::EF_LEFT_MOUSE_BUTTON, 0,
1211 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
1206 button->OnMouseDragged(drag_event1); 1212 button->OnMouseDragged(drag_event1);
1207 1213
1208 ui::MouseEvent drag_event2( 1214 ui::MouseEvent drag_event2(
1209 ui::ET_MOUSE_DRAGGED, press_location + gfx::Vector2d(-1, 0), 1215 ui::ET_MOUSE_DRAGGED, press_location + gfx::Vector2d(-1, 0),
1210 press_location_in_screen + gfx::Vector2d(-1, 0), ui::EventTimeForNow(), 1216 press_location_in_screen + gfx::Vector2d(-1, 0), ui::EventTimeForNow(),
1211 ui::EF_LEFT_MOUSE_BUTTON, 0); 1217 ui::EF_LEFT_MOUSE_BUTTON, 0,
1218 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
1212 button->OnMouseDragged(drag_event2); 1219 button->OnMouseDragged(drag_event2);
1213 1220
1214 ui::MouseEvent release_event( 1221 ui::MouseEvent release_event(
1215 ui::ET_MOUSE_RELEASED, press_location + gfx::Vector2d(-1, 0), 1222 ui::ET_MOUSE_RELEASED, press_location + gfx::Vector2d(-1, 0),
1216 press_location_in_screen + gfx::Vector2d(-1, 0), ui::EventTimeForNow(), 1223 press_location_in_screen + gfx::Vector2d(-1, 0), ui::EventTimeForNow(),
1217 ui::EF_LEFT_MOUSE_BUTTON, 0); 1224 ui::EF_LEFT_MOUSE_BUTTON, 0,
1225 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
1218 button->OnMouseReleased(release_event); 1226 button->OnMouseReleased(release_event);
1219 1227
1220 EXPECT_TRUE(selection_tracker->WasSelected()); 1228 EXPECT_TRUE(selection_tracker->WasSelected());
1221 } 1229 }
1222 1230
1223 // Confirm that item status changes are reflected in the buttons. 1231 // Confirm that item status changes are reflected in the buttons.
1224 TEST_F(ShelfViewTest, ShelfItemStatus) { 1232 TEST_F(ShelfViewTest, ShelfItemStatus) {
1225 // All buttons should be visible. 1233 // All buttons should be visible.
1226 ASSERT_EQ(test_api_->GetButtonCount(), 1234 ASSERT_EQ(test_api_->GetButtonCount(),
1227 test_api_->GetLastVisibleIndex() + 1); 1235 test_api_->GetLastVisibleIndex() + 1);
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after
1885 test_api_->RunMessageLoopUntilAnimationsDone(); 1893 test_api_->RunMessageLoopUntilAnimationsDone();
1886 CheckAllItemsAreInBounds(); 1894 CheckAllItemsAreInBounds();
1887 } 1895 }
1888 1896
1889 INSTANTIATE_TEST_CASE_P(LtrRtl, ShelfViewTextDirectionTest, testing::Bool()); 1897 INSTANTIATE_TEST_CASE_P(LtrRtl, ShelfViewTextDirectionTest, testing::Bool());
1890 INSTANTIATE_TEST_CASE_P(VisibleBounds, ShelfViewVisibleBoundsTest, 1898 INSTANTIATE_TEST_CASE_P(VisibleBounds, ShelfViewVisibleBoundsTest,
1891 testing::Bool()); 1899 testing::Bool());
1892 1900
1893 } // namespace test 1901 } // namespace test
1894 } // namespace ash 1902 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_view.cc ('k') | ash/shelf/shelf_widget_unittest.cc » ('j') | ui/events/event.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698