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

Unified Diff: ash/common/shelf/shelf_background_animator_unittest.cc

Issue 2679333002: [ash-md] Remove the number of animators used for the Shelf animations. (Closed)
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: ash/common/shelf/shelf_background_animator_unittest.cc
diff --git a/ash/common/shelf/shelf_background_animator_unittest.cc b/ash/common/shelf/shelf_background_animator_unittest.cc
index 6a395cae45b82e1c0d72539f23f17e0bb47efc14..9665ca876ca2373e9a2d3855839b2b393a46b1f0 100644
--- a/ash/common/shelf/shelf_background_animator_unittest.cc
+++ b/ash/common/shelf/shelf_background_animator_unittest.cc
@@ -8,17 +8,14 @@
#include "ash/common/shelf/shelf_background_animator_observer.h"
#include "ash/common/shelf/shelf_constants.h"
-#include "ash/common/test/material_design_controller_test_api.h"
#include "base/bind.h"
#include "base/macros.h"
#include "base/test/test_mock_time_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/gfx/animation/slide_animation.h"
namespace ash {
-
-using test::MaterialDesignControllerTestAPI;
-
namespace {
const int kMaxAlpha = 255;
@@ -33,23 +30,23 @@ class TestShelfBackgroundObserver : public ShelfBackgroundAnimatorObserver {
TestShelfBackgroundObserver() {}
~TestShelfBackgroundObserver() override {}
- int opaque_background_alpha() const { return opaque_background_alpha_; }
+ int background_alpha() const { return background_alpha_; }
int item_background_alpha() const { return item_background_alpha_; }
// ShelfBackgroundObserver:
- void UpdateShelfOpaqueBackground(int alpha) override;
+ void UpdateShelfBackground(int alpha) override;
void UpdateShelfItemBackground(int alpha) override;
private:
- int opaque_background_alpha_ = 0;
+ int background_alpha_ = 0;
int item_background_alpha_ = 0;
DISALLOW_COPY_AND_ASSIGN(TestShelfBackgroundObserver);
};
-void TestShelfBackgroundObserver::UpdateShelfOpaqueBackground(int alpha) {
- opaque_background_alpha_ = alpha;
+void TestShelfBackgroundObserver::UpdateShelfBackground(int alpha) {
+ background_alpha_ = alpha;
}
void TestShelfBackgroundObserver::UpdateShelfItemBackground(int alpha) {
@@ -70,15 +67,9 @@ class ShelfBackgroundAnimatorTestApi {
return animator_->previous_background_type_;
}
- BackgroundAnimator* opaque_background_animator() const {
- return animator_->opaque_background_animator_.get();
- }
-
- BackgroundAnimator* item_background_animator() const {
- return animator_->item_background_animator_.get();
- }
+ gfx::SlideAnimation* animator() const { return animator_->animator_.get(); }
- bool can_reuse_animators() const { return animator_->can_reuse_animators_; }
+ bool can_reuse_animator() const { return animator_->can_reuse_animator_; }
private:
// The instance to provide internal access to.
@@ -87,24 +78,17 @@ class ShelfBackgroundAnimatorTestApi {
DISALLOW_COPY_AND_ASSIGN(ShelfBackgroundAnimatorTestApi);
};
-// Note: this is not a parameterized test (like other MD tests) because the
-// behavior is so different and not all tests need to be run for both MD and
-// non-MD variants.
-class ShelfBackgroundAnimatorTestBase : public testing::Test {
+class ShelfBackgroundAnimatorTest : public testing::Test {
public:
- ShelfBackgroundAnimatorTestBase() {}
- ~ShelfBackgroundAnimatorTestBase() override {}
-
- virtual MaterialDesignController::Mode GetMaterialDesignMode() = 0;
-
- int expected_translucent_alpha() const { return expected_translucent_alpha_; }
+ ShelfBackgroundAnimatorTest() {}
+ ~ShelfBackgroundAnimatorTest() override {}
// testing::Test:
void SetUp() override;
protected:
// Convenience wrapper for |animator_|'s PaintBackground() that always uses
- // BACKGROUND_CHANGE_IMMEDIATE.
+ // gfx::ANIMATION_CHANGE_IMMEDIATE.
void PaintBackground(ShelfBackgroundType background_type);
// Set all of the alpha values for the |observer_|.
@@ -127,104 +111,36 @@ class ShelfBackgroundAnimatorTestBase : public testing::Test {
private:
std::unique_ptr<base::ThreadTaskRunnerHandle> task_runner_handle_;
- std::unique_ptr<MaterialDesignControllerTestAPI> material_mode_test_api_;
-
- // The expected alpha value for translucent items. Cannot be a constant
- // because it is different for material design and non-material.
- int expected_translucent_alpha_ = 0;
-
- DISALLOW_COPY_AND_ASSIGN(ShelfBackgroundAnimatorTestBase);
+ DISALLOW_COPY_AND_ASSIGN(ShelfBackgroundAnimatorTest);
};
-void ShelfBackgroundAnimatorTestBase::SetUp() {
+void ShelfBackgroundAnimatorTest::SetUp() {
task_runner_ = new base::TestMockTimeTaskRunner();
task_runner_handle_.reset(new base::ThreadTaskRunnerHandle(task_runner_));
-
- material_mode_test_api_.reset(
- new MaterialDesignControllerTestAPI(GetMaterialDesignMode()));
animator_.reset(
new ShelfBackgroundAnimator(SHELF_BACKGROUND_DEFAULT, nullptr));
animator_->AddObserver(&observer_);
test_api_.reset(new ShelfBackgroundAnimatorTestApi(animator_.get()));
-
- // Initialized after the Material Design mode because GetShelfConstant()
- // depends on the mode.
- expected_translucent_alpha_ = GetShelfConstant(SHELF_BACKGROUND_ALPHA);
}
-void ShelfBackgroundAnimatorTestBase::PaintBackground(
+void ShelfBackgroundAnimatorTest::PaintBackground(
ShelfBackgroundType background_type) {
- animator_->PaintBackground(background_type, BACKGROUND_CHANGE_IMMEDIATE);
+ animator_->PaintBackground(background_type, gfx::ANIMATION_CHANGE_IMMEDIATE);
}
-void ShelfBackgroundAnimatorTestBase::SetAlphaValuesOnObserver(int alpha) {
- observer_.UpdateShelfOpaqueBackground(alpha);
+void ShelfBackgroundAnimatorTest::SetAlphaValuesOnObserver(int alpha) {
+ observer_.UpdateShelfBackground(alpha);
observer_.UpdateShelfItemBackground(alpha);
}
-void ShelfBackgroundAnimatorTestBase::CompleteAnimations() {
+void ShelfBackgroundAnimatorTest::CompleteAnimations() {
task_runner_->FastForwardUntilNoTasksRemain();
}
-class ShelfBackgroundAnimatorNonMDTest
- : public ShelfBackgroundAnimatorTestBase {
- public:
- ShelfBackgroundAnimatorNonMDTest() {}
- ~ShelfBackgroundAnimatorNonMDTest() override {}
-
- MaterialDesignController::Mode GetMaterialDesignMode() override {
- return MaterialDesignController::NON_MATERIAL;
- }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(ShelfBackgroundAnimatorNonMDTest);
-};
-
-// Verify the alpha values for the SHELF_BACKGROUND_DEFAULT state.
-TEST_F(ShelfBackgroundAnimatorNonMDTest, DefaultBackground) {
- PaintBackground(SHELF_BACKGROUND_DEFAULT);
-
- EXPECT_EQ(SHELF_BACKGROUND_DEFAULT, animator_->target_background_type());
- EXPECT_EQ(0, observer_.opaque_background_alpha());
- EXPECT_EQ(expected_translucent_alpha(), observer_.item_background_alpha());
-}
-
-// Verify the alpha values for the SHELF_BACKGROUND_OVERLAP state.
-TEST_F(ShelfBackgroundAnimatorNonMDTest, OverlapBackground) {
- PaintBackground(SHELF_BACKGROUND_OVERLAP);
-
- EXPECT_EQ(SHELF_BACKGROUND_OVERLAP, animator_->target_background_type());
- EXPECT_EQ(0, observer_.opaque_background_alpha());
- EXPECT_EQ(expected_translucent_alpha(), observer_.item_background_alpha());
-}
-
-// Verify the alpha values for the SHELF_BACKGROUND_MAXIMIZED state.
-TEST_F(ShelfBackgroundAnimatorNonMDTest, MaximizedBackground) {
- PaintBackground(SHELF_BACKGROUND_MAXIMIZED);
-
- EXPECT_EQ(SHELF_BACKGROUND_MAXIMIZED, animator_->target_background_type());
- EXPECT_EQ(kMaxAlpha, observer_.opaque_background_alpha());
- EXPECT_EQ(kMaxAlpha, observer_.item_background_alpha());
-}
-
-class ShelfBackgroundAnimatorMDTest : public ShelfBackgroundAnimatorTestBase {
- public:
- ShelfBackgroundAnimatorMDTest() {}
- ~ShelfBackgroundAnimatorMDTest() override {}
-
- MaterialDesignController::Mode GetMaterialDesignMode() override {
- return MaterialDesignController::MATERIAL_EXPERIMENTAL;
- }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(ShelfBackgroundAnimatorMDTest);
-};
-
// Verify the |previous_background_type_| and |target_background_type_| values
// when animating to the same target type multiple times.
-TEST_F(ShelfBackgroundAnimatorMDTest,
- BackgroundTypesWhenAnimatingToSameTarget) {
+TEST_F(ShelfBackgroundAnimatorTest, BackgroundTypesWhenAnimatingToSameTarget) {
PaintBackground(SHELF_BACKGROUND_MAXIMIZED);
EXPECT_EQ(SHELF_BACKGROUND_MAXIMIZED, animator_->target_background_type());
@@ -238,143 +154,131 @@ TEST_F(ShelfBackgroundAnimatorMDTest,
}
// Verify subsequent calls to PaintBackground() using the
-// BACKGROUND_CHANGE_ANIMATE change type are ignored.
-TEST_F(ShelfBackgroundAnimatorMDTest,
+// gfx::ANIMATION_CHANGE_ANIMATE change type are ignored.
+TEST_F(ShelfBackgroundAnimatorTest,
MultipleAnimateCallsToSameTargetAreIgnored) {
PaintBackground(SHELF_BACKGROUND_MAXIMIZED);
SetAlphaValuesOnObserver(kDummyAlpha);
animator_->PaintBackground(SHELF_BACKGROUND_DEFAULT,
- BACKGROUND_CHANGE_ANIMATE);
+ gfx::ANIMATION_CHANGE_ANIMATE);
CompleteAnimations();
- EXPECT_NE(observer_.opaque_background_alpha(), kDummyAlpha);
+ EXPECT_NE(observer_.background_alpha(), kDummyAlpha);
EXPECT_NE(observer_.item_background_alpha(), kDummyAlpha);
SetAlphaValuesOnObserver(kDummyAlpha);
animator_->PaintBackground(SHELF_BACKGROUND_DEFAULT,
- BACKGROUND_CHANGE_ANIMATE);
+ gfx::ANIMATION_CHANGE_ANIMATE);
CompleteAnimations();
- EXPECT_EQ(observer_.opaque_background_alpha(), kDummyAlpha);
+ EXPECT_EQ(observer_.background_alpha(), kDummyAlpha);
EXPECT_EQ(observer_.item_background_alpha(), kDummyAlpha);
}
// Verify observers are updated with the current values when they are added.
-TEST_F(ShelfBackgroundAnimatorMDTest, ObserversUpdatedWhenAdded) {
+TEST_F(ShelfBackgroundAnimatorTest, ObserversUpdatedWhenAdded) {
animator_->RemoveObserver(&observer_);
SetAlphaValuesOnObserver(kDummyAlpha);
animator_->AddObserver(&observer_);
- EXPECT_NE(observer_.opaque_background_alpha(), kDummyAlpha);
+ EXPECT_NE(observer_.background_alpha(), kDummyAlpha);
EXPECT_NE(observer_.item_background_alpha(), kDummyAlpha);
}
// Verify the alpha values for the SHELF_BACKGROUND_DEFAULT state.
-TEST_F(ShelfBackgroundAnimatorMDTest, DefaultBackground) {
+TEST_F(ShelfBackgroundAnimatorTest, DefaultBackground) {
PaintBackground(SHELF_BACKGROUND_DEFAULT);
EXPECT_EQ(SHELF_BACKGROUND_DEFAULT, animator_->target_background_type());
- EXPECT_EQ(0, observer_.opaque_background_alpha());
- EXPECT_EQ(expected_translucent_alpha(), observer_.item_background_alpha());
+ EXPECT_EQ(0, observer_.background_alpha());
+ EXPECT_EQ(kShelfTranslucentAlpha, observer_.item_background_alpha());
}
// Verify the alpha values for the SHELF_BACKGROUND_OVERLAP state.
-TEST_F(ShelfBackgroundAnimatorMDTest, OverlapBackground) {
+TEST_F(ShelfBackgroundAnimatorTest, OverlapBackground) {
PaintBackground(SHELF_BACKGROUND_OVERLAP);
EXPECT_EQ(SHELF_BACKGROUND_OVERLAP, animator_->target_background_type());
- EXPECT_EQ(expected_translucent_alpha(), observer_.opaque_background_alpha());
+ EXPECT_EQ(kShelfTranslucentAlpha, observer_.background_alpha());
EXPECT_EQ(0, observer_.item_background_alpha());
}
// Verify the alpha values for the SHELF_BACKGROUND_MAXIMIZED state.
-TEST_F(ShelfBackgroundAnimatorMDTest, MaximizedBackground) {
+TEST_F(ShelfBackgroundAnimatorTest, MaximizedBackground) {
PaintBackground(SHELF_BACKGROUND_MAXIMIZED);
EXPECT_EQ(SHELF_BACKGROUND_MAXIMIZED, animator_->target_background_type());
- EXPECT_EQ(kMaxAlpha, observer_.opaque_background_alpha());
+ EXPECT_EQ(kMaxAlpha, observer_.background_alpha());
EXPECT_EQ(0, observer_.item_background_alpha());
}
-// Verify that existing animators are used when animating to the previous state.
-TEST_F(ShelfBackgroundAnimatorMDTest, ExistingAnimatorsAreReused) {
+// Verify that existing animator is used when animating to the previous state.
+TEST_F(ShelfBackgroundAnimatorTest, ExistingAnimatorIsReused) {
PaintBackground(SHELF_BACKGROUND_DEFAULT);
PaintBackground(SHELF_BACKGROUND_MAXIMIZED);
- EXPECT_TRUE(test_api_->can_reuse_animators());
+ EXPECT_TRUE(test_api_->can_reuse_animator());
- const BackgroundAnimator* opaque_animator =
- test_api_->opaque_background_animator();
- const BackgroundAnimator* item_animator =
- test_api_->item_background_animator();
+ const gfx::SlideAnimation* animator = test_api_->animator();
PaintBackground(SHELF_BACKGROUND_DEFAULT);
- EXPECT_EQ(opaque_animator, test_api_->opaque_background_animator());
- EXPECT_EQ(item_animator, test_api_->item_background_animator());
+ EXPECT_EQ(animator, test_api_->animator());
}
-// Verify that existing animators are not re-used when the previous animation
+// Verify that existing animator is not re-used when the previous animation
// didn't complete.
-TEST_F(ShelfBackgroundAnimatorMDTest,
- ExistingAnimatorsNotReusedWhenPreviousAnimationsDontComplete) {
+TEST_F(ShelfBackgroundAnimatorTest,
+ ExistingAnimatorNotReusedWhenPreviousAnimationsDontComplete) {
EXPECT_NE(SHELF_BACKGROUND_OVERLAP, test_api_->previous_background_type());
animator_->PaintBackground(SHELF_BACKGROUND_OVERLAP,
- BACKGROUND_CHANGE_ANIMATE);
+ gfx::ANIMATION_CHANGE_ANIMATE);
animator_->PaintBackground(SHELF_BACKGROUND_MAXIMIZED,
- BACKGROUND_CHANGE_ANIMATE);
- EXPECT_FALSE(test_api_->can_reuse_animators());
+ gfx::ANIMATION_CHANGE_ANIMATE);
+ EXPECT_FALSE(test_api_->can_reuse_animator());
- const BackgroundAnimator* opaque_animator =
- test_api_->opaque_background_animator();
- const BackgroundAnimator* item_animator =
- test_api_->item_background_animator();
+ const gfx::SlideAnimation* animator = test_api_->animator();
EXPECT_EQ(SHELF_BACKGROUND_OVERLAP, test_api_->previous_background_type());
animator_->PaintBackground(SHELF_BACKGROUND_OVERLAP,
- BACKGROUND_CHANGE_ANIMATE);
+ gfx::ANIMATION_CHANGE_ANIMATE);
- EXPECT_NE(opaque_animator, test_api_->opaque_background_animator());
- EXPECT_NE(item_animator, test_api_->item_background_animator());
+ EXPECT_NE(animator, test_api_->animator());
}
-// Verify that existing animators are not re-used when the target background
-// isn't the same as the previous background.
-TEST_F(ShelfBackgroundAnimatorMDTest,
- ExistingAnimatorsNotReusedWhenTargetBackgroundNotPreviousBackground) {
+// Verify that existing animator is not re-used when the target background isn't
+// the same as the previous background.
+TEST_F(ShelfBackgroundAnimatorTest,
+ ExistingAnimatorNotReusedWhenTargetBackgroundNotPreviousBackground) {
PaintBackground(SHELF_BACKGROUND_DEFAULT);
PaintBackground(SHELF_BACKGROUND_MAXIMIZED);
- EXPECT_TRUE(test_api_->can_reuse_animators());
+ EXPECT_TRUE(test_api_->can_reuse_animator());
- const BackgroundAnimator* opaque_animator =
- test_api_->opaque_background_animator();
- const BackgroundAnimator* item_animator =
- test_api_->item_background_animator();
+ const gfx::SlideAnimation* animator = test_api_->animator();
EXPECT_NE(SHELF_BACKGROUND_OVERLAP, test_api_->previous_background_type());
PaintBackground(SHELF_BACKGROUND_OVERLAP);
- EXPECT_NE(opaque_animator, test_api_->opaque_background_animator());
- EXPECT_NE(item_animator, test_api_->item_background_animator());
+ EXPECT_NE(animator, test_api_->animator());
}
-// Verify animators are not re-used after snapping to the same background type.
-TEST_F(ShelfBackgroundAnimatorMDTest,
- ExistingAnimatorsNotUsedWhenSnappingToSameTargetBackground) {
+// Verify animator is not re-used after snapping to the same background type.
+TEST_F(ShelfBackgroundAnimatorTest,
+ ExistingAnimatorNotUsedWhenSnappingToSameTargetBackground) {
PaintBackground(SHELF_BACKGROUND_DEFAULT);
PaintBackground(SHELF_BACKGROUND_DEFAULT);
- EXPECT_FALSE(test_api_->can_reuse_animators());
+ EXPECT_FALSE(test_api_->can_reuse_animator());
}
// Verify observers are always notified, even when alpha values don't change.
-TEST_F(ShelfBackgroundAnimatorMDTest,
+TEST_F(ShelfBackgroundAnimatorTest,
ObserversAreNotifiedWhenSnappingToSameTargetBackground) {
PaintBackground(SHELF_BACKGROUND_DEFAULT);
SetAlphaValuesOnObserver(kDummyAlpha);
PaintBackground(SHELF_BACKGROUND_DEFAULT);
- EXPECT_NE(observer_.opaque_background_alpha(), kDummyAlpha);
+ EXPECT_NE(observer_.background_alpha(), kDummyAlpha);
EXPECT_NE(observer_.item_background_alpha(), kDummyAlpha);
}

Powered by Google App Engine
This is Rietveld 408576698