Commit 3a213f73 authored by Trent Apted's avatar Trent Apted Committed by Commit Bot

Closure compile all but one js unittest in ui/file_manager/common

Adds
 - FileManagerJsTest.ImporterCommonTest
 - FileManagerJsTest.LRUCacheTest
 - FileManagerJsTest.AsyncUtilTest
 - FileManagerJsTest.FilesAppEntryTypes
 - FileManagerJsTest.UtilTest

Also adds test_importer_common.js to be typechecked, which isn't
itself a unit test. This exposed a weird dependency group on
ui/file_manager/exerns/volume_info.js - encapsulate those dependencies
as well as we can. Remove the dependency on cr.EventListenerType: it's
a @typedef {...|*} so adds no type safety and requires a dependency on
"//ui/webui/resources/js/cr:event_target" which is not an extern.

Bug: 860355
Cq-Include-Trybots: luci.chromium.try:closure_compilation
Change-Id: I479f8e7b22b56ea315c27fabc5e7ccdeb6277728
Reviewed-on: https://chromium-review.googlesource.com/c/1250762
Commit-Queue: Trent Apted <tapted@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#597017}
parent 27d5bb46
...@@ -46,8 +46,7 @@ IN_PROC_BROWSER_TEST_F(FileManagerJsTest, FileOperationManagerTest) { ...@@ -46,8 +46,7 @@ IN_PROC_BROWSER_TEST_F(FileManagerJsTest, FileOperationManagerTest) {
} }
IN_PROC_BROWSER_TEST_F(FileManagerJsTest, ImporterCommonTest) { IN_PROC_BROWSER_TEST_F(FileManagerJsTest, ImporterCommonTest) {
RunTest(base::FilePath( RunGeneratedTest("/common/js/importer_common_unittest.html");
FILE_PATH_LITERAL("common/js/importer_common_unittest.html")));
} }
IN_PROC_BROWSER_TEST_F(FileManagerJsTest, ImportHistoryTest) { IN_PROC_BROWSER_TEST_F(FileManagerJsTest, ImportHistoryTest) {
...@@ -76,8 +75,7 @@ IN_PROC_BROWSER_TEST_F(FileManagerJsTest, MediaScannerTest) { ...@@ -76,8 +75,7 @@ IN_PROC_BROWSER_TEST_F(FileManagerJsTest, MediaScannerTest) {
} }
IN_PROC_BROWSER_TEST_F(FileManagerJsTest, LRUCacheTest) { IN_PROC_BROWSER_TEST_F(FileManagerJsTest, LRUCacheTest) {
RunTest(base::FilePath( RunGeneratedTest("/common/js/lru_cache_unittest.html");
FILE_PATH_LITERAL("common/js/lru_cache_unittest.html")));
} }
IN_PROC_BROWSER_TEST_F(FileManagerJsTest, MediaImportHandlerTest) { IN_PROC_BROWSER_TEST_F(FileManagerJsTest, MediaImportHandlerTest) {
...@@ -101,8 +99,7 @@ IN_PROC_BROWSER_TEST_F(FileManagerJsTest, ImportControllerTest) { ...@@ -101,8 +99,7 @@ IN_PROC_BROWSER_TEST_F(FileManagerJsTest, ImportControllerTest) {
} }
IN_PROC_BROWSER_TEST_F(FileManagerJsTest, AsyncUtilTest) { IN_PROC_BROWSER_TEST_F(FileManagerJsTest, AsyncUtilTest) {
RunTest(base::FilePath( RunGeneratedTest("/common/js/async_util_unittest.html");
FILE_PATH_LITERAL("common/js/async_util_unittest.html")));
} }
// TODO(sashab): Re-enable when https://crbug.com/842880 is fixed. // TODO(sashab): Re-enable when https://crbug.com/842880 is fixed.
...@@ -210,12 +207,11 @@ IN_PROC_BROWSER_TEST_F(FileManagerJsTest, FileListSelectionModelTest) { ...@@ -210,12 +207,11 @@ IN_PROC_BROWSER_TEST_F(FileManagerJsTest, FileListSelectionModelTest) {
} }
IN_PROC_BROWSER_TEST_F(FileManagerJsTest, FilesAppEntryTypes) { IN_PROC_BROWSER_TEST_F(FileManagerJsTest, FilesAppEntryTypes) {
RunTest(base::FilePath( RunGeneratedTest("/common/js/files_app_entry_types_unittest.html");
FILE_PATH_LITERAL("common/js/files_app_entry_types_unittest.html")));
} }
IN_PROC_BROWSER_TEST_F(FileManagerJsTest, UtilTest) { IN_PROC_BROWSER_TEST_F(FileManagerJsTest, UtilTest) {
RunTest(base::FilePath(FILE_PATH_LITERAL("common/js/util_unittest.html"))); RunGeneratedTest("/common/js/util_unittest.html");
} }
IN_PROC_BROWSER_TEST_F(FileManagerJsTest, Crostini) { IN_PROC_BROWSER_TEST_F(FileManagerJsTest, Crostini) {
......
...@@ -51,6 +51,7 @@ group("closure_compile") { ...@@ -51,6 +51,7 @@ group("closure_compile") {
group("unit_test_data") { group("unit_test_data") {
deps = [ deps = [
"file_manager/common/js:unit_tests",
"file_manager/foreground/js:unit_tests", "file_manager/foreground/js:unit_tests",
"gallery/js:unit_tests", "gallery/js:unit_tests",
"gallery/js/image_editor:unit_tests", "gallery/js/image_editor:unit_tests",
......
...@@ -20,7 +20,6 @@ js_library("closure_compile_externs") { ...@@ -20,7 +20,6 @@ js_library("closure_compile_externs") {
"$externs_path/chrome_extensions.js", "$externs_path/chrome_extensions.js",
"$externs_path/metrics_private.js", "$externs_path/metrics_private.js",
"../../externs/audio_player_foreground.js", "../../externs/audio_player_foreground.js",
"../../externs/entry_location.js",
"../../externs/platform.js", "../../externs/platform.js",
"//third_party/analytics/externs.js", "//third_party/analytics/externs.js",
] ]
......
...@@ -15,18 +15,13 @@ js_type_check("closure_compile") { ...@@ -15,18 +15,13 @@ js_type_check("closure_compile") {
js_library("filtered_volume_manager") { js_library("filtered_volume_manager") {
deps = [ deps = [
"//ui/file_manager/externs:file_manager_private", "//ui/file_manager/externs:file_manager_private",
"//ui/file_manager/externs:volume_manager",
"//ui/file_manager/file_manager/common/js:async_util", "//ui/file_manager/file_manager/common/js:async_util",
"//ui/file_manager/file_manager/common/js:files_app_entry_types", "//ui/file_manager/file_manager/common/js:files_app_entry_types",
"//ui/file_manager/file_manager/common/js:volume_manager_common", "//ui/file_manager/file_manager/common/js:volume_manager_common",
"//ui/webui/resources/js:cr", "//ui/webui/resources/js:cr",
"//ui/webui/resources/js/cr:event_target",
"//ui/webui/resources/js/cr/ui:array_data_model", "//ui/webui/resources/js/cr/ui:array_data_model",
] ]
externs_list = [ externs_list =
"//ui/file_manager/externs/background/volume_manager_factory.js", [ "//ui/file_manager/externs/background/volume_manager_factory.js" ]
"//ui/file_manager/externs/entry_location.js",
"//ui/file_manager/externs/volume_info.js",
"//ui/file_manager/externs/volume_info_list.js",
"//ui/file_manager/externs/volume_manager.js",
]
} }
...@@ -28,3 +28,16 @@ js_library("file_manager_private") { ...@@ -28,3 +28,16 @@ js_library("file_manager_private") {
"$externs_path/file_system_provider.js", "$externs_path/file_system_provider.js",
] ]
} }
js_library("volume_manager") {
sources = []
# Encapsulate volume_manager.js and its dependencies. Note this should really
# depend on volume_manager_common.js as well, but that's not an extern.
externs_list = [
"entry_location.js",
"volume_info.js",
"volume_info_list.js",
"volume_manager.js",
]
}
...@@ -75,7 +75,7 @@ VolumeManager.prototype.getLocationInfo = function(entry) {}; ...@@ -75,7 +75,7 @@ VolumeManager.prototype.getLocationInfo = function(entry) {};
/** /**
* Adds an event listener to the target. * Adds an event listener to the target.
* @param {string} type The name of the event. * @param {string} type The name of the event.
* @param {EventListenerType} handler The handler for the event. This is * @param {function(!Event)} handler The handler for the event. This is
* called when the event is dispatched. * called when the event is dispatched.
*/ */
VolumeManager.prototype.addEventListener = function(type, handler) {}; VolumeManager.prototype.addEventListener = function(type, handler) {};
...@@ -83,7 +83,7 @@ VolumeManager.prototype.addEventListener = function(type, handler) {}; ...@@ -83,7 +83,7 @@ VolumeManager.prototype.addEventListener = function(type, handler) {};
/** /**
* Removes an event listener from the target. * Removes an event listener from the target.
* @param {string} type The name of the event. * @param {string} type The name of the event.
* @param {EventListenerType} handler The handler for the event. * @param {function(!Event)} handler The handler for the event.
*/ */
VolumeManager.prototype.removeEventListener = function(type, handler) {}; VolumeManager.prototype.removeEventListener = function(type, handler) {};
......
...@@ -3,14 +3,14 @@ ...@@ -3,14 +3,14 @@
# found in the LICENSE file. # found in the LICENSE file.
import("//third_party/closure_compiler/compile_js.gni") import("//third_party/closure_compiler/compile_js.gni")
import("//third_party/closure_compiler/js_unit_tests.gni")
# TODO(tapted): This entire folder should move to //ui/file_manager/base. # TODO(tapted): This entire folder should move to //ui/file_manager/base.
visibility = [ "//ui/file_manager/*" ] visibility = [ "//ui/file_manager/*" ]
js_type_check("closure_compile") { js_type_check("closure_compile_module") {
deps = [ deps = [
":async_util", ":async_util",
":closure_compile_externs",
":error_util", ":error_util",
":file_type", ":file_type",
":files_app_entry_types", ":files_app_entry_types",
...@@ -27,24 +27,34 @@ js_type_check("closure_compile") { ...@@ -27,24 +27,34 @@ js_type_check("closure_compile") {
] ]
} }
js_library("closure_compile_externs") { js_library("async_util") {
sources = []
externs_list = [
"../../../externs/background/file_browser_background.js",
"../../../externs/background_window.js",
]
} }
js_library("async_util") { js_library("async_util_unittest") {
deps = [
":async_util",
":unittest_util",
]
} }
js_library("error_util") { js_library("error_util") {
} }
js_library("files_app_entry_types") { js_library("files_app_entry_types") {
deps = [
"../../../externs:file_manager_private",
]
externs_list = [ "../../../externs/volume_info.js" ] externs_list = [ "../../../externs/volume_info.js" ]
} }
js_library("files_app_entry_types_unittest") {
deps = [
":files_app_entry_types",
":unittest_util",
":volume_manager_common",
]
}
js_library("file_type") { js_library("file_type") {
deps = [ deps = [
":files_app_entry_types", ":files_app_entry_types",
...@@ -52,20 +62,53 @@ js_library("file_type") { ...@@ -52,20 +62,53 @@ js_library("file_type") {
] ]
} }
# These importer files actually belong here. Nothing outside the Files app uses
# them, so restrict visibility. TODO(tapted): Simplify visibility when
# everything else moves to //ui/file_manager/base.
js_library("importer_common") { js_library("importer_common") {
visibility = []
visibility = [ "//ui/file_manager/file_manager/*" ]
deps = [ deps = [
":file_type", ":file_type",
":volume_manager_common", ":volume_manager_common",
"../../../externs:volume_manager",
] ]
externs_list = [ externs_list = [
"//third_party/analytics/externs.js",
"../../../externs/volume_info_list.js", "../../../externs/volume_info_list.js",
"../../../externs/volume_manager.js", "../../../externs/background_window.js",
"../../../externs/background/file_browser_background.js",
]
}
js_library("test_importer_common") {
deps = [
":importer_common",
":unittest_util",
]
visibility = []
visibility = [ "//ui/file_manager/file_manager/*" ]
}
js_library("importer_common_unittest") {
deps = [
":mock_entry",
":test_importer_common",
":util",
"//ui/file_manager/file_manager/background/js:mock_volume_manager",
] ]
} }
js_library("lru_cache") { js_library("lru_cache") {
} }
js_library("lru_cache_unittest") {
deps = [
":lru_cache",
"//ui/webui/resources/js:webui_resource_test",
]
}
js_library("metrics") { js_library("metrics") {
deps = [ deps = [
":metrics_base", ":metrics_base",
...@@ -122,8 +165,40 @@ js_library("util") { ...@@ -122,8 +165,40 @@ js_library("util") {
] ]
} }
js_library("util_unittest") {
deps = [
":mock_entry",
":unittest_util",
":util",
]
}
js_library("volume_manager_common") { js_library("volume_manager_common") {
deps = [ deps = [
"//ui/webui/resources/js:assert", "//ui/webui/resources/js:assert",
] ]
} }
js_unit_tests("unit_tests") {
deps = [
":async_util_unittest",
":files_app_entry_types_unittest",
":importer_common_unittest",
":lru_cache_unittest",
":util_unittest",
]
}
js_type_check("test_support_type_check") {
deps = [
":test_importer_common",
]
}
group("closure_compile") {
deps = [
":closure_compile_module",
":test_support_type_check",
":unit_tests_type_check",
]
}
<!-- Copyright 2014 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="async_util.js"></script>
<script src="unittest_util.js"></script>
<script src="async_util_unittest.js"></script>
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
/** /**
* @type {string} Result * @type {?string} Result
*/ */
var result; var result;
......
<!DOCTYPE html>
<!-- Copyright 2018 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.
-->
<html>
<body>
<script src="../../common/js/unittest_util.js"></script>
<script src="files_app_entry_types.js"></script>
<script src="volume_manager_common.js"></script>
<script src="files_app_entry_types_unittest.js"></script>
</body>
</html>
...@@ -4,9 +4,35 @@ ...@@ -4,9 +4,35 @@
'use strict'; 'use strict';
function notreached(error) {
assertTrue(false, 'NOTREACHED(): ' + (error.stack || error));
}
/**
* Creates a new volume with a single, mock VolumeEntry.
* @param {?VolumeManagerCommon.VolumeType} volumeType
* @param {DirectoryEntry=} displayRoot
* @param {Object=} additionalProperties
* @return {!VolumeEntry}
*/
function fakeVolumeEntry(volumeType, displayRoot, additionalProperties) {
const kLabel = 'Fake Filesystem';
if (displayRoot === undefined)
displayRoot = createFakeDisplayRoot();
let fakeVolumeInfo = {
displayRoot: displayRoot,
label: kLabel,
volumeType: volumeType
};
Object.assign(fakeVolumeInfo, additionalProperties || {});
// Create the VolumeEntry via casting (duck typing).
return new VolumeEntry(/** @type{!VolumeInfo} */ (fakeVolumeInfo));
}
/** Test constructor and default public attributes. */ /** Test constructor and default public attributes. */
function testEntryList(testReportCallback) { function testEntryList(testReportCallback) {
const entryList = new EntryList('My files', 'my_files'); const entryList =
new EntryList('My files', VolumeManagerCommon.RootType.MY_FILES);
assertEquals('My files', entryList.label); assertEquals('My files', entryList.label);
assertEquals('entry-list://my_files', entryList.toURL()); assertEquals('entry-list://my_files', entryList.toURL());
assertEquals('my_files', entryList.rootType); assertEquals('my_files', entryList.rootType);
...@@ -15,7 +41,8 @@ function testEntryList(testReportCallback) { ...@@ -15,7 +41,8 @@ function testEntryList(testReportCallback) {
assertTrue(entryList.isDirectory); assertTrue(entryList.isDirectory);
assertFalse(entryList.isFile); assertFalse(entryList.isFile);
entryList.addEntry(new EntryList('Child Entry', 'child_entry')); entryList.addEntry(
new EntryList('Child Entry', VolumeManagerCommon.RootType.MY_FILES));
assertEquals(1, entryList.children.length); assertEquals(1, entryList.children.length);
const reader = entryList.createReader(); const reader = entryList.createReader();
...@@ -28,11 +55,11 @@ function testEntryList(testReportCallback) { ...@@ -28,11 +55,11 @@ function testEntryList(testReportCallback) {
callCounter++; callCounter++;
if (readerResult.length > 0) { if (readerResult.length > 0) {
resultCouter++; resultCouter++;
reader.readEntries(accumulateResults); reader.readEntries(accumulateResults, () => {});
} }
}; };
reader.readEntries(accumulateResults); reader.readEntries(accumulateResults, () => {});
// readEntries runs asynchronously, so let's wait it to be called. // readEntries runs asynchronously, so let's wait it to be called.
reportPromise( reportPromise(
waitUntil(() => { waitUntil(() => {
...@@ -48,29 +75,25 @@ function testEntryList(testReportCallback) { ...@@ -48,29 +75,25 @@ function testEntryList(testReportCallback) {
/** Tests method EntryList.getParent. */ /** Tests method EntryList.getParent. */
function testEntryListGetParent(testReportCallback) { function testEntryListGetParent(testReportCallback) {
const entryList = new EntryList('My files', 'my_files'); const entryList =
new EntryList('My files', VolumeManagerCommon.RootType.MY_FILES);
let callbackTriggered = false; let callbackTriggered = false;
entryList.getParent(parentEntry => { entryList.getParent(parentEntry => {
// EntryList should return itself since it's a root and that's what the web // EntryList should return itself since it's a root and that's what the web
// spec says. // spec says.
callbackTriggered = true; callbackTriggered = true;
assertEquals(parentEntry, entryList); assertEquals(parentEntry, entryList);
}); }, notreached /* error */);
reportPromise(waitUntil(() => callbackTriggered), testReportCallback); reportPromise(waitUntil(() => callbackTriggered), testReportCallback);
} }
/** Tests method EntryList.addEntry. */ /** Tests method EntryList.addEntry. */
function testEntryListAddEntry() { function testEntryListAddEntry() {
const entryList = new EntryList('My files'); const entryList =
new EntryList('My files', VolumeManagerCommon.RootType.MY_FILES);
assertEquals(0, entryList.children.length); assertEquals(0, entryList.children.length);
const fakeRootEntry = createFakeDisplayRoot(); const childEntry = fakeVolumeEntry(VolumeManagerCommon.VolumeType.DOWNLOADS);
const fakeVolumeInfo = {
displayRoot: fakeRootEntry,
label: 'Fake Filesystem',
volumeType: VolumeManagerCommon.VolumeType.DOWNLOADS,
};
const childEntry = new VolumeEntry(fakeVolumeInfo);
entryList.addEntry(childEntry); entryList.addEntry(childEntry);
assertEquals(1, entryList.children.length); assertEquals(1, entryList.children.length);
assertEquals(childEntry, entryList.children[0]); assertEquals(childEntry, entryList.children[0]);
...@@ -78,14 +101,10 @@ function testEntryListAddEntry() { ...@@ -78,14 +101,10 @@ function testEntryListAddEntry() {
/** Tests methods to remove entries. */ /** Tests methods to remove entries. */
function testEntryListRemoveEntry() { function testEntryListRemoveEntry() {
const entryList = new EntryList('My files'); const entryList =
new EntryList('My files', VolumeManagerCommon.RootType.MY_FILES);
const fakeRootEntry = createFakeDisplayRoot(); const childEntry = fakeVolumeEntry(VolumeManagerCommon.VolumeType.DOWNLOADS);
const fakeVolumeInfo = {
displayRoot: fakeRootEntry,
label: 'Fake Filesystem',
};
const childEntry = new VolumeEntry(fakeVolumeInfo);
entryList.addEntry(childEntry); entryList.addEntry(childEntry);
assertTrue(entryList.removeEntry(childEntry)); assertTrue(entryList.removeEntry(childEntry));
assertEquals(0, entryList.children.length); assertEquals(0, entryList.children.length);
...@@ -95,39 +114,27 @@ function testEntryListRemoveEntry() { ...@@ -95,39 +114,27 @@ function testEntryListRemoveEntry() {
* Tests methods findIndexByVolumeInfo, removeByVolumeType, removeByRootType. * Tests methods findIndexByVolumeInfo, removeByVolumeType, removeByRootType.
*/ */
function testEntryFindIndex() { function testEntryFindIndex() {
const entryList = new EntryList('My files'); const entryList =
new EntryList('My files', VolumeManagerCommon.RootType.MY_FILES);
const fakeRootEntry = createFakeDisplayRoot(); const downloads = fakeVolumeEntry(VolumeManagerCommon.VolumeType.DOWNLOADS);
const downloadsVolumeInfo = { const crostini = fakeVolumeEntry(VolumeManagerCommon.VolumeType.CROSTINI);
displayRoot: fakeRootEntry,
label: 'Fake Filesystem',
volumeType: VolumeManagerCommon.VolumeType.DOWNLOADS,
};
const downloads = new VolumeEntry(downloadsVolumeInfo);
const crostiniRootEntry = createFakeDisplayRoot(); const fakeEntry = /** @type{!Entry} */ ({
const crostiniVolumeInfo = {
displayRoot: crostiniRootEntry,
label: 'Fake Filesystem',
volumeType: VolumeManagerCommon.VolumeType.CROSTINI,
};
const crostini = new VolumeEntry(crostiniVolumeInfo);
const fakeEntry = {
isDirectory: true, isDirectory: true,
rootType: VolumeManagerCommon.RootType.CROSTINI, rootType: VolumeManagerCommon.RootType.CROSTINI,
name: 'Linux files', name: 'Linux files',
toURL: function() { toURL: function() {
return 'fake-entry://linux-files'; return 'fake-entry://linux-files';
} }
}; });
entryList.addEntry(downloads); entryList.addEntry(downloads);
entryList.addEntry(crostini); entryList.addEntry(crostini);
// Test findIndexByVolumeInfo. // Test findIndexByVolumeInfo.
assertEquals(0, entryList.findIndexByVolumeInfo(downloadsVolumeInfo)); assertEquals(0, entryList.findIndexByVolumeInfo(downloads.volumeInfo));
assertEquals(1, entryList.findIndexByVolumeInfo(crostiniVolumeInfo)); assertEquals(1, entryList.findIndexByVolumeInfo(crostini.volumeInfo));
// Test removeByVolumeType. // Test removeByVolumeType.
assertTrue( assertTrue(
...@@ -145,12 +152,13 @@ function testEntryFindIndex() { ...@@ -145,12 +152,13 @@ function testEntryFindIndex() {
/** Tests method EntryList.getMetadata. */ /** Tests method EntryList.getMetadata. */
function testEntryListGetMetadata(testReportCallback) { function testEntryListGetMetadata(testReportCallback) {
const entryList = new EntryList('My files'); const entryList =
new EntryList('My files', VolumeManagerCommon.RootType.MY_FILES);
let modificationTime = null; let modificationTime = null;
entryList.getMetadata(metadata => { entryList.getMetadata(metadata => {
modificationTime = metadata.modificationTime; modificationTime = metadata.modificationTime;
}); }, notreached /* error */);
// getMetadata runs asynchronously, so let's wait it to be called. // getMetadata runs asynchronously, so let's wait it to be called.
reportPromise( reportPromise(
...@@ -176,10 +184,10 @@ function testStaticReader(testReportCallback) { ...@@ -176,10 +184,10 @@ function testStaticReader(testReportCallback) {
// merge on testResults. // merge on testResults.
readerResult.map(f => testResults.push(f)); readerResult.map(f => testResults.push(f));
if (readerResult.length > 0) if (readerResult.length > 0)
reader.readEntries(accumulateResults); reader.readEntries(accumulateResults, () => {});
}; };
reader.readEntries(accumulateResults); reader.readEntries(accumulateResults, () => {});
// readEntries runs asynchronously, so let's wait it to be called. // readEntries runs asynchronously, so let's wait it to be called.
reportPromise( reportPromise(
waitUntil(() => { waitUntil(() => {
...@@ -226,13 +234,9 @@ function createFakeDisplayRoot() { ...@@ -226,13 +234,9 @@ function createFakeDisplayRoot() {
*/ */
function testVolumeEntry() { function testVolumeEntry() {
const fakeRootEntry = createFakeDisplayRoot(); const fakeRootEntry = createFakeDisplayRoot();
const fakeVolumeInfo = { const volumeEntry =
displayRoot: fakeRootEntry, fakeVolumeEntry(VolumeManagerCommon.VolumeType.DOWNLOADS, fakeRootEntry);
label: 'Fake Filesystem',
volumeType: VolumeManagerCommon.VolumeType.DOWNLOADS,
};
const volumeEntry = new VolumeEntry(fakeVolumeInfo);
assertEquals(fakeRootEntry, volumeEntry.rootEntry); assertEquals(fakeRootEntry, volumeEntry.rootEntry);
assertEquals(VolumeManagerCommon.VolumeType.DOWNLOADS, volumeEntry.iconName); assertEquals(VolumeManagerCommon.VolumeType.DOWNLOADS, volumeEntry.iconName);
assertEquals('fake-filesystem://', volumeEntry.filesystem); assertEquals('fake-filesystem://', volumeEntry.filesystem);
...@@ -251,19 +255,17 @@ function testVolumeEntry() { ...@@ -251,19 +255,17 @@ function testVolumeEntry() {
function testVolumeEntryDelayedDisplayRoot(testReportCallback) { function testVolumeEntryDelayedDisplayRoot(testReportCallback) {
let callbackTriggered = false; let callbackTriggered = false;
const fakeRootEntry = createFakeDisplayRoot(); const fakeRootEntry = createFakeDisplayRoot();
// A VolumeInfo without displayRoot.
const fakeVolumeInfo = { // Create an entry using a VolumeInfo without displayRoot.
displayRoot: null, const volumeEntry = fakeVolumeEntry(null, null, {
label: 'Fake Filesystem',
resolveDisplayRoot: function(successCallback, errorCallback) { resolveDisplayRoot: function(successCallback, errorCallback) {
setTimeout(() => { setTimeout(() => {
successCallback(fakeRootEntry); successCallback(fakeRootEntry);
callbackTriggered = true; callbackTriggered = true;
}, 0); }, 0);
}, }
}; });
const volumeEntry = new VolumeEntry(fakeVolumeInfo);
// rootEntry starts as null. // rootEntry starts as null.
assertEquals(null, volumeEntry.rootEntry); assertEquals(null, volumeEntry.rootEntry);
reportPromise( reportPromise(
...@@ -275,36 +277,24 @@ function testVolumeEntryDelayedDisplayRoot(testReportCallback) { ...@@ -275,36 +277,24 @@ function testVolumeEntryDelayedDisplayRoot(testReportCallback) {
} }
/** Tests VolumeEntry.getParent */ /** Tests VolumeEntry.getParent */
function testVolumeEntryGetParent(testReportCallback) { function testVolumeEntryGetParent(testReportCallback) {
const fakeRootEntry = createFakeDisplayRoot(); const volumeEntry = fakeVolumeEntry(null);
const fakeVolumeInfo = {
displayRoot: fakeRootEntry,
label: 'Fake Filesystem',
};
const volumeEntry = new VolumeEntry(fakeVolumeInfo);
let callbackTriggered = false; let callbackTriggered = false;
volumeEntry.getParent(parentEntry => { volumeEntry.getParent(parentEntry => {
callbackTriggered = true; callbackTriggered = true;
// VolumeEntry should return itself since it's a root and that's what the // VolumeEntry should return itself since it's a root and that's what the
// web spec says. // web spec says.
assertEquals(parentEntry, volumeEntry); assertEquals(parentEntry, volumeEntry);
}); }, notreached /* error */);
reportPromise(waitUntil(() => callbackTriggered), testReportCallback); reportPromise(waitUntil(() => callbackTriggered), testReportCallback);
} }
/** Tests VolumeEntry.getMetadata */ /** Tests VolumeEntry.getMetadata */
function testVolumeEntryGetMetadata(testReportCallback) { function testVolumeEntryGetMetadata(testReportCallback) {
const fakeRootEntry = createFakeDisplayRoot(); const volumeEntry = fakeVolumeEntry(null);
const fakeVolumeInfo = {
displayRoot: fakeRootEntry,
label: 'Fake Filesystem',
};
const volumeEntry = new VolumeEntry(fakeVolumeInfo);
let modificationTime = null; let modificationTime = null;
volumeEntry.getMetadata(metadata => { volumeEntry.getMetadata(metadata => {
modificationTime = metadata.modificationTime; modificationTime = metadata.modificationTime;
}); }, notreached /* error */);
// getMetadata runs asynchronously, so let's wait it to be called. // getMetadata runs asynchronously, so let's wait it to be called.
reportPromise( reportPromise(
...@@ -324,13 +314,9 @@ function testVolumeEntryGetMetadata(testReportCallback) { ...@@ -324,13 +314,9 @@ function testVolumeEntryGetMetadata(testReportCallback) {
* Test EntryList.addEntry sets prefix on VolumeEntry. * Test EntryList.addEntry sets prefix on VolumeEntry.
*/ */
function testEntryListAddEntrySetsPrefix() { function testEntryListAddEntrySetsPrefix() {
const fakeRootEntry = createFakeDisplayRoot(); const volumeEntry = fakeVolumeEntry(null);
const fakeVolumeInfo = { const entryList =
displayRoot: fakeRootEntry, new EntryList('My files', VolumeManagerCommon.RootType.MY_FILES);
label: 'Fake Filesystem',
};
const volumeEntry = new VolumeEntry(fakeVolumeInfo);
const entryList = new EntryList('My files', 'my_files');
entryList.addEntry(volumeEntry); entryList.addEntry(volumeEntry);
assertEquals(1, entryList.children.length); assertEquals(1, entryList.children.length);
...@@ -343,9 +329,9 @@ function testEntryListAddEntrySetsPrefix() { ...@@ -343,9 +329,9 @@ function testEntryListAddEntrySetsPrefix() {
*/ */
function testFakeEntry(testReportCallback) { function testFakeEntry(testReportCallback) {
let fakeEntry = let fakeEntry =
new FakeEntry('label', VolumeManagerCommon.RootType.CROSTINI, true, null); new FakeEntry('label', VolumeManagerCommon.RootType.CROSTINI, true);
assertEquals(null, fakeEntry.sourceRestriction); assertEquals(undefined, fakeEntry.sourceRestriction);
assertEquals('FakeEntry', fakeEntry.type_name); assertEquals('FakeEntry', fakeEntry.type_name);
assertEquals('label', fakeEntry.label); assertEquals('label', fakeEntry.label);
assertEquals('label', fakeEntry.name); assertEquals('label', fakeEntry.name);
...@@ -357,25 +343,28 @@ function testFakeEntry(testReportCallback) { ...@@ -357,25 +343,28 @@ function testFakeEntry(testReportCallback) {
assertFalse(fakeEntry.isFile); assertFalse(fakeEntry.isFile);
// Check the isDirectory and sourceRestriction constructor args. // Check the isDirectory and sourceRestriction constructor args.
const kSourceRestriction =
/** @type{chrome.fileManagerPrivate.SourceRestriction} */ ('fake');
fakeEntry = new FakeEntry( fakeEntry = new FakeEntry(
'label', VolumeManagerCommon.RootType.CROSTINI, false, 'label', VolumeManagerCommon.RootType.CROSTINI, false,
AllowedPaths.NATIVE_PATH); kSourceRestriction);
assertEquals(AllowedPaths.NATIVE_PATH, fakeEntry.sourceRestriction); assertEquals(kSourceRestriction, fakeEntry.sourceRestriction);
assertFalse(fakeEntry.isDirectory); assertFalse(fakeEntry.isDirectory);
assertTrue(fakeEntry.isFile); assertTrue(fakeEntry.isFile);
let callCounter = 0; let callCounter = 0;
fakeEntry.getMetadata((metadata) => { fakeEntry.getMetadata((metadata) => {
// Returns empty metadata {}. // Returns empty (but non-null) metadata {}.
assert(metadata);
assertEquals(0, Object.keys(metadata).length); assertEquals(0, Object.keys(metadata).length);
callCounter++; callCounter++;
}); }, notreached /* error */);
fakeEntry.getParent((parentEntry) => { fakeEntry.getParent((parentEntry) => {
// Should return itself. // Should return itself.
assertEquals(fakeEntry, parentEntry); assertEquals(fakeEntry, parentEntry);
callCounter++; callCounter++;
}); }, notreached /* error */);
reportPromise( reportPromise(
waitUntil(() => { waitUntil(() => {
......
<!DOCTYPE html>
<!-- Copyright 2014 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.
-->
<html>
<body>
<script src="../../../../../ui/webui/resources/js/cr.js"></script>
<script src="../../../../../ui/webui/resources/js/cr/event_target.js"></script>
<script src="../../../../../ui/webui/resources/js/cr/ui/array_data_model.js"></script>
<script src="../../../../../ui/webui/resources/js/load_time_data.js"></script>
<script src="volume_manager_common.js"></script>
<script src="files_app_entry_types.js"></script>
<script src="../../common/js/lru_cache.js"></script>
<script src="../../background/js/entry_location_impl.js"></script>
<script src="../../background/js/metadata_proxy.js"></script>
<script src="../../background/js/mock_file_operation_manager.js"></script>
<script src="../../background/js/mock_media_scanner.js"></script>
<script src="../../background/js/volume_info_impl.js"></script>
<script src="../../background/js/volume_info_list_impl.js"></script>
<script src="../../background/js/volume_manager_factory.js"></script>
<script src="../../background/js/volume_manager_impl.js"></script>
<script src="../../background/js/volume_manager_util.js"></script>
<script src="../../background/js/mock_volume_manager.js"></script>
<script src="unittest_util.js"></script>
<script src="test_importer_common.js"></script>
<script src="mock_entry.js"></script>
<script src="async_util.js"></script>
<script src="file_type.js"></script>
<script src="util.js"></script>
<script src="importer_common.js"></script>
<script src="importer_common_unittest.js"></script>
</body>
</html>
...@@ -3,28 +3,28 @@ ...@@ -3,28 +3,28 @@
// found in the LICENSE file. // found in the LICENSE file.
/** @type {!MockVolumeManager} */ /** @type {!MockVolumeManager} */
var volumeManager; let volumeManager;
/** @type {!VolumeInfo} */ /** @type {!VolumeInfo} */
var cameraVolume; let cameraVolume;
/** @type {!VolumeInfo} */ /** @type {!VolumeInfo} */
var sdVolume; let sdVolume;
/** @type {!VolumeInfo} */ /** @type {VolumeInfo} */
var driveVolume; let driveVolume;
/** @type {!MockFileEntry} */ /** @type {!MockFileEntry} */
var cameraFileEntry; let cameraFileEntry;
/** @type {!MockFileEntry} */ /** @type {!MockFileEntry} */
var rawFileEntry; let rawFileEntry;
/** @type {!MockFileEntry} */ /** @type {!MockFileEntry} */
var sdFileEntry; let sdFileEntry;
/** @type {!MockFileEntry} */ /** @type {!MockFileEntry} */
var driveFileEntry; let driveFileEntry;
// Sadly, boilerplate setup necessary to include test support classes. // Sadly, boilerplate setup necessary to include test support classes.
loadTimeData.data = { loadTimeData.data = {
...@@ -204,7 +204,7 @@ function testRotateLogs(callback) { ...@@ -204,7 +204,7 @@ function testRotateLogs(callback) {
// Verify the *active* log is deleted. // Verify the *active* log is deleted.
assertEquals(0, fileName.search(/[0-9]{6}-import-debug-0.log/), assertEquals(0, fileName.search(/[0-9]{6}-import-debug-0.log/),
'Filename (' + fileName + ') does not match next pattern.'); 'Filename (' + fileName + ') does not match next pattern.');
driveFileEntry.assertRemoved(); driveFileEntry.asMock().assertRemoved();
return importer.ChromeLocalStorage.getInstance() return importer.ChromeLocalStorage.getInstance()
.get(importer.Setting.LAST_KNOWN_LOG_ID) .get(importer.Setting.LAST_KNOWN_LOG_ID)
...@@ -216,10 +216,16 @@ function testRotateLogs(callback) { ...@@ -216,10 +216,16 @@ function testRotateLogs(callback) {
function testRotateLogs_RemembersInitialActiveLog(callback) { function testRotateLogs_RemembersInitialActiveLog(callback) {
var nextLogId = 1; var nextLogId = 1;
var fileFactory = assertFalse; // Should not be called.
var promise = importer.rotateLogs(nextLogId, assertFalse) // Should not be called.
.then( var fileFactory = (namePromise) => {
function() { assertFalse(true);
return Promise.resolve();
};
var promise =
importer.rotateLogs(nextLogId, fileFactory)
.then(function() {
return importer.ChromeLocalStorage.getInstance() return importer.ChromeLocalStorage.getInstance()
.get(importer.Setting.LAST_KNOWN_LOG_ID) .get(importer.Setting.LAST_KNOWN_LOG_ID)
.then(assertEquals.bind(null, nextLogId)); .then(assertEquals.bind(null, nextLogId));
...@@ -244,7 +250,7 @@ function testDeflateAppUrl() { ...@@ -244,7 +250,7 @@ function testDeflateAppUrl() {
// And finally that we can reconstitute the original. // And finally that we can reconstitute the original.
assertEquals(url, importer.inflateAppUrl(deflated), assertEquals(url, importer.inflateAppUrl(deflated),
'Deflated then inflated URLs must match original URL.'); 'Deflated then inflated URLs must match original URL.');
}; }
function testHasMediaDirectory(callback) { function testHasMediaDirectory(callback) {
var dir = createDirectoryEntry(sdVolume, '/DCIM'); var dir = createDirectoryEntry(sdVolume, '/DCIM');
...@@ -267,12 +273,11 @@ function assertIsNotMediaDir(path) { ...@@ -267,12 +273,11 @@ function assertIsNotMediaDir(path) {
} }
function createFileEntry(volume, path) { function createFileEntry(volume, path) {
var entry = new MockFileEntry( var entry =
volume.fileSystem, new MockFileEntry(volume.fileSystem, path, /** @type{Metadata} */ ({
path, { size: 1234,
size: 1234, modificationTime: new Date().toString()
modificationTime: new Date().toString() }));
});
// Ensure the file entry has a volumeID...necessary for lookups // Ensure the file entry has a volumeID...necessary for lookups
// via the VolumeManager. // via the VolumeManager.
entry.volumeId = volume.volumeId; entry.volumeId = volume.volumeId;
......
<!DOCTYPE html>
<!-- Copyright 2014 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.
-->
<html>
<body>
<script src="lru_cache.js"></script>
<script src="lru_cache_unittest.js"></script>
</body>
</html>
...@@ -281,6 +281,15 @@ MockFileEntry.prototype.clone = function(path, opt_filesystem) { ...@@ -281,6 +281,15 @@ MockFileEntry.prototype.clone = function(path, opt_filesystem) {
opt_filesystem || this.filesystem, path, this.metadata, this.content); opt_filesystem || this.filesystem, path, this.metadata, this.content);
}; };
/**
* Helper to expose methods mixed in via MockEntry to the type checker.
*
* @return {!MockEntry}
*/
MockFileEntry.prototype.asMock = function() {
return /** @type{!MockEntry} */ (/** @type(*) */ (this));
};
/** /**
* Mock class for DirectoryEntry. * Mock class for DirectoryEntry.
* *
......
...@@ -9,6 +9,7 @@ var importer = importer || {}; ...@@ -9,6 +9,7 @@ var importer = importer || {};
* Sets up a logger for use in unit tests. The test logger doesn't attempt to * Sets up a logger for use in unit tests. The test logger doesn't attempt to
* access chrome's sync file system. Call this during setUp. * access chrome's sync file system. Call this during setUp.
* @return {!importer.TestLogger} * @return {!importer.TestLogger}
* @suppress{accessControls} For testing.
*/ */
importer.setupTestLogger = function() { importer.setupTestLogger = function() {
var logger = new importer.TestLogger(); var logger = new importer.TestLogger();
......
...@@ -101,11 +101,11 @@ function TestCallRecorder() { ...@@ -101,11 +101,11 @@ function TestCallRecorder() {
this.calls_ = []; this.calls_ = [];
/** /**
* The recording funciton. Bound in our constructor to ensure we always * The recording function. Bound in our constructor to ensure we always
* return the same object. This is necessary as some clients may make use * return the same object. This is necessary as some clients may make use
* of object equality. * of object equality.
* *
* @type {function()} * @type {function(*)}
*/ */
this.callback = this.recordArguments_.bind(this); this.callback = this.recordArguments_.bind(this);
} }
......
<!DOCTYPE html>
<!-- Copyright 2018 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.
-->
<html>
<body>
<script src="mock_entry.js"></script>
<script src="util.js"></script>
<script src="util_unittest.js"></script>
</body>
</html>
...@@ -148,10 +148,7 @@ js_library("metadata_model") { ...@@ -148,10 +148,7 @@ js_library("metadata_model") {
":metadata_provider", ":metadata_provider",
":multi_metadata_provider", ":multi_metadata_provider",
"../../../common/js:util", "../../../common/js:util",
] "//ui/file_manager/externs:volume_manager",
externs_list = [
"../../../../externs/volume_info_list.js",
"../../../../externs/volume_manager.js",
] ]
} }
...@@ -190,8 +187,8 @@ js_library("multi_metadata_provider") { ...@@ -190,8 +187,8 @@ js_library("multi_metadata_provider") {
":external_metadata_provider", ":external_metadata_provider",
":file_system_metadata_provider", ":file_system_metadata_provider",
":metadata_provider", ":metadata_provider",
"//ui/file_manager/externs:volume_manager",
] ]
externs_list = [ "../../../../externs/volume_manager.js" ]
} }
js_library("thumbnail_model") { js_library("thumbnail_model") {
......
...@@ -59,7 +59,6 @@ js_library("closure_compile_externs") { ...@@ -59,7 +59,6 @@ js_library("closure_compile_externs") {
"../../../../externs/css_rule.js", "../../../../externs/css_rule.js",
"../../../../externs/drag_target.js", "../../../../externs/drag_target.js",
"../../../../externs/entries_changed_event.js", "../../../../externs/entries_changed_event.js",
"../../../../externs/entry_location.js",
"../../../../externs/gallery_foreground.js", "../../../../externs/gallery_foreground.js",
"../../../../externs/menu_item_update_event.js", "../../../../externs/menu_item_update_event.js",
"../../../../externs/paper_elements.js", "../../../../externs/paper_elements.js",
...@@ -308,8 +307,8 @@ js_library("location_line") { ...@@ -308,8 +307,8 @@ js_library("location_line") {
"../../../common/js:metrics", "../../../common/js:metrics",
"../../../common/js:util", "../../../common/js:util",
"../../../common/js:volume_manager_common", "../../../common/js:volume_manager_common",
"//ui/file_manager/externs:volume_manager",
] ]
externs_list = [ "../../../../externs/volume_manager.js" ]
} }
js_library("multi_profile_share_dialog") { js_library("multi_profile_share_dialog") {
......
...@@ -135,10 +135,7 @@ js_library("gallery_util") { ...@@ -135,10 +135,7 @@ js_library("gallery_util") {
"../../file_manager/common/js:file_type", "../../file_manager/common/js:file_type",
"../../file_manager/common/js:util", "../../file_manager/common/js:util",
"../../file_manager/common/js:volume_manager_common", "../../file_manager/common/js:volume_manager_common",
] "//ui/file_manager/externs:volume_manager",
externs_list = [
"../../externs/volume_manager.js",
"../../externs/volume_info_list.js",
] ]
} }
......
...@@ -23,7 +23,6 @@ js_library("closure_compile_externs") { ...@@ -23,7 +23,6 @@ js_library("closure_compile_externs") {
"$externs_path/media_player_private.js", "$externs_path/media_player_private.js",
"$externs_path/metrics_private.js", "$externs_path/metrics_private.js",
"../../externs/chrome_cast.js", "../../externs/chrome_cast.js",
"../../externs/entry_location.js",
"../../externs/platform.js", "../../externs/platform.js",
"//third_party/analytics/externs.js", "//third_party/analytics/externs.js",
] ]
......
...@@ -23,11 +23,7 @@ js_library("closure_compile_externs") { ...@@ -23,11 +23,7 @@ js_library("closure_compile_externs") {
"../../../externs/app_window_common.js", "../../../externs/app_window_common.js",
"../../../externs/background/volume_manager_factory.js", "../../../externs/background/volume_manager_factory.js",
"../../../externs/chrome_cast.js", "../../../externs/chrome_cast.js",
"../../../externs/entry_location.js",
"../../../externs/platform.js", "../../../externs/platform.js",
"../../../externs/volume_info.js",
"../../../externs/volume_info_list.js",
"../../../externs/volume_manager.js",
"//third_party/analytics/externs.js", "//third_party/analytics/externs.js",
] ]
} }
......
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