Commit 454a4f0c authored by Noel Gordon's avatar Noel Gordon Committed by Commit Bot

Closure compile list_thumbnail_loader_unittest

 - remove list_thumbnail_loader_unittest.html
 - add BUILD rules to auto-generate and compile this unittest
 - add @types to the unittest vars
 - inline the canvas dataURL image creation step in Setup()
 - fix all Closure compiler errors

No change in test behavior, no new tests.

Bug: 912557
Change-Id: I157b0c1ef56704901e760e6f5125e4e05ea76377
Reviewed-on: https://chromium-review.googlesource.com/c/1364999
Commit-Queue: Stuart Langley <slangley@chromium.org>
Reviewed-by: default avatarStuart Langley <slangley@chromium.org>
Cr-Commit-Position: refs/heads/master@{#614362}
parent 15bf6880
...@@ -119,8 +119,7 @@ IN_PROC_BROWSER_TEST_F(FileManagerJsTest, MultiMetadataProvider) { ...@@ -119,8 +119,7 @@ IN_PROC_BROWSER_TEST_F(FileManagerJsTest, MultiMetadataProvider) {
} }
IN_PROC_BROWSER_TEST_F(FileManagerJsTest, ListThumbnailLoader) { IN_PROC_BROWSER_TEST_F(FileManagerJsTest, ListThumbnailLoader) {
RunTest(base::FilePath( RunGeneratedTest("/foreground/js/list_thumbnail_loader_unittest.html");
FILE_PATH_LITERAL("foreground/js/list_thumbnail_loader_unittest.html")));
} }
IN_PROC_BROWSER_TEST_F(FileManagerJsTest, FileSystemMetadataProvider) { IN_PROC_BROWSER_TEST_F(FileManagerJsTest, FileSystemMetadataProvider) {
......
...@@ -485,6 +485,15 @@ js_library("list_thumbnail_loader") { ...@@ -485,6 +485,15 @@ js_library("list_thumbnail_loader") {
] ]
} }
js_unittest("list_thumbnail_loader_unittest") {
deps = [
":list_thumbnail_loader",
":mock_thumbnail_loader",
"//ui/file_manager/base/js:test_error_reporting",
"//ui/file_manager/file_manager/common/js:mock_entry",
]
}
js_library("main") { js_library("main") {
deps = [ deps = [
":file_manager", ":file_manager",
...@@ -748,6 +757,7 @@ js_unit_tests("unit_tests") { ...@@ -748,6 +757,7 @@ js_unit_tests("unit_tests") {
":actions_model_unittest", ":actions_model_unittest",
":file_list_model_unittest", ":file_list_model_unittest",
":file_tasks_unittest", ":file_tasks_unittest",
":list_thumbnail_loader_unittest",
":navigation_list_model_unittest", ":navigation_list_model_unittest",
":progress_center_item_group_unittest", ":progress_center_item_group_unittest",
":providers_model_unittest", ":providers_model_unittest",
......
<!DOCTYPE html>
<!-- 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.
-->
<script src="../../../../webui/resources/js/assert.js"></script>
<script src="../../../../webui/resources/js/cr.js"></script>
<script src="../../../../webui/resources/js/cr/event_target.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="../../common/js/file_type.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="../../../base/js/test_error_reporting.js"></script>
<script src="../../../base/js/volume_manager_types.js"></script>
<script src="directory_contents.js"></script>
<script src="file_list_model.js"></script>
<script src="thumbnail_loader.js"></script>
<script src="mock_thumbnail_loader.js"></script>
<script src="list_thumbnail_loader.js"></script>
<script src="list_thumbnail_loader_unittest.js"></script>
...@@ -2,92 +2,121 @@ ...@@ -2,92 +2,121 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
/** /** @type {string} */
* Generates a data url of a sample image for testing. var currentVolumeType;
* TODO(yawano) Consider to share image generation logic with
* gallery/js/image_editor/test_util.js.
*
* @param {Document} document Document.
* @return {string} Data url of a sample image.
*/
function generateSampleImageDataUrl(document) {
var canvas = document.createElement('canvas');
canvas.width = 160;
canvas.height = 160;
var context = canvas.getContext('2d');
context.fillStyle = 'black';
context.fillRect(0, 0, 80, 80);
context.fillRect(80, 80, 80, 80);
return canvas.toDataURL('image/jpeg', 0.5);
}
/** @type {!ListThumbnailLoader} */
var listThumbnailLoader; var listThumbnailLoader;
/** @type {!Object} */
var getCallbacks; var getCallbacks;
/** @type {!Array<Event>} */
var thumbnailLoadedEvents; var thumbnailLoadedEvents;
/** @type {!ThumbnailModel} */
var thumbnailModel; var thumbnailModel;
/** @type {!MetadataModel} */
var metadataModel; var metadataModel;
/** @type {!FileListModel} */
var fileListModel; var fileListModel;
/** @type {!DirectoryModel} */
var directoryModel; var directoryModel;
var currentVolumeType;
var isScanningForTest = false; /** @type {boolean} */
var isScanningForTest;
/** @type {!MockFileSystem} */
var fileSystem = new MockFileSystem('volume-id'); var fileSystem = new MockFileSystem('volume-id');
/** @type {!MockDirectoryEntry} */
var directory1 = new MockDirectoryEntry(fileSystem, '/TestDirectory'); var directory1 = new MockDirectoryEntry(fileSystem, '/TestDirectory');
/** @type {!MockEntry} */
var entry1 = new MockEntry(fileSystem, '/Test1.jpg'); var entry1 = new MockEntry(fileSystem, '/Test1.jpg');
/** @type {!MockEntry} */
var entry2 = new MockEntry(fileSystem, '/Test2.jpg'); var entry2 = new MockEntry(fileSystem, '/Test2.jpg');
/** @type {!MockEntry} */
var entry3 = new MockEntry(fileSystem, '/Test3.jpg'); var entry3 = new MockEntry(fileSystem, '/Test3.jpg');
/** @type {!MockEntry} */
var entry4 = new MockEntry(fileSystem, '/Test4.jpg'); var entry4 = new MockEntry(fileSystem, '/Test4.jpg');
/** @type {!MockEntry} */
var entry5 = new MockEntry(fileSystem, '/Test5.jpg'); var entry5 = new MockEntry(fileSystem, '/Test5.jpg');
/** @type {!MockEntry} */
var entry6 = new MockEntry(fileSystem, '/Test6.jpg'); var entry6 = new MockEntry(fileSystem, '/Test6.jpg');
function setUp() { function setUp() {
currentVolumeType = ListThumbnailLoader.TEST_VOLUME_TYPE; currentVolumeType = ListThumbnailLoader.TEST_VOLUME_TYPE;
/** @suppress {const} */
ListThumbnailLoader.CACHE_SIZE = 5; ListThumbnailLoader.CACHE_SIZE = 5;
/** @suppress {const} */
ListThumbnailLoader.numOfMaxActiveTasksForTest = 2; ListThumbnailLoader.numOfMaxActiveTasksForTest = 2;
/** @suppress {const} */
MockThumbnailLoader.errorUrls = []; MockThumbnailLoader.errorUrls = [];
MockThumbnailLoader.testImageDataUrl = generateSampleImageDataUrl(document); /** @suppress {const} */
MockThumbnailLoader.testImageWidth = 160; MockThumbnailLoader.testImageWidth = 160;
/** @suppress {const} */
MockThumbnailLoader.testImageHeight = 160; MockThumbnailLoader.testImageHeight = 160;
// Create an image dataURL for testing.
var canvas = document.createElement('canvas');
canvas.width = MockThumbnailLoader.testImageWidth;
canvas.height = MockThumbnailLoader.testImageHeight;
var context = canvas.getContext('2d');
context.fillStyle = 'black';
context.fillRect(0, 0, 80, 80);
context.fillRect(80, 80, 80, 80);
/** @const {string} */
var testImageDataUrl = canvas.toDataURL('image/jpeg', 0.5);
/** @suppress {const} */
MockThumbnailLoader.testImageDataUrl = testImageDataUrl;
getCallbacks = {}; getCallbacks = {};
thumbnailModel = {
thumbnailModel = /** @type {!ThumbnailModel} */ ({
get: function(entries) { get: function(entries) {
return new Promise(function(fulfill) { return new Promise(function(fulfill) {
getCallbacks[getKeyOfGetCallback_(entries)] = fulfill; getCallbacks[getKeyOfGetCallback_(entries)] = fulfill;
}); });
} },
}; });
metadataModel = { metadataModel = /** @type {!MetadataModel} */ ({
get: function() {}, get: function() {},
getCache: function(entries, names) { getCache: function(entries, names) {
return [{}]; return [{}];
} },
}; });
fileListModel = new FileListModel(metadataModel); fileListModel = new FileListModel(metadataModel);
directoryModel = { isScanningForTest = false;
directoryModel = /** @type {!DirectoryModel} */ ({
__proto__: cr.EventTarget.prototype, __proto__: cr.EventTarget.prototype,
getFileList: function() { getFileList: function() {
return fileListModel; return fileListModel;
}, },
isScanning: function() { isScanning: function() {
return isScanningForTest; return isScanningForTest;
} },
}; });
listThumbnailLoader = new ListThumbnailLoader( var fakeVolumeManager = /** @type {!VolumeManager} */ ({
directoryModel,
thumbnailModel,
// Mocking volume manager
{
getVolumeInfo: function(entry) { getVolumeInfo: function(entry) {
return { volumeType: currentVolumeType }; return {
} volumeType: currentVolumeType,
};
}, },
MockThumbnailLoader); });
listThumbnailLoader = new ListThumbnailLoader(
directoryModel, thumbnailModel, fakeVolumeManager, MockThumbnailLoader);
thumbnailLoadedEvents = []; thumbnailLoadedEvents = [];
listThumbnailLoader.addEventListener('thumbnailLoaded', function(event) { listThumbnailLoader.addEventListener('thumbnailLoaded', function(event) {
...@@ -366,24 +395,24 @@ function testDirectoryScanIsRunning() { ...@@ -366,24 +395,24 @@ function testDirectoryScanIsRunning() {
function testExifIOError(callback) { function testExifIOError(callback) {
var task = new ListThumbnailLoader.Task( var task = new ListThumbnailLoader.Task(
entry1, entry1,
// Mocking volume manager. /** @type {!VolumeManager} */ ({
{
getVolumeInfo: function(entry) { getVolumeInfo: function(entry) {
return { volumeType: currentVolumeType }; return {
} volumeType: currentVolumeType
};
}, },
// Mocking thumbnail model. }),
{ /** @type {!ThumbnailModel} */ ({
get: function(entries) { get: function(entries) {
return Promise.resolve([{ return Promise.resolve([{
thumbnail: { thumbnail: {
urlError: { urlError: {
errorDescription: 'Error: Unexpected EOF @0' errorDescription: 'Error: Unexpected EOF @0'
} },
} },
}]); }]);
}
}, },
}),
function() { function() {
// Thumbnails should be fetched only from EXIF on IO error. // Thumbnails should be fetched only from EXIF on IO error.
assertTrue(false); assertTrue(false);
......
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