File: paragraph_utils_overflow_test.js

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (160 lines) | stat: -rw-r--r-- 6,582 bytes parent folder | download | duplicates (5)
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
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

GEN_INCLUDE(['../select_to_speak/mv2/select_to_speak_e2e_test_base.js']);

/**
 * Browser tests for select-to-speak's feature to filter out overflow text.
 */
SelectToSpeakParagraphOverflowTest = class extends SelectToSpeakE2ETest {
  generateHorizentalOverflowText(text) {
    return (
        '<div style="width: 50px; overflow: hidden">' +
        '<p style="width: 200px">$text</p>'.replace('$text', text) + '</div>');
  }

  generateVerticalOverflowText(visibleText, overflowText) {
    return (
        '<div style="height: 30px; overflow: hidden">' +
        '<p>$text</p>'.replace('$text', visibleText) +
        '<p>$text</p>'.replace('$text', overflowText) + '</div>');
  }

  generateEntirelyOverflowText(text) {
    return (
        '<div style="width: 50px; overflow:hidden">' +
        '<p style="width: 1000px">' +
        '<span>long text to keep the second node overflow entirely</span>' +
        '$text</p>'.replace('$text', text) + '</div>');
  }

  generateVisibleText(text) {
    return (
        '<div style="width: 50px">' +
        '<p style="width: 200px">$text</p>'.replace('$text', text) + '</div>');
  }
};

AX_TEST_F(
    'SelectToSpeakParagraphOverflowTest',
    'ReplaceseHorizentalOverflowTextWithSpace', async function() {
      const inputText = 'This text overflows partially';
      const root = await this.runWithLoadedTree(
          this.generateHorizentalOverflowText(inputText));
      const overflowText = root.find({
        role: chrome.automation.RoleType.INLINE_TEXT_BOX,
        attributes: {name: inputText},
      });
      var nodeGroup = ParagraphUtils.buildNodeGroup(
          [overflowText], 0 /* index */, {clipOverflowWords: true});

      // The output text should have the same length of the input text
      // plus a space character at the end.
      assertEquals(nodeGroup.text.length, inputText.length + 1);
      // The output text should have less non-empty characters compared
      // to the input text, as any overflow word will be replaced as
      // space characters.
      assertTrue(
          nodeGroup.text.replace(/ /g, '').length <
          inputText.replace(/ /g, '').length);
    });

AX_TEST_F(
    'SelectToSpeakParagraphOverflowTest',
    'ReplaceseVerticalOverflowTextWithSpace', async function() {
      const visibleText = 'This text is visible';
      const overflowText = 'This text overflows';
      const root = await this.runWithLoadedTree(
          this.generateVerticalOverflowText(visibleText, overflowText));
      // Find the visible text.
      const visibleTextNode = root.find({
        role: chrome.automation.RoleType.INLINE_TEXT_BOX,
        attributes: {name: visibleText},
      });
      var nodeGroup = ParagraphUtils.buildNodeGroup(
          [visibleTextNode], 0 /* index */, {clipOverflowWords: true});
      // The output text should have the same length of the visible text
      // plus a space character at the end.
      assertEquals(nodeGroup.text.length, visibleText.length + 1);
      // The output text should be the same of the input text.
      assertEquals(
          nodeGroup.text.replace(/ /g, ''), visibleText.replace(/ /g, ''));

      // Find the overflow text.
      const overflowTextNode = root.find({
        role: chrome.automation.RoleType.INLINE_TEXT_BOX,
        attributes: {name: overflowText},
      });
      var nodeGroup = ParagraphUtils.buildNodeGroup(
          [overflowTextNode], 0 /* index */, {clipOverflowWords: true});

      // The output text should have the same length of the overflow text
      // plus a space character at the end.
      assertEquals(nodeGroup.text.length, overflowText.length + 1);
      // The output text should only have space characters.
      assertEquals(nodeGroup.text.replace(/ /g, '').length, 0);
    });

AX_TEST_F(
    'SelectToSpeakParagraphOverflowTest',
    'ReplacesEntirelyOverflowTextWithSpace', async function() {
      const inputText = 'This text overflows entirely';
      const root = await this.runWithLoadedTree(
          this.generateEntirelyOverflowText(inputText));
      const overflowText = root.find({
        role: chrome.automation.RoleType.INLINE_TEXT_BOX,
        attributes: {name: inputText},
      });
      var nodeGroup = ParagraphUtils.buildNodeGroup(
          [overflowText], 0 /* index */, {clipOverflowWords: true});

      // The output text should have the same length of the input text
      // plus a space character at the end.
      assertEquals(nodeGroup.text.length, inputText.length + 1);
      // The output text should have zero non-empty character.
      assertEquals(nodeGroup.text.replace(/ /g, '').length, 0);
    });

AX_TEST_F(
    'SelectToSpeakParagraphOverflowTest', 'OutputsVisibleText',
    async function() {
      const inputText = 'This text is visible';
      const root =
          await this.runWithLoadedTree(this.generateVisibleText(inputText));
      const visibleText = root.find({
        role: chrome.automation.RoleType.INLINE_TEXT_BOX,
        attributes: {name: inputText},
      });
      var nodeGroup = ParagraphUtils.buildNodeGroup(
          [visibleText], 0 /* index */, {clipOverflowWords: true});

      // The output text should have the same length of the input text plus a
      // space character at the end.
      assertEquals(nodeGroup.text.length, inputText.length + 1);
      // The output text should have same non-empty words as the input text.
      assertEquals(
          nodeGroup.text.replace(/ /g, ''), inputText.replace(/ /g, ''));
    });

AX_TEST_F(
    'SelectToSpeakParagraphOverflowTest',
    'DoesNotClipOverflowWordsWhenDisabled', async function() {
      const inputText = 'This text overflows entirely';
      const root = await this.runWithLoadedTree(
          this.generateEntirelyOverflowText(inputText));
      const overflowText = root.find({
        role: chrome.automation.RoleType.INLINE_TEXT_BOX,
        attributes: {name: inputText},
      });
      var nodeGroup = ParagraphUtils.buildNodeGroup(
          [overflowText], 0 /* index */, {clipOverflowWords: false});

      // The output text should have the same length of the input text
      // plus a space character at the end.
      assertEquals(nodeGroup.text.length, inputText.length + 1);
      // The output text should have same non-empty words as the input
      // text.
      assertEquals(
          nodeGroup.text.replace(/ /g, ''), inputText.replace(/ /g, ''));
    });