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) { ...@@ -16,13 +16,13 @@ IN_PROC_BROWSER_TEST_F(ImageLoaderJsTest, ImageLoaderClientTest) {
} }
IN_PROC_BROWSER_TEST_F(ImageLoaderJsTest, CacheTest) { 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) { 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) { 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") { ...@@ -67,7 +67,6 @@ group("unit_test_data") {
"gallery/js:js_test_gen_html", "gallery/js:js_test_gen_html",
"gallery/js/image_editor:js_test_gen_html", "gallery/js/image_editor:js_test_gen_html",
"gallery/js/image_editor:js_test_gen_html_modules", "gallery/js/image_editor:js_test_gen_html_modules",
"image_loader:js_test_gen_html",
"image_loader:js_test_gen_html_modules", "image_loader:js_test_gen_html_modules",
"video_player/js: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") ...@@ -10,8 +10,14 @@ import("//ui/webui/resources/tools/js_modulizer.gni")
js_type_check("closure_compile_jsmodules") { js_type_check("closure_compile_jsmodules") {
uses_js_modules = true uses_js_modules = true
deps = [ deps = [
":cache.m",
":image_loader.m",
":image_loader_client.m", ":image_loader_client.m",
":image_loader_util.m",
":image_request_task.m",
":load_image_request.m", ":load_image_request.m",
":piex_loader.m",
":scheduler.m",
] ]
} }
...@@ -37,11 +43,16 @@ js_library("background") { ...@@ -37,11 +43,16 @@ js_library("background") {
js_library("cache") { 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 = [ deps = [
":cache", ":load_image_request.m",
":load_image_request", "//chrome/test/data/webui:chai_assert",
"//ui/webui/resources/js:webui_resource_test",
] ]
} }
...@@ -55,10 +66,26 @@ js_library("image_loader") { ...@@ -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 = [ deps = [
":image_loader", ":cache.m",
"//ui/webui/resources/js:webui_resource_test", ":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") { ...@@ -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") { js_library("load_image_request") {
deps = [ deps = [
"//ui/file_manager/file_manager/foreground/js/metadata:image_orientation", "//ui/file_manager/file_manager/foreground/js/metadata:image_orientation",
...@@ -131,6 +169,13 @@ js_library("piex_loader") { ...@@ -131,6 +169,13 @@ js_library("piex_loader") {
externs_list = [ "//ui/file_manager/externs/platform.js" ] 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") { js_library("image_request_task") {
deps = [ deps = [
":cache", ":cache",
...@@ -142,19 +187,48 @@ js_library("image_request_task") { ...@@ -142,19 +187,48 @@ js_library("image_request_task") {
externs_list = [ "//ui/file_manager/externs/platform.js" ] 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") { js_library("scheduler") {
deps = [ ":image_request_task" ] 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 = [ deps = [
":scheduler", ":image_request_task.m",
"//ui/webui/resources/js:webui_resource_test", ":scheduler.m",
"//chrome/test/data/webui:chai_assert",
] ]
} }
js_test_gen_html("js_test_gen_html_modules") { 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 js_module = true
closure_flags = closure_flags =
...@@ -165,22 +239,12 @@ js_test_gen_html("js_test_gen_html_modules") { ...@@ -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") { group("closure_compile") {
testonly = true testonly = true
deps = [ deps = [
":closure_compile_jsmodules", ":closure_compile_jsmodules",
":closure_compile_module", ":closure_compile_module",
":js_test_gen_html_modules_type_check_auto", ":js_test_gen_html_modules_type_check_auto",
":js_test_gen_html_type_check_auto",
] ]
} }
...@@ -188,5 +252,11 @@ js_modulizer("modulize") { ...@@ -188,5 +252,11 @@ js_modulizer("modulize") {
input_files = [ input_files = [
"image_loader_client.js", "image_loader_client.js",
"load_image_request.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 @@ ...@@ -6,7 +6,7 @@
* Persistent cache storing images in an indexed database on the hard disk. * Persistent cache storing images in an indexed database on the hard disk.
* @constructor * @constructor
*/ */
function ImageCache() { /* #export */ function ImageCache() {
/** /**
* IndexedDB database handle. * IndexedDB database handle.
* @type {IDBDatabase} * @type {IDBDatabase}
......
...@@ -2,14 +2,16 @@ ...@@ -2,14 +2,16 @@
// 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.
'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'}); const key = LoadImageRequest.cacheKey({url: 'http://example.com/image.jpg'});
assertTrue(!!key); assertTrue(!!key);
} }
function testNotCreateCacheKey() { export function testNotCreateCacheKey() {
let key = LoadImageRequest.cacheKey({url: 'data:xxx'}); let key = LoadImageRequest.cacheKey({url: 'data:xxx'});
assertFalse(!!key); assertFalse(!!key);
......
...@@ -2,11 +2,20 @@ ...@@ -2,11 +2,20 @@
// 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.
// 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. * Loads and resizes an image.
* @constructor * @constructor
*/ */
function ImageLoader() { /* #export */ function ImageLoader() {
/** /**
* Persistent cache object. * Persistent cache object.
* @type {ImageCache} * @type {ImageCache}
......
...@@ -2,6 +2,12 @@ ...@@ -2,6 +2,12 @@
// 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.
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. * Casts a map of options as an incoming load request to test CopyParameters.
* *
...@@ -19,7 +25,7 @@ function calculateCopyParametersFromOptions(source, options) { ...@@ -19,7 +25,7 @@ function calculateCopyParametersFromOptions(source, options) {
* - Source image: 200x50 * - Source image: 200x50
* - Target: max size is 100x100 * - Target: max size is 100x100
*/ */
function testNormalImage() { export function testNormalImage() {
const source = new Image(); const source = new Image();
source.width = 200; source.width = 200;
source.height = 50; source.height = 50;
...@@ -46,7 +52,7 @@ function testNormalImage() { ...@@ -46,7 +52,7 @@ function testNormalImage() {
* - Source image: 50x200 90 deg clock-wise rotated image. * - Source image: 50x200 90 deg clock-wise rotated image.
* - Target: max size is 100x100 * - Target: max size is 100x100
*/ */
function testRotatedImage() { export function testRotatedImage() {
const source = new Image(); const source = new Image();
source.width = 50; source.width = 50;
source.height = 200; source.height = 200;
...@@ -73,7 +79,7 @@ function testRotatedImage() { ...@@ -73,7 +79,7 @@ function testRotatedImage() {
* - Source image: 800x100 * - Source image: 800x100
* - Target: 50x50 cropped image. * - Target: 50x50 cropped image.
*/ */
function testCroppedImage() { export function testCroppedImage() {
const source = new Image(); const source = new Image();
source.width = 800; source.width = 800;
source.height = 100; source.height = 100;
...@@ -101,7 +107,7 @@ function testCroppedImage() { ...@@ -101,7 +107,7 @@ function testCroppedImage() {
* - Source image: 200x25 * - Source image: 200x25
* - Target: 50x50 cropped image. * - Target: 50x50 cropped image.
*/ */
function testCroppedImageWithResize() { export function testCroppedImageWithResize() {
const source = new Image(); const source = new Image();
source.width = 200; source.width = 200;
source.height = 25; source.height = 25;
...@@ -129,7 +135,7 @@ function testCroppedImageWithResize() { ...@@ -129,7 +135,7 @@ function testCroppedImageWithResize() {
* - Source image: 20x10 * - Source image: 20x10
* - Target: 50x50 cropped image. * - Target: 50x50 cropped image.
*/ */
function testCroppedTinyImage() { export function testCroppedTinyImage() {
const source = new Image(); const source = new Image();
source.width = 20; source.width = 20;
source.height = 10; source.height = 10;
...@@ -157,7 +163,7 @@ function testCroppedTinyImage() { ...@@ -157,7 +163,7 @@ function testCroppedTinyImage() {
* - Source image: 100x400 90 degree clock-wise rotated. * - Source image: 100x400 90 degree clock-wise rotated.
* - Target: 50x50 cropped image * - Target: 50x50 cropped image
*/ */
function testCroppedRotatedImage() { export function testCroppedRotatedImage() {
const source = new Image(); const source = new Image();
source.width = 100; source.width = 100;
source.height = 400; source.height = 400;
......
...@@ -2,7 +2,10 @@ ...@@ -2,7 +2,10 @@
// 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.
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. * Checks if the options on the request contain any image processing.
......
...@@ -2,6 +2,16 @@ ...@@ -2,6 +2,16 @@
// 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.
// 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, * Creates and starts downloading and then resizing of the image. Finally,
* returns the image using the callback. * returns the image using the callback.
...@@ -12,7 +22,7 @@ ...@@ -12,7 +22,7 @@
* @param {function(!LoadImageResponse)} callback Response handler. * @param {function(!LoadImageResponse)} callback Response handler.
* @constructor * @constructor
*/ */
function ImageRequestTask(id, cache, request, callback) { /* #export */ function ImageRequestTask(id, cache, request, callback) {
/** /**
* Global ID (concatenated client ID and client request ID). * Global ID (concatenated client ID and client request ID).
* @type {string} * @type {string}
......
...@@ -718,7 +718,7 @@ class ImageBuffer { ...@@ -718,7 +718,7 @@ class ImageBuffer {
/** /**
* PiexLoader: is a namespace. * PiexLoader: is a namespace.
*/ */
const PiexLoader = {}; /* #export */ const PiexLoader = {};
/** /**
* Loads a RAW image. Returns the image metadata and the image thumbnail in a * Loads a RAW image. Returns the image metadata and the image thumbnail in a
......
...@@ -2,13 +2,15 @@ ...@@ -2,13 +2,15 @@
// 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.
// #import {ImageRequestTask} from './image_request_task.m.js';
/** /**
* Scheduler for ImageRequestTask objects. Fetches tasks from a queue and * Scheduler for ImageRequestTask objects. Fetches tasks from a queue and
* processes them synchronously, taking into account priorities. The highest * processes them synchronously, taking into account priorities. The highest
* priority is 0. * priority is 0.
* @constructor * @constructor
*/ */
function Scheduler() { /* #export */ function Scheduler() {
/** /**
* List of tasks waiting to be checked. If these items are available in * List of tasks waiting to be checked. If these items are available in
* cache, then they are processed immediately after starting the scheduler. * cache, then they are processed immediately after starting the scheduler.
......
...@@ -2,14 +2,17 @@ ...@@ -2,14 +2,17 @@
// 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.
'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. * Fake global clock used to record the "time" at which a task was run.
*/ */
let globalTime = 0; let globalTime = 0;
function setUp() { export function setUp() {
globalTime = 0; globalTime = 0;
} }
...@@ -55,7 +58,7 @@ function newTask(taskId, priority) { ...@@ -55,7 +58,7 @@ function newTask(taskId, priority) {
/** /**
* Checks that adding and removing tasks before the scheduler is started works. * Checks that adding and removing tasks before the scheduler is started works.
*/ */
function testIdleSchedulerAddRemove() { export function testIdleSchedulerAddRemove() {
const scheduler = new Scheduler(); const scheduler = new Scheduler();
const fakeTask = newTask('task-1', 0); const fakeTask = newTask('task-1', 0);
scheduler.add(/** @type {!ImageRequestTask} */ (fakeTask)); scheduler.add(/** @type {!ImageRequestTask} */ (fakeTask));
...@@ -71,7 +74,7 @@ function testIdleSchedulerAddRemove() { ...@@ -71,7 +74,7 @@ function testIdleSchedulerAddRemove() {
* tasks when scheduler is started. They also should be executed in the * tasks when scheduler is started. They also should be executed in the
* order of their priorities. * order of their priorities.
*/ */
function testNewTasksMovedAndRunInPriorityOrder() { export function testNewTasksMovedAndRunInPriorityOrder() {
const fakeTask1 = newTask('task-1', 1); const fakeTask1 = newTask('task-1', 1);
const fakeTask2 = newTask('task-2', 0); const fakeTask2 = newTask('task-2', 0);
...@@ -87,7 +90,7 @@ function testNewTasksMovedAndRunInPriorityOrder() { ...@@ -87,7 +90,7 @@ function testNewTasksMovedAndRunInPriorityOrder() {
/** /**
* Checks that the scheduler only launches MAXIMUM_IN_PARALLEL tasks. * Checks that the scheduler only launches MAXIMUM_IN_PARALLEL tasks.
*/ */
function testParallelTasks() { export function testParallelTasks() {
const scheduler = new Scheduler(); const scheduler = new Scheduler();
const taskList = []; const taskList = [];
for (let i = 0; i <= Scheduler.MAXIMUM_IN_PARALLEL; ++i) { 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