Commit 4ca8b958 authored by Noel Gordon's avatar Noel Gordon Committed by Commit Bot

Prepare to Closure compile Crostini unittest

 - add Closure @type annotations to unittest JS types
 - add setUp(), add setDriveFsEnabled() helpers
 - prefix test cases with a descriptive comment

No change in test behavior, no new tests.

Bug: 911024
Change-Id: Iaa1bcf5b4ab00d7e2c89875361ff14b1dee03a00
Reviewed-on: https://chromium-review.googlesource.com/c/1358316
Commit-Queue: Noel Gordon <noel@chromium.org>
Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#613058}
parent 5d23d73c
...@@ -2,29 +2,67 @@ ...@@ -2,29 +2,67 @@
// 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';
/**
* Mock metrics.
* @type {!Object}
*/
window.metrics = { window.metrics = {
recordSmallCount: function() {}, recordSmallCount: function() {},
}; };
window.loadTimeData = { /** @type {!VolumeManagerCommon.RootType<string>} */
data: {'DRIVE_FS_ENABLED': false}, let volumeManagerRootType;
/** @type {!VolumeManager} */
let volumeManager;
/** @type {!Crostini} */
let crostini;
// Set up the test components.
function setUp() {
// Mock LoadTimeData strings.
window.loadTimeData = {
data: {
'DRIVE_FS_ENABLED': false,
},
getBoolean: function(key) { getBoolean: function(key) {
return window.loadTimeData.data[key]; return window.loadTimeData.data[key];
}, },
getString: id => id, getString: id => id,
}; };
let volumeManagerRootType = 'testroot'; // Create a fake volume manager that provides entry location info.
const volumeManager = /** @type {!VolumeManager} */ ({ volumeManager = /** @type {!VolumeManager} */ ({
getLocationInfo: (entry) => { getLocationInfo: (entry) => {
return {rootType: volumeManagerRootType}; return /** @type {!EntryLocation} */ ({
rootType: volumeManagerRootType,
});
}, },
}); });
// Reset initial root type.
volumeManagerRootType =
/** @type {!VolumeManagerCommon.RootType<string>} */ ('testroot');
const crostini = new Crostini(); // Create and initialize Crostini.
crostini.init(volumeManager); crostini = new Crostini();
crostini.init(volumeManager);
}
/**
* Sets the DriveFs enabled state.
* @param {boolean} enabled
*/
function setDriveFsEnabled(enabled) {
window.loadTimeData.data['DRIVE_FS_ENABLED'] = enabled;
}
/**
* Tests path sharing.
*/
function testIsPathShared() { function testIsPathShared() {
const mockFileSystem = new MockFileSystem('volumeId'); const mockFileSystem = new MockFileSystem('volumeId');
const root = new MockDirectoryEntry(mockFileSystem, '/'); const root = new MockDirectoryEntry(mockFileSystem, '/');
...@@ -83,6 +121,9 @@ function testIsPathShared() { ...@@ -83,6 +121,9 @@ function testIsPathShared() {
assertFalse(crostini.isPathShared(b)); assertFalse(crostini.isPathShared(b));
} }
/*
* Tests disallowed and allowed shared paths.
*/
function testCanSharePath() { function testCanSharePath() {
crostini.setEnabled(true); crostini.setEnabled(true);
...@@ -93,11 +134,13 @@ function testCanSharePath() { ...@@ -93,11 +134,13 @@ function testCanSharePath() {
const fooFile = new MockEntry(mockFileSystem, '/foo/file'); const fooFile = new MockEntry(mockFileSystem, '/foo/file');
const fooFolder = new MockDirectoryEntry(mockFileSystem, '/foo/folder'); const fooFolder = new MockDirectoryEntry(mockFileSystem, '/foo/folder');
window.loadTimeData.data['DRIVE_FS_ENABLED'] = false; // Test with DriveFs disabled.
setDriveFsEnabled(false);
const disallowed = new Map(Crostini.VALID_DRIVE_FS_ROOT_TYPES_FOR_SHARE); const disallowed = new Map(Crostini.VALID_DRIVE_FS_ROOT_TYPES_FOR_SHARE);
disallowed.set('test', 'test'); disallowed.set('test', 'test');
for (let type of disallowed.keys()) { for (let type of disallowed.keys()) {
volumeManagerRootType = type; volumeManagerRootType =
/** @type {!VolumeManagerCommon.RootType<string>} */ (type);
assertFalse(crostini.canSharePath(root, true)); assertFalse(crostini.canSharePath(root, true));
assertFalse(crostini.canSharePath(root, false)); assertFalse(crostini.canSharePath(root, false));
assertFalse(crostini.canSharePath(rootFile, true)); assertFalse(crostini.canSharePath(rootFile, true));
...@@ -110,7 +153,8 @@ function testCanSharePath() { ...@@ -110,7 +153,8 @@ function testCanSharePath() {
assertFalse(crostini.canSharePath(fooFolder, false)); assertFalse(crostini.canSharePath(fooFolder, false));
} }
window.loadTimeData.data['DRIVE_FS_ENABLED'] = true; // Test with DriveFs enabled.
setDriveFsEnabled(true);
const allowed = new Map([ const allowed = new Map([
...Crostini.VALID_ROOT_TYPES_FOR_SHARE, ...Crostini.VALID_ROOT_TYPES_FOR_SHARE,
...Crostini.VALID_DRIVE_FS_ROOT_TYPES_FOR_SHARE ...Crostini.VALID_DRIVE_FS_ROOT_TYPES_FOR_SHARE
......
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