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
|
// Copyright 2023 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 SettingsManager.
*/
ChromeVoxMV2SettingsManagerTest = class extends ChromeVoxE2ETest {
async getStoragePrefs(prefNames) {
const prefs = {};
for (const prefName of prefNames) {
prefs[prefName] = LocalStorage.get(prefName);
}
return prefs;
}
async getSettingsPrefs(prefNames) {
const prefs = {};
for (const prefName of prefNames) {
const {value} = await new Promise(
resolve => chrome.settingsPrivate.getPref(
SettingsManager.getPrefName_(prefName), resolve));
prefs[prefName] = value;
}
return prefs;
}
async setStoragePrefsAndMigrate(prefs) {
Object.entries(prefs).forEach(
([key, value]) => LocalStorage.set(key, value));
// Reinitialize and Migrate Prefs.
Settings.instance = undefined;
SettingsManager.instance = undefined;
await SettingsManager.init();
}
async ensureStoragePrefsRemoved(prefs) {
const storagePrefs = await this.getStoragePrefs(Object.keys(prefs));
assertEqualsJSON(storagePrefs, {}, 'Storage Prefs still present.');
}
async ensureSettingsPrefsIncludes(expectedPrefs) {
const actualPrefs = await this.getSettingsPrefs(Object.keys(expectedPrefs));
assertEqualsJSON(
expectedPrefs, actualPrefs,
'Settings Prefs don\'t match expected results.');
}
};
// Leaves default storage prefs, runs the migration in prefs_manager, verifies
// that prefs are set to their default values, and verifies that there are still
// no storage prefs. This mimics the state of a fresh user profile.
AX_TEST_F(
'ChromeVoxMV2SettingsManagerTest',
'DefaultSettingsPrefsSetAfterNoStoragePrefsSet', async function() {
const defaultPrefs = {
announceDownloadNotifications: true,
announceRichTextAttributes: true,
audioStrategy: 'audioNormal',
brailleSideBySide: true,
brailleTable: '',
brailleTable6: 'en-ueb-g2',
brailleTable8: 'en-nabcc',
brailleTableType: 'brailleTable8',
brailleWordWrap: true,
capitalStrategy: 'increasePitch',
capitalStrategyBackup: '',
menuBrailleCommands: false,
enableBrailleLogging: false,
enableEarconLogging: false,
enableEventStreamLogging: false,
enableSpeechLogging: false,
languageSwitching: false,
numberReadingStyle: 'asWords',
punctuationEcho: 1,
smartStickyMode: true,
speakTextUnderMouse: false,
usePitchChanges: true,
useVerboseMode: true,
virtualBrailleColumns: 40,
virtualBrailleRows: 1,
voiceName: 'chromeos_system_voice',
};
// Set no storage prefs.
await this.setStoragePrefsAndMigrate({});
// Check all storage prefs migrated to settings prefs.
await this.ensureSettingsPrefsIncludes(defaultPrefs);
// Ensure all storage prefs deleted.
await this.ensureStoragePrefsRemoved(defaultPrefs);
});
// Sets some user (non-developer) storage prefs, runs the migration in
// SettingsManager, verifies prefs migrated to settings prefs, and verifies that
// storage prefs are removed.
AX_TEST_F(
'ChromeVoxMV2SettingsManagerTest',
'PrefsMigratedToSettingsAndDefaultsSetAfterSomeStoragePrefsSet',
async function() {
const changedPrefs = {
audioStrategy: 'audioSuspend',
brailleSideBySide: false,
brailleWordWrap: false,
capitalStrategy: 'announceCapitals',
capitalStrategyBackup: 'announceCapitals',
enableEventStreamLogging: true,
enableSpeechLogging: true,
languageSwitching: true,
numberReadingStyle: 'asDigits',
punctuationEcho: 2,
smartStickyMode: false,
speakTextUnderMouse: true,
usePitchChanges: false,
useVerboseMode: false,
virtualBrailleColumns: 29,
virtualBrailleRows: 3,
voiceName: 'eSpeak Danish',
};
const defaultPrefs = {
announceDownloadNotifications: true,
announceRichTextAttributes: true,
brailleTable: '',
brailleTable6: 'en-ueb-g2',
brailleTable8: 'en-nabcc',
brailleTableType: 'brailleTable8',
enableBrailleLogging: false,
enableEarconLogging: false,
menuBrailleCommands: false,
};
const allPrefs = {...changedPrefs, ...defaultPrefs};
// Set changed storage prefs.
await this.setStoragePrefsAndMigrate(changedPrefs);
// Check all storage prefs migrated to settings prefs.
await this.ensureSettingsPrefsIncludes(allPrefs);
// Ensure all storage prefs deleted.
await this.ensureStoragePrefsRemoved(allPrefs);
});
// Sets all user (non-developer) storage prefs, runs the migration in
// SettingsManager, verifies prefs migrated to settings prefs, and verifies that
// storage prefs are removed.
AX_TEST_F(
'ChromeVoxMV2SettingsManagerTest',
'AllPrefsMigratedToSettingsAfterStoragePrefsSet', async function() {
const prefs = {
announceDownloadNotifications: false,
announceRichTextAttributes: false,
audioStrategy: 'audioSuspend',
brailleSideBySide: false,
brailleTable: 'hy',
brailleTable6: 'hy',
brailleTable8: 'fi-fi-8dot',
brailleTableType: 'brailleTable6',
brailleWordWrap: false,
capitalStrategy: 'announceCapitals',
capitalStrategyBackup: 'announceCapitals',
enableBrailleLogging: true,
enableEarconLogging: false,
enableEventStreamLogging: false,
enableSpeechLogging: true,
languageSwitching: true,
menuBrailleCommands: false,
numberReadingStyle: 'asDigits',
punctuationEcho: 2,
smartStickyMode: false,
speakTextUnderMouse: true,
usePitchChanges: false,
useVerboseMode: false,
virtualBrailleColumns: 29,
virtualBrailleRows: 3,
voiceName: 'eSpeak Danish',
};
// Set all storage prefs.
await this.setStoragePrefsAndMigrate(prefs);
// Check all storage prefs migrated to settings prefs.
await this.ensureSettingsPrefsIncludes(prefs);
// Ensure all storage prefs deleted.
await this.ensureStoragePrefsRemoved(prefs);
});
// Sets all developer storage prefs, runs the migration in
// SettingsManager, verifies prefs migrated to settings prefs, and verifies that
// storage prefs are removed.
AX_TEST_F(
'ChromeVoxMV2SettingsManagerTest',
'AllDeveloperPrefsMigratedToSettingsAfterStoragePrefsSet',
async function() {
const loggingPrefs = {
enableBrailleLogging: true,
enableEarconLogging: false,
enableEventStreamLogging: true,
enableSpeechLogging: false,
};
const eventStreamFilters = {
activedescendantchanged: true,
alert: true,
// TODO(crbug.com/1464633) Fully remove ariaAttributeChangedDeprecated
// starting in 122, because although it was removed in 118, it is still
// present in earlier versions of LaCros.
ariaAttributeChangedDeprecated: true,
autocorrectionOccured: false,
blur: true,
checkedStateChanged: false,
childrenChanged: false,
clicked: true,
documentSelectionChanged: true,
documentTitleChanged: false,
expandedChanged: false,
focus: true,
focusContext: true,
hide: false,
hitTestResult: true,
hover: true,
imageFrameUpdated: false,
invalidStatusChanged: true,
layoutComplete: false,
liveRegionChanged: false,
liveRegionCreated: false,
loadComplete: false,
locationChanged: true,
mediaStartedPlaying: true,
mediaStoppedPlaying: true,
menuEnd: true,
menuItemSelected: false,
menuPopupEnd: false,
menuPopupStart: true,
menuStart: true,
mouseCanceled: true,
mouseDragged: true,
mouseMoved: true,
mousePressed: false,
mouseReleased: false,
rowCollapsed: true,
rowCountChanged: true,
rowExpanded: false,
scrollPositionChanged: true,
scrolledToAnchor: true,
selectedChildrenChanged: true,
selection: true,
selectionAdd: false,
selectionRemove: false,
show: true,
stateChanged: false,
textChanged: true,
textSelectionChanged: true,
treeChanged: true,
valueInTextFieldChanged: true,
};
const storagePrefs = {...loggingPrefs, ...eventStreamFilters};
const expectedSettingsPrefs = {...loggingPrefs, eventStreamFilters};
// Set storage prefs.
await this.setStoragePrefsAndMigrate(storagePrefs);
// Check storage prefs migrated to settings prefs.
await this.ensureSettingsPrefsIncludes(expectedSettingsPrefs);
// Ensure all storage prefs deleted.
await this.ensureStoragePrefsRemoved(storagePrefs);
});
|