blob: 9f004358c35cb2bcf52f2ed32fdc317fe394832a [file] [log] [blame]
// Copyright 2016 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']);
/**
* Test fixture for ISearch.
* @constructor
* @extends {ChromeVoxNextE2ETest}
*/
function ChromeVoxISearchTest() {
ChromeVoxNextE2ETest.call(this);
}
ChromeVoxISearchTest.prototype = {
__proto__: ChromeVoxNextE2ETest.prototype,
/** @override */
runtimeDeps: ['ISearch', 'ISearchHandler'],
linksAndHeadingsDoc: function() {/*!
<p>start</p>
<a href='#a'>Home</a>
<a href='#b'>About US</a>
<p>
<h1>Latest Breaking News</h1>
<a href='foo'>See more...</a>
</p>
<a href='#bar'>Questions?</a>
<h2>Privacy Policy</h2>
<p>end<span>of test</span></p>
*/}
};
/**
* @implements {ISearchHandler}
* @constructor
*/
function FakeISearchHandler(testObj) {
this.test = testObj;
this.expect_ = [];
}
FakeISearchHandler.prototype = {
/** @override */
onSearchReachedBoundary: function(boundaryNode) {
this.expect_.shift()(boundaryNode, true);
},
onSearchResultChanged: function(node) {
this.expect_.shift()(node);
},
expect: function(str, opt_callback) {
this.expect_.push(this.test.newCallback(function(node, isBound) {
var actual = node.name || node.role;
if (isBound)
actual = 'boundary=' + actual;
assertEquals(str, actual);
opt_callback && opt_callback();
}));
}
};
TEST_F('ChromeVoxISearchTest', 'DISABLED_Simple', function() {
this.runWithLoadedTree(this.linksAndHeadingsDoc, function(rootNode) {
var handler = new FakeISearchHandler(this);
var search = new ISearch(rootNode);
search.handler = handler;
// Simple forward search.
search.search('US', 'forward');
handler.expect('About US',
search.search.bind(search, 'start', 'backward'));
handler.expect('start',
// Boundary (beginning).
search.search.bind(search, 'foo', 'backward'));
handler.expect('boundary=start',
// Boundary (end).
search.search.bind(search, 'foo', 'forward'));
// Search "focus" doesn't move.
handler.expect('boundary=start',
// Mixed case substring.
search.search.bind(search, 'bReak', 'forward'));
handler.expect('Latest Breaking News',
search.search.bind(search, 'bReak', 'forward'));
handler.expect('boundary=Latest Breaking News');
});
});