Commit fcc24258 authored by Katie D's avatar Katie D Committed by Commit Bot

Select-to-Speak integration tests can tap the ash STS button in the tray.

This allows for more full integration tests from the new button through
to the extension, in addition to the select_to_speak_browsertest.cc tests.

Bug: 753018, 840493
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: Ib60ea7c5beea59b092fe1bb4d2ce68e27c9c347f
Reviewed-on: https://chromium-review.googlesource.com/1047947Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Commit-Queue: Katie Dektar <katie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#557590}
parent cd04c26d
...@@ -699,6 +699,8 @@ SelectToSpeak.prototype = { ...@@ -699,6 +699,8 @@ SelectToSpeak.prototype = {
this.recordSelectToSpeakStateChangeEvent_( this.recordSelectToSpeakStateChangeEvent_(
StateChangeEvent.CANCEL_SELECTION); StateChangeEvent.CANCEL_SELECTION);
} }
this.onStateChangeRequestedCallbackForTest_ &&
this.onStateChangeRequestedCallbackForTest_();
}, },
/** /**
...@@ -1310,9 +1312,9 @@ SelectToSpeak.prototype = { ...@@ -1310,9 +1312,9 @@ SelectToSpeak.prototype = {
}, },
/** /**
* Fires a mock state change request. * Function to be called when a state change request is received from the
* accessibilityPrivate API.
* @type {?function()}
*/ */
fireMockStateChangeRequest: function() { onStateChangeRequestedCallbackForTest_: null,
this.onStateChangeRequested_();
},
}; };
...@@ -87,8 +87,8 @@ SelectToSpeakE2ETest.prototype = { ...@@ -87,8 +87,8 @@ SelectToSpeakE2ETest.prototype = {
* |this.newCallback| if passed to asynchonous calls. Otherwise, the test * |this.newCallback| if passed to asynchonous calls. Otherwise, the test
* will be finished prematurely. * will be finished prematurely.
* @param {string} url Url to load and wait for. * @param {string} url Url to load and wait for.
* @param {function(chrome.automation.AutomationNode)} callback * @param {function(chrome.automation.AutomationNode)} callback Called with
* Called once the document is ready. * the desktop node once the document is ready.
*/ */
runWithLoadedTree: function(url, callback) { runWithLoadedTree: function(url, callback) {
callback = this.newCallback(callback); callback = this.newCallback(callback);
...@@ -99,7 +99,7 @@ SelectToSpeakE2ETest.prototype = { ...@@ -99,7 +99,7 @@ SelectToSpeakE2ETest.prototype = {
r.removeEventListener('focus', listener, true); r.removeEventListener('focus', listener, true);
r.removeEventListener('loadComplete', listener, true); r.removeEventListener('loadComplete', listener, true);
callback && callback(evt.target); callback && callback(r);
callback = null; callback = null;
}; };
r.addEventListener('focus', listener, true); r.addEventListener('focus', listener, true);
......
...@@ -33,6 +33,19 @@ SelectToSpeakMouseSelectionTest.prototype = { ...@@ -33,6 +33,19 @@ SelectToSpeakMouseSelectionTest.prototype = {
selectToSpeak.fireMockKeyUpEvent( selectToSpeak.fireMockKeyUpEvent(
{keyCode: SelectToSpeak.SEARCH_KEY_CODE}); {keyCode: SelectToSpeak.SEARCH_KEY_CODE});
}, },
tapTrayButton(desktop, callback) {
let button = desktop.find({roleType: 'button', attributes:
{className: SELECT_TO_SPEAK_TRAY_CLASS_NAME}
});
callback = this.newCallback(callback);
selectToSpeak.onStateChangeRequestedCallbackForTest_ =
this.newCallback(() => {
selectToSpeak.onStateChangeRequestedCallbackForTest_ = null;
callback();
});
button.doDefault();
},
} }
TEST_F('SelectToSpeakMouseSelectionTest', 'SpeaksNodeWhenClicked', TEST_F('SelectToSpeakMouseSelectionTest', 'SpeaksNodeWhenClicked',
...@@ -124,7 +137,7 @@ TEST_F('SelectToSpeakMouseSelectionTest', 'SpeaksAcrossNodesInAParagraph', ...@@ -124,7 +137,7 @@ TEST_F('SelectToSpeakMouseSelectionTest', 'SpeaksAcrossNodesInAParagraph',
}); });
TEST_F('SelectToSpeakMouseSelectionTest', TEST_F('SelectToSpeakMouseSelectionTest',
'SpeaksNodeWhenInSelectionModeAndClicked', function() { 'SpeaksNodeAfterTrayTapAndMouseClick', function() {
this.runWithLoadedTree('data:text/html;charset=utf-8,' + this.runWithLoadedTree('data:text/html;charset=utf-8,' +
'<p>This is some text</p>', '<p>This is some text</p>',
function(desktop) { function(desktop) {
...@@ -144,9 +157,10 @@ TEST_F('SelectToSpeakMouseSelectionTest', ...@@ -144,9 +157,10 @@ TEST_F('SelectToSpeakMouseSelectionTest',
screenY: textNode.location.top + 1}; screenY: textNode.location.top + 1};
// A state change request should shift us into 'selecting' state from // A state change request should shift us into 'selecting' state from
// 'inactive'. // 'inactive'.
selectToSpeak.fireMockStateChangeRequest(); this.tapTrayButton(desktop, () => {
selectToSpeak.fireMockMouseDownEvent(event); selectToSpeak.fireMockMouseDownEvent(event);
selectToSpeak.fireMockMouseUpEvent(event); selectToSpeak.fireMockMouseUpEvent(event);
});
} }
); );
}); });
...@@ -161,20 +175,20 @@ TEST_F('SelectToSpeakMouseSelectionTest', ...@@ -161,20 +175,20 @@ TEST_F('SelectToSpeakMouseSelectionTest',
screenY: textNode.location.top + 1}; screenY: textNode.location.top + 1};
// A state change request should shift us into 'selecting' state from // A state change request should shift us into 'selecting' state from
// 'inactive'. // 'inactive'.
selectToSpeak.fireMockStateChangeRequest(); this.tapTrayButton(desktop, () => {
selectToSpeak.fireMockMouseDownEvent(event); selectToSpeak.fireMockMouseDownEvent(event);
assertEquals(chrome.accessibilityPrivate.SelectToSpeakState.SELECTING, assertEquals(SelectToSpeakState.SELECTING, selectToSpeak.state_);
selectToSpeak.state_);
// Another state change puts us back in 'inactive'.
// Another state change puts us back in 'inactive'. this.tapTrayButton(desktop, () => {
selectToSpeak.fireMockStateChangeRequest(); assertEquals(SelectToSpeakState.INACTIVE, selectToSpeak.state_);
assertEquals(chrome.accessibilityPrivate.SelectToSpeakState.INACTIVE, });
selectToSpeak.state_); });
} }
); );
}); });
TEST_F('SelectToSpeakMouseSelectionTest', 'CancelsSpeechWithStateChange', TEST_F('SelectToSpeakMouseSelectionTest', 'CancelsSpeechWithTrayTap',
function() { function() {
this.runWithLoadedTree('data:text/html;charset=utf-8,' + this.runWithLoadedTree('data:text/html;charset=utf-8,' +
'<p>This is some text</p>', '<p>This is some text</p>',
...@@ -187,15 +201,14 @@ TEST_F('SelectToSpeakMouseSelectionTest', 'CancelsSpeechWithStateChange', ...@@ -187,15 +201,14 @@ TEST_F('SelectToSpeakMouseSelectionTest', 'CancelsSpeechWithStateChange',
assertTrue(this.mockTts.currentlySpeaking()); assertTrue(this.mockTts.currentlySpeaking());
assertEquals(this.mockTts.pendingUtterances().length, 1); assertEquals(this.mockTts.pendingUtterances().length, 1);
this.assertEqualsCollapseWhitespace( this.assertEqualsCollapseWhitespace(
this.mockTts.pendingUtterances()[0], 'This is some text'); this.mockTts.pendingUtterances()[0], 'This is some text');
// Cancel speech and make sure state resets to INACTIVE. // Cancel speech and make sure state resets to INACTIVE.
selectToSpeak.fireMockStateChangeRequest(); this.tapTrayButton(desktop, () => {
assertFalse(this.mockTts.currentlySpeaking()); assertFalse(this.mockTts.currentlySpeaking());
assertEquals(this.mockTts.pendingUtterances().length, 0); assertEquals(this.mockTts.pendingUtterances().length, 0);
assertEquals( assertEquals(SelectToSpeakState.INACTIVE, selectToSpeak.state_);
chrome.accessibilityPrivate.SelectToSpeakState.INACTIVE, });
selectToSpeak.state_);
} }
)]); )]);
let textNode = this.findTextNode(desktop, 'This is some text'); let textNode = this.findTextNode(desktop, 'This is some text');
...@@ -204,4 +217,38 @@ TEST_F('SelectToSpeakMouseSelectionTest', 'CancelsSpeechWithStateChange', ...@@ -204,4 +217,38 @@ TEST_F('SelectToSpeakMouseSelectionTest', 'CancelsSpeechWithStateChange',
this.selectRangeForSpeech(event, event); this.selectRangeForSpeech(event, event);
} }
); );
}); });
\ No newline at end of file
TEST_F('SelectToSpeakMouseSelectionTest', 'DoesNotSpeakOnlyTheTrayButton',
function() {
// The tray button itself should not be spoken when clicked in selection mode
// per UI review (but if more elements are being verbalized than just the STS
// tray button, it may be spoken). This is similar to how the stylus may
// act as a laser pointer unless it taps on the stylus options button, which
// always opens on a tap regardless of the stylus behavior selected.
chrome.automation.getDesktop(this.newCallback((desktop) => {
this.tapTrayButton(desktop, () => {
assertEquals(selectToSpeak.state_, SelectToSpeakState.SELECTING);
let button = desktop.find({roleType: 'button', attributes:
{className: SELECT_TO_SPEAK_TRAY_CLASS_NAME}
});
// Use the same automation callbacks as Select-to-Speak to make
// sure we actually don't start speech after the hittest and focus
// callbacks are used to check which nodes should be spoken.
desktop.addEventListener(
EventType.MOUSE_RELEASED, this.newCallback((evt) => {
chrome.automation.getFocus(this.newCallback((node) => {
assertEquals(selectToSpeak.state_, SelectToSpeakState.INACTIVE);
assertFalse(this.mockTts.currentlySpeaking());
assertEquals(this.mockTts.pendingUtterances().length, 0);
}));
}), true);
let event = {screenX: button.location.left + 1,
screenY: button.location.top + 1};
selectToSpeak.fireMockMouseDownEvent(event);
selectToSpeak.fireMockMouseUpEvent(event);
});
}));
});
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