blob: f0d207d04147c60f17075118321cdf5f37d5ba35 [file] [log] [blame]
// Copyright 2015 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.
/**
* @param {!Array<string>} list
* @return {string}
*/
function str(list) {
return JSON.stringify(list);
}
var SearchServiceUnitTest = class extends testing.Test {
/** @override */
get extraLibraries() {
return [
'../../../../ui/webui/resources/js/cr.js',
'browser_proxy.js',
'search_service.js',
];
}
}
TEST_F('SearchServiceUnitTest', 'splitTerms', function() {
const SearchService = downloads.SearchService;
assertEquals(str([]), str(SearchService.splitTerms('')));
assertEquals(str([]), str(SearchService.splitTerms(' ')));
assertEquals(str(['a']), str(SearchService.splitTerms('a')));
assertEquals(str(['a b']), str(SearchService.splitTerms('a b')));
assertEquals(str(['a', 'b']), str(SearchService.splitTerms('a "b"')));
assertEquals(str(['a', 'b', 'c']), str(SearchService.splitTerms('a "b" c')));
assertEquals(str(['a', 'b b', 'c']),
str(SearchService.splitTerms('a "b b" c')));
});
TEST_F('SearchServiceUnitTest', 'searchWithSimilarTerms', function() {
// TODO(calamity): Replace this with an downloads.mojom.PageHandlerProxy()
// once we can include generated files from inside a gtestjs.
downloads.BrowserProxy.instance_ = {handler: {}};
class TestSearchService extends downloads.SearchService {
loadMore() { /* Remove call to backend. */ }
}
const searchService = new TestSearchService();
assertTrue(searchService.search('a'));
assertFalse(searchService.search('a ')); // Same term + space should no-op.
});