Commit 39daef1d authored by David Tseng's avatar David Tseng Committed by Commit Bot

Format all test files under c/b/r/c/accessibility

Change-Id: Iff73bb8018053690ec88a6152a5c0740ef462e27
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1937131
Commit-Queue: David Tseng <dtseng@chromium.org>
Reviewed-by: default avatarAnastasia Helfinstein <anastasi@google.com>
Reviewed-by: default avatarHector Carmona <hcarmona@chromium.org>
Cr-Commit-Position: refs/heads/master@{#722718}
parent 65a674b7
...@@ -102,7 +102,7 @@ source_set("browser_tests") { ...@@ -102,7 +102,7 @@ source_set("browser_tests") {
js2gtest("autoclick_extjs_tests") { js2gtest("autoclick_extjs_tests") {
test_type = "extension" test_type = "extension"
sources = [ sources = [
"autoclick_test.extjs", "autoclick_test.js",
] ]
gen_include_files = [ gen_include_files = [
"../chromevox/testing/callback_helper.js", "../chromevox/testing/callback_helper.js",
......
...@@ -120,49 +120,52 @@ AutoclickE2ETest.prototype = { ...@@ -120,49 +120,52 @@ AutoclickE2ETest.prototype = {
}; };
TEST_F('AutoclickE2ETest', 'HighlightsRootWebAreaIfNotScrollable', function() { TEST_F('AutoclickE2ETest', 'HighlightsRootWebAreaIfNotScrollable', function() {
this.runWithLoadedTree('data:text/html;charset=utf-8,<p>Cats rock!</p>', this.runWithLoadedTree(
function(desktop) { 'data:text/html;charset=utf-8,<p>Cats rock!</p>', function(desktop) {
let node = desktop.find({role: 'staticText', let node = desktop.find(
attributes: {name: 'Cats rock!'}}); {role: 'staticText', attributes: {name: 'Cats rock!'}});
this.mockAccessibilityPrivate.callFindScrollableBoundsForPoint( this.mockAccessibilityPrivate.callFindScrollableBoundsForPoint(
// Offset slightly into the node to ensure the hittest happens within // Offset slightly into the node to ensure the hittest happens
// the node. // within the node.
node.location.left + 1, node.location.top + 1, node.location.left + 1, node.location.top + 1,
this.newCallback(() => { this.newCallback(() => {
let expected = node.root.location; let expected = node.root.location;
this.assertSameRect( this.assertSameRect(
this.mockAccessibilityPrivate.getScrollableBounds(), this.mockAccessibilityPrivate.getScrollableBounds(),
expected); expected);
this.assertSameRect(this.mockAccessibilityPrivate.getFocusRings()[0], this.assertSameRect(
expected); this.mockAccessibilityPrivate.getFocusRings()[0], expected);
})); }));
}); });
}); });
TEST_F('AutoclickE2ETest', 'HighlightsScrollableDiv', function() { TEST_F('AutoclickE2ETest', 'HighlightsScrollableDiv', function() {
this.runWithLoadedTree('data:text/html;charset=utf-8,' + this.runWithLoadedTree(
'<div style="width:100px;height:100px;overflow:scroll">' + 'data:text/html;charset=utf-8,' +
'<div style="margin:50px">cats rock! this text wraps and overflows!' + '<div style="width:100px;height:100px;overflow:scroll">' +
'</div></div>', '<div style="margin:50px">cats rock! this text wraps and overflows!' +
'</div></div>',
function(desktop) { function(desktop) {
let node = desktop.find({role: 'staticText', let node = desktop.find({
attributes: {name: 'cats rock! this text wraps and overflows!'}}); role: 'staticText',
this.mockAccessibilityPrivate.callFindScrollableBoundsForPoint( attributes: {name: 'cats rock! this text wraps and overflows!'}
// Offset slightly into the node to ensure the hittest happens within });
// the node. this.mockAccessibilityPrivate.callFindScrollableBoundsForPoint(
node.location.left + 1, node.location.top + 1, // Offset slightly into the node to ensure the hittest happens
this.newCallback(() => { // within the node.
// The outer div, which is the parent of the parent of the node.location.left + 1, node.location.top + 1,
// text, is scrollable. this.newCallback(() => {
assertTrue(node.parent.parent.scrollable); // The outer div, which is the parent of the parent of the
let expected = node.parent.parent.location; // text, is scrollable.
this.assertSameRect( assertTrue(node.parent.parent.scrollable);
this.mockAccessibilityPrivate.getScrollableBounds(), let expected = node.parent.parent.location;
expected); this.assertSameRect(
this.assertSameRect(this.mockAccessibilityPrivate.getFocusRings()[0], this.mockAccessibilityPrivate.getScrollableBounds(),
expected); expected);
})); this.assertSameRect(
}); this.mockAccessibilityPrivate.getFocusRings()[0], expected);
}));
});
}); });
// TODO(crbug.com/978163): Add tests for when the scrollable area is scrolled // TODO(crbug.com/978163): Add tests for when the scrollable area is scrolled
......
...@@ -80,9 +80,7 @@ BrailleImeUnitTest.prototype = { ...@@ -80,9 +80,7 @@ BrailleImeUnitTest.prototype = {
__proto__: testing.Test.prototype, __proto__: testing.Test.prototype,
/** @Override */ /** @Override */
extraLibraries: [ extraLibraries: ['braille_ime.js'],
'braille_ime.js'
],
/** @Override */ /** @Override */
setUp: function() { setUp: function() {
...@@ -102,12 +100,12 @@ BrailleImeUnitTest.prototype = { ...@@ -102,12 +100,12 @@ BrailleImeUnitTest.prototype = {
}, },
createIme: function() { createIme: function() {
var IME_EVENTS = [ 'onActivate', 'onDeactivated', 'onFocus', 'onBlur', var IME_EVENTS = [
'onInputContextUpdate', 'onKeyEvent', 'onReset', 'onActivate', 'onDeactivated', 'onFocus', 'onBlur',
'onMenuItemActivated' ]; 'onInputContextUpdate', 'onKeyEvent', 'onReset', 'onMenuItemActivated'
];
for (var i = 0, name; name = IME_EVENTS[i]; ++i) { for (var i = 0, name; name = IME_EVENTS[i]; ++i) {
this[name] = chrome.input.ime[name] = new MockEvent(); this[name] = chrome.input.ime[name] = new MockEvent();
} }
chrome.input.ime.setMenuItems = function(parameters) { chrome.input.ime.setMenuItems = function(parameters) {
this.menuItems = parameters.items; this.menuItems = parameters.items;
...@@ -124,15 +122,17 @@ BrailleImeUnitTest.prototype = { ...@@ -124,15 +122,17 @@ BrailleImeUnitTest.prototype = {
activateIme: function() { activateIme: function() {
this.onActivate.dispatch(ENGINE_ID); this.onActivate.dispatch(ENGINE_ID);
assertThat(this.port.messages, assertThat(
eqJSON([{type: 'activeState', active: true}])); this.port.messages, eqJSON([{type: 'activeState', active: true}]));
this.port.messages.length = 0; this.port.messages.length = 0;
}, },
sendKeyEvent_: function(type, code, extra) { sendKeyEvent_: function(type, code, extra) {
var event = {type: type, var event = {
code: code, type: type,
requestId: (++this.lastSentKeyRequestId_) + ''}; code: code,
requestId: (++this.lastSentKeyRequestId_) + ''
};
for (var key in extra) { for (var key in extra) {
event[key] = extra[key]; event[key] = extra[key];
} }
...@@ -180,7 +180,7 @@ TEST_F('BrailleImeUnitTest', 'KeysWhenStandardKeysEnabled', function() { ...@@ -180,7 +180,7 @@ TEST_F('BrailleImeUnitTest', 'KeysWhenStandardKeysEnabled', function() {
expectFalse(this.sendKeyDown('KeyX')); expectFalse(this.sendKeyDown('KeyX'));
expectFalse(this.sendKeyUp('KeyX')); expectFalse(this.sendKeyUp('KeyX'));
expectTrue(this.sendKeyDown('KeyS')); // Dot 3 expectTrue(this.sendKeyDown('KeyS')); // Dot 3
expectFalse(this.sendKeyDown('KeyG')); // To the right of dot 1. expectFalse(this.sendKeyDown('KeyG')); // To the right of dot 1.
expectTrue(this.sendKeyUp('KeyS')); expectTrue(this.sendKeyUp('KeyS'));
expectFalse(this.sendKeyUp('KeyG')); expectFalse(this.sendKeyUp('KeyG'));
...@@ -190,7 +190,7 @@ TEST_F('BrailleImeUnitTest', 'KeysWhenStandardKeysEnabled', function() { ...@@ -190,7 +190,7 @@ TEST_F('BrailleImeUnitTest', 'KeysWhenStandardKeysEnabled', function() {
expectFalse(this.sendKeyDown('ControlLeft', ctrlFlag)); expectFalse(this.sendKeyDown('ControlLeft', ctrlFlag));
expectFalse(this.sendKeyDown('KeyL', ctrlFlag)); expectFalse(this.sendKeyDown('KeyL', ctrlFlag));
expectFalse(this.sendKeyUp('KeyL', ctrlFlag)); expectFalse(this.sendKeyUp('KeyL', ctrlFlag));
expectFalse(this.sendKeyUp('ControlLeft', ctrlFlag)) expectFalse(this.sendKeyUp('ControlLeft', ctrlFlag));
// Space key by itself should send a blank cell. // Space key by itself should send a blank cell.
expectTrue(this.sendKeyDown('Space')); expectTrue(this.sendKeyDown('Space'));
...@@ -207,10 +207,10 @@ TEST_F('BrailleImeUnitTest', 'KeysWhenStandardKeysEnabled', function() { ...@@ -207,10 +207,10 @@ TEST_F('BrailleImeUnitTest', 'KeysWhenStandardKeysEnabled', function() {
expectTrue(this.sendKeyUp('Space')); expectTrue(this.sendKeyUp('Space'));
expectTrue(this.sendKeyUp('KeyF')); expectTrue(this.sendKeyUp('KeyF'));
assertThat(this.port.messages, assertThat(this.port.messages, eqJSON([
eqJSON([{type: 'brailleDots', dots: 0x03}, {type: 'brailleDots', dots: 0x03},
{type: 'brailleDots', dots: 0x09}, {type: 'brailleDots', dots: 0x09}, {type: 'brailleDots', dots: 0}
{type: 'brailleDots', dots: 0}])); ]));
}); });
TEST_F('BrailleImeUnitTest', 'TestBackspaceKey', function() { TEST_F('BrailleImeUnitTest', 'TestBackspaceKey', function() {
...@@ -221,13 +221,14 @@ TEST_F('BrailleImeUnitTest', 'TestBackspaceKey', function() { ...@@ -221,13 +221,14 @@ TEST_F('BrailleImeUnitTest', 'TestBackspaceKey', function() {
assertTrue(this.menuItems[0].checked); assertTrue(this.menuItems[0].checked);
expectEquals(undefined, this.sendKeyDown('Backspace')); expectEquals(undefined, this.sendKeyDown('Backspace'));
assertThat(this.port.messages, assertThat(this.port.messages, eqJSON([
eqJSON([{type: 'backspace', {type: 'backspace', requestId: this.lastSentKeyRequestId_ + ''}
requestId: this.lastSentKeyRequestId_ + ''}])); ]));
this.port.onMessage.dispatch( this.port.onMessage.dispatch({
{type: 'keyEventHandled', type: 'keyEventHandled',
requestId: this.lastSentKeyRequestId_ + '', requestId: this.lastSentKeyRequestId_ + '',
result: true}); result: true
});
expectEquals(this.lastSentKeyRequestId_, this.lastHandledKeyRequestId_); expectEquals(this.lastSentKeyRequestId_, this.lastHandledKeyRequestId_);
expectTrue(this.lastHandledKeyResult_); expectTrue(this.lastHandledKeyResult_);
}); });
...@@ -264,9 +265,12 @@ TEST_F('BrailleImeUnitTest', 'ReplaceText', function() { ...@@ -264,9 +265,12 @@ TEST_F('BrailleImeUnitTest', 'ReplaceText', function() {
callback(); callback();
}; };
var sendReplaceText = function(deleteBefore, newText) { var sendReplaceText = function(deleteBefore, newText) {
this.port.onMessage.dispatch( this.port.onMessage.dispatch({
{type: 'replaceText', contextID: CONTEXT_ID, type: 'replaceText',
deleteBefore: deleteBefore, newText: newText}); contextID: CONTEXT_ID,
deleteBefore: deleteBefore,
newText: newText
});
}.bind(this); }.bind(this);
this.activateIme(); this.activateIme();
sendReplaceText(0, 'hello!'); sendReplaceText(0, 'hello!');
......
...@@ -26,6 +26,9 @@ def CheckBrailleIme(): ...@@ -26,6 +26,9 @@ def CheckBrailleIme():
os.path.join(_SCRIPT_DIR, 'braille_ime.js'), os.path.join(_SCRIPT_DIR, 'braille_ime.js'),
os.path.join(_SCRIPT_DIR, 'main.js')] os.path.join(_SCRIPT_DIR, 'main.js')]
externs = [ externs = [
os.path.join(
_CHROME_SOURCE_DIR,
'third_party/closure_compiler/externs/chrome.js'),
os.path.join( os.path.join(
_CHROME_SOURCE_DIR, _CHROME_SOURCE_DIR,
'third_party/closure_compiler/externs/chrome_extensions.js'), 'third_party/closure_compiler/externs/chrome_extensions.js'),
......
...@@ -129,9 +129,9 @@ source_set("browser_tests") { ...@@ -129,9 +129,9 @@ source_set("browser_tests") {
js2gtest("select_to_speak_extjs_tests") { js2gtest("select_to_speak_extjs_tests") {
test_type = "extension" test_type = "extension"
sources = [ sources = [
"select_to_speak_keystroke_selection_test.extjs", "select_to_speak_keystroke_selection_test.js",
"select_to_speak_mouse_selection_test.extjs", "select_to_speak_mouse_selection_test.js",
"select_to_speak_prefs_test.extjs", "select_to_speak_prefs_test.js",
] ]
gen_include_files = [ gen_include_files = [
"../chromevox/testing/callback_helper.js", "../chromevox/testing/callback_helper.js",
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* @constructor * @constructor
* @extends {testing.Test} * @extends {testing.Test}
*/ */
function SelectToSpeakRectUtilsUnitTest () { function SelectToSpeakRectUtilsUnitTest() {
testing.Test.call(this); testing.Test.call(this);
} }
......
...@@ -5,7 +5,8 @@ ...@@ -5,7 +5,8 @@
GEN_INCLUDE(['select_to_speak_e2e_test_base.js']); GEN_INCLUDE(['select_to_speak_e2e_test_base.js']);
GEN_INCLUDE(['../../../../../../ui/webui/resources/js/cr.js']); GEN_INCLUDE(['../../../../../../ui/webui/resources/js/cr.js']);
GEN_INCLUDE(['../../../../../test/data/webui/fake_chrome_event.js']); GEN_INCLUDE(['../../../../../test/data/webui/fake_chrome_event.js']);
GEN_INCLUDE(['../../../../../test/data/webui/settings/fake_settings_private.js']); GEN_INCLUDE(
['../../../../../test/data/webui/settings/fake_settings_private.js']);
GEN_INCLUDE(['mock_storage.js']); GEN_INCLUDE(['mock_storage.js']);
/** /**
...@@ -34,7 +35,7 @@ function SelectToSpeakPrefsTest() { ...@@ -34,7 +35,7 @@ function SelectToSpeakPrefsTest() {
}; };
this.resetStorage(); this.resetStorage();
}; }
SelectToSpeakPrefsTest.prototype = { SelectToSpeakPrefsTest.prototype = {
__proto__: SelectToSpeakE2ETest.prototype, __proto__: SelectToSpeakE2ETest.prototype,
...@@ -48,10 +49,10 @@ SelectToSpeakPrefsTest.prototype = { ...@@ -48,10 +49,10 @@ SelectToSpeakPrefsTest.prototype = {
// properly. // properly.
setGlobalRateAndPitch: function(rate, pitch) { setGlobalRateAndPitch: function(rate, pitch) {
let unused = () => {}; let unused = () => {};
this.mockSettingsPrivate_.setPref('settings.tts.speech_rate', rate, '', this.mockSettingsPrivate_.setPref(
unused); 'settings.tts.speech_rate', rate, '', unused);
this.mockSettingsPrivate_.setPref('settings.tts.speech_pitch', pitch, '', this.mockSettingsPrivate_.setPref(
unused); 'settings.tts.speech_pitch', pitch, '', unused);
}, },
setStsRateAndPitch: function(rate, pitch) { setStsRateAndPitch: function(rate, pitch) {
...@@ -63,12 +64,12 @@ SelectToSpeakPrefsTest.prototype = { ...@@ -63,12 +64,12 @@ SelectToSpeakPrefsTest.prototype = {
let onPrefsRemovedFromStorage = this.newCallback(() => { let onPrefsRemovedFromStorage = this.newCallback(() => {
// Once prefs are removed from storage, make sure the global prefs are // Once prefs are removed from storage, make sure the global prefs are
// updated to the appropriate values. // updated to the appropriate values.
this.mockSettingsPrivate_.getPref('settings.tts.speech_rate', this.mockSettingsPrivate_.getPref(
this.newCallback((pref) => { 'settings.tts.speech_rate', this.newCallback((pref) => {
assertEquals(rate, pref.value); assertEquals(rate, pref.value);
})); }));
this.mockSettingsPrivate_.getPref('settings.tts.speech_pitch', this.mockSettingsPrivate_.getPref(
this.newCallback((pref) => { 'settings.tts.speech_pitch', this.newCallback((pref) => {
assertEquals(pitch, pref.value); assertEquals(pitch, pref.value);
})); }));
}); });
...@@ -82,27 +83,27 @@ SelectToSpeakPrefsTest.prototype = { ...@@ -82,27 +83,27 @@ SelectToSpeakPrefsTest.prototype = {
}; };
// TODO(katie): Test no alert -- this is hard because it happens last. // TODO(katie): Test no alert -- this is hard because it happens last.
TEST_F('SelectToSpeakPrefsTest', 'RemovesPrefsWithNoAlertIfAllDefault', TEST_F(
'SelectToSpeakPrefsTest', 'RemovesPrefsWithNoAlertIfAllDefault',
function() { function() {
this.setGlobalRateAndPitch(1.0, 1.0); this.setGlobalRateAndPitch(1.0, 1.0);
this.setStsRateAndPitch(1.0, 1.0); this.setStsRateAndPitch(1.0, 1.0);
this.mockStorage_.updatePrefs(); this.mockStorage_.updatePrefs();
this.ensurePrefsRemovedAndGlobalSetTo(1.0, 1.0); this.ensurePrefsRemovedAndGlobalSetTo(1.0, 1.0);
}); });
// TODO(katie): Test no alert -- this is hard because it happens last. // TODO(katie): Test no alert -- this is hard because it happens last.
TEST_F('SelectToSpeakPrefsTest', 'RemovesPrefsWithNoAlertIfAllEqual', TEST_F(
function() { 'SelectToSpeakPrefsTest', 'RemovesPrefsWithNoAlertIfAllEqual', function() {
this.setGlobalRateAndPitch(1.5, 1.8); this.setGlobalRateAndPitch(1.5, 1.8);
this.setStsRateAndPitch(1.5, 1.8); this.setStsRateAndPitch(1.5, 1.8);
this.mockStorage_.updatePrefs(); this.mockStorage_.updatePrefs();
this.ensurePrefsRemovedAndGlobalSetTo(1.5, 1.8); this.ensurePrefsRemovedAndGlobalSetTo(1.5, 1.8);
}); });
TEST_F('SelectToSpeakPrefsTest', 'SavesNonDefaultStsPrefsToGlobal', TEST_F('SelectToSpeakPrefsTest', 'SavesNonDefaultStsPrefsToGlobal', function() {
function() {
this.setGlobalRateAndPitch(1.0, 1.0); this.setGlobalRateAndPitch(1.0, 1.0);
this.setStsRateAndPitch(2.0, 2.5); this.setStsRateAndPitch(2.0, 2.5);
this.mockStorage_.updatePrefs(); this.mockStorage_.updatePrefs();
...@@ -110,20 +111,22 @@ TEST_F('SelectToSpeakPrefsTest', 'SavesNonDefaultStsPrefsToGlobal', ...@@ -110,20 +111,22 @@ TEST_F('SelectToSpeakPrefsTest', 'SavesNonDefaultStsPrefsToGlobal',
this.ensurePrefsRemovedAndGlobalSetTo(2.0, 2.5); this.ensurePrefsRemovedAndGlobalSetTo(2.0, 2.5);
}); });
TEST_F('SelectToSpeakPrefsTest', TEST_F(
'SelectToSpeakPrefsTest',
'DoesNotSaveNonDefaultStsPrefsToGlobalIfGlobalChanged', function() { 'DoesNotSaveNonDefaultStsPrefsToGlobalIfGlobalChanged', function() {
this.setGlobalRateAndPitch(1.0, 1.5); this.setGlobalRateAndPitch(1.0, 1.5);
this.setStsRateAndPitch(1.0, 2.5); this.setStsRateAndPitch(1.0, 2.5);
this.mockStorage_.updatePrefs(); this.mockStorage_.updatePrefs();
this.ensurePrefsRemovedAndGlobalSetTo(1.0, 1.5); this.ensurePrefsRemovedAndGlobalSetTo(1.0, 1.5);
}); });
TEST_F('SelectToSpeakPrefsTest', 'DoesNotSaveStsPrefsToGlobalIfGlobalChanged', TEST_F(
'SelectToSpeakPrefsTest', 'DoesNotSaveStsPrefsToGlobalIfGlobalChanged',
function() { function() {
this.setGlobalRateAndPitch(2.0, 1.0); this.setGlobalRateAndPitch(2.0, 1.0);
this.setStsRateAndPitch(1.0, 1.0); this.setStsRateAndPitch(1.0, 1.0);
this.mockStorage_.updatePrefs(); this.mockStorage_.updatePrefs();
this.ensurePrefsRemovedAndGlobalSetTo(2.0, 1.0); this.ensurePrefsRemovedAndGlobalSetTo(2.0, 1.0);
}); });
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* @constructor * @constructor
* @extends {testing.Test} * @extends {testing.Test}
*/ */
function SelectToSpeakUnitTest () { function SelectToSpeakUnitTest() {
testing.Test.call(this); testing.Test.call(this);
} }
...@@ -15,10 +15,7 @@ SelectToSpeakUnitTest.prototype = { ...@@ -15,10 +15,7 @@ SelectToSpeakUnitTest.prototype = {
__proto__: testing.Test.prototype, __proto__: testing.Test.prototype,
/** @override */ /** @override */
extraLibraries: [ extraLibraries: ['test_support.js', 'select_to_speak.js']
'test_support.js',
'select_to_speak.js'
]
}; };
TEST_F('SelectToSpeakUnitTest', 'getGSuiteAppRoot', function() { TEST_F('SelectToSpeakUnitTest', 'getGSuiteAppRoot', function() {
...@@ -43,7 +40,7 @@ TEST_F('SelectToSpeakUnitTest', 'getGSuiteAppRoot', function() { ...@@ -43,7 +40,7 @@ TEST_F('SelectToSpeakUnitTest', 'getGSuiteAppRoot', function() {
assertEquals(getGSuiteAppRoot(div2), root); assertEquals(getGSuiteAppRoot(div2), root);
// Not in GSuite app // Not in GSuite app
root.url = 'https://www.not_a_doc.com' root.url = 'https://www.not_a_doc.com';
assertEquals(getGSuiteAppRoot(focus), null); assertEquals(getGSuiteAppRoot(focus), null);
assertEquals(getGSuiteAppRoot(div2), null); assertEquals(getGSuiteAppRoot(div2), null);
}); });
\ No newline at end of file
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* @constructor * @constructor
* @extends {testing.Test} * @extends {testing.Test}
*/ */
function SelectToSpeakWordUtilsUnitTest () { function SelectToSpeakWordUtilsUnitTest() {
testing.Test.call(this); testing.Test.call(this);
} }
...@@ -22,24 +22,26 @@ SelectToSpeakWordUtilsUnitTest.prototype = { ...@@ -22,24 +22,26 @@ SelectToSpeakWordUtilsUnitTest.prototype = {
] ]
}; };
TEST_F('SelectToSpeakWordUtilsUnitTest', 'getNextWordStartWithoutWordStarts', TEST_F(
'SelectToSpeakWordUtilsUnitTest', 'getNextWordStartWithoutWordStarts',
function() { function() {
let node = {node: {}}; let node = {node: {}};
assertEquals(0, WordUtils.getNextWordStart('kitty cat', 0, node)); assertEquals(0, WordUtils.getNextWordStart('kitty cat', 0, node));
assertEquals(1, WordUtils.getNextWordStart(' kitty cat', 0, node)); assertEquals(1, WordUtils.getNextWordStart(' kitty cat', 0, node));
assertEquals(6, WordUtils.getNextWordStart('kitty cat', 5, node)); assertEquals(6, WordUtils.getNextWordStart('kitty cat', 5, node));
assertEquals(6, WordUtils.getNextWordStart('kitty cat', 6, node)); assertEquals(6, WordUtils.getNextWordStart('kitty cat', 6, node));
assertEquals(7, WordUtils.getNextWordStart('kitty "cat"', 5, node)); assertEquals(7, WordUtils.getNextWordStart('kitty "cat"', 5, node));
}); });
TEST_F('SelectToSpeakWordUtilsUnitTest', 'getNextWordEndWithoutWordEnds', TEST_F(
'SelectToSpeakWordUtilsUnitTest', 'getNextWordEndWithoutWordEnds',
function() { function() {
let node = {node: {}}; let node = {node: {}};
assertEquals(5, WordUtils.getNextWordEnd('kitty cat', 0, node)); assertEquals(5, WordUtils.getNextWordEnd('kitty cat', 0, node));
assertEquals(6, WordUtils.getNextWordEnd(' kitty cat', 0, node)); assertEquals(6, WordUtils.getNextWordEnd(' kitty cat', 0, node));
assertEquals(9, WordUtils.getNextWordEnd('kitty cat', 6, node)); assertEquals(9, WordUtils.getNextWordEnd('kitty cat', 6, node));
assertEquals(9, WordUtils.getNextWordEnd('kitty cat', 7, node)); assertEquals(9, WordUtils.getNextWordEnd('kitty cat', 7, node));
}); });
TEST_F('SelectToSpeakWordUtilsUnitTest', 'getNextWordStart', function() { TEST_F('SelectToSpeakWordUtilsUnitTest', 'getNextWordStart', function() {
let inlineText = {wordStarts: [0, 6], name: 'kitty cat'}; let inlineText = {wordStarts: [0, 6], name: 'kitty cat'};
...@@ -55,21 +57,31 @@ TEST_F('SelectToSpeakWordUtilsUnitTest', 'getNextWordStart', function() { ...@@ -55,21 +57,31 @@ TEST_F('SelectToSpeakWordUtilsUnitTest', 'getNextWordStart', function() {
// Should return the default if the inlineText children are missing. // Should return the default if the inlineText children are missing.
staticText.children = []; staticText.children = [];
assertEquals(10, WordUtils.getNextWordStart('once upon a kitty cat', 10, node)); assertEquals(
10, WordUtils.getNextWordStart('once upon a kitty cat', 10, node));
}); });
TEST_F('SelectToSpeakWordUtilsUnitTest', 'getNextWordStartMultipleChildren', TEST_F(
'SelectToSpeakWordUtilsUnitTest', 'getNextWordStartMultipleChildren',
function() { function() {
let inlineText1 = {wordStarts: [0, 6], name: 'kitty cat ', indexInParent: 0}; let inlineText1 = {
let inlineText2 = {wordStarts: [0, 3], name: 'is cute', indexInParent: 1}; wordStarts: [0, 6],
let staticText = {children: [inlineText1, inlineText2], name: 'kitty cat ',
name: 'kitty cat is cute'}; indexInParent: 0
inlineText1.parent = staticText; };
inlineText2.parent = staticText; let inlineText2 = {wordStarts: [0, 3], name: 'is cute', indexInParent: 1};
let node = {node: staticText, startChar: 0, hasInlineText: true}; let staticText = {
assertEquals(10, WordUtils.getNextWordStart('kitty cat is cute', 7, node)); children: [inlineText1, inlineText2],
assertEquals(13, WordUtils.getNextWordStart('kitty cat is cute', 11, node)); name: 'kitty cat is cute'
}); };
inlineText1.parent = staticText;
inlineText2.parent = staticText;
let node = {node: staticText, startChar: 0, hasInlineText: true};
assertEquals(
10, WordUtils.getNextWordStart('kitty cat is cute', 7, node));
assertEquals(
13, WordUtils.getNextWordStart('kitty cat is cute', 11, node));
});
TEST_F('SelectToSpeakWordUtilsUnitTest', 'getNextWordEnd', function() { TEST_F('SelectToSpeakWordUtilsUnitTest', 'getNextWordEnd', function() {
let inlineText = {wordEnds: [5, 9], name: 'kitty cat'}; let inlineText = {wordEnds: [5, 9], name: 'kitty cat'};
...@@ -89,15 +101,22 @@ TEST_F('SelectToSpeakWordUtilsUnitTest', 'getNextWordEnd', function() { ...@@ -89,15 +101,22 @@ TEST_F('SelectToSpeakWordUtilsUnitTest', 'getNextWordEnd', function() {
assertEquals(5, WordUtils.getNextWordEnd('kitty cat', 4, node)); assertEquals(5, WordUtils.getNextWordEnd('kitty cat', 4, node));
}); });
TEST_F('SelectToSpeakWordUtilsUnitTest', 'getNextWordEndMultipleChildren', TEST_F(
'SelectToSpeakWordUtilsUnitTest', 'getNextWordEndMultipleChildren',
function() { function() {
let inlineText1 = {wordEnds: [5, 9], name: 'kitty cat ', indexInParent: 0}; let inlineText1 = {
let inlineText2 = {wordEnds: [2, 7], name: 'is cute', indexInParent: 1}; wordEnds: [5, 9],
let staticText = {children: [inlineText1, inlineText2], name: 'kitty cat ',
name: 'kitty cat is cute'}; indexInParent: 0
inlineText1.parent = staticText; };
inlineText2.parent = staticText; let inlineText2 = {wordEnds: [2, 7], name: 'is cute', indexInParent: 1};
let node = {node: staticText, startChar: 0, hasInlineText: true}; let staticText = {
assertEquals(12, WordUtils.getNextWordEnd('kitty cat is cute', 10, node)); children: [inlineText1, inlineText2],
assertEquals(17, WordUtils.getNextWordEnd('kitty cat is cute', 13, node)); name: 'kitty cat is cute'
}); };
\ No newline at end of file inlineText1.parent = staticText;
inlineText2.parent = staticText;
let node = {node: staticText, startChar: 0, hasInlineText: true};
assertEquals(12, WordUtils.getNextWordEnd('kitty cat is cute', 10, node));
assertEquals(17, WordUtils.getNextWordEnd('kitty cat is cute', 13, node));
});
\ No newline at end of file
...@@ -112,11 +112,11 @@ source_set("browser_tests") { ...@@ -112,11 +112,11 @@ source_set("browser_tests") {
js2gtest("switch_access_extjs_tests") { js2gtest("switch_access_extjs_tests") {
test_type = "extension" test_type = "extension"
sources = [ sources = [
"auto_scan_manager_test.extjs", "auto_scan_manager_test.js",
"navigation_manager_test.extjs", "navigation_manager_test.js",
"nodes/node_wrapper_test.extjs", "nodes/node_wrapper_test.js",
"switch_access_predicate_test.extjs", "switch_access_predicate_test.js",
"text_navigation_manager_test.extjs", "text_navigation_manager_test.js",
] ]
gen_include_files = [ gen_include_files = [
"../chromevox/testing/callback_helper.js", "../chromevox/testing/callback_helper.js",
......
...@@ -56,32 +56,36 @@ SwitchAccessAutoScanManagerTest.prototype = { ...@@ -56,32 +56,36 @@ SwitchAccessAutoScanManagerTest.prototype = {
TEST_F('SwitchAccessAutoScanManagerTest', 'SetEnabled', function() { TEST_F('SwitchAccessAutoScanManagerTest', 'SetEnabled', function() {
this.runWithLoadedTree('', (desktop) => { this.runWithLoadedTree('', (desktop) => {
assertFalse(this.autoScanManager.isRunning(), assertFalse(
this.autoScanManager.isRunning(),
'Auto scan manager is running prematurely'); 'Auto scan manager is running prematurely');
assertEquals(0, switchAccess.moveForwardCount, assertEquals(
0, switchAccess.moveForwardCount,
'Incorrect initialization of moveForwardCount'); 'Incorrect initialization of moveForwardCount');
assertEquals(0, intervalCount, 'Incorrect initialization of intervalCount'); assertEquals(0, intervalCount, 'Incorrect initialization of intervalCount');
switchAccess.onMoveForwardForTesting_ = switchAccess.onMoveForwardForTesting_ = this.newCallback(() => {
this.newCallback(() => { assertTrue(
assertTrue(this.autoScanManager.isRunning(), this.autoScanManager.isRunning(),
'Auto scan manager has stopped running'); 'Auto scan manager has stopped running');
assertGT(switchAccess.moveForwardCount, 0, assertGT(
'Switch Access has not moved forward'); switchAccess.moveForwardCount, 0,
assertEquals(1, intervalCount, 'Switch Access has not moved forward');
'The number of intervals is no longer exactly 1'); assertEquals(
}); 1, intervalCount, 'The number of intervals is no longer exactly 1');
});
this.autoScanManager.setEnabled(true); this.autoScanManager.setEnabled(true);
assertTrue(this.autoScanManager.isRunning(), assertTrue(
'Auto scan manager is not running'); this.autoScanManager.isRunning(), 'Auto scan manager is not running');
assertEquals(1, intervalCount, 'There is not exactly 1 interval'); assertEquals(1, intervalCount, 'There is not exactly 1 interval');
}); });
}); });
TEST_F('SwitchAccessAutoScanManagerTest', 'SetEnabledMultiple', function() { TEST_F('SwitchAccessAutoScanManagerTest', 'SetEnabledMultiple', function() {
this.runWithLoadedTree('', (desktop) => { this.runWithLoadedTree('', (desktop) => {
assertFalse(this.autoScanManager.isRunning(), assertFalse(
this.autoScanManager.isRunning(),
'Auto scan manager is running prematurely'); 'Auto scan manager is running prematurely');
assertEquals(0, intervalCount, 'Incorrect initialization of intervalCount'); assertEquals(0, intervalCount, 'Incorrect initialization of intervalCount');
...@@ -89,86 +93,101 @@ TEST_F('SwitchAccessAutoScanManagerTest', 'SetEnabledMultiple', function() { ...@@ -89,86 +93,101 @@ TEST_F('SwitchAccessAutoScanManagerTest', 'SetEnabledMultiple', function() {
this.autoScanManager.setEnabled(true); this.autoScanManager.setEnabled(true);
this.autoScanManager.setEnabled(true); this.autoScanManager.setEnabled(true);
assertTrue(this.autoScanManager.isRunning(), assertTrue(
'Auto scan manager is not running'); this.autoScanManager.isRunning(), 'Auto scan manager is not running');
assertEquals(1, intervalCount, 'There is not exactly 1 interval'); assertEquals(1, intervalCount, 'There is not exactly 1 interval');
}); });
}); });
TEST_F('SwitchAccessAutoScanManagerTest', 'EnableAndDisable', function() { TEST_F('SwitchAccessAutoScanManagerTest', 'EnableAndDisable', function() {
this.runWithLoadedTree('', (desktop) => { this.runWithLoadedTree('', (desktop) => {
assertFalse(this.autoScanManager.isRunning(), assertFalse(
this.autoScanManager.isRunning(),
'Auto scan manager is running prematurely'); 'Auto scan manager is running prematurely');
assertEquals(0, intervalCount, 'Incorrect initialization of intervalCount'); assertEquals(0, intervalCount, 'Incorrect initialization of intervalCount');
this.autoScanManager.setEnabled(true); this.autoScanManager.setEnabled(true);
assertTrue(this.autoScanManager.isRunning(), assertTrue(
'Auto scan manager is not running'); this.autoScanManager.isRunning(), 'Auto scan manager is not running');
assertEquals(1, intervalCount, 'There is not exactly 1 interval'); assertEquals(1, intervalCount, 'There is not exactly 1 interval');
this.autoScanManager.setEnabled(false); this.autoScanManager.setEnabled(false);
assertFalse(this.autoScanManager.isRunning(), assertFalse(
this.autoScanManager.isRunning(),
'Auto scan manager did not stop running'); 'Auto scan manager did not stop running');
assertEquals(0, intervalCount, 'Interval was not removed'); assertEquals(0, intervalCount, 'Interval was not removed');
}); });
}); });
TEST_F('SwitchAccessAutoScanManagerTest', 'RestartIfRunningMultiple', function() { TEST_F(
this.runWithLoadedTree('', (desktop) => { 'SwitchAccessAutoScanManagerTest', 'RestartIfRunningMultiple', function() {
assertFalse(this.autoScanManager.isRunning(), this.runWithLoadedTree('', (desktop) => {
'Auto scan manager is running prematurely'); assertFalse(
assertEquals(0, switchAccess.moveForwardCount, this.autoScanManager.isRunning(),
'Incorrect initialization of moveForwardCount'); 'Auto scan manager is running prematurely');
assertEquals(0, intervalCount, 'Incorrect initialization of intervalCount'); assertEquals(
0, switchAccess.moveForwardCount,
this.autoScanManager.setEnabled(true); 'Incorrect initialization of moveForwardCount');
this.autoScanManager.restartIfRunning(); assertEquals(
this.autoScanManager.restartIfRunning(); 0, intervalCount, 'Incorrect initialization of intervalCount');
this.autoScanManager.restartIfRunning();
this.autoScanManager.setEnabled(true);
assertTrue(this.autoScanManager.isRunning(), this.autoScanManager.restartIfRunning();
'Auto scan manager is not running'); this.autoScanManager.restartIfRunning();
assertEquals(1, intervalCount, 'There is not exactly 1 interval'); this.autoScanManager.restartIfRunning();
});
}); assertTrue(
this.autoScanManager.isRunning(),
TEST_F('SwitchAccessAutoScanManagerTest', 'RestartIfRunningWhenOff', function() 'Auto scan manager is not running');
{ assertEquals(1, intervalCount, 'There is not exactly 1 interval');
this.runWithLoadedTree('', (desktop) => { });
assertFalse(this.autoScanManager.isRunning(), });
'Auto scan manager is running at start.');
this.autoScanManager.restartIfRunning(); TEST_F(
assertFalse(this.autoScanManager.isRunning(), 'SwitchAccessAutoScanManagerTest', 'RestartIfRunningWhenOff', function() {
'Auto scan manager enabled by restartIfRunning'); this.runWithLoadedTree('', (desktop) => {
}); assertFalse(
}); this.autoScanManager.isRunning(),
'Auto scan manager is running at start.');
this.autoScanManager.restartIfRunning();
assertFalse(
this.autoScanManager.isRunning(),
'Auto scan manager enabled by restartIfRunning');
});
});
TEST_F('SwitchAccessAutoScanManagerTest', 'SetDefaultScanTime', function() { TEST_F('SwitchAccessAutoScanManagerTest', 'SetDefaultScanTime', function() {
this.runWithLoadedTree('', (desktop) => { this.runWithLoadedTree('', (desktop) => {
assertFalse(this.autoScanManager.isRunning(), assertFalse(
this.autoScanManager.isRunning(),
'Auto scan manager is running prematurely'); 'Auto scan manager is running prematurely');
assertEquals(UNDEFINED_INTERVAL_DELAY, intervalDelay, assertEquals(
UNDEFINED_INTERVAL_DELAY, intervalDelay,
'Interval delay improperly initialized'); 'Interval delay improperly initialized');
this.autoScanManager.setDefaultScanTime(2); this.autoScanManager.setDefaultScanTime(2);
assertFalse(this.autoScanManager.isRunning(), assertFalse(
this.autoScanManager.isRunning(),
'Setting default scan time started auto-scanning'); 'Setting default scan time started auto-scanning');
assertEquals(2, this.autoScanManager.defaultScanTime_, assertEquals(
2, this.autoScanManager.defaultScanTime_,
'Default scan time set improperly'); 'Default scan time set improperly');
assertEquals(UNDEFINED_INTERVAL_DELAY, intervalDelay, assertEquals(
UNDEFINED_INTERVAL_DELAY, intervalDelay,
'Interval delay set prematurely'); 'Interval delay set prematurely');
this.autoScanManager.setEnabled(true); this.autoScanManager.setEnabled(true);
assertTrue(this.autoScanManager.isRunning(), 'Auto scan did not start'); assertTrue(this.autoScanManager.isRunning(), 'Auto scan did not start');
assertEquals(2, this.autoScanManager.defaultScanTime_, assertEquals(
2, this.autoScanManager.defaultScanTime_,
'Default scan time has changed'); 'Default scan time has changed');
assertEquals(2, intervalDelay, 'Interval delay not set'); assertEquals(2, intervalDelay, 'Interval delay not set');
this.autoScanManager.setDefaultScanTime(5); this.autoScanManager.setDefaultScanTime(5);
assertTrue(this.autoScanManager.isRunning(), 'Auto scan stopped'); assertTrue(this.autoScanManager.isRunning(), 'Auto scan stopped');
assertEquals(5, this.autoScanManager.defaultScanTime_, assertEquals(
5, this.autoScanManager.defaultScanTime_,
'Default scan time did not change when set a second time'); 'Default scan time did not change when set a second time');
assertEquals(5, intervalDelay, 'Interval delay did not update'); assertEquals(5, intervalDelay, 'Interval delay did not update');
}); });
}); });
...@@ -27,12 +27,13 @@ TEST_F('SwitchAccessNodeWrapperTest', 'BuildDesktopTree', function() { ...@@ -27,12 +27,13 @@ TEST_F('SwitchAccessNodeWrapperTest', 'BuildDesktopTree', function() {
assertFalse(child instanceof BackButtonNode); assertFalse(child instanceof BackButtonNode);
// Check that the children form a loop. // Check that the children form a loop.
const next = children[(i+1) % children.length]; const next = children[(i + 1) % children.length];
assertEquals(next, child.next, assertEquals(
'next not properly initialized on child ' + i); next, child.next, 'next not properly initialized on child ' + i);
// We add children.length to ensure the value is greater than zero. // We add children.length to ensure the value is greater than zero.
const previous = children[(i-1 + children.length) % children.length]; const previous = children[(i - 1 + children.length) % children.length];
assertEquals(previous, child.previous, assertEquals(
previous, child.previous,
'previous not properly initialized on child ' + i); 'previous not properly initialized on child ' + i);
} }
}); });
...@@ -47,25 +48,28 @@ TEST_F('SwitchAccessNodeWrapperTest', 'AsRootNode', function() { ...@@ -47,25 +48,28 @@ TEST_F('SwitchAccessNodeWrapperTest', 'AsRootNode', function() {
<button></button> <button></button>
</div>`; </div>`;
this.runWithLoadedTree(website, (desktop) => { this.runWithLoadedTree(website, (desktop) => {
const slider = desktop.find({role: chrome.automation.RoleType.SLIDER}) const slider = desktop.find({role: chrome.automation.RoleType.SLIDER});
const inner = slider.parent; const inner = slider.parent;
assertNotEquals(undefined, inner, 'Could not find inner group'); assertNotEquals(undefined, inner, 'Could not find inner group');
const outer = inner.parent; const outer = inner.parent;
assertNotEquals(undefined, outer, 'Could not find outer group'); assertNotEquals(undefined, outer, 'Could not find outer group');
const outerRootNode = RootNodeWrapper.buildTree(outer, null); const outerRootNode = RootNodeWrapper.buildTree(outer, null);
const innerNode = outerRootNode.firstChild; const innerNode = outerRootNode.firstChild;
assertTrue(innerNode.isGroup(), 'Inner group node is not a group'); assertTrue(innerNode.isGroup(), 'Inner group node is not a group');
const innerRootNode = innerNode.asRootNode(); const innerRootNode = innerNode.asRootNode();
assertEquals(3, innerRootNode.children.length, 'Expected 3 children'); assertEquals(3, innerRootNode.children.length, 'Expected 3 children');
const sliderNode = innerRootNode.firstChild; const sliderNode = innerRootNode.firstChild;
assertEquals(chrome.automation.RoleType.SLIDER, sliderNode.role, assertEquals(
'First child should be a slider'); chrome.automation.RoleType.SLIDER, sliderNode.role,
assertEquals(chrome.automation.RoleType.BUTTON, sliderNode.next.role, 'First child should be a slider');
'Second child should be a button'); assertEquals(
assertTrue(innerRootNode.lastChild instanceof BackButtonNode, chrome.automation.RoleType.BUTTON, sliderNode.next.role,
'Final child should be the back button'); 'Second child should be a button');
assertTrue(
innerRootNode.lastChild instanceof BackButtonNode,
'Final child should be the back button');
}); });
}); });
...@@ -82,46 +86,60 @@ TEST_F('SwitchAccessNodeWrapperTest', 'Equals', function() { ...@@ -82,46 +86,60 @@ TEST_F('SwitchAccessNodeWrapperTest', 'Equals', function() {
childGroup = childGroup.asRootNode(); childGroup = childGroup.asRootNode();
assertFalse(desktopRootNode.equals(), 'Root node equals nothing'); assertFalse(desktopRootNode.equals(), 'Root node equals nothing');
assertFalse(desktopRootNode.equals(new SARootNode()), assertFalse(
desktopRootNode.equals(new SARootNode()),
'Different type root nodes are equal'); 'Different type root nodes are equal');
assertFalse(new SARootNode().equals(desktopRootNode), assertFalse(
new SARootNode().equals(desktopRootNode),
'Equals is not symmetric? Different types of root are equal'); 'Equals is not symmetric? Different types of root are equal');
assertFalse(desktopRootNode.equals(childGroup), assertFalse(
desktopRootNode.equals(childGroup),
'Groups with different children are equal'); 'Groups with different children are equal');
assertFalse(childGroup.equals(desktopRootNode), assertFalse(
childGroup.equals(desktopRootNode),
'Equals is not symmetric? Groups with different children are equal'); 'Equals is not symmetric? Groups with different children are equal');
assertTrue(desktopRootNode.equals(desktopRootNode), assertTrue(
desktopRootNode.equals(desktopRootNode),
'Equals is not reflexive? (root node)'); 'Equals is not reflexive? (root node)');
const desktopCopy = RootNodeWrapper.buildDesktopTree(desktop); const desktopCopy = RootNodeWrapper.buildDesktopTree(desktop);
assertTrue(desktopRootNode.equals(desktopCopy), assertTrue(
'Two desktop roots are not equal'); desktopRootNode.equals(desktopCopy), 'Two desktop roots are not equal');
assertTrue(desktopCopy.equals(desktopRootNode), assertTrue(
desktopCopy.equals(desktopRootNode),
'Equals is not symmetric? Two desktop roots aren\'t equal'); 'Equals is not symmetric? Two desktop roots aren\'t equal');
const wrappedNode = desktopRootNode.firstChild; const wrappedNode = desktopRootNode.firstChild;
assertTrue(wrappedNode instanceof NodeWrapper, assertTrue(
wrappedNode instanceof NodeWrapper,
'Child node is not of type NodeWrapper'); 'Child node is not of type NodeWrapper');
assertGT(desktopRootNode.children.length, 1, assertGT(
'Desktop root has only 1 child'); desktopRootNode.children.length, 1, 'Desktop root has only 1 child');
assertFalse(wrappedNode.equals(), 'Child NodeWrapper equals nothing'); assertFalse(wrappedNode.equals(), 'Child NodeWrapper equals nothing');
assertFalse(wrappedNode.equals(new BackButtonNode()), assertFalse(
wrappedNode.equals(new BackButtonNode()),
'Child NodeWrapper equals a BackButtonNode'); 'Child NodeWrapper equals a BackButtonNode');
assertFalse(new BackButtonNode().equals(wrappedNode), assertFalse(
new BackButtonNode().equals(wrappedNode),
'Equals is not symmetric? NodeWrapper equals a BackButtonNode'); 'Equals is not symmetric? NodeWrapper equals a BackButtonNode');
assertFalse(wrappedNode.equals(desktopRootNode.lastChild), assertFalse(
wrappedNode.equals(desktopRootNode.lastChild),
'Children with different base nodes are equal'); 'Children with different base nodes are equal');
assertFalse(desktopRootNode.lastChild.equals(wrappedNode), assertFalse(
desktopRootNode.lastChild.equals(wrappedNode),
'Equals is not symmetric? Nodes with different base nodes are equal'); 'Equals is not symmetric? Nodes with different base nodes are equal');
const equivalentWrappedNode = new NodeWrapper(wrappedNode.baseNode_, const equivalentWrappedNode =
desktopRootNode); new NodeWrapper(wrappedNode.baseNode_, desktopRootNode);
assertTrue(wrappedNode.equals(wrappedNode), assertTrue(
wrappedNode.equals(wrappedNode),
'Equals is not reflexive? (child node)'); 'Equals is not reflexive? (child node)');
assertTrue(wrappedNode.equals(equivalentWrappedNode), assertTrue(
wrappedNode.equals(equivalentWrappedNode),
'Two nodes with the same base node are not equal'); 'Two nodes with the same base node are not equal');
assertTrue(equivalentWrappedNode.equals(wrappedNode), assertTrue(
equivalentWrappedNode.equals(wrappedNode),
'Equals is not symmetric? Nodes with the same base node aren\'t equal'); 'Equals is not symmetric? Nodes with the same base node aren\'t equal');
}); });
}); });
...@@ -135,37 +153,48 @@ TEST_F('SwitchAccessNodeWrapperTest', 'Actions', function() { ...@@ -135,37 +153,48 @@ TEST_F('SwitchAccessNodeWrapperTest', 'Actions', function() {
desktop.find({role: chrome.automation.RoleType.TEXT_FIELD}), desktop.find({role: chrome.automation.RoleType.TEXT_FIELD}),
new SARootNode()); new SARootNode());
assertEquals(chrome.automation.RoleType.TEXT_FIELD, textField.role, assertEquals(
chrome.automation.RoleType.TEXT_FIELD, textField.role,
'Text field node is not a text field'); 'Text field node is not a text field');
assertTrue(textField.hasAction(SAConstants.MenuAction.OPEN_KEYBOARD), assertTrue(
textField.hasAction(SAConstants.MenuAction.OPEN_KEYBOARD),
'Text field does not have action OPEN_KEYBOARD'); 'Text field does not have action OPEN_KEYBOARD');
assertTrue(textField.hasAction(SAConstants.MenuAction.DICTATION), assertTrue(
textField.hasAction(SAConstants.MenuAction.DICTATION),
'Text field does not have action DICTATION'); 'Text field does not have action DICTATION');
assertFalse(textField.hasAction(SAConstants.MenuAction.SELECT), assertFalse(
textField.hasAction(SAConstants.MenuAction.SELECT),
'Text field has action SELECT'); 'Text field has action SELECT');
const button = new NodeWrapper( const button = new NodeWrapper(
desktop.find({role: chrome.automation.RoleType.BUTTON}), desktop.find({role: chrome.automation.RoleType.BUTTON}),
new SARootNode()); new SARootNode());
assertEquals(chrome.automation.RoleType.BUTTON, button.role, assertEquals(
chrome.automation.RoleType.BUTTON, button.role,
'Button node is not a button'); 'Button node is not a button');
assertTrue(button.hasAction(SAConstants.MenuAction.SELECT), assertTrue(
button.hasAction(SAConstants.MenuAction.SELECT),
'Button does not have action SELECT'); 'Button does not have action SELECT');
assertFalse(button.hasAction(SAConstants.MenuAction.OPEN_KEYBOARD), assertFalse(
button.hasAction(SAConstants.MenuAction.OPEN_KEYBOARD),
'Button has action OPEN_KEYBOARD'); 'Button has action OPEN_KEYBOARD');
assertFalse(button.hasAction(SAConstants.MenuAction.DICTATION), assertFalse(
button.hasAction(SAConstants.MenuAction.DICTATION),
'Button has action DICTATION'); 'Button has action DICTATION');
const slider = new NodeWrapper( const slider = new NodeWrapper(
desktop.find({role: chrome.automation.RoleType.SLIDER}), desktop.find({role: chrome.automation.RoleType.SLIDER}),
new SARootNode()); new SARootNode());
assertEquals(chrome.automation.RoleType.SLIDER, slider.role, assertEquals(
chrome.automation.RoleType.SLIDER, slider.role,
'Slider node is not a slider'); 'Slider node is not a slider');
assertTrue(slider.hasAction(SAConstants.MenuAction.INCREMENT), assertTrue(
slider.hasAction(SAConstants.MenuAction.INCREMENT),
'Slider does not have action INCREMENT'); 'Slider does not have action INCREMENT');
assertTrue(slider.hasAction(SAConstants.MenuAction.DECREMENT), assertTrue(
slider.hasAction(SAConstants.MenuAction.DECREMENT),
'Slider does not have action DECREMENT'); 'Slider does not have action DECREMENT');
}); });
}); });
...@@ -10,28 +10,29 @@ var MachineLearningInternalsUnitTests = class extends testing.Test { ...@@ -10,28 +10,29 @@ var MachineLearningInternalsUnitTests = class extends testing.Test {
'machine_learning_internals_utils.js', 'machine_learning_internals_utils.js',
]; ];
} }
} };
TEST_F('MachineLearningInternalsUnitTests', 'enumToString', function() { TEST_F('MachineLearningInternalsUnitTests', 'enumToString', function() {
const TestEnum = { const TestEnum = {
OK: 1, OK: 1,
FAIL: 2, FAIL: 2,
}; };
assertEquals("OK", machine_learning_internals.utils.enumToString(1, TestEnum)); assertEquals(
assertEquals("FAIL", machine_learning_internals.utils.enumToString(2, TestEnum)); 'OK', machine_learning_internals.utils.enumToString(1, TestEnum));
assertThrows( assertEquals(
() => {machine_learning_internals.utils.enumToString(3, TestEnum)}, 'FAIL', machine_learning_internals.utils.enumToString(2, TestEnum));
"Unknown enumValue: 3"); assertThrows(() => {
machine_learning_internals.utils.enumToString(3, TestEnum);
}, 'Unknown enumValue: 3');
}); });
TEST_F('MachineLearningInternalsUnitTests', 'makeTensor', function() { TEST_F('MachineLearningInternalsUnitTests', 'makeTensor', function() {
const myArray = [1.0, 2.0, 3.0]; const myArray = [1.0, 2.0, 3.0];
const myTensor = machine_learning_internals.utils.makeTensor( const myTensor =
myArray, [myArray.length]); machine_learning_internals.utils.makeTensor(myArray, [myArray.length]);
assertEquals(myArray, myTensor.data.floatList.value); assertEquals(myArray, myTensor.data.floatList.value);
assertEquals(myArray.length, myTensor.shape.value[0]); assertEquals(myArray.length, myTensor.shape.value[0]);
assertThrows( assertThrows(() => {
() => {machine_learning_internals.utils.makeTensor(myArray, [2,3])}, machine_learning_internals.utils.makeTensor(myArray, [2, 3]);
`valueList.length ${myArray.length} != expectedLength 6`); }, `valueList.length ${myArray.length} != expectedLength 6`);
}); });
...@@ -258,14 +258,14 @@ js2gtest("unit_tests_js") { ...@@ -258,14 +258,14 @@ js2gtest("unit_tests_js") {
] ]
if (is_chromeos) { if (is_chromeos) {
sources += [ sources += [
"../../../browser/resources/chromeos/accessibility/braille_ime/braille_ime_unittest.gtestjs", "../../../browser/resources/chromeos/accessibility/braille_ime/braille_ime_unittest.js",
"../../../browser/resources/chromeos/accessibility/select_to_speak/node_utils_unittest.gtestjs", "../../../browser/resources/chromeos/accessibility/select_to_speak/node_utils_unittest.js",
"../../../browser/resources/chromeos/accessibility/select_to_speak/paragraph_utils_unittest.gtestjs", "../../../browser/resources/chromeos/accessibility/select_to_speak/paragraph_utils_unittest.js",
"../../../browser/resources/chromeos/accessibility/select_to_speak/rect_utils_unittest.gtestjs", "../../../browser/resources/chromeos/accessibility/select_to_speak/rect_utils_unittest.js",
"../../../browser/resources/chromeos/accessibility/select_to_speak/select_to_speak_unittest.gtestjs", "../../../browser/resources/chromeos/accessibility/select_to_speak/select_to_speak_unittest.js",
"../../../browser/resources/chromeos/accessibility/select_to_speak/word_utils_unittest.gtestjs", "../../../browser/resources/chromeos/accessibility/select_to_speak/word_utils_unittest.js",
"../../../browser/resources/chromeos/accessibility/switch_access/rect_helper_unittest.gtestjs", "../../../browser/resources/chromeos/accessibility/switch_access/rect_helper_unittest.js",
"../../../browser/resources/chromeos/machine_learning/machine_learning_internals_utils_unittest.gtestjs", "../../../browser/resources/chromeos/machine_learning/machine_learning_internals_utils_unittest.js",
] ]
extra_js_files += [ extra_js_files += [
"../../../browser/resources/chromeos/accessibility/braille_ime/braille_ime.js", "../../../browser/resources/chromeos/accessibility/braille_ime/braille_ime.js",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment