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 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
'use strict';
/**
* Mock metrics.
* @type {!Object}
*/
window.metrics = {
recordSmallCount: function() {},
};
window.loadTimeData = {
data: {'DRIVE_FS_ENABLED': false},
getBoolean: function(key) {
return window.loadTimeData.data[key];
},
getString: id => id,
};
/** @type {!VolumeManagerCommon.RootType<string>} */
let volumeManagerRootType;
/** @type {!VolumeManager} */
let volumeManager;
let volumeManagerRootType = 'testroot';
const volumeManager = /** @type {!VolumeManager} */ ({
getLocationInfo: (entry) => {
return {rootType: volumeManagerRootType};
},
});
/** @type {!Crostini} */
let crostini;
// Set up the test components.
function setUp() {
// Mock LoadTimeData strings.
window.loadTimeData = {
data: {
'DRIVE_FS_ENABLED': false,
},
getBoolean: function(key) {
return window.loadTimeData.data[key];
},
getString: id => id,
};
const crostini = new Crostini();
crostini.init(volumeManager);
// Create a fake volume manager that provides entry location info.
volumeManager = /** @type {!VolumeManager} */ ({
getLocationInfo: (entry) => {
return /** @type {!EntryLocation} */ ({
rootType: volumeManagerRootType,
});
},
});
// Reset initial root type.
volumeManagerRootType =
/** @type {!VolumeManagerCommon.RootType<string>} */ ('testroot');
// Create and initialize Crostini.
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() {
const mockFileSystem = new MockFileSystem('volumeId');
const root = new MockDirectoryEntry(mockFileSystem, '/');
......@@ -83,6 +121,9 @@ function testIsPathShared() {
assertFalse(crostini.isPathShared(b));
}
/*
* Tests disallowed and allowed shared paths.
*/
function testCanSharePath() {
crostini.setEnabled(true);
......@@ -93,11 +134,13 @@ function testCanSharePath() {
const fooFile = new MockEntry(mockFileSystem, '/foo/file');
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);
disallowed.set('test', 'test');
for (let type of disallowed.keys()) {
volumeManagerRootType = type;
volumeManagerRootType =
/** @type {!VolumeManagerCommon.RootType<string>} */ (type);
assertFalse(crostini.canSharePath(root, true));
assertFalse(crostini.canSharePath(root, false));
assertFalse(crostini.canSharePath(rootFile, true));
......@@ -110,7 +153,8 @@ function testCanSharePath() {
assertFalse(crostini.canSharePath(fooFolder, false));
}
window.loadTimeData.data['DRIVE_FS_ENABLED'] = true;
// Test with DriveFs enabled.
setDriveFsEnabled(true);
const allowed = new Map([
...Crostini.VALID_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