Commit 54b8c1d0 authored by Austin Tankiang's avatar Austin Tankiang Committed by Commit Bot

Invalidate ActionsModels for Drive entries on pinned changes

The pinning related actions change depending on whether the entry is
pinned or not, which can change externally from the ActionsModel. So,
invalidate ActionsModels for Drive entries when pinned state changes.

Also remove destroy() as it is never used.

Bug: 1096920
Change-Id: Iaafc87bd38035f548cd403eda1ee7014360595e6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2342524Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Commit-Queue: Austin Tankiang <austinct@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797178}
parent e0c5b2c4
......@@ -587,6 +587,7 @@ WRAPPED_INSTANTIATE_TEST_SUITE_P(
::testing::Values(TestCase("driveOpenSidebarOffline"),
TestCase("driveOpenSidebarSharedWithMe"),
TestCase("driveAutoCompleteQuery"),
TestCase("drivePinMultiple"),
TestCase("drivePinFileMobileNetwork"),
TestCase("driveClickFirstSearchResult"),
TestCase("drivePressEnterToSearch"),
......
......@@ -81,6 +81,9 @@ class ActionsController {
'menushow', this.onMenuShow_.bind(this));
this.ui_.gearButton.addEventListener(
'menushow', this.onMenuShow_.bind(this));
this.metadataModel_.addEventListener(
'update', this.onMetadataUpdated_.bind(this));
}
/**
......@@ -213,6 +216,27 @@ class ActionsController {
this.getActionsForEntries([entry]);
}
/**
* @param {?Event} event
* @private
*/
onMetadataUpdated_(event) {
if (!event || !event.names.has('pinned')) {
return;
}
for (const key of this.readyModels_.keys()) {
if (key.split(';').some(url => event.entriesMap.has(url))) {
this.readyModels_.delete(key);
}
}
for (const key of this.initializingdModels_.keys()) {
if (key.split(';').some(url => event.entriesMap.has(url))) {
this.initializingdModels_.delete(key);
}
}
}
/**
* @param {!Array<Entry|FileEntry>} entries
* @return {?ActionsModel}
......
......@@ -191,6 +191,70 @@ testcase.drivePressClearSearch = async () => {
'Search text cleared, showing all files and folders.', a11yMessages[1]);
};
/**
* Tests that pinning multiple files affects the pin action of individual files.
*/
testcase.drivePinMultiple = async () => {
const appId = await setupAndWaitUntilReady(RootPath.DRIVE);
// Select world.ogv.
await remoteCall.waitAndClickElement(
appId, '#file-list [file-name="world.ogv"]');
await remoteCall.waitForElement(appId, '[file-name="world.ogv"][selected]');
// Open the context menu once the file is selected.
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'fakeMouseRightClick', appId, ['.table-row[selected]']));
// Check that the pin action is unticked, i.e. the action will pin the file.
await remoteCall.waitForElement(
appId,
'#file-context-menu:not([hidden]) ' +
'[command="#toggle-pinned"]:not([checked])');
// Additionally select hello.txt.
await remoteCall.waitAndClickElement(
appId, '#file-list [file-name="hello.txt"]', {shift: true});
await remoteCall.waitForElement(appId, '[file-name="hello.txt"][selected]');
// Open the context menu with both files selected.
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'fakeMouseRightClick', appId, ['.table-row[selected]']));
// Pin both files.
await remoteCall.waitAndClickElement(
appId,
'#file-context-menu:not([hidden]) ' +
'[command="#toggle-pinned"]:not([checked])');
// Wait the toggle pinned async action to finish, so the next call to display
// context menu is after the action has finished.
await remoteCall.waitForElement(appId, '#file-context-menu[hidden]');
// Wait the pinned action to finish, it's flagged in the file list by
// removing CSS class "dim-offline".
await remoteCall.waitForElementLost(
appId, '#file-list .dim-offline[file-name="world.ogv"]');
// Select world.ogv by itself.
await remoteCall.waitAndClickElement(
appId, '#file-list [file-name="world.ogv"]');
// Wait for hello.txt to be unselected.
await remoteCall.waitForElement(
appId, '[file-name="hello.txt"]:not([selected])');
// Open the context menu for world.ogv.
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'fakeMouseRightClick', appId, ['.table-row[selected]']));
// Check that the pin action is ticked, i.e. the action will unpin the file.
await remoteCall.waitForElement(
appId,
'#file-context-menu:not([hidden]) ' +
'[command="#toggle-pinned"][checked]');
};
/**
* Tests pinning a file to a mobile network.
*/
......
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