Commit 2500163b authored by Joel Hockey's avatar Joel Hockey Committed by Commit Bot

CrOS FilesApp: refactor only: split out crostini UI tests

Split crostini UI tests from crostini.js into test files:
 * crostini_mount.js
 * crostini_share.js
 * crostini_tasks.js
The existing tests are getting a bit too large and pushing
the bot testing time limits.

Bug: 878324
Change-Id: I882a38e3f644916e3c904709f3bfc540034b1383
Reviewed-on: https://chromium-review.googlesource.com/c/1278429Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Commit-Queue: Joel Hockey <joelhockey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#599098}
parent dfeab488
......@@ -61,8 +61,16 @@ IN_PROC_BROWSER_TEST_F(FileManagerUITest, CheckSelect) {
RunTest("checkselect");
}
IN_PROC_BROWSER_TEST_F(FileManagerUITest, Crostini) {
RunTest("crostini");
IN_PROC_BROWSER_TEST_F(FileManagerUITest, CrostiniMount) {
RunTest("crostiniMount");
}
IN_PROC_BROWSER_TEST_F(FileManagerUITest, CrostiniShare) {
RunTest("crostiniShare");
}
IN_PROC_BROWSER_TEST_F(FileManagerUITest, CrostiniTasks) {
RunTest("crostiniTasks");
}
IN_PROC_BROWSER_TEST_F(FileManagerUITest, QuickView) {
......
......@@ -21,7 +21,9 @@ action("create_test_main") {
"//chrome/browser/chromeos/extensions/file_manager/private_api_strings.cc",
"//ui/webui/resources/css/text_defaults.css",
"check_select.js",
"crostini.js",
"crostini_mount.js",
"crostini_share.js",
"crostini_tasks.js",
"js/strings.js",
"quick_view.js",
"uma.js",
......@@ -36,7 +38,9 @@ js_type_check("closure_compile") {
deps = [
":check_select",
":closure_compile_externs",
":crostini",
":crostini_mount",
":crostini_share",
":crostini_tasks",
":quick_view",
":uma",
]
......@@ -68,7 +72,23 @@ js_library("check_select") {
]
}
js_library("crostini") {
js_library("crostini_mount") {
deps = [
"../foreground/js:crostini",
"js:test_util",
"//ui/webui/resources/js:webui_resource_test",
]
}
js_library("crostini_share") {
deps = [
"../foreground/js:crostini",
"js:test_util",
"//ui/webui/resources/js:webui_resource_test",
]
}
js_library("crostini_tasks") {
deps = [
"../foreground/js:crostini",
"js:test_util",
......
// 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.
const crostiniMount = {};
crostiniMount.testCrostiniNotEnabled = (done) => {
chrome.fileManagerPrivate.crostiniEnabled_ = false;
test.setupAndWaitUntilReady()
.then(() => {
fileManager.setupCrostini_();
return test.waitForElementLost(
'#directory-tree .tree-item [root-type-icon="crostini"]');
})
.then(() => {
// Reset crostini back to default enabled=true.
chrome.fileManagerPrivate.crostiniEnabled_ = true;
done();
});
};
crostiniMount.testMountCrostiniSuccess = (done) => {
const oldMount = chrome.fileManagerPrivate.mountCrostini;
let mountCallback = null;
chrome.fileManagerPrivate.mountCrostini = (callback) => {
mountCallback = callback;
};
test.setupAndWaitUntilReady()
.then(() => {
// Linux files fake root is shown.
return test.waitForElement(
'#directory-tree .tree-item [root-type-icon="crostini"]');
})
.then(() => {
// Click on Linux files.
assertTrue(
test.fakeMouseClick(
'#directory-tree .tree-item [root-type-icon="crostini"]'),
'click linux files');
return test.waitForElement('paper-progress:not([hidden])');
})
.then(() => {
// Ensure mountCrostini is called.
return test.repeatUntil(() => {
if (!mountCallback)
return test.pending('Waiting for mountCrostini');
return mountCallback;
});
})
.then(() => {
// Intercept the fileManagerPrivate.mountCrostini call
// and add crostini disk mount.
test.mountCrostini();
// Continue from fileManagerPrivate.mountCrostini callback
// and ensure expected files are shown.
mountCallback();
return test.waitForFiles(
test.TestEntryInfo.getExpectedRows(test.BASIC_CROSTINI_ENTRY_SET));
})
.then(() => {
// Reset fileManagerPrivate.mountCrostini and remove mount.
chrome.fileManagerPrivate.mountCrostini = oldMount;
chrome.fileManagerPrivate.removeMount('crostini');
// Linux Files fake root is shown.
return test.waitForElement(
'#directory-tree .tree-item [root-type-icon="crostini"]');
})
.then(() => {
// Downloads folder should be shown when crostini goes away.
return test.waitForFiles(
test.TestEntryInfo.getExpectedRows(test.BASIC_LOCAL_ENTRY_SET));
})
.then(() => {
done();
});
};
crostiniMount.testMountCrostiniError = (done) => {
const oldMount = chrome.fileManagerPrivate.mountCrostini;
// Override fileManagerPrivate.mountCrostini to return error.
chrome.fileManagerPrivate.mountCrostini = (callback) => {
chrome.runtime.lastError = {message: 'test message'};
callback();
delete chrome.runtime.lastError;
};
test.setupAndWaitUntilReady()
.then(() => {
return test.waitForElement(
'#directory-tree .tree-item [root-type-icon="crostini"]');
})
.then(() => {
// Click on Linux Files, ensure error dialog is shown.
assertTrue(test.fakeMouseClick(
'#directory-tree .tree-item [root-type-icon="crostini"]'));
return test.waitForElement('.cr-dialog-container.shown');
})
.then(() => {
// Click OK button to close.
assertTrue(test.fakeMouseClick('button.cr-dialog-ok'));
return test.waitForElementLost('.cr-dialog-container');
})
.then(() => {
// Reset chrome.fileManagerPrivate.mountCrostini.
chrome.fileManagerPrivate.mountCrostini = oldMount;
done();
});
};
crostiniMount.testCrostiniMountOnDrag = (done) => {
chrome.fileManagerPrivate.mountCrostiniDelay_ = 0;
test.setupAndWaitUntilReady()
.then(() => {
return test.waitForElement(
'#directory-tree .tree-item [root-type-icon="crostini"]');
})
.then(() => {
assertTrue(test.sendEvent(
'#directory-tree .tree-item [root-type-icon="crostini"]',
new Event('dragenter', {bubbles: true})));
assertTrue(test.sendEvent(
'#directory-tree .tree-item [root-type-icon="crostini"]',
new Event('dragleave', {bubbles: true})));
return test.waitForFiles(
test.TestEntryInfo.getExpectedRows(test.BASIC_CROSTINI_ENTRY_SET));
})
.then(() => {
chrome.fileManagerPrivate.removeMount('crostini');
return test.waitForElement(
'#directory-tree .tree-item [root-type-icon="crostini"]');
})
.then(() => {
done();
});
};
// 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.
const crostiniShare = {};
crostiniShare.testSharePathCrostiniSuccess = (done) => {
const oldSharePath = chrome.fileManagerPrivate.sharePathWithCrostini;
let sharePathCalled = false;
chrome.fileManagerPrivate.sharePathWithCrostini = (entry, callback) => {
oldSharePath(entry, () => {
sharePathCalled = true;
callback();
});
};
chrome.metricsPrivate.smallCounts_ = [];
chrome.metricsPrivate.values_ = [];
test.setupAndWaitUntilReady()
.then(() => {
// Right-click 'photos' directory.
// Check 'Share with Linux' is shown in menu.
assertTrue(
test.fakeMouseRightClick('#file-list [file-name="photos"]'),
'right-click photos');
return test.waitForElement(
'#file-context-menu:not([hidden]) ' +
'[command="#share-with-linux"]:not([hidden]):not([disabled])');
})
.then(() => {
// Click on 'Share with Linux'.
assertTrue(
test.fakeMouseClick(
'#file-context-menu [command="#share-with-linux"]'),
'Share with Linux');
// Check sharePathWithCrostini is called.
return test.repeatUntil(() => {
return sharePathCalled || test.pending('wait for sharePathCalled');
});
})
.then(() => {
// Validate UMAs.
assertEquals(1, chrome.metricsPrivate.smallCounts_.length);
assertArrayEquals(
['FileBrowser.CrostiniSharedPaths.Depth.downloads', 1],
chrome.metricsPrivate.smallCounts_[0]);
const lastEnumUma = chrome.metricsPrivate.values_.pop();
assertEquals('FileBrowser.MenuItemSelected', lastEnumUma[0].metricName);
assertEquals(12 /* Share with Linux */, lastEnumUma[1]);
// Restore fmp.*.
chrome.fileManagerPrivate.sharePathWithCrostini = oldSharePath;
done();
});
};
// Verify right-click menu with 'Share with Linux' is not shown for:
// * Files (not directory)
// * Any folder already shared
// * Root Downloads folder
// * Any folder outside of downloads (e.g. crostini or orive)
crostiniShare.testSharePathNotShown = (done) => {
const myFiles = '#directory-tree .tree-item [root-type-icon="my_files"]';
const downloads = '#file-list li [file-type-icon="downloads"]';
const linuxFiles = '#directory-tree .tree-item [root-type-icon="crostini"]';
const googleDrive = '#directory-tree .tree-item [volume-type-icon="drive"]';
const menuNoShareWithLinux = '#file-context-menu:not([hidden]) ' +
'[command="#share-with-linux"][hidden][disabled="disabled"]';
let alreadySharedPhotosDir;
test.setupAndWaitUntilReady()
.then(() => {
// Right-click 'hello.txt' file.
// Check 'Share with Linux' is not shown in menu.
assertTrue(
test.fakeMouseRightClick('#file-list [file-name="hello.txt"]'),
'right-click hello.txt');
return test.waitForElement(menuNoShareWithLinux);
})
.then(() => {
// Set a folder as already shared.
alreadySharedPhotosDir =
mockVolumeManager
.getCurrentProfileVolumeInfo(
VolumeManagerCommon.VolumeType.DOWNLOADS)
.fileSystem.entries['/photos'];
Crostini.registerSharedPath(alreadySharedPhotosDir, mockVolumeManager);
assertTrue(
test.fakeMouseRightClick('#file-list [file-name="photos"]'),
'right-click hello.txt');
return test.waitForElement(menuNoShareWithLinux);
})
.then(() => {
// Select 'My files' in directory tree to show Downloads in file list.
assertTrue(test.fakeMouseClick(myFiles), 'click My files');
return test.waitForElement(downloads);
})
.then(() => {
// Right-click 'Downloads' directory.
// Check 'Share with Linux' is not shown in menu.
assertTrue(
test.fakeMouseRightClick(downloads), 'right-click downloads');
return test.waitForElement(menuNoShareWithLinux);
})
.then(() => {
// Select 'Linux files' in directory tree to show dir A in file list.
return test.waitForElement(linuxFiles);
})
.then(() => {
assertTrue(test.fakeMouseClick(linuxFiles), 'click Linux files');
return test.waitForFiles(
test.TestEntryInfo.getExpectedRows(test.BASIC_CROSTINI_ENTRY_SET));
})
.then(() => {
// Check 'Share with Linux' is not shown in menu.
assertTrue(
test.fakeMouseRightClick('#file-list [file-name="A"]'),
'right-click directory A');
return test.waitForElement(menuNoShareWithLinux);
})
.then(() => {
// Select 'Google Drive' to show dir photos in file list.
return test.waitForElement(googleDrive);
})
.then(() => {
assertTrue(test.fakeMouseClick(googleDrive), 'click Google Drive');
return test.waitForFiles(
test.TestEntryInfo.getExpectedRows(test.BASIC_DRIVE_ENTRY_SET));
})
.then(() => {
// Check 'Share with Linux' is not shown in menu.
assertTrue(
test.fakeMouseRightClick('#file-list [file-name="photos"]'),
'right-click photos');
return test.waitForElement(menuNoShareWithLinux);
})
.then(() => {
// Reset Linux files back to unmounted.
chrome.fileManagerPrivate.removeMount('crostini');
return test.waitForElement(
'#directory-tree .tree-item [root-type-icon="crostini"]');
})
.then(() => {
// Clear Crostini shared folders.
Crostini.unregisterSharedPath(
alreadySharedPhotosDir, mockVolumeManager);
done();
});
};
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