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) {
}
IN_PROC_BROWSER_TEST_F(FileManagerJsTest, ListThumbnailLoader) {
RunTest(base::FilePath(
FILE_PATH_LITERAL("foreground/js/list_thumbnail_loader_unittest.html")));
RunGeneratedTest("/foreground/js/list_thumbnail_loader_unittest.html");
}
IN_PROC_BROWSER_TEST_F(FileManagerJsTest, FileSystemMetadataProvider) {
......
......@@ -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") {
deps = [
":file_manager",
......@@ -748,6 +757,7 @@ js_unit_tests("unit_tests") {
":actions_model_unittest",
":file_list_model_unittest",
":file_tasks_unittest",
":list_thumbnail_loader_unittest",
":navigation_list_model_unittest",
":progress_center_item_group_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 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* Generates a data url of a sample image for testing.
* 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 {string} */
var currentVolumeType;
/** @type {!ListThumbnailLoader} */
var listThumbnailLoader;
/** @type {!Object} */
var getCallbacks;
/** @type {!Array<Event>} */
var thumbnailLoadedEvents;
/** @type {!ThumbnailModel} */
var thumbnailModel;
/** @type {!MetadataModel} */
var metadataModel;
/** @type {!FileListModel} */
var fileListModel;
/** @type {!DirectoryModel} */
var directoryModel;
var currentVolumeType;
var isScanningForTest = false;
/** @type {boolean} */
var isScanningForTest;
/** @type {!MockFileSystem} */
var fileSystem = new MockFileSystem('volume-id');
/** @type {!MockDirectoryEntry} */
var directory1 = new MockDirectoryEntry(fileSystem, '/TestDirectory');
/** @type {!MockEntry} */
var entry1 = new MockEntry(fileSystem, '/Test1.jpg');
/** @type {!MockEntry} */
var entry2 = new MockEntry(fileSystem, '/Test2.jpg');
/** @type {!MockEntry} */
var entry3 = new MockEntry(fileSystem, '/Test3.jpg');
/** @type {!MockEntry} */
var entry4 = new MockEntry(fileSystem, '/Test4.jpg');
/** @type {!MockEntry} */
var entry5 = new MockEntry(fileSystem, '/Test5.jpg');
/** @type {!MockEntry} */
var entry6 = new MockEntry(fileSystem, '/Test6.jpg');
function setUp() {
currentVolumeType = ListThumbnailLoader.TEST_VOLUME_TYPE;
/** @suppress {const} */
ListThumbnailLoader.CACHE_SIZE = 5;
/** @suppress {const} */
ListThumbnailLoader.numOfMaxActiveTasksForTest = 2;
/** @suppress {const} */
MockThumbnailLoader.errorUrls = [];
MockThumbnailLoader.testImageDataUrl = generateSampleImageDataUrl(document);
/** @suppress {const} */
MockThumbnailLoader.testImageWidth = 160;
/** @suppress {const} */
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 = {};
thumbnailModel = {
thumbnailModel = /** @type {!ThumbnailModel} */ ({
get: function(entries) {
return new Promise(function(fulfill) {
getCallbacks[getKeyOfGetCallback_(entries)] = fulfill;
});
}
};
},
});
metadataModel = {
metadataModel = /** @type {!MetadataModel} */ ({
get: function() {},
getCache: function(entries, names) {
return [{}];
}
};
},
});
fileListModel = new FileListModel(metadataModel);
directoryModel = {
isScanningForTest = false;
directoryModel = /** @type {!DirectoryModel} */ ({
__proto__: cr.EventTarget.prototype,
getFileList: function() {
return fileListModel;
},
isScanning: function() {
return isScanningForTest;
}
};
},
});
var fakeVolumeManager = /** @type {!VolumeManager} */ ({
getVolumeInfo: function(entry) {
return {
volumeType: currentVolumeType,
};
},
});
listThumbnailLoader = new ListThumbnailLoader(
directoryModel,
thumbnailModel,
// Mocking volume manager
{
getVolumeInfo: function(entry) {
return { volumeType: currentVolumeType };
}
},
MockThumbnailLoader);
directoryModel, thumbnailModel, fakeVolumeManager, MockThumbnailLoader);
thumbnailLoadedEvents = [];
listThumbnailLoader.addEventListener('thumbnailLoaded', function(event) {
......@@ -366,24 +395,24 @@ function testDirectoryScanIsRunning() {
function testExifIOError(callback) {
var task = new ListThumbnailLoader.Task(
entry1,
// Mocking volume manager.
{
/** @type {!VolumeManager} */ ({
getVolumeInfo: function(entry) {
return { volumeType: currentVolumeType };
}
},
// Mocking thumbnail model.
{
return {
volumeType: currentVolumeType
};
},
}),
/** @type {!ThumbnailModel} */ ({
get: function(entries) {
return Promise.resolve([{
thumbnail: {
urlError: {
errorDescription: 'Error: Unexpected EOF @0'
}
}
},
},
}]);
}
},
},
}),
function() {
// Thumbnails should be fetched only from EXIF on IO error.
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