summaryrefslogtreecommitdiffstats
path: root/layout/base/tests/test_scroll_snapping.html
blob: 1ba862ee1ca5a1feb704c8e3892bedc7816e34b5 (plain)
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
<!DOCTYPE HTML>
<html>
<head>
  <title>Test for scroll snapping</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>

<p id="display"></p>
<div id="sc" style="margin: 0px; padding: 0px; overflow: scroll; width: 500px; height: 250px;">
  <div id="sd" style="margin: 0px; padding: 0px; width: 1500px; height: 1250px;"></div>
</div>

<pre id="test">
<script class="testbody" type="text/javascript">

var testCases = [
  {
    "description"             : "Proximity + Within proximity => Snaps to point (Right)",
    "scrollSnapType"          : "proximity",
    "scrollSnapPointsX"       : "none",
    "scrollSnapPointsY"       : "none",
    "scrollSnapDestination"   : "0px 0px",
    "scrollSnapCoordinate"    : "525px 500px",
    "initialX"                : 500,
    "initialY"                : 500,
    "key"                     : "VK_RIGHT",
    "expectedX"               : 525,
    "expectedY"               : 500,
    "notExpected"             : false
  },

  {
    "description"             : "Proximity + Within proximity => Snaps to point (Left)",
    "scrollSnapType"          : "proximity",
    "scrollSnapPointsX"       : "none",
    "scrollSnapPointsY"       : "none",
    "scrollSnapDestination"   : "0px 0px",
    "scrollSnapCoordinate"    : "475px 500px",
    "initialX"                : 500,
    "initialY"                : 500,
    "key"                     : "VK_LEFT",
    "expectedX"               : 475,
    "expectedY"               : 500,
    "notExpected"             : false
  },

  {
    "description"             : "Proximity + Within proximity => Snaps to point (Up)",
    "scrollSnapType"          : "proximity",
    "scrollSnapPointsX"       : "none",
    "scrollSnapPointsY"       : "none",
    "scrollSnapDestination"   : "0px 0px",
    "scrollSnapCoordinate"    : "500px 475px",
    "initialX"                : 500,
    "initialY"                : 500,
    "key"                     : "VK_UP",
    "expectedX"               : 500,
    "expectedY"               : 475,
    "notExpected"             : false
  },

  {
    "description"             : "Proximity + Within proximity => Snaps to point (Down)",
    "scrollSnapType"          : "proximity",
    "scrollSnapPointsX"       : "none",
    "scrollSnapPointsY"       : "none",
    "scrollSnapDestination"   : "0px 0px",
    "scrollSnapCoordinate"    : "500px 525px",
    "initialX"                : 500,
    "initialY"                : 500,
    "key"                     : "VK_DOWN",
    "expectedX"               : 500,
    "expectedY"               : 525,
    "notExpected"             : false
  },

  {
    "description"             : "Proximity + Beyond proximity => Does not snap to point (Right)",
    "scrollSnapType"          : "proximity",
    "scrollSnapPointsX"       : "none",
    "scrollSnapPointsY"       : "none",
    "scrollSnapDestination"   : "0px 0px",
    "scrollSnapCoordinate"    : "700px 500px",
    "initialX"                : 500,
    "initialY"                : 500,
    "key"                     : "VK_RIGHT",
    "expectedX"               : 700,
    "expectedY"               : 500,
    "notExpected"             : true
  },

  {
    "description"             : "Proximity + Beyond proximity => Does not snap to point (Left)",
    "scrollSnapType"          : "proximity",
    "scrollSnapPointsX"       : "none",
    "scrollSnapPointsY"       : "none",
    "scrollSnapDestination"   : "0px 0px",
    "scrollSnapCoordinate"    : "300px 500px",
    "initialX"                : 500,
    "initialY"                : 500,
    "key"                     : "VK_LEFT",
    "expectedX"               : 300,
    "expectedY"               : 500,
    "notExpected"             : true
  },

  {
    "description"             : "Proximity + Beyond proximity => Does not snap to point (Up)",
    "scrollSnapType"          : "proximity",
    "scrollSnapPointsX"       : "none",
    "scrollSnapPointsY"       : "none",
    "scrollSnapDestination"   : "0px 0px",
    "scrollSnapCoordinate"    : "500px 300px",
    "initialX"                : 500,
    "initialY"                : 500,
    "key"                     : "VK_UP",
    "expectedX"               : 500,
    "expectedY"               : 300,
    "notExpected"             : true
  },

  {
    "description"             : "Proximity + Beyond proximity => Does not snap to point (Down)",
    "scrollSnapType"          : "proximity",
    "scrollSnapPointsX"       : "none",
    "scrollSnapPointsY"       : "none",
    "scrollSnapDestination"   : "0px 0px",
    "scrollSnapCoordinate"    : "500px 700px",
    "initialX"                : 500,
    "initialY"                : 500,
    "key"                     : "VK_DOWN",
    "expectedX"               : 500,
    "expectedY"               : 700,
    "notExpected"             : true
  },

  {
    "description"             : "Mandatory + Beyond proximity => Snaps to point (Right)",
    "scrollSnapType"          : "mandatory",
    "scrollSnapPointsX"       : "none",
    "scrollSnapPointsY"       : "none",
    "scrollSnapDestination"   : "0px 0px",
    "scrollSnapCoordinate"    : "700px 500px",
    "initialX"                : 500,
    "initialY"                : 500,
    "key"                     : "VK_RIGHT",
    "expectedX"               : 700,
    "expectedY"               : 500,
    "notExpected"             : false
  },

  {
    "description"             : "Mandatory + Beyond proximity => Snaps to point (Left)",
    "scrollSnapType"          : "mandatory",
    "scrollSnapPointsX"       : "none",
    "scrollSnapPointsY"       : "none",
    "scrollSnapDestination"   : "0px 0px",
    "scrollSnapCoordinate"    : "300px 500px",
    "initialX"                : 500,
    "initialY"                : 500,
    "key"                     : "VK_LEFT",
    "expectedX"               : 300,
    "expectedY"               : 500,
    "notExpected"             : false
  },

  {
    "description"             : "Mandatory + Beyond proximity => Snaps to point (Up)",
    "scrollSnapType"          : "mandatory",
    "scrollSnapPointsX"       : "none",
    "scrollSnapPointsY"       : "none",
    "scrollSnapDestination"   : "0px 0px",
    "scrollSnapCoordinate"    : "500px 300px",
    "initialX"                : 500,
    "initialY"                : 500,
    "key"                     : "VK_UP",
    "expectedX"               : 500,
    "expectedY"               : 300,
    "notExpected"             : false
  },

  {
    "description"             : "Mandatory + Beyond proximity => Snaps to point (Down)",
    "scrollSnapType"          : "mandatory",
    "scrollSnapPointsX"       : "none",
    "scrollSnapPointsY"       : "none",
    "scrollSnapDestination"   : "0px 0px",
    "scrollSnapCoordinate"    : "500px 700px",
    "initialX"                : 500,
    "initialY"                : 500,
    "key"                     : "VK_DOWN",
    "expectedX"               : 500,
    "expectedY"               : 700,
    "notExpected"             : false
  },

  {
    "description"             : "Mandatory + No snap points => Does not snap or scroll (Left)",
    "scrollSnapType"          : "mandatory",
    "scrollSnapPointsX"       : "none",
    "scrollSnapPointsY"       : "none",
    "scrollSnapDestination"   : "0px 0px",
    "scrollSnapCoordinate"    : "none",
    "initialX"                : 500,
    "initialY"                : 500,
    "key"                     : "VK_LEFT",
    "expectedX"               : 500,
    "expectedY"               : 500,
    "notExpected"             : false
  },

  {
    "description"             : "Mandatory + No snap points => Does not snap or scroll (Right)",
    "scrollSnapType"          : "mandatory",
    "scrollSnapPointsX"       : "none",
    "scrollSnapPointsY"       : "none",
    "scrollSnapDestination"   : "0px 0px",
    "scrollSnapCoordinate"    : "none",
    "initialX"                : 500,
    "initialY"                : 500,
    "key"                     : "VK_RIGHT",
    "expectedX"               : 500,
    "expectedY"               : 500,
    "notExpected"             : false
  },

  {
    "description"             : "Mandatory + No snap points => Does not snap or scroll (Up)",
    "scrollSnapType"          : "mandatory",
    "scrollSnapPointsX"       : "none",
    "scrollSnapPointsY"       : "none",
    "scrollSnapDestination"   : "0px 0px",
    "scrollSnapCoordinate"    : "none",
    "initialX"                : 500,
    "initialY"                : 500,
    "key"                     : "VK_UP",
    "expectedX"               : 500,
    "expectedY"               : 500,
    "notExpected"             : false
  },

  {
    "description"             : "Mandatory + No snap points => Does not snap or scroll (Down)",
    "scrollSnapType"          : "mandatory",
    "scrollSnapPointsX"       : "none",
    "scrollSnapPointsY"       : "none",
    "scrollSnapDestination"   : "0px 0px",
    "scrollSnapCoordinate"    : "none",
    "initialX"                : 500,
    "initialY"                : 500,
    "key"                     : "VK_DOWN",
    "expectedX"               : 500,
    "expectedY"               : 500,
    "notExpected"             : false
  },

  {
    "description"             : "Mandatory + scroll-snap-points-y + scroll-snap-destination + Start of page + No snap point at start of page => Does not snap to top of page (Up)",
    "scrollSnapType"          : "mandatory",
    "scrollSnapPointsX"       : "none",
    "scrollSnapPointsY"       : "repeat(500px)",
    "scrollSnapDestination"   : "25px 25px",
    "scrollSnapCoordinate"    : "none",
    "initialX"                : 0,
    "initialY"                : 200,
    "key"                     : "VK_UP",
    "expectedX"               : 0,
    "expectedY"               : 200,
    "notExpected"             : false
  },

  {
    "description"             : "Mandatory + scroll-snap-points-y + scroll-snap-destination + Start of page + No snap point at start of page => Does not snap to top of page (Page Up)",
    "scrollSnapType"          : "mandatory",
    "scrollSnapPointsX"       : "none",
    "scrollSnapPointsY"       : "repeat(500px)",
    "scrollSnapDestination"   : "25px 25px",
    "scrollSnapCoordinate"    : "none",
    "initialX"                : 0,
    "initialY"                : 200,
    "key"                     : "VK_PAGE_UP",
    "expectedX"               : 0,
    "expectedY"               : 200,
    "notExpected"             : false
  },

  {
    "description"             : "Mandatory + scroll-snap-points-y + scroll-snap-destination + Start of page + No snap point at start of page => Snaps to highest snap point (Home)",
    "scrollSnapType"          : "mandatory",
    "scrollSnapPointsX"       : "none",
    "scrollSnapPointsY"       : "repeat(500px)",
    "scrollSnapDestination"   : "25px 25px",
    "scrollSnapCoordinate"    : "none",
    "initialX"                : 0,
    "initialY"                : 200,
    "key"                     : "VK_HOME",
    "expectedX"               : 0,
    "expectedY"               : 475,
    "notExpected"             : false
  },

  {
    "description"             : "Mandatory + scroll-snap-points-x + scroll-snap-destination + Start of page + No snap point at start of page => Does not snap to left of page (Left)",
    "scrollSnapType"          : "mandatory",
    "scrollSnapPointsX"       : "repeat(500px)",
    "scrollSnapPointsY"       : "none",
    "scrollSnapDestination"   : "25px 25px",
    "scrollSnapCoordinate"    : "none",
    "initialX"                : 200,
    "initialY"                : 0,
    "key"                     : "VK_LEFT",
    "expectedX"               : 200,
    "expectedY"               : 0,
    "notExpected"             : false
  },

  {
    "description"             : "Mandatory + scroll-snap-points-y + negative scroll-snap-destination + End of page + No snap point at end of page => Does not snap to end of page (Down)",
    "scrollSnapType"          : "mandatory",
    "scrollSnapPointsX"       : "none",
    "scrollSnapPointsY"       : "repeat(500px)",
    "scrollSnapDestination"   : "-25px -25px",
    "scrollSnapCoordinate"    : "none",
    "initialX"                : 0,
    "initialY"                : 800,
    "key"                     : "VK_DOWN",
    "expectedX"               : 0,
    "expectedY"               : 800,
    "notExpected"             : false
  },

  {
    "description"             : "Mandatory + scroll-snap-points-y + negative scroll-snap-destination + End of page + No snap point at end of page => Does not snap to end of page (Page Down)",
    "scrollSnapType"          : "mandatory",
    "scrollSnapPointsX"       : "none",
    "scrollSnapPointsY"       : "repeat(500px)",
    "scrollSnapDestination"   : "-25px -25px",
    "scrollSnapCoordinate"    : "none",
    "initialX"                : 0,
    "initialY"                : 800,
    "key"                     : "VK_PAGE_DOWN",
    "expectedX"               : 0,
    "expectedY"               : 800,
    "notExpected"             : false
  },

  {
    "description"             : "Mandatory + scroll-snap-points-y + negative scroll-snap-destination + End of page + No snap point at end of page => Snaps to lowest snap point (End)",
    "scrollSnapType"          : "mandatory",
    "scrollSnapPointsX"       : "none",
    "scrollSnapPointsY"       : "repeat(500px)",
    "scrollSnapDestination"   : "-25px -25px",
    "scrollSnapCoordinate"    : "none",
    "initialX"                : 0,
    "initialY"                : 800,
    "key"                     : "VK_END",
    "expectedX"               : 0,
    "expectedY"               : 525,
    "notExpected"             : false
  },

  {
    "description"             : "Mandatory + scroll-snap-coordinate + No snap point at start of page => Does not snap to top of page (Home)",
    "scrollSnapType"          : "mandatory",
    "scrollSnapPointsX"       : "none",
    "scrollSnapPointsY"       : "none",
    "scrollSnapDestination"   : "0px 0px",
    "scrollSnapCoordinate"    : "500px 100px",
    "initialX"                : 500,
    "initialY"                : 500,
    "key"                     : "VK_HOME",
    "expectedX"               : 500,
    "expectedY"               : 100,
    "notExpected"             : false
  },

  {
    "description"             : "Mandatory + scroll-snap-coordinate + No snap point at end of page => Does not snap to end of page (End)",
    "scrollSnapType"          : "mandatory",
    "scrollSnapPointsX"       : "none",
    "scrollSnapPointsY"       : "none",
    "scrollSnapDestination"   : "0px 0px",
    "scrollSnapCoordinate"    : "500px 900px",
    "initialX"                : 500,
    "initialY"                : 500,
    "key"                     : "VK_END",
    "expectedX"               : 500,
    "expectedY"               : 900,
    "notExpected"             : false
  },

  {
    "description"             : "Mandatory + scroll-snap-points-y greater than scrolling rect + positive non-zero scroll-snap-destination => No snap points, does not scroll or snap (Left)",
    "scrollSnapType"          : "mandatory",
    "scrollSnapPointsX"       : "none",
    "scrollSnapPointsY"       : "repeat(1500px)",
    "scrollSnapDestination"   : "25px 25px",
    "scrollSnapCoordinate"    : "none",
    "initialX"                : 500,
    "initialY"                : 500,
    "key"                     : "VK_LEFT",
    "expectedX"               : 500,
    "expectedY"               : 500,
    "notExpected"             : false
  },

  {
    "description"             : "Mandatory + scroll-snap-points-y greater than scrolling rect + positive non-zero scroll-snap-destination => No snap points, does not scroll or snap (Right)",
    "scrollSnapType"          : "mandatory",
    "scrollSnapPointsX"       : "none",
    "scrollSnapPointsY"       : "repeat(1500px)",
    "scrollSnapDestination"   : "25px 25px",
    "scrollSnapCoordinate"    : "none",
    "initialX"                : 500,
    "initialY"                : 500,
    "key"                     : "VK_RIGHT",
    "expectedX"               : 500,
    "expectedY"               : 500,
    "notExpected"             : false
  },

  {
    "description"             : "Mandatory + scroll-snap-points-y greater than scrolling rect + positive non-zero scroll-snap-destination => No snap points, does not scroll or snap (Up)",
    "scrollSnapType"          : "mandatory",
    "scrollSnapPointsX"       : "none",
    "scrollSnapPointsY"       : "repeat(1500px)",
    "scrollSnapDestination"   : "25px 25px",
    "scrollSnapCoordinate"    : "none",
    "initialX"                : 500,
    "initialY"                : 500,
    "key"                     : "VK_UP",
    "expectedX"               : 500,
    "expectedY"               : 500,
    "notExpected"             : false
  },

  {
    "description"             : "Mandatory + scroll-snap-points-y greater than scrolling rect + positive non-zero scroll-snap-destination => No snap points, does not scroll or snap (Down)",
    "scrollSnapType"          : "mandatory",
    "scrollSnapPointsX"       : "none",
    "scrollSnapPointsY"       : "repeat(1500px)",
    "scrollSnapDestination"   : "25px 25px",
    "scrollSnapCoordinate"    : "none",
    "initialX"                : 500,
    "initialY"                : 500,
    "key"                     : "VK_DOWN",
    "expectedX"               : 500,
    "expectedY"               : 500,
    "notExpected"             : false
  },

  {
    "description"             : "Mandatory + scroll-snap-points-{x|y} + scroll-snap-coordinate with two points => Interval and element snapping points are combined. Test 1 snap point generated by scroll-snap-points-{x|y} and two generated by scroll-snap-coordinate, ensure that they are evaluated as snap points. (Right #1)",
    "scrollSnapType"          : "mandatory",
    "scrollSnapPointsX"       : "repeat(200px)",
    "scrollSnapPointsY"       : "repeat(200px)",
    "scrollSnapDestination"   : "0px 0px",
    "scrollSnapCoordinate"    : "120px 120px, 220px 220px",
    "initialX"                : 0,
    "initialY"                : 0,
    "key"                     : "VK_RIGHT",
    "expectedX"               : 120,
    "expectedY"               : 0,
    "notExpected"             : false
  },

  {
    "description"             : "Mandatory + scroll-snap-points-{x|y} + scroll-snap-coordinate with two points => Interval and element snapping points are combined. Test 1 snap point generated by scroll-snap-points-{x|y} and two generated by scroll-snap-coordinate, ensure that they are evaluated as snap points. (Right #2)",
    "scrollSnapType"          : "mandatory",
    "scrollSnapPointsX"       : "repeat(200px)",
    "scrollSnapPointsY"       : "repeat(200px)",
    "scrollSnapDestination"   : "0px 0px",
    "scrollSnapCoordinate"    : "120px 120px, 220px 220px",
    "initialX"                : 120,
    "initialY"                : 0,
    "key"                     : "VK_RIGHT",
    "expectedX"               : 200,
    "expectedY"               : 0,
    "notExpected"             : false
  },


  {
    "description"             : "Mandatory + scroll-snap-points-{x|y} + scroll-snap-coordinate with two points => Interval and element snapping points are combined. Test 1 snap point generated by scroll-snap-points-{x|y} and two generated by scroll-snap-coordinate, ensure that they are evaluated as snap points. (Right #3)",
    "scrollSnapType"          : "mandatory",
    "scrollSnapPointsX"       : "repeat(200px)",
    "scrollSnapPointsY"       : "repeat(200px)",
    "scrollSnapDestination"   : "0px 0px",
    "scrollSnapCoordinate"    : "120px 120px, 220px 220px",
    "initialX"                : 200,
    "initialY"                : 0,
    "key"                     : "VK_RIGHT",
    "expectedX"               : 220,
    "expectedY"               : 0,
    "notExpected"             : false
  },

  {
    "description"             : "Mandatory + scroll-snap-points-{x|y} + scroll-snap-coordinate with two points => Interval and element snapping points are combined. Test 1 snap point generated by scroll-snap-points-{x|y} and two generated by scroll-snap-coordinate, ensure that they are evaluated as snap points. (Up #1)",
    "scrollSnapType"          : "mandatory",
    "scrollSnapPointsX"       : "repeat(200px)",
    "scrollSnapPointsY"       : "repeat(200px)",
    "scrollSnapDestination"   : "0px 0px",
    "scrollSnapCoordinate"    : "120px 120px, 220px 220px",
    "initialX"                : 0,
    "initialY"                : 300,
    "key"                     : "VK_UP",
    "expectedX"               : 0,
    "expectedY"               : 220,
    "notExpected"             : false
  },

  {
    "description"             : "Mandatory + scroll-snap-points-{x|y} + scroll-snap-coordinate with two points => Interval and element snapping points are combined. Test 1 snap point generated by scroll-snap-points-{x|y} and two generated by scroll-snap-coordinate, ensure that they are evaluated as snap points. (Up #2)",
    "scrollSnapType"          : "mandatory",
    "scrollSnapPointsX"       : "repeat(200px)",
    "scrollSnapPointsY"       : "repeat(200px)",
    "scrollSnapDestination"   : "0px 0px",
    "scrollSnapCoordinate"    : "120px 120px, 220px 220px",
    "initialX"                : 0,
    "initialY"                : 220,
    "key"                     : "VK_UP",
    "expectedX"               : 0,
    "expectedY"               : 200,
    "notExpected"             : false
  },

  {
    "description"             : "Mandatory + scroll-snap-points-{x|y} + scroll-snap-coordinate with two points => Interval and element snapping points are combined. Test 1 snap point generated by scroll-snap-points-{x|y} and two generated by scroll-snap-coordinate, ensure that they are evaluated as snap points. (Up #3)",
    "scrollSnapType"          : "mandatory",
    "scrollSnapPointsX"       : "repeat(200px)",
    "scrollSnapPointsY"       : "repeat(200px)",
    "scrollSnapDestination"   : "0px 0px",
    "scrollSnapCoordinate"    : "120px 120px, 220px 220px",
    "initialX"                : 0,
    "initialY"                : 200,
    "key"                     : "VK_UP",
    "expectedX"               : 0,
    "expectedY"               : 120,
    "notExpected"             : false
  },

  {
    "description"             : "Ensure that when paging down/up that the next snap point in the direction of the scroll is selected rather than a closer point in the opposite direction (page Down)",
    "scrollSnapType"          : "mandatory",
    "scrollSnapPointsX"       : "none",
    "scrollSnapPointsY"       : "none",
    "scrollSnapDestination"   : "0px 0px",
    "scrollSnapCoordinate"    : "600px 600px, 475px 475px",
    "initialX"                : 500,
    "initialY"                : 500,
    "key"                     : "VK_PAGE_DOWN",
    "expectedX"               : 500,
    "expectedY"               : 600,
    "notExpected"             : false
  },

  {
    "description"             : "Ensure that when paging down/up that the next snap point in the direction of the scroll is selected rather than a closer point in the opposite direction (Page Up)",
    "scrollSnapType"          : "mandatory",
    "scrollSnapPointsX"       : "none",
    "scrollSnapPointsY"       : "none",
    "scrollSnapDestination"   : "0px 0px",
    "scrollSnapCoordinate"    : "400px 400px, 525px 525px",
    "initialX"                : 500,
    "initialY"                : 500,
    "key"                     : "VK_PAGE_UP",
    "expectedX"               : 500,
    "expectedY"               : 400,
    "notExpected"             : false
  },

  {
    "description"             : "Ensure that when paging down/up that the farthest snap point before the destination is selected and prioritized over a snap point that is past the destination, even if the snap point past the destination is closer to the destination.  Setup - two snap points between current position and destination and one snap point past the destination which is closer than any of the other points. Scrollable rect size is 500px. (Page Down)",
    "scrollSnapType"          : "mandatory",
    "scrollSnapPointsX"       : "none",
    "scrollSnapPointsY"       : "none",
    "scrollSnapDestination"   : "0px 0px",
    "scrollSnapCoordinate"    : "525px 525px, 550px 550px, 800px 800px",
    "initialX"                : 500,
    "initialY"                : 500,
    "key"                     : "VK_PAGE_DOWN",
    "expectedX"               : 500,
    "expectedY"               : 550,
    "notExpected"             : false
  },

  {
    "description"             : "Ensure that when paging down/up that the farthest snap point before the destination is selected and prioritized over a snap point that is past the destination, even if the snap point past the destination is closer to the destination.  Setup - two snap points between current position and destination and one snap point past the destination which is closer than any of the other points. Scrollable rect size is 500px. (Page Up)",
    "scrollSnapType"          : "mandatory",
    "scrollSnapPointsX"       : "none",
    "scrollSnapPointsY"       : "none",
    "scrollSnapDestination"   : "0px 0px",
    "scrollSnapCoordinate"    : "475px 475px, 450px 450px, 200px 200px",
    "initialX"                : 500,
    "initialY"                : 500,
    "key"                     : "VK_PAGE_UP",
    "expectedX"               : 500,
    "expectedY"               : 450,
    "notExpected"             : false
  },

  {
    "description"             : "Ensure that when paging down/up that the closest snap point past the destination is selected when no snap points exist between the starting position and the destination.  Additionally, a snap point closer to the destination than the one past the snap point, but not in the scrolling direction, must not be selected.  Setup - Two snap points beyond the destination and one snap point in the opposite direction of scrolling which is closest to the destination. Scrollable rect size is 500px. (Page Down)",
    "scrollSnapType"          : "mandatory",
    "scrollSnapPointsX"       : "none",
    "scrollSnapPointsY"       : "none",
    "scrollSnapDestination"   : "0px 0px",
    "scrollSnapCoordinate"    : "50px 50px, 800px 800px, 900px 900px",
    "initialX"                : 100,
    "initialY"                : 100,
    "key"                     : "VK_PAGE_DOWN",
    "expectedX"               : 100,
    "expectedY"               : 800,
    "notExpected"             : false
  },

  {
    "description"             : "Ensure that when paging down/up that the closest snap point past the destination is selected when no snap points exist between the starting position and the destination.  Additionally, a snap point closer to the destination than the one past the snap point, but not in the scrolling direction, must not be selected.  Setup - Two snap points beyond the destination and one snap point in the opposite direction of scrolling which is closest to the destination. Scrollable rect size is 500px. (Page Up)",
    "scrollSnapType"          : "mandatory",
    "scrollSnapPointsX"       : "none",
    "scrollSnapPointsY"       : "none",
    "scrollSnapDestination"   : "0px 0px",
    "scrollSnapCoordinate"    : "950px 950px, 200px 200px, 100px 100px",
    "initialX"                : 900,
    "initialY"                : 900,
    "key"                     : "VK_PAGE_UP",
    "expectedX"               : 900,
    "expectedY"               : 200,
    "notExpected"             : false
  },

  {
    "description"             : "Ensure that when scrolling by lines up,down,left,or right, that the closest snap point to the destination in the direction of travel is selected.  Setup - Two snap points in the direction of travel and one in the opposite direction.  Snap point in opposite direction is closest to the destination but must not be selected. (Down)",
    "scrollSnapType"          : "mandatory",
    "scrollSnapPointsX"       : "none",
    "scrollSnapPointsY"       : "none",
    "scrollSnapDestination"   : "0px 0px",
    "scrollSnapCoordinate"    : "50px 50px, 800px 800px, 900px 900px",
    "initialX"                : 100,
    "initialY"                : 100,
    "key"                     : "VK_PAGE_DOWN",
    "expectedX"               : 100,
    "expectedY"               : 800,
    "notExpected"             : false
  },

  {
    "description"             : "Ensure that when scrolling by lines up,down,left,or right, that the closest snap point to the destination in the direction of travel is selected.  Setup - Two snap points in the direction of travel and one in the opposite direction.  Snap point in opposite direction is closest to the destination but must not be selected. (Up)",
    "scrollSnapType"          : "mandatory",
    "scrollSnapPointsX"       : "none",
    "scrollSnapPointsY"       : "none",
    "scrollSnapDestination"   : "0px 0px",
    "scrollSnapCoordinate"    : "950px 950px, 200px 200px, 100px 100px",
    "initialX"                : 900,
    "initialY"                : 900,
    "key"                     : "VK_PAGE_UP",
    "expectedX"               : 900,
    "expectedY"               : 200,
    "notExpected"             : false
  },

  {
    "description"             : "Ensure that when scrolling by lines up,down,left,or right, that the closest snap point to the destination in the direction of travel is selected.  Setup - Two snap points in the direction of travel and one in the opposite direction.  Snap point in opposite direction is closest to the destination but must not be selected. (Left)",
    "scrollSnapType"          : "mandatory",
    "scrollSnapPointsX"       : "none",
    "scrollSnapPointsY"       : "none",
    "scrollSnapDestination"   : "0px 0px",
    "scrollSnapCoordinate"    : "950px 950px, 200px 200px, 100px 100px",
    "initialX"                : 900,
    "initialY"                : 900,
    "key"                     : "VK_LEFT",
    "expectedX"               : 200,
    "expectedY"               : 900,
    "notExpected"             : false
  }
];

