Commit 0ca3fa6a authored by David Tseng's avatar David Tseng Committed by Commit Bot

Reland: Include line numbers in SpeechMonitor async api

Fixed by

Suppress -Wpredefined-identifier-outside-function in SpeechMonitor

TBR=dtseng@chromium.org

Change-Id: I5e583e9b9c7c35778ca081ec7b3bd7e82da81af4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2121474Reviewed-by: default avatarDavid Tseng <dtseng@chromium.org>
Commit-Queue: David Tseng <dtseng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#753534}
parent 1decfe8a
......@@ -161,7 +161,8 @@ double SpeechMonitor::GetDelayForLastUtteranceMS() {
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());
replay_queue_.push_back({[this, text]() {
for (auto it = utterance_queue_.begin();
......@@ -176,11 +177,12 @@ SpeechMonitor& SpeechMonitor::ExpectSpeech(const std::string& text) {
}
return false;
},
"ExpectSpeech(\"" + text + "\")"});
return *this;
"ExpectSpeech(\"" + text + "\") " +
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());
replay_queue_.push_back({[this, pattern]() {
for (auto it = utterance_queue_.begin();
......@@ -195,30 +197,31 @@ SpeechMonitor& SpeechMonitor::ExpectSpeechPattern(const std::string& pattern) {
}
return false;
},
"ExpectSpeechPattern(\"" + pattern + "\")"});
return *this;
"ExpectSpeechPattern(\"" + pattern + "\") " +
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());
replay_queue_.push_back({[this, text]() {
replay_queue_.push_back(
{[this, text]() {
if (utterance_queue_.empty())
return false;
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());
replay_queue_.push_back({[func]() {
func();
return true;
},
"Call()"});
return *this;
"Call() " + location.ToString()});
}
void SpeechMonitor::Replay() {
......@@ -266,9 +269,15 @@ void SpeechMonitor::MaybePrintExpectations() {
for (const auto& pair : replay_queue_)
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"
<< "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"
<< base::JoinString(replayed_queue_, "\n");
}
......
......@@ -55,17 +55,26 @@ class SpeechMonitor : public content::TtsPlatform {
// Non-blocking api.
// Use these apis if you want to write an async test e.g.
// speech_monitor_.ExpectSpeech("foo")
// .Call([this]() { DoSomething(); })
// .Replay();
// sm_.ExpectSpeech("foo");
// sm_.Call([this]() { DoSomething(); })
// sm_.Replay();
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpredefined-identifier-outside-function"
// Adds an expectation of spoken text.
SpeechMonitor& ExpectSpeech(const std::string& text);
SpeechMonitor& ExpectSpeechPattern(const std::string& pattern);
SpeechMonitor& ExpectNextSpeechIsNot(const std::string& text);
void ExpectSpeech(const std::string& text,
const base::Location& location = FROM_HERE);
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.
SpeechMonitor& Call(std::function<void()> func);
void Call(std::function<void()> func,
const base::Location& location = FROM_HERE);
#pragma clang diagnostic pop
// Replays all expectations.
void Replay();
......
......@@ -49,7 +49,7 @@ class LoggedInSpokenFeedbackTest : public InProcessBrowserTest {
void PressRepeatedlyUntilUtterance(ui::KeyboardCode key,
const std::string& expected_utterance);
SpeechMonitor speech_monitor_;
SpeechMonitor sm_;
private:
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