Commit a3768b5d authored by Luciano Pacheco's avatar Luciano Pacheco Committed by Commit Bot

[Files app] Deflake test drivePinFileMobileNetwork

Remove wait(100) and wait for an UI clue that the pinned action has
finished, which is more predictable.

Change the ActionsController to listen to ActionModel invalidated event
to clear the cached ActionsModel instance.

Change the pinned action (DriveToggleOfflineAction) to call
'onExecute_' which invalidates the model, after it has finished
processing all entries, the last |pinDriveFile| API callback has been
called and metadata has been cleared and re-fetched from backend. The
flakiness was due to cache invalidation and refreshing was happening
before the |pinDriveFile| API had finished, so metadata and
ActionsModel were getting cached with outdated value for |pinned|.

Bug: 936429
Change-Id: Ib0878d41d28a46205dc3e2ced8243d681ec1945d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1660301
Commit-Queue: Noel Gordon <noel@chromium.org>
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#669610}
parent 55683d7d
...@@ -248,6 +248,9 @@ class ActionsController { ...@@ -248,6 +248,9 @@ class ActionsController {
this.volumeManager_, this.metadataModel_, this.shortcutsModel_, this.volumeManager_, this.metadataModel_, this.shortcutsModel_,
this.driveSyncHandler_, this.ui_, entries); this.driveSyncHandler_, this.ui_, entries);
actionsModel.addEventListener(
'invalidated', this.clearLocalCache_.bind(this, key), {once: true});
// Once it's initialized, move to readyModels_ so we don't have to construct // Once it's initialized, move to readyModels_ so we don't have to construct
// and initialized again. // and initialized again.
const init = actionsModel.initialize().then(() => { const init = actionsModel.initialize().then(() => {
......
...@@ -237,7 +237,6 @@ class DriveToggleOfflineAction { ...@@ -237,7 +237,6 @@ class DriveToggleOfflineAction {
start: () => { start: () => {
// Check if all the entries are pinned or not. // Check if all the entries are pinned or not.
if (entries.length === 0) { if (entries.length === 0) {
this.onExecute_();
return; return;
} }
currentEntry = entries.shift(); currentEntry = entries.shift();
...@@ -261,6 +260,11 @@ class DriveToggleOfflineAction { ...@@ -261,6 +260,11 @@ class DriveToggleOfflineAction {
// Update the user interface according to the cache state. // Update the user interface according to the cache state.
updateUI: () => { updateUI: () => {
// After execution of last entry call "onExecute_" to invalidate the
// model.
if (entries.length === 0) {
this.onExecute_();
}
this.ui_.listContainer.currentView.updateListItemsMetadata( this.ui_.listContainer.currentView.updateListItemsMetadata(
'external', [currentEntry]); 'external', [currentEntry]);
if (!error) { if (!error) {
......
...@@ -221,8 +221,12 @@ testcase.drivePinFileMobileNetwork = async () => { ...@@ -221,8 +221,12 @@ testcase.drivePinFileMobileNetwork = async () => {
// Wait the toggle pinned async action to finish, so the next call to display // Wait the toggle pinned async action to finish, so the next call to display
// context menu is after the action has finished. // context menu is after the action has finished.
await remoteCall.waitForElement(appId, '#file-context-menu[hidden]'); await remoteCall.waitForElement(appId, '#file-context-menu[hidden]');
// TODO(crbug.com/953616): Change wait for a deterministic option.
await wait(100); // 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="hello.txt"]');
// Open context menu again. // Open context menu again.
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil( chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
......
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