var step = 0;
var sc; // Scroll Container
var sd; // Scrolled Div

var lastScrollTop;
var lastScrollLeft;
var stopFrameCount;

// The tests should work the same way when all the values for the scroll
// container are provided in percentages. To assert that, we just duplicate all
// the test cases and replace the pixel values related to the scroll container
// with percentage values, based on its clientWidth/Height sespectively.
function addPercentageTests() {
  var width = sc.clientWidth;
  var height = sc.clientHeight;
  var pxRegexp = /(\d+)px/;
  var rewriteW = (_, w) => (parseInt(w, 10) / width * 100) + "%";
  var rewriteH = (_, h) => (parseInt(h, 10) / height * 100) + "%";
  testCases = testCases.concat(testCases.map(testCase => Object.assign({}, testCase, {
    description: "With Percentages: " + testCase.description,
    scrollSnapPointsX: testCase.scrollSnapPointsX.replace(pxRegexp, rewriteW),
    scrollSnapPointsY: testCase.scrollSnapPointsY.replace(pxRegexp, rewriteH),
    scrollSnapDestination: testCase.scrollSnapDestination
      .replace(pxRegexp, rewriteW).replace(pxRegexp, rewriteH),
  })));
}

function initTest() {
  var testCase = testCases[step];
  sc.style.scrollSnapType = testCase.scrollSnapType;
  sc.style.scrollSnapPointsX = testCase.scrollSnapPointsX;
  sc.style.scrollSnapPointsY = testCase.scrollSnapPointsY;
  sc.style.scrollSnapDestination = testCase.scrollSnapDestination;
  sd.style.scrollSnapCoordinate = testCase.scrollSnapCoordinate;
  sc.scrollTo(testCase.initialX, testCase.initialY);
  sc.focus();
  synthesizeKey(testCase.key, {});

  stopFrameCount = 0;
  lastScrollTop = sc.scrollTop;
  lastScrollLeft = sc.scrollLeft;

  window.requestAnimationFrame(waitForScrollStop);
}

