Add test for ChromeVox injection into webview

TEST=browser_tests
BUG=342546

Review URL: https://codereview.chromium.org/153263006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@251148 0039d316-1c4b-4281-b951-d872f2087c98
parent afbd9d0e
......@@ -32,6 +32,11 @@
#include "net/test/embedded_test_server/http_response.h"
#include "ui/gl/gl_switches.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
#include "chrome/browser/chromeos/accessibility/speech_monitor.h"
#endif
// For fine-grained suppression on flaky tests.
#if defined(OS_WIN)
#include "base/win/windows_version.h"
......@@ -1545,6 +1550,26 @@ IN_PROC_BROWSER_TEST_F(WebViewTest, SpeechRecognition) {
EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle());
}
#if defined(OS_CHROMEOS)
IN_PROC_BROWSER_TEST_F(WebViewTest, ChromeVoxInjection) {
EXPECT_FALSE(
chromeos::AccessibilityManager::Get()->IsSpokenFeedbackEnabled());
ASSERT_TRUE(StartEmbeddedTestServer());
content::WebContents* guest_web_contents = LoadGuest(
"/extensions/platform_apps/web_view/chromevox_injection/guest.html",
"web_view/chromevox_injection");
ASSERT_TRUE(guest_web_contents);
chromeos::SpeechMonitor monitor;
chromeos::AccessibilityManager::Get()->EnableSpokenFeedback(
true, ash::A11Y_NOTIFICATION_NONE);
EXPECT_TRUE(monitor.SkipChromeVoxEnabledMessage());
EXPECT_EQ("chrome vox test title", monitor.GetNextUtterance());
}
#endif
// Flaky on Windows. http://crbug.com/303966
#if defined(OS_WIN)
#define MAYBE_TearDownTest DISABLED_TearDownTest
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/accessibility/speech_monitor.h"
namespace chromeos {
namespace {
const char kChromeVoxEnabledMessage[] = "chrome vox spoken feedback is ready";
} // anonymous namespace
SpeechMonitor::SpeechMonitor() {
TtsController::GetInstance()->SetPlatformImpl(this);
}
SpeechMonitor::~SpeechMonitor() {
TtsController::GetInstance()->SetPlatformImpl(TtsPlatformImpl::GetInstance());
}
std::string SpeechMonitor::GetNextUtterance() {
if (utterance_queue_.empty()) {
loop_runner_ = new content::MessageLoopRunner();
loop_runner_->Run();
loop_runner_ = NULL;
}
std::string result = utterance_queue_.front();
utterance_queue_.pop_front();
return result;
}
bool SpeechMonitor::SkipChromeVoxEnabledMessage() {
return GetNextUtterance() == kChromeVoxEnabledMessage;
}
bool SpeechMonitor::PlatformImplAvailable() {
return true;
}
bool SpeechMonitor::Speak(
int utterance_id,
const std::string& utterance,
const std::string& lang,
const VoiceData& voice,
const UtteranceContinuousParameters& params) {
TtsController::GetInstance()->OnTtsEvent(
utterance_id,
TTS_EVENT_END,
static_cast<int>(utterance.size()),
std::string());
return true;
}
bool SpeechMonitor::StopSpeaking() {
return true;
}
bool SpeechMonitor::IsSpeaking() {
return false;
}
void SpeechMonitor::GetVoices(std::vector<VoiceData>* out_voices) {
out_voices->push_back(VoiceData());
VoiceData& voice = out_voices->back();
voice.native = true;
voice.name = "SpeechMonitor";
voice.events.insert(TTS_EVENT_END);
}
std::string SpeechMonitor::error() {
return "";
}
void SpeechMonitor::WillSpeakUtteranceWithVoice(const Utterance* utterance,
const VoiceData& voice_data) {
utterance_queue_.push_back(utterance->text());
if (loop_runner_.get())
loop_runner_->Quit();
}
} // namespace chromeos
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_ACCESSIBILITY_SPEECH_MONITOR_H_
#define CHROME_BROWSER_CHROMEOS_ACCESSIBILITY_SPEECH_MONITOR_H_
#include <deque>
#include "base/memory/ref_counted.h"
#include "chrome/browser/speech/tts_platform.h"
#include "content/public/test/test_utils.h"
namespace chromeos {
// For testing purpose installs itself as the platform speech synthesis engine,
// allowing it to intercept all speech calls, and then provides a method to
// block until the next utterance is spoken.
class SpeechMonitor : public TtsPlatformImpl {
public:
SpeechMonitor();
virtual ~SpeechMonitor();
// Blocks until the next utterance is spoken, and returns its text.
std::string GetNextUtterance();
// Wait for next utterance and return true if next utterance is ChromeVox
// enabled message.
bool SkipChromeVoxEnabledMessage();
// TtsPlatformImpl implementation.
virtual bool PlatformImplAvailable() OVERRIDE;
virtual bool Speak(
int utterance_id,
const std::string& utterance,
const std::string& lang,
const VoiceData& voice,
const UtteranceContinuousParameters& params) OVERRIDE;
virtual bool StopSpeaking() OVERRIDE;
virtual bool IsSpeaking() OVERRIDE;
virtual void GetVoices(std::vector<VoiceData>* out_voices) OVERRIDE;
virtual void Pause() OVERRIDE {}
virtual void Resume() OVERRIDE {}
virtual std::string error() OVERRIDE;
virtual void clear_error() OVERRIDE {}
virtual void set_error(const std::string& error) OVERRIDE {}
virtual void WillSpeakUtteranceWithVoice(
const Utterance* utterance, const VoiceData& voice_data) OVERRIDE;
private:
scoped_refptr<content::MessageLoopRunner> loop_runner_;
std::deque<std::string> utterance_queue_;
DISALLOW_COPY_AND_ASSIGN(SpeechMonitor);
};
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_ACCESSIBILITY_SPEECH_MONITOR_H_
......@@ -8,6 +8,7 @@
#include "base/strings/string_util.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
#include "chrome/browser/chromeos/accessibility/speech_monitor.h"
#include "chrome/browser/chromeos/login/login_display_host.h"
#include "chrome/browser/chromeos/login/login_display_host_impl.h"
#include "chrome/browser/chromeos/login/user_manager.h"
......@@ -33,86 +34,6 @@ using extensions::api::braille_display_private::StubBrailleController;
namespace chromeos {
namespace {
const char kChromeVoxEnabledMessage[] = "chrome vox spoken feedback is ready";
} // anonymous namespace
// Installs itself as the platform speech synthesis engine, allowing it to
// intercept all speech calls, and then provides a method to block until the
// next utterance is spoken.
class SpeechMonitor : public TtsPlatformImpl {
public:
SpeechMonitor();
virtual ~SpeechMonitor();
// Blocks until the next utterance is spoken, and returns its text.
std::string GetNextUtterance();
// TtsPlatformImpl implementation.
virtual bool PlatformImplAvailable() OVERRIDE { return true; }
virtual bool Speak(
int utterance_id,
const std::string& utterance,
const std::string& lang,
const VoiceData& voice,
const UtteranceContinuousParameters& params) OVERRIDE {
TtsController::GetInstance()->OnTtsEvent(
utterance_id,
TTS_EVENT_END,
static_cast<int>(utterance.size()),
std::string());
return true;
}
virtual bool StopSpeaking() OVERRIDE { return true; }
virtual bool IsSpeaking() OVERRIDE { return false; }
virtual void GetVoices(std::vector<VoiceData>* out_voices) OVERRIDE {
out_voices->push_back(VoiceData());
VoiceData& voice = out_voices->back();
voice.native = true;
voice.name = "SpeechMonitor";
voice.events.insert(TTS_EVENT_END);
}
virtual void Pause() OVERRIDE {}
virtual void Resume() OVERRIDE {}
virtual std::string error() OVERRIDE { return ""; }
virtual void clear_error() OVERRIDE {}
virtual void set_error(const std::string& error) OVERRIDE {}
virtual void WillSpeakUtteranceWithVoice(
const Utterance* utterance, const VoiceData& voice_data) OVERRIDE;
private:
scoped_refptr<content::MessageLoopRunner> loop_runner_;
std::deque<std::string> utterance_queue_;
DISALLOW_COPY_AND_ASSIGN(SpeechMonitor);
};
SpeechMonitor::SpeechMonitor() {
TtsController::GetInstance()->SetPlatformImpl(this);
}
SpeechMonitor::~SpeechMonitor() {
TtsController::GetInstance()->SetPlatformImpl(TtsPlatformImpl::GetInstance());
}
void SpeechMonitor::WillSpeakUtteranceWithVoice(const Utterance* utterance,
const VoiceData& voice_data) {
utterance_queue_.push_back(utterance->text());
if (loop_runner_.get())
loop_runner_->Quit();
}
std::string SpeechMonitor::GetNextUtterance() {
if (utterance_queue_.empty()) {
loop_runner_ = new content::MessageLoopRunner();
loop_runner_->Run();
loop_runner_ = NULL;
}
std::string result = utterance_queue_.front();
utterance_queue_.pop_front();
return result;
}
//
// Spoken feedback tests in a normal browser window.
//
......@@ -141,7 +62,7 @@ IN_PROC_BROWSER_TEST_F(SpokenFeedbackTest, EnableSpokenFeedback) {
SpeechMonitor monitor;
AccessibilityManager::Get()->EnableSpokenFeedback(
true, ash::A11Y_NOTIFICATION_NONE);
EXPECT_EQ(kChromeVoxEnabledMessage, monitor.GetNextUtterance());
EXPECT_TRUE(monitor.SkipChromeVoxEnabledMessage());
}
IN_PROC_BROWSER_TEST_F(SpokenFeedbackTest, FocusToolbar) {
......@@ -150,7 +71,7 @@ IN_PROC_BROWSER_TEST_F(SpokenFeedbackTest, FocusToolbar) {
SpeechMonitor monitor;
AccessibilityManager::Get()->EnableSpokenFeedback(
true, ash::A11Y_NOTIFICATION_NONE);
EXPECT_EQ(kChromeVoxEnabledMessage, monitor.GetNextUtterance());
EXPECT_TRUE(monitor.SkipChromeVoxEnabledMessage());
chrome::ExecuteCommand(browser(), IDC_FOCUS_TOOLBAR);
// Might be "Google Chrome Toolbar" or "Chromium Toolbar".
......@@ -195,7 +116,7 @@ IN_PROC_BROWSER_TEST_F(OobeSpokenFeedbackTest, SpokenFeedbackInOobe) {
SpeechMonitor monitor;
AccessibilityManager::Get()->EnableSpokenFeedback(
true, ash::A11Y_NOTIFICATION_NONE);
EXPECT_EQ(kChromeVoxEnabledMessage, monitor.GetNextUtterance());
EXPECT_TRUE(monitor.SkipChromeVoxEnabledMessage());
EXPECT_EQ("Select your language:", monitor.GetNextUtterance());
EXPECT_EQ("English ( United States)", monitor.GetNextUtterance());
......
......@@ -423,6 +423,8 @@
}],
],
'sources': [
'browser/chromeos/accessibility/speech_monitor.cc',
'browser/chromeos/accessibility/speech_monitor.h',
'browser/chromeos/accessibility/spoken_feedback_browsertest.cc',
'browser/chromeos/accessibility/sticky_keys_browsertest.cc',
'browser/chromeos/input_method/textinput_browsertest.cc',
......@@ -1017,6 +1019,8 @@
'browser/chrome_switches_browsertest.cc',
'browser/chromeos/accessibility/accessibility_manager_browsertest.cc',
'browser/chromeos/accessibility/magnification_manager_browsertest.cc',
'browser/chromeos/accessibility/speech_monitor.cc',
'browser/chromeos/accessibility/speech_monitor.h',
'browser/chromeos/app_mode/kiosk_app_manager_browsertest.cc',
'browser/chromeos/app_mode/kiosk_app_update_service_browsertest.cc',
'browser/chromeos/attestation/attestation_policy_browsertest.cc',
......
<!doctype html>
<!--
* Copyright (c) 2014 The Chromium Authors. All rights reserved. Use of this
* source code is governed by a BSD-style license that can be found in the
* LICENSE file.
-->
<html>
<head>
<title>ChromeVox test title</title>
</head>
<body>
<div>Some text</div>
</body>
</html>
<!doctype html>
<!--
* Copyright (c) 2014 The Chromium Authors. All rights reserved. Use of this
* source code is governed by a BSD-style license that can be found in the
* LICENSE file.
-->
<html>
<body>
<div id="webview-tag-container"></div>
<script src="main.js"></script>
</body>
</html>
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var startTest = function() {
chrome.test.sendMessage('guest-loaded');
};
chrome.test.getConfig(function(config) {
var guestURL = 'http://localhost:' + config.testServer.port +
'/extensions/platform_apps/web_view/chromevox_injection/guest.html';
document.querySelector('#webview-tag-container').innerHTML =
'<webview style="width: 10px; height: 10px; margin: 0; padding: 0;"' +
' src="' + guestURL + '"' +
'></webview>';
startTest();
});
{
"name": "<webview> ChromeVox injection test.",
"version": "1",
"permissions": [
"webview"
],
"app": {
"background": {
"scripts": ["test.js"]
}
}
}
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
chrome.app.runtime.onLaunched.addListener(function() {
chrome.app.window.create('main.html', {}, function () {});
});
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