Commit 59211f2c authored by David Tseng's avatar David Tseng Committed by Commit Bot

Include line numbers in SpeechMonitor async api

Unfortunately, to resolve base::Location for each api call, we cannot support chaining.

However, shortening the variable name for
|speech_monitor_|
to
|sm_|
and not having to indent, we actually save some indent space.

Also, this change now includes all pending utterances (for understanding the state when the test is waiting).

Sample output:
[158567:158567:0325/082550.588956:ERROR:speech_monitor.cc(276)] Still waiting for expectation(s).
Unsatisfied expectations...
ExpectSpeech("Fail!Rate 19 percent") RunTestOnMainThread@../../chrome/browser/chromeos/accessibility/spoken_feedback_browsertest.cc:931
Call() RunTestOnMainThread@../../chrome/browser/chromeos/accessibility/spoken_feedback_browsertest.cc:933
ExpectSpeech("Pitch 50 percent") RunTestOnMainThread@../../chrome/browser/chromeos/accessibility/spoken_feedback_browsertest.cc:934
Call() RunTestOnMainThread@../../chrome/browser/chromeos/accessibility/spoken_feedback_browsertest.cc:936
ExpectSpeech("Reset text to speech settings to default values") RunTestOnMainThread@../../chrome/browser/chromeos/accessibility/spoken_feedback_browsertest.cc:938
Call() RunTestOnMainThread@../../chrome/browser/chromeos/accessibility/spoken_feedback_browsertest.cc:941
ExpectSpeech("Rate 19 percent") RunTestOnMainThread@../../chrome/browser/chromeos/accessibility/spoken_feedback_browsertest.cc:942
Call() RunTestOnMainThread@../../chrome/browser/chromeos/accessibility/spoken_feedback_browsertest.cc:943
ExpectSpeech("Pitch 50 percent") RunTestOnMainThread@../../chrome/browser/chromeos/accessibility/spoken_feedback_browsertest.cc:944

pending speech utterances...
Volume 100 percent
Rate 19 percent

Satisfied expectations...
Call() RunTestOnMainThread@../../chrome/browser/chromeos/accessibility/spoken_feedback_browsertest.cc:926
ExpectSpeech("Reset text to speech settings to default values") RunTestOnMainThread@../../chrome/browser/chromeos/accessibility/spoken_feedback_browsertest.cc:928
Call() RunTestOnMainThread@../../chrome/browser/chromeos/accessibility/spoken_feedback_browsertest.cc:930

