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