summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/scroll-animations/view-timelines/view-timeline-source.tentative.html
blob: f8aabc8bdd9cc202c94240bdba2f17769d89290e (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
<!DOCTYPE html>
<html id="top">
<meta charset="utf-8">
<title>View timeline source</title>
<link rel="help" href="https://drafts.csswg.org/scroll-animations-1/#viewtimeline-interface">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/web-animations/testcommon.js"></script>
<style>
#outer {
  height: 400px;
  width: 400px;
  overflow: clip;
}

#inner {
  height: 300px;
  width: 300px;
  overflow: clip;
}

#outer.scroller,
#inner.scroller {
  overflow: scroll;
}

#spacer {
  height: 1000px;
}

#target {
  background: green;
  height: 40px;
  width: 40px;
}
</style>
<body>
  <div id="outer" class="scroller">
    <div id="inner" class="scroller">
      <div id="target"></div>
      <div id="spacer"></div>
    </div>
  </div>
</body>
<script>
'use strict';

function resetScrollers() {
  inner.classList.add('scroller');
  outer.classList.add('scroller');
}

function assert_source_id(viewTimeline, expected) {
  const source = viewTimeline.source;
  assert_true(!!source, 'No source');
  assert_equals(source.id, expected);
}

promise_test(async t => {
  t.add_cleanup(resetScrollers);
  const viewTimeline = new ViewTimeline({ subject: target });
  assert_equals(viewTimeline.subject, target);
  assert_source_id(viewTimeline, 'inner');

  inner.classList.remove('scroller');
  assert_source_id(viewTimeline, 'outer');

  outer.classList.remove('scroller');
  assert_source_id(viewTimeline, 'top');
}, 'Default source for a View timeline is the nearest scroll ' +
   'ancestor to the subject');

promise_test(async t => {
  t.add_cleanup(resetScrollers);
  const viewTimeline =
      new ViewTimeline({ source: outer, subject: target });
  assert_equals(viewTimeline.subject, target);
  assert_source_id(viewTimeline, 'inner');
}, 'View timeline ignores explicitly set source');

promise_test(async t => {
  t.add_cleanup(resetScrollers);
  const viewTimeline =
      new ViewTimeline({ subject: target });
  assert_equals(viewTimeline.subject, target);
  assert_source_id(viewTimeline, 'inner');

  target.style = "display: none";
  assert_equals(viewTimeline.source, null);

}, 'View timeline source is null when display:none');

</script>
</html>