Commit 9bebd3a8 authored by Sam McNally's avatar Sam McNally Committed by Commit Bot

Convert metadata.js to use async-await.

Bug: 909056
Change-Id: I0134351962bb3332f90f9430751241f0bf6c2eb5
Reviewed-on: https://chromium-review.googlesource.com/c/1355304Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Commit-Queue: Sam McNally <sammc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612532}
parent 75aac59d
......@@ -113,48 +113,38 @@ const testEntries = [
* - Opening Files app in My Drive with 8 files and 3 folders.
* - Navigate to My Drive > photos1 > folder2, which is empty.
*/
testcase.metadataDrive = function() {
let appId;
StepsRunner.run([
// Open Files app on Drive.
function() {
setupAndWaitUntilReady(
null, RootPath.DRIVE, this.next, testEntries, testEntries);
},
// Navigate 2 folders deep, because navigating in directory tree might
// triggers further metadata fetches.
function(result) {
appId = result.windowId;
remoteCall
.navigateWithDirectoryTree(appId, '/root/photos1/folder1', 'My Drive')
.then(this.next);
},
// Fetch the metadata stats.
function() {
remoteCall.callRemoteTestUtil('getMetadataStats', appId, [], this.next);
},
// Verify the number of metadata operations generated by the whole
// navigation above.
// If the asserts below fail, check if your change has increased the number
// of metadata operations, because they impact the overall app performance.
function(metadataStats) {
// Full fetch tally:
// 8 files in My Drive
// + 3 folders in My Drive.
// + 1 My Drive root.
// + 2 folders when expanding photos1
// = 14
chrome.test.assertEq(14, metadataStats.fullFetch);
chrome.test.assertEq(12, metadataStats.fromCache);
// Cleared 8 files + 3 folders when navigated out of My Drive and
// clearing file list.
chrome.test.assertEq(11, metadataStats.clearCacheCount);
chrome.test.assertEq(0, metadataStats.clearAllCount);
chrome.test.assertEq(0, metadataStats.invalidateCount);
checkIfNoErrorsOccured(this.next);
},
]);
testcase.metadataDrive = async function() {
// Open Files app on Drive.
const {appId} = await setupAndWaitUntilReady(
null, RootPath.DRIVE, null, testEntries, testEntries);
// Navigate 2 folders deep, because navigating in directory tree might
// trigger further metadata fetches.
await remoteCall.navigateWithDirectoryTree(
appId, '/root/photos1/folder1', 'My Drive');
// Fetch the metadata stats.
const metadataStats =
await remoteCall.callRemoteTestUtil('getMetadataStats', appId, []);
// Verify the number of metadata operations generated by the whole
// navigation above.
// If the asserts below fail, check if your change has increased the number
// of metadata operations, because they impact the overall app performance.
// Full fetch tally:
// 8 files in My Drive
// + 3 folders in My Drive.
// + 1 My Drive root.
// + 2 folders when expanding photos1
// = 14
chrome.test.assertEq(14, metadataStats.fullFetch);
chrome.test.assertEq(12, metadataStats.fromCache);
// Cleared 8 files + 3 folders when navigated out of My Drive and
// clearing file list.
chrome.test.assertEq(11, metadataStats.clearCacheCount);
chrome.test.assertEq(0, metadataStats.clearAllCount);
chrome.test.assertEq(0, metadataStats.invalidateCount);
};
/**
......@@ -162,54 +152,43 @@ testcase.metadataDrive = function() {
* - Opening Files app in Downloads with 8 files and 3 folders.
* - Navigate to Downloads > photos1 > folder1 which is empty.
*/
testcase.metadataDownloads = function() {
let appId;
StepsRunner.run([
// Open Files app on Downloads.
function() {
setupAndWaitUntilReady(
null, RootPath.DOWNLOADS, this.next, testEntries, testEntries);
},
// Navigate 2 folders deep, because navigating in directory tree might
// triggers further metadata fetches.
function(result) {
appId = result.windowId;
remoteCall
.navigateWithDirectoryTree(
appId, RootPath.DOWNLOADS_PATH + '/photos1/folder1',
'My files/Downloads')
.then(this.next);
},
// Fetch the metadata stats.
function() {
remoteCall.callRemoteTestUtil('getMetadataStats', appId, [], this.next);
},
// Verify the number of metadata operations generated by the whole
// navigation above.
// If the asserts below fail, check if your change has increased the number
// of metadata operations, because they impact the overall app performance.
function(metadataStats) {
// Full fetch tally:
// 8 files in Downloads
// + 3 folders in Downloads.
// + 1 Downloads root.
// + 1 read again photos1 when naviated to it.
// + 8 files in Downloads again.
// = 21
chrome.test.assertEq(21, metadataStats.fullFetch);
// 8 files and 3 folders in Downloads when expanding in the directory
// tree.
chrome.test.assertEq(0, metadataStats.fromCache);
// Cleared 8 files + 3 folders when navigated out of Downloads and
// clearing file list.
chrome.test.assertEq(11, metadataStats.clearCacheCount);
chrome.test.assertEq(0, metadataStats.clearAllCount);
chrome.test.assertEq(0, metadataStats.invalidateCount);
checkIfNoErrorsOccured(this.next);
},
]);
testcase.metadataDownloads = async function() {
// Open Files app on Downloads.
const {appId} = await setupAndWaitUntilReady(
null, RootPath.DOWNLOADS, null, testEntries, testEntries);
// Navigate 2 folders deep, because navigating in directory tree might
// triggers further metadata fetches.
await remoteCall.navigateWithDirectoryTree(
appId, RootPath.DOWNLOADS_PATH + '/photos1/folder1',
'My files/Downloads');
// Fetch the metadata stats.
const metadataStats =
await remoteCall.callRemoteTestUtil('getMetadataStats', appId, []);
// Verify the number of metadata operations generated by the whole
// navigation above.
// If the asserts below fail, check if your change has increased the number
// of metadata operations, because they impact the overall app performance.
// Full fetch tally:
// 8 files in Downloads
// + 3 folders in Downloads.
// + 1 Downloads root.
// + 1 read again photos1 when naviated to it.
// + 8 files in Downloads again.
// = 21
chrome.test.assertEq(21, metadataStats.fullFetch);
// 8 files and 3 folders in Downloads when expanding in the directory
// tree.
chrome.test.assertEq(0, metadataStats.fromCache);
// Cleared 8 files + 3 folders when navigated out of Downloads and
// clearing file list.
chrome.test.assertEq(11, metadataStats.clearCacheCount);
chrome.test.assertEq(0, metadataStats.clearAllCount);
chrome.test.assertEq(0, metadataStats.invalidateCount);
};
/**
......@@ -220,8 +199,7 @@ testcase.metadataDownloads = function() {
* Using 50 files and 50 folders because in the Drive backend it has a
* throttle for max of 20 concurrent operations.
*/
testcase.metadataLargeDrive = function() {
let appId;
testcase.metadataLargeDrive = async function() {
const entries = [createTestFolder('folder1')];
const folder1ExpectedRows = [];
......@@ -236,54 +214,44 @@ testcase.metadataLargeDrive = function() {
entries.push(createTestFile('sibling-folder-' + i));
}
StepsRunner.run([
// Open Files app on Drive.
function() {
setupAndWaitUntilReady(null, RootPath.DRIVE, this.next, entries, entries);
},
// Navigate only 1 folder deep,which is slightly different from
// metadatatDrive test.
function(result) {
appId = result.windowId;
remoteCall.navigateWithDirectoryTree(appId, '/root/folder1', 'My Drive')
.then(this.next);
},
// Wait for the metadata stats to reach the desired count.
// File list component, doesn't display all files at once for performance
// reasons. Since we can't check the modifiedTime for all files in file
// list, which is a proxy for "all metadata requests have finished", we have
// to wait until the metadata stats to have the expected count.
// If the asserts below fail, check if your change has increased the number
// of metadata operations, because they impact the overall app performance.
function() {
const checkMetadata = (metadataStats) => {
let result = true;
// Full fetch tally:
// 51 files in My Drive.
// + 50 files in My Drive>folder1.
// + 1 My Drive root.
// + 1 read again folder1 when naviated to it.
// = 103
result &= equal1PercentMargin(metadataStats.fullFetch, 103);
// 50 team drives cached, reading from file list when navigating to
// /team_drives, then read cached when expanding directory tree.
result &= metadataStats.fromCache < 70;
// Cleared 51 folders when navigated out of My Drive and clearing file
// list.
result &= equal1PercentMargin(metadataStats.clearCacheCount, 51);
result &= metadataStats.clearAllCount === 0;
result &= metadataStats.invalidateCount === 0;
return result;
};
remoteCall.waitFor('getMetadataStats', appId, checkMetadata)
.then(this.next);
},
function(metadataStats) {
checkIfNoErrorsOccured(this.next);
},
]);
// Open Files app on Drive.
const {appId} = await setupAndWaitUntilReady(
null, RootPath.DRIVE, null, entries, entries);
// Navigate only 1 folder deep,which is slightly different from
// metadatatDrive test.
await remoteCall.navigateWithDirectoryTree(
appId, '/root/folder1', 'My Drive');
// Wait for the metadata stats to reach the desired count.
// File list component, doesn't display all files at once for performance
// reasons. Since we can't check the modifiedTime for all files in file
// list, which is a proxy for "all metadata requests have finished", we have
// to wait until the metadata stats to have the expected count.
// If the asserts below fail, check if your change has increased the number
// of metadata operations, because they impact the overall app performance.
const checkMetadata = (metadataStats) => {
let result = true;
// Full fetch tally:
// 51 files in My Drive.
// + 50 files in My Drive>folder1.
// + 1 My Drive root.
// + 1 read again folder1 when naviated to it.
// = 103
result &= equal1PercentMargin(metadataStats.fullFetch, 103);
// 50 team drives cached, reading from file list when navigating to
// /team_drives, then read cached when expanding directory tree.
result &= metadataStats.fromCache < 70;
// Cleared 51 folders when navigated out of My Drive and clearing file
// list.
result &= equal1PercentMargin(metadataStats.clearCacheCount, 51);
result &= metadataStats.clearAllCount === 0;
result &= metadataStats.invalidateCount === 0;
return result;
};
await remoteCall.waitFor('getMetadataStats', appId, checkMetadata);
};
/**
......@@ -292,8 +260,7 @@ testcase.metadataLargeDrive = function() {
* - Navigate to Team Drives, with 50 team drives.
* - Expand Team Drives to display the 50 team drives..
*/
testcase.metadataTeamDrives = function() {
let appId;
testcase.metadataTeamDrives = async function() {
const entries = [];
const driveEntries = [];
......@@ -314,76 +281,64 @@ testcase.metadataTeamDrives = function() {
const downloadsEntries = entries.slice(0, 7);
const teamDriveTreeItem = '#directory-tree [entry-label="Team Drives"]';
StepsRunner.run([
// Open Files app on Drive.
function() {
setupAndWaitUntilReady(
null, RootPath.DRIVE, this.next, downloadsEntries,
entries.concat(driveEntries));
},
// Navigate to Team Drives root.
function(result) {
appId = result.windowId;
remoteCall.navigateWithDirectoryTree(appId, '/team_drives', 'Team Drives')
.then(this.next);
},
// Expand Team Drives, because expanding might need metadata.
function() {
const expandIcon = teamDriveTreeItem + ' > .tree-row > .expand-icon';
return remoteCall.waitForElement(appId, expandIcon)
.then(() => {
// Click expand icon.
return remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId, [expandIcon]);
})
.then(result => {
chrome.test.assertTrue(result);
// Wait for the subtree to expand and display its children.
const expandedSubItems =
teamDriveTreeItem + ' > .tree-children[expanded] > .tree-item';
return remoteCall.waitForElement(appId, expandedSubItems);
})
.then(element => {
// Get all Team Drives' children.
return remoteCall.callRemoteTestUtil('queryAllElements', appId, [
teamDriveTreeItem + ' > .tree-children[expanded] > .tree-item'
]);
})
.then(elements => {
// Check that we have 50 team drives.
chrome.test.assertEq(50, elements.length);
})
.then(this.next);
},
// Fetch the metadata stats.
function() {
remoteCall.callRemoteTestUtil('getMetadataStats', appId, [], this.next);
},
// Verify the number of metadata operations generated by the whole
// navigation above.
// If the asserts below fail, check if your change has increased the number
// of metadata operations, because they impact the overall app performance.
function(metadataStats) {
// Full fetch tally:
// 50 files in My Drive.
// + 50 folders in My Drive.
// + 50 team drives.
// + 1 My Drive root.
// + 1 Team Drives root.
// = 152
chrome.test.assertEq(152, metadataStats.fullFetch);
// 50 team drives cached, reading from file list when navigating to
// /team_drives, then read cached when expanding directory tree.
chrome.test.assertEq(50, metadataStats.fromCache);
// Cleared 50 folders + 50 files when navigated out of My Drive and
// clearing file list.
chrome.test.assertEq(100, metadataStats.clearCacheCount);
chrome.test.assertEq(0, metadataStats.clearAllCount);
chrome.test.assertEq(0, metadataStats.invalidateCount);
checkIfNoErrorsOccured(this.next);
},
]);
// Open Files app on Drive.
const {appId} = await setupAndWaitUntilReady(
null, RootPath.DRIVE, null, downloadsEntries,
entries.concat(driveEntries));
// Navigate to Team Drives root.
await remoteCall.navigateWithDirectoryTree(
appId, '/team_drives', 'Team Drives');
// Expand Team Drives, because expanding might need metadata.
const expandIcon = teamDriveTreeItem + ' > .tree-row > .expand-icon';
await remoteCall.waitForElement(appId, expandIcon);
// Click expand icon.
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId, [expandIcon]));
// Wait for the subtree to expand and display its children.
const expandedSubItems =
teamDriveTreeItem + ' > .tree-children[expanded] > .tree-item';
await remoteCall.waitForElement(appId, expandedSubItems);
// Get all Team Drives' children.
const elements = await remoteCall.callRemoteTestUtil(
'queryAllElements', appId,
[teamDriveTreeItem + ' > .tree-children[expanded] > .tree-item']);
// Check that we have 50 team drives.
chrome.test.assertEq(50, elements.length);
// Fetch the metadata stats.
const metadataStats =
await remoteCall.callRemoteTestUtil('getMetadataStats', appId, []);
// Verify the number of metadata operations generated by the whole
// navigation above.
// If the asserts below fail, check if your change has increased the number
// of metadata operations, because they impact the overall app performance.
//
// Full fetch tally:
// 50 files in My Drive.
// + 50 folders in My Drive.
// + 50 team drives.
// + 1 My Drive root.
// + 1 Team Drives root.
// = 152
chrome.test.assertEq(152, metadataStats.fullFetch);
// 50 team drives cached, reading from file list when navigating to
// /team_drives, then read cached when expanding directory tree.
chrome.test.assertEq(50, metadataStats.fromCache);
// Cleared 50 folders + 50 files when navigated out of My Drive and
// clearing file list.
chrome.test.assertEq(100, metadataStats.clearCacheCount);
chrome.test.assertEq(0, metadataStats.clearAllCount);
chrome.test.assertEq(0, metadataStats.invalidateCount);
};
})();
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