Commit b4e92b23 authored by Timothy Loh's avatar Timothy Loh Committed by Commit Bot

Add tests for InstallLinuxPackageDialog

This CL adds some tests for the linux package install flow in the File
Manager. It also fixes a bug in the CrostiniManager where package
progress observers were not correctly removed, as discovered by these
tests.

Bug: 868221
Change-Id: I2b6adf2530ff43a0b22fe2b552bb877f98fd61c7
Reviewed-on: https://chromium-review.googlesource.com/1152643Reviewed-by: default avatarJoel Hockey <joelhockey@chromium.org>
Commit-Queue: Timothy Loh <timloh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#578975}
parent 969cf704
......@@ -981,7 +981,7 @@ void CrostiniManager::RemoveInstallLinuxPackageProgressObserver(
auto range = install_linux_package_progress_observers_.equal_range(
CryptohomeIdForProfile(profile));
for (auto it = range.first; it != range.second; ++it) {
if (it->second != observer) {
if (it->second == observer) {
install_linux_package_progress_observers_.erase(it);
return;
}
......
......@@ -554,6 +554,11 @@ WRAPPED_INSTANTIATE_TEST_CASE_P(
TestCase("directoryTreeRefresh"),
TestCase("myFilesUpdatesChildren")));
WRAPPED_INSTANTIATE_TEST_CASE_P(
InstallLinuxPackageDialog, /* install_linux_package_dialog.js */
FilesAppBrowserTest,
::testing::Values(TestCase("installLinuxPackageDialog")));
// Structure to describe an account info.
struct TestAccountInfo {
const char* const gaia_id;
......
......@@ -9,7 +9,8 @@ window.metrics = {
var mockTaskHistory = {
getLastExecutedTime: function(id) {
return 0;
}
},
recordTaskExecuted: function(id) {}
};
loadTimeData.data = {
......@@ -20,6 +21,7 @@ loadTimeData.data = {
NO_TASK_FOR_CRX: 'NO_TASK_FOR_CRX',
NO_TASK_FOR_CRX_TITLE: 'NO_TASK_FOR_CRX_TITLE',
OPEN_WITH_BUTTON_LABEL: 'OPEN_WITH_BUTTON_LABEL',
TASK_INSTALL_LINUX_PACKAGE: 'TASK_INSTALL_LINUX_PACKAGE',
TASK_OPEN: 'TASK_OPEN',
MORE_ACTIONS_BUTTON_LABEL: 'MORE_ACTIONS_BUTTON_LABEL'
};
......@@ -57,7 +59,7 @@ function getMockFileManager() {
return {
volumeManager: {
getLocationInfo: function(entry) {
return VolumeManagerCommon.RootType.DRIVE;
return {rootType: VolumeManagerCommon.RootType.DRIVE};
},
getDriveConnectionState: function() {
return VolumeManagerCommon.DriveConnectionType.ONLINE;
......@@ -69,8 +71,7 @@ function getMockFileManager() {
}
},
ui: {
alertDialog:
{showHtml: function(title, text, onOk, onCancel, onShow) {}}
alertDialog: {showHtml: function(title, text, onOk, onCancel, onShow) {}}
},
metadataModel: {},
directoryModel: {
......@@ -431,3 +432,45 @@ function testChooseZipArchiverOverZipUnpacker(callback) {
});
reportPromise(promise, callback);
}
function testOpenInstallLinuxPackageDialog(callback) {
window.chrome.fileManagerPrivate.getFileTasks = function(entries, callback) {
setTimeout(
callback.bind(
null,
[
{
taskId: 'test-extension-id|file|install-linux-package',
isDefault: false,
isGenericFileHandler: false,
title: '__MSG_INSTALL_LINUX_PACKAGE__',
},
]),
0);
};
var mockFileSystem = new MockFileSystem('volumeId');
var mockEntry = new MockFileEntry(mockFileSystem, '/test.deb');
var promise = new Promise(function(resolve, reject) {
var fileManager = getMockFileManager();
fileManager.ui.installLinuxPackageDialog = {
showInstallLinuxPackageDialog: function(entry) {
resolve();
}
};
fileManager.volumeManager.getLocationInfo = function(entry) {
return {rootType: VolumeManagerCommon.RootType.CROSTINI};
};
FileTasks
.create(
fileManager.volumeManager, fileManager.metadataModel,
fileManager.directoryModel, fileManager.ui, [mockEntry], [null],
mockTaskHistory)
.then(function(tasks) {
tasks.executeDefault();
});
});
reportPromise(promise, callback);
}
// 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.
'use strict';
testcase.installLinuxPackageDialog = function() {
const fake = '#directory-tree .tree-item [root-type-icon="crostini"]';
const real = '#directory-tree .tree-item [volume-type-icon="crostini"]';
// The dialog has an INSTALL and OK button, both as .cr-dialog-ok, but only
// one is visible at a time.
const dialog = '#install-linux-package-dialog';
const okButton = dialog + ' .cr-dialog-ok:not([hidden])';
let appId;
StepsRunner.run([
function() {
setupAndWaitUntilReady(null, RootPath.DOWNLOADS, this.next);
},
// Add entries to crostini volume, but do not mount.
function(results) {
appId = results.windowId;
addEntries(['crostini'], [ENTRIES.debPackage], this.next);
},
// Linux Files fake root is shown.
function() {
remoteCall.waitForElement(appId, fake).then(this.next);
},
// Mount crostini, and ensure real root and files are shown.
function() {
remoteCall.callRemoteTestUtil('fakeMouseClick', appId, [fake]);
remoteCall.waitForElement(appId, real).then(this.next);
},
function() {
const files = TestEntryInfo.getExpectedRows([ENTRIES.debPackage]);
remoteCall.waitForFiles(appId, files).then(this.next);
},
// Open the deb package.
function() {
remoteCall.callRemoteTestUtil(
'openFile', appId, [ENTRIES.debPackage.targetPath], this.next);
},
// Ensure package install dialog is shown.
function() {
remoteCall.waitForElement(appId, dialog).then(this.next);
},
// Begin installation.
function() {
remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId, [okButton], this.next);
},
// Wait for the installation to start (under test, we use a fake D-Bus
// client, so it doesn't actually install anything).
function() {
repeatUntil(function() {
return remoteCall
.callRemoteTestUtil('queryAllElements', appId, ['.cr-dialog-text'])
.then(function(elements) {
return elements[0] &&
elements[0].text == 'Installation successfully started.' ||
pending('Waiting for installation to start.');
});
}).then(this.next);
},
// Dismiss dialog
function() {
remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId, [okButton], this.next);
},
// Ensure dialog closes
function() {
remoteCall.waitForElementLost(appId, dialog).then(this.next);
},
function() {
checkIfNoErrorsOccured(this.next);
},
]);
};
......@@ -26,6 +26,7 @@
"file_manager/folder_shortcuts.js",
"file_manager/gear_menu.js",
"file_manager/grid_view.js",
"file_manager/install_linux_package_dialog.js",
"file_manager/keyboard_operations.js",
"file_manager/my_files.js",
"file_manager/open_audio_files.js",
......
......@@ -545,6 +545,17 @@ var ENTRIES = {
typeText: 'Zip archive'
}),
debPackage: new TestEntryInfo({
type: EntryType.FILE,
sourceFileName: 'package.deb',
targetPath: 'package.deb',
mimeType: 'application/vnd.debian.binary-package',
lastModifiedTime: 'Jan 1, 2014, 1:00 AM',
nameText: 'package.deb',
sizeText: '724 bytes',
typeText: 'DEB file'
}),
hiddenFile: new TestEntryInfo({
type: EntryType.FILE,
sourceFileName: 'text.txt',
......
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