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) {
}
IN_PROC_BROWSER_TEST_F(FileManagerJsTest, FileOperationHandlerTest) {
RunTest(base::FilePath(
FILE_PATH_LITERAL("background/js/file_operation_handler_unittest.html")));
RunGeneratedTest("/background/js/file_operation_handler_unittest.html");
}
IN_PROC_BROWSER_TEST_F(FileManagerJsTest, ProgressCenterItemGroupTest) {
......
......@@ -234,7 +234,15 @@ js_library("file_operation_handler") {
deps = [
":file_operation_manager",
":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") {
":device_handler_unittest",
":drive_sync_handler_unittest",
":duplicate_finder_unittest",
":file_operation_handler_unittest",
":file_operation_manager_unittest",
":import_history_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.
// 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;
/** @type {!MockFileOperationManager} */
var fileOperationManager;
/** @type {!MockProgressCenter} */
var progressCenter;
// Test target.
var handler = null;
/** @type {!FileOperationHandler} */
var fileOperationHandler;
// Set up the test components.
function setUp() {
// Set up string assets.
// Mock LoadTimeData strings.
window.loadTimeData.data = {
COPY_FILE_NAME: 'Copying $1...',
COPY_TARGET_EXISTS_ERROR: '$1 is already exists.',
......@@ -21,16 +24,23 @@ function setUp() {
COPY_UNEXPECTED_ERROR: 'Copy unexpected error: $1'
};
// Make ProgressCenterHandler.
// Create mock items needed for FileOperationHandler.
fileOperationManager = new MockFileOperationManager();
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() {
// Dispatch an event.
fileOperationManager.dispatchEvent({
// Dispatch copy event.
fileOperationManager.dispatchEvent(
/** @type {!Event} */ ({
type: 'copy-progress',
taskId: 'TASK_ID',
reason: fileOperationUtil.EventRouter.EventType.BEGIN,
......@@ -39,9 +49,9 @@ function testCopySuccess() {
numRemainingItems: 1,
processingEntryName: 'sample.txt',
totalBytes: 200,
processedBytes: 0
}
});
processedBytes: 0,
},
}));
// Check the updated item.
var item = progressCenter.items['TASK_ID'];
......@@ -52,17 +62,18 @@ function testCopySuccess() {
assertEquals(true, item.single);
assertEquals(0, item.progressRateInPercent);
// Dispatch an event.
fileOperationManager.dispatchEvent({
// Dispatch success event.
fileOperationManager.dispatchEvent(
/** @type {!Event} */ ({
type: 'copy-progress',
taskId: 'TASK_ID',
reason: fileOperationUtil.EventRouter.EventType.SUCCESS,
status: {
operationType: 'COPY'
}
});
operationType: 'COPY',
},
}));
// Check the updated item.
// Check the item completed.
item = progressCenter.items['TASK_ID'];
assertEquals(ProgressItemState.COMPLETED, item.state);
assertEquals('TASK_ID', item.id);
......@@ -72,10 +83,13 @@ function testCopySuccess() {
assertEquals(100, item.progressRateInPercent);
}
// Test for copy cancel.
/**
* Tests copy cancel.
*/
function testCopyCancel() {
// Dispatch an event.
fileOperationManager.dispatchEvent({
// Dispatch copy event.
fileOperationManager.dispatchEvent(
/** @type {!Event} */ ({
type: 'copy-progress',
taskId: 'TASK_ID',
reason: fileOperationUtil.EventRouter.EventType.BEGIN,
......@@ -84,9 +98,9 @@ function testCopyCancel() {
numRemainingItems: 1,
processingEntryName: 'sample.txt',
totalBytes: 200,
processedBytes: 0
}
});
processedBytes: 0,
},
}));
// Check the updated item.
var item = progressCenter.items['TASK_ID'];
......@@ -96,18 +110,22 @@ function testCopyCancel() {
assertEquals(true, item.single);
assertEquals(0, item.progressRateInPercent);
// Dispatch an event.
fileOperationManager.cancelEvent = {
// Setup cancel event.
fileOperationManager.cancelEvent =
/** @type {!Event} */ ({
type: 'copy-progress',
taskId: 'TASK_ID',
reason: fileOperationUtil.EventRouter.EventType.CANCELED,
status: {
operationType: 'COPY'
}
};
operationType: 'COPY',
},
});
// Dispatch cancel event.
assertTrue(item.cancelable);
item.cancelCallback();
// Check the updated item.
// Check the item cancelled.
item = progressCenter.items['TASK_ID'];
assertEquals(ProgressItemState.CANCELED, item.state);
assertEquals('', item.message);
......@@ -116,23 +134,28 @@ function testCopyCancel() {
assertEquals(0, item.progressRateInPercent);
}
// Test for copy target exists error.
/**
* Tests target already exists error.
*/
function testCopyTargetExistsError() {
// Dispatch an event.
fileOperationManager.dispatchEvent({
// Dispatch error event.
fileOperationManager.dispatchEvent(
/** @type {!Event} */ ({
type: 'copy-progress',
taskId: 'TASK_ID',
reason: fileOperationUtil.EventRouter.EventType.ERROR,
status: {
operationType: 'COPY'
operationType: 'COPY',
},
error: {
code: util.FileOperationErrorType.TARGET_EXISTS,
data: {name: 'sample.txt'}
}
});
data: {
name: 'sample.txt',
},
},
}));
// Check the updated item.
// Check the item errored.
var item = progressCenter.items['TASK_ID'];
assertEquals(ProgressItemState.ERROR, item.state);
assertEquals('sample.txt is already exists.', item.message);
......@@ -141,23 +164,28 @@ function testCopyTargetExistsError() {
assertEquals(0, item.progressRateInPercent);
}
// Test for copy file system error.
/**
* Tests file system error.
*/
function testCopyFileSystemError() {
// Dispatch an event.
fileOperationManager.dispatchEvent({
// Dispatch error event.
fileOperationManager.dispatchEvent(
/** @type {!Event} */ ({
type: 'copy-progress',
taskId: 'TASK_ID',
reason: fileOperationUtil.EventRouter.EventType.ERROR,
status: {
operationType: 'COPY'
operationType: 'COPY',
},
error: {
code: util.FileOperationErrorType.FILESYSTEM_ERROR,
data: {code: ''}
}
});
data: {
name: 'sample.txt',
},
},
}));
// Check the updated item.
// Check the item errored.
var item = progressCenter.items['TASK_ID'];
assertEquals(ProgressItemState.ERROR, item.state);
assertEquals('Copy filesystem error: File error generic.', item.message);
......@@ -166,23 +194,28 @@ function testCopyFileSystemError() {
assertEquals(0, item.progressRateInPercent);
}
// Test for copy unexpected error.
/**
* Tests unexpected error.
*/
function testCopyUnexpectedError() {
// Dispatch an event.
fileOperationManager.dispatchEvent({
// Dispatch error event.
fileOperationManager.dispatchEvent(
/** @type {!Event} */ ({
type: 'copy-progress',
taskId: 'TASK_ID',
reason: fileOperationUtil.EventRouter.EventType.ERROR,
status: {
operationType: 'COPY'
operationType: 'COPY',
},
error: {
code: 'Unexpected',
data: {name: 'sample.txt'}
}
});
data: {
name: 'sample.txt',
},
},
}));
// Check the updated item.
// Check the item errored.
var item = progressCenter.items['TASK_ID'];
assertEquals(ProgressItemState.ERROR, item.state);
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