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

Side by Side Diff: third_party/WebKit/Source/web/tests/SmoothScrollTest.cpp

Issue 2650343008: Implement Element.scrollIntoView for scroll-behavior: smooth. (Closed)
Patch Set: Rebase Created 3 years, 8 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 unified diff | Download patch
OLDNEW
(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(window().scrollY(), 0);
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 // Scrolling the container
56 compositor().beginFrame();
sunyunjia 2017/04/07 13:53:21 Seems I have to add this extra beginFrame() to sta
bokan 2017/04/07 15:56:52 Does this mean the ASSERT above should be scrollY
sunyunjia 2017/05/12 18:40:25 I did some investigation. In the 1st BeginFrame(),
bokan 2017/05/15 17:15:27 Ahh, that makes sense - thanks for digging into it
57 compositor().beginFrame(0.2);
58 ASSERT_GT(window().scrollY(), 250);
59 ASSERT_LT(window().scrollY(), 350);
60
61 // Finish scrolling the container
62 compositor().beginFrame(1);
63 ASSERT_GE(window().scrollY(), 1000);
bokan 2017/04/07 15:56:52 This should be testing scrollY == 1000 right? if w
sunyunjia 2017/05/12 18:40:25 Done.
64 }
65
66 TEST_F(SmoothScrollTest, NestedContainer) {
67 v8::HandleScope handleScope(v8::Isolate::GetCurrent());
68 webView().resize(WebSize(800, 600));
69 SimRequest request("https://example.com/test.html", "text/html");
70 loadURL("https://example.com/test.html");
71 request.complete(
72 "<div id='space' style='height: 1000px'></div>"
73 "<div id='container' style='height: 600px; overflow: scroll'>"
74 " <div id='space1' style='height: 1000px'></div>"
75 " <div id='block' style='height: 1000px'></div>"
76 "</div>");
77
78 compositor().beginFrame();
79 Element* container = document().getElementById("container");
80
81 ASSERT_EQ(window().scrollY(), 0);
82 ASSERT_EQ(container->scrollTop(), 0);
83
84 mainFrame().executeScriptAndReturnValue(
85 WebScriptSource("document.getElementById('block').scrollIntoView("
86 "{block: 'start', behavior: 'smooth'});"));
87 compositor().beginFrame();
88 ASSERT_LT(window().scrollY(), 100);
89
90 // Scrolling the outer container
91 compositor().beginFrame();
92 compositor().beginFrame(0.2);
93 ASSERT_GT(window().scrollY(), 250);
94 ASSERT_LT(window().scrollY(), 350);
95 ASSERT_EQ(container->scrollTop(), 0);
96
97 // Finish scrolling the outer container
98 compositor().beginFrame(1);
99 ASSERT_GE(window().scrollY(), 1000);
100 ASSERT_LE(container->scrollTop(), 20);
101
102 // Scrolling the inner container
103 compositor().beginFrame();
104 compositor().beginFrame(0.2);
105 ASSERT_GE(container->scrollTop(), 250);
106 ASSERT_LE(container->scrollTop(), 350);
107
108 // Finish scrolling the inner container
109 compositor().beginFrame(1);
110 ASSERT_GE(container->scrollTop(), 1000);
111 }
112
bokan 2017/04/07 15:56:52 If we start another programmatic smooth scroll (or
sunyunjia 2017/05/12 18:40:25 Thanks! I would cancel the original one.
bokan 2017/05/15 17:15:27 Correct me if I'm wrong but I think your current p
113 } // namespace
114
115 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698