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/common/shelf/shelf_view.h" | 5 #include "ash/common/shelf/shelf_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <memory> | 8 #include <memory> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 19 matching lines...) Expand all Loading... |
30 #include "ash/root_window_controller.h" | 30 #include "ash/root_window_controller.h" |
31 #include "ash/shell.h" | 31 #include "ash/shell.h" |
32 #include "ash/test/ash_test_base.h" | 32 #include "ash/test/ash_test_base.h" |
33 #include "ash/test/ash_test_helper.h" | 33 #include "ash/test/ash_test_helper.h" |
34 #include "ash/test/overflow_bubble_view_test_api.h" | 34 #include "ash/test/overflow_bubble_view_test_api.h" |
35 #include "ash/test/shelf_view_test_api.h" | 35 #include "ash/test/shelf_view_test_api.h" |
36 #include "ash/test/test_shell_delegate.h" | 36 #include "ash/test/test_shell_delegate.h" |
37 #include "base/i18n/rtl.h" | 37 #include "base/i18n/rtl.h" |
38 #include "base/macros.h" | 38 #include "base/macros.h" |
39 #include "base/memory/ptr_util.h" | 39 #include "base/memory/ptr_util.h" |
| 40 #include "base/numerics/safe_conversions.h" |
40 #include "base/run_loop.h" | 41 #include "base/run_loop.h" |
41 #include "base/strings/string_number_conversions.h" | 42 #include "base/strings/string_number_conversions.h" |
42 #include "base/strings/utf_string_conversions.h" | 43 #include "base/strings/utf_string_conversions.h" |
43 #include "base/test/histogram_tester.h" | 44 #include "base/test/histogram_tester.h" |
44 #include "base/test/scoped_mock_time_message_loop_task_runner.h" | 45 #include "base/test/scoped_mock_time_message_loop_task_runner.h" |
45 #include "base/test/user_action_tester.h" | 46 #include "base/test/user_action_tester.h" |
46 #include "base/time/time.h" | 47 #include "base/time/time.h" |
47 #include "testing/gmock/include/gmock/gmock.h" | 48 #include "testing/gmock/include/gmock/gmock.h" |
48 #include "ui/app_list/presenter/app_list.h" | 49 #include "ui/app_list/presenter/app_list.h" |
49 #include "ui/aura/test/aura_test_base.h" | 50 #include "ui/aura/test/aura_test_base.h" |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 // value of IsAppPinned(...) is configurable. | 250 // value of IsAppPinned(...) is configurable. |
250 class TestShelfDelegateForShelfView : public TestShelfDelegate { | 251 class TestShelfDelegateForShelfView : public TestShelfDelegate { |
251 public: | 252 public: |
252 TestShelfDelegateForShelfView() {} | 253 TestShelfDelegateForShelfView() {} |
253 ~TestShelfDelegateForShelfView() override {} | 254 ~TestShelfDelegateForShelfView() override {} |
254 | 255 |
255 void set_is_app_pinned(bool is_pinned) { is_app_pinned_ = is_pinned; } | 256 void set_is_app_pinned(bool is_pinned) { is_app_pinned_ = is_pinned; } |
256 | 257 |
257 // ShelfDelegate overrides: | 258 // ShelfDelegate overrides: |
258 ShelfID GetShelfIDForAppID(const std::string& app_id) override { | 259 ShelfID GetShelfIDForAppID(const std::string& app_id) override { |
259 ShelfID id = 0; | 260 unsigned id = kInvalidShelfID; |
260 EXPECT_TRUE(base::StringToInt(app_id, &id)); | 261 EXPECT_TRUE(base::StringToUint(app_id, &id)); |
261 return id; | 262 return base::checked_cast<ShelfID>(id); |
262 } | 263 } |
263 | 264 |
264 bool HasShelfIDToAppIDMapping(ShelfID id) const override { return true; } | 265 bool HasShelfIDToAppIDMapping(ShelfID id) const override { return true; } |
265 | 266 |
266 const std::string& GetAppIDForShelfID(ShelfID id) override { | 267 const std::string& GetAppIDForShelfID(ShelfID id) override { |
267 // Use |app_id_| member variable because returning a reference to local | 268 // Use |app_id_| member variable because returning a reference to local |
268 // variable is not allowed. | 269 // variable is not allowed. |
269 app_id_ = base::IntToString(id); | 270 app_id_ = base::IntToString(id); |
270 return app_id_; | 271 return app_id_; |
271 } | 272 } |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 cur_index--) | 547 cur_index--) |
547 ContinueDrag(button, pointer, cur_index + 1, cur_index, true); | 548 ContinueDrag(button, pointer, cur_index + 1, cur_index, true); |
548 } | 549 } |
549 return button; | 550 return button; |
550 } | 551 } |
551 | 552 |
552 void DragAndVerify( | 553 void DragAndVerify( |
553 int from, | 554 int from, |
554 int to, | 555 int to, |
555 ShelfView* shelf_view, | 556 ShelfView* shelf_view, |
556 const std::vector<std::pair<int, views::View*>>& expected_id_map) { | 557 const std::vector<std::pair<ShelfID, views::View*>>& expected_id_map) { |
557 views::View* dragged_button = | 558 views::View* dragged_button = |
558 SimulateDrag(ShelfView::MOUSE, from, to, true); | 559 SimulateDrag(ShelfView::MOUSE, from, to, true); |
559 shelf_view->PointerReleasedOnButton(dragged_button, ShelfView::MOUSE, | 560 shelf_view->PointerReleasedOnButton(dragged_button, ShelfView::MOUSE, |
560 false); | 561 false); |
561 test_api_->RunMessageLoopUntilAnimationsDone(); | 562 test_api_->RunMessageLoopUntilAnimationsDone(); |
562 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(expected_id_map)); | 563 ASSERT_NO_FATAL_FAILURE(CheckModelIDs(expected_id_map)); |
563 } | 564 } |
564 | 565 |
565 void SetupForDragTest(std::vector<std::pair<ShelfID, views::View*>>* id_map) { | 566 void SetupForDragTest(std::vector<std::pair<ShelfID, views::View*>>* id_map) { |
566 // Initialize |id_map| with the automatically-created shelf buttons. | 567 // Initialize |id_map| with the automatically-created shelf buttons. |
(...skipping 25 matching lines...) Expand all Loading... |
592 | 593 |
593 void TestDraggingAnItemFromOverflowToShelf(bool cancel) { | 594 void TestDraggingAnItemFromOverflowToShelf(bool cancel) { |
594 test_api_->ShowOverflowBubble(); | 595 test_api_->ShowOverflowBubble(); |
595 ASSERT_TRUE(test_api_->IsShowingOverflowBubble()); | 596 ASSERT_TRUE(test_api_->IsShowingOverflowBubble()); |
596 | 597 |
597 ShelfViewTestAPI test_api_for_overflow( | 598 ShelfViewTestAPI test_api_for_overflow( |
598 test_api_->overflow_bubble()->shelf_view()); | 599 test_api_->overflow_bubble()->shelf_view()); |
599 | 600 |
600 int total_item_count = model_->item_count(); | 601 int total_item_count = model_->item_count(); |
601 | 602 |
602 int last_visible_item_id_in_shelf = | 603 ShelfID last_visible_item_id_in_shelf = |
603 GetItemId(test_api_->GetLastVisibleIndex()); | 604 GetItemId(test_api_->GetLastVisibleIndex()); |
604 int second_last_visible_item_id_in_shelf = | 605 ShelfID second_last_visible_item_id_in_shelf = |
605 GetItemId(test_api_->GetLastVisibleIndex() - 1); | 606 GetItemId(test_api_->GetLastVisibleIndex() - 1); |
606 int first_visible_item_id_in_overflow = | 607 ShelfID first_visible_item_id_in_overflow = |
607 GetItemId(test_api_for_overflow.GetFirstVisibleIndex()); | 608 GetItemId(test_api_for_overflow.GetFirstVisibleIndex()); |
608 int second_last_visible_item_id_in_overflow = | 609 ShelfID second_last_visible_item_id_in_overflow = |
609 GetItemId(test_api_for_overflow.GetLastVisibleIndex() - 1); | 610 GetItemId(test_api_for_overflow.GetLastVisibleIndex() - 1); |
610 | 611 |
611 int drag_item_index = test_api_for_overflow.GetLastVisibleIndex(); | 612 int drag_item_index = test_api_for_overflow.GetLastVisibleIndex(); |
612 ShelfID drag_item_id = GetItemId(drag_item_index); | 613 ShelfID drag_item_id = GetItemId(drag_item_index); |
613 ShelfButton* drag_button = test_api_for_overflow.GetButton(drag_item_index); | 614 ShelfButton* drag_button = test_api_for_overflow.GetButton(drag_item_index); |
614 gfx::Point center_point_of_drag_item = | 615 gfx::Point center_point_of_drag_item = |
615 drag_button->GetBoundsInScreen().CenterPoint(); | 616 drag_button->GetBoundsInScreen().CenterPoint(); |
616 | 617 |
617 ui::test::EventGenerator& generator = GetEventGenerator(); | 618 ui::test::EventGenerator& generator = GetEventGenerator(); |
618 generator.set_current_location(center_point_of_drag_item); | 619 generator.set_current_location(center_point_of_drag_item); |
(...skipping 2392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3011 EXPECT_EQ(views::InkDropState::ACTIVATED, | 3012 EXPECT_EQ(views::InkDropState::ACTIVATED, |
3012 overflow_button_ink_drop_->GetTargetInkDropState()); | 3013 overflow_button_ink_drop_->GetTargetInkDropState()); |
3013 EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(), | 3014 EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(), |
3014 IsEmpty()); | 3015 IsEmpty()); |
3015 | 3016 |
3016 ASSERT_TRUE(test_api_->IsShowingOverflowBubble()); | 3017 ASSERT_TRUE(test_api_->IsShowingOverflowBubble()); |
3017 } | 3018 } |
3018 | 3019 |
3019 } // namespace test | 3020 } // namespace test |
3020 } // namespace ash | 3021 } // namespace ash |
OLD | NEW |