| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_background_animator.h" | 5 #include "ash/common/shelf/shelf_background_animator.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "ash/common/shelf/shelf_background_animator_observer.h" | 9 #include "ash/common/shelf/shelf_background_animator_observer.h" |
| 10 #include "ash/common/shelf/shelf_constants.h" | 10 #include "ash/common/shelf/shelf_constants.h" |
| 11 #include "ash/common/test/material_design_controller_test_api.h" | |
| 12 #include "base/bind.h" | 11 #include "base/bind.h" |
| 13 #include "base/macros.h" | 12 #include "base/macros.h" |
| 14 #include "base/test/test_mock_time_task_runner.h" | 13 #include "base/test/test_mock_time_task_runner.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "ui/gfx/animation/slide_animation.h" |
| 17 | 17 |
| 18 namespace ash { | 18 namespace ash { |
| 19 | |
| 20 using test::MaterialDesignControllerTestAPI; | |
| 21 | |
| 22 namespace { | 19 namespace { |
| 23 | 20 |
| 24 const int kMaxAlpha = 255; | 21 const int kMaxAlpha = 255; |
| 25 | 22 |
| 26 // A valid alpha value that is distinct from any final animation state values. | 23 // A valid alpha value that is distinct from any final animation state values. |
| 27 // Used to check if alpha values are changed during animations. | 24 // Used to check if alpha values are changed during animations. |
| 28 const int kDummyAlpha = 111; | 25 const int kDummyAlpha = 111; |
| 29 | 26 |
| 30 // Observer that caches alpha values for the last observation. | 27 // Observer that caches alpha values for the last observation. |
| 31 class TestShelfBackgroundObserver : public ShelfBackgroundAnimatorObserver { | 28 class TestShelfBackgroundObserver : public ShelfBackgroundAnimatorObserver { |
| 32 public: | 29 public: |
| 33 TestShelfBackgroundObserver() {} | 30 TestShelfBackgroundObserver() {} |
| 34 ~TestShelfBackgroundObserver() override {} | 31 ~TestShelfBackgroundObserver() override {} |
| 35 | 32 |
| 36 int opaque_background_alpha() const { return opaque_background_alpha_; } | 33 int background_alpha() const { return background_alpha_; } |
| 37 | 34 |
| 38 int item_background_alpha() const { return item_background_alpha_; } | 35 int item_background_alpha() const { return item_background_alpha_; } |
| 39 | 36 |
| 40 // ShelfBackgroundObserver: | 37 // ShelfBackgroundObserver: |
| 41 void UpdateShelfOpaqueBackground(int alpha) override; | 38 void UpdateShelfBackground(int alpha) override; |
| 42 void UpdateShelfItemBackground(int alpha) override; | 39 void UpdateShelfItemBackground(int alpha) override; |
| 43 | 40 |
| 44 private: | 41 private: |
| 45 int opaque_background_alpha_ = 0; | 42 int background_alpha_ = 0; |
| 46 int item_background_alpha_ = 0; | 43 int item_background_alpha_ = 0; |
| 47 | 44 |
| 48 DISALLOW_COPY_AND_ASSIGN(TestShelfBackgroundObserver); | 45 DISALLOW_COPY_AND_ASSIGN(TestShelfBackgroundObserver); |
| 49 }; | 46 }; |
| 50 | 47 |
| 51 void TestShelfBackgroundObserver::UpdateShelfOpaqueBackground(int alpha) { | 48 void TestShelfBackgroundObserver::UpdateShelfBackground(int alpha) { |
| 52 opaque_background_alpha_ = alpha; | 49 background_alpha_ = alpha; |
| 53 } | 50 } |
| 54 | 51 |
| 55 void TestShelfBackgroundObserver::UpdateShelfItemBackground(int alpha) { | 52 void TestShelfBackgroundObserver::UpdateShelfItemBackground(int alpha) { |
| 56 item_background_alpha_ = alpha; | 53 item_background_alpha_ = alpha; |
| 57 } | 54 } |
| 58 | 55 |
| 59 } // namespace | 56 } // namespace |
| 60 | 57 |
| 61 // Provides internal access to a ShelfBackgroundAnimator instance. | 58 // Provides internal access to a ShelfBackgroundAnimator instance. |
| 62 class ShelfBackgroundAnimatorTestApi { | 59 class ShelfBackgroundAnimatorTestApi { |
| 63 public: | 60 public: |
| 64 explicit ShelfBackgroundAnimatorTestApi(ShelfBackgroundAnimator* animator) | 61 explicit ShelfBackgroundAnimatorTestApi(ShelfBackgroundAnimator* animator) |
| 65 : animator_(animator) {} | 62 : animator_(animator) {} |
| 66 | 63 |
| 67 ~ShelfBackgroundAnimatorTestApi() {} | 64 ~ShelfBackgroundAnimatorTestApi() {} |
| 68 | 65 |
| 69 ShelfBackgroundType previous_background_type() const { | 66 ShelfBackgroundType previous_background_type() const { |
| 70 return animator_->previous_background_type_; | 67 return animator_->previous_background_type_; |
| 71 } | 68 } |
| 72 | 69 |
| 73 BackgroundAnimator* opaque_background_animator() const { | 70 gfx::SlideAnimation* animator() const { return animator_->animator_.get(); } |
| 74 return animator_->opaque_background_animator_.get(); | |
| 75 } | |
| 76 | 71 |
| 77 BackgroundAnimator* item_background_animator() const { | 72 bool can_reuse_animator() const { return animator_->can_reuse_animator_; } |
| 78 return animator_->item_background_animator_.get(); | |
| 79 } | |
| 80 | |
| 81 bool can_reuse_animators() const { return animator_->can_reuse_animators_; } | |
| 82 | 73 |
| 83 private: | 74 private: |
| 84 // The instance to provide internal access to. | 75 // The instance to provide internal access to. |
| 85 ShelfBackgroundAnimator* animator_; | 76 ShelfBackgroundAnimator* animator_; |
| 86 | 77 |
| 87 DISALLOW_COPY_AND_ASSIGN(ShelfBackgroundAnimatorTestApi); | 78 DISALLOW_COPY_AND_ASSIGN(ShelfBackgroundAnimatorTestApi); |
| 88 }; | 79 }; |
| 89 | 80 |
| 90 // Note: this is not a parameterized test (like other MD tests) because the | 81 class ShelfBackgroundAnimatorTest : public testing::Test { |
| 91 // behavior is so different and not all tests need to be run for both MD and | |
| 92 // non-MD variants. | |
| 93 class ShelfBackgroundAnimatorTestBase : public testing::Test { | |
| 94 public: | 82 public: |
| 95 ShelfBackgroundAnimatorTestBase() {} | 83 ShelfBackgroundAnimatorTest() {} |
| 96 ~ShelfBackgroundAnimatorTestBase() override {} | 84 ~ShelfBackgroundAnimatorTest() override {} |
| 97 | |
| 98 virtual MaterialDesignController::Mode GetMaterialDesignMode() = 0; | |
| 99 | |
| 100 int expected_translucent_alpha() const { return expected_translucent_alpha_; } | |
| 101 | 85 |
| 102 // testing::Test: | 86 // testing::Test: |
| 103 void SetUp() override; | 87 void SetUp() override; |
| 104 | 88 |
| 105 protected: | 89 protected: |
| 106 // Convenience wrapper for |animator_|'s PaintBackground() that always uses | 90 // Convenience wrapper for |animator_|'s PaintBackground() that always uses |
| 107 // BACKGROUND_CHANGE_IMMEDIATE. | 91 // gfx::ANIMATION_CHANGE_IMMEDIATE. |
| 108 void PaintBackground(ShelfBackgroundType background_type); | 92 void PaintBackground(ShelfBackgroundType background_type); |
| 109 | 93 |
| 110 // Set all of the alpha values for the |observer_|. | 94 // Set all of the alpha values for the |observer_|. |
| 111 void SetAlphaValuesOnObserver(int alpha); | 95 void SetAlphaValuesOnObserver(int alpha); |
| 112 | 96 |
| 113 // Completes all the animations. | 97 // Completes all the animations. |
| 114 void CompleteAnimations(); | 98 void CompleteAnimations(); |
| 115 | 99 |
| 116 TestShelfBackgroundObserver observer_; | 100 TestShelfBackgroundObserver observer_; |
| 117 | 101 |
| 118 // Test target. | 102 // Test target. |
| 119 std::unique_ptr<ShelfBackgroundAnimator> animator_; | 103 std::unique_ptr<ShelfBackgroundAnimator> animator_; |
| 120 | 104 |
| 121 // Provides internal access to |animator_|. | 105 // Provides internal access to |animator_|. |
| 122 std::unique_ptr<ShelfBackgroundAnimatorTestApi> test_api_; | 106 std::unique_ptr<ShelfBackgroundAnimatorTestApi> test_api_; |
| 123 | 107 |
| 124 // Used to control the animations. | 108 // Used to control the animations. |
| 125 scoped_refptr<base::TestMockTimeTaskRunner> task_runner_; | 109 scoped_refptr<base::TestMockTimeTaskRunner> task_runner_; |
| 126 | 110 |
| 127 private: | 111 private: |
| 128 std::unique_ptr<base::ThreadTaskRunnerHandle> task_runner_handle_; | 112 std::unique_ptr<base::ThreadTaskRunnerHandle> task_runner_handle_; |
| 129 | 113 |
| 130 std::unique_ptr<MaterialDesignControllerTestAPI> material_mode_test_api_; | 114 DISALLOW_COPY_AND_ASSIGN(ShelfBackgroundAnimatorTest); |
| 131 | |
| 132 // The expected alpha value for translucent items. Cannot be a constant | |
| 133 // because it is different for material design and non-material. | |
| 134 int expected_translucent_alpha_ = 0; | |
| 135 | |
| 136 DISALLOW_COPY_AND_ASSIGN(ShelfBackgroundAnimatorTestBase); | |
| 137 }; | 115 }; |
| 138 | 116 |
| 139 void ShelfBackgroundAnimatorTestBase::SetUp() { | 117 void ShelfBackgroundAnimatorTest::SetUp() { |
| 140 task_runner_ = new base::TestMockTimeTaskRunner(); | 118 task_runner_ = new base::TestMockTimeTaskRunner(); |
| 141 task_runner_handle_.reset(new base::ThreadTaskRunnerHandle(task_runner_)); | 119 task_runner_handle_.reset(new base::ThreadTaskRunnerHandle(task_runner_)); |
| 142 | |
| 143 material_mode_test_api_.reset( | |
| 144 new MaterialDesignControllerTestAPI(GetMaterialDesignMode())); | |
| 145 animator_.reset( | 120 animator_.reset( |
| 146 new ShelfBackgroundAnimator(SHELF_BACKGROUND_DEFAULT, nullptr)); | 121 new ShelfBackgroundAnimator(SHELF_BACKGROUND_DEFAULT, nullptr)); |
| 147 animator_->AddObserver(&observer_); | 122 animator_->AddObserver(&observer_); |
| 148 | 123 |
| 149 test_api_.reset(new ShelfBackgroundAnimatorTestApi(animator_.get())); | 124 test_api_.reset(new ShelfBackgroundAnimatorTestApi(animator_.get())); |
| 150 | |
| 151 // Initialized after the Material Design mode because GetShelfConstant() | |
| 152 // depends on the mode. | |
| 153 expected_translucent_alpha_ = GetShelfConstant(SHELF_BACKGROUND_ALPHA); | |
| 154 } | 125 } |
| 155 | 126 |
| 156 void ShelfBackgroundAnimatorTestBase::PaintBackground( | 127 void ShelfBackgroundAnimatorTest::PaintBackground( |
| 157 ShelfBackgroundType background_type) { | 128 ShelfBackgroundType background_type) { |
| 158 animator_->PaintBackground(background_type, BACKGROUND_CHANGE_IMMEDIATE); | 129 animator_->PaintBackground(background_type, gfx::ANIMATION_CHANGE_IMMEDIATE); |
| 159 } | 130 } |
| 160 | 131 |
| 161 void ShelfBackgroundAnimatorTestBase::SetAlphaValuesOnObserver(int alpha) { | 132 void ShelfBackgroundAnimatorTest::SetAlphaValuesOnObserver(int alpha) { |
| 162 observer_.UpdateShelfOpaqueBackground(alpha); | 133 observer_.UpdateShelfBackground(alpha); |
| 163 observer_.UpdateShelfItemBackground(alpha); | 134 observer_.UpdateShelfItemBackground(alpha); |
| 164 } | 135 } |
| 165 | 136 |
| 166 void ShelfBackgroundAnimatorTestBase::CompleteAnimations() { | 137 void ShelfBackgroundAnimatorTest::CompleteAnimations() { |
| 167 task_runner_->FastForwardUntilNoTasksRemain(); | 138 task_runner_->FastForwardUntilNoTasksRemain(); |
| 168 } | 139 } |
| 169 | 140 |
| 170 class ShelfBackgroundAnimatorNonMDTest | |
| 171 : public ShelfBackgroundAnimatorTestBase { | |
| 172 public: | |
| 173 ShelfBackgroundAnimatorNonMDTest() {} | |
| 174 ~ShelfBackgroundAnimatorNonMDTest() override {} | |
| 175 | |
| 176 MaterialDesignController::Mode GetMaterialDesignMode() override { | |
| 177 return MaterialDesignController::NON_MATERIAL; | |
| 178 } | |
| 179 | |
| 180 private: | |
| 181 DISALLOW_COPY_AND_ASSIGN(ShelfBackgroundAnimatorNonMDTest); | |
| 182 }; | |
| 183 | |
| 184 // Verify the alpha values for the SHELF_BACKGROUND_DEFAULT state. | |
| 185 TEST_F(ShelfBackgroundAnimatorNonMDTest, DefaultBackground) { | |
| 186 PaintBackground(SHELF_BACKGROUND_DEFAULT); | |
| 187 | |
| 188 EXPECT_EQ(SHELF_BACKGROUND_DEFAULT, animator_->target_background_type()); | |
| 189 EXPECT_EQ(0, observer_.opaque_background_alpha()); | |
| 190 EXPECT_EQ(expected_translucent_alpha(), observer_.item_background_alpha()); | |
| 191 } | |
| 192 | |
| 193 // Verify the alpha values for the SHELF_BACKGROUND_OVERLAP state. | |
| 194 TEST_F(ShelfBackgroundAnimatorNonMDTest, OverlapBackground) { | |
| 195 PaintBackground(SHELF_BACKGROUND_OVERLAP); | |
| 196 | |
| 197 EXPECT_EQ(SHELF_BACKGROUND_OVERLAP, animator_->target_background_type()); | |
| 198 EXPECT_EQ(0, observer_.opaque_background_alpha()); | |
| 199 EXPECT_EQ(expected_translucent_alpha(), observer_.item_background_alpha()); | |
| 200 } | |
| 201 | |
| 202 // Verify the alpha values for the SHELF_BACKGROUND_MAXIMIZED state. | |
| 203 TEST_F(ShelfBackgroundAnimatorNonMDTest, MaximizedBackground) { | |
| 204 PaintBackground(SHELF_BACKGROUND_MAXIMIZED); | |
| 205 | |
| 206 EXPECT_EQ(SHELF_BACKGROUND_MAXIMIZED, animator_->target_background_type()); | |
| 207 EXPECT_EQ(kMaxAlpha, observer_.opaque_background_alpha()); | |
| 208 EXPECT_EQ(kMaxAlpha, observer_.item_background_alpha()); | |
| 209 } | |
| 210 | |
| 211 class ShelfBackgroundAnimatorMDTest : public ShelfBackgroundAnimatorTestBase { | |
| 212 public: | |
| 213 ShelfBackgroundAnimatorMDTest() {} | |
| 214 ~ShelfBackgroundAnimatorMDTest() override {} | |
| 215 | |
| 216 MaterialDesignController::Mode GetMaterialDesignMode() override { | |
| 217 return MaterialDesignController::MATERIAL_EXPERIMENTAL; | |
| 218 } | |
| 219 | |
| 220 private: | |
| 221 DISALLOW_COPY_AND_ASSIGN(ShelfBackgroundAnimatorMDTest); | |
| 222 }; | |
| 223 | |
| 224 // Verify the |previous_background_type_| and |target_background_type_| values | 141 // Verify the |previous_background_type_| and |target_background_type_| values |
| 225 // when animating to the same target type multiple times. | 142 // when animating to the same target type multiple times. |
| 226 TEST_F(ShelfBackgroundAnimatorMDTest, | 143 TEST_F(ShelfBackgroundAnimatorTest, BackgroundTypesWhenAnimatingToSameTarget) { |
| 227 BackgroundTypesWhenAnimatingToSameTarget) { | |
| 228 PaintBackground(SHELF_BACKGROUND_MAXIMIZED); | 144 PaintBackground(SHELF_BACKGROUND_MAXIMIZED); |
| 229 EXPECT_EQ(SHELF_BACKGROUND_MAXIMIZED, animator_->target_background_type()); | 145 EXPECT_EQ(SHELF_BACKGROUND_MAXIMIZED, animator_->target_background_type()); |
| 230 | 146 |
| 231 PaintBackground(SHELF_BACKGROUND_DEFAULT); | 147 PaintBackground(SHELF_BACKGROUND_DEFAULT); |
| 232 EXPECT_EQ(SHELF_BACKGROUND_DEFAULT, animator_->target_background_type()); | 148 EXPECT_EQ(SHELF_BACKGROUND_DEFAULT, animator_->target_background_type()); |
| 233 EXPECT_EQ(SHELF_BACKGROUND_MAXIMIZED, test_api_->previous_background_type()); | 149 EXPECT_EQ(SHELF_BACKGROUND_MAXIMIZED, test_api_->previous_background_type()); |
| 234 | 150 |
| 235 PaintBackground(SHELF_BACKGROUND_DEFAULT); | 151 PaintBackground(SHELF_BACKGROUND_DEFAULT); |
| 236 EXPECT_EQ(SHELF_BACKGROUND_DEFAULT, animator_->target_background_type()); | 152 EXPECT_EQ(SHELF_BACKGROUND_DEFAULT, animator_->target_background_type()); |
| 237 EXPECT_EQ(SHELF_BACKGROUND_MAXIMIZED, test_api_->previous_background_type()); | 153 EXPECT_EQ(SHELF_BACKGROUND_MAXIMIZED, test_api_->previous_background_type()); |
| 238 } | 154 } |
| 239 | 155 |
| 240 // Verify subsequent calls to PaintBackground() using the | 156 // Verify subsequent calls to PaintBackground() using the |
| 241 // BACKGROUND_CHANGE_ANIMATE change type are ignored. | 157 // gfx::ANIMATION_CHANGE_ANIMATE change type are ignored. |
| 242 TEST_F(ShelfBackgroundAnimatorMDTest, | 158 TEST_F(ShelfBackgroundAnimatorTest, |
| 243 MultipleAnimateCallsToSameTargetAreIgnored) { | 159 MultipleAnimateCallsToSameTargetAreIgnored) { |
| 244 PaintBackground(SHELF_BACKGROUND_MAXIMIZED); | 160 PaintBackground(SHELF_BACKGROUND_MAXIMIZED); |
| 245 SetAlphaValuesOnObserver(kDummyAlpha); | 161 SetAlphaValuesOnObserver(kDummyAlpha); |
| 246 animator_->PaintBackground(SHELF_BACKGROUND_DEFAULT, | 162 animator_->PaintBackground(SHELF_BACKGROUND_DEFAULT, |
| 247 BACKGROUND_CHANGE_ANIMATE); | 163 gfx::ANIMATION_CHANGE_ANIMATE); |
| 248 CompleteAnimations(); | 164 CompleteAnimations(); |
| 249 | 165 |
| 250 EXPECT_NE(observer_.opaque_background_alpha(), kDummyAlpha); | 166 EXPECT_NE(observer_.background_alpha(), kDummyAlpha); |
| 251 EXPECT_NE(observer_.item_background_alpha(), kDummyAlpha); | 167 EXPECT_NE(observer_.item_background_alpha(), kDummyAlpha); |
| 252 | 168 |
| 253 SetAlphaValuesOnObserver(kDummyAlpha); | 169 SetAlphaValuesOnObserver(kDummyAlpha); |
| 254 animator_->PaintBackground(SHELF_BACKGROUND_DEFAULT, | 170 animator_->PaintBackground(SHELF_BACKGROUND_DEFAULT, |
| 255 BACKGROUND_CHANGE_ANIMATE); | 171 gfx::ANIMATION_CHANGE_ANIMATE); |
| 256 CompleteAnimations(); | 172 CompleteAnimations(); |
| 257 | 173 |
| 258 EXPECT_EQ(observer_.opaque_background_alpha(), kDummyAlpha); | 174 EXPECT_EQ(observer_.background_alpha(), kDummyAlpha); |
| 259 EXPECT_EQ(observer_.item_background_alpha(), kDummyAlpha); | 175 EXPECT_EQ(observer_.item_background_alpha(), kDummyAlpha); |
| 260 } | 176 } |
| 261 | 177 |
| 262 // Verify observers are updated with the current values when they are added. | 178 // Verify observers are updated with the current values when they are added. |
| 263 TEST_F(ShelfBackgroundAnimatorMDTest, ObserversUpdatedWhenAdded) { | 179 TEST_F(ShelfBackgroundAnimatorTest, ObserversUpdatedWhenAdded) { |
| 264 animator_->RemoveObserver(&observer_); | 180 animator_->RemoveObserver(&observer_); |
| 265 SetAlphaValuesOnObserver(kDummyAlpha); | 181 SetAlphaValuesOnObserver(kDummyAlpha); |
| 266 | 182 |
| 267 animator_->AddObserver(&observer_); | 183 animator_->AddObserver(&observer_); |
| 268 | 184 |
| 269 EXPECT_NE(observer_.opaque_background_alpha(), kDummyAlpha); | 185 EXPECT_NE(observer_.background_alpha(), kDummyAlpha); |
| 270 EXPECT_NE(observer_.item_background_alpha(), kDummyAlpha); | 186 EXPECT_NE(observer_.item_background_alpha(), kDummyAlpha); |
| 271 } | 187 } |
| 272 | 188 |
| 273 // Verify the alpha values for the SHELF_BACKGROUND_DEFAULT state. | 189 // Verify the alpha values for the SHELF_BACKGROUND_DEFAULT state. |
| 274 TEST_F(ShelfBackgroundAnimatorMDTest, DefaultBackground) { | 190 TEST_F(ShelfBackgroundAnimatorTest, DefaultBackground) { |
| 275 PaintBackground(SHELF_BACKGROUND_DEFAULT); | 191 PaintBackground(SHELF_BACKGROUND_DEFAULT); |
| 276 | 192 |
| 277 EXPECT_EQ(SHELF_BACKGROUND_DEFAULT, animator_->target_background_type()); | 193 EXPECT_EQ(SHELF_BACKGROUND_DEFAULT, animator_->target_background_type()); |
| 278 EXPECT_EQ(0, observer_.opaque_background_alpha()); | 194 EXPECT_EQ(0, observer_.background_alpha()); |
| 279 EXPECT_EQ(expected_translucent_alpha(), observer_.item_background_alpha()); | 195 EXPECT_EQ(kShelfTranslucentAlpha, observer_.item_background_alpha()); |
| 280 } | 196 } |
| 281 | 197 |
| 282 // Verify the alpha values for the SHELF_BACKGROUND_OVERLAP state. | 198 // Verify the alpha values for the SHELF_BACKGROUND_OVERLAP state. |
| 283 TEST_F(ShelfBackgroundAnimatorMDTest, OverlapBackground) { | 199 TEST_F(ShelfBackgroundAnimatorTest, OverlapBackground) { |
| 284 PaintBackground(SHELF_BACKGROUND_OVERLAP); | 200 PaintBackground(SHELF_BACKGROUND_OVERLAP); |
| 285 | 201 |
| 286 EXPECT_EQ(SHELF_BACKGROUND_OVERLAP, animator_->target_background_type()); | 202 EXPECT_EQ(SHELF_BACKGROUND_OVERLAP, animator_->target_background_type()); |
| 287 EXPECT_EQ(expected_translucent_alpha(), observer_.opaque_background_alpha()); | 203 EXPECT_EQ(kShelfTranslucentAlpha, observer_.background_alpha()); |
| 288 EXPECT_EQ(0, observer_.item_background_alpha()); | 204 EXPECT_EQ(0, observer_.item_background_alpha()); |
| 289 } | 205 } |
| 290 | 206 |
| 291 // Verify the alpha values for the SHELF_BACKGROUND_MAXIMIZED state. | 207 // Verify the alpha values for the SHELF_BACKGROUND_MAXIMIZED state. |
| 292 TEST_F(ShelfBackgroundAnimatorMDTest, MaximizedBackground) { | 208 TEST_F(ShelfBackgroundAnimatorTest, MaximizedBackground) { |
| 293 PaintBackground(SHELF_BACKGROUND_MAXIMIZED); | 209 PaintBackground(SHELF_BACKGROUND_MAXIMIZED); |
| 294 | 210 |
| 295 EXPECT_EQ(SHELF_BACKGROUND_MAXIMIZED, animator_->target_background_type()); | 211 EXPECT_EQ(SHELF_BACKGROUND_MAXIMIZED, animator_->target_background_type()); |
| 296 EXPECT_EQ(kMaxAlpha, observer_.opaque_background_alpha()); | 212 EXPECT_EQ(kMaxAlpha, observer_.background_alpha()); |
| 297 EXPECT_EQ(0, observer_.item_background_alpha()); | 213 EXPECT_EQ(0, observer_.item_background_alpha()); |
| 298 } | 214 } |
| 299 | 215 |
| 300 // Verify that existing animators are used when animating to the previous state. | 216 // Verify that existing animator is used when animating to the previous state. |
| 301 TEST_F(ShelfBackgroundAnimatorMDTest, ExistingAnimatorsAreReused) { | 217 TEST_F(ShelfBackgroundAnimatorTest, ExistingAnimatorIsReused) { |
| 302 PaintBackground(SHELF_BACKGROUND_DEFAULT); | 218 PaintBackground(SHELF_BACKGROUND_DEFAULT); |
| 303 PaintBackground(SHELF_BACKGROUND_MAXIMIZED); | 219 PaintBackground(SHELF_BACKGROUND_MAXIMIZED); |
| 304 EXPECT_TRUE(test_api_->can_reuse_animators()); | 220 EXPECT_TRUE(test_api_->can_reuse_animator()); |
| 305 | 221 |
| 306 const BackgroundAnimator* opaque_animator = | 222 const gfx::SlideAnimation* animator = test_api_->animator(); |
| 307 test_api_->opaque_background_animator(); | |
| 308 const BackgroundAnimator* item_animator = | |
| 309 test_api_->item_background_animator(); | |
| 310 | 223 |
| 311 PaintBackground(SHELF_BACKGROUND_DEFAULT); | 224 PaintBackground(SHELF_BACKGROUND_DEFAULT); |
| 312 | 225 |
| 313 EXPECT_EQ(opaque_animator, test_api_->opaque_background_animator()); | 226 EXPECT_EQ(animator, test_api_->animator()); |
| 314 EXPECT_EQ(item_animator, test_api_->item_background_animator()); | |
| 315 } | 227 } |
| 316 | 228 |
| 317 // Verify that existing animators are not re-used when the previous animation | 229 // Verify that existing animator is not re-used when the previous animation |
| 318 // didn't complete. | 230 // didn't complete. |
| 319 TEST_F(ShelfBackgroundAnimatorMDTest, | 231 TEST_F(ShelfBackgroundAnimatorTest, |
| 320 ExistingAnimatorsNotReusedWhenPreviousAnimationsDontComplete) { | 232 ExistingAnimatorNotReusedWhenPreviousAnimationsDontComplete) { |
| 321 EXPECT_NE(SHELF_BACKGROUND_OVERLAP, test_api_->previous_background_type()); | 233 EXPECT_NE(SHELF_BACKGROUND_OVERLAP, test_api_->previous_background_type()); |
| 322 animator_->PaintBackground(SHELF_BACKGROUND_OVERLAP, | 234 animator_->PaintBackground(SHELF_BACKGROUND_OVERLAP, |
| 323 BACKGROUND_CHANGE_ANIMATE); | 235 gfx::ANIMATION_CHANGE_ANIMATE); |
| 324 animator_->PaintBackground(SHELF_BACKGROUND_MAXIMIZED, | 236 animator_->PaintBackground(SHELF_BACKGROUND_MAXIMIZED, |
| 325 BACKGROUND_CHANGE_ANIMATE); | 237 gfx::ANIMATION_CHANGE_ANIMATE); |
| 326 EXPECT_FALSE(test_api_->can_reuse_animators()); | 238 EXPECT_FALSE(test_api_->can_reuse_animator()); |
| 327 | 239 |
| 328 const BackgroundAnimator* opaque_animator = | 240 const gfx::SlideAnimation* animator = test_api_->animator(); |
| 329 test_api_->opaque_background_animator(); | |
| 330 const BackgroundAnimator* item_animator = | |
| 331 test_api_->item_background_animator(); | |
| 332 | 241 |
| 333 EXPECT_EQ(SHELF_BACKGROUND_OVERLAP, test_api_->previous_background_type()); | 242 EXPECT_EQ(SHELF_BACKGROUND_OVERLAP, test_api_->previous_background_type()); |
| 334 animator_->PaintBackground(SHELF_BACKGROUND_OVERLAP, | 243 animator_->PaintBackground(SHELF_BACKGROUND_OVERLAP, |
| 335 BACKGROUND_CHANGE_ANIMATE); | 244 gfx::ANIMATION_CHANGE_ANIMATE); |
| 336 | 245 |
| 337 EXPECT_NE(opaque_animator, test_api_->opaque_background_animator()); | 246 EXPECT_NE(animator, test_api_->animator()); |
| 338 EXPECT_NE(item_animator, test_api_->item_background_animator()); | |
| 339 } | 247 } |
| 340 | 248 |
| 341 // Verify that existing animators are not re-used when the target background | 249 // Verify that existing animator is not re-used when the target background isn't |
| 342 // isn't the same as the previous background. | 250 // the same as the previous background. |
| 343 TEST_F(ShelfBackgroundAnimatorMDTest, | 251 TEST_F(ShelfBackgroundAnimatorTest, |
| 344 ExistingAnimatorsNotReusedWhenTargetBackgroundNotPreviousBackground) { | 252 ExistingAnimatorNotReusedWhenTargetBackgroundNotPreviousBackground) { |
| 345 PaintBackground(SHELF_BACKGROUND_DEFAULT); | 253 PaintBackground(SHELF_BACKGROUND_DEFAULT); |
| 346 PaintBackground(SHELF_BACKGROUND_MAXIMIZED); | 254 PaintBackground(SHELF_BACKGROUND_MAXIMIZED); |
| 347 EXPECT_TRUE(test_api_->can_reuse_animators()); | 255 EXPECT_TRUE(test_api_->can_reuse_animator()); |
| 348 | 256 |
| 349 const BackgroundAnimator* opaque_animator = | 257 const gfx::SlideAnimation* animator = test_api_->animator(); |
| 350 test_api_->opaque_background_animator(); | |
| 351 const BackgroundAnimator* item_animator = | |
| 352 test_api_->item_background_animator(); | |
| 353 | 258 |
| 354 EXPECT_NE(SHELF_BACKGROUND_OVERLAP, test_api_->previous_background_type()); | 259 EXPECT_NE(SHELF_BACKGROUND_OVERLAP, test_api_->previous_background_type()); |
| 355 PaintBackground(SHELF_BACKGROUND_OVERLAP); | 260 PaintBackground(SHELF_BACKGROUND_OVERLAP); |
| 356 | 261 |
| 357 EXPECT_NE(opaque_animator, test_api_->opaque_background_animator()); | 262 EXPECT_NE(animator, test_api_->animator()); |
| 358 EXPECT_NE(item_animator, test_api_->item_background_animator()); | |
| 359 } | 263 } |
| 360 | 264 |
| 361 // Verify animators are not re-used after snapping to the same background type. | 265 // Verify animator is not re-used after snapping to the same background type. |
| 362 TEST_F(ShelfBackgroundAnimatorMDTest, | 266 TEST_F(ShelfBackgroundAnimatorTest, |
| 363 ExistingAnimatorsNotUsedWhenSnappingToSameTargetBackground) { | 267 ExistingAnimatorNotUsedWhenSnappingToSameTargetBackground) { |
| 364 PaintBackground(SHELF_BACKGROUND_DEFAULT); | 268 PaintBackground(SHELF_BACKGROUND_DEFAULT); |
| 365 PaintBackground(SHELF_BACKGROUND_DEFAULT); | 269 PaintBackground(SHELF_BACKGROUND_DEFAULT); |
| 366 | 270 |
| 367 EXPECT_FALSE(test_api_->can_reuse_animators()); | 271 EXPECT_FALSE(test_api_->can_reuse_animator()); |
| 368 } | 272 } |
| 369 | 273 |
| 370 // Verify observers are always notified, even when alpha values don't change. | 274 // Verify observers are always notified, even when alpha values don't change. |
| 371 TEST_F(ShelfBackgroundAnimatorMDTest, | 275 TEST_F(ShelfBackgroundAnimatorTest, |
| 372 ObserversAreNotifiedWhenSnappingToSameTargetBackground) { | 276 ObserversAreNotifiedWhenSnappingToSameTargetBackground) { |
| 373 PaintBackground(SHELF_BACKGROUND_DEFAULT); | 277 PaintBackground(SHELF_BACKGROUND_DEFAULT); |
| 374 SetAlphaValuesOnObserver(kDummyAlpha); | 278 SetAlphaValuesOnObserver(kDummyAlpha); |
| 375 PaintBackground(SHELF_BACKGROUND_DEFAULT); | 279 PaintBackground(SHELF_BACKGROUND_DEFAULT); |
| 376 | 280 |
| 377 EXPECT_NE(observer_.opaque_background_alpha(), kDummyAlpha); | 281 EXPECT_NE(observer_.background_alpha(), kDummyAlpha); |
| 378 EXPECT_NE(observer_.item_background_alpha(), kDummyAlpha); | 282 EXPECT_NE(observer_.item_background_alpha(), kDummyAlpha); |
| 379 } | 283 } |
| 380 | 284 |
| 381 } // namespace ash | 285 } // namespace ash |
| OLD | NEW |