Change-Id: If1bdbfb517014e681cb233800eab3f62f608188f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2120741Reviewed-by: default avatarAkihiro Ota <akihiroota@chromium.org>
Commit-Queue: David Tseng <dtseng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#753353}
parent e835be8e
...@@ -161,7 +161,8 @@ double SpeechMonitor::GetDelayForLastUtteranceMS() { ...@@ -161,7 +161,8 @@ double SpeechMonitor::GetDelayForLastUtteranceMS() {
return delay_for_last_utterance_ms_; return delay_for_last_utterance_ms_;
} }
SpeechMonitor& SpeechMonitor::ExpectSpeech(const std::string& text) { void SpeechMonitor::ExpectSpeech(const std::string& text,
const base::Location& location) {
CHECK(!replay_loop_runner_.get()); CHECK(!replay_loop_runner_.get());
replay_queue_.push_back({[this, text]() { replay_queue_.push_back({[this, text]() {
for (auto it = utterance_queue_.begin(); for (auto it = utterance_queue_.begin();
...@@ -176,11 +177,12 @@ SpeechMonitor& SpeechMonitor::ExpectSpeech(const std::string& text) { ...@@ -176,11 +177,12 @@ SpeechMonitor& SpeechMonitor::ExpectSpeech(const std::string& text) {
} }
return false; return false;
}, },
"ExpectSpeech(\"" + text + "\")"}); "ExpectSpeech(\"" + text + "\") " +
return *this; location.ToString()});
} }
SpeechMonitor& SpeechMonitor::ExpectSpeechPattern(const std::string& pattern) { void SpeechMonitor::ExpectSpeechPattern(const std::string& pattern,
const base::Location& location) {
CHECK(!replay_loop_runner_.get()); CHECK(!replay_loop_runner_.get());
replay_queue_.push_back({[this, pattern]() { replay_queue_.push_back({[this, pattern]() {
for (auto it = utterance_queue_.begin(); for (auto it = utterance_queue_.begin();
...@@ -195,30 +197,31 @@ SpeechMonitor& SpeechMonitor::ExpectSpeechPattern(const std::string& pattern) { ...@@ -195,30 +197,31 @@ SpeechMonitor& SpeechMonitor::ExpectSpeechPattern(const std::string& pattern) {
} }
return false; return false;
}, },
"ExpectSpeechPattern(\"" + pattern + "\")"}); "ExpectSpeechPattern(\"" + pattern + "\") " +
return *this; location.ToString()});
} }
SpeechMonitor& SpeechMonitor::ExpectNextSpeechIsNot(const std::string& text) { void SpeechMonitor::ExpectNextSpeechIsNot(const std::string& text,
const base::Location& location) {
CHECK(!replay_loop_runner_.get()); CHECK(!replay_loop_runner_.get());
replay_queue_.push_back({[this, text]() { replay_queue_.push_back(
if (utterance_queue_.empty()) {[this, text]() {
return false; if (utterance_queue_.empty())
return false;
return text != utterance_queue_.front().text;
}, return text != utterance_queue_.front().text;
"ExpectNextSpeechIsNot(\"" + text + "\")"}); },
return *this; "ExpectNextSpeechIsNot(\"" + text + "\") " + location.ToString()});
} }
SpeechMonitor& SpeechMonitor::Call(std::function<void()> func) { void SpeechMonitor::Call(std::function<void()> func,
const base::Location& location) {
CHECK(!replay_loop_runner_.get()); CHECK(!replay_loop_runner_.get());
replay_queue_.push_back({[func]() { replay_queue_.push_back({[func]() {
func(); func();
return true; return true;
}, },
"Call()"}); "Call() " + location.ToString()});
return *this;
} }
void SpeechMonitor::Replay() { void SpeechMonitor::Replay() {
...@@ -266,9 +269,15 @@ void SpeechMonitor::MaybePrintExpectations() { ...@@ -266,9 +269,15 @@ void SpeechMonitor::MaybePrintExpectations() {
for (const auto& pair : replay_queue_) for (const auto& pair : replay_queue_)
replay_queue_descriptions.push_back(pair.second); replay_queue_descriptions.push_back(pair.second);
std::vector<std::string> utterance_queue_descriptions;
for (const auto& item : utterance_queue_)
utterance_queue_descriptions.push_back("\"" + item.text + "\"");
LOG(ERROR) << "Still waiting for expectation(s).\n" LOG(ERROR) << "Still waiting for expectation(s).\n"
<< "Unsatisfied expectations...\n" << "Unsatisfied expectations...\n"
<< base::JoinString(replay_queue_descriptions, "\n") << "\n\n\n" << base::JoinString(replay_queue_descriptions, "\n") << "\n\n"
<< "pending speech utterances...\n"
<< base::JoinString(utterance_queue_descriptions, "\n") << "\n\n"
<< "Satisfied expectations...\n" << "Satisfied expectations...\n"
<< base::JoinString(replayed_queue_, "\n"); << base::JoinString(replayed_queue_, "\n");
} }
......
...@@ -55,17 +55,21 @@ class SpeechMonitor : public content::TtsPlatform { ...@@ -55,17 +55,21 @@ class SpeechMonitor : public content::TtsPlatform {
// Non-blocking api. // Non-blocking api.
// Use these apis if you want to write an async test e.g. // Use these apis if you want to write an async test e.g.
// speech_monitor_.ExpectSpeech("foo") // sm_.ExpectSpeech("foo");
// .Call([this]() { DoSomething(); }) // sm_.Call([this]() { DoSomething(); })
// .Replay(); // sm_.Replay();
// Adds an expectation of spoken text. // Adds an expectation of spoken text.
SpeechMonitor& ExpectSpeech(const std::string& text); void ExpectSpeech(const std::string& text,
SpeechMonitor& ExpectSpeechPattern(const std::string& pattern); const base::Location& location = FROM_HERE);
SpeechMonitor& ExpectNextSpeechIsNot(const std::string& text); void ExpectSpeechPattern(const std::string& pattern,
const base::Location& location = FROM_HERE);
void ExpectNextSpeechIsNot(const std::string& text,
const base::Location& location = FROM_HERE);
// Adds a call to be included in replay. // Adds a call to be included in replay.
SpeechMonitor& Call(std::function<void()> func); void Call(std::function<void()> func,
const base::Location& location = FROM_HERE);
// Replays all expectations. // Replays all expectations.
void Replay(); void Replay();
......
...@@ -49,7 +49,7 @@ class LoggedInSpokenFeedbackTest : public InProcessBrowserTest { ...@@ -49,7 +49,7 @@ class LoggedInSpokenFeedbackTest : public InProcessBrowserTest {
void PressRepeatedlyUntilUtterance(ui::KeyboardCode key, void PressRepeatedlyUntilUtterance(ui::KeyboardCode key,
const std::string& expected_utterance); const std::string& expected_utterance);
SpeechMonitor speech_monitor_; SpeechMonitor sm_;
private: private:
StubBrailleController braille_controller_; StubBrailleController braille_controller_;
......
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