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

Side by Side Diff: chrome/test/data/extensions/api_test/file_system_provider/get_metadata/test.js

Issue 295933002: [fsp] Do not crash on an invalid modification time. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments. Created 6 years, 7 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
« no previous file with comments | « chrome/browser/chromeos/file_system_provider/operations/get_metadata.cc ('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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 'use strict'; 5 'use strict';
6 6
7 var fileSystemId; 7 var fileSystemId;
8 var fileSystem; 8 var fileSystem;
9 9
10 /** 10 /**
(...skipping 12 matching lines...) Expand all
23 * @const 23 * @const
24 */ 24 */
25 var TESTING_FILE = Object.freeze({ 25 var TESTING_FILE = Object.freeze({
26 isDirectory: false, 26 isDirectory: false,
27 name: 'tiramisu.txt', 27 name: 'tiramisu.txt',
28 size: 4096, 28 size: 4096,
29 modificationTime: new Date(2014, 4, 28, 10, 39, 15) 29 modificationTime: new Date(2014, 4, 28, 10, 39, 15)
30 }); 30 });
31 31
32 /** 32 /**
33 * @type {Object}
34 * @const
35 */
36 var TESTING_WRONG_TIME_FILE = Object.freeze({
37 isDirectory: false,
38 name: 'invalid-time.txt',
39 size: 4096,
40 modificationTime: new Date('Invalid date.')
41 });
42
43 /**
33 * Returns metadata for a requested entry. 44 * Returns metadata for a requested entry.
34 * 45 *
35 * @param {number} inFileSystemId ID of the file system. 46 * @param {number} inFileSystemId ID of the file system.
36 * @param {string} entryPath Path of the requested entry. 47 * @param {string} entryPath Path of the requested entry.
37 * @param {function(Object)} onSuccess Success callback with metadata passed 48 * @param {function(Object)} onSuccess Success callback with metadata passed
38 * an argument. 49 * an argument.
39 * @param {function(string)} onError Error callback with an error code. 50 * @param {function(string)} onError Error callback with an error code.
40 */ 51 */
41 function onGetMetadataRequested( 52 function onGetMetadataRequested(
42 inFileSystemId, entryPath, onSuccess, onError) { 53 inFileSystemId, entryPath, onSuccess, onError) {
43 if (inFileSystemId != fileSystemId) { 54 if (inFileSystemId != fileSystemId) {
44 onError('SECURITY_ERROR'); // enum ProviderError. 55 onError('SECURITY_ERROR'); // enum ProviderError.
45 return; 56 return;
46 } 57 }
47 58
48 if (entryPath == '/') { 59 if (entryPath == '/') {
49 onSuccess(TESTING_ROOT); 60 onSuccess(TESTING_ROOT);
50 return; 61 return;
51 } 62 }
52 63
53 if (entryPath == '/' + TESTING_FILE.name) { 64 if (entryPath == '/' + TESTING_FILE.name) {
54 onSuccess(TESTING_FILE); 65 onSuccess(TESTING_FILE);
55 return; 66 return;
56 } 67 }
57 68
69 if (entryPath == '/' + TESTING_WRONG_TIME_FILE.name) {
70 onSuccess(TESTING_WRONG_TIME_FILE);
71 return;
72 }
73
58 onError('NOT_FOUND'); // enum ProviderError. 74 onError('NOT_FOUND'); // enum ProviderError.
59 } 75 }
60 76
61 /** 77 /**
62 * Sets up the tests. Called once per all test cases. In case of a failure, 78 * Sets up the tests. Called once per all test cases. In case of a failure,
63 * the callback is not called. 79 * the callback is not called.
64 * 80 *
65 * @param {function()} callback Success callback. 81 * @param {function()} callback Success callback.
66 */ 82 */
67 function setUp(callback) { 83 function setUp(callback) {
(...skipping 17 matching lines...) Expand all
85 }); 101 });
86 } 102 }
87 103
88 /** 104 /**
89 * Runs all of the test cases, one by one. 105 * Runs all of the test cases, one by one.
90 */ 106 */
91 function runTests() { 107 function runTests() {
92 chrome.test.runTests([ 108 chrome.test.runTests([
93 // Read metadata of the root. 109 // Read metadata of the root.
94 function getFileMetadataSuccess() { 110 function getFileMetadataSuccess() {
95 var onSuccess = chrome.test.callbackPass(function() {}); 111 var onSuccess = chrome.test.callbackPass();
96 fileSystem.root.getMetadata( 112 fileSystem.root.getMetadata(
97 function(metadata) { 113 function(metadata) {
98 chrome.test.assertEq(TESTING_ROOT.size, metadata.size); 114 chrome.test.assertEq(TESTING_ROOT.size, metadata.size);
99 chrome.test.assertEq( 115 chrome.test.assertEq(
100 TESTING_ROOT.modificationTime.toString(), 116 TESTING_ROOT.modificationTime.toString(),
101 metadata.modificationTime.toString()); 117 metadata.modificationTime.toString());
102 onSuccess(); 118 onSuccess();
103 }, function(error) { 119 }, function(error) {
104 chrome.test.fail(error.name); 120 chrome.test.fail(error.name);
105 }); 121 });
106 }, 122 },
107 // Read metadata of an existing testing file. 123 // Read metadata of an existing testing file.
108 function getFileMetadataSuccess() { 124 function getFileMetadataSuccess() {
109 var onSuccess = chrome.test.callbackPass(function() {}); 125 var onSuccess = chrome.test.callbackPass();
110 fileSystem.root.getFile( 126 fileSystem.root.getFile(
111 TESTING_FILE.name, 127 TESTING_FILE.name,
112 {create: false}, 128 {create: false},
113 function(fileEntry) { 129 function(fileEntry) {
114 chrome.test.assertEq(TESTING_FILE.name, fileEntry.name); 130 chrome.test.assertEq(TESTING_FILE.name, fileEntry.name);
115 chrome.test.assertEq( 131 chrome.test.assertEq(
116 TESTING_FILE.isDirectory, fileEntry.isDirectory); 132 TESTING_FILE.isDirectory, fileEntry.isDirectory);
117 fileEntry.getMetadata(function(metadata) { 133 fileEntry.getMetadata(function(metadata) {
118 chrome.test.assertEq(TESTING_FILE.size, metadata.size); 134 chrome.test.assertEq(TESTING_FILE.size, metadata.size);
119 chrome.test.assertEq( 135 chrome.test.assertEq(
120 TESTING_FILE.modificationTime.toString(), 136 TESTING_FILE.modificationTime.toString(),
121 metadata.modificationTime.toString()); 137 metadata.modificationTime.toString());
122 onSuccess(); 138 onSuccess();
123 }, function(error) { 139 }, function(error) {
124 chrome.test.fail(error.name); 140 chrome.test.fail(error.name);
125 }); 141 });
126 }, 142 },
127 function(error) { 143 function(error) {
128 chrome.test.fail(error.name); 144 chrome.test.fail(error.name);
129 }); 145 });
130 }, 146 },
147 // Read metadata of an existing testing file, which however has an invalid
148 // modification time. It should not cause an error, but an invalid date
149 // should be passed to fileapi instead. The reason is, that there is no
150 // easy way to verify an incorrect modification time at early stage.
151 function getFileMetadataWrongTimeSuccess() {
152 var onSuccess = chrome.test.callbackPass();
153 fileSystem.root.getFile(
154 TESTING_WRONG_TIME_FILE.name,
155 {create: false},
156 function(fileEntry) {
157 chrome.test.assertEq(TESTING_WRONG_TIME_FILE.name, fileEntry.name);
158 fileEntry.getMetadata(function(metadata) {
159 chrome.test.assertTrue(
160 Number.isNaN(metadata.modificationTime.getTime()));
161 onSuccess();
162 }, function(error) {
163 chrome.test.fail(error.name);
164 });
165 }, function(error) {
166 chrome.test.fail(error.name);
167 });
168 },
131 // Read metadata of a directory which does not exist, what should return an 169 // Read metadata of a directory which does not exist, what should return an
132 // error. DirectoryEntry.getDirectory() causes fetching metadata. 170 // error. DirectoryEntry.getDirectory() causes fetching metadata.
133 function getFileMetadataNotFound() { 171 function getFileMetadataNotFound() {
134 var onSuccess = chrome.test.callbackPass(function() {}); 172 var onSuccess = chrome.test.callbackPass();
135 fileSystem.root.getDirectory( 173 fileSystem.root.getDirectory(
136 'cranberries', 174 'cranberries',
137 {create: false}, 175 {create: false},
138 function(dirEntry) { 176 function(dirEntry) {
139 chrome.test.fail(); 177 chrome.test.fail();
140 }, 178 },
141 function(error) { 179 function(error) {
142 chrome.test.assertEq('NotFoundError', error.name); 180 chrome.test.assertEq('NotFoundError', error.name);
143 onSuccess(); 181 onSuccess();
144 }); 182 });
145 }, 183 },
146 // Read metadata of a file using getDirectory(). An error should be returned 184 // Read metadata of a file using getDirectory(). An error should be returned
147 // because of type mismatching. DirectoryEntry.getDirectory() causes 185 // because of type mismatching. DirectoryEntry.getDirectory() causes
148 // fetching metadata. 186 // fetching metadata.
149 function getFileMetadataWrongType() { 187 function getFileMetadataWrongType() {
150 var onSuccess = chrome.test.callbackPass(function() {}); 188 var onSuccess = chrome.test.callbackPass();
151 fileSystem.root.getDirectory( 189 fileSystem.root.getDirectory(
152 TESTING_FILE.name, 190 TESTING_FILE.name,
153 {create: false}, 191 {create: false},
154 function(fileEntry) { 192 function(fileEntry) {
155 chrome.test.fail(); 193 chrome.test.fail();
156 }, 194 },
157 function(error) { 195 function(error) {
158 chrome.test.assertEq('TypeMismatchError', error.name); 196 chrome.test.assertEq('TypeMismatchError', error.name);
159 onSuccess(); 197 onSuccess();
160 }); 198 });
161 } 199 }
162 ]); 200 ]);
163 } 201 }
164 202
165 // Setup and run all of the test cases. 203 // Setup and run all of the test cases.
166 setUp(runTests); 204 setUp(runTests);
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/file_system_provider/operations/get_metadata.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698