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
|
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Include test fixture.
GEN_INCLUDE(['../testing/chromevox_e2e_test_base.js']);
/**
* Test fixture for CaptionsHandler.
*/
ChromeVoxCaptionsHandlerTest = class extends ChromeVoxE2ETest {};
AX_TEST_F('ChromeVoxCaptionsHandlerTest', 'Open', function() {
let liveCaptionEnabledCount = 0;
chrome.accessibilityPrivate.enableLiveCaption = () =>
liveCaptionEnabledCount++;
// Simulate the preference being false beforehand.
SettingsManager.getBoolean = () => false;
CaptionsHandler.open();
assertEquals(1, liveCaptionEnabledCount);
// Simulate the preference being true beforehand.
SettingsManager.getBoolean = () => true;
liveCaptionEnabledCount = 0;
CaptionsHandler.open();
assertEquals(0, liveCaptionEnabledCount);
});
AX_TEST_F('ChromeVoxCaptionsHandlerTest', 'RangeObserver', async function() {
const root =
await this.runWithLoadedTree('<button>Hello</button><p>World</p>');
const button = root.find({role: 'button'});
const text = root.find({attributes: {name: 'World'}});
assertTrue(Boolean(button));
assertTrue(Boolean(text));
// Case: Range changes when focus is in captions.
CaptionsHandler.instance.onEnterCaptions_();
assertTrue(CaptionsHandler.instance.inCaptions_);
ChromeVoxRange.navigateTo(CursorRange.fromNode(text));
assertFalse(CaptionsHandler.instance.inCaptions_);
});
AX_TEST_F(
'ChromeVoxCaptionsHandlerTest', 'NoAttributeChangedEvent',
async function() {
const desktop =
await new Promise(resolve => this.runWithLoadedDesktop(resolve));
let goCount = 0;
Output.prototype.go = () => goCount++;
CaptionsHandler.instance.inCaptions_ = true;
ChromeVoxRange.instance.current_ = CursorRange.fromNode(desktop);
const onAttributeChanged = () =>
RangeAutomationHandler.instance.onAttributeChanged(
new CustomAutomationEvent('name', desktop));
onAttributeChanged();
assertEquals(goCount, 0);
onAttributeChanged();
assertEquals(goCount, 0);
});
AX_TEST_F('ChromeVoxCaptionsHandlerTest', 'MergeLines', function() {
// Use braille captions as a fake braille display.
BrailleCaptionsBackground.setActive(true);
let getBrailleText =
function() {
return BrailleDisplayManager.instance.panStrategy_
.getCurrentTextViewportContents();
}
// Simulates the text on live caption bubble.
let lines = ['line1'];
// First line shows up automatically.
CaptionsHandler.instance.mergeLines_(lines);
assertEquals('line1', getBrailleText());
// First line gets updated but braille display will not.
lines[0] += [' word2'];
CaptionsHandler.instance.mergeLines_(lines);
assertEquals('line1', getBrailleText());
// Pan right and the next part of the first line shows up.
CaptionsHandler.instance.next();
assertEquals(' word2', getBrailleText());
// First line is added and a 2nd line is created. No braille output yet.
lines[0] += [' word3'];
lines.push('line2');
CaptionsHandler.instance.mergeLines_(lines);
assertEquals(' word2', getBrailleText());
// Pan right. And new word shows up.
CaptionsHandler.instance.next();
assertEquals(' word3', getBrailleText());
// Pan right. And output is moved the 2nd line.
CaptionsHandler.instance.next();
assertEquals('line2', getBrailleText());
// Adding more lines to make buffer almost overflow. Braille output is not
// changed.
for (let i = lines.length; i <= CaptionsHandler.MAX_LINES; ++i) {
lines.push('line' + i);
}
CaptionsHandler.instance.mergeLines_(lines);
assertEquals('line2', getBrailleText());
// Push over the limit. The next line shows up on braille when buffer is
// overflown.
lines.push('line101');
lines.push('line102');
CaptionsHandler.instance.mergeLines_(lines);
assertEquals('line3', getBrailleText());
// Dropping input lines as caption lines scroll away.
lines.splice(0, 10);
CaptionsHandler.instance.mergeLines_(lines);
// Output and buffer is not affected since first line in `lines` is in buffer.
assertEquals('line3', getBrailleText());
CaptionsHandler.instance.next();
assertEquals('line4', getBrailleText());
// Reset buffer if first line in `lines` could not be found in the buffer.
lines = ['complete new'];
CaptionsHandler.instance.mergeLines_(lines);
// Output is updated in this case.
assertEquals('complete new', getBrailleText());
});
|