Commit 41d310d7 authored by dpapad's avatar dpapad Committed by Commit Bot

Downloads WebUI: Rename ActionService to SearchService.

This is a follow up from r492869 which reduced the responsibilities of
ActionService to only contain search related logic.

Bug: 752319
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: I81452d2ada95ed1ef4478f93961b8467b4724cb8
Reviewed-on: https://chromium-review.googlesource.com/610822Reviewed-by: default avatarScott Chen <scottchen@chromium.org>
Commit-Queue: Demetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#501144}
parent 5851f75e
......@@ -149,8 +149,6 @@
</then>
<else>
<include name="IDR_MD_DOWNLOADS_DOWNLOADS_HTML" file="resources\md_downloads\downloads.html" flattenhtml="true" allowexternalscript="true" type="BINDATA" />
<include name="IDR_MD_DOWNLOADS_ACTION_SERVICE_HTML" file="resources\md_downloads\action_service.html" type="BINDATA" />
<include name="IDR_MD_DOWNLOADS_ACTION_SERVICE_JS" file="resources\md_downloads\action_service.js" type="BINDATA" />
<include name="IDR_MD_DOWNLOADS_BROWSER_PROXY_HTML" file="resources\md_downloads\browser_proxy.html" type="BINDATA" />
<include name="IDR_MD_DOWNLOADS_BROWSER_PROXY_JS" file="resources\md_downloads\browser_proxy.js" type="BINDATA" />
<include name="IDR_MD_DOWNLOADS_CONSTANTS_HTML" file="resources\md_downloads\constants.html" type="BINDATA" />
......@@ -162,6 +160,8 @@
<include name="IDR_MD_DOWNLOADS_ITEM_JS" file="resources\md_downloads\item.js" type="BINDATA" />
<include name="IDR_MD_DOWNLOADS_MANAGER_HTML" file="resources\md_downloads\manager.html" type="BINDATA" />
<include name="IDR_MD_DOWNLOADS_MANAGER_JS" file="resources\md_downloads\manager.js" type="BINDATA" />
<include name="IDR_MD_DOWNLOADS_SEARCH_SERVICE_HTML" file="resources\md_downloads\search_service.html" type="BINDATA" />
<include name="IDR_MD_DOWNLOADS_SEARCH_SERVICE_JS" file="resources\md_downloads\search_service.js" type="BINDATA" />
<include name="IDR_MD_DOWNLOADS_TOOLBAR_HTML" file="resources\md_downloads\toolbar.html" type="BINDATA" />
<include name="IDR_MD_DOWNLOADS_TOOLBAR_JS" file="resources\md_downloads\toolbar.js" type="BINDATA" />
</else>
......
......@@ -3,15 +3,6 @@
# found in the LICENSE file.
{
'targets': [
{
'target_name': 'action_service',
'dependencies': [
'<(DEPTH)/ui/webui/resources/js/compiled_resources2.gyp:cr',
'<(DEPTH)/ui/webui/resources/js/compiled_resources2.gyp:load_time_data',
'browser_proxy',
],
'includes': ['../../../../third_party/closure_compiler/compile_js2.gypi'],
},
{
'target_name': 'browser_proxy',
'dependencies': [
......@@ -58,15 +49,24 @@
'<(DEPTH)/ui/webui/resources/js/cr/compiled_resources2.gyp:ui',
'<(DEPTH)/ui/webui/resources/js/cr/ui/compiled_resources2.gyp:command',
'<(DEPTH)/third_party/polymer/v1_0/components-chromium/iron-list/compiled_resources2.gyp:iron-list-extracted',
'action_service',
'browser_proxy',
'item',
'search_service',
'toolbar',
'<(EXTERNS_GYP):chrome_send',
'externs',
],
'includes': ['../../../../third_party/closure_compiler/compile_js2.gypi'],
},
{
'target_name': 'search_service',
'dependencies': [
'<(DEPTH)/ui/webui/resources/js/compiled_resources2.gyp:cr',
'<(DEPTH)/ui/webui/resources/js/compiled_resources2.gyp:load_time_data',
'browser_proxy',
],
'includes': ['../../../../third_party/closure_compiler/compile_js2.gypi'],
},
{
'target_name': 'toolbar',
'dependencies': [
......@@ -76,8 +76,8 @@
'<(DEPTH)/ui/webui/resources/cr_elements/cr_toolbar/compiled_resources2.gyp:cr_toolbar',
'<(DEPTH)/third_party/polymer/v1_0/components-chromium/iron-a11y-announcer/compiled_resources2.gyp:iron-a11y-announcer-extracted',
'<(DEPTH)/third_party/polymer/v1_0/components-chromium/paper-menu/compiled_resources2.gyp:paper-menu-extracted',
'action_service',
'browser_proxy',
'search_service',
],
'includes': ['../../../../third_party/closure_compiler/compile_js2.gypi'],
},
......
......@@ -7,11 +7,11 @@
<link rel="import" href="chrome://resources/html/util.html">
<link rel="import" href="chrome://resources/polymer/v1_0/iron-a11y-announcer/iron-a11y-announcer.html">
<link rel="import" href="chrome://resources/polymer/v1_0/iron-list/iron-list.html">
<link rel="import" href="chrome://downloads/action_service.html">
<link rel="import" href="chrome://downloads/browser_proxy.html">
<link rel="import" href="chrome://downloads/constants.html">
<link rel="import" href="chrome://downloads/i18n_setup.html">
<link rel="import" href="chrome://downloads/item.html">
<link rel="import" href="chrome://downloads/search_service.html">
<link rel="import" href="chrome://downloads/toolbar.html">
<dom-module id="downloads-manager">
......
......@@ -58,8 +58,8 @@ cr.define('downloads', function() {
/** @private {?downloads.BrowserProxy} */
browserProxy_: null,
/** @private {?downloads.ActionService} */
actionService_: null,
/** @private {?downloads.SearchService} */
searchService_: null,
/** @private {!PromiseResolver} */
loaded_: new PromiseResolver,
......@@ -67,7 +67,7 @@ cr.define('downloads', function() {
/** @override */
created: function() {
this.browserProxy_ = downloads.BrowserProxy.getInstance();
this.actionService_ = downloads.ActionService.getInstance();
this.searchService_ = downloads.SearchService.getInstance();
},
/** @override */
......@@ -167,7 +167,7 @@ cr.define('downloads', function() {
const list = this.$['downloads-list'];
if (list.scrollHeight - list.scrollTop - list.offsetHeight <= 100) {
// Approaching the end of the scrollback. Attempt to load more items.
this.actionService_.loadMore();
this.searchService_.loadMore();
}
this.hasShadow_ = list.scrollTop > 0;
},
......@@ -181,13 +181,13 @@ cr.define('downloads', function() {
document.addEventListener('canExecute', this.onCanExecute_.bind(this));
document.addEventListener('command', this.onCommand_.bind(this));
this.actionService_.loadMore();
this.searchService_.loadMore();
return this.loaded_.promise;
},
/** @private */
onSearchChanged_: function() {
this.inSearchMode_ = this.actionService_.isSearching();
this.inSearchMode_ = this.searchService_.isSearching();
},
/**
......
<link rel="import" href="chrome://resources/html/cr.html">
<link rel="import" href="chrome://downloads/i18n_setup.html">
<link rel="import" href="chrome://downloads/browser_proxy.html">
<script src="chrome://downloads/action_service.js"></script>
<script src="chrome://downloads/search_service.js"></script>
......@@ -3,8 +3,7 @@
// found in the LICENSE file.
cr.define('downloads', function() {
// TODO(dpapad): Rename to SearchService.
class ActionService {
class SearchService {
constructor() {
/** @private {!Array<string>} */
this.searchTerms_ = [];
......@@ -48,7 +47,7 @@ cr.define('downloads', function() {
* @return {boolean} Whether |searchText| resulted in new search terms.
*/
search(searchText) {
const searchTerms = ActionService.splitTerms(searchText);
const searchTerms = SearchService.splitTerms(searchText);
let sameTerms = searchTerms.length == this.searchTerms_.length;
for (let i = 0; sameTerms && i < searchTerms.length; ++i) {
......@@ -65,7 +64,7 @@ cr.define('downloads', function() {
}
}
cr.addSingletonGetter(ActionService);
cr.addSingletonGetter(SearchService);
return {ActionService: ActionService};
return {SearchService: SearchService};
});
......@@ -10,36 +10,36 @@ function str(list) {
return JSON.stringify(list);
}
var ActionServiceUnitTest = class extends testing.Test {
var SearchServiceUnitTest = class extends testing.Test {
/** @override */
get extraLibraries() {
return [
'../../../../ui/webui/resources/js/cr.js',
'browser_proxy.js',
'action_service.js',
'search_service.js',
];
}
}
TEST_F('ActionServiceUnitTest', 'splitTerms', function() {
const ActionService = downloads.ActionService;
assertEquals(str([]), str(ActionService.splitTerms('')));
assertEquals(str([]), str(ActionService.splitTerms(' ')));
assertEquals(str(['a']), str(ActionService.splitTerms('a')));
assertEquals(str(['a b']), str(ActionService.splitTerms('a b')));
assertEquals(str(['a', 'b']), str(ActionService.splitTerms('a "b"')));
assertEquals(str(['a', 'b', 'c']), str(ActionService.splitTerms('a "b" c')));
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(ActionService.splitTerms('a "b b" c')));
str(SearchService.splitTerms('a "b b" c')));
});
TEST_F('ActionServiceUnitTest', 'searchWithSimilarTerms', function() {
class TestActionService extends downloads.ActionService {
TEST_F('SearchServiceUnitTest', 'searchWithSimilarTerms', function() {
class TestSearchService extends downloads.SearchService {
loadMore() { /* No chrome.send() for you! */ }
}
const actionService = new TestActionService();
const searchService = new TestSearchService();
assertTrue(actionService.search('a'));
assertFalse(actionService.search('a ')); // Same term + space should no-op.
assertTrue(searchService.search('a'));
assertFalse(searchService.search('a ')); // Same term + space should no-op.
});
<link rel="import" href="chrome://resources/html/polymer.html">
<link rel="import" href="chrome://downloads/action_service.html">
<link rel="import" href="chrome://downloads/search_service.html">
<link rel="import" href="chrome://downloads/browser_proxy.html">
<link rel="import" href="chrome://resources/cr_elements/hidden_style_css.html">
<link rel="import" href="chrome://resources/html/assert.html">
......
......@@ -69,9 +69,9 @@ cr.define('downloads', function() {
* @private
*/
onSearchChanged_: function(event) {
const actionService = downloads.ActionService.getInstance();
if (actionService.search(/** @type {string} */ (event.detail)))
this.spinnerActive = actionService.isSearching();
const searchService = downloads.SearchService.getInstance();
if (searchService.search(/** @type {string} */ (event.detail)))
this.spinnerActive = searchService.isSearching();
this.updateClearAll_();
},
......
......@@ -114,10 +114,6 @@ content::WebUIDataSource* CreateDownloadsUIHTMLSource(Profile* profile) {
source->AddResourcePath("crisper.js", IDR_MD_DOWNLOADS_CRISPER_JS);
source->SetDefaultResource(IDR_MD_DOWNLOADS_VULCANIZED_HTML);
#else
source->AddResourcePath("action_service.html",
IDR_MD_DOWNLOADS_ACTION_SERVICE_HTML);
source->AddResourcePath("action_service.js",
IDR_MD_DOWNLOADS_ACTION_SERVICE_JS);
source->AddResourcePath("browser_proxy.html",
IDR_MD_DOWNLOADS_BROWSER_PROXY_HTML);
source->AddResourcePath("browser_proxy.js",
......@@ -131,6 +127,10 @@ content::WebUIDataSource* CreateDownloadsUIHTMLSource(Profile* profile) {
source->AddResourcePath("item.js", IDR_MD_DOWNLOADS_ITEM_JS);
source->AddResourcePath("manager.html", IDR_MD_DOWNLOADS_MANAGER_HTML);
source->AddResourcePath("manager.js", IDR_MD_DOWNLOADS_MANAGER_JS);
source->AddResourcePath("search_service.html",
IDR_MD_DOWNLOADS_SEARCH_SERVICE_HTML);
source->AddResourcePath("search_service.js",
IDR_MD_DOWNLOADS_SEARCH_SERVICE_JS);
source->AddResourcePath("toolbar.html", IDR_MD_DOWNLOADS_TOOLBAR_HTML);
source->AddResourcePath("toolbar.js", IDR_MD_DOWNLOADS_TOOLBAR_JS);
source->SetDefaultResource(IDR_MD_DOWNLOADS_DOWNLOADS_HTML);
......
......@@ -140,17 +140,17 @@ js2gtest("browser_tests_js_webui") {
js2gtest("unit_tests_js") {
test_type = "unit"
sources = [
"../../../browser/resources/md_downloads/action_service_unittest.gtestjs",
"../../../browser/resources/md_downloads/search_service_unittest.gtestjs",
"../../../browser/resources/print_preview/data/measurement_system_unittest.gtestjs",
"../../../browser/resources/print_preview/print_preview_utils_unittest.gtestjs",
"../../../renderer/resources/extensions/notifications_custom_bindings.gtestjs",
"../unit/framework_unittest.gtestjs",
]
extra_js_files = [
"../../../browser/resources/md_downloads/action_service.js",
"../../../browser/resources/md_downloads/browser_proxy.js",
"../../../browser/resources/print_preview/data/measurement_system.js",
"../../../browser/resources/print_preview/print_preview_utils.js",
"../../../browser/resources/md_downloads/search_service.js",
"../../../renderer/resources/extensions/notifications_custom_bindings.js",
"../../../renderer/resources/extensions/notifications_test_util.js",
"//ui/webui/resources/js/cr.js",
......
......@@ -7,12 +7,12 @@ suite('toolbar tests', function() {
let toolbar;
setup(function() {
class TestActionService extends downloads.ActionService {
class TestSearchService extends downloads.SearchService {
loadMore() { /* Prevent chrome.send(). */ }
}
toolbar = document.createElement('downloads-toolbar');
downloads.ActionService.instance_ = new TestActionService;
downloads.SearchService.instance_ = new TestSearchService;
document.body.appendChild(toolbar);
});
......
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