forked from flutter/flutter
/
semantics_helper_test.dart
157 lines (120 loc) · 5.32 KB
/
semantics_helper_test.dart
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
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:html' as html;
import 'package:ui/src/engine.dart';
import 'package:test/test.dart';
void main() {
group('$DesktopSemanticsEnabler', () {
DesktopSemanticsEnabler desktopSemanticsEnabler;
html.Element _placeholder;
setUp(() {
desktopSemanticsEnabler = DesktopSemanticsEnabler();
});
tearDown(() {
if (_placeholder != null) {
_placeholder.remove();
}
if (desktopSemanticsEnabler?.semanticsActivationTimer != null) {
desktopSemanticsEnabler.semanticsActivationTimer.cancel();
desktopSemanticsEnabler.semanticsActivationTimer = null;
}
});
test('prepare accesibility placeholder', () async {
_placeholder = desktopSemanticsEnabler.prepareAccesibilityPlaceholder();
expect(_placeholder.getAttribute('role'), 'button');
expect(_placeholder.getAttribute('aria-live'), 'true');
expect(_placeholder.getAttribute('tabindex'), '0');
html.document.body.append(_placeholder);
expect(html.document.getElementsByTagName('flt-semantics-placeholder'),
isNotEmpty);
expect(_placeholder.getBoundingClientRect().height, 1);
expect(_placeholder.getBoundingClientRect().width, 1);
expect(_placeholder.getBoundingClientRect().top, -1);
expect(_placeholder.getBoundingClientRect().left, -1);
},
// TODO(nurhan): https://github.com/flutter/flutter/issues/50590
skip: browserEngine == BrowserEngine.webkit);
test('Not relevant events should be forwarded to the framework', () async {
// Prework. Attach the placeholder to dom.
_placeholder = desktopSemanticsEnabler.prepareAccesibilityPlaceholder();
html.document.body.append(_placeholder);
html.Event event = html.MouseEvent('mousemove');
bool shouldForwardToFramework =
desktopSemanticsEnabler.tryEnableSemantics(event);
expect(shouldForwardToFramework, true);
event = html.PointerEvent('pointermove');
shouldForwardToFramework =
desktopSemanticsEnabler.tryEnableSemantics(event);
expect(shouldForwardToFramework, true);
},
// TODO(nurhan): https://github.com/flutter/flutter/issues/50754
skip: browserEngine == BrowserEngine.edge);
test(
'Relevants events targeting placeholder should not be forwarded to the framework',
() async {
// Prework. Attach the placeholder to dom.
_placeholder = desktopSemanticsEnabler.prepareAccesibilityPlaceholder();
html.document.body.append(_placeholder);
html.Event event = html.MouseEvent('mousedown');
_placeholder.dispatchEvent(event);
bool shouldForwardToFramework =
desktopSemanticsEnabler.tryEnableSemantics(event);
expect(shouldForwardToFramework, false);
});
test(
'After max number of relevant events, events should be forwarded to the framework',
() async {
// Prework. Attach the placeholder to dom.
_placeholder = desktopSemanticsEnabler.prepareAccesibilityPlaceholder();
html.document.body.append(_placeholder);
html.Event event = html.MouseEvent('mousedown');
_placeholder.dispatchEvent(event);
bool shouldForwardToFramework =
desktopSemanticsEnabler.tryEnableSemantics(event);
expect(shouldForwardToFramework, false);
// Send max number of events;
for (int i = 1; i <= kMaxSemanticsActivationAttempts; i++) {
event = html.MouseEvent('mousedown');
_placeholder.dispatchEvent(event);
shouldForwardToFramework =
desktopSemanticsEnabler.tryEnableSemantics(event);
}
expect(shouldForwardToFramework, true);
});
});
group('$MobileSemanticsEnabler', () {
MobileSemanticsEnabler mobileSemanticsEnabler;
html.Element _placeholder;
setUp(() {
mobileSemanticsEnabler = MobileSemanticsEnabler();
});
tearDown(() {
if (_placeholder != null) {
_placeholder.remove();
}
});
test('prepare accesibility placeholder', () async {
_placeholder = mobileSemanticsEnabler.prepareAccesibilityPlaceholder();
expect(_placeholder.getAttribute('role'), 'button');
html.document.body.append(_placeholder);
// Placeholder should cover all the screen on a mobile device.
final num bodyHeight = html.window.innerHeight;
final num bodyWidht = html.window.innerWidth;
expect(_placeholder.getBoundingClientRect().height, bodyHeight);
expect(_placeholder.getBoundingClientRect().width, bodyWidht);
},
// TODO(nurhan): https://github.com/flutter/flutter/issues/50590
skip: browserEngine == BrowserEngine.webkit);
test('Not relevant events should be forwarded to the framework', () async {
final html.Event event = html.TouchEvent('touchcancel');
bool shouldForwardToFramework =
mobileSemanticsEnabler.tryEnableSemantics(event);
expect(shouldForwardToFramework, true);
},
// TODO(nurhan): https://github.com/flutter/flutter/issues/50590
// TODO(nurhan): https://github.com/flutter/flutter/issues/46638
// TODO(nurhan): https://github.com/flutter/flutter/issues/50754
skip: browserEngine != BrowserEngine.blink);
});
}