1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
12 // Set up the test components.
14 // Set up string assets.
16 COPY_FILE_NAME: 'Copying $1...',
17 COPY_TARGET_EXISTS_ERROR: '$1 is already exists.',
18 COPY_FILESYSTEM_ERROR: 'Copy filesystem error: $1',
19 FILE_ERROR_GENERIC: 'File error generic.',
20 COPY_UNEXPECTED_ERROR: 'Copy unexpected error: $1'
23 // Make ProgressCenterHandler.
24 background = new MockBackground();
25 handler = new FileOperationHandler(background);
28 // Test for success copy.
29 function testCopySuccess() {
31 background.fileOperationManager.dispatchEvent({
32 type: 'copy-progress',
36 operationType: 'COPY',
38 processingEntryName: 'sample.txt',
44 // Check the updated item.
45 var item = background.progressCenter.items['TASK_ID'];
46 assertEquals(ProgressItemState.PROGRESSING, item.state);
47 assertEquals('TASK_ID', item.id);
48 assertEquals('Copying sample.txt...', item.message);
49 assertEquals('copy', item.type);
50 assertEquals(true, item.single);
51 assertEquals(0, item.progressRateInPercent);
54 background.fileOperationManager.dispatchEvent({
55 type: 'copy-progress',
63 // Check the updated item.
64 item = background.progressCenter.items['TASK_ID'];
65 assertEquals(ProgressItemState.COMPLETED, item.state);
66 assertEquals('TASK_ID', item.id);
67 assertEquals('', item.message);
68 assertEquals('copy', item.type);
69 assertEquals(true, item.single);
70 assertEquals(100, item.progressRateInPercent);
71 assertEquals(1, background.closeRequestCount);
74 // Test for copy cancel.
75 function testCopyCancel() {
77 background.fileOperationManager.dispatchEvent({
78 type: 'copy-progress',
82 operationType: 'COPY',
84 processingEntryName: 'sample.txt',
90 // Check the updated item.
91 var item = background.progressCenter.items['TASK_ID'];
92 assertEquals(ProgressItemState.PROGRESSING, item.state);
93 assertEquals('Copying sample.txt...', item.message);
94 assertEquals('copy', item.type);
95 assertEquals(true, item.single);
96 assertEquals(0, item.progressRateInPercent);
99 background.fileOperationManager.cancelEvent = {
100 type: 'copy-progress',
104 operationType: 'COPY'
107 item.cancelCallback();
109 // Check the updated item.
110 item = background.progressCenter.items['TASK_ID'];
111 assertEquals(ProgressItemState.CANCELED, item.state);
112 assertEquals('', item.message);
113 assertEquals('copy', item.type);
114 assertEquals(true, item.single);
115 assertEquals(0, item.progressRateInPercent);
116 assertEquals(1, background.closeRequestCount);
119 // Test for copy target exists error.
120 function testCopyTargetExistsError() {
121 // Dispatch an event.
122 background.fileOperationManager.dispatchEvent({
123 type: 'copy-progress',
127 operationType: 'COPY'
130 code: util.FileOperationErrorType.TARGET_EXISTS,
131 data: {name: 'sample.txt'}
135 // Check the updated item.
136 var item = background.progressCenter.items['TASK_ID'];
137 assertEquals(ProgressItemState.ERROR, item.state);
138 assertEquals('sample.txt is already exists.', item.message);
139 assertEquals('copy', item.type);
140 assertEquals(true, item.single);
141 assertEquals(0, item.progressRateInPercent);
142 assertEquals(1, background.closeRequestCount);
145 // Test for copy file system error.
146 function testCopyFileSystemError() {
147 // Dispatch an event.
148 background.fileOperationManager.dispatchEvent({
149 type: 'copy-progress',
153 operationType: 'COPY'
156 code: util.FileOperationErrorType.FILESYSTEM_ERROR,
161 // Check the updated item.
162 var item = background.progressCenter.items['TASK_ID'];
163 assertEquals(ProgressItemState.ERROR, item.state);
164 assertEquals('Copy filesystem error: File error generic.', item.message);
165 assertEquals('copy', item.type);
166 assertEquals(true, item.single);
167 assertEquals(0, item.progressRateInPercent);
168 assertEquals(1, background.closeRequestCount);
171 // Test for copy unexpected error.
172 function testCopyUnexpectedError() {
173 // Dispatch an event.
174 background.fileOperationManager.dispatchEvent({
175 type: 'copy-progress',
179 operationType: 'COPY'
183 data: {name: 'sample.txt'}
187 // Check the updated item.
188 var item = background.progressCenter.items['TASK_ID'];
189 assertEquals(ProgressItemState.ERROR, item.state);
190 assertEquals('Copy unexpected error: Unexpected', item.message);
191 assertEquals('copy', item.type);
192 assertEquals(true, item.single);
193 assertEquals(0, item.progressRateInPercent);
194 assertEquals(1, background.closeRequestCount);