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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4 'use strict';
5
6 // Mock items.
7 var fileOperationManager = null;
8 var progressCenter = null;
9
10 // Test target.
11 var handler = null;
12
13 // Set up the test components.
14 function setUp() {
15 // Set up string assets.
16 loadTimeData.data = {
17 COPY_FILE_NAME: 'Copying $1...',
18 COPY_TARGET_EXISTS_ERROR: '$1 is already exists.',
19 COPY_FILESYSTEM_ERROR: 'Copy filesystem error: $1',
20 FILE_ERROR_GENERIC: 'File error generic.',
21 COPY_UNEXPECTED_ERROR: 'Copy unexpected error: $1'
22 };
23
24 // Make ProgressCenterHandler.
25 fileOperationManager = new MockFileOperationManager();
26 progressCenter = new MockProgressCenter();
27 handler = new ProgressCenterHandler(
28 fileOperationManager,
29 progressCenter);
30 }
31
32 // Test for success copy.
33 function testCopySuccess() {
34 // Dispatch an event.
35 fileOperationManager.dispatchEvent({
36 type: 'copy-progress',
37 taskId: 'TASK_ID',
38 reason: 'BEGIN',
39 status: {
40 operationType: 'COPY',
41 numRemainingItems: 1,
42 processingEntry: {name: 'sample.txt'},
43 totalBytes: 200,
44 processedBytes: 0
45 }
46 });
47
48 // Check the updated item.
49 var item = progressCenter.items['TASK_ID'];
50 assertEquals(ProgressItemState.PROGRESSING, item.state);
51 assertEquals('TASK_ID', item.id);
52 assertEquals('Copying sample.txt...', item.message);
53 assertEquals('copy', item.type);
54 assertEquals(false, item.summarized);
55 assertEquals(0, item.progressRateInPercent);
56
57 // Dispatch an event.
58 fileOperationManager.cancelEvent = {
59 type: 'copy-progress',
60 taskId: 'TASK_ID',
61 reason: 'SUCCESS',
62 status: {
63 operationType: 'COPY'
64 }
65 };
66 item.cancelCallback();
67
68 // Check the updated item.
69 item = progressCenter.items['TASK_ID'];
70 assertEquals(ProgressItemState.COMPLETED, item.state);
71 assertEquals('TASK_ID', item.id);
72 assertEquals('', item.message);
73 assertEquals('copy', item.type);
74 assertEquals(false, item.summarized);
75 assertEquals(100, item.progressRateInPercent);
76 }
77
78 // Test for copy cancel.
79 function testCopyCancel() {
80 // Dispatch an event.
81 fileOperationManager.dispatchEvent({
82 type: 'copy-progress',
83 taskId: 'TASK_ID',
84 reason: 'BEGIN',
85 status: {
86 operationType: 'COPY',
87 numRemainingItems: 1,
88 processingEntry: {name: 'sample.txt'},
89 totalBytes: 200,
90 processedBytes: 0
91 }
92 });
93
94 // Check the updated item.
95 var item = progressCenter.items['TASK_ID'];
96 assertEquals(ProgressItemState.PROGRESSING, item.state);
97 assertEquals('Copying sample.txt...', item.message);
98 assertEquals('copy', item.type);
99 assertEquals(false, item.summarized);
100 assertEquals(0, item.progressRateInPercent);
101
102 // Dispatch an event.
103 fileOperationManager.dispatchEvent({
104 type: 'copy-progress',
105 taskId: 'TASK_ID',
106 reason: 'CANCELED',
107 status: {
108 operationType: 'COPY'
109 }
110 });
111
112 // Check the updated item.
113 item = progressCenter.items['TASK_ID'];
114 assertEquals(ProgressItemState.CANCELED, item.state);
115 assertEquals('', item.message);
116 assertEquals('copy', item.type);
117 assertEquals(false, item.summarized);
118 assertEquals(0, item.progressRateInPercent);
119 }
120
121 // Test for copy target exists error.
122 function testCopyTargetExistsError() {
123 // Dispatch an event.
124 fileOperationManager.dispatchEvent({
125 type: 'copy-progress',
126 taskId: 'TASK_ID',
127 reason: 'ERROR',
128 status: {
129 operationType: 'COPY'
130 },
131 error: {
132 code: util.FileOperationErrorType.TARGET_EXISTS,
133 data: {name: 'sample.txt'}
134 }
135 });
136
137 // Check the updated item.
138 var item = progressCenter.items['TASK_ID'];
139 assertEquals(ProgressItemState.ERROR, item.state);
140 assertEquals('sample.txt is already exists.', item.message);
141 assertEquals('copy', item.type);
142 assertEquals(false, item.summarized);
143 assertEquals(0, item.progressRateInPercent);
144 }
145
146 // Test for copy file system error.
147 function testCopyFileSystemError() {
148 // Dispatch an event.
149 fileOperationManager.dispatchEvent({
150 type: 'copy-progress',
151 taskId: 'TASK_ID',
152 reason: 'ERROR',
153 status: {
154 operationType: 'COPY'
155 },
156 error: {
157 code: util.FileOperationErrorType.FILESYSTEM_ERROR,
158 data: {code: ''}
159 }
160 });
161
162 // Check the updated item.
163 var item = progressCenter.items['TASK_ID'];
164 assertEquals(ProgressItemState.ERROR, item.state);
165 assertEquals('Copy filesystem error: File error generic.', item.message);
166 assertEquals('copy', item.type);
167 assertEquals(false, item.summarized);
168 assertEquals(0, item.progressRateInPercent);
169 }
170
171 // Test for copy unexpected error.
172 function testCopyUnexpectedError() {
173 // Dispatch an event.
174 fileOperationManager.dispatchEvent({
175 type: 'copy-progress',
176 taskId: 'TASK_ID',
177 reason: 'ERROR',
178 status: {
179 operationType: 'COPY'
180 },
181 error: {
182 code: 'Unexpected',
183 data: {name: 'sample.txt'}
184 }
185 });
186
187 // Check the updated item.
188 var item = 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(false, item.summarized);
193 assertEquals(0, item.progressRateInPercent);
194 }
OLDNEW
« 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