Commit 6959a615 authored by Jérémie Boulic's avatar Jérémie Boulic Committed by Chromium LUCI CQ

Image loader: Generate JS modules

In //ui/file_manager/image_loader/:
- cache.js
- cache_unittest.js
- image_loader.js
- image_loader_unittest.js
- image_loader_util.js
- image_request_task.js
- piex_loader.js
- scheduler.js
- scheduler_unittest.js

Bug: 1133186
Change-Id: Id23e03c916590830be342b2fda99e5701610a88f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2631398
Commit-Queue: Jeremie Boulic <jboulic@chromium.org>
Auto-Submit: Jeremie Boulic <jboulic@chromium.org>
Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/heads/master@{#844455}
parent b11fe782
......@@ -16,13 +16,13 @@ IN_PROC_BROWSER_TEST_F(ImageLoaderJsTest, ImageLoaderClientTest) {
}
IN_PROC_BROWSER_TEST_F(ImageLoaderJsTest, CacheTest) {
RunTestURL("cache_unittest_gen.html");
RunTestURL("cache_unittest.m_gen.html");
}
IN_PROC_BROWSER_TEST_F(ImageLoaderJsTest, ImageLoaderTest) {
RunTestURL("image_loader_unittest_gen.html");
RunTestURL("image_loader_unittest.m_gen.html");
}
IN_PROC_BROWSER_TEST_F(ImageLoaderJsTest, SchedulerTest) {
RunTestURL("scheduler_unittest_gen.html");
RunTestURL("scheduler_unittest.m_gen.html");
}
......@@ -67,7 +67,6 @@ group("unit_test_data") {
"gallery/js:js_test_gen_html",
"gallery/js/image_editor:js_test_gen_html",
"gallery/js/image_editor:js_test_gen_html_modules",
"image_loader:js_test_gen_html",
"image_loader:js_test_gen_html_modules",
"video_player/js:js_test_gen_html_modules",
]
......
......@@ -10,8 +10,14 @@ import("//ui/webui/resources/tools/js_modulizer.gni")
js_type_check("closure_compile_jsmodules") {
uses_js_modules = true
deps = [
":cache.m",
":image_loader.m",
":image_loader_client.m",
":image_loader_util.m",
":image_request_task.m",
":load_image_request.m",
":piex_loader.m",
":scheduler.m",
]
}
......@@ -37,11 +43,16 @@ js_library("background") {
js_library("cache") {
}
js_unittest("cache_unittest") {
js_library("cache.m") {
sources = [ "$root_gen_dir/ui/file_manager/image_loader/cache.m.js" ]
extra_deps = [ ":modulize" ]
}
js_unittest("cache_unittest.m") {
deps = [
":cache",
":load_image_request",
"//ui/webui/resources/js:webui_resource_test",
":load_image_request.m",
"//chrome/test/data/webui:chai_assert",
]
}
......@@ -55,10 +66,26 @@ js_library("image_loader") {
]
}
js_unittest("image_loader_unittest") {
js_library("image_loader.m") {
sources = [ "$root_gen_dir/ui/file_manager/image_loader/image_loader.m.js" ]
deps = [
":image_loader",
"//ui/webui/resources/js:webui_resource_test",
":cache.m",
":image_request_task.m",
":load_image_request.m",
":scheduler.m",
"//ui/file_manager/file_manager/foreground/js/metadata:image_orientation.m",
"//ui/webui/resources/js:assert.m",
]
extra_deps = [ ":modulize" ]
}
js_unittest("image_loader_unittest.m") {
deps = [
":image_loader_util.m",
":load_image_request.m",
"//chrome/test/data/webui:chai_assert",
"//ui/file_manager/file_manager/foreground/js/metadata:image_orientation.m",
]
}
......@@ -69,6 +96,17 @@ js_library("image_loader_util") {
]
}
js_library("image_loader_util.m") {
sources =
[ "$root_gen_dir/ui/file_manager/image_loader/image_loader_util.m.js" ]
deps = [
":load_image_request.m",
"//ui/webui/resources/js:assert.m",
]
extra_deps = [ ":modulize" ]
}
js_library("load_image_request") {
deps = [
"//ui/file_manager/file_manager/foreground/js/metadata:image_orientation",
......@@ -131,6 +169,13 @@ js_library("piex_loader") {
externs_list = [ "//ui/file_manager/externs/platform.js" ]
}
js_library("piex_loader.m") {
sources = [ "$root_gen_dir/ui/file_manager/image_loader/piex_loader.m.js" ]
externs_list = [ "//ui/file_manager/externs/platform.js" ]
extra_deps = [ ":modulize" ]
}
js_library("image_request_task") {
deps = [
":cache",
......@@ -142,19 +187,48 @@ js_library("image_request_task") {
externs_list = [ "//ui/file_manager/externs/platform.js" ]
}
js_library("image_request_task.m") {
sources =
[ "$root_gen_dir/ui/file_manager/image_loader/image_request_task.m.js" ]
deps = [
":cache.m",
":image_loader_util.m",
":load_image_request.m",
":piex_loader.m",
"//ui/file_manager/file_manager/common/js:file_type.m",
"//ui/file_manager/file_manager/foreground/js/metadata:image_orientation.m",
"//ui/webui/resources/js:assert.m",
]
extra_deps = [ ":modulize" ]
}
js_library("scheduler") {
deps = [ ":image_request_task" ]
}
js_unittest("scheduler_unittest") {
js_library("scheduler.m") {
sources = [ "$root_gen_dir/ui/file_manager/image_loader/scheduler.m.js" ]
deps = [ ":image_request_task.m" ]
extra_deps = [ ":modulize" ]
}
js_unittest("scheduler_unittest.m") {
deps = [
":scheduler",
"//ui/webui/resources/js:webui_resource_test",
":image_request_task.m",
":scheduler.m",
"//chrome/test/data/webui:chai_assert",
]
}
js_test_gen_html("js_test_gen_html_modules") {
deps = [ ":image_loader_client_unittest.m" ]
deps = [
":cache_unittest.m",
":image_loader_client_unittest.m",
":image_loader_unittest.m",
":scheduler_unittest.m",
]
js_module = true
closure_flags =
......@@ -165,22 +239,12 @@ js_test_gen_html("js_test_gen_html_modules") {
]
}
js_test_gen_html("js_test_gen_html") {
closure_flags = default_closure_args + [ "jscomp_error=strictCheckTypes" ]
deps = [
":cache_unittest",
":image_loader_unittest",
":scheduler_unittest",
]
}
group("closure_compile") {
testonly = true
deps = [
":closure_compile_jsmodules",
":closure_compile_module",
":js_test_gen_html_modules_type_check_auto",
":js_test_gen_html_type_check_auto",
]
}
......@@ -188,5 +252,11 @@ js_modulizer("modulize") {
input_files = [
"image_loader_client.js",
"load_image_request.js",
"cache.js",
"piex_loader.js",
"image_loader_util.js",
"scheduler.js",
"image_request_task.js",
"image_loader.js",
]
}
......@@ -6,7 +6,7 @@
* Persistent cache storing images in an indexed database on the hard disk.
* @constructor
*/
function ImageCache() {
/* #export */ function ImageCache() {
/**
* IndexedDB database handle.
* @type {IDBDatabase}
......
......@@ -2,14 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
'use strict';
import {assertFalse, assertTrue} from 'chrome://test/chai_assert.js';
import {LoadImageRequest} from './load_image_request.m.js';
function testCreateCacheKey() {
export function testCreateCacheKey() {
const key = LoadImageRequest.cacheKey({url: 'http://example.com/image.jpg'});
assertTrue(!!key);
}
function testNotCreateCacheKey() {
export function testNotCreateCacheKey() {
let key = LoadImageRequest.cacheKey({url: 'data:xxx'});
assertFalse(!!key);
......
......@@ -2,11 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// clang-format off
// #import {LoadImageRequest, LoadImageResponse} from './load_image_request.m.js';
// #import {ImageRequestTask} from './image_request_task.m.js';
// #import {ImageOrientation} from '../file_manager/foreground/js/metadata/image_orientation.m.js';
// #import {assert} from 'chrome://resources/js/assert.m.js';
// #import {Scheduler} from './scheduler.m.js';
// #import {ImageCache} from './cache.m.js';
// clang-format on
/**
* Loads and resizes an image.
* @constructor
*/
function ImageLoader() {
/* #export */ function ImageLoader() {
/**
* Persistent cache object.
* @type {ImageCache}
......
......@@ -2,6 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import {assertEquals} from 'chrome://test/chai_assert.js';
import {ImageOrientation} from '../file_manager/foreground/js/metadata/image_orientation.m.js';
import {ImageLoaderUtil} from './image_loader_util.m.js';
import {LoadImageRequest} from './load_image_request.m.js';
/**
* Casts a map of options as an incoming load request to test CopyParameters.
*
......@@ -19,7 +25,7 @@ function calculateCopyParametersFromOptions(source, options) {
* - Source image: 200x50
* - Target: max size is 100x100
*/
function testNormalImage() {
export function testNormalImage() {
const source = new Image();
source.width = 200;
source.height = 50;
......@@ -46,7 +52,7 @@ function testNormalImage() {
* - Source image: 50x200 90 deg clock-wise rotated image.
* - Target: max size is 100x100
*/
function testRotatedImage() {
export function testRotatedImage() {
const source = new Image();
source.width = 50;
source.height = 200;
......@@ -73,7 +79,7 @@ function testRotatedImage() {
* - Source image: 800x100
* - Target: 50x50 cropped image.
*/
function testCroppedImage() {
export function testCroppedImage() {
const source = new Image();
source.width = 800;
source.height = 100;
......@@ -101,7 +107,7 @@ function testCroppedImage() {
* - Source image: 200x25
* - Target: 50x50 cropped image.
*/
function testCroppedImageWithResize() {
export function testCroppedImageWithResize() {
const source = new Image();
source.width = 200;
source.height = 25;
......@@ -129,7 +135,7 @@ function testCroppedImageWithResize() {
* - Source image: 20x10
* - Target: 50x50 cropped image.
*/
function testCroppedTinyImage() {
export function testCroppedTinyImage() {
const source = new Image();
source.width = 20;
source.height = 10;
......@@ -157,7 +163,7 @@ function testCroppedTinyImage() {
* - Source image: 100x400 90 degree clock-wise rotated.
* - Target: 50x50 cropped image
*/
function testCroppedRotatedImage() {
export function testCroppedRotatedImage() {
const source = new Image();
source.width = 100;
source.height = 400;
......
......@@ -2,7 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function ImageLoaderUtil() {}
// #import {LoadImageRequest} from './load_image_request.m.js';
// #import {assert} from 'chrome://resources/js/assert.m.js';
/* #export */ function ImageLoaderUtil() {}
/**
* Checks if the options on the request contain any image processing.
......
......@@ -2,6 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// clang-format off
// #import {ImageCache} from './cache.m.js';
// #import {ImageLoaderUtil} from './image_loader_util.m.js';
// #import {ImageOrientation} from '../file_manager/foreground/js/metadata/image_orientation.m.js';
// #import {PiexLoader} from './piex_loader.m.js';
// #import {FileType} from '../file_manager/common/js/file_type.m.js';
// #import {LoadImageRequest, LoadImageResponse, LoadImageResponseStatus} from './load_image_request.m.js';
// #import {assert, assertInstanceof} from 'chrome://resources/js/assert.m.js';
// clang-format on
/**
* Creates and starts downloading and then resizing of the image. Finally,
* returns the image using the callback.
......@@ -12,7 +22,7 @@
* @param {function(!LoadImageResponse)} callback Response handler.
* @constructor
*/
function ImageRequestTask(id, cache, request, callback) {
/* #export */ function ImageRequestTask(id, cache, request, callback) {
/**
* Global ID (concatenated client ID and client request ID).
* @type {string}
......
......@@ -718,7 +718,7 @@ class ImageBuffer {
/**
* PiexLoader: is a namespace.
*/
const PiexLoader = {};
/* #export */ const PiexLoader = {};
/**
* Loads a RAW image. Returns the image metadata and the image thumbnail in a
......
......@@ -2,13 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// #import {ImageRequestTask} from './image_request_task.m.js';
/**
* Scheduler for ImageRequestTask objects. Fetches tasks from a queue and
* processes them synchronously, taking into account priorities. The highest
* priority is 0.
* @constructor
*/
function Scheduler() {
/* #export */ function Scheduler() {
/**
* List of tasks waiting to be checked. If these items are available in
* cache, then they are processed immediately after starting the scheduler.
......
......@@ -2,14 +2,17 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
'use strict';
import {assertEquals} from 'chrome://test/chai_assert.js';
import {ImageRequestTask} from './image_request_task.m.js';
import {Scheduler} from './scheduler.m.js';
/**
* Fake global clock used to record the "time" at which a task was run.
*/
let globalTime = 0;
function setUp() {
export function setUp() {
globalTime = 0;
}
......@@ -55,7 +58,7 @@ function newTask(taskId, priority) {
/**
* Checks that adding and removing tasks before the scheduler is started works.
*/
function testIdleSchedulerAddRemove() {
export function testIdleSchedulerAddRemove() {
const scheduler = new Scheduler();
const fakeTask = newTask('task-1', 0);
scheduler.add(/** @type {!ImageRequestTask} */ (fakeTask));
......@@ -71,7 +74,7 @@ function testIdleSchedulerAddRemove() {
* tasks when scheduler is started. They also should be executed in the
* order of their priorities.
*/
function testNewTasksMovedAndRunInPriorityOrder() {
export function testNewTasksMovedAndRunInPriorityOrder() {
const fakeTask1 = newTask('task-1', 1);
const fakeTask2 = newTask('task-2', 0);
......@@ -87,7 +90,7 @@ function testNewTasksMovedAndRunInPriorityOrder() {
/**
* Checks that the scheduler only launches MAXIMUM_IN_PARALLEL tasks.
*/
function testParallelTasks() {
export function testParallelTasks() {
const scheduler = new Scheduler();
const taskList = [];
for (let i = 0; i <= Scheduler.MAXIMUM_IN_PARALLEL; ++i) {
......
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