Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "public/web/WebScriptSource.h" | |
| 6 #include "testing/gtest/include/gtest/gtest.h" | |
| 7 #include "web/WebLocalFrameImpl.h" | |
| 8 #include "web/tests/sim/SimCompositor.h" | |
| 9 #include "web/tests/sim/SimDisplayItemList.h" | |
| 10 #include "web/tests/sim/SimRequest.h" | |
| 11 #include "web/tests/sim/SimTest.h" | |
| 12 | |
| 13 namespace blink { | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 class SmoothScrollTest : public SimTest {}; | |
| 18 | |
| 19 TEST_F(SmoothScrollTest, InstantScroll) { | |
| 20 v8::HandleScope handleScope(v8::Isolate::GetCurrent()); | |
| 21 webView().resize(WebSize(800, 600)); | |
| 22 SimRequest request("https://example.com/test.html", "text/html"); | |
| 23 loadURL("https://example.com/test.html"); | |
| 24 request.complete( | |
| 25 "<div id='space' style='height: 1000px'></div>" | |
| 26 "<div id='block' style='height: 1000px'></div>"); | |
| 27 | |
| 28 compositor().beginFrame(); | |
| 29 ASSERT_EQ(0, window().scrollY()); | |
| 30 mainFrame().executeScriptAndReturnValue( | |
| 31 WebScriptSource("document.getElementById('block').scrollIntoView();")); | |
| 32 | |
| 33 compositor().beginFrame(); | |
| 34 ASSERT_GE(window().scrollY(), 1000); | |
| 35 } | |
| 36 | |
| 37 TEST_F(SmoothScrollTest, SmoothScroll) { | |
| 38 v8::HandleScope handleScope(v8::Isolate::GetCurrent()); | |
| 39 webView().resize(WebSize(800, 600)); | |
| 40 SimRequest request("https://example.com/test.html", "text/html"); | |
| 41 loadURL("https://example.com/test.html"); | |
| 42 request.complete( | |
| 43 "<div id='space' style='height: 1000px'></div>" | |
| 44 "<div id='block' style='height: 1000px'></div>"); | |
| 45 | |
| 46 compositor().beginFrame(); | |
| 47 ASSERT_EQ(0, window().scrollY()); | |
| 48 | |
| 49 mainFrame().executeScriptAndReturnValue( | |
| 50 WebScriptSource("document.getElementById('block').scrollIntoView(" | |
| 51 "{block: 'start', behavior: 'smooth'});")); | |
| 52 compositor().beginFrame(); | |
| 53 ASSERT_LT(window().scrollY(), 100); | |
| 54 | |
| 55 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.
| |
| 56 compositor().beginFrame(); | |
| 57 } | |
| 58 ASSERT_GT(window().scrollY(), 200); | |
| 59 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.
| |
| 60 | |
| 61 while (compositor().needsBeginFrame()) { | |
| 62 compositor().beginFrame(); | |
| 63 } | |
| 64 ASSERT_GE(window().scrollY(), 1000); | |
| 65 } | |
|
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.
| |
| 66 | |
| 67 } // namespace | |
| 68 | |
| 69 } // namespace blink | |
| OLD | NEW |