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

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

Issue 2528623003: Remove shelf_view_unittest's ScopedMockTaskRunnerWrapper copy. (Closed)
Patch Set: Remove redundant RunAllPendingInMessageLoop() and unnecessary code block. Created 4 years 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
« no previous file with comments | « no previous file | no next file » | 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/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 26 matching lines...) Expand all
37 #include "ash/test/overflow_bubble_view_test_api.h" 37 #include "ash/test/overflow_bubble_view_test_api.h"
38 #include "ash/test/shelf_view_test_api.h" 38 #include "ash/test/shelf_view_test_api.h"
39 #include "ash/test/test_shell_delegate.h" 39 #include "ash/test/test_shell_delegate.h"
40 #include "base/i18n/rtl.h" 40 #include "base/i18n/rtl.h"
41 #include "base/macros.h" 41 #include "base/macros.h"
42 #include "base/memory/ptr_util.h" 42 #include "base/memory/ptr_util.h"
43 #include "base/run_loop.h" 43 #include "base/run_loop.h"
44 #include "base/strings/string_number_conversions.h" 44 #include "base/strings/string_number_conversions.h"
45 #include "base/strings/utf_string_conversions.h" 45 #include "base/strings/utf_string_conversions.h"
46 #include "base/test/histogram_tester.h" 46 #include "base/test/histogram_tester.h"
47 #include "base/test/test_mock_time_task_runner.h" 47 #include "base/test/scoped_mock_time_message_loop_task_runner.h"
48 #include "base/test/user_action_tester.h" 48 #include "base/test/user_action_tester.h"
49 #include "base/threading/thread_task_runner_handle.h"
50 #include "base/time/time.h" 49 #include "base/time/time.h"
51 #include "testing/gmock/include/gmock/gmock.h" 50 #include "testing/gmock/include/gmock/gmock.h"
52 #include "ui/app_list/presenter/app_list_presenter.h" 51 #include "ui/app_list/presenter/app_list_presenter.h"
53 #include "ui/aura/test/aura_test_base.h" 52 #include "ui/aura/test/aura_test_base.h"
54 #include "ui/aura/window.h" 53 #include "ui/aura/window.h"
55 #include "ui/aura/window_event_dispatcher.h" 54 #include "ui/aura/window_event_dispatcher.h"
56 #include "ui/compositor/layer.h" 55 #include "ui/compositor/layer.h"
57 #include "ui/events/event.h" 56 #include "ui/events/event.h"
58 #include "ui/events/event_constants.h" 57 #include "ui/events/event_constants.h"
59 #include "ui/events/event_utils.h" 58 #include "ui/events/event_utils.h"
(...skipping 2538 matching lines...) Expand 10 before | Expand all | Expand 10 after
2598 ui::MenuModel* CreateContextMenu(WmShelf* wm_shelf, 2597 ui::MenuModel* CreateContextMenu(WmShelf* wm_shelf,
2599 const ShelfItem* item) override { 2598 const ShelfItem* item) override {
2600 // Caller takes ownership of the returned object. 2599 // Caller takes ownership of the returned object.
2601 return new TestShellMenuModel; 2600 return new TestShellMenuModel;
2602 } 2601 }
2603 2602
2604 private: 2603 private:
2605 DISALLOW_COPY_AND_ASSIGN(TestOverflowButtonShellDelegate); 2604 DISALLOW_COPY_AND_ASSIGN(TestOverflowButtonShellDelegate);
2606 }; 2605 };
2607 2606
2608 // A scoped wrapper around TestMockTimeTaskRunner that replaces message loop's
2609 // task runner with a TestMockTimeTaskRunner and resets it back at the end of
2610 // the scope.
2611 class ScopedMockTaskRunnerWrapper {
2612 public:
2613 ScopedMockTaskRunnerWrapper() {
2614 mock_task_runner_ = new base::TestMockTimeTaskRunner;
2615 previous_task_runner_ = base::ThreadTaskRunnerHandle::Get();
2616 base::MessageLoop::current()->SetTaskRunner(mock_task_runner_);
2617 }
2618
2619 ~ScopedMockTaskRunnerWrapper() {
2620 DCHECK_EQ(mock_task_runner_, base::ThreadTaskRunnerHandle::Get());
2621 mock_task_runner_->ClearPendingTasks();
2622 base::MessageLoop::current()->SetTaskRunner(previous_task_runner_);
2623 }
2624
2625 void FastForwardUntilNoTasksRemain() {
2626 mock_task_runner_->FastForwardUntilNoTasksRemain();
2627 }
2628
2629 private:
2630 scoped_refptr<base::TestMockTimeTaskRunner> mock_task_runner_;
2631 scoped_refptr<base::SingleThreadTaskRunner> previous_task_runner_;
2632
2633 DISALLOW_COPY_AND_ASSIGN(ScopedMockTaskRunnerWrapper);
2634 };
2635
2636 } // namespace 2607 } // namespace
2637 2608
2638 // Test fixture for testing material design ink drop on overflow button. 2609 // Test fixture for testing material design ink drop on overflow button.
2639 class OverflowButtonInkDropTest : public ShelfViewInkDropTest { 2610 class OverflowButtonInkDropTest : public ShelfViewInkDropTest {
2640 public: 2611 public:
2641 OverflowButtonInkDropTest() {} 2612 OverflowButtonInkDropTest() {}
2642 ~OverflowButtonInkDropTest() override {} 2613 ~OverflowButtonInkDropTest() override {}
2643 2614
2644 void SetUp() override { 2615 void SetUp() override {
2645 ShelfViewInkDropTest::SetUp(); 2616 ShelfViewInkDropTest::SetUp();
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
2884 IsEmpty()); 2855 IsEmpty());
2885 2856
2886 EXPECT_FALSE(test_api_->IsShowingOverflowBubble()); 2857 EXPECT_FALSE(test_api_->IsShowingOverflowBubble());
2887 } 2858 }
2888 2859
2889 // Tests ink drop state transitions for the overflow button when the user long 2860 // Tests ink drop state transitions for the overflow button when the user long
2890 // presses on the button to show the context menu. 2861 // presses on the button to show the context menu.
2891 TEST_F(OverflowButtonInkDropTest, TouchContextMenu) { 2862 TEST_F(OverflowButtonInkDropTest, TouchContextMenu) {
2892 ui::test::EventGenerator& generator = GetEventGenerator(); 2863 ui::test::EventGenerator& generator = GetEventGenerator();
2893 generator.set_current_location(GetScreenPointInsideOverflowButton()); 2864 generator.set_current_location(GetScreenPointInsideOverflowButton());
2865 base::ScopedMockTimeMessageLoopTaskRunner mock_task_runner;
James Cook 2016/11/28 23:05:15 Wow, I had no idea that ScopedMockTimeMessageLoopT
msw 2016/11/28 23:21:31 Neither did I; it came up in a review I did, and I
2894 2866
2895 RunAllPendingInMessageLoop(); 2867 generator.PressTouch();
2896 { 2868 EXPECT_EQ(views::InkDropState::ACTION_PENDING,
2897 ScopedMockTaskRunnerWrapper mock_task_runner; 2869 overflow_button_ink_drop_->GetTargetInkDropState());
2870 EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
2871 ElementsAre(views::InkDropState::ACTION_PENDING));
2898 2872
2899 generator.PressTouch(); 2873 mock_task_runner->FastForwardUntilNoTasksRemain();
2900 EXPECT_EQ(views::InkDropState::ACTION_PENDING, 2874 EXPECT_EQ(views::InkDropState::HIDDEN,
2901 overflow_button_ink_drop_->GetTargetInkDropState()); 2875 overflow_button_ink_drop_->GetTargetInkDropState());
2902 EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(), 2876 EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
2903 ElementsAre(views::InkDropState::ACTION_PENDING)); 2877 ElementsAre(views::InkDropState::ALTERNATE_ACTION_PENDING,
2878 views::InkDropState::HIDDEN));
2904 2879
2905 mock_task_runner.FastForwardUntilNoTasksRemain(); 2880 generator.ReleaseTouch();
2906 EXPECT_EQ(views::InkDropState::HIDDEN, 2881 EXPECT_EQ(views::InkDropState::HIDDEN,
2907 overflow_button_ink_drop_->GetTargetInkDropState()); 2882 overflow_button_ink_drop_->GetTargetInkDropState());
2908 EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(), 2883 EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
2909 ElementsAre(views::InkDropState::ALTERNATE_ACTION_PENDING, 2884 IsEmpty());
2910 views::InkDropState::HIDDEN));
2911 2885
2912 generator.ReleaseTouch(); 2886 EXPECT_FALSE(test_api_->IsShowingOverflowBubble());
2913 EXPECT_EQ(views::InkDropState::HIDDEN,
2914 overflow_button_ink_drop_->GetTargetInkDropState());
2915 EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
2916 IsEmpty());
2917
2918 EXPECT_FALSE(test_api_->IsShowingOverflowBubble());
2919 }
2920 } 2887 }
2921 2888
2922 #endif // !defined(OS_WIN) 2889 #endif // !defined(OS_WIN)
2923 2890
2924 // Test fixture for testing material design ink drop on overflow button when it 2891 // Test fixture for testing material design ink drop on overflow button when it
2925 // is active. 2892 // is active.
2926 class OverflowButtonActiveInkDropTest : public OverflowButtonInkDropTest { 2893 class OverflowButtonActiveInkDropTest : public OverflowButtonInkDropTest {
2927 public: 2894 public:
2928 OverflowButtonActiveInkDropTest() {} 2895 OverflowButtonActiveInkDropTest() {}
2929 ~OverflowButtonActiveInkDropTest() override {} 2896 ~OverflowButtonActiveInkDropTest() override {}
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
3129 IsEmpty()); 3096 IsEmpty());
3130 3097
3131 ASSERT_TRUE(test_api_->IsShowingOverflowBubble()); 3098 ASSERT_TRUE(test_api_->IsShowingOverflowBubble());
3132 } 3099 }
3133 3100
3134 // Tests ink drop state transitions for the overflow button when it is active 3101 // Tests ink drop state transitions for the overflow button when it is active
3135 // and the user long presses on the button to show the context menu. 3102 // and the user long presses on the button to show the context menu.
3136 TEST_F(OverflowButtonActiveInkDropTest, TouchContextMenu) { 3103 TEST_F(OverflowButtonActiveInkDropTest, TouchContextMenu) {
3137 ui::test::EventGenerator& generator = GetEventGenerator(); 3104 ui::test::EventGenerator& generator = GetEventGenerator();
3138 generator.set_current_location(GetScreenPointInsideOverflowButton()); 3105 generator.set_current_location(GetScreenPointInsideOverflowButton());
3106 base::ScopedMockTimeMessageLoopTaskRunner mock_task_runner;
3139 3107
3140 RunAllPendingInMessageLoop(); 3108 generator.PressTouch();
3141 { 3109 EXPECT_EQ(views::InkDropState::ACTIVATED,
3142 ScopedMockTaskRunnerWrapper mock_task_runner; 3110 overflow_button_ink_drop_->GetTargetInkDropState());
3111 EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
3112 IsEmpty());
3143 3113
3144 generator.PressTouch(); 3114 mock_task_runner->FastForwardUntilNoTasksRemain();
3145 EXPECT_EQ(views::InkDropState::ACTIVATED, 3115 EXPECT_EQ(views::InkDropState::ACTIVATED,
3146 overflow_button_ink_drop_->GetTargetInkDropState()); 3116 overflow_button_ink_drop_->GetTargetInkDropState());
3147 EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(), 3117 EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
3148 IsEmpty()); 3118 IsEmpty());
3149 3119
3150 mock_task_runner.FastForwardUntilNoTasksRemain(); 3120 generator.ReleaseTouch();
3151 EXPECT_EQ(views::InkDropState::ACTIVATED, 3121 EXPECT_EQ(views::InkDropState::ACTIVATED,
3152 overflow_button_ink_drop_->GetTargetInkDropState()); 3122 overflow_button_ink_drop_->GetTargetInkDropState());
3153 EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(), 3123 EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
3154 IsEmpty()); 3124 IsEmpty());
3155 3125
3156 generator.ReleaseTouch(); 3126 ASSERT_TRUE(test_api_->IsShowingOverflowBubble());
3157 EXPECT_EQ(views::InkDropState::ACTIVATED,
3158 overflow_button_ink_drop_->GetTargetInkDropState());
3159 EXPECT_THAT(overflow_button_ink_drop_->GetAndResetRequestedStates(),
3160 IsEmpty());
3161
3162 ASSERT_TRUE(test_api_->IsShowingOverflowBubble());
3163 }
3164 } 3127 }
3165 3128
3166 #endif // !defined(OS_WIN) 3129 #endif // !defined(OS_WIN)
3167 3130
3168 } // namespace test 3131 } // namespace test
3169 } // namespace ash 3132 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698