Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Unified Diff: chrome/test/data/file_manager/unit_tests/progress_center_handler_unittest.js

Issue 98363003: Files.app: Add a unit test of ProgressCenterHandler class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/data/file_manager/unit_tests/progress_center_handler_unittest.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/file_manager/unit_tests/progress_center_handler_unittest.js
diff --git a/chrome/test/data/file_manager/unit_tests/progress_center_handler_unittest.js b/chrome/test/data/file_manager/unit_tests/progress_center_handler_unittest.js
new file mode 100644
index 0000000000000000000000000000000000000000..067cac4c2abf309e27952837b26cccb975369e61
--- /dev/null
+++ b/chrome/test/data/file_manager/unit_tests/progress_center_handler_unittest.js
@@ -0,0 +1,194 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+'use strict';
+
+// Mock items.
+var fileOperationManager = null;
+var progressCenter = null;
+
+// Test target.
+var handler = null;
+
+// Set up the test components.
+function setUp() {
+ // Set up string assets.
+ loadTimeData.data = {
+ COPY_FILE_NAME: 'Copying $1...',
+ COPY_TARGET_EXISTS_ERROR: '$1 is already exists.',
+ COPY_FILESYSTEM_ERROR: 'Copy filesystem error: $1',
+ FILE_ERROR_GENERIC: 'File error generic.',
+ COPY_UNEXPECTED_ERROR: 'Copy unexpected error: $1'
+ };
+
+ // Make ProgressCenterHandler.
+ fileOperationManager = new MockFileOperationManager();
+ progressCenter = new MockProgressCenter();
+ handler = new ProgressCenterHandler(
+ fileOperationManager,
+ progressCenter);
+}
+
+// Test for success copy.
+function testCopySuccess() {
+ // Dispatch an event.
+ fileOperationManager.dispatchEvent({
+ type: 'copy-progress',
+ taskId: 'TASK_ID',
+ reason: 'BEGIN',
+ status: {
+ operationType: 'COPY',
+ numRemainingItems: 1,
+ processingEntry: {name: 'sample.txt'},
+ totalBytes: 200,
+ processedBytes: 0
+ }
+ });
+
+ // Check the updated item.
+ var item = progressCenter.items['TASK_ID'];
+ assertEquals(ProgressItemState.PROGRESSING, item.state);
+ assertEquals('TASK_ID', item.id);
+ assertEquals('Copying sample.txt...', item.message);
+ assertEquals('copy', item.type);
+ assertEquals(false, item.summarized);
+ assertEquals(0, item.progressRateInPercent);
+
+ // Dispatch an event.
+ fileOperationManager.cancelEvent = {
+ type: 'copy-progress',
+ taskId: 'TASK_ID',
+ reason: 'SUCCESS',
+ status: {
+ operationType: 'COPY'
+ }
+ };
+ item.cancelCallback();
+
+ // Check the updated item.
+ item = progressCenter.items['TASK_ID'];
+ assertEquals(ProgressItemState.COMPLETED, item.state);
+ assertEquals('TASK_ID', item.id);
+ assertEquals('', item.message);
+ assertEquals('copy', item.type);
+ assertEquals(false, item.summarized);
+ assertEquals(100, item.progressRateInPercent);
+}
+
+// Test for copy cancel.
+function testCopyCancel() {
+ // Dispatch an event.
+ fileOperationManager.dispatchEvent({
+ type: 'copy-progress',
+ taskId: 'TASK_ID',
+ reason: 'BEGIN',
+ status: {
+ operationType: 'COPY',
+ numRemainingItems: 1,
+ processingEntry: {name: 'sample.txt'},
+ totalBytes: 200,
+ processedBytes: 0
+ }
+ });
+
+ // Check the updated item.
+ var item = progressCenter.items['TASK_ID'];
+ assertEquals(ProgressItemState.PROGRESSING, item.state);
+ assertEquals('Copying sample.txt...', item.message);
+ assertEquals('copy', item.type);
+ assertEquals(false, item.summarized);
+ assertEquals(0, item.progressRateInPercent);
+
+ // Dispatch an event.
+ fileOperationManager.dispatchEvent({
+ type: 'copy-progress',
+ taskId: 'TASK_ID',
+ reason: 'CANCELED',
+ status: {
+ operationType: 'COPY'
+ }
+ });
+
+ // Check the updated item.
+ item = progressCenter.items['TASK_ID'];
+ assertEquals(ProgressItemState.CANCELED, item.state);
+ assertEquals('', item.message);
+ assertEquals('copy', item.type);
+ assertEquals(false, item.summarized);
+ assertEquals(0, item.progressRateInPercent);
+}
+
+// Test for copy target exists error.
+function testCopyTargetExistsError() {
+ // Dispatch an event.
+ fileOperationManager.dispatchEvent({
+ type: 'copy-progress',
+ taskId: 'TASK_ID',
+ reason: 'ERROR',
+ status: {
+ operationType: 'COPY'
+ },
+ error: {
+ code: util.FileOperationErrorType.TARGET_EXISTS,
+ data: {name: 'sample.txt'}
+ }
+ });
+
+ // Check the updated item.
+ var item = progressCenter.items['TASK_ID'];
+ assertEquals(ProgressItemState.ERROR, item.state);
+ assertEquals('sample.txt is already exists.', item.message);
+ assertEquals('copy', item.type);
+ assertEquals(false, item.summarized);
+ assertEquals(0, item.progressRateInPercent);
+}
+
+// Test for copy file system error.
+function testCopyFileSystemError() {
+ // Dispatch an event.
+ fileOperationManager.dispatchEvent({
+ type: 'copy-progress',
+ taskId: 'TASK_ID',
+ reason: 'ERROR',
+ status: {
+ operationType: 'COPY'
+ },
+ error: {
+ code: util.FileOperationErrorType.FILESYSTEM_ERROR,
+ data: {code: ''}
+ }
+ });
+
+ // Check the updated item.
+ var item = progressCenter.items['TASK_ID'];
+ assertEquals(ProgressItemState.ERROR, item.state);
+ assertEquals('Copy filesystem error: File error generic.', item.message);
+ assertEquals('copy', item.type);
+ assertEquals(false, item.summarized);
+ assertEquals(0, item.progressRateInPercent);
+}
+
+// Test for copy unexpected error.
+function testCopyUnexpectedError() {
+ // Dispatch an event.
+ fileOperationManager.dispatchEvent({
+ type: 'copy-progress',
+ taskId: 'TASK_ID',
+ reason: 'ERROR',
+ status: {
+ operationType: 'COPY'
+ },
+ error: {
+ code: 'Unexpected',
+ data: {name: 'sample.txt'}
+ }
+ });
+
+ // Check the updated item.
+ var item = progressCenter.items['TASK_ID'];
+ assertEquals(ProgressItemState.ERROR, item.state);
+ assertEquals('Copy unexpected error: Unexpected', item.message);
+ assertEquals('copy', item.type);
+ assertEquals(false, item.summarized);
+ assertEquals(0, item.progressRateInPercent);
+}
« no previous file with comments | « chrome/test/data/file_manager/unit_tests/progress_center_handler_unittest.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698