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

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

Issue 1372253002: gfx: Make conversions from gfx::Point to PointF explicit. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pointfconvert-gfx: . Created 5 years, 2 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::PointF(),
448 ui::EventTimeForNow(), 0, 0); 448 gfx::PointF(button->GetBoundsInScreen().origin()),
449 ui::EventTimeForNow(), 0, 0);
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::PointF(),
460 ui::EventTimeForNow(), 0, 0); 461 gfx::PointF(button->GetBoundsInScreen().origin()),
462 ui::EventTimeForNow(), 0, 0);
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::PointF(),
472 ui::EventTimeForNow(), ui::EF_IS_DOUBLE_CLICK, 474 gfx::PointF(button->GetBoundsInScreen().origin()),
473 0); 475 ui::EventTimeForNow(), ui::EF_IS_DOUBLE_CLICK, 0);
474 test_api_->ButtonPressed(button, release_event); 476 test_api_->ButtonPressed(button, release_event);
475 button_host->PointerReleasedOnButton(button, ShelfButtonHost::MOUSE, false); 477 button_host->PointerReleasedOnButton(button, ShelfButtonHost::MOUSE, false);
476 } 478 }
477 479
478 views::View* SimulateDrag(ShelfButtonHost::Pointer pointer, 480 views::View* SimulateDrag(ShelfButtonHost::Pointer pointer,
479 int button_index, 481 int button_index,
480 int destination_index) { 482 int destination_index) {
481 ShelfButtonHost* button_host = shelf_view_; 483 ShelfButtonHost* button_host = shelf_view_;
482 views::View* button = SimulateButtonPressed(pointer, button_index); 484 views::View* button = SimulateButtonPressed(pointer, button_index);
483 485
484 // Drag. 486 // Drag.
485 views::View* destination = test_api_->GetButton(destination_index); 487 views::View* destination = test_api_->GetButton(destination_index);
486 ui::MouseEvent drag_event( 488 ui::MouseEvent drag_event(
487 ui::ET_MOUSE_DRAGGED, gfx::Point(destination->x() - button->x(), 489 ui::ET_MOUSE_DRAGGED, gfx::PointF(destination->x() - button->x(),
488 destination->y() - button->y()), 490 destination->y() - button->y()),
489 destination->GetBoundsInScreen().origin(), ui::EventTimeForNow(), 0, 0); 491 gfx::PointF(destination->GetBoundsInScreen().origin()),
492 ui::EventTimeForNow(), 0, 0);
490 button_host->PointerDraggedOnButton(button, pointer, drag_event); 493 button_host->PointerDraggedOnButton(button, pointer, drag_event);
491 return button; 494 return button;
492 } 495 }
493 496
494 void SetupForDragTest( 497 void SetupForDragTest(
495 std::vector<std::pair<ShelfID, views::View*> >* id_map) { 498 std::vector<std::pair<ShelfID, views::View*> >* id_map) {
496 // Initialize |id_map| with the automatically-created shelf buttons. 499 // Initialize |id_map| with the automatically-created shelf buttons.
497 for (size_t i = 0; i < model_->items().size(); ++i) { 500 for (size_t i = 0; i < model_->items().size(); ++i) {
498 ShelfButton* button = test_api_->GetButton(i); 501 ShelfButton* button = test_api_->GetButton(i);
499 id_map->push_back(std::make_pair(model_->items()[i].id, button)); 502 id_map->push_back(std::make_pair(model_->items()[i].id, button));
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 ShelfID shelf_id = (id_map.begin() + 1)->first; 1185 ShelfID shelf_id = (id_map.begin() + 1)->first;
1183 views::View* button = (id_map.begin() + 1)->second; 1186 views::View* button = (id_map.begin() + 1)->second;
1184 1187
1185 // Replace the ShelfItemDelegate for |shelf_id| with one which tracks whether 1188 // Replace the ShelfItemDelegate for |shelf_id| with one which tracks whether
1186 // the shelf item gets selected. 1189 // the shelf item gets selected.
1187 ShelfItemSelectionTracker* selection_tracker = new ShelfItemSelectionTracker; 1190 ShelfItemSelectionTracker* selection_tracker = new ShelfItemSelectionTracker;
1188 item_manager_->SetShelfItemDelegate( 1191 item_manager_->SetShelfItemDelegate(
1189 shelf_id, 1192 shelf_id,
1190 scoped_ptr<ShelfItemDelegate>(selection_tracker).Pass()); 1193 scoped_ptr<ShelfItemDelegate>(selection_tracker).Pass());
1191 1194
1192 gfx::Vector2d press_offset(5, 30); 1195 gfx::Vector2dF press_offset(5.f, 30.f);
1193 gfx::Point press_location = gfx::Point() + press_offset; 1196 gfx::PointF press_location = gfx::PointF() + press_offset;
1194 gfx::Point press_location_in_screen = 1197 gfx::PointF press_location_in_screen =
1195 button->GetBoundsInScreen().origin() + press_offset; 1198 gfx::PointF(button->GetBoundsInScreen().origin()) + press_offset;
1196 1199
1197 ui::MouseEvent click_event(ui::ET_MOUSE_PRESSED, press_location, 1200 ui::MouseEvent click_event(ui::ET_MOUSE_PRESSED, press_location,
1198 press_location_in_screen, ui::EventTimeForNow(), 1201 press_location_in_screen, ui::EventTimeForNow(),
1199 ui::EF_LEFT_MOUSE_BUTTON, 0); 1202 ui::EF_LEFT_MOUSE_BUTTON, 0);
1200 button->OnMousePressed(click_event); 1203 button->OnMousePressed(click_event);
1201 1204
1202 ui::MouseEvent drag_event1( 1205 ui::MouseEvent drag_event1(
1203 ui::ET_MOUSE_DRAGGED, press_location + gfx::Vector2d(0, 1), 1206 ui::ET_MOUSE_DRAGGED, press_location + gfx::Vector2d(0, 1),
1204 press_location_in_screen + gfx::Vector2d(0, 1), ui::EventTimeForNow(), 1207 press_location_in_screen + gfx::Vector2dF(0.f, 1.f),
1205 ui::EF_LEFT_MOUSE_BUTTON, 0); 1208 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0);
1206 button->OnMouseDragged(drag_event1); 1209 button->OnMouseDragged(drag_event1);
1207 1210
1208 ui::MouseEvent drag_event2( 1211 ui::MouseEvent drag_event2(
1209 ui::ET_MOUSE_DRAGGED, press_location + gfx::Vector2d(-1, 0), 1212 ui::ET_MOUSE_DRAGGED, press_location + gfx::Vector2d(-1, 0),
1210 press_location_in_screen + gfx::Vector2d(-1, 0), ui::EventTimeForNow(), 1213 press_location_in_screen + gfx::Vector2dF(-1.f, 0.f),
1211 ui::EF_LEFT_MOUSE_BUTTON, 0); 1214 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0);
1212 button->OnMouseDragged(drag_event2); 1215 button->OnMouseDragged(drag_event2);
1213 1216
1214 ui::MouseEvent release_event( 1217 ui::MouseEvent release_event(
1215 ui::ET_MOUSE_RELEASED, press_location + gfx::Vector2d(-1, 0), 1218 ui::ET_MOUSE_RELEASED, press_location + gfx::Vector2d(-1, 0),
1216 press_location_in_screen + gfx::Vector2d(-1, 0), ui::EventTimeForNow(), 1219 press_location_in_screen + gfx::Vector2dF(-1.f, 0.f),
1217 ui::EF_LEFT_MOUSE_BUTTON, 0); 1220 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0);
1218 button->OnMouseReleased(release_event); 1221 button->OnMouseReleased(release_event);
1219 1222
1220 EXPECT_TRUE(selection_tracker->WasSelected()); 1223 EXPECT_TRUE(selection_tracker->WasSelected());
1221 } 1224 }
1222 1225
1223 // Confirm that item status changes are reflected in the buttons. 1226 // Confirm that item status changes are reflected in the buttons.
1224 TEST_F(ShelfViewTest, ShelfItemStatus) { 1227 TEST_F(ShelfViewTest, ShelfItemStatus) {
1225 // All buttons should be visible. 1228 // All buttons should be visible.
1226 ASSERT_EQ(test_api_->GetButtonCount(), 1229 ASSERT_EQ(test_api_->GetButtonCount(),
1227 test_api_->GetLastVisibleIndex() + 1); 1230 test_api_->GetLastVisibleIndex() + 1);
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after
1885 test_api_->RunMessageLoopUntilAnimationsDone(); 1888 test_api_->RunMessageLoopUntilAnimationsDone();
1886 CheckAllItemsAreInBounds(); 1889 CheckAllItemsAreInBounds();
1887 } 1890 }
1888 1891
1889 INSTANTIATE_TEST_CASE_P(LtrRtl, ShelfViewTextDirectionTest, testing::Bool()); 1892 INSTANTIATE_TEST_CASE_P(LtrRtl, ShelfViewTextDirectionTest, testing::Bool());
1890 INSTANTIATE_TEST_CASE_P(VisibleBounds, ShelfViewVisibleBoundsTest, 1893 INSTANTIATE_TEST_CASE_P(VisibleBounds, ShelfViewVisibleBoundsTest,
1891 testing::Bool()); 1894 testing::Bool());
1892 1895
1893 } // namespace test 1896 } // namespace test
1894 } // namespace ash 1897 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698