Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / inspector / isolated-filesystem-test.js
blobc890a50c9bb9562978f55e971aaab272ebda7951
1 var initialize_IsolatedFileSystemTest = function() {
3 InspectorTest.createIsolatedFileSystemManager = function(workspace)
5 var normalizePath = WebInspector.IsolatedFileSystem.normalizePath
6 WebInspector.IsolatedFileSystem = MockIsolatedFileSystem;
7 WebInspector.IsolatedFileSystem.normalizePath = normalizePath;
9 var manager = new MockIsolatedFileSystemManager();
10 manager.fileSystemMapping = InspectorTest.testFileSystemMapping;
11 manager.fileSystemWorkspaceBinding = new WebInspector.FileSystemWorkspaceBinding(manager, workspace, InspectorTest.testNetworkMapping);
12 return manager;
15 var MockIsolatedFileSystem = function(manager, path, name, rootURL)
17 MockIsolatedFileSystem._isolatedFileSystemMocks = MockIsolatedFileSystem._isolatedFileSystemMocks || {};
18 MockIsolatedFileSystem._isolatedFileSystemMocks[path] = this;
19 this.originalTimestamp = 1000000;
20 this.modificationTimestampDelta = 1000;
21 this._path = path;
22 this._manager = manager;
24 MockIsolatedFileSystem.prototype = {
25 path: function()
27 return this._path;
30 normalizedPath: function()
32 return this._path;
35 requestFileContent: function(path, callback)
37 callback(this._files[path]);
40 requestMetadata: function(path, callback)
42 if (!(path in this._files)) {
43 callback(null, null);
44 return;
46 callback(new Date(this._modificationTimestamps[path]), this._files[path].length);
49 setFileContent: function(path, newContent, callback)
51 this._files[path] = newContent;
52 this._modificationTimestamps[path] = (this._modificationTimestamps[path] || (this.originalTimestamp - this.modifiationTimestampDelta)) + this.modificationTimestampDelta;
53 callback();
56 requestFilesRecursive: function(path, callback)
58 this._callback = callback;
59 if (!this._files)
60 return;
61 this._innerRequestFilesRecursive();
64 renameFile: function(filePath, newName, callback)
66 callback(true, newName);
69 _innerRequestFilesRecursive: function()
71 if (!this._callback)
72 return;
73 var files = Object.keys(this._files);
74 for (var i = 0; i < files.length; ++i) {
75 var isExcluded = false;
76 for (var j = 0; j < files[i].length; ++j) {
77 if (files[i][j] === "/") {
78 if (InspectorTest.testExcludedFolderManager.isFileExcluded(this._path, files[i].substr(0, j + 1)))
79 isExcluded = true;
82 if (isExcluded)
83 continue;
84 this._callback(files[i].substr(1));
86 delete this._callback;
89 _addFiles: function(files)
91 this._files = files;
92 this._modificationTimestamps = {};
93 var files = Object.keys(this._files);
94 for (var i = 0; i < files.length; ++i)
95 this._modificationTimestamps[files[i]] = this.originalTimestamp;
96 this._innerRequestFilesRecursive();
100 var MockIsolatedFileSystemManager = function() {};
101 MockIsolatedFileSystemManager.prototype = {
102 addMockFileSystem: function(path, skipAddFileSystem)
104 var fileSystem = new MockIsolatedFileSystem(this, path, "", "");
105 this._fileSystems = this._fileSystems || {};
106 this._fileSystems[path] = fileSystem;
107 if (!skipAddFileSystem)
108 this.fileSystemMapping.addFileSystem(path);
109 this.dispatchEventToListeners(WebInspector.IsolatedFileSystemManager.Events.FileSystemAdded, fileSystem);
112 addFiles: function(path, files)
114 var fileSystem = this._fileSystems[path];
115 fileSystem._addFiles(files);
118 removeFileSystem: function(path)
120 var fileSystem = this._fileSystems[path];
121 delete this._fileSystems[path];
122 this.fileSystemMapping.removeFileSystem(path);
123 this.dispatchEventToListeners(WebInspector.IsolatedFileSystemManager.Events.FileSystemRemoved, fileSystem);
126 mapping: function()
128 return this.fileSystemMapping;
131 excludedFolderManager: function()
133 return InspectorTest.testExcludedFolderManager;
136 __proto__: WebInspector.Object.prototype
139 InspectorTest.addMockFileSystem = function(path)
141 var fileSystem = { fileSystemName: "", rootURL: "", fileSystemPath: path };
142 WebInspector.isolatedFileSystemManager._onFileSystemAdded({data: {fileSystem: fileSystem}});
143 return MockIsolatedFileSystem._isolatedFileSystemMocks[path];
146 InspectorTest.addFilesToMockFileSystem = function(path, files)
148 MockIsolatedFileSystem._isolatedFileSystemMocks[path]._addFiles(files);
151 InspectorFrontendHost.isolatedFileSystem = function(name, url)
153 return InspectorTest.TestFileSystem._instances[name];
156 InspectorTest.TestFileSystem = function(fileSystemPath)
158 this.root = new InspectorTest.TestFileSystem.Entry("", true);
159 this.fileSystemPath = fileSystemPath;
162 InspectorTest.TestFileSystem._instances = {};
164 InspectorTest.TestFileSystem.prototype = {
165 reportCreated: function()
167 WebInspector.isolatedFileSystemManager._loaded = true;
168 InspectorTest.TestFileSystem._instances[this.fileSystemPath] = this;
169 InspectorFrontendHost.events.dispatchEventToListeners(InspectorFrontendHostAPI.Events.FileSystemAdded, {
170 fileSystem: { fileSystemPath: this.fileSystemPath,
171 fileSystemName: this.fileSystemPath }
175 removeFileSystem: function()
177 delete InspectorTest.TestFileSystem._instances[this.fileSystemPath];
178 InspectorFrontendHost.events.dispatchEventToListeners(InspectorFrontendHostAPI.Events.FileSystemRemoved, this.fileSystemPath);
182 InspectorTest.TestFileSystem.Entry = function(name, isDirectory)
184 this.name = name;
185 this._children = [];
186 this._childrenMap = {};
187 this.isDirectory = isDirectory;
188 this._timestamp = 1000000;
191 InspectorTest.TestFileSystem.Entry.prototype = {
192 get fullPath()
194 return this.parent ? this.parent.fullPath + "/" + this.name : "";
197 mkdir: function(name)
199 var child = new InspectorTest.TestFileSystem.Entry(name, true);
200 this._childrenMap[name] = child;
201 this._children.push(child);
202 child.parent = this;
203 return child;
206 addFile: function(name, content)
208 var child = new InspectorTest.TestFileSystem.Entry(name, false);
209 this._childrenMap[name] = child;
210 this._children.push(child);
211 child.parent = this;
212 child.content = new Blob([content], {type: 'text/plain'});
215 createReader: function()
217 return new InspectorTest.TestFileSystem.Reader(this._children);
220 createWriter: function(success, failure)
222 success(new InspectorTest.TestFileSystem.Writer(this));
225 file: function(callback)
227 callback(this.content);
230 getDirectory: function(path, noop, callback)
232 this.getEntry(path, noop, callback);
235 getFile: function(path, noop, callback)
237 this.getEntry(path, noop, callback);
240 getEntry: function(path, noop, callback)
242 if (path.startsWith("/"))
243 path = path.substring(1);
244 if (!path) {
245 callback(this);
246 return;
248 var entry = this;
249 for (var token of path.split("/"))
250 entry = entry._childrenMap[token];
251 callback(entry);
254 getMetadata: function(success, failure)
256 success({
257 modificationTime: new Date(this._timestamp),
258 size: this.isDirectory ? 0 : this.content.size
263 InspectorTest.TestFileSystem.Reader = function(children)
265 this._children = children;
268 InspectorTest.TestFileSystem.Reader.prototype = {
269 readEntries: function(callback)
271 var children = this._children;
272 this._children = [];
273 callback(children);
277 InspectorTest.TestFileSystem.Writer = function(entry)
279 this._entry = entry;
280 this._modificationTimesDelta = 500;
283 InspectorTest.TestFileSystem.Writer.prototype = {
284 write: function(blob)
286 this._entry._timestamp += this._modificationTimesDelta;
287 this._entry.content = blob;
288 if (this.onwriteend)
289 this.onwriteend();
292 truncate: function(num)
294 this._entry._timestamp += this._modificationTimesDelta;
295 this._entry.content = this._entry.content.slice(0, num);
296 if (this.onwriteend)
297 this.onwriteend();