blob: c847e03f7f7a1564da19a4d18945267e621bab77 [file] [log] [blame]
// 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 test fixture.
GEN_INCLUDE(['../../testing/chromevox_next_e2e_test_base.js']);
GEN_INCLUDE(['../../testing/mock_tts.js']);
/**
* Test fixture for Background.
* @constructor
* @extends {ChromeVoxNextE2ETest}
*/
function BackgroundTest() {}
BackgroundTest.prototype = {
__proto__: ChromeVoxNextE2ETest.prototype,
/** @override */
setUp: function() {
this.mockTts = new MockTts();
cvox.ChromeVox.tts = this.mockTts;
}
};
/** Tests that ChromeVox classic is in this context. */
SYNC_TEST_F('BackgroundTest', 'ClassicNamespaces', function() {
assertEquals('object', typeof(cvox));
assertEquals('function', typeof(cvox.ChromeVoxBackground));
});
/** Tests that ChromeVox next is in this context. */
SYNC_TEST_F('BackgroundTest', 'NextNamespaces', function() {
assertEquals('function', typeof(Background));
});
/** Tests that ChromeVox reads the desktop tree. */
TEST_F('BackgroundTest', 'DesktopFocus', function() {
function findStatusTray(root) {
if (root.role == chrome.automation.RoleType.button &&
root.attributes.name &&
root.attributes.name.indexOf('Status tray') != -1) {
return root;
}
for (var i = 0; i < root.children().length; i++) {
var found = findStatusTray(root.children()[i]);
if (found)
return found;
}
return null;
}
chrome.automation.getDesktop(function(root) {
var testButton = findStatusTray(root);
cvox.ChromeVox.tts.expectSpeech('Status tray', testDone);
testButton.focus();
});
});
/** Tests feedback once a page loads. */
TEST_F('BackgroundTest', 'InitialFeedback', function() {
this.runWithDocument(function() {/*!
<p>start
<p>end
*/},
function() {
cvox.ChromeVox.tts.expectSpeech('start', function() {
global.backgroundObj.onGotCommand('nextLine');
});
cvox.ChromeVox.tts.expectSpeech('end', testDone);
}.bind(this));
});
/** Tests consistency of navigating forward and backward. */
TEST_F('BackgroundTest', 'ForwardBackwardNavigation', function() {
this.runWithDocument(function() {/*!
<p>start</p>
<a href='#a'>alpha</a>
<a href='#b'>beta</a>
<p>
<h1>charlie</h1>
<a href='foo'>delta</a>
</p>
<a href='#bar'>echo</a>
<h2>foxtraut</h2>
<p>end<span>of test</span></p>
*/},
function() {
var doCmd = function(cmd) {
return function() {
global.backgroundObj.onGotCommand(cmd);
};
};
var expectAfter =
cvox.ChromeVox.tts.expectSpeechAfter.bind(cvox.ChromeVox.tts);
cvox.ChromeVox.tts.expectSpeech('start');
expectAfter('alpha', doCmd('nextLink'));
expectAfter('beta', doCmd('nextLink'));
expectAfter('delta', doCmd('nextLink'));
expectAfter('beta', doCmd('previousLink'));
expectAfter('charlie', doCmd('nextHeading'));
expectAfter('foxtraut', doCmd('nextHeading'));
expectAfter('charlie', doCmd('previousHeading'));
expectAfter('delta', doCmd('nextElement'));
expectAfter('echo', doCmd('nextElement'));
expectAfter('foxtraut', doCmd('nextElement'));
expectAfter('end', doCmd('nextElement'));
expectAfter('foxtraut', doCmd('previousElement'));
// TODO(dtseng): cleanup these utterances.
expectAfter(', end, paragraph, of test, paragraph', doCmd('nextLine'));
expectAfter('start', doCmd('goToBeginning'));
expectAfter('of test', doCmd('goToEnd'));
cvox.ChromeVox.tts.finishExpectations();
}.bind(this));
});