Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / http / tests / inspector / isolated-filesystem-test.js
1 var initialize_IsolatedFileSystemTest = function() {
2
3 InspectorTest.createIsolatedFileSystemManager = function(workspace, fileSystemMapping)
4 {
5     var manager = new MockIsolatedFileSystemManager();
6     manager.fileSystemWorkspaceBinding = new WebInspector.FileSystemWorkspaceBinding(manager, workspace);
7     manager.fileSystemMapping = fileSystemMapping;
8     return manager;
9 }
10
11 var MockIsolatedFileSystem = function(manager, path, name, rootURL)
12 {
13     MockIsolatedFileSystem._isolatedFileSystemMocks = MockIsolatedFileSystem._isolatedFileSystemMocks || {};
14     MockIsolatedFileSystem._isolatedFileSystemMocks[path] = this;
15     this.originalTimestamp = 1000000;
16     this.modificationTimestampDelta = 1000;
17     this._path = path;
18     this._manager = manager;
19 };
20 MockIsolatedFileSystem.prototype = {
21     path: function()
22     {
23         return this._path;
24     },
25
26     normalizedPath: function()
27     {
28         return this._path;
29     },
30
31     requestFileContent: function(path, callback)
32     {
33         callback(this._files[path]);
34     },
35
36     requestMetadata: function(path, callback)
37     {
38         if (!(path in this._files)) {
39             callback(null, null);
40             return;
41         }
42         callback(new Date(this._modificationTimestamps[path]), this._files[path].length);
43     },
44
45     setFileContent: function(path, newContent, callback)
46     {
47         this._files[path] = newContent;
48         this._modificationTimestamps[path] = (this._modificationTimestamps[path] || (this.originalTimestamp - this.modifiationTimestampDelta)) + this.modificationTimestampDelta;
49         callback();
50     },
51
52     requestFilesRecursive: function(path, callback)
53     {
54         this._callback = callback;
55         if (!this._files)
56             return;
57         this._innerRequestFilesRecursive();
58     },
59
60     renameFile: function(filePath, newName, callback)
61     {
62         callback(true, newName);
63     },
64
65     _innerRequestFilesRecursive: function()
66     {
67         if (!this._callback)
68             return;
69         var files = Object.keys(this._files);
70         for (var i = 0; i < files.length; ++i) {
71             var isExcluded = false;
72             for (var j = 0; j < files[i].length; ++j) {
73                 if (files[i][j] === "/") {
74                     if (this._manager.mapping().isFileExcluded(this._path, files[i].substr(0, j + 1)))
75                         isExcluded = true;
76                 }
77             }
78             if (isExcluded)
79                 continue;
80             this._callback(files[i].substr(1));
81         }
82         delete this._callback;
83     },
84
85     _addFiles: function(files)
86     {
87         this._files = files;
88         this._modificationTimestamps = {};
89         var files = Object.keys(this._files);
90         for (var i = 0; i < files.length; ++i)
91             this._modificationTimestamps[files[i]] = this.originalTimestamp;
92         this._innerRequestFilesRecursive();
93     }
94 }
95
96 var normalizePath = WebInspector.IsolatedFileSystem.normalizePath
97 WebInspector.IsolatedFileSystem = MockIsolatedFileSystem;
98 WebInspector.IsolatedFileSystem.normalizePath = normalizePath;
99
100 var MockIsolatedFileSystemManager = function() {};
101 MockIsolatedFileSystemManager.prototype = {
102     addMockFileSystem: function(path, skipAddFileSystem)
103     {
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);
110     },
111
112     addFiles: function(path, files)
113     {
114         var fileSystem = this._fileSystems[path];
115         fileSystem._addFiles(files);
116     },
117
118     removeFileSystem: function(path)
119     {
120         var fileSystem = this._fileSystems[path];
121         delete this._fileSystems[path];
122         this.fileSystemMapping.removeFileSystem(path);
123         this.dispatchEventToListeners(WebInspector.IsolatedFileSystemManager.Events.FileSystemRemoved, fileSystem);
124     },
125
126     mapping: function()
127     {
128         return this.fileSystemMapping;
129     },
130
131     __proto__: WebInspector.Object.prototype
132 }
133
134 InspectorTest.addMockFileSystem = function(path)
135 {
136     var fileSystem = { fileSystemName: "", rootURL: "", fileSystemPath: path };
137     WebInspector.isolatedFileSystemManager._onFileSystemAdded({data: {fileSystem: fileSystem}});
138     return MockIsolatedFileSystem._isolatedFileSystemMocks[path];
139 }
140
141 InspectorTest.addFilesToMockFileSystem = function(path, files)
142 {
143     MockIsolatedFileSystem._isolatedFileSystemMocks[path]._addFiles(files);
144 }
145
146 };