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() { ...@@ -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,26 @@ class SpeechMonitor : public content::TtsPlatform { ...@@ -55,17 +55,26 @@ 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();
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpredefined-identifier-outside-function"
// 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);
#pragma clang diagnostic pop
// 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