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

Side by Side Diff: ui/views/animation/ink_drop_animation_controller_factory_unittest.cc

Issue 1878973002: [reland] Makes MaterialDesignController initialization explicit (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Made it possible to restore MaterialDesignController state after each test case (nits) Created 4 years, 8 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "ui/views/animation/ink_drop_animation_controller_factory.h" 5 #include "ui/views/animation/ink_drop_animation_controller_factory.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/test/test_mock_time_task_runner.h" 10 #include "base/test/test_mock_time_task_runner.h"
(...skipping 28 matching lines...) Expand all
39 39
40 private: 40 private:
41 // Extracts and returns the material design mode from the test parameters. 41 // Extracts and returns the material design mode from the test parameters.
42 ui::MaterialDesignController::Mode GetMaterialMode() const; 42 ui::MaterialDesignController::Mode GetMaterialMode() const;
43 43
44 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> zero_duration_mode_; 44 std::unique_ptr<ui::ScopedAnimationDurationScaleMode> zero_duration_mode_;
45 45
46 // Required by base::Timer's. 46 // Required by base::Timer's.
47 std::unique_ptr<base::ThreadTaskRunnerHandle> thread_task_runner_handle_; 47 std::unique_ptr<base::ThreadTaskRunnerHandle> thread_task_runner_handle_;
48 48
49 std::unique_ptr<ui::test::MaterialDesignControllerTestAPI>
50 material_design_state_;
51
49 DISALLOW_COPY_AND_ASSIGN(InkDropAnimationControllerFactoryTest); 52 DISALLOW_COPY_AND_ASSIGN(InkDropAnimationControllerFactoryTest);
50 }; 53 };
51 54
52 InkDropAnimationControllerFactoryTest::InkDropAnimationControllerFactoryTest() 55 InkDropAnimationControllerFactoryTest::InkDropAnimationControllerFactoryTest()
53 : ink_drop_animation_controller_(nullptr) { 56 : ink_drop_animation_controller_(nullptr) {
54 // Any call by a previous test to MaterialDesignController::GetMode() will 57 // Any call by a previous test to MaterialDesignController::GetMode() will
55 // initialize and cache the mode. This ensures that these tests will run from 58 // initialize and cache the mode. This ensures that these tests will run from
56 // a non-initialized state. 59 // a non-initialized state.
57 ui::test::MaterialDesignControllerTestAPI::UninitializeMode(); 60 material_design_state_.reset(
58 ui::test::MaterialDesignControllerTestAPI::SetMode(GetMaterialMode()); 61 new ui::test::MaterialDesignControllerTestAPI(GetMaterialMode()));
59 ink_drop_animation_controller_.reset( 62 ink_drop_animation_controller_.reset(
60 InkDropAnimationControllerFactory::CreateInkDropAnimationController( 63 InkDropAnimationControllerFactory::CreateInkDropAnimationController(
61 &test_ink_drop_host_) 64 &test_ink_drop_host_)
62 .release()); 65 .release());
63 66
64 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( 67 zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode(
65 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); 68 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION));
66 69
67 switch (GetMaterialMode()) { 70 switch (GetMaterialMode()) {
68 case ui::MaterialDesignController::NON_MATERIAL: 71 case ui::MaterialDesignController::NON_MATERIAL:
69 break; 72 break;
70 case ui::MaterialDesignController::MATERIAL_NORMAL: 73 case ui::MaterialDesignController::MATERIAL_NORMAL:
71 case ui::MaterialDesignController::MATERIAL_HYBRID: 74 case ui::MaterialDesignController::MATERIAL_HYBRID:
72 // The Timer's used by the InkDropAnimationControllerImpl class require a 75 // The Timer's used by the InkDropAnimationControllerImpl class require a
73 // base::ThreadTaskRunnerHandle instance. 76 // base::ThreadTaskRunnerHandle instance.
74 scoped_refptr<base::TestMockTimeTaskRunner> task_runner( 77 scoped_refptr<base::TestMockTimeTaskRunner> task_runner(
75 new base::TestMockTimeTaskRunner); 78 new base::TestMockTimeTaskRunner);
76 thread_task_runner_handle_.reset( 79 thread_task_runner_handle_.reset(
77 new base::ThreadTaskRunnerHandle(task_runner)); 80 new base::ThreadTaskRunnerHandle(task_runner));
78 break; 81 break;
79 } 82 }
80 } 83 }
81 84
82 InkDropAnimationControllerFactoryTest:: 85 InkDropAnimationControllerFactoryTest::
83 ~InkDropAnimationControllerFactoryTest() { 86 ~InkDropAnimationControllerFactoryTest() {
84 ui::test::MaterialDesignControllerTestAPI::UninitializeMode(); 87 material_design_state_.reset();
85 } 88 }
86 89
87 ui::MaterialDesignController::Mode 90 ui::MaterialDesignController::Mode
88 InkDropAnimationControllerFactoryTest::GetMaterialMode() const { 91 InkDropAnimationControllerFactoryTest::GetMaterialMode() const {
89 return testing::get<0>(GetParam()); 92 return testing::get<0>(GetParam());
90 } 93 }
91 94
92 // Note: First argument is optional and intentionally left blank. 95 // Note: First argument is optional and intentionally left blank.
93 // (it's a prefix for the generated test cases) 96 // (it's a prefix for the generated test cases)
94 INSTANTIATE_TEST_CASE_P( 97 INSTANTIATE_TEST_CASE_P(
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING); 159 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTION_PENDING);
157 ink_drop_animation_controller_->AnimateToState( 160 ink_drop_animation_controller_->AnimateToState(
158 InkDropState::ALTERNATE_ACTION_PENDING); 161 InkDropState::ALTERNATE_ACTION_PENDING);
159 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTIVATED); 162 ink_drop_animation_controller_->AnimateToState(InkDropState::ACTIVATED);
160 ink_drop_animation_controller_->AnimateToState(InkDropState::DEACTIVATED); 163 ink_drop_animation_controller_->AnimateToState(InkDropState::DEACTIVATED);
161 EXPECT_EQ(InkDropState::HIDDEN, 164 EXPECT_EQ(InkDropState::HIDDEN,
162 ink_drop_animation_controller_->GetTargetInkDropState()); 165 ink_drop_animation_controller_->GetTargetInkDropState());
163 } 166 }
164 167
165 } // namespace views 168 } // namespace views
OLDNEW
« no previous file with comments | « ui/shell_dialogs/run_all_unittests.cc ('k') | ui/views/controls/button/label_button_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698