Commit 0bb6b2a8 authored by Noel Gordon's avatar Noel Gordon Committed by Commit Bot

Closure compile file_operation_handler_unittest

 - remove file_operation_handler_unittest.html
 - add BUILD rules to auto-generate and compile this unittest
 - document, add Closure @type's, and auto-format the unittest
 - fix Closure compile errors

No change in test behavior, no new tests.

Bug: 910774
Change-Id: Ie91e8ac6951821af05cd5c8482b7be7ae2c3b04f
Reviewed-on: https://chromium-review.googlesource.com/c/1356726
Commit-Queue: Noel Gordon <noel@chromium.org>
Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612990}
parent 5b3c3ff0
...@@ -25,8 +25,7 @@ IN_PROC_BROWSER_TEST_F(FileManagerJsTest, NavigationListModelTest) { ...@@ -25,8 +25,7 @@ IN_PROC_BROWSER_TEST_F(FileManagerJsTest, NavigationListModelTest) {
} }
IN_PROC_BROWSER_TEST_F(FileManagerJsTest, FileOperationHandlerTest) { IN_PROC_BROWSER_TEST_F(FileManagerJsTest, FileOperationHandlerTest) {
RunTest(base::FilePath( RunGeneratedTest("/background/js/file_operation_handler_unittest.html");
FILE_PATH_LITERAL("background/js/file_operation_handler_unittest.html")));
} }
IN_PROC_BROWSER_TEST_F(FileManagerJsTest, ProgressCenterItemGroupTest) { IN_PROC_BROWSER_TEST_F(FileManagerJsTest, ProgressCenterItemGroupTest) {
......
...@@ -234,7 +234,15 @@ js_library("file_operation_handler") { ...@@ -234,7 +234,15 @@ js_library("file_operation_handler") {
deps = [ deps = [
":file_operation_manager", ":file_operation_manager",
":progress_center", ":progress_center",
"../../common/js:progress_center_common", ]
}
js_unittest("file_operation_handler_unittest") {
deps = [
":file_operation_handler",
":mock_file_operation_manager",
":mock_progress_center",
"//ui/file_manager/base/js:test_error_reporting",
] ]
} }
...@@ -488,6 +496,7 @@ js_unit_tests("unit_tests") { ...@@ -488,6 +496,7 @@ js_unit_tests("unit_tests") {
":device_handler_unittest", ":device_handler_unittest",
":drive_sync_handler_unittest", ":drive_sync_handler_unittest",
":duplicate_finder_unittest", ":duplicate_finder_unittest",
":file_operation_handler_unittest",
":file_operation_manager_unittest", ":file_operation_manager_unittest",
":import_history_unittest", ":import_history_unittest",
":media_scanner_unittest", ":media_scanner_unittest",
......
<!DOCTYPE html>
<!-- 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.
-->
<html>
<body>
<script src="../../../../../ui/webui/resources/js/assert.js"></script>
<script src="../../../../../ui/webui/resources/js/cr.js"></script>
<script src="../../../../../ui/webui/resources/js/cr/event_target.js"></script>
<script src="../../../../../ui/webui/resources/js/load_time_data.js"></script>
<script src="../../common/js/progress_center_common.js"></script>
<script src="../../common/js/util.js"></script>
<script src="mock_file_operation_manager.js"></script>
<script src="mock_progress_center.js"></script>
<script src="file_operation_util.js"></script>
<script src="file_operation_handler.js"></script>
<script src="file_operation_handler_unittest.js"></script>
</body>
</html>
// Copyright 2013 The Chromium Authors. All rights reserved. // Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
'use strict'; 'use strict';
// Mock items. /** @type {!MockFileOperationManager} */
var fileOperationManager = null; var fileOperationManager;
var progressCenter = null;
/** @type {!MockProgressCenter} */
var progressCenter;
// Test target. /** @type {!FileOperationHandler} */
var handler = null; var fileOperationHandler;
// Set up the test components. // Set up the test components.
function setUp() { function setUp() {
// Set up string assets. // Mock LoadTimeData strings.
window.loadTimeData.data = { window.loadTimeData.data = {
COPY_FILE_NAME: 'Copying $1...', COPY_FILE_NAME: 'Copying $1...',
COPY_TARGET_EXISTS_ERROR: '$1 is already exists.', COPY_TARGET_EXISTS_ERROR: '$1 is already exists.',
...@@ -21,27 +24,34 @@ function setUp() { ...@@ -21,27 +24,34 @@ function setUp() {
COPY_UNEXPECTED_ERROR: 'Copy unexpected error: $1' COPY_UNEXPECTED_ERROR: 'Copy unexpected error: $1'
}; };
// Make ProgressCenterHandler. // Create mock items needed for FileOperationHandler.
fileOperationManager = new MockFileOperationManager(); fileOperationManager = new MockFileOperationManager();
progressCenter = new MockProgressCenter(); progressCenter = new MockProgressCenter();
handler = new FileOperationHandler(fileOperationManager, progressCenter);
// Create FileOperationHandler. Note: the file operation handler is
// required, but not used directly, by the unittests.
fileOperationHandler =
new FileOperationHandler(fileOperationManager, progressCenter);
} }
// Test for success copy. /**
* Tests copy success.
*/
function testCopySuccess() { function testCopySuccess() {
// Dispatch an event. // Dispatch copy event.
fileOperationManager.dispatchEvent({ fileOperationManager.dispatchEvent(
type: 'copy-progress', /** @type {!Event} */ ({
taskId: 'TASK_ID', type: 'copy-progress',
reason: fileOperationUtil.EventRouter.EventType.BEGIN, taskId: 'TASK_ID',
status: { reason: fileOperationUtil.EventRouter.EventType.BEGIN,
operationType: 'COPY', status: {
numRemainingItems: 1, operationType: 'COPY',
processingEntryName: 'sample.txt', numRemainingItems: 1,
totalBytes: 200, processingEntryName: 'sample.txt',
processedBytes: 0 totalBytes: 200,
} processedBytes: 0,
}); },
}));
// Check the updated item. // Check the updated item.
var item = progressCenter.items['TASK_ID']; var item = progressCenter.items['TASK_ID'];
...@@ -52,17 +62,18 @@ function testCopySuccess() { ...@@ -52,17 +62,18 @@ function testCopySuccess() {
assertEquals(true, item.single); assertEquals(true, item.single);
assertEquals(0, item.progressRateInPercent); assertEquals(0, item.progressRateInPercent);
// Dispatch an event. // Dispatch success event.
fileOperationManager.dispatchEvent({ fileOperationManager.dispatchEvent(
type: 'copy-progress', /** @type {!Event} */ ({
taskId: 'TASK_ID', type: 'copy-progress',
reason: fileOperationUtil.EventRouter.EventType.SUCCESS, taskId: 'TASK_ID',
status: { reason: fileOperationUtil.EventRouter.EventType.SUCCESS,
operationType: 'COPY' status: {
} operationType: 'COPY',
}); },
}));
// Check the updated item.
// Check the item completed.
item = progressCenter.items['TASK_ID']; item = progressCenter.items['TASK_ID'];
assertEquals(ProgressItemState.COMPLETED, item.state); assertEquals(ProgressItemState.COMPLETED, item.state);
assertEquals('TASK_ID', item.id); assertEquals('TASK_ID', item.id);
...@@ -72,21 +83,24 @@ function testCopySuccess() { ...@@ -72,21 +83,24 @@ function testCopySuccess() {
assertEquals(100, item.progressRateInPercent); assertEquals(100, item.progressRateInPercent);
} }
// Test for copy cancel. /**
* Tests copy cancel.
*/
function testCopyCancel() { function testCopyCancel() {
// Dispatch an event. // Dispatch copy event.
fileOperationManager.dispatchEvent({ fileOperationManager.dispatchEvent(
type: 'copy-progress', /** @type {!Event} */ ({
taskId: 'TASK_ID', type: 'copy-progress',
reason: fileOperationUtil.EventRouter.EventType.BEGIN, taskId: 'TASK_ID',
status: { reason: fileOperationUtil.EventRouter.EventType.BEGIN,
operationType: 'COPY', status: {
numRemainingItems: 1, operationType: 'COPY',
processingEntryName: 'sample.txt', numRemainingItems: 1,
totalBytes: 200, processingEntryName: 'sample.txt',
processedBytes: 0 totalBytes: 200,
} processedBytes: 0,
}); },
}));
// Check the updated item. // Check the updated item.
var item = progressCenter.items['TASK_ID']; var item = progressCenter.items['TASK_ID'];
...@@ -96,18 +110,22 @@ function testCopyCancel() { ...@@ -96,18 +110,22 @@ function testCopyCancel() {
assertEquals(true, item.single); assertEquals(true, item.single);
assertEquals(0, item.progressRateInPercent); assertEquals(0, item.progressRateInPercent);
// Dispatch an event. // Setup cancel event.
fileOperationManager.cancelEvent = { fileOperationManager.cancelEvent =
type: 'copy-progress', /** @type {!Event} */ ({
taskId: 'TASK_ID', type: 'copy-progress',
reason: fileOperationUtil.EventRouter.EventType.CANCELED, taskId: 'TASK_ID',
status: { reason: fileOperationUtil.EventRouter.EventType.CANCELED,
operationType: 'COPY' status: {
} operationType: 'COPY',
}; },
});
// Dispatch cancel event.
assertTrue(item.cancelable);
item.cancelCallback(); item.cancelCallback();
// Check the updated item. // Check the item cancelled.
item = progressCenter.items['TASK_ID']; item = progressCenter.items['TASK_ID'];
assertEquals(ProgressItemState.CANCELED, item.state); assertEquals(ProgressItemState.CANCELED, item.state);
assertEquals('', item.message); assertEquals('', item.message);
...@@ -116,23 +134,28 @@ function testCopyCancel() { ...@@ -116,23 +134,28 @@ function testCopyCancel() {
assertEquals(0, item.progressRateInPercent); assertEquals(0, item.progressRateInPercent);
} }
// Test for copy target exists error. /**
* Tests target already exists error.
*/
function testCopyTargetExistsError() { function testCopyTargetExistsError() {
// Dispatch an event. // Dispatch error event.
fileOperationManager.dispatchEvent({ fileOperationManager.dispatchEvent(
type: 'copy-progress', /** @type {!Event} */ ({
taskId: 'TASK_ID', type: 'copy-progress',
reason: fileOperationUtil.EventRouter.EventType.ERROR, taskId: 'TASK_ID',
status: { reason: fileOperationUtil.EventRouter.EventType.ERROR,
operationType: 'COPY' status: {
}, operationType: 'COPY',
error: { },
code: util.FileOperationErrorType.TARGET_EXISTS, error: {
data: {name: 'sample.txt'} code: util.FileOperationErrorType.TARGET_EXISTS,
} data: {
}); name: 'sample.txt',
},
// Check the updated item. },
}));
// Check the item errored.
var item = progressCenter.items['TASK_ID']; var item = progressCenter.items['TASK_ID'];
assertEquals(ProgressItemState.ERROR, item.state); assertEquals(ProgressItemState.ERROR, item.state);
assertEquals('sample.txt is already exists.', item.message); assertEquals('sample.txt is already exists.', item.message);
...@@ -141,23 +164,28 @@ function testCopyTargetExistsError() { ...@@ -141,23 +164,28 @@ function testCopyTargetExistsError() {
assertEquals(0, item.progressRateInPercent); assertEquals(0, item.progressRateInPercent);
} }
// Test for copy file system error. /**
* Tests file system error.
*/
function testCopyFileSystemError() { function testCopyFileSystemError() {
// Dispatch an event. // Dispatch error event.
fileOperationManager.dispatchEvent({ fileOperationManager.dispatchEvent(
type: 'copy-progress', /** @type {!Event} */ ({
taskId: 'TASK_ID', type: 'copy-progress',
reason: fileOperationUtil.EventRouter.EventType.ERROR, taskId: 'TASK_ID',
status: { reason: fileOperationUtil.EventRouter.EventType.ERROR,
operationType: 'COPY' status: {
}, operationType: 'COPY',
error: { },
code: util.FileOperationErrorType.FILESYSTEM_ERROR, error: {
data: {code: ''} code: util.FileOperationErrorType.FILESYSTEM_ERROR,
} data: {
}); name: 'sample.txt',
},
// Check the updated item. },
}));
// Check the item errored.
var item = progressCenter.items['TASK_ID']; var item = progressCenter.items['TASK_ID'];
assertEquals(ProgressItemState.ERROR, item.state); assertEquals(ProgressItemState.ERROR, item.state);
assertEquals('Copy filesystem error: File error generic.', item.message); assertEquals('Copy filesystem error: File error generic.', item.message);
...@@ -166,23 +194,28 @@ function testCopyFileSystemError() { ...@@ -166,23 +194,28 @@ function testCopyFileSystemError() {
assertEquals(0, item.progressRateInPercent); assertEquals(0, item.progressRateInPercent);
} }
// Test for copy unexpected error. /**
* Tests unexpected error.
*/
function testCopyUnexpectedError() { function testCopyUnexpectedError() {
// Dispatch an event. // Dispatch error event.
fileOperationManager.dispatchEvent({ fileOperationManager.dispatchEvent(
type: 'copy-progress', /** @type {!Event} */ ({
taskId: 'TASK_ID', type: 'copy-progress',
reason: fileOperationUtil.EventRouter.EventType.ERROR, taskId: 'TASK_ID',
status: { reason: fileOperationUtil.EventRouter.EventType.ERROR,
operationType: 'COPY' status: {
}, operationType: 'COPY',
error: { },
code: 'Unexpected', error: {
data: {name: 'sample.txt'} code: 'Unexpected',
} data: {
}); name: 'sample.txt',
},
// Check the updated item. },
}));
// Check the item errored.
var item = progressCenter.items['TASK_ID']; var item = progressCenter.items['TASK_ID'];
assertEquals(ProgressItemState.ERROR, item.state); assertEquals(ProgressItemState.ERROR, item.state);
assertEquals('Copy unexpected error: Unexpected', item.message); assertEquals('Copy unexpected error: Unexpected', item.message);
......
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