function waitForScrollStop() {
  if (stopFrameCount > 30) {
    // We have the same position for 30 consecutive frames -- we are stopped
    testScrolling();
  } else {
    // Still moving
    if (lastScrollTop == sc.scrollTop && lastScrollLeft == sc.scrollLeft) {
      stopFrameCount++;
    } else {
      stopFrameCount = 0;
      lastScrollTop = sc.scrollTop;
      lastScrollLeft = sc.scrollLeft;
    }
    window.requestAnimationFrame(waitForScrollStop);
  }
}

function testScrollSnapping() {
  sc = document.getElementById("sc");
  sd = document.getElementById("sd");

  addPercentageTests();

  initTest();
}

function testScrolling() {
  var testCase = testCases[step];
  if (document.getElementById('display').style.direction == "rtl") {
    if (testCase.notExpected) {
      isnot("(" + -sc.scrollLeft + "," + sc.scrollTop + ")",
            "(" + -testCase.expectedX + "," + testCase.expectedY + ")",
            "rtl: " + testCase.description);
    } else {
      is("(" + -sc.scrollLeft + "," + sc.scrollTop + ")",
         "(" + -testCase.expectedX + "," + testCase.expectedY + ")",
         "rtl: " + testCase.description);
    }
  } else {
    // ltr direction
    if (testCase.notExpected) {
      isnot("(" + sc.scrollLeft + "," + sc.scrollTop + ")",
            "(" + testCase.expectedX + "," + testCase.expectedY + ")",
            "ltr: " + testCase.description);
    } else {
      is("(" + sc.scrollLeft + "," + sc.scrollTop + ")",
         "(" + testCase.expectedX + "," + testCase.expectedY + ")",
         "ltr: " + testCase.description);
    }
  }

  step++;
  if (step < Object.keys(testCases).length) {
    initTest();
  } else {
    if (document.getElementById('display').style.direction == "rtl") {
      SimpleTest.finish();
    } else {
      // Do everything again, but with rtl
      document.getElementById('display').style.direction = "rtl";
      step = 0;
      initTest();
    }
  }
}

function doTest() {
  SpecialPowers.pushPrefEnv({
    "set": [["layout.css.scroll-snap.enabled", true],
            ["layout.css.scroll-snap.proximity-threshold", 100]]},
    testScrollSnapping);
}

SimpleTest.waitForExplicitFinish();
addLoadEvent(doTest);
</script>
</pre>
</body>

</html>