Commit 5630fe0b authored by Ondrej Skopek's avatar Ondrej Skopek Committed by Commit Bot

[Local NTP Voice] Try Again UI regression fix.

Fixes the issue of showing an error message for a short time before
restarting Voice Search after click on the Try Again link (the microphone
icon retrying worked correctly). As a result, removed the
|speech.restart| function and associated test. Now, the display of the
"Try Again" message is tested in text module tests, and the actual click
handling is tested in the view module.

Renamed the |text.cancelListeningTimeout| function to
|text.clearListeningTimeout| for consistency.

Bug: 583291
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: Id5815f9857b90264340ebb37b9ef603bbae404ea
Reviewed-on: https://chromium-review.googlesource.com/663547Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Commit-Queue: Ondrej Škopek <oskopek@google.com>
Cr-Commit-Position: refs/heads/master@{#501600}
parent f2c4d52d
...@@ -813,7 +813,8 @@ speech.onClick_ = function(shouldSubmit, shouldRetry, navigatingAway) { ...@@ -813,7 +813,8 @@ speech.onClick_ = function(shouldSubmit, shouldRetry, navigatingAway) {
if (speech.finalResult_ && shouldSubmit) { if (speech.finalResult_ && shouldSubmit) {
speech.submitFinalResult_(); speech.submitFinalResult_();
} else if (speech.currentState_ == speech.State_.STOPPED && shouldRetry) { } else if (speech.currentState_ == speech.State_.STOPPED && shouldRetry) {
speech.restart(); speech.reset_();
speech.start();
} else if (speech.currentState_ == speech.State_.STOPPED && navigatingAway) { } else if (speech.currentState_ == speech.State_.STOPPED && navigatingAway) {
// If the user clicks on a "Learn more" or "Details" support page link // If the user clicks on a "Learn more" or "Details" support page link
// from an error message, do nothing, and let Chrome navigate to that page. // from an error message, do nothing, and let Chrome navigate to that page.
...@@ -822,14 +823,6 @@ speech.onClick_ = function(shouldSubmit, shouldRetry, navigatingAway) { ...@@ -822,14 +823,6 @@ speech.onClick_ = function(shouldSubmit, shouldRetry, navigatingAway) {
} }
}; };
/**
* Restarts voice recognition. Used for the 'Try again' error link.
*/
speech.restart = function() {
speech.reset_();
speech.start();
};
/* TEXT VIEW */ /* TEXT VIEW */
/** /**
...@@ -970,7 +963,7 @@ text.init = function() { ...@@ -970,7 +963,7 @@ text.init = function() {
*/ */
text.updateTextArea = function(interimText, opt_finalText = '') { text.updateTextArea = function(interimText, opt_finalText = '') {
window.clearTimeout(text.initializingTimer_); window.clearTimeout(text.initializingTimer_);
text.cancelListeningTimeout(); text.clearListeningTimeout();
text.interim_.textContent = interimText; text.interim_.textContent = interimText;
text.final_.textContent = opt_finalText; text.final_.textContent = opt_finalText;
...@@ -1006,6 +999,7 @@ text.showInitializingMessage = function() { ...@@ -1006,6 +999,7 @@ text.showInitializingMessage = function() {
*/ */
text.showReadyMessage = function() { text.showReadyMessage = function() {
window.clearTimeout(text.initializingTimer_); window.clearTimeout(text.initializingTimer_);
text.clearListeningTimeout();
text.updateTextArea(speech.messages.ready); text.updateTextArea(speech.messages.ready);
text.startListeningMessageAnimation_(); text.startListeningMessageAnimation_();
}; };
...@@ -1066,7 +1060,7 @@ text.getErrorLink_ = function(error) { ...@@ -1066,7 +1060,7 @@ text.getErrorLink_ = function(error) {
case RecognitionError.NO_MATCH: case RecognitionError.NO_MATCH:
linkElement.id = text.RETRY_LINK_ID; linkElement.id = text.RETRY_LINK_ID;
linkElement.textContent = speech.messages.tryAgain; linkElement.textContent = speech.messages.tryAgain;
linkElement.onclick = speech.restart; // When clicked, |view.onWindowClick_| gets called.
return linkElement; return linkElement;
case RecognitionError.NO_SPEECH: case RecognitionError.NO_SPEECH:
case RecognitionError.AUDIO_CAPTURE: case RecognitionError.AUDIO_CAPTURE:
...@@ -1094,7 +1088,7 @@ text.getErrorLink_ = function(error) { ...@@ -1094,7 +1088,7 @@ text.getErrorLink_ = function(error) {
text.clear = function() { text.clear = function() {
text.updateTextArea(''); text.updateTextArea('');
text.cancelListeningTimeout(); text.clearListeningTimeout();
window.clearTimeout(text.initializingTimer_); window.clearTimeout(text.initializingTimer_);
text.interim_.className = text.TEXT_AREA_CLASS_; text.interim_.className = text.TEXT_AREA_CLASS_;
...@@ -1105,7 +1099,7 @@ text.clear = function() { ...@@ -1105,7 +1099,7 @@ text.clear = function() {
/** /**
* Cancels listening message display. * Cancels listening message display.
*/ */
text.cancelListeningTimeout = function() { text.clearListeningTimeout = function() {
window.clearTimeout(text.listeningTimer_); window.clearTimeout(text.listeningTimer_);
}; };
...@@ -1427,7 +1421,7 @@ view.setReceivingSpeech = function() { ...@@ -1427,7 +1421,7 @@ view.setReceivingSpeech = function() {
if (view.isVisible_) { if (view.isVisible_) {
view.container_.className = view.RECEIVING_SPEECH_CLASS_; view.container_.className = view.RECEIVING_SPEECH_CLASS_;
microphone.startInputAnimation(); microphone.startInputAnimation();
text.cancelListeningTimeout(); text.clearListeningTimeout();
} }
}; };
......
...@@ -96,15 +96,9 @@ test.text.testShowErrorMessageWithLink = function() { ...@@ -96,15 +96,9 @@ test.text.testShowErrorMessageWithLink = function() {
/** /**
* Test updating the text with an error message containing a callback. * Test updating the text with an error message containing a "Try Again" link.
*/ */
test.text.testShowErrorMessageWithCallback = function() { test.text.testShowErrorMessageWithTryAgainLink = function() {
// Mock the restart callback.
let restartCalled = false;
test.text.stubs.replace(speech, 'restart', function() {
restartCalled = true;
});
// Display the try again error. // Display the try again error.
const tryAgainError = RecognitionError.NO_MATCH; const tryAgainError = RecognitionError.NO_MATCH;
text.showErrorMessage(tryAgainError); text.showErrorMessage(tryAgainError);
...@@ -113,12 +107,6 @@ test.text.testShowErrorMessageWithCallback = function() { ...@@ -113,12 +107,6 @@ test.text.testShowErrorMessageWithCallback = function() {
'Try again</a>', 'Try again</a>',
text.interim_.innerHTML); text.interim_.innerHTML);
assertEquals('', text.final_.innerHTML); assertEquals('', text.final_.innerHTML);
// Assert the callback is called when the link element is clicked.
assertFalse(restartCalled);
assertEquals(1, text.interim_.children.length);
text.interim_.children[0].click();
assertTrue(restartCalled);
}; };
......
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