Chromium Code Reviews| Index: content/browser/web_contents/aura/overscroll_window_delegate_unittest.cc |
| diff --git a/content/browser/web_contents/aura/overscroll_window_delegate_unittest.cc b/content/browser/web_contents/aura/overscroll_window_delegate_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e9a8ce4d3b0f393d7e96fdcc4e73857ead0c52de |
| --- /dev/null |
| +++ b/content/browser/web_contents/aura/overscroll_window_delegate_unittest.cc |
| @@ -0,0 +1,190 @@ |
| +// 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_delegate.h" |
| + |
| +#include "content/browser/renderer_host/overscroll_controller_delegate.h" |
| +#include "content/public/browser/overscroll_configuration.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "ui/aura/test/aura_test_base.h" |
| +#include "ui/aura/window.h" |
| +#include "ui/events/test/event_generator.h" |
| + |
| +namespace content { |
| + |
| +namespace { |
| + const int kTestWindowWidth = 600; |
| +} |
| + |
| +class OverscrollWindowDelegateTest : public aura::test::AuraTestBase, |
| + public OverscrollControllerDelegate { |
| + public: |
| + OverscrollWindowDelegateTest() |
| + : window_(nullptr), |
| + overscroll_complete_(false), |
| + overscroll_started_(false), |
| + current_mode_(OVERSCROLL_NONE), |
| + touch_start_threshold_(content::GetOverscrollConfig( |
| + content::OVERSCROLL_CONFIG_HORIZ_THRESHOLD_START_TOUCHSCREEN)), |
| + touch_complete_threshold_(content::GetOverscrollConfig( |
| + content::OVERSCROLL_CONFIG_HORIZ_THRESHOLD_COMPLETE)) {} |
| + |
| + ~OverscrollWindowDelegateTest() override {} |
| + |
| + void Reset() { |
| + overscroll_complete_ = false; |
| + overscroll_started_ = false; |
| + current_mode_ = OVERSCROLL_NONE; |
| + window_.reset(CreateNormalWindow( |
| + 0, root_window(), new OverscrollWindowDelegate(this, gfx::Image()))); |
| + window_->SetBounds(gfx::Rect(0, 0, kTestWindowWidth, kTestWindowWidth)); |
| + } |
| + |
| + // Accessors. |
| + aura::Window* window() { return window_.get(); } |
| + |
| + bool overscroll_complete() { return overscroll_complete_; } |
| + bool overscroll_started() { return overscroll_started_; } |
| + |
| + OverscrollMode current_mode() { return current_mode_; } |
| + |
| + const float touch_start_threshold() { |
| + return touch_start_threshold_; |
| + } |
| + |
| + const float touch_complete_threshold() { |
| + return kTestWindowWidth * touch_complete_threshold_; |
| + } |
| + |
| + protected: |
| + // aura::test::AuraTestBase: |
| + void SetUp() override { |
| + aura::test::AuraTestBase::SetUp(); |
| + Reset(); |
| + } |
| + |
| + void TearDown() override { |
| + window_.reset(); |
| + aura::test::AuraTestBase::TearDown(); |
| + } |
| + |
| + private: |
| + // OverscrollControllerDelegate: |
| + gfx::Rect GetVisibleBounds() const override { |
| + return gfx::Rect(600, 0); |
| + } |
| + |
| + bool OnOverscrollUpdate(float delta_x, float delta_y) override { |
| + return true; |
| + } |
| + |
| + void OnOverscrollComplete(OverscrollMode overscroll_mode) override { |
| + overscroll_complete_ = true; |
| + } |
| + |
| + void OnOverscrollModeChange(OverscrollMode old_mode, |
| + OverscrollMode new_mode) override { |
| + current_mode_ = new_mode; |
| + if (current_mode_ != OVERSCROLL_NONE) |
| + overscroll_started_ = true; |
| + } |
| + |
| + // Window in which the overscroll window delegate is installed. |
| + scoped_ptr<aura::Window> window_; |
| + |
| + // State flags. |
| + bool overscroll_complete_; |
| + bool overscroll_started_; |
| + |
| + OverscrollMode current_mode_; |
| + |
| + // Config defined constants. |
| + const float touch_start_threshold_; |
| + const float touch_complete_threshold_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(OverscrollWindowDelegateTest); |
| +}; |
| + |
| +// Tests that the basic overscroll gesture works and sends updates to the |
| +// delegate. |
| +TEST_F(OverscrollWindowDelegateTest, BasicOverscroll) { |
| + ui::test::EventGenerator generator(root_window()); |
| + |
| + // Start an OVERSCROLL_EAST gesture. |
| + generator.GestureScrollSequence( |
| + gfx::Point(10, 10), |
| + gfx::Point(20 + touch_complete_threshold(), 10), |
|
mfomitchev
2015/03/27 00:14:05
10 + touch_complete_threshold() + 1?
Nina
2015/03/27 17:52:37
By using 10, we add 1 per motion, which I thought
mfomitchev
2015/03/31 22:16:31
We want to ensure that if we are over the threshol
Nina
2015/04/01 18:10:00
OK, modified test accordingly.
|
| + base::TimeDelta::FromMilliseconds(10), |
| + 10); |
| + EXPECT_TRUE(overscroll_started()); |
| + EXPECT_EQ(current_mode(), OVERSCROLL_EAST); |
|
mfomitchev
2015/03/27 00:14:05
SO by the end of the gesture I'd think the mode wo
Nina
2015/03/27 17:52:37
Yes, the mode in OWD is changed to none. However,
mfomitchev
2015/03/31 22:16:31
Acknowledged.
|
| + EXPECT_TRUE(overscroll_complete()); |
| + |
| + Reset(); |
| + // Start an OVERSCROLL_WEST gesture. |
| + generator.GestureScrollSequence( |
| + gfx::Point(20 + touch_complete_threshold(), 10), |
| + gfx::Point(10, 10), |
| + base::TimeDelta::FromMilliseconds(10), |
| + 10); |
| + EXPECT_TRUE(overscroll_started()); |
| + EXPECT_EQ(current_mode(), OVERSCROLL_WEST); |
| + EXPECT_TRUE(overscroll_complete()); |
| +} |
| + |
| +// Tests that the overscroll does not start until the gesture gets past a |
| +// particular threshold. |
| +TEST_F(OverscrollWindowDelegateTest, OverscrollThreshold) { |
| + ui::test::EventGenerator generator(root_window()); |
| + |
| + // Start an OVERSCROLL_EAST gesture. |
| + generator.GestureScrollSequence( |
| + gfx::Point(10, 10), |
| + gfx::Point(10 + touch_start_threshold(), 10), |
| + base::TimeDelta::FromMilliseconds(10), |
| + 10); |
| + EXPECT_FALSE(overscroll_started()); |
| + EXPECT_EQ(current_mode(), OVERSCROLL_NONE); |
| + EXPECT_FALSE(overscroll_complete()); |
| + |
| + Reset(); |
| + // Start an OVERSCROLL_WEST gesture. |
| + generator.GestureScrollSequence( |
| + gfx::Point(10 + touch_start_threshold(), 10), |
| + gfx::Point(10, 10), |
| + base::TimeDelta::FromMilliseconds(10), |
| + 10); |
| + EXPECT_FALSE(overscroll_started()); |
| + EXPECT_EQ(current_mode(), OVERSCROLL_NONE); |
| + EXPECT_FALSE(overscroll_complete()); |
| +} |
| + |
| +// Tests that the overscroll is aborted if the gesture does not get past the |
| +// completion threshold. |
| +TEST_F(OverscrollWindowDelegateTest, AbortOverscrollThreshold) { |
| + ui::test::EventGenerator generator(root_window()); |
| + |
| + // Start an OVERSCROLL_EAST gesture. |
| + generator.GestureScrollSequence( |
| + gfx::Point(10, 10), |
| + gfx::Point(10 + touch_start_threshold() + 10, 10), |
|
mfomitchev
2015/03/27 00:14:05
10 + touch_start_threshold() + 1?
Nina
2015/03/27 17:52:37
Same comment as above, I think it's cleaner (espec
mfomitchev
2015/03/31 22:16:31
ditto
Nina
2015/04/01 18:10:00
Done.
|
| + base::TimeDelta::FromMilliseconds(10), |
| + 10); |
| + EXPECT_TRUE(overscroll_started()); |
| + EXPECT_EQ(current_mode(), OVERSCROLL_NONE); |
| + EXPECT_FALSE(overscroll_complete()); |
| + |
| + Reset(); |
| + // Start an OVERSCROLL_WEST gesture. |
| + generator.GestureScrollSequence( |
| + gfx::Point(10 + touch_start_threshold() + 10, 10), |
| + gfx::Point(10, 10), |
| + base::TimeDelta::FromMilliseconds(10), |
| + 10); |
| + EXPECT_TRUE(overscroll_started()); |
| + EXPECT_EQ(current_mode(), OVERSCROLL_NONE); |
| + EXPECT_FALSE(overscroll_complete()); |
| +} |
| + |
| +} // namespace content |