Commit ad2869c0 authored by Katie Dektar's avatar Katie Dektar Committed by Commit Bot

Adds integration / browser tests for Select-to-Speak.

Adds a function to SpeechMonitor to block until a stop
event is called. This will be used in later tests.

Bug: 789598
Change-Id: Id25069e60d472eed3bf363e9cf597d2fe07d91e2
Reviewed-on: https://chromium-review.googlesource.com/804415
Commit-Queue: Katie D <katie@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521379}
parent 60769e65
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include "base/strings/pattern.h" #include "base/strings/pattern.h"
#include "chrome/browser/chromeos/accessibility/accessibility_manager.h" #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
#include "chrome/browser/chromeos/accessibility/speech_monitor.h" #include "chrome/browser/chromeos/accessibility/speech_monitor.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/notification_details.h" #include "content/public/browser/notification_details.h"
...@@ -40,6 +42,20 @@ class SelectToSpeakTest : public InProcessBrowserTest { ...@@ -40,6 +42,20 @@ class SelectToSpeakTest : public InProcessBrowserTest {
SpeechMonitor speech_monitor_; SpeechMonitor speech_monitor_;
std::unique_ptr<ui::test::EventGenerator> generator_; std::unique_ptr<ui::test::EventGenerator> generator_;
void ActivateSelectToSpeakInWindowBounds(std::string url) {
ui_test_utils::NavigateToURL(browser(), GURL(url));
gfx::Rect bounds = browser()->window()->GetBounds();
// Hold down Search and click a few pixels into the window bounds.
generator_->PressKey(ui::VKEY_LWIN, 0 /* flags */);
generator_->MoveMouseTo(bounds.x() + 8, bounds.y() + 50);
generator_->PressLeftButton();
generator_->MoveMouseTo(bounds.x() + bounds.width() - 8,
bounds.y() + bounds.height() - 8);
generator_->ReleaseLeftButton();
generator_->ReleaseKey(ui::VKEY_LWIN, 0 /* flags */);
}
private: private:
DISALLOW_COPY_AND_ASSIGN(SelectToSpeakTest); DISALLOW_COPY_AND_ASSIGN(SelectToSpeakTest);
}; };
...@@ -59,4 +75,80 @@ IN_PROC_BROWSER_TEST_F(SelectToSpeakTest, SpeakStatusTray) { ...@@ -59,4 +75,80 @@ IN_PROC_BROWSER_TEST_F(SelectToSpeakTest, SpeakStatusTray) {
base::MatchPattern(speech_monitor_.GetNextUtterance(), "Status tray*")); base::MatchPattern(speech_monitor_.GetNextUtterance(), "Status tray*"));
} }
IN_PROC_BROWSER_TEST_F(SelectToSpeakTest, SearchLocksToSelectToSpeakMode) {
ui_test_utils::NavigateToURL(browser(), GURL("data:text/html;charset=utf-8,"
"<p>This is some text</p>"));
gfx::Rect bounds = browser()->window()->GetBounds();
// Hold click Search, then and click a few pixels into the window bounds.
generator_->PressKey(ui::VKEY_LWIN, 0 /* flags */);
generator_->ReleaseKey(ui::VKEY_LWIN, 0 /* flags */);
for (int i = 0; i < 2; ++i) {
// With the mouse only, have it speak a few times.
generator_->MoveMouseTo(bounds.x() + 8, bounds.y() + 50);
generator_->PressLeftButton();
generator_->MoveMouseTo(bounds.x() + bounds.width() - 8,
bounds.y() + bounds.height() - 8);
generator_->ReleaseLeftButton();
EXPECT_TRUE(base::MatchPattern(speech_monitor_.GetNextUtterance(),
"This is some text*"));
}
}
IN_PROC_BROWSER_TEST_F(SelectToSpeakTest, SmoothlyReadsAcrossInlineUrl) {
// Make sure an inline URL is read smoothly.
ActivateSelectToSpeakInWindowBounds(
"data:text/html;charset=utf-8,<p>This is some text <a href=>with a"
" node</a> in the middle");
// Should combine nodes in a paragraph into one utterance.
// Includes some wildcards between words because there may be extra
// spaces. Spaces are not pronounced, so extra spaces do not impact output.
EXPECT_TRUE(
base::MatchPattern(speech_monitor_.GetNextUtterance(),
"This is some text*with a node*in the middle*"));
}
IN_PROC_BROWSER_TEST_F(SelectToSpeakTest, SmoothlyReadsAcrossMultipleLines) {
// Sentences spanning multiple lines.
ActivateSelectToSpeakInWindowBounds(
"data:text/html;charset=utf-8,<div style=\"width:100px\">This"
" is some text with a node in the middle");
// Should combine nodes in a paragraph into one utterance.
// Includes some wildcards between words because there may be extra
// spaces, for example at line wraps. Extra wildcards included to
// reduce flakyness in case wrapping is not consistent.
// Spaces are not pronounced, so extra spaces do not impact output.
EXPECT_TRUE(
base::MatchPattern(speech_monitor_.GetNextUtterance(),
"This is some*text*with*a*node*in*the*middle*"));
}
IN_PROC_BROWSER_TEST_F(SelectToSpeakTest, SmoothlyReadsAcrossFormattedText) {
// Bold or formatted text
ActivateSelectToSpeakInWindowBounds(
"data:text/html;charset=utf-8,<p>This is some text <b>with a node"
"</b> in the middle");
// Should combine nodes in a paragraph into one utterance.
// Includes some wildcards between words because there may be extra
// spaces. Spaces are not pronounced, so extra spaces do not impact output.
EXPECT_TRUE(
base::MatchPattern(speech_monitor_.GetNextUtterance(),
"This is some text*with a node*in the middle*"));
}
IN_PROC_BROWSER_TEST_F(SelectToSpeakTest, BreaksAtParagraphBounds) {
ActivateSelectToSpeakInWindowBounds(
"data:text/html;charset=utf-8,<div><p>First paragraph</p>"
"<p>Second paragraph</p></div>");
// Should keep each paragraph as its own utterance.
EXPECT_TRUE(base::MatchPattern(speech_monitor_.GetNextUtterance(),
"First paragraph*"));
EXPECT_TRUE(base::MatchPattern(speech_monitor_.GetNextUtterance(),
"Second paragraph*"));
}
} // namespace chromeos } // namespace chromeos
...@@ -40,6 +40,14 @@ bool SpeechMonitor::DidStop() { ...@@ -40,6 +40,14 @@ bool SpeechMonitor::DidStop() {
return did_stop_; return did_stop_;
} }
void SpeechMonitor::BlockUntilStop() {
if (!did_stop_) {
loop_runner_ = new content::MessageLoopRunner();
loop_runner_->Run();
loop_runner_ = NULL;
}
}
bool SpeechMonitor::SkipChromeVoxMessage(const std::string& message) { bool SpeechMonitor::SkipChromeVoxMessage(const std::string& message) {
while (true) { while (true) {
if (utterance_queue_.empty()) { if (utterance_queue_.empty()) {
......
...@@ -32,6 +32,9 @@ class SpeechMonitor : public TtsPlatformImpl { ...@@ -32,6 +32,9 @@ class SpeechMonitor : public TtsPlatformImpl {
// Returns true if StopSpeaking() was called on TtsController. // Returns true if StopSpeaking() was called on TtsController.
bool DidStop(); bool DidStop();
// Blocks until StopSpeaking() is called on TtsController.
void BlockUntilStop();
private: private:
// TtsPlatformImpl implementation. // TtsPlatformImpl implementation.
bool PlatformImplAvailable() override; bool PlatformImplAvailable() override;
......
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