Commit 08c1c7a9 authored by Demetrios Papadopoulos's avatar Demetrios Papadopoulos Committed by Commit Bot

Downloads WebUI: Convert SearchServiceUnitTest to browser_tests.

This is in preparation of migrating to Polymer3. JS unit tests (V8UnitTest)
have no way currently of loading JS modules within a test context, since
they rely on a chrome://test data source that only exists in a
browser_tests context (WebUIBrowserTest).

Bug: 1022215
Change-Id: Ieb8caa155d3b83567160eb0927f43adbf548b153
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1918650
Auto-Submit: Demetrios Papadopoulos <dpapad@chromium.org>
Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Commit-Queue: Demetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#715582}
parent a8dd236d
// 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.
});
......@@ -248,7 +248,6 @@ js2gtest("browser_tests_js_mojo_lite_webui") {
js2gtest("unit_tests_js") {
test_type = "unit"
sources = [
"../../../browser/resources/downloads/search_service_unittest.gtestjs",
"../../../renderer/resources/extensions/notifications_custom_bindings.gtestjs",
"../unit/framework_unittest.gtestjs",
]
......
......@@ -122,3 +122,27 @@ TEST_F('DownloadsUrlTest', 'All', function() {
});
mocha.run();
});
/**
* @constructor
* @extends {DownloadsTest}
*/
function DownloadsSearchServiceTest() {}
DownloadsSearchServiceTest.prototype = {
__proto__: DownloadsTest.prototype,
/** @override */
browsePreload: 'chrome://downloads/manager.html',
/** @override */
extraLibraries: DownloadsTest.prototype.extraLibraries.concat([
'../test_browser_proxy.js',
'test_support.js',
'search_service_test.js',
]),
};
TEST_F('DownloadsSearchServiceTest', 'All', function() {
mocha.run();
});
// 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.
suite('search service tests', function() {
/**
* @param {!Array<string>} list
* @return {string}
*/
function str(list) {
return JSON.stringify(list);
}
test('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('searchWithSimilarTerms', function() {
downloads.BrowserProxy.instance_ = new TestDownloadsProxy();
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.
});
});
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