Upstream version 7.36.149.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     _innerRequestFilesRecursive: function()
61     {
62         if (!this._callback)
63             return;
64         var files = Object.keys(this._files);
65         for (var i = 0; i < files.length; ++i) {
66             var isExcluded = false;
67             for (var j = 0; j < files[i].length; ++j) {
68                 if (files[i][j] === "/") {
69                     if (this._manager.mapping().isFileExcluded(this._path, files[i].substr(0, j + 1)))
70                         isExcluded = true;
71                 }
72             }
73             if (isExcluded)
74                 continue;
75             this._callback(files[i].substr(1));
76         }
77         delete this._callback;
78     },
79
80     _addFiles: function(files)
81     {
82         this._files = files;
83         this._modificationTimestamps = {};
84         var files = Object.keys(this._files);
85         for (var i = 0; i < files.length; ++i)
86             this._modificationTimestamps[files[i]] = this.originalTimestamp;
87         this._innerRequestFilesRecursive();
88     }
89 }
90
91 var normalizePath = WebInspector.IsolatedFileSystem.normalizePath
92 WebInspector.IsolatedFileSystem = MockIsolatedFileSystem;
93 WebInspector.IsolatedFileSystem.normalizePath = normalizePath;
94
95 var MockIsolatedFileSystemManager = function() {};
96 MockIsolatedFileSystemManager.prototype = {
97     addMockFileSystem: function(path, skipAddFileSystem)
98     {
99         var fileSystem = new MockIsolatedFileSystem(this, path, "", "");
100         this._fileSystems = this._fileSystems || {};
101         this._fileSystems[path] = fileSystem;
102         if (!skipAddFileSystem)
103             this.fileSystemMapping.addFileSystem(path);
104         this.dispatchEventToListeners(WebInspector.IsolatedFileSystemManager.Events.FileSystemAdded, fileSystem);
105     },
106
107     addFiles: function(path, files)
108     {
109         var fileSystem = this._fileSystems[path];
110         fileSystem._addFiles(files);
111     },
112
113     removeMockFileSystem: function(path)
114     {
115         var fileSystem = this._fileSystems[path];
116         delete this._fileSystems[path];
117         this.fileSystemMapping.removeFileSystem(path);
118         this.dispatchEventToListeners(WebInspector.IsolatedFileSystemManager.Events.FileSystemRemoved, fileSystem);
119     },
120
121     mapping: function()
122     {
123         return this.fileSystemMapping;
124     },
125
126     __proto__: WebInspector.Object.prototype
127 }
128
129 InspectorTest.addMockFileSystem = function(path)
130 {
131     var fileSystem = { fileSystemName: "", rootURL: "", fileSystemPath: path };
132     WebInspector.isolatedFileSystemDispatcher.fileSystemAdded("", fileSystem);
133     return MockIsolatedFileSystem._isolatedFileSystemMocks[path];
134 }
135
136 InspectorTest.addFilesToMockFileSystem = function(path, files)
137 {
138     MockIsolatedFileSystem._isolatedFileSystemMocks[path]._addFiles(files);
139 }
140
141 };