Commit 1a127741 authored by Noel Gordon's avatar Noel Gordon Committed by Commit Bot

Add mock progress center items count helper for unittests

Add helper to count the number of items on the MockProgressCenter. Use
it in drive_sync_handler_unittest as an example, to remove a shed-load
of closure compiler complaints about the following code:

   Object.keys(progressCenter.items)

Move that code into the MockProgressCenter helper: getItemCount(), and
the Closure compiler will be a happy koala.

No change in test behavior, no new tests.

Bug: 907964
No-try: true
Change-Id: I3da5fda8226a64a0cad27dcb57b84fac6c7a43be
Reviewed-on: https://chromium-review.googlesource.com/c/1351201
Commit-Queue: Noel Gordon <noel@chromium.org>
Reviewed-by: default avatarStuart Langley <slangley@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611038}
parent a9fd3e2e
......@@ -110,7 +110,7 @@ function testUniqueErrorIds() {
});
// Check that this created one item.
assertEquals(1, Object.keys(progressCenter.items).length);
assertEquals(1, progressCenter.getItemCount());
// Dispatch another event.
chrome.fileManagerPrivate.onDriveSyncError.listener_({
......@@ -119,7 +119,7 @@ function testUniqueErrorIds() {
});
// Check that this created second item.
assertEquals(2, Object.keys(progressCenter.items).length);
assertEquals(2, progressCenter.getItemCount());
}
// Test that item IDs produced for quota errors are same.
......@@ -131,7 +131,7 @@ function testErrorDedupe() {
});
// Check that this created one item.
assertEquals(1, Object.keys(progressCenter.items).length);
assertEquals(1, progressCenter.getItemCount());
// Dispatch another event.
chrome.fileManagerPrivate.onDriveSyncError.listener_({
......@@ -140,7 +140,7 @@ function testErrorDedupe() {
});
// Check that this created second item.
assertEquals(1, Object.keys(progressCenter.items).length);
assertEquals(1, progressCenter.getItemCount());
}
// Test offline.
......@@ -156,14 +156,14 @@ function testOffline() {
});
// Check that this created one item.
assertEquals(1, Object.keys(progressCenter.items).length);
assertEquals(1, progressCenter.getItemCount());
assertEquals(
ProgressItemState.PROGRESSING, progressCenter.items['drive-sync'].state);
assertTrue(driveSyncHandler.syncing);
chrome.fileManagerPrivate.onDriveConnectionStatusChanged.listener_();
assertEquals(1, Object.keys(progressCenter.items).length);
assertEquals(1, progressCenter.getItemCount());
assertEquals(
ProgressItemState.CANCELED, progressCenter.items['drive-sync'].state);
assertFalse(driveSyncHandler.syncing);
......
......@@ -39,3 +39,13 @@ MockProgressCenter.prototype.requestCancel = function() {};
MockProgressCenter.prototype.addPanel = function() {};
MockProgressCenter.prototype.removePanel = function() {};
/**
* Returns the number of unique keys in |this.items|.
* @return {number}
*/
MockProgressCenter.prototype.getItemCount = function() {
const array = Object.keys(
/** @type {!Object} */ (this.items));
return array.length;
};
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