Commit a2c28438 authored by yawano's avatar yawano Committed by Commit bot

Handle sorted event.

BUG=438050
TEST=out/Release/browser_tests --gtest_filter=FileManagerJsTest.ListThumbnailLoader

Review URL: https://codereview.chromium.org/886503006

Cr-Commit-Position: refs/heads/master@{#314990}
parent cf7d082e
...@@ -10,16 +10,6 @@ ...@@ -10,16 +10,6 @@
* is responsible to return dataUrls of valid thumbnails and fetch them with * is responsible to return dataUrls of valid thumbnails and fetch them with
* proper priority. * proper priority.
* *
* TODOs
* The following list is a todo list for this class. This list will be deleted
* after all of them are implemented.
* * Done: Fetch thumbnails with range based priority control.
* * Done: Implement cache size limitation.
* * Done: Modest queueing for low priority thumbnail fetches.
* * Handle other event types of FileListModel, e.g. sort.
* * Done: Change ThumbnailLoader to directly return dataUrl.
* * Handle file types for which generic images are used.
*
* @param {!FileListModel} dataModel A file list model. * @param {!FileListModel} dataModel A file list model.
* @param {!MetadataCache} metadataCache Metadata cache. * @param {!MetadataCache} metadataCache Metadata cache.
* @param {!Document} document Document. * @param {!Document} document Document.
...@@ -89,8 +79,10 @@ function ListThumbnailLoader( ...@@ -89,8 +79,10 @@ function ListThumbnailLoader(
*/ */
this.cursor_ = 0; this.cursor_ = 0;
// TODO(yawano): Handle other event types of FileListModel, e.g. sort. // TODO(yawano): Change FileListModel to dispatch change event for file
// change, and change this class to handle it.
this.dataModel_.addEventListener('splice', this.onSplice_.bind(this)); this.dataModel_.addEventListener('splice', this.onSplice_.bind(this));
this.dataModel_.addEventListener('sorted', this.onSorted_.bind(this));
} }
ListThumbnailLoader.prototype.__proto__ = cr.EventTarget.prototype; ListThumbnailLoader.prototype.__proto__ = cr.EventTarget.prototype;
...@@ -125,6 +117,17 @@ ListThumbnailLoader.prototype.onSplice_ = function(event) { ...@@ -125,6 +117,17 @@ ListThumbnailLoader.prototype.onSplice_ = function(event) {
this.continue_(); this.continue_();
} }
/**
* An event handler for sorted event of data model. When list is sorted, start
* to rescan items.
*
* @param {!Event} event Event
*/
ListThumbnailLoader.prototype.onSorted_ = function(event) {
this.cursor_ = this.beginIndex_;
this.continue_();
}
/** /**
* Sets high priority range in the list. * Sets high priority range in the list.
* *
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
<script src="../../../../webui/resources/js/cr/ui.js"></script> <script src="../../../../webui/resources/js/cr/ui.js"></script>
<script src="../../../../webui/resources/js/cr/ui/array_data_model.js"></script> <script src="../../../../webui/resources/js/cr/ui/array_data_model.js"></script>
<script src="../../common/js/lru_cache.js"></script> <script src="../../common/js/lru_cache.js"></script>
<script src="../../common/js/util.js"></script>
<script src="../../common/js/mock_entry.js"></script> <script src="../../common/js/mock_entry.js"></script>
<script src="../../common/js/unittest_util.js"></script> <script src="../../common/js/unittest_util.js"></script>
<script src="directory_contents.js"></script> <script src="directory_contents.js"></script>
......
...@@ -242,3 +242,30 @@ function testErrorHandling(callback) { ...@@ -242,3 +242,30 @@ function testErrorHandling(callback) {
return !!getOneCallbacks[entry3.toURL()]; return !!getOneCallbacks[entry3.toURL()];
}), callback); }), callback);
} }
/**
* Test case for handling sorted event in data model.
*/
function testSortedEvent(callback) {
listThumbnailLoader.setHighPriorityRange(0, 2);
fileListModel.push(directory1, entry1, entry2, entry3, entry4, entry5);
resolveGetOneCallback(entry1.toURL());
resolveGetOneCallback(entry2.toURL());
assertEquals(0, Object.keys(getOneCallbacks).length);
// In order to assert that following task enqueues are fired by sorted event,
// wait until all thumbnail loads are completed.
reportPromise(waitUntil(function() {
return thumbnailLoadedEvents.length === 2;
}).then(function() {
// After the sort, list should be
// directory1, entry5, entry4, entry3, entry2, entry1.
fileListModel.sort('name', 'desc');
return waitUntil(function() {
return !!getOneCallbacks[entry5.toURL()] &&
!!getOneCallbacks[entry4.toURL()]
});
}), callback);
}
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