Commit 9025984c authored by Trent Apted's avatar Trent Apted Committed by Commit Bot

Gallery: closure-compile image_view_unittest.js

Bug: 867700, 860355
Change-Id: Ifcc4ada00bc459b8cd59a5c2b234af0ef3554c61
Reviewed-on: https://chromium-review.googlesource.com/1150015Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Commit-Queue: Trent Apted <tapted@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579292}
parent c808b278
......@@ -91,20 +91,33 @@ MockFileSystem.prototype.findChildren_ = function(directory) {
return children;
};
/** @interface */
function MockEntryInterface() {}
/**
* Clones the entry with the new fullpath.
*
* @param {string} fullpath New fullpath.
* @param {FileSystem=} opt_filesystem New file system
* @return {Entry} Cloned entry.
*/
MockEntryInterface.prototype.clone = function(fullpath, opt_filesystem) {};
/**
* Base class of mock entries.
*
* @param {FileSystem} filesystem File system where the entry is localed.
* @param {string} fullPath Full path of the entry.
* @param {!Metadata} metadata Metadata.
* @param {Metadata=} opt_metadata Metadata.
* @constructor
* @extends {Entry}
* @implements {MockEntryInterface}
*/
function MockEntry(filesystem, fullPath, metadata) {
function MockEntry(filesystem, fullPath, opt_metadata) {
filesystem.entries[fullPath] = this;
this.filesystem = filesystem;
this.fullPath = fullPath;
this.metadata = metadata;
this.metadata = opt_metadata || /** @type {!Metadata} */ ({});
this.removed_ = false;
}
......@@ -221,13 +234,7 @@ MockEntry.prototype.assertRemoved = function() {
throw new Error('expected removed for file ' + this.name);
};
/**
* Clones the entry with the new fullpath.
*
* @param {string} fullpath New fullpath.
* @param {FileSystem=} opt_filesystem New file system
* @return {Entry} Cloned entry.
*/
/** @override */
MockEntry.prototype.clone = function(fullpath, opt_filesystem) {
throw new Error('Not implemented.');
};
......@@ -237,14 +244,19 @@ MockEntry.prototype.clone = function(fullpath, opt_filesystem) {
*
* @param {FileSystem} filesystem File system where the entry is localed.
* @param {string} fullPath Full path for the entry.
* @param {!Metadata} metadata Metadata.
* @param {Metadata=} opt_metadata Metadata.
* @param {Blob=} opt_content Optional content.
* @extends {MockEntry}
* @extends {FileEntry}
* @implements {MockEntryInterface}
* @constructor
*/
function MockFileEntry(filesystem, fullPath, metadata, opt_content) {
MockEntry.call(this, filesystem, fullPath, metadata);
function MockFileEntry(filesystem, fullPath, opt_metadata, opt_content) {
filesystem.entries[fullPath] = this;
this.filesystem = filesystem;
this.fullPath = fullPath;
this.metadata = opt_metadata || /** @type {!Metadata} */ ({});
this.content = opt_content || new Blob([]);
this.removed_ = false;
this.isFile = true;
this.isDirectory = false;
}
......@@ -257,15 +269,13 @@ MockFileEntry.prototype = {
* Returns a File that this represents.
*
* @param {function(!File)} onSuccess Function to take the file.
* @param {function(!Error)} onError
* @param {function(!FileError)=} onError
*/
MockFileEntry.prototype.file = function(onSuccess, onError) {
onSuccess(new File([this.content], this.toURL()));
};
/**
* @override
*/
/** @override */
MockFileEntry.prototype.clone = function(path, opt_filesystem) {
return new MockFileEntry(
opt_filesystem || this.filesystem, path, this.metadata, this.content);
......@@ -293,9 +303,7 @@ MockDirectoryEntry.prototype = {
__proto__: MockEntry.prototype
};
/**
* @override
*/
/** @override */
MockDirectoryEntry.prototype.clone = function(path, opt_filesystem) {
return new MockDirectoryEntry(opt_filesystem || this.filesystem, path);
};
......
......@@ -22,6 +22,7 @@ js_type_check("closure_compile") {
":image_transform",
":image_util",
":image_view",
":image_view_unittest",
":test_util",
":viewport",
]
......@@ -180,6 +181,14 @@ js_library("image_view") {
]
}
js_library("image_view_unittest") {
deps = [
":image_view",
"../../../file_manager/common/js:mock_entry",
"//ui/webui/resources/js:webui_resource_test",
]
}
js_library("test_util") {
}
......
......@@ -2,53 +2,77 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* Helper to construct testing GalleryItem objects.
*
* @param {!FileEntry} entry
* @param {EntryLocation} locationInfo
* @param {Object} metadataItem
* @param {ThumbnailMetadataItem=} opt_thumbnailMetadataItem
* @param {boolean=} opt_original Whether the entry is original or edited.
* @constructor
* @extends GalleryItem
*/
function MockGalleryItem(
entry, locationInfo, metadataItem, opt_thumbnailMetadataItem,
opt_original) {
let entryLocation = locationInfo || /** @type {!EntryLocation} */ ({});
GalleryItem.call(
this, entry, entryLocation, /** @type {MetadataItem} */ (metadataItem),
opt_thumbnailMetadataItem || null, opt_original || false);
}
MockGalleryItem.prototype = {
__proto__: GalleryItem.prototype
};
function testImageView() {
var mockFileSystem = new MockFileSystem('volumeId');
var mockEntry = new MockEntry(mockFileSystem, '/test.jpg');
var mockEntry = new MockFileEntry(mockFileSystem, '/test.jpg');
// Item has full size cache.
var itemWithFullCache = new GalleryItem(mockEntry, null, {}, null, false);
itemWithFullCache.contentImage = document.createElement('canvas');
var itemWithFullCache = new MockGalleryItem(mockEntry, null, {});
itemWithFullCache.contentImage =
assertInstanceof(document.createElement('canvas'), HTMLCanvasElement);
assertEquals(
ImageView.LoadTarget.CACHED_MAIN_IMAGE,
ImageView.getLoadTarget(itemWithFullCache, new ImageView.Effect.None()));
// Item with content thumbnail.
var itemWithContentThumbnail = new GalleryItem(
mockEntry, null, {thumbnail: {url: 'url'}}, null, false);
var itemWithContentThumbnail =
new MockGalleryItem(mockEntry, null, {thumbnail: {url: 'url'}});
assertEquals(
ImageView.LoadTarget.THUMBNAIL,
ImageView.getLoadTarget(
itemWithContentThumbnail, new ImageView.Effect.None()));
// Item with external thumbnail.
var itemWithExternalThumbnail = new GalleryItem(
mockEntry, null, {external: {thumbnailUrl: 'url'}}, null, false);
var itemWithExternalThumbnail =
new MockGalleryItem(mockEntry, null, {external: {thumbnailUrl: 'url'}});
assertEquals(
ImageView.LoadTarget.THUMBNAIL,
ImageView.getLoadTarget(
itemWithExternalThumbnail, new ImageView.Effect.None()));
// Item with external thumbnail but present localy.
var itemWithExternalThumbnailPresent = new GalleryItem(
mockEntry, null, {external: {thumbnailUrl: 'url', present: true}}, null,
false);
// Item with external thumbnail but present locally.
var itemWithExternalThumbnailPresent = new MockGalleryItem(
mockEntry, null, {external: {thumbnailUrl: 'url', present: true}});
assertEquals(
ImageView.LoadTarget.MAIN_IMAGE,
ImageView.getLoadTarget(
itemWithExternalThumbnailPresent, new ImageView.Effect.None()));
// Item with external thumbnail shown by slide effect.
var itemWithExternalThumbnailSlide = new GalleryItem(
mockEntry, null, {external: {thumbnailUrl: 'url'}}, null, false);
var itemWithExternalThumbnailSlide =
new MockGalleryItem(mockEntry, null, {external: {thumbnailUrl: 'url'}});
assertEquals(
ImageView.LoadTarget.THUMBNAIL,
ImageView.getLoadTarget(
itemWithExternalThumbnailSlide, new ImageView.Effect.Slide(1)));
// Item with external thumbnail shown by zoom to screen effect.
var itemWithExternalThumbnailZoomToScreen = new GalleryItem(
mockEntry, null, {external: {thumbnailUrl: 'url'}}, null, false);
var itemWithExternalThumbnailZoomToScreen =
new MockGalleryItem(mockEntry, null, {external: {thumbnailUrl: 'url'}});
assertEquals(
ImageView.LoadTarget.THUMBNAIL,
ImageView.getLoadTarget(
......@@ -56,17 +80,16 @@ function testImageView() {
new ImageView.Effect.ZoomToScreen(new ImageRect(0, 0, 100, 100))));
// Item with external thumbnail shown by zoom effect.
var itemWithExternalThumbnailZoom = new GalleryItem(
mockEntry, null, {external: {thumbnailUrl: 'url'}}, null, false);
var itemWithExternalThumbnailZoom =
new MockGalleryItem(mockEntry, null, {external: {thumbnailUrl: 'url'}});
assertEquals(
ImageView.LoadTarget.MAIN_IMAGE,
ImageView.getLoadTarget(
itemWithExternalThumbnailZoom,
new ImageView.Effect.Zoom(0, 0, null)));
new ImageView.Effect.Zoom(0, 0, new ImageRect(0, 0, 1, 1))));
// Item without cache/thumbnail.
var itemWithoutCacheOrThumbnail = new GalleryItem(
mockEntry, null, {}, null, false);
var itemWithoutCacheOrThumbnail = new MockGalleryItem(mockEntry, null, {});
assertEquals(
ImageView.LoadTarget.MAIN_IMAGE,
ImageView.getLoadTarget(
......@@ -74,27 +97,31 @@ function testImageView() {
}
function testLoadVideo(callback) {
var container = document.createElement('div');
var container = assertInstanceof(document.createElement('div'), HTMLElement);
// We re-use the image-container for video, it starts with this class.
container.classList.add('image-container');
var viewport = new Viewport(window);
// Mock volume manager.
var volumeManager = {
getVolumeInfo: function(entry) {
return {volumeType: VolumeManagerCommon.VolumeType.DOWNLOADS};
}
};
/**
* Mock volume manager.
* @constructor
* @extends MetadataProvider
*/
function MockDownloadVolumeManager() {
this.__proto__.getVolumeInfo =
function(entry) {
return {volumeType: VolumeManagerCommon.VolumeType.DOWNLOADS};
};
}
var metadataModel = new MetadataModel(volumeManager);
var metadataModel = new MetadataModel(new MockDownloadVolumeManager());
var imageView = new ImageView(container, viewport, metadataModel);
var downloads = new MockFileSystem('file:///downloads');
var getGalleryItem = function(path) {
return new GalleryItem(
new MockEntry(downloads, path), {isReadOnly: false}, {size: 100}, {},
true /* original */);
return new MockGalleryItem(
new MockFileEntry(downloads, path), null, {size: 100});
};
var item = getGalleryItem('/test.webm');
var effect = new ImageView.Effect.None();
......
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