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

Side by Side Diff: chrome/test/data/file_manager/unit_tests/file_operation_manager_unittest.js

Issue 441643004: Add unit tests for utility functions of FileOperationManager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed. Created 6 years, 4 months 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
OLDNEW
(Empty)
1 // Copyright 2014 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 /**
7 * Reports the result of promise to the test system.
8 * @param {Promise} promise Promise to be fulfilled or rejected.
9 * @param {function(boolean:hasError)} callback Callback to be passed true on
10 * error.
11 */
12 function reportPromise(promise, callback) {
13 promise.then(
14 callback.bind(null, false),
15 function(error) {
16 if (error instanceof FileOperationManager.Error) {
17 console.log('FileOperationManager.Error: code=' + error.code);
18 } else {
19 console.log(error.stack || error.name || error);
20 }
21 callback(true);
22 });
23 }
24
25 /**
26 * Tests the fileOperationUtil.resolvePath function.
27 * @param {function(boolean:hasError)} callback Callback to be passed true on
28 * error.
29 */
30 function testResolvePath(callback) {
31 var fileEntry = new MockFileEntry('testVolume', '/file', {});
32 var directoryEntry = new MockDirectoryEntry('testVolume', '/directory', {});
33 var root = new MockDirectoryEntry('testVolume', '/', {
34 '/file': fileEntry,
35 '/directory': directoryEntry
36 });
37 var rootPromise = fileOperationUtil.resolvePath(root, '/');
38 var filePromise = fileOperationUtil.resolvePath(root, '/file');
39 var directoryPromise = fileOperationUtil.resolvePath(root, '/directory');
40 var errorPromise = fileOperationUtil.resolvePath(root, '/not_found').then(
41 function() {
42 assertTrue(false, 'The NOT_FOUND error is not reported.');
43 },
44 function(error) {
45 assertEquals('NotFoundError', error.name);
46 });
47 reportPromise(Promise.all([
48 rootPromise,
49 filePromise,
50 directoryPromise,
51 errorPromise
52 ]).then(function(results) {
53 assertArrayEquals([
54 root,
55 fileEntry,
56 directoryEntry,
57 undefined
58 ], results);
59 }), callback);
60 }
61
62 /**
63 * Tests the fileOperationUtil.deduplicatePath
64 * @param {function(boolean:hasError)} callback Callback to be passed true on
65 * error.
66 */
67 function testDeduplicatePath(callback) {
68 var directoryEntry1 = new MockDirectoryEntry('testVolume', '/directory', {});
69 var directoryEntry2 = new MockDirectoryEntry(
70 'testVolume',
71 '/directory',
72 {'file.txt': new MockFileEntry('testVolume', '/file.txt', {})});
73 var directoryEntry3 = new MockDirectoryEntry(
74 'testVolume',
75 '/directory',
76 {
77 'file.txt': new MockFileEntry('testVolume', '/file.txt', {}),
78 'file (1).txt': new MockFileEntry('testVolume', '/file (1).txt', {}),
79 'file (2).txt': new MockFileEntry('testVolume', '/file (2).txt', {}),
80 'file (3).txt': new MockFileEntry('testVolume', '/file (3).txt', {}),
81 'file (4).txt': new MockFileEntry('testVolume', '/file (4).txt', {}),
82 'file (5).txt': new MockFileEntry('testVolume', '/file (5).txt', {}),
83 'file (6).txt': new MockFileEntry('testVolume', '/file (6).txt', {}),
84 'file (7).txt': new MockFileEntry('testVolume', '/file (7).txt', {}),
85 'file (8).txt': new MockFileEntry('testVolume', '/file (8).txt', {}),
86 'file (9).txt': new MockFileEntry('testVolume', '/file (9).txt', {})
87 });
88
89 var nonExistingPromise =
90 fileOperationUtil.deduplicatePath(directoryEntry1, 'file.txt').
91 then(function(path) {
92 assertEquals('file.txt', path);
93 });
94 var existingPathPromise =
95 fileOperationUtil.deduplicatePath(directoryEntry2, 'file.txt').
96 then(function(path) {
97 assertEquals('file (1).txt', path);
98 });
99 var failedPromise =
100 fileOperationUtil.deduplicatePath(directoryEntry3, 'file.txt').
101 then(function() {
102 assertTrue(false, 'FileOperationManager.Error is not reported.');
103 }, function(error) {
104 assertTrue(error instanceof FileOperationManager.Error);
105 assertEquals(util.FileOperationErrorType.TARGET_EXISTS, error.code);
106 });
107
108 var testPromise = Promise.all([
109 nonExistingPromise,
110 existingPathPromise,
111 failedPromise
112 ]);
113 reportPromise(testPromise, callback);
114 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698