diff options
author | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2016-08-01 12:59:39 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2016-08-04 12:40:43 +0000 |
commit | 28b1110370900897ab652cb420c371fab8857ad4 (patch) | |
tree | 41b32127d23b0df4f2add2a27e12dc87bddb260e /chromium/ui/views/animation/ink_drop_unittest.cc | |
parent | 399c965b6064c440ddcf4015f5f8e9d131c7a0a6 (diff) | |
download | qtwebengine-chromium-28b1110370900897ab652cb420c371fab8857ad4.tar.gz |
BASELINE: Update Chromium to 53.0.2785.41
Also adds a few extra files for extensions.
Change-Id: Iccdd55d98660903331cf8b7b29188da781830af4
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/ui/views/animation/ink_drop_unittest.cc')
-rw-r--r-- | chromium/ui/views/animation/ink_drop_unittest.cc | 144 |
1 files changed, 144 insertions, 0 deletions
diff --git a/chromium/ui/views/animation/ink_drop_unittest.cc b/chromium/ui/views/animation/ink_drop_unittest.cc new file mode 100644 index 00000000000..43a77fe0b05 --- /dev/null +++ b/chromium/ui/views/animation/ink_drop_unittest.cc @@ -0,0 +1,144 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include <memory> + +#include "base/macros.h" +#include "base/test/test_mock_time_task_runner.h" +#include "base/threading/thread_task_runner_handle.h" +#include "base/timer/timer.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "ui/base/test/material_design_controller_test_api.h" +#include "ui/compositor/scoped_animation_duration_scale_mode.h" +#include "ui/views/animation/ink_drop.h" +#include "ui/views/animation/ink_drop_host.h" +#include "ui/views/animation/ink_drop_impl.h" +#include "ui/views/animation/ink_drop_state.h" +#include "ui/views/animation/ink_drop_stub.h" +#include "ui/views/animation/test/test_ink_drop_host.h" + +namespace views { +namespace test { + +// Enumeration of all the different InkDrop types. +enum InkDropType { INK_DROP_STUB, INK_DROP_IMPL }; + +class InkDropTest : public testing::TestWithParam<testing::tuple<InkDropType>> { + public: + InkDropTest(); + ~InkDropTest(); + + protected: + // A dummy InkDropHost required to create an InkDrop. + TestInkDropHost test_ink_drop_host_; + + // The InkDrop returned by the InkDropFactory test target. + std::unique_ptr<InkDrop> ink_drop_; + + private: + // Extracts and returns the InkDropType from the test parameters. + InkDropType GetInkDropType() const; + + std::unique_ptr<ui::ScopedAnimationDurationScaleMode> zero_duration_mode_; + + // Required by base::Timer's. + std::unique_ptr<base::ThreadTaskRunnerHandle> thread_task_runner_handle_; + + DISALLOW_COPY_AND_ASSIGN(InkDropTest); +}; + +InkDropTest::InkDropTest() : ink_drop_(nullptr) { + zero_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode( + ui::ScopedAnimationDurationScaleMode::ZERO_DURATION)); + + switch (InkDropType()) { + case INK_DROP_STUB: + ink_drop_.reset(new InkDropStub()); + break; + case INK_DROP_IMPL: + ink_drop_.reset(new InkDropImpl(&test_ink_drop_host_)); + // The Timer's used by the InkDropImpl class require a + // base::ThreadTaskRunnerHandle instance. + scoped_refptr<base::TestMockTimeTaskRunner> task_runner( + new base::TestMockTimeTaskRunner); + thread_task_runner_handle_.reset( + new base::ThreadTaskRunnerHandle(task_runner)); + break; + } +} + +InkDropTest::~InkDropTest() {} + +InkDropType InkDropTest::GetInkDropType() const { + return testing::get<0>(GetParam()); +} + +// Note: First argument is optional and intentionally left blank. +// (it's a prefix for the generated test cases) +INSTANTIATE_TEST_CASE_P(, + InkDropTest, + testing::Values(INK_DROP_STUB, INK_DROP_IMPL)); + +TEST_P(InkDropTest, + VerifyInkDropLayersRemovedAfterDestructionWhenRippleIsActive) { + ink_drop_->AnimateToState(InkDropState::ACTION_PENDING); + ink_drop_.reset(); + EXPECT_EQ(0, test_ink_drop_host_.num_ink_drop_layers()); +} + +TEST_P(InkDropTest, + VerifyInkDropLayersRemovedAfterDestructionWhenHoverIsActive) { + test_ink_drop_host_.set_should_show_highlight(true); + ink_drop_->SetHovered(true); + ink_drop_.reset(); + EXPECT_EQ(0, test_ink_drop_host_.num_ink_drop_layers()); +} + +TEST_P(InkDropTest, StateIsHiddenInitially) { + EXPECT_EQ(InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState()); +} + +TEST_P(InkDropTest, TypicalQuickAction) { + ink_drop_->AnimateToState(InkDropState::ACTION_PENDING); + ink_drop_->AnimateToState(InkDropState::ACTION_TRIGGERED); + EXPECT_EQ(InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState()); +} + +TEST_P(InkDropTest, CancelQuickAction) { + ink_drop_->AnimateToState(InkDropState::ACTION_PENDING); + ink_drop_->AnimateToState(InkDropState::HIDDEN); + EXPECT_EQ(InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState()); +} + +TEST_P(InkDropTest, TypicalSlowAction) { + ink_drop_->AnimateToState(InkDropState::ACTION_PENDING); + ink_drop_->AnimateToState(InkDropState::ALTERNATE_ACTION_PENDING); + ink_drop_->AnimateToState(InkDropState::ALTERNATE_ACTION_TRIGGERED); + EXPECT_EQ(InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState()); +} + +TEST_P(InkDropTest, CancelSlowAction) { + ink_drop_->AnimateToState(InkDropState::ACTION_PENDING); + ink_drop_->AnimateToState(InkDropState::ALTERNATE_ACTION_PENDING); + ink_drop_->AnimateToState(InkDropState::HIDDEN); + EXPECT_EQ(InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState()); +} + +TEST_P(InkDropTest, TypicalQuickActivated) { + ink_drop_->AnimateToState(InkDropState::ACTION_PENDING); + ink_drop_->AnimateToState(InkDropState::ACTIVATED); + ink_drop_->AnimateToState(InkDropState::DEACTIVATED); + EXPECT_EQ(InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState()); +} + +TEST_P(InkDropTest, TypicalSlowActivated) { + ink_drop_->AnimateToState(InkDropState::ACTION_PENDING); + ink_drop_->AnimateToState(InkDropState::ALTERNATE_ACTION_PENDING); + ink_drop_->AnimateToState(InkDropState::ACTIVATED); + ink_drop_->AnimateToState(InkDropState::DEACTIVATED); + EXPECT_EQ(InkDropState::HIDDEN, ink_drop_->GetTargetInkDropState()); +} + +} // namespace test +} // namespace views |