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

Side by Side Diff: ash/common/shelf/shelf_background_animator_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698