Chromium Code Reviews| Index: third_party/WebKit/Source/web/tests/SmoothScrollTest.cpp |
| diff --git a/third_party/WebKit/Source/web/tests/SmoothScrollTest.cpp b/third_party/WebKit/Source/web/tests/SmoothScrollTest.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5ba754788965c37095454b50dfd227adee0e05c9 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/web/tests/SmoothScrollTest.cpp |
| @@ -0,0 +1,69 @@ |
| +// Copyright 2017 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 "public/web/WebScriptSource.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "web/WebLocalFrameImpl.h" |
| +#include "web/tests/sim/SimCompositor.h" |
| +#include "web/tests/sim/SimDisplayItemList.h" |
| +#include "web/tests/sim/SimRequest.h" |
| +#include "web/tests/sim/SimTest.h" |
| + |
| +namespace blink { |
| + |
| +namespace { |
| + |
| +class SmoothScrollTest : public SimTest {}; |
| + |
| +TEST_F(SmoothScrollTest, InstantScroll) { |
| + v8::HandleScope handleScope(v8::Isolate::GetCurrent()); |
| + webView().resize(WebSize(800, 600)); |
| + SimRequest request("https://example.com/test.html", "text/html"); |
| + loadURL("https://example.com/test.html"); |
| + request.complete( |
| + "<div id='space' style='height: 1000px'></div>" |
| + "<div id='block' style='height: 1000px'></div>"); |
| + |
| + compositor().beginFrame(); |
| + ASSERT_EQ(0, window().scrollY()); |
| + mainFrame().executeScriptAndReturnValue( |
| + WebScriptSource("document.getElementById('block').scrollIntoView();")); |
| + |
| + compositor().beginFrame(); |
| + ASSERT_GE(window().scrollY(), 1000); |
| +} |
| + |
| +TEST_F(SmoothScrollTest, SmoothScroll) { |
| + v8::HandleScope handleScope(v8::Isolate::GetCurrent()); |
| + webView().resize(WebSize(800, 600)); |
| + SimRequest request("https://example.com/test.html", "text/html"); |
| + loadURL("https://example.com/test.html"); |
| + request.complete( |
| + "<div id='space' style='height: 1000px'></div>" |
| + "<div id='block' style='height: 1000px'></div>"); |
| + |
| + compositor().beginFrame(); |
| + ASSERT_EQ(0, window().scrollY()); |
| + |
| + mainFrame().executeScriptAndReturnValue( |
| + WebScriptSource("document.getElementById('block').scrollIntoView(" |
| + "{block: 'start', behavior: 'smooth'});")); |
| + compositor().beginFrame(); |
| + ASSERT_LT(window().scrollY(), 100); |
| + |
| + for (int i = 0; i < 1500; ++i) { |
|
bokan
2017/03/28 16:29:53
You can modify beginFrame to take a deltaTime so t
sunyunjia
2017/04/07 13:53:21
Done.
|
| + compositor().beginFrame(); |
| + } |
| + ASSERT_GT(window().scrollY(), 200); |
| + ASSERT_LT(window().scrollY(), 1000); |
|
bokan
2017/03/28 16:29:53
Is there a reason this range is so wide? Presumabl
sunyunjia
2017/04/07 13:53:21
Done.
|
| + |
| + while (compositor().needsBeginFrame()) { |
| + compositor().beginFrame(); |
| + } |
| + ASSERT_GE(window().scrollY(), 1000); |
| +} |
|
bokan
2017/03/28 16:29:53
We should add a test for the nested case to test t
sunyunjia
2017/04/07 13:53:21
Done.
|
| + |
| +} // namespace |
| + |
| +} // namespace blink |