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,32 +113,24 @@ const testEntries = [ ...@@ -113,32 +113,24 @@ 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;
StepsRunner.run([
// Open Files app on Drive. // Open Files app on Drive.
function() { const {appId} = await setupAndWaitUntilReady(
setupAndWaitUntilReady( null, RootPath.DRIVE, null, testEntries, testEntries);
null, RootPath.DRIVE, this.next, testEntries, testEntries);
},
// Navigate 2 folders deep, because navigating in directory tree might // Navigate 2 folders deep, because navigating in directory tree might
// triggers further metadata fetches. // trigger further metadata fetches.
function(result) { await remoteCall.navigateWithDirectoryTree(
appId = result.windowId; appId, '/root/photos1/folder1', 'My Drive');
remoteCall
.navigateWithDirectoryTree(appId, '/root/photos1/folder1', 'My Drive')
.then(this.next);
},
// Fetch the metadata stats. // Fetch the metadata stats.
function() { const metadataStats =
remoteCall.callRemoteTestUtil('getMetadataStats', appId, [], this.next); await remoteCall.callRemoteTestUtil('getMetadataStats', appId, []);
},
// Verify the number of metadata operations generated by the whole // Verify the number of metadata operations generated by the whole
// navigation above. // navigation above.
// If the asserts below fail, check if your change has increased the number // If the asserts below fail, check if your change has increased the number
// of metadata operations, because they impact the overall app performance. // of metadata operations, because they impact the overall app performance.
function(metadataStats) {
// Full fetch tally: // Full fetch tally:
// 8 files in My Drive // 8 files in My Drive
// + 3 folders in My Drive. // + 3 folders in My Drive.
...@@ -147,14 +139,12 @@ testcase.metadataDrive = function() { ...@@ -147,14 +139,12 @@ testcase.metadataDrive = function() {
// = 14 // = 14
chrome.test.assertEq(14, metadataStats.fullFetch); chrome.test.assertEq(14, metadataStats.fullFetch);
chrome.test.assertEq(12, metadataStats.fromCache); chrome.test.assertEq(12, metadataStats.fromCache);
// Cleared 8 files + 3 folders when navigated out of My Drive and // Cleared 8 files + 3 folders when navigated out of My Drive and
// clearing file list. // clearing file list.
chrome.test.assertEq(11, metadataStats.clearCacheCount); chrome.test.assertEq(11, metadataStats.clearCacheCount);
chrome.test.assertEq(0, metadataStats.clearAllCount); chrome.test.assertEq(0, metadataStats.clearAllCount);
chrome.test.assertEq(0, metadataStats.invalidateCount); chrome.test.assertEq(0, metadataStats.invalidateCount);
checkIfNoErrorsOccured(this.next);
},
]);
}; };
/** /**
...@@ -162,34 +152,25 @@ testcase.metadataDrive = function() { ...@@ -162,34 +152,25 @@ 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;
StepsRunner.run([
// Open Files app on Downloads. // Open Files app on Downloads.
function() { const {appId} = await setupAndWaitUntilReady(
setupAndWaitUntilReady( null, RootPath.DOWNLOADS, null, testEntries, testEntries);
null, RootPath.DOWNLOADS, this.next, testEntries, testEntries);
},
// Navigate 2 folders deep, because navigating in directory tree might // Navigate 2 folders deep, because navigating in directory tree might
// triggers further metadata fetches. // triggers further metadata fetches.
function(result) { await remoteCall.navigateWithDirectoryTree(
appId = result.windowId;
remoteCall
.navigateWithDirectoryTree(
appId, RootPath.DOWNLOADS_PATH + '/photos1/folder1', appId, RootPath.DOWNLOADS_PATH + '/photos1/folder1',
'My files/Downloads') 'My files/Downloads');
.then(this.next);
},
// Fetch the metadata stats. // Fetch the metadata stats.
function() { const metadataStats =
remoteCall.callRemoteTestUtil('getMetadataStats', appId, [], this.next); await remoteCall.callRemoteTestUtil('getMetadataStats', appId, []);
},
// Verify the number of metadata operations generated by the whole // Verify the number of metadata operations generated by the whole
// navigation above. // navigation above.
// If the asserts below fail, check if your change has increased the number // If the asserts below fail, check if your change has increased the number
// of metadata operations, because they impact the overall app performance. // of metadata operations, because they impact the overall app performance.
function(metadataStats) {
// Full fetch tally: // Full fetch tally:
// 8 files in Downloads // 8 files in Downloads
// + 3 folders in Downloads. // + 3 folders in Downloads.
...@@ -198,18 +179,16 @@ testcase.metadataDownloads = function() { ...@@ -198,18 +179,16 @@ testcase.metadataDownloads = function() {
// + 8 files in Downloads again. // + 8 files in Downloads again.
// = 21 // = 21
chrome.test.assertEq(21, metadataStats.fullFetch); chrome.test.assertEq(21, metadataStats.fullFetch);
// 8 files and 3 folders in Downloads when expanding in the directory // 8 files and 3 folders in Downloads when expanding in the directory
// tree. // tree.
chrome.test.assertEq(0, metadataStats.fromCache); chrome.test.assertEq(0, metadataStats.fromCache);
// Cleared 8 files + 3 folders when navigated out of Downloads and // Cleared 8 files + 3 folders when navigated out of Downloads and
// clearing file list. // clearing file list.
chrome.test.assertEq(11, metadataStats.clearCacheCount); chrome.test.assertEq(11, metadataStats.clearCacheCount);
chrome.test.assertEq(0, metadataStats.clearAllCount); chrome.test.assertEq(0, metadataStats.clearAllCount);
chrome.test.assertEq(0, metadataStats.invalidateCount); 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,18 +214,15 @@ testcase.metadataLargeDrive = function() { ...@@ -236,18 +214,15 @@ 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.
function() { const {appId} = await setupAndWaitUntilReady(
setupAndWaitUntilReady(null, RootPath.DRIVE, this.next, entries, entries); null, RootPath.DRIVE, null, 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.
function(result) { await remoteCall.navigateWithDirectoryTree(
appId = result.windowId; appId, '/root/folder1', 'My Drive');
remoteCall.navigateWithDirectoryTree(appId, '/root/folder1', 'My Drive')
.then(this.next);
},
// Wait for the metadata stats to reach the desired count. // Wait for the metadata stats to reach the desired count.
// File list component, doesn't display all files at once for performance // 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 // reasons. Since we can't check the modifiedTime for all files in file
...@@ -255,7 +230,6 @@ testcase.metadataLargeDrive = function() { ...@@ -255,7 +230,6 @@ testcase.metadataLargeDrive = function() {
// to wait until the metadata stats to have the expected count. // to wait until the metadata stats to have the expected count.
// If the asserts below fail, check if your change has increased the number // If the asserts below fail, check if your change has increased the number
// of metadata operations, because they impact the overall app performance. // of metadata operations, because they impact the overall app performance.
function() {
const checkMetadata = (metadataStats) => { const checkMetadata = (metadataStats) => {
let result = true; let result = true;
// Full fetch tally: // Full fetch tally:
...@@ -277,13 +251,7 @@ testcase.metadataLargeDrive = function() { ...@@ -277,13 +251,7 @@ testcase.metadataLargeDrive = function() {
result &= metadataStats.invalidateCount === 0; result &= metadataStats.invalidateCount === 0;
return result; return result;
}; };
remoteCall.waitFor('getMetadataStats', appId, checkMetadata) await 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,57 +281,46 @@ testcase.metadataTeamDrives = function() { ...@@ -314,57 +281,46 @@ 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. // Open Files app on Drive.
function() { const {appId} = await setupAndWaitUntilReady(
setupAndWaitUntilReady( null, RootPath.DRIVE, null, downloadsEntries,
null, RootPath.DRIVE, this.next, downloadsEntries,
entries.concat(driveEntries)); entries.concat(driveEntries));
},
// Navigate to Team Drives root. // Navigate to Team Drives root.
function(result) { await remoteCall.navigateWithDirectoryTree(
appId = result.windowId; appId, '/team_drives', 'Team Drives');
remoteCall.navigateWithDirectoryTree(appId, '/team_drives', 'Team Drives')
.then(this.next);
},
// Expand Team Drives, because expanding might need metadata. // Expand Team Drives, because expanding might need metadata.
function() {
const expandIcon = teamDriveTreeItem + ' > .tree-row > .expand-icon'; const expandIcon = teamDriveTreeItem + ' > .tree-row > .expand-icon';
return remoteCall.waitForElement(appId, expandIcon) await remoteCall.waitForElement(appId, expandIcon);
.then(() => {
// Click expand icon. // Click expand icon.
return remoteCall.callRemoteTestUtil( chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId, [expandIcon]); 'fakeMouseClick', appId, [expandIcon]));
})
.then(result => {
chrome.test.assertTrue(result);
// Wait for the subtree to expand and display its children. // Wait for the subtree to expand and display its children.
const expandedSubItems = const expandedSubItems =
teamDriveTreeItem + ' > .tree-children[expanded] > .tree-item'; teamDriveTreeItem + ' > .tree-children[expanded] > .tree-item';
return remoteCall.waitForElement(appId, expandedSubItems); await remoteCall.waitForElement(appId, expandedSubItems);
})
.then(element => {
// Get all Team Drives' children. // Get all Team Drives' children.
return remoteCall.callRemoteTestUtil('queryAllElements', appId, [ const elements = await remoteCall.callRemoteTestUtil(
teamDriveTreeItem + ' > .tree-children[expanded] > .tree-item' 'queryAllElements', appId,
]); [teamDriveTreeItem + ' > .tree-children[expanded] > .tree-item']);
})
.then(elements => {
// Check that we have 50 team drives. // Check that we have 50 team drives.
chrome.test.assertEq(50, elements.length); chrome.test.assertEq(50, elements.length);
})
.then(this.next);
},
// Fetch the metadata stats. // Fetch the metadata stats.
function() { const metadataStats =
remoteCall.callRemoteTestUtil('getMetadataStats', appId, [], this.next); await remoteCall.callRemoteTestUtil('getMetadataStats', appId, []);
},
// Verify the number of metadata operations generated by the whole // Verify the number of metadata operations generated by the whole
// navigation above. // navigation above.
// If the asserts below fail, check if your change has increased the number // If the asserts below fail, check if your change has increased the number
// of metadata operations, because they impact the overall app performance. // of metadata operations, because they impact the overall app performance.
function(metadataStats) { //
// Full fetch tally: // Full fetch tally:
// 50 files in My Drive. // 50 files in My Drive.
// + 50 folders in My Drive. // + 50 folders in My Drive.
...@@ -373,17 +329,16 @@ testcase.metadataTeamDrives = function() { ...@@ -373,17 +329,16 @@ testcase.metadataTeamDrives = function() {
// + 1 Team Drives root. // + 1 Team Drives root.
// = 152 // = 152
chrome.test.assertEq(152, metadataStats.fullFetch); chrome.test.assertEq(152, metadataStats.fullFetch);
// 50 team drives cached, reading from file list when navigating to // 50 team drives cached, reading from file list when navigating to
// /team_drives, then read cached when expanding directory tree. // /team_drives, then read cached when expanding directory tree.
chrome.test.assertEq(50, metadataStats.fromCache); chrome.test.assertEq(50, metadataStats.fromCache);
// Cleared 50 folders + 50 files when navigated out of My Drive and // Cleared 50 folders + 50 files when navigated out of My Drive and
// clearing file list. // clearing file list.
chrome.test.assertEq(100, metadataStats.clearCacheCount); chrome.test.assertEq(100, metadataStats.clearCacheCount);
chrome.test.assertEq(0, metadataStats.clearAllCount); chrome.test.assertEq(0, metadataStats.clearAllCount);
chrome.test.assertEq(0, metadataStats.invalidateCount); chrome.test.assertEq(0, metadataStats.invalidateCount);
checkIfNoErrorsOccured(this.next);
},
]);
}; };
})(); })();
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