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

Unified Diff: content/browser/web_contents/aura/overscroll_window_animation_unittest.cc

Issue 895543005: Refactor GestureNavigation to eliminate code redundancy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Brought back gesture cancellation by mouse and linted code. Created 5 years, 9 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: content/browser/web_contents/aura/overscroll_window_animation_unittest.cc
diff --git a/content/browser/web_contents/aura/overscroll_window_animation_unittest.cc b/content/browser/web_contents/aura/overscroll_window_animation_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a96834ef772723f5136444bd39d938848f17e5c1
--- /dev/null
+++ b/content/browser/web_contents/aura/overscroll_window_animation_unittest.cc
@@ -0,0 +1,226 @@
+// Copyright (c) 2013 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 "content/browser/web_contents/aura/overscroll_window_animation.h"
mfomitchev 2015/03/26 15:36:00 I think we need a test for overscroll_window_deleg
Nina 2015/03/27 17:52:36 Done.
+
+#include "testing/gtest/include/gtest/gtest.h"
mfomitchev 2015/03/26 15:36:01 The old window slider tests have three tests which
Nina 2015/03/27 17:52:36 This should not be a problem IMHO, if the contents
+#include "ui/aura/test/aura_test_base.h"
+#include "ui/aura/window.h"
+#include "ui/compositor/scoped_animation_duration_scale_mode.h"
+#include "ui/compositor/scoped_layer_animation_settings.h"
+#include "ui/compositor/test/layer_animator_test_controller.h"
+#include "ui/gfx/frame_time.h"
+
+namespace content {
+
+class OverscrollWindowAnimationTest
+ : public OverscrollWindowAnimation::Delegate,
+ public aura::test::AuraTestBase {
+ public:
+ OverscrollWindowAnimationTest()
+ : create_window_(true),
+ overscroll_started_(false),
+ overscroll_completing_(false),
+ overscroll_completed_(false),
+ overscroll_aborted_(false),
+ target_window_(nullptr) {}
+
+ ~OverscrollWindowAnimationTest() override {}
+
+ OverscrollWindowAnimation* owa() { return owa_.get(); }
+
+ // Set to true to return a window in the Create*Window functions, false to
+ // return null.
+ void set_create_window(bool create_window) { create_window_ = create_window; }
+
+ // The following functions indicate if the events have been called on this
+ // delegate.
+ bool overscroll_started() { return overscroll_started_; }
+ bool overscroll_completing() { return overscroll_completing_; }
+ bool overscroll_completed() { return overscroll_completed_; }
+ bool overscroll_aborted() { return overscroll_aborted_; }
+
+ void ResetFlags() {
+ overscroll_started_ = false;
+ overscroll_completing_ = false;
+ overscroll_completed_ = false;
+ overscroll_aborted_ = false;
+ }
+
+ protected:
+ // aura::test::AuraTestBase:
+ void SetUp() override {
+ aura::test::AuraTestBase::SetUp();
+ target_window_.reset(CreateNormalWindow(0, root_window(), nullptr));
+ ResetFlags();
+ create_window_ = true;
+ last_window_id_ = 0;
+ owa_.reset(new OverscrollWindowAnimation(this));
+ }
+
+ void TearDown() override {
+ owa_.reset();
+ target_window_.reset();
+ aura::test::AuraTestBase::TearDown();
+ }
+
+ // OverscrollWindowAnimation::Delegate:
+ scoped_ptr<aura::Window> CreateFrontWindow() override {
+ return CreateWindow();
+ }
+
+ scoped_ptr<aura::Window> CreateBackWindow() override {
+ return CreateWindow();
+ }
+
+ aura::Window* GetTargetWindow() const override {
+ return target_window_.get();
+ }
+
+ void OnOverscrollCompleting() override { overscroll_completing_ = true; }
+
+ void OnOverscrollCompleted(scoped_ptr<aura::Window> window) override {
+ overscroll_completed_ = true;
+ }
+
+ void OnOverscrollAborted() override { overscroll_aborted_ = true; }
+
+ private:
+ // The overscroll window animation under test.
+ scoped_ptr<OverscrollWindowAnimation> owa_;
+
+ scoped_ptr<aura::Window> CreateWindow() {
+ overscroll_started_ = true;
+ if (create_window_) {
+ return scoped_ptr<aura::Window>(
+ CreateNormalWindow(++last_window_id_, root_window(), nullptr));
+ }
+ return nullptr;
+ }
+
+ // Controls if we return a window for the window creation callbacks or not.
+ bool create_window_;
+
+ // State flags.
+ bool overscroll_started_;
+ bool overscroll_completing_;
+ bool overscroll_completed_;
+ bool overscroll_aborted_;
+
+ int last_window_id_;
+
+ // The dummy target window we provide.
+ scoped_ptr<aura::Window> target_window_;
+
+ DISALLOW_COPY_AND_ASSIGN(OverscrollWindowAnimationTest);
+};
+
+// Tests a simple overscroll gesture.
+TEST_F(OverscrollWindowAnimationTest, BasicOverscroll) {
mfomitchev 2015/03/26 15:36:00 what about north/south overscroll?
Nina 2015/03/27 17:52:36 We don't support it in OWD as we didn't support it
+ EXPECT_FALSE(owa()->is_active());
+ EXPECT_FALSE(overscroll_started());
+ EXPECT_FALSE(overscroll_completing());
+ EXPECT_FALSE(overscroll_completed());
+ EXPECT_FALSE(overscroll_aborted());
+
+ // Start an OVERSCROLL_EAST gesture.
+ owa()->OnOverscrollModeChange(OVERSCROLL_NONE, OVERSCROLL_EAST);
+ EXPECT_TRUE(owa()->is_active());
+ EXPECT_TRUE(overscroll_started());
+ EXPECT_FALSE(overscroll_completing());
+ EXPECT_FALSE(overscroll_completed());
+ EXPECT_FALSE(overscroll_aborted());
+
+ // Complete the overscroll.
+ owa()->OnOverscrollComplete(OVERSCROLL_EAST);
+ EXPECT_FALSE(owa()->is_active());
+ EXPECT_TRUE(overscroll_started());
+ EXPECT_TRUE(overscroll_completing());
+ EXPECT_TRUE(overscroll_completed());
+ EXPECT_FALSE(overscroll_aborted());
+}
+
+// Tests aborting an overscroll gesture.
+TEST_F(OverscrollWindowAnimationTest, BasicAbort) {
+ // Start an OVERSCROLL_EAST gesture.
+ owa()->OnOverscrollModeChange(OVERSCROLL_NONE, OVERSCROLL_EAST);
+ // Abort the overscroll.
+ owa()->OnOverscrollModeChange(OVERSCROLL_EAST, OVERSCROLL_NONE);
+ EXPECT_FALSE(owa()->is_active());
+ EXPECT_TRUE(overscroll_started());
+ EXPECT_FALSE(overscroll_completing());
+ EXPECT_FALSE(overscroll_completed());
+ EXPECT_TRUE(overscroll_aborted());
+}
+
+// Tests starting an overscroll gesture when navigation is impossible.
mfomitchev 2015/03/26 15:36:00 "when navigation is impossible" -> "when xyz windo
Nina 2015/03/27 17:52:36 Done.
+TEST_F(OverscrollWindowAnimationTest, BasicCannotNavigate) {
+ set_create_window(false);
+ // Start an OVERSCROLL_EAST gesture.
+ owa()->OnOverscrollModeChange(OVERSCROLL_NONE, OVERSCROLL_EAST);
+ EXPECT_FALSE(owa()->is_active());
+ EXPECT_TRUE(overscroll_started());
+ EXPECT_FALSE(overscroll_completing());
+ EXPECT_FALSE(overscroll_completed());
+ EXPECT_FALSE(overscroll_aborted());
+}
+
+// Tests starting an overscroll gesture while another one was in progress
+// completes the first one.
+TEST_F(OverscrollWindowAnimationTest, NewOverscrollCompletesPreviousGesture) {
+ // This test requires a normal animation duration so that
+ // OnImplicitAnimationsCancelled is not called as soon as the first overscroll
+ // finishes.
+ ui::ScopedAnimationDurationScaleMode normal_duration(
+ ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
+ ui::LayerAnimator* animator = GetTargetWindow()->layer()->GetAnimator();
+ ui::ScopedLayerAnimationSettings settings(animator);
+ animator->set_disable_timer_for_test(true);
+ ui::LayerAnimatorTestController test_controller(animator);
+ // Start an OVERSCROLL_EAST gesture.
+ owa()->OnOverscrollModeChange(OVERSCROLL_NONE, OVERSCROLL_EAST);
+
+ // Finishes the OVERSCROLL_EAST gesture. At this point the window should be
+ // being animated to its final position.
+ owa()->OnOverscrollComplete(OVERSCROLL_EAST);
+ EXPECT_TRUE(owa()->is_active());
+ EXPECT_TRUE(overscroll_started());
+ EXPECT_TRUE(overscroll_completing());
+ EXPECT_FALSE(overscroll_completed());
+ EXPECT_FALSE(overscroll_aborted());
+
+ // Start another OVERSCROLL_EAST gesture.
+ owa()->OnOverscrollModeChange(OVERSCROLL_NONE, OVERSCROLL_EAST);
+ EXPECT_TRUE(owa()->is_active());
+ EXPECT_TRUE(overscroll_started());
+ EXPECT_TRUE(overscroll_completing());
+ EXPECT_TRUE(overscroll_completed());
+ EXPECT_FALSE(overscroll_aborted());
+
+ // Complete the overscroll gesture.
+ ResetFlags();
+ owa()->OnOverscrollComplete(OVERSCROLL_EAST);
+
+ base::TimeDelta duration = settings.GetTransitionDuration();
+ test_controller.StartThreadedAnimationsIfNeeded();
+ base::TimeTicks start_time = gfx::FrameTime::Now();
+
+ // Halfway through the animation, OverscrollCompleting should have been fired.
+ animator->Step(start_time + duration / 2);
+ EXPECT_TRUE(owa()->is_active());
+ EXPECT_FALSE(overscroll_started());
+ EXPECT_TRUE(overscroll_completing());
+ EXPECT_FALSE(overscroll_completed());
+ EXPECT_FALSE(overscroll_aborted());
+
+ // The animation has finished, OverscrollCompleted should have been fired.
+ animator->Step(start_time + duration);
+ EXPECT_FALSE(owa()->is_active());
+ EXPECT_FALSE(overscroll_started());
+ EXPECT_TRUE(overscroll_completing());
+ EXPECT_TRUE(overscroll_completed());
+ EXPECT_FALSE(overscroll_aborted());
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698