-
Notifications
You must be signed in to change notification settings - Fork 54
/
scroll-timeline-phases.tentative.html
186 lines (167 loc) · 5.18 KB
/
scroll-timeline-phases.tentative.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<!DOCTYPE html>
<meta charset=utf-8>
<title>Test basic functionality of scroll timeline phases.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/web-animations/testcommon.js"></script>
<script src="testcommon.js"></script>
<style>
.scroller {
overflow: auto;
height: 100px;
width: 100px;
}
.contents {
height: 1000px;
width: 100%;
}
</style>
<div id="log"></div>
<script>
'use strict';
promise_test(async t => {
const timeline = createScrollTimeline(t);
assert_throws_js(TypeError, () => {
timeline.phase = "after";
});
}, 'Setting scroll timeline phase (which is readonly) throws TypeError.');
const test_cases = {
before_start: {
name: "before start",
scroll_percent: 0.1,
timeline_phase: "before"
},
at_start: {
name: "at start",
scroll_percent: 0.2,
timeline_phase: "active"
},
in_range: {
name: "in range",
scroll_percent: 0.5,
timeline_phase: "active"
},
at_end: {
name: "at end",
scroll_percent: 0.8,
timeline_phase: "after"
},
after_end: {
name: "after end",
scroll_percent: 0.9,
timeline_phase: "after"
}
}
for (const test_case_key in test_cases){
const test_case = test_cases[test_case_key];
test(t => {
const timeline = createScrollTimelineWithOffsets(t, "20%", "80%");
const scroller = timeline.scrollSource;
const maxScroll = scroller.scrollHeight - scroller.clientHeight;
scroller.scrollTop = test_case.scroll_percent * maxScroll;
assert_equals(
timeline.phase,
test_case.timeline_phase,
"timeline.phase"
);
}, "Timeline phase while scroll offset is " + test_case.name);
}
// TODO(crbug.com/1060384): Spec is unclear in this case, revisit this when
// desired results have been established.
// These test cases are worded strangely because they test an edge case
// where startScrollOffset is GREATER THAN endScrollOffset
const test_cases_start_offset_greater_than_end_offset = {
before_end: {
name: "before end",
scroll_percent: 0.1,
timeline_phase: "before"
},
at_end: {
name: "at end",
scroll_percent: 0.2,
timeline_phase: "before"
},
before_start: {
name: "before start",
scroll_percent: 0.5,
timeline_phase: "before"
},
at_start: {
name: "at start",
scroll_percent: 0.8,
timeline_phase: "after"
},
after_start: {
name: "after start",
scroll_percent: 0.9,
timeline_phase: "after"
}
}
for (const test_case_key in test_cases_start_offset_greater_than_end_offset){
const test_case =
test_cases_start_offset_greater_than_end_offset[test_case_key];
test(t => {
const timeline = createScrollTimelineWithOffsets(t, "80%", "20%");
const scroller = timeline.scrollSource;
const maxScroll = scroller.scrollHeight - scroller.clientHeight;
scroller.scrollTop = test_case.scroll_percent * maxScroll;
assert_equals(
timeline.phase,
test_case.timeline_phase,
"timeline.phase"
);
}, "Timeline phase while start offset is greater than end offset and" +
" scroll offset is " + test_case.name);
}
// TODO(crbug.com/1060384): Spec is unclear in this case, revisit this when
// desired results have been established.
// Test cases where startScrollOffset is EQUAL TO endScrollOffset
const test_cases_start_offset_equal_to_end_offset = {
before_end: {
name: "before start",
scroll_percent: 0.3,
timeline_phase: "before"
},
at_end: {
name: "at both",
scroll_percent: 0.5,
timeline_phase: "after"
},
before_start: {
name: "after end",
scroll_percent: 0.7,
timeline_phase: "after"
}
}
for (const test_case_key in test_cases_start_offset_equal_to_end_offset){
const test_case =
test_cases_start_offset_equal_to_end_offset[test_case_key];
test(t => {
const timeline = createScrollTimelineWithOffsets(t, "50%", "50%");
const scroller = timeline.scrollSource;
const maxScroll = scroller.scrollHeight - scroller.clientHeight;
scroller.scrollTop = test_case.scroll_percent * maxScroll;
assert_equals(
timeline.phase,
test_case.timeline_phase,
"timeline.phase"
);
}, "Timeline phase while start offset is equal to end offset and scroll" +
" offset is " + test_case.name);
}
test(t => {
const timeline = createScrollTimeline(t);
const scroller = timeline.scrollSource;
// Timeline should be inactive since layout hasn't updated yet
assert_equals(timeline.phase, "inactive");
// Accessing scroller.scrollHeight forces the scroller to update
scroller.scrollHeight;
assert_equals(timeline.phase, "active");
// Setting the scroller to display none should make the timeline inactive
scroller.style.display = "none"
// Force another layout
scroller.scrollHeight;
assert_equals(timeline.phase, "inactive");
}, 'Scroll timeline starts inactive, can transition to active, and then' +
' back to inactive.');
</script>